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: New surface concept #208

Merged
merged 1 commit into from
Mar 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/_rules/semantic.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ export const semanticRules = [
[getSemanticRegEx('outline'), ([, semanticVal = '']) => ({ 'outline-color': h.semanticToken(`border${semanticVal}`) })],
[getSemanticRegEx('border', 'lrtbxy'), handleBorder],
[getSemanticRegEx('divide', 'xy'), handleDivide],
[/^s-surface-sunken$/, () => ({ 'background-color': 'var(--w-s-color-surface-sunken)' })],
[
/^s-(surface-elevated-.*)$/,
([, semanticVal]) => ({
'background-color': `var(--w-s-color-${semanticVal}`,
'box-shadow': `var(--w-s-shadow-${semanticVal})`,
}),
],
];
14 changes: 14 additions & 0 deletions test/__snapshots__/semantic.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`it generates css based on semantic surface tokens 1`] = `
"/* layer: default */
.s-surface-sunken{background-color:var(--w-s-color-surface-sunken);}
.s-surface-elevated-100{background-color:var(--w-s-color-surface-elevated-100;box-shadow:var(--w-s-shadow-surface-elevated-100);}
.s-surface-elevated-100-active{background-color:var(--w-s-color-surface-elevated-100-active;box-shadow:var(--w-s-shadow-surface-elevated-100-active);}
.s-surface-elevated-100-hover{background-color:var(--w-s-color-surface-elevated-100-hover;box-shadow:var(--w-s-shadow-surface-elevated-100-hover);}
.s-surface-elevated-200{background-color:var(--w-s-color-surface-elevated-200;box-shadow:var(--w-s-shadow-surface-elevated-200);}
.s-surface-elevated-200-active{background-color:var(--w-s-color-surface-elevated-200-active;box-shadow:var(--w-s-shadow-surface-elevated-200-active);}
.s-surface-elevated-200-hover{background-color:var(--w-s-color-surface-elevated-200-hover;box-shadow:var(--w-s-shadow-surface-elevated-200-hover);}
.s-surface-elevated-300{background-color:var(--w-s-color-surface-elevated-300;box-shadow:var(--w-s-shadow-surface-elevated-300);}
.s-surface-elevated-300-active{background-color:var(--w-s-color-surface-elevated-300-active;box-shadow:var(--w-s-shadow-surface-elevated-300-active);}
.s-surface-elevated-300-hover{background-color:var(--w-s-color-surface-elevated-300-hover;box-shadow:var(--w-s-shadow-surface-elevated-300-hover);}"
`;

exports[`it generates css based on semantic warp tokens 1`] = `
"/* layer: default */
.s-bg{background-color:var(--w-s-color-background);}
Expand Down
12 changes: 12 additions & 0 deletions test/semantic.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ test('it should not generate css with incorrect alpha channel values', async ({
const { css } = await uno.generate(antiClasses);
expect(css).toHaveLength(0);
});

test('it generates css based on semantic surface tokens', async ({ uno }) => {
const classes = ['s-surface-sunken', 's-surface-elevated-100', 's-surface-elevated-100-hover', 's-surface-elevated-100-active', 's-surface-elevated-200', 's-surface-elevated-200-hover', 's-surface-elevated-200-active', 's-surface-elevated-300', 's-surface-elevated-300-hover', 's-surface-elevated-300-active'];
const { css } = await uno.generate(classes);
expect(css).toMatchSnapshot();
});

test('it should not generate css for incorrect surface classes', async ({ uno }) => {
const antiClasses = ['s-surface', 's-surface-sunken-100', 's-surface-elevated', 'surface-elevated-100', 'surface-sunken'];
const { css } = await uno.generate(antiClasses);
expect(css).toHaveLength(0);
});
Loading