Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generation of prose-headings variant #264

Merged
merged 2 commits into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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