Skip to content

Commit

Permalink
fix: be able to use a one-off background image (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaRybkina committed Apr 26, 2023
1 parent af2b289 commit 12df5a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/_rules/background.js
Expand Up @@ -36,4 +36,7 @@ export const backgrounds = [
['bg-origin-padding', { 'background-origin': 'padding-box' }],
['bg-origin-content', { 'background-origin': 'content-box' }],
...makeGlobalStaticRules('bg-origin', 'background-origin'),

//arbitrary
[/^bg-\[url\('(.+)'\)]/, ([, p]) => ({ 'background-image': `url(${p})` })],
];
9 changes: 9 additions & 0 deletions test/background.js
Expand Up @@ -51,3 +51,12 @@ test('bg invalid', async ({ uno }) => {
const { css } = await uno.generate(classes);
expect(css).toMatchInlineSnapshot('""');
});

test('bg arbitrary url', async ({ uno }) => {
const classes = [`bg-[url('/img/hero-pattern.svg')]`];
const { css } = await uno.generate(classes);
expect(css).toMatchInlineSnapshot(`
"/* layer: default */
.bg-\\\\[url\\\\(\\\\'\\\\/img\\\\/hero-pattern\\\\.svg\\\\'\\\\)\\\\]{background-image:url(/img/hero-pattern.svg);}"
`);
});

0 comments on commit 12df5a9

Please sign in to comment.