@griffel/react 1.0.0 → 1.0.3

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/README.md CHANGED
@@ -133,6 +133,40 @@ function App() {
133
133
  }
134
134
  ```
135
135
 
136
+ ## `createDOMRenderer()`, `RendererProvider`
137
+
138
+ `createDOMRenderer` is paired with `RendererProvider` component and is useful for child window rendering and SSR scenarios. This is the default renderer for web, and will make sure that styles are injected to a document.
139
+
140
+ ```jsx
141
+ import { createDOMRenderer, RendererProvider } from '@griffel/react';
142
+
143
+ function App(props) {
144
+ const { targetDocument } = props;
145
+ const renderer = React.useMemo(() => createDOMRenderer(targetDocument), [targetDocument]);
146
+
147
+ return (
148
+ <RendererProvider renderer={renderer} targetDocument={targetDocument}>
149
+ {/* Children components */}
150
+ {/* ... */}
151
+ </RendererProvider>
152
+ );
153
+ }
154
+ ```
155
+
156
+ ### styleElementAttributes
157
+
158
+ A map of attributes that's passed to the generated style elements. For example, is useful to set ["nonce" attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce).
159
+
160
+ ```js
161
+ import { createDOMRenderer } from '@griffel/react';
162
+
163
+ const renderer = createDOMRenderer(targetDocument, {
164
+ styleElementAttributes: {
165
+ nonce: 'random',
166
+ },
167
+ });
168
+ ```
169
+
136
170
  ## Features support
137
171
 
138
172
  ### 📃 pseudo & class selectors, at-rules, global styles
@@ -149,7 +183,7 @@ const useClasses = makeStyles({
149
183
  // :link, :focus, etc.
150
184
 
151
185
  '.foo': { color: 'black' },
152
- ':nth-child(2n)': { background: '#fafafa' },
186
+ ':nth-child(2n)': { backgroundColor: '#fafafa' },
153
187
 
154
188
  '@media screen and (max-width: 992px)': { color: 'orange' },
155
189
  '@supports (display: grid)': { color: 'red' },
@@ -164,8 +198,8 @@ import { makeStyles } from '@griffel/react';
164
198
 
165
199
  const useClasses = makeStyles({
166
200
  root: {
167
- ':global(html[data-whatintent="mouse"])': { background: 'yellow' },
168
- // outputs: html[data-whatintent="mouse"] .abcd { background: yellow }
201
+ ':global(html[data-whatintent="mouse"])': { backgroundColor: 'yellow' },
202
+ // outputs: html[data-whatintent="mouse"] .abcd { background-color: yellow }
169
203
  },
170
204
  });
171
205
  ```
@@ -202,3 +236,18 @@ const useClasses = makeStyles({
202
236
  },
203
237
  });
