Skip to content

Commit

Permalink
Fix generation of prose-headings variant (#264)
Browse files Browse the repository at this point in the history
* Fix prose-headings variant

* Update changelog
  • Loading branch information
thecrypticace committed Apr 13, 2022
1 parent b42c452 commit ac0fcda
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix prose elements `legacy` mode ([#259](https://github.com/tailwindlabs/tailwindcss-typography/pull/259))
- Allow `lead` class to override element styles ([#260](https://github.com/tailwindlabs/tailwindcss-typography/pull/260))
- Fix generation of `prose-headings` variant ([#264](https://github.com/tailwindlabs/tailwindcss-typography/pull/264))

## [0.5.2] - 2022-02-14

Expand Down
12 changes: 9 additions & 3 deletions src/index.js
Expand Up @@ -89,8 +89,8 @@ module.exports = plugin.withOptions(

let options = { className, prefix }

for (let [name, selector = name] of [
['headings', 'h1, h2, h3, h4, th'],
for (let [name, ...selectors] of [
['headings', 'h1', 'h2', 'h3', 'h4', 'th'],
['h1'],
['h2'],
['h3'],
Expand All @@ -117,7 +117,13 @@ module.exports = plugin.withOptions(
['hr'],
['lead', '[class~="lead"]'],
]) {
addVariant(`${className}-${name}`, target === 'legacy' ? `& ${selector}` : `& :is(${inWhere(selector, options)})`)
selectors = selectors.length === 0 ? [name] : selectors

let selector = target === 'legacy'
? selectors.map(selector => `& ${selector}`)
: selectors.join(', ')

addVariant(`${className}-${name}`, target === 'legacy' ? selector : `& :is(${inWhere(selector, options)})`)
}

addComponents(
Expand Down
17 changes: 16 additions & 1 deletion src/index.test.js
Expand Up @@ -335,7 +335,7 @@ test('modifiers', async () => {
test('legacy target', async () => {
let config = {
plugins: [typographyPlugin({ target: 'legacy' })],
content: [{ raw: html`<div class="prose prose-h1:text-center"></div>` }],
content: [{ raw: html`<div class="prose prose-h1:text-center prose-headings:text-ellipsis"></div>` }],
theme: {
typography: {
DEFAULT: {
Expand Down Expand Up @@ -423,6 +423,21 @@ test('legacy target', async () => {
.prose code::after {
content: '&#96;';
}
.prose-headings\:text-ellipsis h1 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h2 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h3 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h4 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis th {
text-overflow: ellipsis;
}
.prose-h1\:text-center h1 {
text-align: center;
}
Expand Down

1 comment on commit ac0fcda

@vercel
Copy link

@vercel vercel bot commented on ac0fcda Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.