Skip to content

Commit

Permalink
feat: Add support for arbitrary box-shadow (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: Balbina K <41303231+BalbinaK@users.noreply.github.com>
  • Loading branch information
magnuh and BalbinaK committed Jan 24, 2024
1 parent 94ed482 commit 984e3d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/_rules/shadow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const shadows = [[/^shadow-(s|m|l|xl)$/, ([, size]) => ({ 'box-shadow': `var(--w-shadow-${size})` })]];
import { resolveArbitraryValues } from '#utils';

export const shadows = [
[/^shadow-(s|m|l|xl)$/, ([, size]) => ({ 'box-shadow': `var(--w-shadow-${size})` })],
[/^shadow-\[(.+)]$/, ([, val]) => ({ 'box-shadow': val.startsWith('--') ? `var(${val})` : resolveArbitraryValues(val) })],
];

const dropShadowDefaultColor = '64, 64, 64';

Expand Down
4 changes: 2 additions & 2 deletions src/_rules/slider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Hardcoded styling for slider border shadow, will be modified and handled with correct color variables at a later stage
// TODO: Make the colors for the slider shadow themeable
// Deprecated - DO NOT USE! - Replace with arbitrary box-shadow (shadow-[--token]) to handle theming

const defaultColor = 'rgba(0, 0, 0, .08)';
const sliderStates = {
active: '0 0 0 8px',
Expand Down
7 changes: 7 additions & 0 deletions test/__snapshots__/shadow.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`arbitrary box-shadows work 1`] = `
"/* layer: default */
.shadow-\\[--w-shadow-m\\]{box-shadow:var(--w-shadow-m);}
.shadow-\\[0_6px_12px_rgba\\(0\\,0\\,0\\,\\.2\\)\\,0_10px_20px_rgba\\(0\\,0\\,0\\,\\.1\\)\\]{box-shadow:0rem 6px 12px rgba(0,0,0,.2),0 10px 20px rgba(0,0,0,.1);}
.shadow-\\[var\\(--arbitrary-shadow-var\\)\\]{box-shadow:var(--arbitrary-shadow-var);}"
`;

exports[`drop shadows 1`] = `
"/* layer: default */
.drop-shadow-l{filter:drop-shadow(rgba(64, 64, 64, .23) 0 6px 8px) drop-shadow(rgba(64, 64, 64, .19) 0 10px 20px);}
Expand Down
6 changes: 6 additions & 0 deletions test/shadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ test('shadows work', async ({ uno }) => {
expect(css).toMatchSnapshot();
});

test('arbitrary box-shadows work', async ({ uno }) => {
const classes = ['shadow-[var(--arbitrary-shadow-var)]', 'shadow-[--w-shadow-m]', 'shadow-[0_6px_12px_rgba(0,0,0,.2),0_10px_20px_rgba(0,0,0,.1)]'];
const { css } = await uno.generate(classes);
expect(css).toMatchSnapshot();
});

test('drop shadows', async ({ uno }) => {
const classes = ['drop-shadow-s', 'drop-shadow-m', 'drop-shadow-l', 'drop-shadow-xl'];
const { css } = await uno.generate(classes);
Expand Down

0 comments on commit 984e3d3

Please sign in to comment.