Skip to content

Commit

Permalink
feat: New surface concept (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
magnuh committed Mar 15, 2024
1 parent 9e0834d commit c8ad03d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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);
});

0 comments on commit c8ad03d

Please sign in to comment.