From cedec803fb05b5d92ef32c67352265fc7636500c Mon Sep 17 00:00:00 2001 From: Tim Kolberger Date: Tue, 1 Feb 2022 21:57:06 +0100 Subject: [PATCH] feat: add [data-css-vars-root=true] as css var root --- .changeset/twenty-cooks-visit.md | 7 +++++++ packages/system/src/providers.tsx | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/twenty-cooks-visit.md diff --git a/.changeset/twenty-cooks-visit.md b/.changeset/twenty-cooks-visit.md new file mode 100644 index 00000000000..c8095ae0da3 --- /dev/null +++ b/.changeset/twenty-cooks-visit.md @@ -0,0 +1,7 @@ +--- +"@chakra-ui/system": minor +--- + +Added `[data-css-vars-root=true]` to the CSS variables root selector. This +allows to layer the CSS variable definitions and allow the semantic tokens to +react to `data-theme="dark"` and `data-theme="light"`. diff --git a/packages/system/src/providers.tsx b/packages/system/src/providers.tsx index a54690b2796..5fe06fd9815 100644 --- a/packages/system/src/providers.tsx +++ b/packages/system/src/providers.tsx @@ -34,12 +34,17 @@ export const ThemeProvider = (props: ThemeProviderProps) => { export interface CSSVarsProps { /** * The element to attach the CSS custom properties to. - * @default ":host, :root" + * Re-hoist CSS vars by attaching `data-css-vars-root={true}` to a DOM element. + * @example
+ * + * @default ":host, :root, [data-css-vars-root=true]" */ root?: string } -export const CSSVars = ({ root = ":host, :root" }: CSSVarsProps) => ( +export const CSSVars = ({ + root = ":host, :root, [data-css-vars-root=true]", +}: CSSVarsProps) => ( ({ [root]: theme.__cssVars })} /> )