Skip to content

Commit

Permalink
Merge pull request #283 from core-ds/fix/skip-css-prefix-for-root
Browse files Browse the repository at this point in the history
fix(postcss-prefix-selector): keep only prefix for :root selector
  • Loading branch information
dryabinin94 authored Nov 6, 2024
2 parents 6f1e6ec + c84f2f6 commit 10748c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-schools-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'arui-scripts': minor
---

Исправление реализации префикса для :root селектора для правильной работы css переменных
15 changes: 14 additions & 1 deletion packages/arui-scripts/src/plugins/postcss-prefix-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type PostCssPrefixOptions = {

const VisitedRule = Symbol('VisitedRule');

const ROOT_SELECTOR = ':root';

type RootWithVisitedRule = Root & {
[VisitedRule]?: boolean;
};
Expand Down Expand Up @@ -49,7 +51,18 @@ const postCssPrefix: PluginCreator<PostCssPrefixOptions> = (options) => {
return;
}

rule.selectors = rule.selectors.map((selector) => `${prefix}${selector}`);
rule.selectors = rule.selectors.map((selector) => {
/**
* Оборачивам только самим префиксом без :root.
* Позволяет инкапсулировать css переменные под классом.
* В таком случае они будут доступны в модулях приложений после использования флага keepCssVars.
*/
if (selector === ROOT_SELECTOR) {
return prefix;
}

return `${prefix}${selector}`;
});
});
},
};
Expand Down

0 comments on commit 10748c5

Please sign in to comment.