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

feat: add '.accent-x' utility class #637

Merged
merged 2 commits into from
Dec 29, 2021
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 src/config/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,5 @@ export enum pluginOrder {
'willChange' = 14200,
'touchAction' = 14300,
'scrollBehavior' = 14400,
'accentColor' = 14500,
}
14 changes: 14 additions & 0 deletions src/lib/utilities/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,19 @@ function content(utility: Utility, { theme }: PluginUtils): Output {
?.updateMeta('utilities', 'content', pluginOrder.content, 1, true);
}

// https://windicss.org/utilities/behaviors.html#accent-color
function accent(utility:Utility, { theme }: PluginUtils): Output {
const color = utility.handler
.handleColor(theme('boxShadowColor'))
.handleOpacity(theme('opacity'))
.handleSquareBrackets()
.handleVariable()
.createColorValue('1');

return new Style(utility.class, new Property('accent-color', color))
.updateMeta('utilities', 'accentColor', pluginOrder.accentColor, 0, true);
}

export const dynamicUtilities: DynamicUtility = {
columns: columns,
container: container,
Expand Down Expand Up @@ -1650,4 +1663,5 @@ export const dynamicUtilities: DynamicUtility = {
delay: delay,
content: content,
animate: animation,
accent: accent,
};
10 changes: 7 additions & 3 deletions test/processor/__snapshots__/resolve.test.ts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ Tools / get corePlugins / list / 0: |-
"backdropSepia",
"willChange",
"touchAction",
"scrollBehavior"
"scrollBehavior",
"accentColor"
]
Tools / get corePlugins / list2 / 1: |-
[
Expand Down Expand Up @@ -353,7 +354,8 @@ Tools / get corePlugins / list3 / 2: |-
"backdropSepia",
"willChange",
"touchAction",
"scrollBehavior"
"scrollBehavior",
"accentColor"
]
Tools / resolve dynamic utilities / with-plugins / 1: |-
[
Expand Down Expand Up @@ -440,6 +442,7 @@ Tools / resolve dynamic utilities / with-plugins / 1: |-
"delay",
"content",
"animate",
"accent",
"filter",
"aspect-w",
"aspect-h",
Expand Down Expand Up @@ -531,5 +534,6 @@ Tools / resolve dynamic utilities / without-plugins / 0: |-
"duration",
"delay",
"content",
"animate"
"animate",
"accent"
]
13 changes: 13 additions & 0 deletions test/processor/__snapshots__/utilities.test.ts.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Tools / accent-color / css / 0: |-
.accent-green-500\/50 {
accent-color: rgba(16, 185, 129, 0.5);
}
.accent-red-500\/50 {
accent-color: rgba(239, 68, 68, 0.5);
}
.accent-green-500 {
accent-color: rgba(16, 185, 129, 1);
}
.accent-red-500 {
accent-color: rgba(239, 68, 68, 1);
}
Tools / animation / animation / 0: |-
@keyframes spin {
from {
Expand Down
9 changes: 9 additions & 0 deletions test/processor/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,13 @@ describe('Utilities', () => {
basis-1/2
`).styleSheet.build()).toMatchSnapshot('css');
});

it('accent-color', () => {
expect(processor.interpret(`
accent-green-500/50
accent-red-500/50
accent-green-500
accent-red-500
`).styleSheet.build()).toMatchSnapshot('css');
});
});