Skip to content

Commit

Permalink
feat: attribute scope style strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Aug 1, 2023
1 parent e35d2b9 commit b187935
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .changeset/neat-suns-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'astro': minor
---

Implements a new scope style strategy called `attribute`. When enabled, styles are applied using `data-*` attributes.

```js
import { defineConfig } from 'astro/config';

export default defineConfig({
scopedStyleStrategy: 'attribute',
});
```
32 changes: 32 additions & 0 deletions packages/astro/test/scoped-style-strategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,36 @@ describe('scopedStyleStrategy', () => {
expect(stylesheet).to.match(/h1\.astro/);
});
});

describe('scopedStyleStrategy: "attribute"', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let stylesheet;

before(async () => {
fixture = await loadFixture({
root: './fixtures/scoped-style-strategy/',
scopedStyleStrategy: 'attribute',
});
await fixture.build();

const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const $link = $('link[rel=stylesheet]');
const href = $link.attr('href');
stylesheet = await fixture.readFile(href);
});

it('does not include :where pseudo-selector', () => {
expect(stylesheet).to.not.match(/:where/);
});

it('does not include the class name directly in the selector', () => {
expect(stylesheet).to.not.match(/h1\.astro/);
});

it('includes the data attribute hash', () => {
expect(stylesheet).to.include('h1[data-astro-hash-');
});
});
});
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b187935

Please sign in to comment.