@griffel/react 1.0.1 → 1.0.4
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 +184 -0
- package/makeStyles.cjs.js +12 -2
- package/makeStyles.cjs.js.map +1 -1
- package/makeStyles.esm.js +12 -2
- package/makeStyles.esm.js.map +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -70,6 +70,140 @@ function Component() {
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
## `shorthands`
|
|
74
|
+
|
|
75
|
+
`shorthands` provides a set of functions to mimic [CSS shorthands](https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties) and improve developer experience as [CSS shorthands are not supported](https://griffel.js.org/react/guides/limitations#css-shorthands-are-not-supported) by Griffel.
|
|
76
|
+
|
|
77
|
+
### `shorthands.border`
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
81
|
+
|
|
82
|
+
const useClasses = makeStyles({
|
|
83
|
+
root: {
|
|
84
|
+
...shorthands.border('2px'),
|
|
85
|
+
...shorthands.border('2px', 'solid'),
|
|
86
|
+
...shorthands.border('2px', 'solid', 'red'),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `shorthands.borderBottom`, `shorthands.borderTop`, `shorthands.borderLeft`, `shorthands.borderRight`
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
95
|
+
|
|
96
|
+
const useClasses = makeStyles({
|
|
97
|
+
root: {
|
|
98
|
+
// The same is true for "borderTop", "borderLeft" & "borderRight"
|
|
99
|
+
...shorthands.borderBottom('2px'),
|
|
100
|
+
...shorthands.borderBottom('2px', 'solid'),
|
|
101
|
+
...shorthands.borderBottom('2px', 'solid', 'red'),
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### `shorthands.borderColor`
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
110
|
+
|
|
111
|
+
const useClasses = makeStyles({
|
|
112
|
+
root: {
|
|
113
|
+
...shorthands.borderColor('red'),
|
|
114
|
+
...shorthands.borderColor('red', 'blue'),
|
|
115
|
+
...shorthands.borderColor('red', 'blue', 'green'),
|
|
116
|
+
...shorthands.borderColor('red', 'blue', 'green', 'yellow'),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `shorthands.borderStyle`
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
125
|
+
|
|
126
|
+
const useClasses = makeStyles({
|
|
127
|
+
root: {
|
|
128
|
+
...shorthands.borderStyle('solid'),
|
|
129
|
+
...shorthands.borderStyle('solid', 'dashed'),
|
|
130
|
+
...shorthands.borderStyle('solid', 'dashed', 'dotted'),
|
|
131
|
+
...shorthands.borderStyle('solid', 'dashed', 'dotted', 'double'),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### `shorthands.borderWidth`
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
140
|
+
|
|
141
|
+
const useClasses = makeStyles({
|
|
142
|
+
root: {
|
|
143
|
+
...shorthands.borderWidth('12px'),
|
|
144
|
+
...shorthands.borderWidth('12px', '24px'),
|
|
145
|
+
...shorthands.borderWidth('12px', '24px', '36px'),
|
|
146
|
+
...shorthands.borderWidth('12px', '24px', '36px', '48px'),
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `shorthands.gap`
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
155
|
+
|
|
156
|
+
const useClasses = makeStyles({
|
|
157
|
+
root: {
|
|
158
|
+
...shorthands.gap('12px'),
|
|
159
|
+
...shorthands.gap('12px', '24px'),
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `shorthands.margin`
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
168
|
+
|
|
169
|
+
const useClasses = makeStyles({
|
|
170
|
+
root: {
|
|
171
|
+
...shorthands.margin('12px'),
|
|
172
|
+
...shorthands.margin('12px', '24px'),
|
|
173
|
+
...shorthands.margin('12px', '24px', '36px'),
|
|
174
|
+
...shorthands.margin('12px', '24px', '36px', '48px'),
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `shorthands.overflow`
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
183
|
+
|
|
184
|
+
const useClasses = makeStyles({
|
|
185
|
+
root: {
|
|
186
|
+
...shorthands.overflow('visible'),
|
|
187
|
+
...shorthands.overflow('visible', 'hidden'),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### `shorthands.padding`
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
import { makeStyles, shorthands } from '@griffel/react';
|
|
196
|
+
|
|
197
|
+
const useClasses = makeStyles({
|
|
198
|
+
root: {
|
|
199
|
+
...shorthands.padding('12px'),
|
|
200
|
+
...shorthands.padding('12px', '24px'),
|
|
201
|
+
...shorthands.padding('12px', '24px', '36px'),
|
|
202
|
+
...shorthands.padding('12px', '24px', '36px', '48px'),
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
73
207
|
## `makeStaticStyles()`
|
|
74
208
|
|
|
75
209
|
Creates styles attached to a global selector. Styles can be defined via objects:
|
|
@@ -133,6 +267,40 @@ function App() {
|
|
|
133
267
|
}
|
|
134
268
|
```
|
|
135
269
|
|
|
270
|
+
## `createDOMRenderer()`, `RendererProvider`
|
|
271
|
+
|
|
272
|
+
`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.
|
|
273
|
+
|
|
274
|
+
```jsx
|
|
275
|
+
import { createDOMRenderer, RendererProvider } from '@griffel/react';
|
|
276
|
+
|
|
277
|
+
function App(props) {
|
|
278
|
+
const { targetDocument } = props;
|
|
279
|
+
const renderer = React.useMemo(() => createDOMRenderer(targetDocument), [targetDocument]);
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<RendererProvider renderer={renderer} targetDocument={targetDocument}>
|
|
283
|
+
{/* Children components */}
|
|
284
|
+
{/* ... */}
|
|
285
|
+
</RendererProvider>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### styleElementAttributes
|
|
291
|
+
|
|
292
|
+
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).
|
|
293
|
+
|
|
294
|
+
```js
|
|
295
|
+
import { createDOMRenderer } from '@griffel/react';
|
|
296
|
+
|
|
297
|
+
const renderer = createDOMRenderer(targetDocument, {
|
|
298
|
+
styleElementAttributes: {
|
|
299
|
+
nonce: 'random',
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
136
304
|
## Features support
|
|
137
305
|
|
|
138
306
|
### 📃 pseudo & class selectors, at-rules, global styles
|
|
@@ -153,6 +321,7 @@ const useClasses = makeStyles({
|
|
|
153
321
|
|
|
154
322
|
'@media screen and (max-width: 992px)': { color: 'orange' },
|
|
155
323
|
'@supports (display: grid)': { color: 'red' },
|
|
324
|
+
'@layer utility': { marginBottom: '1em' }
|
|
156
325
|
},
|
|
157
326
|
});
|
|
158
327
|
```
|
|
@@ -202,3 +371,18 @@ const useClasses = makeStyles({
|
|
|
202
371
|
},
|
|
203
372
|
});
|
|
204
373
|
```
|
|
374
|
+
|
|
375
|
+
### CSS Fallback Properties
|
|
376
|
+
|
|
377
|
+
Any CSS property accepts an array of values which are all added to the styles.
|
|
378
|
+
Every browser will use the latest valid value (which might be a different one in different browsers, based on supported CSS in that browser):
|
|
379
|
+
|
|
380
|
+
```js
|
|
381
|
+
import { makeStyles } from '@griffel/react';
|
|
382
|
+
|
|
383
|
+
const useClasses = makeStyles({
|
|
384
|
+
root: {
|
|
385
|
+
overflowY: ['scroll', 'overlay'],
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
```
|
package/makeStyles.cjs.js
CHANGED
|
@@ -28,9 +28,19 @@ function _interopNamespace(e) {
|
|
|
28
28
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
29
|
|
|
30
30
|
function isInsideComponent() {
|
|
31
|
+
// React 18 always logs errors if a dispatcher is not present:
|
|
32
|
+
// https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36
|
|
31
33
|
try {
|
|
32
|
-
//
|
|
33
|
-
React__namespace.
|
|
34
|
+
// @ts-expect-error "SECRET_INTERNALS" are not typed
|
|
35
|
+
const dispatcher = React__namespace.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current; // Before any React component was rendered "dispatcher" will be "null"
|
|
36
|
+
|
|
37
|
+
if (dispatcher === null || dispatcher === undefined) {
|
|
38
|
+
return false;
|
|
39
|
+
} // A check with hooks call (i.e. call "React.useContext()" outside a component) will always produce errors, but
|
|
40
|
+
// a call on the dispatcher don't
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
dispatcher.useContext({});
|
|
34
44
|
return true;
|
|
35
45
|
} catch (e) {
|
|
36
46
|
return false;
|
package/makeStyles.cjs.js.map
CHANGED
|
@@ -1 +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 //
|
|
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 // React 18 always logs errors if a dispatcher is not present:\n // https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36\n try {\n // @ts-expect-error \"SECRET_INTERNALS\" are not typed\n const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;\n\n // Before any React component was rendered \"dispatcher\" will be \"null\"\n if (dispatcher === null || dispatcher === undefined) {\n return false;\n }\n\n // A check with hooks call (i.e. call \"React.useContext()\" outside a component) will always produce errors, but\n // a call on the dispatcher don't\n dispatcher.useContext({});\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","dispatcher","React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","current","undefined","useContext","e","makeStyles","stylesBySlots","getStyles","vanillaMakeStyles","process","env","NODE_ENV","Error","join","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAASA,iBAAT;AACE;AACA;AACA,MAAI;AACF;AACA,UAAMC,UAAU,GAAGC,gBAAK,CAACC,kDAAN,CAAyDC,sBAAzD,CAAgFC,OAAnG,CAFE;;AAKF,QAAIJ,UAAU,KAAK,IAAf,IAAuBA,UAAU,KAAKK,SAA1C,EAAqD;AACnD,aAAO,KAAP;AACD,KAPC;AAUF;;;AACAL,IAAAA,UAAU,CAACM,UAAX,CAAsB,EAAtB;AACA,WAAO,IAAP;AACD,GAbD,CAaE,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,QAAIf,iBAAiB,EAArB,EAAyB;AACvB,YAAM,IAAIgB,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
|
@@ -4,9 +4,19 @@ import { useRenderer } from './RendererContext.esm.js';
|
|
|
4
4
|
import { useTextDirection } from './TextDirectionContext.esm.js';
|
|
5
5
|
|
|
6
6
|
function isInsideComponent() {
|
|
7
|
+
// React 18 always logs errors if a dispatcher is not present:
|
|
8
|
+
// https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36
|
|
7
9
|
try {
|
|
8
|
-
//
|
|
9
|
-
React.
|
|
10
|
+
// @ts-expect-error "SECRET_INTERNALS" are not typed
|
|
11
|
+
const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current; // Before any React component was rendered "dispatcher" will be "null"
|
|
12
|
+
|
|
13
|
+
if (dispatcher === null || dispatcher === undefined) {
|
|
14
|
+
return false;
|
|
15
|
+
} // A check with hooks call (i.e. call "React.useContext()" outside a component) will always produce errors, but
|
|
16
|
+
// a call on the dispatcher don't
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
dispatcher.useContext({});
|
|
10
20
|
return true;
|
|
11
21
|
} catch (e) {
|
|
12
22
|
return false;
|
package/makeStyles.esm.js.map
CHANGED
|
@@ -1 +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 //
|
|
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 // React 18 always logs errors if a dispatcher is not present:\n // https://github.com/facebook/react/blob/42f15b324f50d0fd98322c21646ac3013e30344a/packages/react/src/ReactHooks.js#L26-L36\n try {\n // @ts-expect-error \"SECRET_INTERNALS\" are not typed\n const dispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;\n\n // Before any React component was rendered \"dispatcher\" will be \"null\"\n if (dispatcher === null || dispatcher === undefined) {\n return false;\n }\n\n // A check with hooks call (i.e. call \"React.useContext()\" outside a component) will always produce errors, but\n // a call on the dispatcher don't\n dispatcher.useContext({});\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","dispatcher","React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","current","undefined","useContext","e","makeStyles","stylesBySlots","getStyles","vanillaMakeStyles","process","env","NODE_ENV","Error","join","useClasses","dir","useTextDirection","renderer","useRenderer"],"mappings":";;;;;AAOA,SAASA,iBAAT;AACE;AACA;AACA,MAAI;AACF;AACA,UAAMC,UAAU,GAAGC,KAAK,CAACC,kDAAN,CAAyDC,sBAAzD,CAAgFC,OAAnG,CAFE;;AAKF,QAAIJ,UAAU,KAAK,IAAf,IAAuBA,UAAU,KAAKK,SAA1C,EAAqD;AACnD,aAAO,KAAP;AACD,KAPC;AAUF;;;AACAL,IAAAA,UAAU,CAACM,UAAX,CAAsB,EAAtB;AACA,WAAO,IAAP;AACD,GAbD,CAaE,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,QAAIf,iBAAiB,EAArB,EAAyB;AACvB,YAAM,IAAIgB,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.
|
|
3
|
+
"version": "1.0.4",
|
|
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.3.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
|
-
|
|
18
|
-
"@griffel/core": "1.0.7"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
20
|
+
"typings": "./index.d.ts"
|
|
21
|
+
}
|