204
238
  ```
239
+
240
+ ### CSS Fallback Properties
241
+
242
+ Any CSS property accepts an array of values which are all added to the styles.
243
+ Every browser will use the latest valid value (which might be a different one in different browsers, based on supported CSS in that browser):
244
+
245
+ ```js
246
+ import { makeStyles } from '@griffel/react';
247
+
248
+ const useClasses = makeStyles({
249
+ root: {
250
+ overflowY: ['scroll', 'overlay'],
251
+ },
252
+ });
253
+ ```
@@ -5,20 +5,39 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@griffel/core');
6
6
  var React = require('react');
7
7
 
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n["default"] = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
+
8
28
  /**
9
29
  * Verifies if an application can use DOM.
10
30
  */
11
31
 
12
32
  function canUseDOM() {
13
- return typeof window !== 'undefined' && !!(window.document && // eslint-disable-next-line deprecation/deprecation
14
- window.document.createElement);
33
+ return typeof window !== 'undefined' && !!(window.document && window.document.createElement);
15
34
  }
16
35
  /**
17
36
  * @private
18
37
  */
19
38
 
20
39
 
21
- const RendererContext = /*#__PURE__*/React.createContext( /*#__PURE__*/core.createDOMRenderer());
40
+ const RendererContext = /*#__PURE__*/React__namespace.createContext( /*#__PURE__*/core.createDOMRenderer());
22
41
  /**
23
42
  * @public
24
43
  */
@@ -32,14 +51,14 @@ const RendererProvider = ({
32
51
  // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
33
52
  // mounting.
34
53
  // eslint-disable-next-line react-hooks/rules-of-hooks
35
- React.useMemo(() => {
54
+ React__namespace.useMemo(() => {
36
55
  // "rehydrateCache()" can't be called in effects as it needs to be called before any component will be rendered to
37
56
  // avoid double insertion of classes
38
57
  core.rehydrateRendererCache(renderer, targetDocument);
39
58
  }, [renderer, targetDocument]);
40
59
  }
41
60
 
42
- return /*#__PURE__*/React.createElement(RendererContext.Provider, {
61
+ return /*#__PURE__*/React__namespace.createElement(RendererContext.Provider, {
43
62
  value: renderer
44
63
  }, children);
45
64
  };
@@ -50,8 +69,9 @@ const RendererProvider = ({
50
69
  */
51
70
 
52
71
  function useRenderer() {
53
- return React.useContext(RendererContext);
72
+ return React__namespace.useContext(RendererContext);
54
73
  }
55
74
 
56
75
  exports.RendererProvider = RendererProvider;
57
76
  exports.useRenderer = useRenderer;
77
+ //# sourceMappingURL=RendererContext.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RendererContext.cjs.js","sources":["../../../packages/react/src/RendererContext.tsx"],"sourcesContent":["import { createDOMRenderer, rehydrateRendererCache } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer } from '@griffel/core';\n\nexport interface RendererProviderProps {\n /** An instance of Griffel renderer. */\n renderer: GriffelRenderer;\n\n /**\n * Document used to insert CSS variables to head\n */\n targetDocument?: Document;\n}\n\n/**\n * Verifies if an application can use DOM.\n */\nfunction canUseDOM(): boolean {\n return typeof window !== 'undefined' && !!(window.document && window.document.createElement);\n}\n\n/**\n * @private\n */\nconst RendererContext = React.createContext<GriffelRenderer>(createDOMRenderer());\n\n/**\n * @public\n */\nexport const RendererProvider: React.FC<RendererProviderProps> = ({ children, renderer, targetDocument }) => {\n if (canUseDOM()) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useMemo(() => {\n // \"rehydrateCache()\" can't be called in effects as it needs to be called before any component will be rendered to\n // avoid double insertion of classes\n rehydrateRendererCache(renderer, targetDocument);\n }, [renderer, targetDocument]);\n }\n\n return <RendererContext.Provider value={renderer}>{children}</RendererContext.Provider>;\n};\n\n/**\n * Returns an instance of current makeStyles() renderer.\n *\n * @private\n */\nexport function useRenderer(): GriffelRenderer {\n return React.useContext(RendererContext);\n}\n"],"names":["canUseDOM","window","document","createElement","RendererContext","React","createContext","createDOMRenderer","RendererProvider","children","renderer","targetDocument","useMemo","rehydrateRendererCache","Provider","value","useRenderer","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;AAGA,SAASA,SAAT;AACE,SAAO,OAAOC,MAAP,KAAkB,WAAlB,IAAiC,CAAC,EAAEA,MAAM,CAACC,QAAP,IAAmBD,MAAM,CAACC,QAAP,CAAgBC,aAArC,CAAzC;AACD;AAED;;;;;AAGA,MAAMC,eAAe,gBAAGC,gBAAK,CAACC,aAAN,eAAqCC,sBAAiB,EAAtD,CAAxB;AAEA;;;;MAGaC,gBAAgB,GAAoC,CAAC;AAAEC,EAAAA,QAAF;AAAYC,EAAAA,QAAZ;AAAsBC,EAAAA;AAAtB,CAAD;AAC/D,MAAIX,SAAS,EAAb,EAAiB;AACf;AACA;AACA;AACAK,IAAAA,gBAAK,CAACO,OAAN,CAAc;AACZ;AACA;AACAC,MAAAA,2BAAsB,CAACH,QAAD,EAAWC,cAAX,CAAtB;AACD,KAJD,EAIG,CAACD,QAAD,EAAWC,cAAX,CAJH;AAKD;;AAED,sBAAON,8BAAA,CAACD,eAAe,CAACU,QAAjB;AAA0BC,IAAAA,KAAK,EAAEL;GAAjC,EAA4CD,QAA5C,CAAP;AACD;AAED;;;;;;SAKgBO;AACd,SAAOX,gBAAK,CAACY,UAAN,CAAiBb,eAAjB,CAAP;AACD;;;;;"}
@@ -6,8 +6,7 @@ import * as React from 'react';
6
6
  */
7
7
 
8
8
  function canUseDOM() {
9
- return typeof window !== 'undefined' && !!(window.document && // eslint-disable-next-line deprecation/deprecation
10
- window.document.createElement);
9
+ return typeof window !== 'undefined' && !!(window.document && window.document.createElement);
11
10
  }
12
11
  /**
13
12
  * @private
@@ -50,3 +49,4 @@ function useRenderer() {
50
49
  }
51
50
 
52
51
  export { RendererProvider, useRenderer };
52
+ //# sourceMappingURL=RendererContext.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RendererContext.esm.js","sources":["../../../packages/react/src/RendererContext.tsx"],"sourcesContent":["import { createDOMRenderer, rehydrateRendererCache } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer } from '@griffel/core';\n\nexport interface RendererProviderProps {\n /** An instance of Griffel renderer. */\n renderer: GriffelRenderer;\n\n /**\n * Document used to insert CSS variables to head\n */\n targetDocument?: Document;\n}\n\n/**\n * Verifies if an application can use DOM.\n */\nfunction canUseDOM(): boolean {\n return typeof window !== 'undefined' && !!(window.document && window.document.createElement);\n}\n\n/**\n * @private\n */\nconst RendererContext = React.createContext<GriffelRenderer>(createDOMRenderer());\n\n/**\n * @public\n */\nexport const RendererProvider: React.FC<RendererProviderProps> = ({ children, renderer, targetDocument }) => {\n if (canUseDOM()) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useMemo(() => {\n // \"rehydrateCache()\" can't be called in effects as it needs to be called before any component will be rendered to\n // avoid double insertion of classes\n rehydrateRendererCache(renderer, targetDocument);\n }, [renderer, targetDocument]);\n }\n\n return <RendererContext.Provider value={renderer}>{children}</RendererContext.Provider>;\n};\n\n/**\n * Returns an instance of current makeStyles() renderer.\n *\n * @private\n */\nexport function useRenderer(): GriffelRenderer {\n return React.useContext(RendererContext);\n}\n"],"names":["canUseDOM","window","document","createElement","RendererContext","React","createContext","createDOMRenderer","RendererProvider","children","renderer","targetDocument","useMemo","rehydrateRendererCache","Provider","value","useRenderer","useContext"],"mappings":";;;AAcA;;;;AAGA,SAASA,SAAT;AACE,SAAO,OAAOC,MAAP,KAAkB,WAAlB,IAAiC,CAAC,EAAEA,MAAM,CAACC,QAAP,IAAmBD,MAAM,CAACC,QAAP,CAAgBC,aAArC,CAAzC;AACD;AAED;;;;;AAGA,MAAMC,eAAe,gBAAGC,KAAK,CAACC,aAAN,eAAqCC,iBAAiB,EAAtD,CAAxB;AAEA;;;;MAGaC,gBAAgB,GAAoC,CAAC;AAAEC,EAAAA,QAAF;AAAYC,EAAAA,QAAZ;AAAsBC,EAAAA;AAAtB,CAAD;AAC/D,MAAIX,SAAS,EAAb,EAAiB;AACf;AACA;AACA;AACAK,IAAAA,KAAK,CAACO,OAAN,CAAc;AACZ;AACA;AACAC,MAAAA,sBAAsB,CAACH,QAAD,EAAWC,cAAX,CAAtB;AACD,KAJD,EAIG,CAACD,QAAD,EAAWC,cAAX,CAJH;AAKD;;AAED,sBAAON,mBAAA,CAACD,eAAe,CAACU,QAAjB;AAA0BC,IAAAA,KAAK,EAAEL;GAAjC,EAA4CD,QAA5C,CAAP;AACD;AAED;;;;;;SAKgBO;AACd,SAAOX,KAAK,CAACY,UAAN,CAAiBb,eAAjB,CAAP;AACD;;;;"}
@@ -4,11 +4,31 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
 
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
+
7
27
  /**
8
28
  * @private
9
29
  */
10
30
 
11
- const TextDirectionContext = /*#__PURE__*/React.createContext('ltr');
31
+ const TextDirectionContext = /*#__PURE__*/React__namespace.createContext('ltr');
12
32
  /**
13
33
  * @public
14
34
  */
@@ -17,7 +37,7 @@ const TextDirectionProvider = ({
17
37
  children,
18
38
  dir
19
39
  }) => {
20
- return /*#__PURE__*/React.createElement(TextDirectionContext.Provider, {
40
+ return /*#__PURE__*/React__namespace.createElement(TextDirectionContext.Provider, {
21
41
  value: dir
22
42
  }, children);
23
43
  };
@@ -28,8 +48,9 @@ const TextDirectionProvider = ({
28
48
  */
29
49
 
30
50
  function useTextDirection() {
31
- return React.useContext(TextDirectionContext);
51
+ return React__namespace.useContext(TextDirectionContext);
32
52
  }
33
53
 
34
54
  exports.TextDirectionProvider = TextDirectionProvider;
35
55
  exports.useTextDirection = useTextDirection;
56
+ //# sourceMappingURL=TextDirectionContext.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextDirectionContext.cjs.js","sources":["../../../packages/react/src/TextDirectionContext.tsx"],"sourcesContent":["import * as React from 'react';\n\nexport interface TextDirectionProviderProps {\n /** Indicates the directionality of the element's text. */\n dir: 'ltr' | 'rtl';\n}\n\n/**\n * @private\n */\nconst TextDirectionContext = React.createContext<'ltr' | 'rtl'>('ltr');\n\n/**\n * @public\n */\nexport const TextDirectionProvider: React.FC<TextDirectionProviderProps> = ({ children, dir }) => {\n return <TextDirectionContext.Provider value={dir}>{children}</TextDirectionContext.Provider>;\n};\n\n/**\n * Returns current directionality of the element's text.\n *\n * @private\n */\nexport function useTextDirection() {\n return React.useContext(TextDirectionContext);\n}\n"],"names":["TextDirectionContext","React","createContext","TextDirectionProvider","children","dir","Provider","value","useTextDirection","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;;;AAGA,MAAMA,oBAAoB,gBAAGC,gBAAK,CAACC,aAAN,CAAmC,KAAnC,CAA7B;AAEA;;;;MAGaC,qBAAqB,GAAyC,CAAC;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAD;AACzE,sBAAOJ,8BAAA,CAACD,oBAAoB,CAACM,QAAtB;AAA+BC,IAAAA,KAAK,EAAEF;GAAtC,EAA4CD,QAA5C,CAAP;AACD;AAED;;;;;;SAKgBI;AACd,SAAOP,gBAAK,CAACQ,UAAN,CAAiBT,oBAAjB,CAAP;AACD;;;;;"}
@@ -28,3 +28,4 @@ function useTextDirection() {
28
28
  }
29
29
 
30
30
  export { TextDirectionProvider, useTextDirection };
31
+ //# sourceMappingURL=TextDirectionContext.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextDirectionContext.esm.js","sources":["../../../packages/react/src/TextDirectionContext.tsx"],"sourcesContent":["import * as React from 'react';\n\nexport interface TextDirectionProviderProps {\n /** Indicates the directionality of the element's text. */\n dir: 'ltr' | 'rtl';\n}\n\n/**\n * @private\n */\nconst TextDirectionContext = React.createContext<'ltr' | 'rtl'>('ltr');\n\n/**\n * @public\n */\nexport const TextDirectionProvider: React.FC<TextDirectionProviderProps> = ({ children, dir }) => {\n return <TextDirectionContext.Provider value={dir}>{children}</TextDirectionContext.Provider>;\n};\n\n/**\n * Returns current directionality of the element's text.\n *\n * @private\n */\nexport function useTextDirection() {\n return React.useContext(TextDirectionContext);\n}\n"],"names":["TextDirectionContext","React","createContext","TextDirectionProvider","children","dir","Provider","value","useTextDirection","useContext"],"mappings":";;AAOA;;;;AAGA,MAAMA,oBAAoB,gBAAGC,KAAK,CAACC,aAAN,CAAmC,KAAnC,CAA7B;AAEA;;;;MAGaC,qBAAqB,GAAyC,CAAC;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAD;AACzE,sBAAOJ,mBAAA,CAACD,oBAAoB,CAACM,QAAtB;AAA+BC,IAAAA,KAAK,EAAEF;GAAtC,EAA4CD,QAA5C,CAAP;AACD;AAED;;;;;;SAKgBI;AACd,SAAOP,KAAK,CAACQ,UAAN,CAAiBT,oBAAjB,CAAP;AACD;;;;"}
package/__styles.cjs.js CHANGED
@@ -26,3 +26,4 @@ function __styles(classesMapBySlot, cssRules) {
26
26
  }
27
27
 
28
28
  exports.__styles = __styles;
29
+ //# sourceMappingURL=__styles.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__styles.cjs.js","sources":["../../../packages/react/src/__styles.ts"],"sourcesContent":["import { __styles as vanillaStyles } from '@griffel/core';\nimport type { CSSClassesMapBySlot, CSSRulesByBucket } from '@griffel/core';\n\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\n/**\n * A version of makeStyles() that accepts build output as an input and skips all runtime transforms.\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function __styles<Slots extends string>(\n classesMapBySlot: CSSClassesMapBySlot<Slots>,\n cssRules: CSSRulesByBucket,\n) {\n const getStyles = vanillaStyles(classesMapBySlot, cssRules);\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["__styles","classesMapBySlot","cssRules","getStyles","vanillaStyles","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;;;;AAMA;;;;;AAKA;;SACgBA,SACdC,kBACAC;AAEA,QAAMC,SAAS,GAAGC,aAAa,CAACH,gBAAD,EAAmBC,QAAnB,CAA/B;AAEA,SAAO,SAASG,UAAT;AACL,UAAMC,GAAG,GAAGC,qCAAgB,EAA5B;AACA,UAAMC,QAAQ,GAAGC,2BAAW,EAA5B;AAEA,WAAON,SAAS,CAAC;AAAEG,MAAAA,GAAF;AAAOE,MAAAA;AAAP,KAAD,CAAhB;AACD,GALD;AAMD;;;;"}
package/__styles.esm.js CHANGED
@@ -22,3 +22,4 @@ function __styles(classesMapBySlot, cssRules) {
22
22
  }
23
23
 
24
24
  export { __styles };
25
+ //# sourceMappingURL=__styles.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__styles.esm.js","sources":["../../../packages/react/src/__styles.ts"],"sourcesContent":["import { __styles as vanillaStyles } from '@griffel/core';\nimport type { CSSClassesMapBySlot, CSSRulesByBucket } from '@griffel/core';\n\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\n/**\n * A version of makeStyles() that accepts build output as an input and skips all runtime transforms.\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function __styles<Slots extends string>(\n classesMapBySlot: CSSClassesMapBySlot<Slots>,\n cssRules: CSSRulesByBucket,\n) {\n const getStyles = vanillaStyles(classesMapBySlot, cssRules);\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["__styles","classesMapBySlot","cssRules","getStyles","vanillaStyles","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;AAMA;;;;;AAKA;;SACgBA,SACdC,kBACAC;AAEA,QAAMC,SAAS,GAAGC,UAAa,CAACH,gBAAD,EAAmBC,QAAnB,CAA/B;AAEA,SAAO,SAASG,UAAT;AACL,UAAMC,GAAG,GAAGC,gBAAgB,EAA5B;AACA,UAAMC,QAAQ,GAAGC,WAAW,EAA5B;AAEA,WAAON,SAAS,CAAC;AAAEG,MAAAA,GAAF;AAAOE,MAAAA;AAAP,KAAD,CAAhB;AACD,GALD;AAMD;;;;"}
package/index.cjs.js CHANGED
@@ -30,3 +30,4 @@ exports.renderToStyleElements = renderToStyleElements.renderToStyleElements;
30
30
  exports.RendererProvider = RendererContext.RendererProvider;
31
31
  exports.TextDirectionProvider = TextDirectionContext.TextDirectionProvider;
32
32
  exports.__styles = __styles.__styles;
33
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/index.esm.js CHANGED
@@ -5,3 +5,4 @@ export { renderToStyleElements } from './renderToStyleElements.esm.js';
5
5
  export { RendererProvider } from './RendererContext.esm.js';
6
6
  export { TextDirectionProvider } from './TextDirectionContext.esm.js';
7
7
  export { __styles } from './__styles.esm.js';
8
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -23,3 +23,4 @@ function makeStaticStyles(styles) {
23
23
  }
24
24
 
25
25
  exports.makeStaticStyles = makeStaticStyles;
26
+ //# sourceMappingURL=makeStaticStyles.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeStaticStyles.cjs.js","sources":["../../../packages/react/src/makeStaticStyles.ts"],"sourcesContent":["import { makeStaticStyles as vanillaMakeStaticStyles } from '@griffel/core';\n\nimport { useRenderer } from './RendererContext';\nimport type { GriffelStaticStyles, MakeStaticStylesOptions } from '@griffel/core';\n\nexport function makeStaticStyles(styles: GriffelStaticStyles | GriffelStaticStyles[]) {\n const getStyles = vanillaMakeStaticStyles(styles);\n\n if (process.env.NODE_ENV === 'test') {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n return function useStaticStyles(): void {\n const renderer = useRenderer();\n const options: MakeStaticStylesOptions = { renderer };\n\n return getStyles(options);\n };\n}\n"],"names":["makeStaticStyles","styles","getStyles","vanillaMakeStaticStyles","process","env","NODE_ENV","useStaticStyles","renderer","useRenderer","options"],"mappings":";;;;;;;SAKgBA,iBAAiBC;AAC/B,QAAMC,SAAS,GAAGC,qBAAuB,CAACF,MAAD,CAAzC;;AAEA,MAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC;AACnC;AACA,WAAO,QAAP;AACD;;AAED,SAAO,SAASC,eAAT;AACL,UAAMC,QAAQ,GAAGC,2BAAW,EAA5B;AACA,UAAMC,OAAO,GAA4B;AAAEF,MAAAA;AAAF,KAAzC;AAEA,WAAON,SAAS,CAACQ,OAAD,CAAhB;AACD,GALD;AAMD;;;;"}
@@ -1,2 +1,2 @@
1
1
  import type { GriffelStaticStyles } from '@griffel/core';
2
- export declare function makeStaticStyles<Selectors>(styles: GriffelStaticStyles | GriffelStaticStyles[]): () => void;
2
+ export declare function makeStaticStyles(styles: GriffelStaticStyles | GriffelStaticStyles[]): () => void;
@@ -19,3 +19,4 @@ function makeStaticStyles(styles) {
19
19
  }
20
20
 
21
21
  export { makeStaticStyles };
22
+ //# sourceMappingURL=makeStaticStyles.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeStaticStyles.esm.js","sources":["../../../packages/react/src/makeStaticStyles.ts"],"sourcesContent":["import { makeStaticStyles as vanillaMakeStaticStyles } from '@griffel/core';\n\nimport { useRenderer } from './RendererContext';\nimport type { GriffelStaticStyles, MakeStaticStylesOptions } from '@griffel/core';\n\nexport function makeStaticStyles(styles: GriffelStaticStyles | GriffelStaticStyles[]) {\n const getStyles = vanillaMakeStaticStyles(styles);\n\n if (process.env.NODE_ENV === 'test') {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n return function useStaticStyles(): void {\n const renderer = useRenderer();\n const options: MakeStaticStylesOptions = { renderer };\n\n return getStyles(options);\n };\n}\n"],"names":["makeStaticStyles","styles","getStyles","vanillaMakeStaticStyles","process","env","NODE_ENV","useStaticStyles","renderer","useRenderer","options"],"mappings":";;;SAKgBA,iBAAiBC;AAC/B,QAAMC,SAAS,GAAGC,kBAAuB,CAACF,MAAD,CAAzC;;AAEA,MAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA7B,EAAqC;AACnC;AACA,WAAO,QAAP;AACD;;AAED,SAAO,SAASC,eAAT;AACL,UAAMC,QAAQ,GAAGC,WAAW,EAA5B;AACA,UAAMC,OAAO,GAA4B;AAAEF,MAAAA;AAAF,KAAzC;AAEA,WAAON,SAAS,CAACQ,OAAD,CAAhB;AACD,GALD;AAMD;;;;"}
package/makeStyles.cjs.js CHANGED
@@ -7,10 +7,30 @@ var React = require('react');
7
7
  var RendererContext = require('./RendererContext.cjs.js');
8
8
  var TextDirectionContext = require('./TextDirectionContext.cjs.js');
9
9
 
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n["default"] = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
+
10
30
  function isInsideComponent() {
11
31
  try {
12
32
  // eslint-disable-next-line react-hooks/rules-of-hooks
13
- React.useContext({});
33
+ React__namespace.useContext({});
14
34
  return true;
15
35
  } catch (e) {
16
36
  return false;
@@ -37,3 +57,4 @@ function makeStyles(stylesBySlots) {
37
57
  }
38
58
 
39
59
  exports.makeStyles = makeStyles;
60
+ //# sourceMappingURL=makeStyles.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeStyles.cjs.js","sources":["../../../packages/react/src/makeStyles.ts"],"sourcesContent":["import { makeStyles as vanillaMakeStyles } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelStyle } from '@griffel/core';\n\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\nfunction isInsideComponent() {\n try {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useContext({} as unknown as React.Context<unknown>);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nexport function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>) {\n const getStyles = vanillaMakeStyles(stylesBySlots);\n\n if (process.env.NODE_ENV !== 'production') {\n if (isInsideComponent()) {\n throw new Error(\n [\n \"makeStyles(): this function cannot be called in component's scope.\",\n 'All makeStyles() calls should be top level i.e. in a root scope of a file.',\n ].join(' '),\n );\n }\n }\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["isInsideComponent","React","useContext","e","makeStyles","stylesBySlots","getStyles","vanillaMakeStyles","process","env","NODE_ENV","Error","join","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAASA,iBAAT;AACE,MAAI;AACF;AACAC,IAAAA,gBAAK,CAACC,UAAN,CAAiB,EAAjB;AACA,WAAO,IAAP;AACD,GAJD,CAIE,OAAOC,CAAP,EAAU;AACV,WAAO,KAAP;AACD;AACF;;SAEeC,WAA0CC;AACxD,QAAMC,SAAS,GAAGC,eAAiB,CAACF,aAAD,CAAnC;;AAEA,MAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QAAIV,iBAAiB,EAArB,EAAyB;AACvB,YAAM,IAAIW,KAAJ,CACJ,CACE,oEADF,EAEE,4EAFF,EAGEC,IAHF,CAGO,GAHP,CADI,CAAN;AAMD;AACF;;AAED,SAAO,SAASC,UAAT;AACL,UAAMC,GAAG,GAAGC,qCAAgB,EAA5B;AACA,UAAMC,QAAQ,GAAGC,2BAAW,EAA5B;AAEA,WAAOX,SAAS,CAAC;AAAEQ,MAAAA,GAAF;AAAOE,MAAAA;AAAP,KAAD,CAAhB;AACD,GALD;AAMD;;;;"}
package/makeStyles.esm.js CHANGED
@@ -33,3 +33,4 @@ function makeStyles(stylesBySlots) {
33
33
  }
34
34
 
35
35
  export { makeStyles };
36
+ //# sourceMappingURL=makeStyles.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeStyles.esm.js","sources":["../../../packages/react/src/makeStyles.ts"],"sourcesContent":["import { makeStyles as vanillaMakeStyles } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelStyle } from '@griffel/core';\n\nimport { useRenderer } from './RendererContext';\nimport { useTextDirection } from './TextDirectionContext';\n\nfunction isInsideComponent() {\n try {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useContext({} as unknown as React.Context<unknown>);\n return true;\n } catch (e) {\n return false;\n }\n}\n\nexport function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>) {\n const getStyles = vanillaMakeStyles(stylesBySlots);\n\n if (process.env.NODE_ENV !== 'production') {\n if (isInsideComponent()) {\n throw new Error(\n [\n \"makeStyles(): this function cannot be called in component's scope.\",\n 'All makeStyles() calls should be top level i.e. in a root scope of a file.',\n ].join(' '),\n );\n }\n }\n\n return function useClasses(): Record<Slots, string> {\n const dir = useTextDirection();\n const renderer = useRenderer();\n\n return getStyles({ dir, renderer });\n };\n}\n"],"names":["isInsideComponent","React","useContext","e","makeStyles","stylesBySlots","getStyles","vanillaMakeStyles","process","env","NODE_ENV","Error","join","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;AAOA,SAASA,iBAAT;AACE,MAAI;AACF;AACAC,IAAAA,KAAK,CAACC,UAAN,CAAiB,EAAjB;AACA,WAAO,IAAP;AACD,GAJD,CAIE,OAAOC,CAAP,EAAU;AACV,WAAO,KAAP;AACD;AACF;;SAEeC,WAA0CC;AACxD,QAAMC,SAAS,GAAGC,YAAiB,CAACF,aAAD,CAAnC;;AAEA,MAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QAAIV,iBAAiB,EAArB,EAAyB;AACvB,YAAM,IAAIW,KAAJ,CACJ,CACE,oEADF,EAEE,4EAFF,EAGEC,IAHF,CAGO,GAHP,CADI,CAAN;AAMD;AACF;;AAED,SAAO,SAASC,UAAT;AACL,UAAMC,GAAG,GAAGC,gBAAgB,EAA5B;AACA,UAAMC,QAAQ,GAAGC,WAAW,EAA5B;AAEA,WAAOX,SAAS,CAAC;AAAEQ,MAAAA,GAAF;AAAOE,MAAAA;AAAP,KAAD,CAAhB;AACD,GALD;AAMD;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@griffel/react",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "React implementation of Atomic CSS-in-JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,13 +8,14 @@
8
8
  "url": "https://github.com/microsoft/griffel"
9
9
  },
10
10
  "sideEffects": false,
11
+ "dependencies": {
12
+ "@griffel/core": "^1.2.0",
13
+ "tslib": "^2.1.0"
14
+ },
11
15
  "peerDependencies": {
12
16
  "react": ">=16.8.0 <18.0.0"
13
17
  },
14
18
  "main": "./index.cjs.js",
15
19
  "module": "./index.esm.js",
16
- "typings": "./index.d.ts",
17
- "dependencies": {
18
- "@griffel/core": "1.0.7"
19
- }
20
- }
20
+ "typings": "./index.d.ts"
21
+ }
@@ -5,6 +5,26 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@griffel/core');
6
6
  var React = require('react');
7
7
 
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n["default"] = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
+
8
28
  /**
9
29
  * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.
10
30
  *
@@ -30,7 +50,7 @@ function renderToStyleElements(renderer) {
30
50
  return null;
31
51
  }
32
52
 
33
- return /*#__PURE__*/React.createElement('style', {
53
+ return /*#__PURE__*/React__namespace.createElement('style', {
34
54
  key: bucketName,
35
55
  // TODO: support "nonce"
36
56
  // ...renderer.styleNodeAttributes,
@@ -44,3 +64,4 @@ function renderToStyleElements(renderer) {
44
64
  }
45
65
 
46
66
  exports.renderToStyleElements = renderToStyleElements;
67
+ //# sourceMappingURL=renderToStyleElements.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderToStyleElements.cjs.js","sources":["../../../packages/react/src/renderToStyleElements.ts"],"sourcesContent":["import { styleBucketOrdering } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer, StyleBucketName } from '@griffel/core';\n\ntype CSSRulesGroupedByStyleBucket = Record<StyleBucketName, string[]>;\n\n/**\n * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.\n *\n * @public\n */\nexport function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {\n const styles = styleBucketOrdering.reduce<CSSRulesGroupedByStyleBucket>((acc, bucketName) => {\n return { ...acc, [bucketName]: [] };\n }, {} as CSSRulesGroupedByStyleBucket);\n\n // eslint-disable-next-line guard-for-in\n for (const cssRule in renderer.insertionCache) {\n const bucketName: StyleBucketName = renderer.insertionCache[cssRule];\n\n styles[bucketName].push(cssRule);\n }\n\n return (Object.keys(styles) as StyleBucketName[])\n .map(bucketName => {\n const cssRules = styles[bucketName].join('');\n\n // We don't want to create empty style elements\n if (cssRules.length === 0) {\n return null;\n }\n\n return React.createElement('style', {\n key: bucketName,\n\n // TODO: support \"nonce\"\n // ...renderer.styleNodeAttributes,\n\n 'data-make-styles-bucket': bucketName || 'default',\n 'data-make-styles-rehydration': true,\n\n dangerouslySetInnerHTML: {\n __html: cssRules,\n },\n });\n })\n .filter(Boolean) as React.ReactElement[];\n}\n"],"names":["renderToStyleElements","renderer","styles","styleBucketOrdering","reduce","acc","bucketName","cssRule","insertionCache","push","Object","keys","map","cssRules","join","length","React","createElement","key","dangerouslySetInnerHTML","__html","filter","Boolean"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;;;;;;SAKgBA,sBAAsBC;AACpC,QAAMC,MAAM,GAAGC,wBAAmB,CAACC,MAApB,CAAyD,CAACC,GAAD,EAAMC,UAAN;AACtE,2CAAYD;AAAK,OAACC,UAAD,GAAc;MAA/B;AACD,GAFc,EAEZ,EAFY,CAAf;;AAKA,OAAK,MAAMC,OAAX,IAAsBN,QAAQ,CAACO,cAA/B,EAA+C;AAC7C,UAAMF,UAAU,GAAoBL,QAAQ,CAACO,cAAT,CAAwBD,OAAxB,CAApC;AAEAL,IAAAA,MAAM,CAACI,UAAD,CAAN,CAAmBG,IAAnB,CAAwBF,OAAxB;AACD;;AAED,SAAQG,MAAM,CAACC,IAAP,CAAYT,MAAZ,EACLU,GADK,CACDN,UAAU;AACb,UAAMO,QAAQ,GAAGX,MAAM,CAACI,UAAD,CAAN,CAAmBQ,IAAnB,CAAwB,EAAxB,CAAjB;;AAGA,QAAID,QAAQ,CAACE,MAAT,KAAoB,CAAxB,EAA2B;AACzB,aAAO,IAAP;AACD;;AAED,wBAAOC,gBAAK,CAACC,aAAN,CAAoB,OAApB,EAA6B;AAClCC,MAAAA,GAAG,EAAEZ,UAD6B;AAGlC;AACA;AAEA,iCAA2BA,UAAU,IAAI,SANP;AAOlC,sCAAgC,IAPE;AASlCa,MAAAA,uBAAuB,EAAE;AACvBC,QAAAA,MAAM,EAAEP;AADe;AATS,KAA7B,CAAP;AAaD,GAtBK,EAuBLQ,MAvBK,CAuBEC,OAvBF,CAAR;AAwBD;;;;"}
@@ -40,3 +40,4 @@ function renderToStyleElements(renderer) {
40
40
  }
41
41
 
42
42
  export { renderToStyleElements };
43
+ //# sourceMappingURL=renderToStyleElements.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderToStyleElements.esm.js","sources":["../../../packages/react/src/renderToStyleElements.ts"],"sourcesContent":["import { styleBucketOrdering } from '@griffel/core';\nimport * as React from 'react';\nimport type { GriffelRenderer, StyleBucketName } from '@griffel/core';\n\ntype CSSRulesGroupedByStyleBucket = Record<StyleBucketName, string[]>;\n\n/**\n * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.\n *\n * @public\n */\nexport function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[] {\n const styles = styleBucketOrdering.reduce<CSSRulesGroupedByStyleBucket>((acc, bucketName) => {\n return { ...acc, [bucketName]: [] };\n }, {} as CSSRulesGroupedByStyleBucket);\n\n // eslint-disable-next-line guard-for-in\n for (const cssRule in renderer.insertionCache) {\n const bucketName: StyleBucketName = renderer.insertionCache[cssRule];\n\n styles[bucketName].push(cssRule);\n }\n\n return (Object.keys(styles) as StyleBucketName[])\n .map(bucketName => {\n const cssRules = styles[bucketName].join('');\n\n // We don't want to create empty style elements\n if (cssRules.length === 0) {\n return null;\n }\n\n return React.createElement('style', {\n key: bucketName,\n\n // TODO: support \"nonce\"\n // ...renderer.styleNodeAttributes,\n\n 'data-make-styles-bucket': bucketName || 'default',\n 'data-make-styles-rehydration': true,\n\n dangerouslySetInnerHTML: {\n __html: cssRules,\n },\n });\n })\n .filter(Boolean) as React.ReactElement[];\n}\n"],"names":["renderToStyleElements","renderer","styles","styleBucketOrdering","reduce","acc","bucketName","cssRule","insertionCache","push","Object","keys","map","cssRules","join","length","React","createElement","key","dangerouslySetInnerHTML","__html","filter","Boolean"],"mappings":";;;AAMA;;;;;;SAKgBA,sBAAsBC;AACpC,QAAMC,MAAM,GAAGC,mBAAmB,CAACC,MAApB,CAAyD,CAACC,GAAD,EAAMC,UAAN;AACtE,2CAAYD;AAAK,OAACC,UAAD,GAAc;MAA/B;AACD,GAFc,EAEZ,EAFY,CAAf;;AAKA,OAAK,MAAMC,OAAX,IAAsBN,QAAQ,CAACO,cAA/B,EAA+C;AAC7C,UAAMF,UAAU,GAAoBL,QAAQ,CAACO,cAAT,CAAwBD,OAAxB,CAApC;AAEAL,IAAAA,MAAM,CAACI,UAAD,CAAN,CAAmBG,IAAnB,CAAwBF,OAAxB;AACD;;AAED,SAAQG,MAAM,CAACC,IAAP,CAAYT,MAAZ,EACLU,GADK,CACDN,UAAU;AACb,UAAMO,QAAQ,GAAGX,MAAM,CAACI,UAAD,CAAN,CAAmBQ,IAAnB,CAAwB,EAAxB,CAAjB;;AAGA,QAAID,QAAQ,CAACE,MAAT,KAAoB,CAAxB,EAA2B;AACzB,aAAO,IAAP;AACD;;AAED,wBAAOC,KAAK,CAACC,aAAN,CAAoB,OAApB,EAA6B;AAClCC,MAAAA,GAAG,EAAEZ,UAD6B;AAGlC;AACA;AAEA,iCAA2BA,UAAU,IAAI,SANP;AAOlC,sCAAgC,IAPE;AASlCa,MAAAA,uBAAuB,EAAE;AACvBC,QAAAA,MAAM,EAAEP;AADe;AATS,KAA7B,CAAP;AAaD,GAtBK,EAuBLQ,MAvBK,CAuBEC,OAvBF,CAAR;AAwBD;;;;"}