@griffel/react 1.0.3 → 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 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:
@@ -187,6 +321,7 @@ const useClasses = makeStyles({
187
321
 
188
322
  '@media screen and (max-width: 992px)': { color: 'orange' },
189
323
  '@supports (display: grid)': { color: 'red' },
324
+ '@layer utility': { marginBottom: '1em' }
190
325
  },
191
326
  });
192
327
  ```
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
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
- React__namespace.useContext({});
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;
@@ -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 // 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;;;;"}
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
- // eslint-disable-next-line react-hooks/rules-of-hooks
9
- React.useContext({});
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;
@@ -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 // 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;;;;"}
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",
3
+ "version": "1.0.4",
4
4
  "description": "React implementation of Atomic CSS-in-JS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "sideEffects": false,
11
11
  "dependencies": {
12
- "@griffel/core": "^1.2.0",
12
+ "@griffel/core": "^1.3.0",
13
13
  "tslib": "^2.1.0"
14
14
  },
15
15
  "peerDependencies": {