@griffel/react 1.0.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # Griffel for React
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ npm install @griffel/react
7
+ # or
8
+ yarn add @griffel/react
9
+ ```
10
+
11
+ ## API
12
+
13
+ ### `makeStyles()`
14
+
15
+ Is used to define styles, returns a React hook that should be called inside a component:
16
+
17
+ ```tsx
18
+ import { makeStyles } from '@griffel/react';
19
+
20
+ const useClasses = makeStyles({
21
+ button: { color: 'red' },
22
+ icon: { paddingLeft: '5px' },
23
+ });
24
+
25
+ function Component() {
26
+ const classes = useClasses();
27
+
28
+ return (
29
+ <div>
30
+ <button className={classes.button} />
31
+ <span className={classes.icon} />
32
+ </div>
33
+ );
34
+ }
35
+ ```
36
+
37
+ ### `mergeClasses()`
38
+
39
+ > 💡 **It is not possible to simply concatenate classes returned by `useClasses()`.**
40
+
41
+ There are cases where you need to merge classes from multiple `useClasses` calls.
42
+
43
+ To properly merge the classes, you need to use `mergeClasses()` function, which performs merge and deduplication of atomic classes generated by `makeStyles()`.
44
+
45
+ ```tsx
46
+ import { mergeClasses, makeStyles } from '@griffel/react';
47
+
48
+ const useClasses = makeStyles({
49
+ blueBold: {
50
+ color: 'blue',
51
+ fontWeight: 'bold',
52
+ },
53
+ red: {
54
+ color: 'red',
55
+ },
56
+ });
57
+
58
+ function Component() {
59
+ const classes = useClasses();
60
+
61
+ const firstClassName = mergeClasses(classes.blueBold, classes.red); // { color: 'red', fontWeight: 'bold' }
62
+ const secondClassName = mergeClasses(classes.red, classes.blueBold); // { color: 'blue', fontWeight: 'bold' }
63
+
64
+ return (
65
+ <>
66
+ <div className={firstClassName} />
67
+ <div className={secondClassName} />
68
+ </>
69
+ );
70
+ }
71
+ ```
72
+
73
+ ## `makeStaticStyles()`
74
+
75
+ Creates styles attached to a global selector. Styles can be defined via objects:
76
+
77
+ ```tsx
78
+ import { makeStaticStyles } from '@griffel/react';
79
+
80
+ const useStaticStyles = makeStaticStyles({
81
+ '@font-face': {
82
+ fontFamily: 'Open Sans',
83
+ src: `url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
84
+ url("/fonts/OpenSans-Regular-webfont.woff") format("woff")`,
85
+ },
86
+ body: {
87
+ background: 'red',
88
+ },
89
+
90
+ /**
91
+ * ⚠️ nested and pseudo selectors are not supported for this scenario via nesting
92
+ *
93
+ * Not supported:
94
+ * .some {
95
+ * .class { ... },
96
+ * ':hover': { ... }
97
+ * }
98
+ *
99
+ * Supported:
100
+ * '.some.class': { ... }
101
+ * '.some.class:hover': { ... }
102
+ */
103
+ });
104
+
105
+ function App() {
106
+ useStaticStyles();
107
+
108
+ return <div />;
109
+ }
110
+ ```
111
+
112
+ Or with string & arrays of strings/objects:
113
+
114
+ ```tsx
115
+ import { makeStaticStyles } from '@griffel/react';
116
+
117
+ const useStaticStyles1 = makeStaticStyles('body { background: red; } .foo { color: green; }');
118
+ const useStaticStyles2 = makeStaticStyles([
119
+ {
120
+ '@font-face': {
121
+ fontFamily: 'My Font',
122
+ src: `url(my_font.woff)`,
123
+ },
124
+ },
125
+ 'html { line-height: 20px; }',
126
+ ]);
127
+
128
+ function App() {
129
+ useStaticStyles1();
130
+ useStaticStyles2();
131
+
132
+ return <div />;
133
+ }
134
+ ```
135
+
136
+ ## Features support
137
+
138
+ ### 📃 pseudo & class selectors, at-rules, global styles
139
+
140
+ `makeStyles()` supports pseudo, class selectors and at-rules.
141
+
142
+ ```ts
143
+ import { makeStyles } from '@griffel/react';
144
+
145
+ const useClasses = makeStyles({
146
+ root: {
147
+ ':active': { color: 'pink' },
148
+ ':hover': { color: 'blue' },
149
+ // :link, :focus, etc.
150
+
151
+ '.foo': { color: 'black' },
152
+ ':nth-child(2n)': { background: '#fafafa' },
153
+
154
+ '@media screen and (max-width: 992px)': { color: 'orange' },
155
+ '@supports (display: grid)': { color: 'red' },
156
+ },
157
+ });
158
+ ```
159
+
160
+ Another useful feature is `:global()` selector, it allows connecting local styles with global selectors.
161
+
162
+ ```ts
163
+ import { makeStyles } from '@griffel/react';
164
+
165
+ const useClasses = makeStyles({
166
+ root: {
167
+ ':global(html[data-whatintent="mouse"])': { background: 'yellow' },
168
+ // outputs: html[data-whatintent="mouse"] .abcd { background: yellow }
169
+ },
170
+ });
171
+ ```
172
+
173
+ ### 🎞 `keyframes` (animations)
174
+
175
+ `keyframes` are supported via `animationName` property that can be defined as an object or an array of objects:
176
+
177
+ ```tsx
178
+ import { makeStyles } from '@griffel/react';
179
+
180
+ const useClasses = makeStyles({
181
+ root: {
182
+ animationIterationCount: 'infinite',
183
+ animationDuration: '3s',
184
+ animationName: {
185
+ from: { transform: 'rotate(0deg)' },
186
+ to: { transform: 'rotate(360deg)' },
187
+ },
188
+ },
189
+ array: {
190
+ animationIterationCount: 'infinite',
191
+ animationDuration: '3s',
192
+ animationName: [
193
+ {
194
+ from: { transform: 'rotate(0deg)' },
195
+ to: { transform: 'rotate(360deg)' },
196
+ },
197
+ {
198
+ from: { height: '100px' },
199
+ to: { height: '200px' },
200
+ },
201
+ ],
202
+ },
203
+ });
204
+ ```
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var React = require('react');
7
+
8
+ /**
9
+ * Verifies if an application can use DOM.
10
+ */
11
+
12
+ function canUseDOM() {
13
+ return typeof window !== 'undefined' && !!(window.document && // eslint-disable-next-line deprecation/deprecation
14
+ window.document.createElement);
15
+ }
16
+ /**
17
+ * @private
18
+ */
19
+
20
+
21
+ const RendererContext = /*#__PURE__*/React.createContext( /*#__PURE__*/core.createDOMRenderer());
22
+ /**
23
+ * @public
24
+ */
25
+
26
+ const RendererProvider = ({
27
+ children,
28
+ renderer,
29
+ targetDocument
30
+ }) => {
31
+ if (canUseDOM()) {
32
+ // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
33
+ // mounting.
34
+ // eslint-disable-next-line react-hooks/rules-of-hooks
35
+ React.useMemo(() => {
36
+ // "rehydrateCache()" can't be called in effects as it needs to be called before any component will be rendered to
37
+ // avoid double insertion of classes
38
+ core.rehydrateRendererCache(renderer, targetDocument);
39
+ }, [renderer, targetDocument]);
40
+ }
41
+
42
+ return /*#__PURE__*/React.createElement(RendererContext.Provider, {
43
+ value: renderer
44
+ }, children);
45
+ };
46
+ /**
47
+ * Returns an instance of current makeStyles() renderer.
48
+ *
49
+ * @private
50
+ */
51
+
52
+ function useRenderer() {
53
+ return React.useContext(RendererContext);
54
+ }
55
+
56
+ exports.RendererProvider = RendererProvider;
57
+ exports.useRenderer = useRenderer;
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import type { GriffelRenderer } from '@griffel/core';
3
+ export interface RendererProviderProps {
4
+ /** An instance of Griffel renderer. */
5
+ renderer: GriffelRenderer;
6
+ /**
7
+ * Document used to insert CSS variables to head
8
+ */
9
+ targetDocument?: Document;
10
+ }
11
+ /**
12
+ * @public
13
+ */
14
+ export declare const RendererProvider: React.FC<RendererProviderProps>;
15
+ /**
16
+ * Returns an instance of current makeStyles() renderer.
17
+ *
18
+ * @private
19
+ */
20
+ export declare function useRenderer(): GriffelRenderer;
@@ -0,0 +1,52 @@
1
+ import { rehydrateRendererCache, createDOMRenderer } from '@griffel/core';
2
+ import * as React from 'react';
3
+
4
+ /**
5
+ * Verifies if an application can use DOM.
6
+ */
7
+
8
+ function canUseDOM() {
9
+ return typeof window !== 'undefined' && !!(window.document && // eslint-disable-next-line deprecation/deprecation
10
+ window.document.createElement);
11
+ }
12
+ /**
13
+ * @private
14
+ */
15
+
16
+
17
+ const RendererContext = /*#__PURE__*/React.createContext( /*#__PURE__*/createDOMRenderer());
18
+ /**
19
+ * @public
20
+ */
21
+
22
+ const RendererProvider = ({
23
+ children,
24
+ renderer,
25
+ targetDocument
26
+ }) => {
27
+ if (canUseDOM()) {
28
+ // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
29
+ // mounting.
30
+ // eslint-disable-next-line react-hooks/rules-of-hooks
31
+ React.useMemo(() => {
32
+ // "rehydrateCache()" can't be called in effects as it needs to be called before any component will be rendered to
33
+ // avoid double insertion of classes
34
+ rehydrateRendererCache(renderer, targetDocument);
35
+ }, [renderer, targetDocument]);
36
+ }
37
+
38
+ return /*#__PURE__*/React.createElement(RendererContext.Provider, {
39
+ value: renderer
40
+ }, children);
41
+ };
42
+ /**
43
+ * Returns an instance of current makeStyles() renderer.
44
+ *
45
+ * @private
46
+ */
47
+
48
+ function useRenderer() {
49
+ return React.useContext(RendererContext);
50
+ }
51
+
52
+ export { RendererProvider, useRenderer };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ /**
8
+ * @private
9
+ */
10
+
11
+ const TextDirectionContext = /*#__PURE__*/React.createContext('ltr');
12
+ /**
13
+ * @public
14
+ */
15
+
16
+ const TextDirectionProvider = ({
17
+ children,
18
+ dir
19
+ }) => {
20
+ return /*#__PURE__*/React.createElement(TextDirectionContext.Provider, {
21
+ value: dir
22
+ }, children);
23
+ };
24
+ /**
25
+ * Returns current directionality of the element's text.
26
+ *
27
+ * @private
28
+ */
29
+
30
+ function useTextDirection() {
31
+ return React.useContext(TextDirectionContext);
32
+ }
33
+
34
+ exports.TextDirectionProvider = TextDirectionProvider;
35
+ exports.useTextDirection = useTextDirection;
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ export interface TextDirectionProviderProps {
3
+ /** Indicates the directionality of the element's text. */
4
+ dir: 'ltr' | 'rtl';
5
+ }
6
+ /**
7
+ * @public
8
+ */
9
+ export declare const TextDirectionProvider: React.FC<TextDirectionProviderProps>;
10
+ /**
11
+ * Returns current directionality of the element's text.
12
+ *
13
+ * @private
14
+ */
15
+ export declare function useTextDirection(): "ltr" | "rtl";
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * @private
5
+ */
6
+
7
+ const TextDirectionContext = /*#__PURE__*/React.createContext('ltr');
8
+ /**
9
+ * @public
10
+ */
11
+
12
+ const TextDirectionProvider = ({
13
+ children,
14
+ dir
15
+ }) => {
16
+ return /*#__PURE__*/React.createElement(TextDirectionContext.Provider, {
17
+ value: dir
18
+ }, children);
19
+ };
20
+ /**
21
+ * Returns current directionality of the element's text.
22
+ *
23
+ * @private
24
+ */
25
+
26
+ function useTextDirection() {
27
+ return React.useContext(TextDirectionContext);
28
+ }
29
+
30
+ export { TextDirectionProvider, useTextDirection };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var RendererContext = require('./RendererContext.cjs.js');
7
+ var TextDirectionContext = require('./TextDirectionContext.cjs.js');
8
+
9
+ /**
10
+ * A version of makeStyles() that accepts build output as an input and skips all runtime transforms.
11
+ *
12
+ * @internal
13
+ */
14
+ // eslint-disable-next-line @typescript-eslint/naming-convention
15
+
16
+ function __styles(classesMapBySlot, cssRules) {
17
+ const getStyles = core.__styles(classesMapBySlot, cssRules);
18
+ return function useClasses() {
19
+ const dir = TextDirectionContext.useTextDirection();
20
+ const renderer = RendererContext.useRenderer();
21
+ return getStyles({
22
+ dir,
23
+ renderer
24
+ });
25
+ };
26
+ }
27
+
28
+ exports.__styles = __styles;
package/__styles.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { CSSClassesMapBySlot, CSSRulesByBucket } from '@griffel/core';
2
+ /**
3
+ * A version of makeStyles() that accepts build output as an input and skips all runtime transforms.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare function __styles<Slots extends string>(classesMapBySlot: CSSClassesMapBySlot<Slots>, cssRules: CSSRulesByBucket): () => Record<Slots, string>;
@@ -0,0 +1,24 @@
1
+ import { __styles as __styles$1 } from '@griffel/core';
2
+ import { useRenderer } from './RendererContext.esm.js';
3
+ import { useTextDirection } from './TextDirectionContext.esm.js';
4
+
5
+ /**
6
+ * A version of makeStyles() that accepts build output as an input and skips all runtime transforms.
7
+ *
8
+ * @internal
9
+ */
10
+ // eslint-disable-next-line @typescript-eslint/naming-convention
11
+
12
+ function __styles(classesMapBySlot, cssRules) {
13
+ const getStyles = __styles$1(classesMapBySlot, cssRules);
14
+ return function useClasses() {
15
+ const dir = useTextDirection();
16
+ const renderer = useRenderer();
17
+ return getStyles({
18
+ dir,
19
+ renderer
20
+ });
21
+ };
22
+ }
23
+
24
+ export { __styles };
package/index.cjs.js ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var makeStyles = require('./makeStyles.cjs.js');
7
+ var makeStaticStyles = require('./makeStaticStyles.cjs.js');
8
+ var renderToStyleElements = require('./renderToStyleElements.cjs.js');
9
+ var RendererContext = require('./RendererContext.cjs.js');
10
+ var TextDirectionContext = require('./TextDirectionContext.cjs.js');
11
+ var __styles = require('./__styles.cjs.js');
12
+
13
+
14
+
15
+ Object.defineProperty(exports, 'createDOMRenderer', {
16
+ enumerable: true,
17
+ get: function () { return core.createDOMRenderer; }
18
+ });
19
+ Object.defineProperty(exports, 'mergeClasses', {
20
+ enumerable: true,
21
+ get: function () { return core.mergeClasses; }
22
+ });
23
+ Object.defineProperty(exports, 'shorthands', {
24
+ enumerable: true,
25
+ get: function () { return core.shorthands; }
26
+ });
27
+ exports.makeStyles = makeStyles.makeStyles;
28
+ exports.makeStaticStyles = makeStaticStyles.makeStaticStyles;
29
+ exports.renderToStyleElements = renderToStyleElements.renderToStyleElements;
30
+ exports.RendererProvider = RendererContext.RendererProvider;
31
+ exports.TextDirectionProvider = TextDirectionContext.TextDirectionProvider;
32
+ exports.__styles = __styles.__styles;
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { shorthands, mergeClasses, createDOMRenderer } from '@griffel/core';
2
+ export type { GriffelStyle } from '@griffel/core';
3
+ export { makeStyles } from './makeStyles';
4
+ export { makeStaticStyles } from './makeStaticStyles';
5
+ export { renderToStyleElements } from './renderToStyleElements';
6
+ export { RendererProvider } from './RendererContext';
7
+ export { TextDirectionProvider } from './TextDirectionContext';
8
+ export { __styles } from './__styles';
package/index.esm.js ADDED
@@ -0,0 +1,7 @@
1
+ export { createDOMRenderer, mergeClasses, shorthands } from '@griffel/core';
2
+ export { makeStyles } from './makeStyles.esm.js';
3
+ export { makeStaticStyles } from './makeStaticStyles.esm.js';
4
+ export { renderToStyleElements } from './renderToStyleElements.esm.js';
5
+ export { RendererProvider } from './RendererContext.esm.js';
6
+ export { TextDirectionProvider } from './TextDirectionContext.esm.js';
7
+ export { __styles } from './__styles.esm.js';
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var RendererContext = require('./RendererContext.cjs.js');
7
+
8
+ function makeStaticStyles(styles) {
9
+ const getStyles = core.makeStaticStyles(styles);
10
+
11
+ if (process.env.NODE_ENV === 'test') {
12
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
13
+ return () => {};
14
+ }
15
+
16
+ return function useStaticStyles() {
17
+ const renderer = RendererContext.useRenderer();
18
+ const options = {
19
+ renderer
20
+ };
21
+ return getStyles(options);
22
+ };
23
+ }
24
+
25
+ exports.makeStaticStyles = makeStaticStyles;
@@ -0,0 +1,2 @@
1
+ import type { GriffelStaticStyles } from '@griffel/core';
2
+ export declare function makeStaticStyles<Selectors>(styles: GriffelStaticStyles | GriffelStaticStyles[]): () => void;
@@ -0,0 +1,21 @@
1
+ import { makeStaticStyles as makeStaticStyles$1 } from '@griffel/core';
2
+ import { useRenderer } from './RendererContext.esm.js';
3
+
4
+ function makeStaticStyles(styles) {
5
+ const getStyles = makeStaticStyles$1(styles);
6
+
7
+ if (process.env.NODE_ENV === 'test') {
8
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
9
+ return () => {};
10
+ }
11
+
12
+ return function useStaticStyles() {
13
+ const renderer = useRenderer();
14
+ const options = {
15
+ renderer
16
+ };
17
+ return getStyles(options);
18
+ };
19
+ }
20
+
21
+ export { makeStaticStyles };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var React = require('react');
7
+ var RendererContext = require('./RendererContext.cjs.js');
8
+ var TextDirectionContext = require('./TextDirectionContext.cjs.js');
9
+
10
+ function isInsideComponent() {
11
+ try {
12
+ // eslint-disable-next-line react-hooks/rules-of-hooks
13
+ React.useContext({});
14
+ return true;
15
+ } catch (e) {
16
+ return false;
17
+ }
18
+ }
19
+
20
+ function makeStyles(stylesBySlots) {
21
+ const getStyles = core.makeStyles(stylesBySlots);
22
+
23
+ if (process.env.NODE_ENV !== 'production') {
24
+ if (isInsideComponent()) {
25
+ throw new Error(["makeStyles(): this function cannot be called in component's scope.", 'All makeStyles() calls should be top level i.e. in a root scope of a file.'].join(' '));
26
+ }
27
+ }
28
+
29
+ return function useClasses() {
30
+ const dir = TextDirectionContext.useTextDirection();
31
+ const renderer = RendererContext.useRenderer();
32
+ return getStyles({
33
+ dir,
34
+ renderer
35
+ });
36
+ };
37
+ }
38
+
39
+ exports.makeStyles = makeStyles;
@@ -0,0 +1,2 @@
1
+ import type { GriffelStyle } from '@griffel/core';
2
+ export declare function makeStyles<Slots extends string | number>(stylesBySlots: Record<Slots, GriffelStyle>): () => Record<Slots, string>;
@@ -0,0 +1,35 @@
1
+ import { makeStyles as makeStyles$1 } from '@griffel/core';
2
+ import * as React from 'react';
3
+ import { useRenderer } from './RendererContext.esm.js';
4
+ import { useTextDirection } from './TextDirectionContext.esm.js';
5
+
6
+ function isInsideComponent() {
7
+ try {
8
+ // eslint-disable-next-line react-hooks/rules-of-hooks
9
+ React.useContext({});
10
+ return true;
11
+ } catch (e) {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ function makeStyles(stylesBySlots) {
17
+ const getStyles = makeStyles$1(stylesBySlots);
18
+
19
+ if (process.env.NODE_ENV !== 'production') {
20
+ if (isInsideComponent()) {
21
+ throw new Error(["makeStyles(): this function cannot be called in component's scope.", 'All makeStyles() calls should be top level i.e. in a root scope of a file.'].join(' '));
22
+ }
23
+ }
24
+
25
+ return function useClasses() {
26
+ const dir = useTextDirection();
27
+ const renderer = useRenderer();
28
+ return getStyles({
29
+ dir,
30
+ renderer
31
+ });
32
+ };
33
+ }
34
+
35
+ export { makeStyles };
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@griffel/react",
3
+ "version": "1.0.0",
4
+ "description": "React implementation of Atomic CSS-in-JS",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/microsoft/griffel"
9
+ },
10
+ "sideEffects": false,
11
+ "peerDependencies": {
12
+ "react": ">=16.8.0 <18.0.0"
13
+ },
14
+ "main": "./index.cjs.js",
15
+ "module": "./index.esm.js",
16
+ "typings": "./index.d.ts",
17
+ "dependencies": {
18
+ "@griffel/core": "1.0.7"
19
+ }
20
+ }
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@griffel/core');
6
+ var React = require('react');
7
+
8
+ /**
9
+ * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.
10
+ *
11
+ * @public
12
+ */
13
+
14
+ function renderToStyleElements(renderer) {
15
+ const styles = core.styleBucketOrdering.reduce((acc, bucketName) => {
16
+ return Object.assign(Object.assign({}, acc), {
17
+ [bucketName]: []
18
+ });
19
+ }, {}); // eslint-disable-next-line guard-for-in
20
+
21
+ for (const cssRule in renderer.insertionCache) {
22
+ const bucketName = renderer.insertionCache[cssRule];
23
+ styles[bucketName].push(cssRule);
24
+ }
25
+
26
+ return Object.keys(styles).map(bucketName => {
27
+ const cssRules = styles[bucketName].join(''); // We don't want to create empty style elements
28
+
29
+ if (cssRules.length === 0) {
30
+ return null;
31
+ }
32
+
33
+ return /*#__PURE__*/React.createElement('style', {
34
+ key: bucketName,
35
+ // TODO: support "nonce"
36
+ // ...renderer.styleNodeAttributes,
37
+ 'data-make-styles-bucket': bucketName || 'default',
38
+ 'data-make-styles-rehydration': true,
39
+ dangerouslySetInnerHTML: {
40
+ __html: cssRules
41
+ }
42
+ });
43
+ }).filter(Boolean);
44
+ }
45
+
46
+ exports.renderToStyleElements = renderToStyleElements;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import type { GriffelRenderer } from '@griffel/core';
3
+ /**
4
+ * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.
5
+ *
6
+ * @public
7
+ */
8
+ export declare function renderToStyleElements(renderer: GriffelRenderer): React.ReactElement[];
@@ -0,0 +1,42 @@
1
+ import { styleBucketOrdering } from '@griffel/core';
2
+ import * as React from 'react';
3
+
4
+ /**
5
+ * This method returns a list of <style> React elements with the rendered CSS. This is useful for Server-Side rendering.
6
+ *
7
+ * @public
8
+ */
9
+
10
+ function renderToStyleElements(renderer) {
11
+ const styles = styleBucketOrdering.reduce((acc, bucketName) => {
12
+ return Object.assign(Object.assign({}, acc), {
13
+ [bucketName]: []
14
+ });
15
+ }, {}); // eslint-disable-next-line guard-for-in
16
+
17
+ for (const cssRule in renderer.insertionCache) {
18
+ const bucketName = renderer.insertionCache[cssRule];
19
+ styles[bucketName].push(cssRule);
20
+ }
21
+
22
+ return Object.keys(styles).map(bucketName => {
23
+ const cssRules = styles[bucketName].join(''); // We don't want to create empty style elements
24
+
25
+ if (cssRules.length === 0) {
26
+ return null;
27
+ }
28
+
29
+ return /*#__PURE__*/React.createElement('style', {
30
+ key: bucketName,
31
+ // TODO: support "nonce"
32
+ // ...renderer.styleNodeAttributes,
33
+ 'data-make-styles-bucket': bucketName || 'default',
34
+ 'data-make-styles-rehydration': true,
35
+ dangerouslySetInnerHTML: {
36
+ __html: cssRules
37
+ }
38
+ });
39
+ }).filter(Boolean);
40
+ }
41
+
42
+ export { renderToStyleElements };