components-test-pb 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { assertSlots, slot, useARIAButtonProps } from './utilities';
2
- export { tokens, defaultTheme, themeToCSS } from './theme';
2
+ export { tokens, defaultTheme, themeToCSS, insertTheme } from './theme';
3
3
  export type { Theme } from './theme';
4
4
  export { Button, useButton, renderButton, useButtonStyles, buttonClassNames, } from './components';
5
5
  export type { ButtonSlots, ButtonAppearance, ButtonShape, ButtonSize, ButtonProps, ButtonState, } from './components';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { assertSlots, slot, useARIAButtonProps } from './utilities';
2
- export { tokens, defaultTheme, themeToCSS } from './theme';
2
+ export { tokens, defaultTheme, themeToCSS, insertTheme } from './theme';
3
3
  export { Button, useButton, renderButton, useButtonStyles, buttonClassNames, } from './components';
@@ -1,4 +1,4 @@
1
1
  export { tokens } from './tokens';
2
2
  export { defaultTheme } from './defaultTheme';
3
- export { themeToCSS } from './themeToCSS';
3
+ export { themeToCSS, insertTheme } from './themeToCSS';
4
4
  export type { Theme } from './types';
@@ -1,3 +1,3 @@
1
1
  export { tokens } from './tokens';
2
2
  export { defaultTheme } from './defaultTheme';
3
- export { themeToCSS } from './themeToCSS';
3
+ export { themeToCSS, insertTheme } from './themeToCSS';
@@ -1,2 +1,3 @@
1
1
  import type { Theme } from './types';
2
2
  export declare function themeToCSS(theme: Theme): string;
3
+ export declare function insertTheme(theme: Theme): void;
@@ -1,5 +1,21 @@
1
+ let themeStyleElement = null;
1
2
  export function themeToCSS(theme) {
2
3
  return Object.keys(theme)
3
4
  .map((key) => `--${key}: ${theme[key]};`)
4
5
  .join(' ');
5
6
  }
7
+ export function insertTheme(theme) {
8
+ if (!themeStyleElement) {
9
+ themeStyleElement = document.createElement('style');
10
+ themeStyleElement.setAttribute('data-theme', 'default');
11
+ document.head.appendChild(themeStyleElement);
12
+ }
13
+ const rule = `:root { ${themeToCSS(theme)} }`;
14
+ const sheet = themeStyleElement.sheet;
15
+ if (sheet) {
16
+ while (sheet.cssRules.length > 0) {
17
+ sheet.deleteRule(0);
18
+ }
19
+ sheet.insertRule(rule, 0);
20
+ }
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "components-test-pb",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { assertSlots, slot, useARIAButtonProps } from './utilities';
2
2
 
3
- export { tokens, defaultTheme, themeToCSS } from './theme';
3
+ export { tokens, defaultTheme, themeToCSS, insertTheme } from './theme';
4
4
  export type { Theme } from './theme';
5
5
 
6
6
  export {
@@ -1,4 +1,4 @@
1
1
  export { tokens } from './tokens';
2
2
  export { defaultTheme } from './defaultTheme';
3
- export { themeToCSS } from './themeToCSS';
3
+ export { themeToCSS, insertTheme } from './themeToCSS';
4
4
  export type { Theme } from './types';
@@ -1,7 +1,27 @@
1
1
  import type { Theme } from './types';
2
2
 
3
+ let themeStyleElement: HTMLStyleElement | null = null;
4
+
3
5
  export function themeToCSS(theme: Theme): string {
4
6
  return (Object.keys(theme) as (keyof Theme)[])
5
7
  .map((key) => `--${key}: ${theme[key]};`)
6
8
  .join(' ');
7
9
  }
10
+
11
+ export function insertTheme(theme: Theme): void {
12
+ if (!themeStyleElement) {
13
+ themeStyleElement = document.createElement('style');
14
+ themeStyleElement.setAttribute('data-theme', 'default');
15
+ document.head.appendChild(themeStyleElement);
16
+ }
17
+
18
+ const rule = `:root { ${themeToCSS(theme)} }`;
19
+
20
+ const sheet = themeStyleElement.sheet;
21
+ if (sheet) {
22
+ while (sheet.cssRules.length > 0) {
23
+ sheet.deleteRule(0);
24
+ }
25
+ sheet.insertRule(rule, 0);
26
+ }
27
+ }