Skip to content

Commit

Permalink
Add support for important key from configs
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Sep 24, 2024
1 parent 9b5d3d5 commit e9dfc22
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/tailwindcss/src/compat/apply-compat-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ export async function applyCompatibilityHooks({
designSystem.theme.prefix = resolvedConfig.prefix
}

// If an important strategy has already been set in CSS don't override it
if (!designSystem.important && resolvedConfig.important) {
designSystem.important =
typeof resolvedConfig.important === 'string'
? `${resolvedConfig.important} &`
: resolvedConfig.important
}

// Replace `resolveThemeValue` with a version that is backwards compatible
// with dot-notation but also aware of any JS theme configurations registered
// by plugins or JS config files. This is significantly slower than just
Expand Down
76 changes: 76 additions & 0 deletions packages/tailwindcss/src/compat/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,3 +1371,79 @@ test('a prefix must be letters only', async () => {
`[Error: The prefix "__" is invalid. Prefixes must be lowercase ASCII letters (a-z) only.]`,
)
})

test('important: `#app`', async () => {
let input = css`
@tailwind utilities;
@config "./config.js";
@utility custom {
color: red;
}
`

let compiler = await compile(input, {
loadModule: async (_, base) => ({
base,
module: { important: '#app' },
}),
})

expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toMatchInlineSnapshot(`
".custom {
#app & {
color: red;
}
}
.underline {
#app & {
text-decoration-line: underline;
}
}
.hover\\:line-through {
#app & {
&:hover {
@media (hover: hover) {
text-decoration-line: line-through;
}
}
}
}
"
`)
})

test('important: true', async () => {
let input = css`
@tailwind utilities;
@config "./config.js";
@utility custom {
color: red;
}
`

let compiler = await compile(input, {
loadModule: async (_, base) => ({
base,
module: { important: true },
}),
})

expect(compiler.build(['underline', 'hover:line-through', 'custom'])).toMatchInlineSnapshot(`
".custom {
color: red!important;
}
.underline {
text-decoration-line: underline!important;
}
.hover\\:line-through {
&:hover {
@media (hover: hover) {
text-decoration-line: line-through!important;
}
}
}
"
`)
})

0 comments on commit e9dfc22

Please sign in to comment.