@react-spectrum/utils 3.11.11 → 3.12.1
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 +201 -0
- package/dist/BreakpointProvider.main.js.map +1 -1
- package/dist/BreakpointProvider.module.js.map +1 -1
- package/dist/Slots.main.js +6 -4
- package/dist/Slots.main.js.map +1 -1
- package/dist/Slots.mjs +6 -4
- package/dist/Slots.module.js +6 -4
- package/dist/Slots.module.js.map +1 -1
- package/dist/classNames.main.js.map +1 -1
- package/dist/classNames.module.js.map +1 -1
- package/dist/styleProps.main.js +2 -2
- package/dist/styleProps.main.js.map +1 -1
- package/dist/styleProps.mjs +2 -2
- package/dist/styleProps.module.js +2 -2
- package/dist/styleProps.module.js.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -8
- package/src/BreakpointProvider.tsx +4 -4
- package/src/Slots.tsx +10 -5
- package/src/classNames.ts +1 -1
- package/src/styleProps.ts +6 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2019 Adobe
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAM,8CAAU,CAAA,GAAA,sCAAI,EAAE,aAAa,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AAcA,MAAM,8CAAU,CAAA,GAAA,sCAAI,EAAE,aAAa,CAA2B;AAC9D,8BAAQ,WAAW,GAAG;AAOf,SAAS,0CAAmB,KAA8B;IAC/D,IAAI,YACF,QAAQ,s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AAO;IACnB,OAAO,QAAQ;QAAC;KAAO,GAAG;AAC5B;AAEO,SAAS;IACd,OAAO,CAAA,GAAA,uBAAS,EAAE;AACpB","sources":["packages/@react-spectrum/utils/src/BreakpointProvider.tsx"],"sourcesContent":["import React, {ReactNode, useContext, useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\n\ninterface Breakpoints {\n S?: number,\n M?: number,\n L?: number,\n [custom: string]: number | undefined\n}\n\ninterface BreakpointContext {\n matchedBreakpoints: string[]\n}\n\nconst Context = React.createContext<BreakpointContext | null>(null);\nContext.displayName = 'BreakpointContext';\n\ninterface BreakpointProviderProps {\n children?: ReactNode,\n matchedBreakpoints: string[]\n}\n\nexport function BreakpointProvider(props: BreakpointProviderProps) {\n let {\n children,\n matchedBreakpoints\n } = props;\n return (\n <Context.Provider\n value={{matchedBreakpoints}} >\n {children}\n </Context.Provider>\n );\n}\n\nexport function useMatchedBreakpoints(breakpoints: Breakpoints): string[] {\n let entries = Object.entries(breakpoints).sort(([, valueA], [, valueB]) => valueB! - valueA!);\n let breakpointQueries = entries.map(([, value]) => `(min-width: ${value}px)`);\n\n let supportsMatchMedia = typeof window !== 'undefined' && typeof window.matchMedia === 'function';\n let getBreakpointHandler = () => {\n let matched: string[] = [];\n for (let i in breakpointQueries) {\n let query = breakpointQueries[i];\n if (window.matchMedia(query).matches) {\n matched.push(entries[i][0]);\n }\n }\n matched.push('base');\n return matched;\n };\n\n let [breakpoint, setBreakpoint] = useState(() =>\n supportsMatchMedia\n ? getBreakpointHandler()\n : ['base']\n );\n\n useEffect(() => {\n if (!supportsMatchMedia) {\n return;\n }\n\n let onResize = () => {\n const breakpointHandler = getBreakpointHandler();\n\n setBreakpoint(previousBreakpointHandler => {\n if (previousBreakpointHandler.length !== breakpointHandler.length ||\n previousBreakpointHandler.some((breakpoint, idx) => breakpoint !== breakpointHandler[idx])) {\n return [...breakpointHandler]; // Return a new array to force state change\n }\n\n return previousBreakpointHandler;\n });\n };\n\n window.addEventListener('resize', onResize);\n return () => {\n window.removeEventListener('resize', onResize);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [supportsMatchMedia]);\n\n // If in SSR, the media query should never match. Once the page hydrates,\n // this will update and the real value will be returned.\n let isSSR = useIsSSR();\n return isSSR ? ['base'] : breakpoint;\n}\n\nexport function useBreakpoint() {\n return useContext(Context);\n}\n"],"names":[],"version":3,"file":"BreakpointProvider.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAcA,MAAM,8CAAU,CAAA,GAAA,YAAI,EAAE,aAAa,
|
|
1
|
+
{"mappings":";;;;;AAcA,MAAM,8CAAU,CAAA,GAAA,YAAI,EAAE,aAAa,CAA2B;AAC9D,8BAAQ,WAAW,GAAG;AAOf,SAAS,0CAAmB,KAA8B;IAC/D,IAAI,YACF,QAAQ,sBACR,kBAAkB,EACnB,GAAG;IACJ,qBACE,gCAAC,8BAAQ,QAAQ;QACf,OAAO;gCAAC;QAAkB;OACzB;AAGP;AAEO,SAAS,0CAAsB,WAAwB;IAC5D,IAAI,UAAU,OAAO,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,GAAK,SAAU;IACrF,IAAI,oBAAoB,QAAQ,GAAG,CAAC,CAAC,GAAG,MAAM,GAAK,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC;IAE5E,IAAI,qBAAqB,OAAO,WAAW,eAAe,OAAO,OAAO,UAAU,KAAK;IACvF,IAAI,uBAAuB;QACzB,IAAI,UAAoB,EAAE;QAC1B,IAAK,IAAI,KAAK,kBAAmB;YAC/B,IAAI,QAAQ,iBAAiB,CAAC,EAAE;YAChC,IAAI,OAAO,UAAU,CAAC,OAAO,OAAO,EAClC,QAAQ,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QAE9B;QACA,QAAQ,IAAI,CAAC;QACb,OAAO;IACT;IAEA,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,eAAO,EAAE,IACzC,qBACI,yBACA;YAAC;SAAO;IAGd,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAC,oBACH;QAGF,IAAI,WAAW;YACb,MAAM,oBAAoB;YAE1B,cAAc,CAAA;gBACZ,IAAI,0BAA0B,MAAM,KAAK,kBAAkB,MAAM,IAC/D,0BAA0B,IAAI,CAAC,CAAC,YAAY,MAAQ,eAAe,iBAAiB,CAAC,IAAI,GACzF,OAAO;uBAAI;iBAAkB,EAAE,2CAA2C;gBAG5E,OAAO;YACT;QACF;QAEA,OAAO,gBAAgB,CAAC,UAAU;QAClC,OAAO;YACL,OAAO,mBAAmB,CAAC,UAAU;QACvC;IACF,uDAAuD;IACvD,GAAG;QAAC;KAAmB;IAEvB,yEAAyE;IACzE,wDAAwD;IACxD,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,OAAO,QAAQ;QAAC;KAAO,GAAG;AAC5B;AAEO,SAAS;IACd,OAAO,CAAA,GAAA,iBAAS,EAAE;AACpB","sources":["packages/@react-spectrum/utils/src/BreakpointProvider.tsx"],"sourcesContent":["import React, {ReactNode, useContext, useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\n\ninterface Breakpoints {\n S?: number,\n M?: number,\n L?: number,\n [custom: string]: number | undefined\n}\n\ninterface BreakpointContext {\n matchedBreakpoints: string[]\n}\n\nconst Context = React.createContext<BreakpointContext | null>(null);\nContext.displayName = 'BreakpointContext';\n\ninterface BreakpointProviderProps {\n children?: ReactNode,\n matchedBreakpoints: string[]\n}\n\nexport function BreakpointProvider(props: BreakpointProviderProps) {\n let {\n children,\n matchedBreakpoints\n } = props;\n return (\n <Context.Provider\n value={{matchedBreakpoints}} >\n {children}\n </Context.Provider>\n );\n}\n\nexport function useMatchedBreakpoints(breakpoints: Breakpoints): string[] {\n let entries = Object.entries(breakpoints).sort(([, valueA], [, valueB]) => valueB! - valueA!);\n let breakpointQueries = entries.map(([, value]) => `(min-width: ${value}px)`);\n\n let supportsMatchMedia = typeof window !== 'undefined' && typeof window.matchMedia === 'function';\n let getBreakpointHandler = () => {\n let matched: string[] = [];\n for (let i in breakpointQueries) {\n let query = breakpointQueries[i];\n if (window.matchMedia(query).matches) {\n matched.push(entries[i][0]);\n }\n }\n matched.push('base');\n return matched;\n };\n\n let [breakpoint, setBreakpoint] = useState(() =>\n supportsMatchMedia\n ? getBreakpointHandler()\n : ['base']\n );\n\n useEffect(() => {\n if (!supportsMatchMedia) {\n return;\n }\n\n let onResize = () => {\n const breakpointHandler = getBreakpointHandler();\n\n setBreakpoint(previousBreakpointHandler => {\n if (previousBreakpointHandler.length !== breakpointHandler.length ||\n previousBreakpointHandler.some((breakpoint, idx) => breakpoint !== breakpointHandler[idx])) {\n return [...breakpointHandler]; // Return a new array to force state change\n }\n\n return previousBreakpointHandler;\n });\n };\n\n window.addEventListener('resize', onResize);\n return () => {\n window.removeEventListener('resize', onResize);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [supportsMatchMedia]);\n\n // If in SSR, the media query should never match. Once the page hydrates,\n // this will update and the real value will be returned.\n let isSSR = useIsSSR();\n return isSSR ? ['base'] : breakpoint;\n}\n\nexport function useBreakpoint() {\n return useContext(Context);\n}\n"],"names":[],"version":3,"file":"BreakpointProvider.module.js.map"}
|
package/dist/Slots.main.js
CHANGED
|
@@ -29,6 +29,7 @@ $parcel$export(module.exports, "ClearSlots", () => $e81916440cf6fd84$export$ceb1
|
|
|
29
29
|
let $e81916440cf6fd84$var$SlotContext = /*#__PURE__*/ (0, ($parcel$interopDefault($iTRw5$react))).createContext(null);
|
|
30
30
|
function $e81916440cf6fd84$export$1e5c9e6e4e15efe3(props, defaultSlot) {
|
|
31
31
|
let slot = props.slot || defaultSlot;
|
|
32
|
+
// @ts-ignore TODO why is slot an object and not just string or undefined?
|
|
32
33
|
let { [slot]: slotProps = {} } = (0, $iTRw5$react.useContext)($e81916440cf6fd84$var$SlotContext) || {};
|
|
33
34
|
return (0, $iTRw5$reactariautils.mergeProps)(props, (0, $iTRw5$reactariautils.mergeProps)(slotProps, {
|
|
34
35
|
id: props.id
|
|
@@ -43,9 +44,9 @@ function $e81916440cf6fd84$export$365cf34cda9978e2(cssModule) {
|
|
|
43
44
|
}, {});
|
|
44
45
|
}
|
|
45
46
|
function $e81916440cf6fd84$export$8107b24b91795686(props) {
|
|
46
|
-
|
|
47
|
-
let parentSlots = (0, $iTRw5$react.useContext)($e81916440cf6fd84$var$SlotContext) ||
|
|
48
|
-
let { slots: slots =
|
|
47
|
+
const emptyObj = (0, $iTRw5$react.useMemo)(()=>({}), []);
|
|
48
|
+
let parentSlots = (0, $iTRw5$react.useContext)($e81916440cf6fd84$var$SlotContext) || emptyObj;
|
|
49
|
+
let { slots: slots = emptyObj, children: children } = props;
|
|
49
50
|
// Merge props for each slot from parent context and props
|
|
50
51
|
let value = (0, $iTRw5$react.useMemo)(()=>Object.keys(parentSlots).concat(Object.keys(slots)).reduce((o, p)=>({
|
|
51
52
|
...o,
|
|
@@ -60,12 +61,13 @@ function $e81916440cf6fd84$export$8107b24b91795686(props) {
|
|
|
60
61
|
}
|
|
61
62
|
function $e81916440cf6fd84$export$ceb145244332b7a2(props) {
|
|
62
63
|
let { children: children, ...otherProps } = props;
|
|
64
|
+
const emptyObj = (0, $iTRw5$react.useMemo)(()=>({}), []);
|
|
63
65
|
let content = children;
|
|
64
66
|
if ((0, ($parcel$interopDefault($iTRw5$react))).Children.toArray(children).length <= 1) {
|
|
65
67
|
if (typeof children === 'function') content = /*#__PURE__*/ (0, ($parcel$interopDefault($iTRw5$react))).cloneElement((0, ($parcel$interopDefault($iTRw5$react))).Children.only(children), otherProps);
|
|
66
68
|
}
|
|
67
69
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($iTRw5$react))).createElement($e81916440cf6fd84$var$SlotContext.Provider, {
|
|
68
|
-
value:
|
|
70
|
+
value: emptyObj
|
|
69
71
|
}, content);
|
|
70
72
|
}
|
|
71
73
|
|
package/dist/Sl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,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE,IAAI,CAAC;YAAE,CAAA,GAAI,CAAC,IAC1D;QAAC;QAAa;KAAM;IAE1B,qBACE,0DAAC,kCAAY,QAAQ;QAAC,OAAO;OAC1B;AAGP;AAEO,SAAS,0CAAW,KAAK;IAC9B,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAEhC,MAAM,WAAW,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA,CAAC,CAAA,GAAI,EAAE;IAEvC,IAAI,UAAU;IACd,IAAI,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,MAAM,IAAI,GAC7C;QAAA,IAAI,OAAO,aAAa,YACtB,wBAAU,CAAA,GAAA,sCAAI,EAAE,YAAY,CAAC,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;IAC9D;IAEF,qBACE,0DAAC,kCAAY,QAAQ;QAAC,OAAO;OAC1B;AAGP","sources":["packages/@react-spectrum/utils/src/Slots.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {mergeProps} from '@react-aria/utils';\nimport React, {useContext, useMemo} from 'react';\n\ninterface SlotProps {\n slot?: string\n}\n\nlet SlotContext = React.createContext<{} | null>(null);\n\nexport function useSlotProps<T>(props: T & {id?: string}, defaultSlot?: string): T {\n let slot = (props as SlotProps).slot || defaultSlot;\n // @ts-ignore TODO why is slot an object and not just string or undefined?\n let {[slot]: slotProps = {}} = useContext(SlotContext) || {};\n\n return mergeProps(props, mergeProps(slotProps, {id: props.id}));\n}\n\nexport function cssModuleToSlots(cssModule) {\n return Object.keys(cssModule).reduce((acc, slot) => {\n acc[slot] = {UNSAFE_className: cssModule[slot]};\n return acc;\n }, {});\n}\n\nexport function SlotProvider(props) {\n const emptyObj = useMemo(() => ({}), []);\n \n let parentSlots = useContext(SlotContext) || emptyObj;\n let {slots = emptyObj, children} = props;\n\n // Merge props for each slot from parent context and props\n let value = useMemo(() =>\n Object.keys(parentSlots)\n .concat(Object.keys(slots))\n .reduce((o, p) => ({\n ...o,\n [p]: mergeProps(parentSlots[p] || {}, slots[p] || {})}), {})\n , [parentSlots, slots]);\n\n return (\n <SlotContext.Provider value={value}>\n {children}\n </SlotContext.Provider>\n );\n}\n\nexport function ClearSlots(props) {\n let {children, ...otherProps} = props;\n\n const emptyObj = useMemo(() => ({}), []);\n\n let content = children;\n if (React.Children.toArray(children).length <= 1) {\n if (typeof children === 'function') { // need to know if the node is a string or something else that react can render that doesn't get props\n content = React.cloneElement(React.Children.only(children), otherProps);\n }\n }\n return (\n <SlotContext.Provider value={emptyObj}>\n {content}\n </SlotContext.Provider>\n );\n}\n"],"names":[],"version":3,"file":"Slots.main.js.map"}
|
package/dist/Slots.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import $doF98$react, {useContext as $doF98$useContext, useMemo as $doF98$useMemo
|
|
|
16
16
|
let $59d09bcc83651bf9$var$SlotContext = /*#__PURE__*/ (0, $doF98$react).createContext(null);
|
|
17
17
|
function $59d09bcc83651bf9$export$1e5c9e6e4e15efe3(props, defaultSlot) {
|
|
18
18
|
let slot = props.slot || defaultSlot;
|
|
19
|
+
// @ts-ignore TODO why is slot an object and not just string or undefined?
|
|
19
20
|
let { [slot]: slotProps = {} } = (0, $doF98$useContext)($59d09bcc83651bf9$var$SlotContext) || {};
|
|
20
21
|
return (0, $doF98$mergeProps)(props, (0, $doF98$mergeProps)(slotProps, {
|
|
21
22
|
id: props.id
|
|
@@ -30,9 +31,9 @@ function $59d09bcc83651bf9$export$365cf34cda9978e2(cssModule) {
|
|
|
30
31
|
}, {});
|
|
31
32
|
}
|
|
32
33
|
function $59d09bcc83651bf9$export$8107b24b91795686(props) {
|
|
33
|
-
|
|
34
|
-
let parentSlots = (0, $doF98$useContext)($59d09bcc83651bf9$var$SlotContext) ||
|
|
35
|
-
let { slots: slots =
|
|
34
|
+
const emptyObj = (0, $doF98$useMemo)(()=>({}), []);
|
|
35
|
+
let parentSlots = (0, $doF98$useContext)($59d09bcc83651bf9$var$SlotContext) || emptyObj;
|
|
36
|
+
let { slots: slots = emptyObj, children: children } = props;
|
|
36
37
|
// Merge props for each slot from parent context and props
|
|
37
38
|
let value = (0, $doF98$useMemo)(()=>Object.keys(parentSlots).concat(Object.keys(slots)).reduce((o, p)=>({
|
|
38
39
|
...o,
|
|
@@ -47,12 +48,13 @@ function $59d09bcc83651bf9$export$8107b24b91795686(props) {
|
|
|
47
48
|
}
|
|
48
49
|
function $59d09bcc83651bf9$export$ceb145244332b7a2(props) {
|
|
49
50
|
let { children: children, ...otherProps } = props;
|
|
51
|
+
const emptyObj = (0, $doF98$useMemo)(()=>({}), []);
|
|
50
52
|
let content = children;
|
|
51
53
|
if ((0, $doF98$react).Children.toArray(children).length <= 1) {
|
|
52
54
|
if (typeof children === 'function') content = /*#__PURE__*/ (0, $doF98$react).cloneElement((0, $doF98$react).Children.only(children), otherProps);
|
|
53
55
|
}
|
|
54
56
|
return /*#__PURE__*/ (0, $doF98$react).createElement($59d09bcc83651bf9$var$SlotContext.Provider, {
|
|
55
|
-
value:
|
|
57
|
+
value: emptyObj
|
|
56
58
|
}, content);
|
|
57
59
|
}
|
|
58
60
|
|
package/dist/Slots.module.js
CHANGED
|
@@ -16,6 +16,7 @@ import $doF98$react, {useContext as $doF98$useContext, useMemo as $doF98$useMemo
|
|
|
16
16
|
let $59d09bcc83651bf9$var$SlotContext = /*#__PURE__*/ (0, $doF98$react).createContext(null);
|
|
17
17
|
function $59d09bcc83651bf9$export$1e5c9e6e4e15efe3(props, defaultSlot) {
|
|
18
18
|
let slot = props.slot || defaultSlot;
|
|
19
|
+
// @ts-ignore TODO why is slot an object and not just string or undefined?
|
|
19
20
|
let { [slot]: slotProps = {} } = (0, $doF98$useContext)($59d09bcc83651bf9$var$SlotContext) || {};
|
|
20
21
|
return (0, $doF98$mergeProps)(props, (0, $doF98$mergeProps)(slotProps, {
|
|
21
22
|
id: props.id
|
|
@@ -30,9 +31,9 @@ function $59d09bcc83651bf9$export$365cf34cda9978e2(cssModule) {
|
|
|
30
31
|
}, {});
|
|
31
32
|
}
|
|
32
33
|
function $59d09bcc83651bf9$export$8107b24b91795686(props) {
|
|
33
|
-
|
|
34
|
-
let parentSlots = (0, $doF98$useContext)($59d09bcc83651bf9$var$SlotContext) ||
|
|
35
|
-
let { slots: slots =
|
|
34
|
+
const emptyObj = (0, $doF98$useMemo)(()=>({}), []);
|
|
35
|
+
let parentSlots = (0, $doF98$useContext)($59d09bcc83651bf9$var$SlotContext) || emptyObj;
|
|
36
|
+
let { slots: slots = emptyObj, children: children } = props;
|
|
36
37
|
// Merge props for each slot from parent context and props
|
|
37
38
|
let value = (0, $doF98$useMemo)(()=>Object.keys(parentSlots).concat(Object.keys(slots)).reduce((o, p)=>({
|
|
38
39
|
...o,
|
|
@@ -47,12 +48,13 @@ function $59d09bcc83651bf9$export$8107b24b91795686(props) {
|
|
|
47
48
|
}
|
|
48
49
|
function $59d09bcc83651bf9$export$ceb145244332b7a2(props) {
|
|
49
50
|
let { children: children, ...otherProps } = props;
|
|
51
|
+
const emptyObj = (0, $doF98$useMemo)(()=>({}), []);
|
|
50
52
|
let content = children;
|
|
51
53
|
if ((0, $doF98$react).Children.toArray(children).length <= 1) {
|
|
52
54
|
if (typeof children === 'function') content = /*#__PURE__*/ (0, $doF98$react).cloneElement((0, $doF98$react).Children.only(children), otherProps);
|
|
53
55
|
}
|
|
54
56
|
return /*#__PURE__*/ (0, $doF98$react).createElement($59d09bcc83651bf9$var$SlotContext.Provider, {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J,CAAC,EAAE,EAAE,CAAA,GAAA,iBAAS,EAAE,WAAW,CAAC,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE,IAAI,CAAC;YAAE,CAAA,GAAI,CAAC,IAC1D;QAAC;QAAa;KAAM;IAE1B,qBACE,gCAAC,kCAAY,QAAQ;QAAC,OAAO;OAC1B;AAGP;AAEO,SAAS,0CAAW,KAAK;IAC9B,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAEhC,MAAM,WAAW,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA,CAAC,CAAA,GAAI,EAAE;IAEvC,IAAI,UAAU;IACd,IAAI,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,UAAU,MAAM,IAAI,GAC7C;QAAA,IAAI,OAAO,aAAa,YACtB,wBAAU,CAAA,GAAA,YAAI,EAAE,YAAY,CAAC,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;IAC9D;IAEF,qBACE,gCAAC,kCAAY,QAAQ;QAAC,OAAO;OAC1B;AAGP","sources":["packages/@react-spectrum/utils/src/Slots.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {mergeProps} from '@react-aria/utils';\nimport React, {useContext, useMemo} from 'react';\n\ninterface SlotProps {\n slot?: string\n}\n\nlet SlotContext = React.createContext<{} | null>(null);\n\nexport function useSlotProps<T>(props: T & {id?: string}, defaultSlot?: string): T {\n let slot = (props as SlotProps).slot || defaultSlot;\n // @ts-ignore TODO why is slot an object and not just string or undefined?\n let {[slot]: slotProps = {}} = useContext(SlotContext) || {};\n\n return mergeProps(props, mergeProps(slotProps, {id: props.id}));\n}\n\nexport function cssModuleToSlots(cssModule) {\n return Object.keys(cssModule).reduce((acc, slot) => {\n acc[slot] = {UNSAFE_className: cssModule[slot]};\n return acc;\n }, {});\n}\n\nexport function SlotProvider(props) {\n const emptyObj = useMemo(() => ({}), []);\n \n let parentSlots = useContext(SlotContext) || emptyObj;\n let {slots = emptyObj, children} = props;\n\n // Merge props for each slot from parent context and props\n let value = useMemo(() =>\n Object.keys(parentSlots)\n .concat(Object.keys(slots))\n .reduce((o, p) => ({\n ...o,\n [p]: mergeProps(parentSlots[p] || {}, slots[p] || {})}), {})\n , [parentSlots, slots]);\n\n return (\n <SlotContext.Provider value={value}>\n {children}\n </SlotContext.Provider>\n );\n}\n\nexport function ClearSlots(props) {\n let {children, ...otherProps} = props;\n\n const emptyObj = useMemo(() => ({}), []);\n\n let content = children;\n if (React.Children.toArray(children).length <= 1) {\n if (typeof children === 'function') { // need to know if the node is a string or something else that react can render that doesn't get props\n content = React.cloneElement(React.Children.only(children), otherProps);\n }\n }\n return (\n <SlotContext.Provider value={emptyObj}>\n {content}\n </SlotContext.Provider>\n );\n}\n"],"names":[],"version":3,"file":"Slots.module.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAIM,IAAI,4CAA+B;AAEnC,SAAS;IACd,4CAA+B;IAC/B,QAAQ,IAAI,CACV;AAIJ;AAEO,SAAS,0CAAW,SAAkC,EAAE,GAAG,MAA0C;IAC1G,IAAI,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAIM,IAAI,4CAA+B;AAEnC,SAAS;IACd,4CAA+B;IAC/B,QAAQ,IAAI,CACV;AAIJ;AAEO,SAAS,0CAAW,SAAkC,EAAE,GAAG,MAA0C;IAC1G,IAAI,UAAiC,EAAE;IACvC,KAAK,IAAI,SAAS,OAAQ;QACxB,IAAI,OAAO,UAAU,YAAY,OAAO;YACtC,IAAI,SAAS,CAAC;YACd,IAAK,IAAI,OAAO,MAAO;gBACrB,IAAI,SAAS,CAAC,IAAI,EAChB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI;gBAGrC,IAAI,6CAAgC,CAAC,SAAS,CAAC,IAAI,EACjD,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI;YAE5B;YAEA,QAAQ,IAAI,CAAC;QACf,OAAO,IAAI,OAAO,UAAU,UAAU;YACpC,IAAI,SAAS,CAAC,MAAM,EAClB,QAAQ,IAAI,CAAC,SAAS,CAAC,MAAM;YAG/B,IAAI,6CAAgC,CAAC,SAAS,CAAC,MAAM,EACnD,QAAQ,IAAI,CAAC;QAEjB,OACE,QAAQ,IAAI,CAAC;IAEjB;IAEA,OAAO,CAAA,GAAA,qCAAI,KAAK;AAClB","sources":["packages/@react-spectrum/utils/src/classNames.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport _clsx from 'clsx';\n\nexport let shouldKeepSpectrumClassNames = false;\n\nexport function keepSpectrumClassNames() {\n shouldKeepSpectrumClassNames = true;\n console.warn(\n 'Legacy spectrum-prefixed class names enabled for backward compatibility. ' +\n 'We recommend replacing instances of CSS overrides targeting spectrum selectors ' +\n 'in your app with custom class names of your own, and disabling this flag.'\n );\n}\n\nexport function classNames(cssModule: {[key: string]: string}, ...values: Array<string | Object | undefined>): string {\n let classes: Array<{} | undefined> = [];\n for (let value of values) {\n if (typeof value === 'object' && value) {\n let mapped = {};\n for (let key in value) {\n if (cssModule[key]) {\n mapped[cssModule[key]] = value[key];\n }\n\n if (shouldKeepSpectrumClassNames || !cssModule[key]) {\n mapped[key] = value[key];\n }\n }\n\n classes.push(mapped);\n } else if (typeof value === 'string') {\n if (cssModule[value]) {\n classes.push(cssModule[value]);\n }\n\n if (shouldKeepSpectrumClassNames || !cssModule[value]) {\n classes.push(value);\n }\n } else {\n classes.push(value);\n }\n }\n\n return _clsx(...classes);\n}\n"],"names":[],"version":3,"file":"classNames.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAIM,IAAI,4CAA+B;AAEnC,SAAS;IACd,4CAA+B;IAC/B,QAAQ,IAAI,CACV;AAIJ;AAEO,SAAS,0CAAW,SAAkC,EAAE,GAAG,MAA0C;IAC1G,IAAI,
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAIM,IAAI,4CAA+B;AAEnC,SAAS;IACd,4CAA+B;IAC/B,QAAQ,IAAI,CACV;AAIJ;AAEO,SAAS,0CAAW,SAAkC,EAAE,GAAG,MAA0C;IAC1G,IAAI,UAAiC,EAAE;IACvC,KAAK,IAAI,SAAS,OAAQ;QACxB,IAAI,OAAO,UAAU,YAAY,OAAO;YACtC,IAAI,SAAS,CAAC;YACd,IAAK,IAAI,OAAO,MAAO;gBACrB,IAAI,SAAS,CAAC,IAAI,EAChB,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI;gBAGrC,IAAI,6CAAgC,CAAC,SAAS,CAAC,IAAI,EACjD,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI;YAE5B;YAEA,QAAQ,IAAI,CAAC;QACf,OAAO,IAAI,OAAO,UAAU,UAAU;YACpC,IAAI,SAAS,CAAC,MAAM,EAClB,QAAQ,IAAI,CAAC,SAAS,CAAC,MAAM;YAG/B,IAAI,6CAAgC,CAAC,SAAS,CAAC,MAAM,EACnD,QAAQ,IAAI,CAAC;QAEjB,OACE,QAAQ,IAAI,CAAC;IAEjB;IAEA,OAAO,CAAA,GAAA,WAAI,KAAK;AAClB","sources":["packages/@react-spectrum/utils/src/classNames.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport _clsx from 'clsx';\n\nexport let shouldKeepSpectrumClassNames = false;\n\nexport function keepSpectrumClassNames() {\n shouldKeepSpectrumClassNames = true;\n console.warn(\n 'Legacy spectrum-prefixed class names enabled for backward compatibility. ' +\n 'We recommend replacing instances of CSS overrides targeting spectrum selectors ' +\n 'in your app with custom class names of your own, and disabling this flag.'\n );\n}\n\nexport function classNames(cssModule: {[key: string]: string}, ...values: Array<string | Object | undefined>): string {\n let classes: Array<{} | undefined> = [];\n for (let value of values) {\n if (typeof value === 'object' && value) {\n let mapped = {};\n for (let key in value) {\n if (cssModule[key]) {\n mapped[cssModule[key]] = value[key];\n }\n\n if (shouldKeepSpectrumClassNames || !cssModule[key]) {\n mapped[key] = value[key];\n }\n }\n\n classes.push(mapped);\n } else if (typeof value === 'string') {\n if (cssModule[value]) {\n classes.push(cssModule[value]);\n }\n\n if (shouldKeepSpectrumClassNames || !cssModule[value]) {\n classes.push(value);\n }\n } else {\n classes.push(value);\n }\n }\n\n return _clsx(...classes);\n}\n"],"names":[],"version":3,"file":"classNames.module.js.map"}
|
package/dist/styleProps.main.js
CHANGED
|
@@ -374,8 +374,8 @@ function $d3b73be57066120b$export$abc24f5b99744ea6(value) {
|
|
|
374
374
|
return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;
|
|
375
375
|
}
|
|
376
376
|
function $d3b73be57066120b$export$f348bec194f2e6b5(value, matchedBreakpoints) {
|
|
377
|
-
|
|
378
|
-
return $d3b73be57066120b$export$abc24f5b99744ea6(
|
|
377
|
+
let responsiveValue = $d3b73be57066120b$export$52dbfdbe1b2c3541(value, matchedBreakpoints);
|
|
378
|
+
if (responsiveValue != null) return $d3b73be57066120b$export$abc24f5b99744ea6(responsiveValue);
|
|
379
379
|
}
|
|
380
380
|
function $d3b73be57066120b$var$colorValue(value, type = 'default', version = 5) {
|
|
381
381
|
if (version > 5) return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAcM,MAAM,4CAAgC;IAC3C,QAAQ;QAAC;QAAU;KAAe;IAClC,aAAa;QAAC,0BAAI,cAAc;QAAgB;KAAe;IAC/D,WAAW;QAAC,0BAAI,eAAe;QAAe;KAAe;IAC7D,8CAA8C;IAC9C,gDAAgD;IAChD,WAAW;QAAC;QAAa;KAAe;IACxC,cAAc;QAAC;QAAgB;KAAe;IAC9C,SAAS;QAAC;YAAC;YAAc;SAAc;QAAE;KAAe;IACxD,SAAS;QAAC;YAAC;YAAa;SAAe;QAAE;KAAe;IACxD,OAAO;QAAC;QAAS;KAAe;IAChC,QAAQ;QAAC;QAAU;KAAe;IAClC,UAAU;QAAC;QAAY;KAAe;IACtC,WAAW;QAAC;QAAa;KAAe;IACxC,UAAU;QAAC;QAAY;KAAe;IACtC,WAAW;QAAC;QAAa;KAAe;IACxC,UAAU;QAAC;QAAW;KAAY;IAClC,WAAW;QAAC;QAAa;KAAiB;IAC1C,aAAa;QAAC;QAAe;KAAiB;IAC9C,UAAU;QAAC;QAAY;KAAS;IAChC,QAAQ;QAAC;QAAU;KAAS;IAC5B,KAAK;QAAC;QAAO;KAAe;IAC5B,Q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IAAI,QAAQ;QAAC,GAAG,YAAY;QAAE,GAAG,MAAM;IAAA;IAEvC,aAAa;IACb,IAAI,WAAW,SAAS,EACtB,QAAQ,IAAI,CACV;IAMJ,aAAa;IACb,IAAI,WAAW,KAAK,EAClB,QAAQ,IAAI,CACV;IAMJ,IAAI,aAA0C;eAC5C;QACA,WAAW;IACb;IAEA,IAAI,0CAAkB,MAAM,QAAQ,EAAE,qBACpC,WAAW,MAAM,GAAG;IAGtB,OAAO;oBACL;IACF;AACF;AAEO,SAAS,0CAAiB,KAAK;IACpC,OAAO;AACT;AAEO,SAAS,0CAAqB,IAAmB,EAAE,kBAAgC;IACxF,IAAI,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,OAAO,CAAC,OAAO;QAC5D,IAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,MAAM,EAAE,IAAK;YAClD,IAAI,aAAa,kBAAkB,CAAC,EAAE;YACtC,IAAI,IAAI,CAAC,WAAW,IAAI,MACtB,OAAO,IAAI,CAAC,WAAW;QAE3B;QACA,OAAO,AAAC,KAA2B,IAAI;IACzC;IACA,OAAO;AACT","sources":["packages/@react-spectrum/utils/src/styleProps.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BackgroundColorValue, BorderColorValue, BorderRadiusValue, BorderSizeValue, ColorValue, ColorVersion, DimensionValue, Direction, Responsive, ResponsiveProp, StyleProps, ViewStyleProps} from '@react-types/shared';\nimport {CSSProperties, HTMLAttributes} from 'react';\nimport {useBreakpoint} from './BreakpointProvider';\nimport {useLocale} from '@react-aria/i18n';\n\ntype Breakpoint = 'base' | 'S' | 'M' | 'L' | string;\ntype StyleName = string | string[] | ((dir: Direction) => string);\ntype StyleHandler = (value: any, colorVersion?: number) => string;\nexport interface StyleHandlers {\n [key: string]: [StyleName, StyleHandler]\n}\n\nexport const baseStyleProps: StyleHandlers = {\n margin: ['margin', dimensionValue],\n marginStart: [rtl('marginLeft', 'marginRight'), dimensionValue],\n marginEnd: [rtl('marginRight', 'marginLeft'), dimensionValue],\n // marginLeft: ['marginLeft', dimensionValue],\n // marginRight: ['marginRight', dimensionValue],\n marginTop: ['marginTop', dimensionValue],\n marginBottom: ['marginBottom', dimensionValue],\n marginX: [['marginLeft', 'marginRight'], dimensionValue],\n marginY: [['marginTop', 'marginBottom'], dimensionValue],\n width: ['width', dimensionValue],\n height: ['height', dimensionValue],\n minWidth: ['minWidth', dimensionValue],\n minHeight: ['minHeight', dimensionValue],\n maxWidth: ['maxWidth', dimensionValue],\n maxHeight: ['maxHeight', dimensionValue],\n isHidden: ['display', hiddenValue],\n alignSelf: ['alignSelf', passthroughStyle],\n justifySelf: ['justifySelf', passthroughStyle],\n position: ['position', anyValue],\n zIndex: ['zIndex', anyValue],\n top: ['top', dimensionValue],\n bottom: ['bottom', dimensionValue],\n start: [rtl('left', 'right'), dimensionValue],\n end: [rtl('right', 'left'), dimensionValue],\n left: ['left', dimensionValue],\n right: ['right', dimensionValue],\n order: ['order', anyValue],\n flex: ['flex', flexValue],\n flexGrow: ['flexGrow', passthroughStyle],\n flexShrink: ['flexShrink', passthroughStyle],\n flexBasis: ['flexBasis', passthroughStyle],\n gridArea: ['gridArea', passthroughStyle],\n gridColumn: ['gridColumn', passthroughStyle],\n gridColumnEnd: ['gridColumnEnd', passthroughStyle],\n gridColumnStart: ['gridColumnStart', passthroughStyle],\n gridRow: ['gridRow', passthroughStyle],\n gridRowEnd: ['gridRowEnd', passthroughStyle],\n gridRowStart: ['gridRowStart', passthroughStyle]\n};\n\nexport const viewStyleProps: StyleHandlers = {\n ...baseStyleProps,\n backgroundColor: ['backgroundColor', backgroundColorValue],\n borderWidth: ['borderWidth', borderSizeValue],\n borderStartWidth: [rtl('borderLeftWidth', 'borderRightWidth'), borderSizeValue],\n borderEndWidth: [rtl('borderRightWidth', 'borderLeftWidth'), borderSizeValue],\n borderLeftWidth: ['borderLeftWidth', borderSizeValue],\n borderRightWidth: ['borderRightWidth', borderSizeValue],\n borderTopWidth: ['borderTopWidth', borderSizeValue],\n borderBottomWidth: ['borderBottomWidth', borderSizeValue],\n borderXWidth: [['borderLeftWidth', 'borderRightWidth'], borderSizeValue],\n borderYWidth: [['borderTopWidth', 'borderBottomWidth'], borderSizeValue],\n borderColor: ['borderColor', borderColorValue],\n borderStartColor: [rtl('borderLeftColor', 'borderRightColor'), borderColorValue],\n borderEndColor: [rtl('borderRightColor', 'borderLeftColor'), borderColorValue],\n borderLeftColor: ['borderLeftColor', borderColorValue],\n borderRightColor: ['borderRightColor', borderColorValue],\n borderTopColor: ['borderTopColor', borderColorValue],\n borderBottomColor: ['borderBottomColor', borderColorValue],\n borderXColor: [['borderLeftColor', 'borderRightColor'], borderColorValue],\n borderYColor: [['borderTopColor', 'borderBottomColor'], borderColorValue],\n borderRadius: ['borderRadius', borderRadiusValue],\n borderTopStartRadius: [rtl('borderTopLeftRadius', 'borderTopRightRadius'), borderRadiusValue],\n borderTopEndRadius: [rtl('borderTopRightRadius', 'borderTopLeftRadius'), borderRadiusValue],\n borderBottomStartRadius: [rtl('borderBottomLeftRadius', 'borderBottomRightRadius'), borderRadiusValue],\n borderBottomEndRadius: [rtl('borderBottomRightRadius', 'borderBottomLeftRadius'), borderRadiusValue],\n borderTopLeftRadius: ['borderTopLeftRadius', borderRadiusValue],\n borderTopRightRadius: ['borderTopRightRadius', borderRadiusValue],\n borderBottomLeftRadius: ['borderBottomLeftRadius', borderRadiusValue],\n borderBottomRightRadius: ['borderBottomRightRadius', borderRadiusValue],\n padding: ['padding', dimensionValue],\n paddingStart: [rtl('paddingLeft', 'paddingRight'), dimensionValue],\n paddingEnd: [rtl('paddingRight', 'paddingLeft'), dimensionValue],\n paddingLeft: ['paddingLeft', dimensionValue],\n paddingRight: ['paddingRight', dimensionValue],\n paddingTop: ['paddingTop', dimensionValue],\n paddingBottom: ['paddingBottom', dimensionValue],\n paddingX: [['paddingLeft', 'paddingRight'], dimensionValue],\n paddingY: [['paddingTop', 'paddingBottom'], dimensionValue],\n overflow: ['overflow', passthroughStyle]\n};\n\nconst borderStyleProps = {\n borderWidth: 'borderStyle',\n borderLeftWidth: 'borderLeftStyle',\n borderRightWidth: 'borderRightStyle',\n borderTopWidth: 'borderTopStyle',\n borderBottomWidth: 'borderBottomStyle'\n};\n\nfunction rtl(ltr: string, rtl: string) {\n return (direction: Direction) => (\n direction === 'rtl' ? rtl : ltr\n );\n}\n\nconst UNIT_RE = /(%|px|em|rem|vw|vh|auto|cm|mm|in|pt|pc|ex|ch|rem|vmin|vmax|fr)$/;\nconst FUNC_RE = /^\\s*\\w+\\(/;\nconst SPECTRUM_VARIABLE_RE = /(static-)?size-\\d+|single-line-(height|width)/g;\n\nexport function dimensionValue(value: DimensionValue) {\n if (typeof value === 'number') {\n return value + 'px';\n }\n\n if (!value) {\n return undefined;\n }\n\n if (UNIT_RE.test(value)) {\n return value;\n }\n\n if (FUNC_RE.test(value)) {\n return value.replace(SPECTRUM_VARIABLE_RE, 'var(--spectrum-global-dimension-$&, var(--spectrum-alias-$&))');\n }\n\n return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;\n}\n\nexport function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]) {\n value = getResponsiveProp(value, matchedBreakpoints);\n return dimensionValue(value);\n}\n\ntype ColorType = 'default' | 'background' | 'border' | 'icon' | 'status';\nfunction colorValue(value: ColorValue, type: ColorType = 'default', version = 5) {\n if (version > 5) {\n return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;\n }\n\n return `var(--spectrum-legacy-color-${value}, var(--spectrum-global-color-${value}, var(--spectrum-semantic-${value}-color-${type})))`;\n}\n\nfunction backgroundColorValue(value: BackgroundColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-background-color-${value}, ${colorValue(value as ColorValue, 'background', version)})`;\n}\n\nfunction borderColorValue(value: BorderColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n if (value === 'default') {\n return 'var(--spectrum-alias-border-color)';\n }\n\n return `var(--spectrum-alias-border-color-${value}, ${colorValue(value as ColorValue, 'border', version)})`;\n}\n\nfunction borderSizeValue(value?: BorderSizeValue | null) {\n return value && value !== 'none'\n ? `var(--spectrum-alias-border-size-${value})`\n : '0';\n}\n\nfunction borderRadiusValue(value: BorderRadiusValue) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-border-radius-${value})`;\n}\n\nfunction hiddenValue(value: boolean) {\n return value ? 'none' : undefined;\n}\n\nfunction anyValue(value: any) {\n return value;\n}\n\nfunction flexValue(value: boolean | number | string) {\n if (typeof value === 'boolean') {\n return value ? '1' : undefined;\n }\n\n return '' + value;\n}\n\nexport function convertStyleProps<C extends ColorVersion>(props: ViewStyleProps<C>, handlers: StyleHandlers, direction: Direction, matchedBreakpoints: Breakpoint[]) {\n let style: CSSProperties = {};\n for (let key in props) {\n let styleProp = handlers[key];\n if (!styleProp || props[key] == null) {\n continue;\n }\n\n let [name, convert] = styleProp;\n if (typeof name === 'function') {\n name = name(direction);\n }\n\n let prop = getResponsiveProp(props[key], matchedBreakpoints);\n let value = convert(prop, props.colorVersion);\n if (Array.isArray(name)) {\n for (let k of name) {\n style[k] = value;\n }\n } else {\n style[name] = value;\n }\n }\n\n for (let prop in borderStyleProps) {\n if (style[prop]) {\n style[borderStyleProps[prop]] = 'solid';\n style.boxSizing = 'border-box';\n }\n }\n\n return style;\n}\n\ntype StylePropsOptions = {\n matchedBreakpoints?: Breakpoint[]\n};\n\nexport function useStyleProps<T extends StyleProps>(\n props: T,\n handlers: StyleHandlers = baseStyleProps,\n options: StylePropsOptions = {}\n) {\n let {\n UNSAFE_className,\n UNSAFE_style,\n ...otherProps\n } = props;\n let breakpointProvider = useBreakpoint();\n let {direction} = useLocale();\n let {\n matchedBreakpoints = breakpointProvider?.matchedBreakpoints || ['base']\n } = options;\n let styles = convertStyleProps(props, handlers, direction, matchedBreakpoints);\n let style = {...UNSAFE_style, ...styles};\n\n // @ts-ignore\n if (otherProps.className) {\n console.warn(\n 'The className prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_className if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n // @ts-ignore\n if (otherProps.style) {\n console.warn(\n 'The style prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_style if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n let styleProps: HTMLAttributes<HTMLElement> = {\n style,\n className: UNSAFE_className\n };\n\n if (getResponsiveProp(props.isHidden, matchedBreakpoints)) {\n styleProps.hidden = true;\n }\n\n return {\n styleProps\n };\n}\n\nexport function passthroughStyle(value) {\n return value;\n}\n\nexport function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T {\n if (prop && typeof prop === 'object' && !Array.isArray(prop)) {\n for (let i = 0; i < matchedBreakpoints.length; i++) {\n let breakpoint = matchedBreakpoints[i];\n if (prop[breakpoint] != null) {\n return prop[breakpoint];\n }\n }\n return (prop as ResponsiveProp<T>).base;\n }\n return prop as T;\n}\n"],"names":[],"version":3,"file":"styleProps.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAcM,MAAM,4CAAgC;IAC3C,QAAQ;QAAC;QAAU;KAAe;IAClC,aAAa;QAAC,0BAAI,cAAc;QAAgB;KAAe;IAC/D,WAAW;QAAC,0BAAI,eAAe;QAAe;KAAe;IAC7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B;QACA,OAAO,AAAC,KAA2B,IAAI;IACzC;IACA,OAAO;AACT","sources":["packages/@react-spectrum/utils/src/styleProps.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BackgroundColorValue, BorderColorValue, BorderRadiusValue, BorderSizeValue, ColorValue, ColorVersion, DimensionValue, Direction, Responsive, ResponsiveProp, StyleProps, ViewStyleProps} from '@react-types/shared';\nimport {CSSProperties, HTMLAttributes} from 'react';\nimport {useBreakpoint} from './BreakpointProvider';\nimport {useLocale} from '@react-aria/i18n';\n\ntype Breakpoint = 'base' | 'S' | 'M' | 'L' | string;\ntype StyleName = string | string[] | ((dir: Direction) => string);\ntype StyleHandler = (value: any, colorVersion?: number) => string | undefined;\nexport interface StyleHandlers {\n [key: string]: [StyleName, StyleHandler]\n}\n\nexport const baseStyleProps: StyleHandlers = {\n margin: ['margin', dimensionValue],\n marginStart: [rtl('marginLeft', 'marginRight'), dimensionValue],\n marginEnd: [rtl('marginRight', 'marginLeft'), dimensionValue],\n // marginLeft: ['marginLeft', dimensionValue],\n // marginRight: ['marginRight', dimensionValue],\n marginTop: ['marginTop', dimensionValue],\n marginBottom: ['marginBottom', dimensionValue],\n marginX: [['marginLeft', 'marginRight'], dimensionValue],\n marginY: [['marginTop', 'marginBottom'], dimensionValue],\n width: ['width', dimensionValue],\n height: ['height', dimensionValue],\n minWidth: ['minWidth', dimensionValue],\n minHeight: ['minHeight', dimensionValue],\n maxWidth: ['maxWidth', dimensionValue],\n maxHeight: ['maxHeight', dimensionValue],\n isHidden: ['display', hiddenValue],\n alignSelf: ['alignSelf', passthroughStyle],\n justifySelf: ['justifySelf', passthroughStyle],\n position: ['position', anyValue],\n zIndex: ['zIndex', anyValue],\n top: ['top', dimensionValue],\n bottom: ['bottom', dimensionValue],\n start: [rtl('left', 'right'), dimensionValue],\n end: [rtl('right', 'left'), dimensionValue],\n left: ['left', dimensionValue],\n right: ['right', dimensionValue],\n order: ['order', anyValue],\n flex: ['flex', flexValue],\n flexGrow: ['flexGrow', passthroughStyle],\n flexShrink: ['flexShrink', passthroughStyle],\n flexBasis: ['flexBasis', passthroughStyle],\n gridArea: ['gridArea', passthroughStyle],\n gridColumn: ['gridColumn', passthroughStyle],\n gridColumnEnd: ['gridColumnEnd', passthroughStyle],\n gridColumnStart: ['gridColumnStart', passthroughStyle],\n gridRow: ['gridRow', passthroughStyle],\n gridRowEnd: ['gridRowEnd', passthroughStyle],\n gridRowStart: ['gridRowStart', passthroughStyle]\n};\n\nexport const viewStyleProps: StyleHandlers = {\n ...baseStyleProps,\n backgroundColor: ['backgroundColor', backgroundColorValue],\n borderWidth: ['borderWidth', borderSizeValue],\n borderStartWidth: [rtl('borderLeftWidth', 'borderRightWidth'), borderSizeValue],\n borderEndWidth: [rtl('borderRightWidth', 'borderLeftWidth'), borderSizeValue],\n borderLeftWidth: ['borderLeftWidth', borderSizeValue],\n borderRightWidth: ['borderRightWidth', borderSizeValue],\n borderTopWidth: ['borderTopWidth', borderSizeValue],\n borderBottomWidth: ['borderBottomWidth', borderSizeValue],\n borderXWidth: [['borderLeftWidth', 'borderRightWidth'], borderSizeValue],\n borderYWidth: [['borderTopWidth', 'borderBottomWidth'], borderSizeValue],\n borderColor: ['borderColor', borderColorValue],\n borderStartColor: [rtl('borderLeftColor', 'borderRightColor'), borderColorValue],\n borderEndColor: [rtl('borderRightColor', 'borderLeftColor'), borderColorValue],\n borderLeftColor: ['borderLeftColor', borderColorValue],\n borderRightColor: ['borderRightColor', borderColorValue],\n borderTopColor: ['borderTopColor', borderColorValue],\n borderBottomColor: ['borderBottomColor', borderColorValue],\n borderXColor: [['borderLeftColor', 'borderRightColor'], borderColorValue],\n borderYColor: [['borderTopColor', 'borderBottomColor'], borderColorValue],\n borderRadius: ['borderRadius', borderRadiusValue],\n borderTopStartRadius: [rtl('borderTopLeftRadius', 'borderTopRightRadius'), borderRadiusValue],\n borderTopEndRadius: [rtl('borderTopRightRadius', 'borderTopLeftRadius'), borderRadiusValue],\n borderBottomStartRadius: [rtl('borderBottomLeftRadius', 'borderBottomRightRadius'), borderRadiusValue],\n borderBottomEndRadius: [rtl('borderBottomRightRadius', 'borderBottomLeftRadius'), borderRadiusValue],\n borderTopLeftRadius: ['borderTopLeftRadius', borderRadiusValue],\n borderTopRightRadius: ['borderTopRightRadius', borderRadiusValue],\n borderBottomLeftRadius: ['borderBottomLeftRadius', borderRadiusValue],\n borderBottomRightRadius: ['borderBottomRightRadius', borderRadiusValue],\n padding: ['padding', dimensionValue],\n paddingStart: [rtl('paddingLeft', 'paddingRight'), dimensionValue],\n paddingEnd: [rtl('paddingRight', 'paddingLeft'), dimensionValue],\n paddingLeft: ['paddingLeft', dimensionValue],\n paddingRight: ['paddingRight', dimensionValue],\n paddingTop: ['paddingTop', dimensionValue],\n paddingBottom: ['paddingBottom', dimensionValue],\n paddingX: [['paddingLeft', 'paddingRight'], dimensionValue],\n paddingY: [['paddingTop', 'paddingBottom'], dimensionValue],\n overflow: ['overflow', passthroughStyle]\n};\n\nconst borderStyleProps = {\n borderWidth: 'borderStyle',\n borderLeftWidth: 'borderLeftStyle',\n borderRightWidth: 'borderRightStyle',\n borderTopWidth: 'borderTopStyle',\n borderBottomWidth: 'borderBottomStyle'\n};\n\nfunction rtl(ltr: string, rtl: string) {\n return (direction: Direction) => (\n direction === 'rtl' ? rtl : ltr\n );\n}\n\nconst UNIT_RE = /(%|px|em|rem|vw|vh|auto|cm|mm|in|pt|pc|ex|ch|rem|vmin|vmax|fr)$/;\nconst FUNC_RE = /^\\s*\\w+\\(/;\nconst SPECTRUM_VARIABLE_RE = /(static-)?size-\\d+|single-line-(height|width)/g;\n\nexport function dimensionValue(value: DimensionValue) {\n if (typeof value === 'number') {\n return value + 'px';\n }\n\n if (!value) {\n return undefined;\n }\n\n if (UNIT_RE.test(value)) {\n return value;\n }\n\n if (FUNC_RE.test(value)) {\n return value.replace(SPECTRUM_VARIABLE_RE, 'var(--spectrum-global-dimension-$&, var(--spectrum-alias-$&))');\n }\n\n return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;\n}\n\nexport function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]) {\n let responsiveValue = getResponsiveProp(value, matchedBreakpoints);\n if (responsiveValue != null) {\n return dimensionValue(responsiveValue);\n }\n}\n\ntype ColorType = 'default' | 'background' | 'border' | 'icon' | 'status';\nfunction colorValue(value: ColorValue, type: ColorType = 'default', version = 5) {\n if (version > 5) {\n return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;\n }\n\n return `var(--spectrum-legacy-color-${value}, var(--spectrum-global-color-${value}, var(--spectrum-semantic-${value}-color-${type})))`;\n}\n\nfunction backgroundColorValue(value: BackgroundColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-background-color-${value}, ${colorValue(value as ColorValue, 'background', version)})`;\n}\n\nfunction borderColorValue(value: BorderColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n if (value === 'default') {\n return 'var(--spectrum-alias-border-color)';\n }\n\n return `var(--spectrum-alias-border-color-${value}, ${colorValue(value as ColorValue, 'border', version)})`;\n}\n\nfunction borderSizeValue(value?: BorderSizeValue | null) {\n return value && value !== 'none'\n ? `var(--spectrum-alias-border-size-${value})`\n : '0';\n}\n\nfunction borderRadiusValue(value: BorderRadiusValue) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-border-radius-${value})`;\n}\n\nfunction hiddenValue(value: boolean) {\n return value ? 'none' : undefined;\n}\n\nfunction anyValue(value: any) {\n return value;\n}\n\nfunction flexValue(value: boolean | number | string) {\n if (typeof value === 'boolean') {\n return value ? '1' : undefined;\n }\n\n return '' + value;\n}\n\nexport function convertStyleProps<C extends ColorVersion>(props: ViewStyleProps<C>, handlers: StyleHandlers, direction: Direction, matchedBreakpoints: Breakpoint[]) {\n let style: CSSProperties = {};\n for (let key in props) {\n let styleProp = handlers[key];\n if (!styleProp || props[key] == null) {\n continue;\n }\n\n let [name, convert] = styleProp;\n if (typeof name === 'function') {\n name = name(direction);\n }\n\n let prop = getResponsiveProp(props[key], matchedBreakpoints);\n let value = convert(prop, props.colorVersion);\n if (Array.isArray(name)) {\n for (let k of name) {\n style[k] = value;\n }\n } else {\n style[name] = value;\n }\n }\n\n for (let prop in borderStyleProps) {\n if (style[prop]) {\n style[borderStyleProps[prop]] = 'solid';\n style.boxSizing = 'border-box';\n }\n }\n\n return style;\n}\n\ntype StylePropsOptions = {\n matchedBreakpoints?: Breakpoint[]\n};\n\nexport function useStyleProps<T extends StyleProps>(\n props: T,\n handlers: StyleHandlers = baseStyleProps,\n options: StylePropsOptions = {}\n) {\n let {\n UNSAFE_className,\n UNSAFE_style,\n ...otherProps\n } = props;\n let breakpointProvider = useBreakpoint();\n let {direction} = useLocale();\n let {\n matchedBreakpoints = breakpointProvider?.matchedBreakpoints || ['base']\n } = options;\n let styles = convertStyleProps(props, handlers, direction, matchedBreakpoints);\n let style = {...UNSAFE_style, ...styles};\n\n // @ts-ignore\n if (otherProps.className) {\n console.warn(\n 'The className prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_className if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n // @ts-ignore\n if (otherProps.style) {\n console.warn(\n 'The style prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_style if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n let styleProps: HTMLAttributes<HTMLElement> = {\n style,\n className: UNSAFE_className\n };\n\n if (getResponsiveProp(props.isHidden, matchedBreakpoints)) {\n styleProps.hidden = true;\n }\n\n return {\n styleProps\n };\n}\n\nexport function passthroughStyle(value) {\n return value;\n}\n\nexport function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T | undefined {\n if (prop && typeof prop === 'object' && !Array.isArray(prop)) {\n for (let i = 0; i < matchedBreakpoints.length; i++) {\n let breakpoint = matchedBreakpoints[i];\n if (prop[breakpoint] != null) {\n return prop[breakpoint];\n }\n }\n return (prop as ResponsiveProp<T>).base;\n }\n return prop as T;\n}\n"],"names":[],"version":3,"file":"styleProps.main.js.map"}
|
package/dist/styleProps.mjs
CHANGED
|
@@ -361,8 +361,8 @@ function $380ed8f3903c3931$export$abc24f5b99744ea6(value) {
|
|
|
361
361
|
return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;
|
|
362
362
|
}
|
|
363
363
|
function $380ed8f3903c3931$export$f348bec194f2e6b5(value, matchedBreakpoints) {
|
|
364
|
-
|
|
365
|
-
return $380ed8f3903c3931$export$abc24f5b99744ea6(
|
|
364
|
+
let responsiveValue = $380ed8f3903c3931$export$52dbfdbe1b2c3541(value, matchedBreakpoints);
|
|
365
|
+
if (responsiveValue != null) return $380ed8f3903c3931$export$abc24f5b99744ea6(responsiveValue);
|
|
366
366
|
}
|
|
367
367
|
function $380ed8f3903c3931$var$colorValue(value, type = 'default', version = 5) {
|
|
368
368
|
if (version > 5) return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;
|
|
@@ -361,8 +361,8 @@ function $380ed8f3903c3931$export$abc24f5b99744ea6(value) {
|
|
|
361
361
|
return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;
|
|
362
362
|
}
|
|
363
363
|
function $380ed8f3903c3931$export$f348bec194f2e6b5(value, matchedBreakpoints) {
|
|
364
|
-
|
|
365
|
-
return $380ed8f3903c3931$export$abc24f5b99744ea6(
|
|
364
|
+
let responsiveValue = $380ed8f3903c3931$export$52dbfdbe1b2c3541(value, matchedBreakpoints);
|
|
365
|
+
if (responsiveValue != null) return $380ed8f3903c3931$export$abc24f5b99744ea6(responsiveValue);
|
|
366
366
|
}
|
|
367
367
|
function $380ed8f3903c3931$var$colorValue(value, type = 'default', version = 5) {
|
|
368
368
|
if (version > 5) return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAcM,MAAM,4CAAgC;IAC3C,QAAQ;QAAC;QAAU;KAAe;IAClC,aAAa;QAAC,0BAAI,cAAc;QAAgB;KAAe;IAC/D,WAAW;QAAC,0BAAI,eAAe;QAAe;KAAe;IAC7D,8CAA8C;IAC9C,gDAAgD;IAChD,WAAW;QAAC;QAAa;KAAe;IACxC,cAAc;QAAC;QAAgB;KAAe;IAC9C,SAAS;QAAC;YAAC;YAAc;SAAc;QAAE;KAAe;IACxD,SAAS;QAAC;YAAC;YAAa;SAAe;QAAE;KAAe;IACxD,OAAO;QAAC;QAAS;KAAe;IAChC,QAAQ;QAAC;QAAU;KAAe;IAClC,UAAU;QAAC;QAAY;KAAe;IACtC,WAAW;QAAC;QAAa;KAAe;IACxC,UAAU;QAAC;QAAY;KAAe;IACtC,WAAW;QAAC;QAAa;KAAe;IACxC,UAAU;QAAC;QAAW;KAAY;IAClC,WAAW;QAAC;QAAa;KAAiB;IAC1C,aAAa;QAAC;QAAe;KAAiB;IAC9C,UAAU;QAAC;QAAY;KAAS;IAChC,QAAQ;QAAC;QAAU;KAAS;IAC5B,KAAK;QAAC;QAAO;KAAe;IAC5B,QAAQ;QAAC;QAAU;KAAe;IAClC,OAAO;QAAC,0BAAI,QAAQ;QAAU;KAAe;IAC7C,KAAK;QAAC,0BAAI,SAAS;QAAS;KAAe;IAC3C,MAAM;QAAC;QAAQ;KAAe;IAC9B,OAAO;QAAC;QAAS;KAAe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IAMJ,IAAI,aAA0C;eAC5C;QACA,WAAW;IACb;IAEA,IAAI,0CAAkB,MAAM,QAAQ,EAAE,qBACpC,WAAW,MAAM,GAAG;IAGtB,OAAO;oBACL;IACF;AACF;AAEO,SAAS,0CAAiB,KAAK;IACpC,OAAO;AACT;AAEO,SAAS,0CAAqB,IAAmB,EAAE,kBAAgC;IACxF,IAAI,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,OAAO,CAAC,OAAO;QAC5D,IAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,MAAM,EAAE,IAAK;YAClD,IAAI,aAAa,kBAAkB,CAAC,EAAE;YACtC,IAAI,IAAI,CAAC,WAAW,IAAI,MACtB,OAAO,IAAI,CAAC,WAAW;QAE3B;QACA,OAAO,AAAC,KAA2B,IAAI;IACzC;IACA,OAAO;AACT","sources":["packages/@react-spectrum/utils/src/styleProps.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BackgroundColorValue, BorderColorValue, BorderRadiusValue, BorderSizeValue, ColorValue, ColorVersion, DimensionValue, Direction, Responsive, ResponsiveProp, StyleProps, ViewStyleProps} from '@react-types/shared';\nimport {CSSProperties, HTMLAttributes} from 'react';\nimport {useBreakpoint} from './BreakpointProvider';\nimport {useLocale} from '@react-aria/i18n';\n\ntype Breakpoint = 'base' | 'S' | 'M' | 'L' | string;\ntype StyleName = string | string[] | ((dir: Direction) => string);\ntype StyleHandler = (value: any, colorVersion?: number) => string;\nexport interface StyleHandlers {\n [key: string]: [StyleName, StyleHandler]\n}\n\nexport const baseStyleProps: StyleHandlers = {\n margin: ['margin', dimensionValue],\n marginStart: [rtl('marginLeft', 'marginRight'), dimensionValue],\n marginEnd: [rtl('marginRight', 'marginLeft'), dimensionValue],\n // marginLeft: ['marginLeft', dimensionValue],\n // marginRight: ['marginRight', dimensionValue],\n marginTop: ['marginTop', dimensionValue],\n marginBottom: ['marginBottom', dimensionValue],\n marginX: [['marginLeft', 'marginRight'], dimensionValue],\n marginY: [['marginTop', 'marginBottom'], dimensionValue],\n width: ['width', dimensionValue],\n height: ['height', dimensionValue],\n minWidth: ['minWidth', dimensionValue],\n minHeight: ['minHeight', dimensionValue],\n maxWidth: ['maxWidth', dimensionValue],\n maxHeight: ['maxHeight', dimensionValue],\n isHidden: ['display', hiddenValue],\n alignSelf: ['alignSelf', passthroughStyle],\n justifySelf: ['justifySelf', passthroughStyle],\n position: ['position', anyValue],\n zIndex: ['zIndex', anyValue],\n top: ['top', dimensionValue],\n bottom: ['bottom', dimensionValue],\n start: [rtl('left', 'right'), dimensionValue],\n end: [rtl('right', 'left'), dimensionValue],\n left: ['left', dimensionValue],\n right: ['right', dimensionValue],\n order: ['order', anyValue],\n flex: ['flex', flexValue],\n flexGrow: ['flexGrow', passthroughStyle],\n flexShrink: ['flexShrink', passthroughStyle],\n flexBasis: ['flexBasis', passthroughStyle],\n gridArea: ['gridArea', passthroughStyle],\n gridColumn: ['gridColumn', passthroughStyle],\n gridColumnEnd: ['gridColumnEnd', passthroughStyle],\n gridColumnStart: ['gridColumnStart', passthroughStyle],\n gridRow: ['gridRow', passthroughStyle],\n gridRowEnd: ['gridRowEnd', passthroughStyle],\n gridRowStart: ['gridRowStart', passthroughStyle]\n};\n\nexport const viewStyleProps: StyleHandlers = {\n ...baseStyleProps,\n backgroundColor: ['backgroundColor', backgroundColorValue],\n borderWidth: ['borderWidth', borderSizeValue],\n borderStartWidth: [rtl('borderLeftWidth', 'borderRightWidth'), borderSizeValue],\n borderEndWidth: [rtl('borderRightWidth', 'borderLeftWidth'), borderSizeValue],\n borderLeftWidth: ['borderLeftWidth', borderSizeValue],\n borderRightWidth: ['borderRightWidth', borderSizeValue],\n borderTopWidth: ['borderTopWidth', borderSizeValue],\n borderBottomWidth: ['borderBottomWidth', borderSizeValue],\n borderXWidth: [['borderLeftWidth', 'borderRightWidth'], borderSizeValue],\n borderYWidth: [['borderTopWidth', 'borderBottomWidth'], borderSizeValue],\n borderColor: ['borderColor', borderColorValue],\n borderStartColor: [rtl('borderLeftColor', 'borderRightColor'), borderColorValue],\n borderEndColor: [rtl('borderRightColor', 'borderLeftColor'), borderColorValue],\n borderLeftColor: ['borderLeftColor', borderColorValue],\n borderRightColor: ['borderRightColor', borderColorValue],\n borderTopColor: ['borderTopColor', borderColorValue],\n borderBottomColor: ['borderBottomColor', borderColorValue],\n borderXColor: [['borderLeftColor', 'borderRightColor'], borderColorValue],\n borderYColor: [['borderTopColor', 'borderBottomColor'], borderColorValue],\n borderRadius: ['borderRadius', borderRadiusValue],\n borderTopStartRadius: [rtl('borderTopLeftRadius', 'borderTopRightRadius'), borderRadiusValue],\n borderTopEndRadius: [rtl('borderTopRightRadius', 'borderTopLeftRadius'), borderRadiusValue],\n borderBottomStartRadius: [rtl('borderBottomLeftRadius', 'borderBottomRightRadius'), borderRadiusValue],\n borderBottomEndRadius: [rtl('borderBottomRightRadius', 'borderBottomLeftRadius'), borderRadiusValue],\n borderTopLeftRadius: ['borderTopLeftRadius', borderRadiusValue],\n borderTopRightRadius: ['borderTopRightRadius', borderRadiusValue],\n borderBottomLeftRadius: ['borderBottomLeftRadius', borderRadiusValue],\n borderBottomRightRadius: ['borderBottomRightRadius', borderRadiusValue],\n padding: ['padding', dimensionValue],\n paddingStart: [rtl('paddingLeft', 'paddingRight'), dimensionValue],\n paddingEnd: [rtl('paddingRight', 'paddingLeft'), dimensionValue],\n paddingLeft: ['paddingLeft', dimensionValue],\n paddingRight: ['paddingRight', dimensionValue],\n paddingTop: ['paddingTop', dimensionValue],\n paddingBottom: ['paddingBottom', dimensionValue],\n paddingX: [['paddingLeft', 'paddingRight'], dimensionValue],\n paddingY: [['paddingTop', 'paddingBottom'], dimensionValue],\n overflow: ['overflow', passthroughStyle]\n};\n\nconst borderStyleProps = {\n borderWidth: 'borderStyle',\n borderLeftWidth: 'borderLeftStyle',\n borderRightWidth: 'borderRightStyle',\n borderTopWidth: 'borderTopStyle',\n borderBottomWidth: 'borderBottomStyle'\n};\n\nfunction rtl(ltr: string, rtl: string) {\n return (direction: Direction) => (\n direction === 'rtl' ? rtl : ltr\n );\n}\n\nconst UNIT_RE = /(%|px|em|rem|vw|vh|auto|cm|mm|in|pt|pc|ex|ch|rem|vmin|vmax|fr)$/;\nconst FUNC_RE = /^\\s*\\w+\\(/;\nconst SPECTRUM_VARIABLE_RE = /(static-)?size-\\d+|single-line-(height|width)/g;\n\nexport function dimensionValue(value: DimensionValue) {\n if (typeof value === 'number') {\n return value + 'px';\n }\n\n if (!value) {\n return undefined;\n }\n\n if (UNIT_RE.test(value)) {\n return value;\n }\n\n if (FUNC_RE.test(value)) {\n return value.replace(SPECTRUM_VARIABLE_RE, 'var(--spectrum-global-dimension-$&, var(--spectrum-alias-$&))');\n }\n\n return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;\n}\n\nexport function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]) {\n value = getResponsiveProp(value, matchedBreakpoints);\n return dimensionValue(value);\n}\n\ntype ColorType = 'default' | 'background' | 'border' | 'icon' | 'status';\nfunction colorValue(value: ColorValue, type: ColorType = 'default', version = 5) {\n if (version > 5) {\n return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;\n }\n\n return `var(--spectrum-legacy-color-${value}, var(--spectrum-global-color-${value}, var(--spectrum-semantic-${value}-color-${type})))`;\n}\n\nfunction backgroundColorValue(value: BackgroundColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-background-color-${value}, ${colorValue(value as ColorValue, 'background', version)})`;\n}\n\nfunction borderColorValue(value: BorderColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n if (value === 'default') {\n return 'var(--spectrum-alias-border-color)';\n }\n\n return `var(--spectrum-alias-border-color-${value}, ${colorValue(value as ColorValue, 'border', version)})`;\n}\n\nfunction borderSizeValue(value?: BorderSizeValue | null) {\n return value && value !== 'none'\n ? `var(--spectrum-alias-border-size-${value})`\n : '0';\n}\n\nfunction borderRadiusValue(value: BorderRadiusValue) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-border-radius-${value})`;\n}\n\nfunction hiddenValue(value: boolean) {\n return value ? 'none' : undefined;\n}\n\nfunction anyValue(value: any) {\n return value;\n}\n\nfunction flexValue(value: boolean | number | string) {\n if (typeof value === 'boolean') {\n return value ? '1' : undefined;\n }\n\n return '' + value;\n}\n\nexport function convertStyleProps<C extends ColorVersion>(props: ViewStyleProps<C>, handlers: StyleHandlers, direction: Direction, matchedBreakpoints: Breakpoint[]) {\n let style: CSSProperties = {};\n for (let key in props) {\n let styleProp = handlers[key];\n if (!styleProp || props[key] == null) {\n continue;\n }\n\n let [name, convert] = styleProp;\n if (typeof name === 'function') {\n name = name(direction);\n }\n\n let prop = getResponsiveProp(props[key], matchedBreakpoints);\n let value = convert(prop, props.colorVersion);\n if (Array.isArray(name)) {\n for (let k of name) {\n style[k] = value;\n }\n } else {\n style[name] = value;\n }\n }\n\n for (let prop in borderStyleProps) {\n if (style[prop]) {\n style[borderStyleProps[prop]] = 'solid';\n style.boxSizing = 'border-box';\n }\n }\n\n return style;\n}\n\ntype StylePropsOptions = {\n matchedBreakpoints?: Breakpoint[]\n};\n\nexport function useStyleProps<T extends StyleProps>(\n props: T,\n handlers: StyleHandlers = baseStyleProps,\n options: StylePropsOptions = {}\n) {\n let {\n UNSAFE_className,\n UNSAFE_style,\n ...otherProps\n } = props;\n let breakpointProvider = useBreakpoint();\n let {direction} = useLocale();\n let {\n matchedBreakpoints = breakpointProvider?.matchedBreakpoints || ['base']\n } = options;\n let styles = convertStyleProps(props, handlers, direction, matchedBreakpoints);\n let style = {...UNSAFE_style, ...styles};\n\n // @ts-ignore\n if (otherProps.className) {\n console.warn(\n 'The className prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_className if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n // @ts-ignore\n if (otherProps.style) {\n console.warn(\n 'The style prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_style if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n let styleProps: HTMLAttributes<HTMLElement> = {\n style,\n className: UNSAFE_className\n };\n\n if (getResponsiveProp(props.isHidden, matchedBreakpoints)) {\n styleProps.hidden = true;\n }\n\n return {\n styleProps\n };\n}\n\nexport function passthroughStyle(value) {\n return value;\n}\n\nexport function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T {\n if (prop && typeof prop === 'object' && !Array.isArray(prop)) {\n for (let i = 0; i < matchedBreakpoints.length; i++) {\n let breakpoint = matchedBreakpoints[i];\n if (prop[breakpoint] != null) {\n return prop[breakpoint];\n }\n }\n return (prop as ResponsiveProp<T>).base;\n }\n return prop as T;\n}\n"],"names":[],"version":3,"file":"styleProps.module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAcM,MAAM,4CAAgC;IAC3C,QAAQ;QAAC;QAAU;KAAe;IAClC,aAAa;QAAC,0BAAI,cAAc;QAAgB;KAAe;IAC/D,WAAW;QAAC,0BAAI,eAAe;QAAe;KAAe;IAC7D,8CAA8C;IAC9C,gDAAgD;IAChD,WAAW;QAAC;QAAa;KAAe;IACxC,cAAc;QAAC;QAAgB;KAAe;IAC9C,SAAS;QAAC;YAAC;YAAc;SAAc;QAAE;KAAe;IACxD,SAAS;QAAC;YAAC;YAAa;SAAe;QAAE;KAAe;IACxD,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;IACpB;IAGF,OAAO;AACT;AAMO,SAAS,0CACd,KAAQ,EACR,WAA0B,yCAAc,EACxC,UAA6B,CAAC,CAAC;IAE/B,IAAI,oBACF,gBAAgB,gBAChB,YAAY,EACZ,GAAG,YACJ,GAAG;IACJ,IAAI,qBAAqB,CAAA,GAAA,yCAAY;IACrC,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,sBACF,qBAAqB,CAAA,+BAAA,yCAAA,mBAAoB,kBAAkB,KAAI;QAAC;KAAO,EACxE,GAAG;IACJ,IAAI,SAAS,0CAAkB,OAAO,UAAU,WAAW;IAC3D,IAAI,QAAQ;QAAC,GAAG,YAAY;QAAE,GAAG,MAAM;IAAA;IAEvC,aAAa;IACb,IAAI,WAAW,SAAS,EACtB,QAAQ,IAAI,CACV;IAMJ,aAAa;IACb,IAAI,WAAW,KAAK,EAClB,QAAQ,IAAI,CACV;IAMJ,IAAI,aAA0C;eAC5C;QACA,WAAW;IACb;IAEA,IAAI,0CAAkB,MAAM,QAAQ,EAAE,qBACpC,WAAW,MAAM,GAAG;IAGtB,OAAO;oBACL;IACF;AACF;AAEO,SAAS,0CAAiB,KAAK;IACpC,OAAO;AACT;AAEO,SAAS,0CAAqB,IAAmB,EAAE,kBAAgC;IACxF,IAAI,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,OAAO,CAAC,OAAO;QAC5D,IAAK,IAAI,IAAI,GAAG,IAAI,mBAAmB,MAAM,EAAE,IAAK;YAClD,IAAI,aAAa,kBAAkB,CAAC,EAAE;YACtC,IAAI,IAAI,CAAC,WAAW,IAAI,MACtB,OAAO,IAAI,CAAC,WAAW;QAE3B;QACA,OAAO,AAAC,KAA2B,IAAI;IACzC;IACA,OAAO;AACT","sources":["packages/@react-spectrum/utils/src/styleProps.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BackgroundColorValue, BorderColorValue, BorderRadiusValue, BorderSizeValue, ColorValue, ColorVersion, DimensionValue, Direction, Responsive, ResponsiveProp, StyleProps, ViewStyleProps} from '@react-types/shared';\nimport {CSSProperties, HTMLAttributes} from 'react';\nimport {useBreakpoint} from './BreakpointProvider';\nimport {useLocale} from '@react-aria/i18n';\n\ntype Breakpoint = 'base' | 'S' | 'M' | 'L' | string;\ntype StyleName = string | string[] | ((dir: Direction) => string);\ntype StyleHandler = (value: any, colorVersion?: number) => string | undefined;\nexport interface StyleHandlers {\n [key: string]: [StyleName, StyleHandler]\n}\n\nexport const baseStyleProps: StyleHandlers = {\n margin: ['margin', dimensionValue],\n marginStart: [rtl('marginLeft', 'marginRight'), dimensionValue],\n marginEnd: [rtl('marginRight', 'marginLeft'), dimensionValue],\n // marginLeft: ['marginLeft', dimensionValue],\n // marginRight: ['marginRight', dimensionValue],\n marginTop: ['marginTop', dimensionValue],\n marginBottom: ['marginBottom', dimensionValue],\n marginX: [['marginLeft', 'marginRight'], dimensionValue],\n marginY: [['marginTop', 'marginBottom'], dimensionValue],\n width: ['width', dimensionValue],\n height: ['height', dimensionValue],\n minWidth: ['minWidth', dimensionValue],\n minHeight: ['minHeight', dimensionValue],\n maxWidth: ['maxWidth', dimensionValue],\n maxHeight: ['maxHeight', dimensionValue],\n isHidden: ['display', hiddenValue],\n alignSelf: ['alignSelf', passthroughStyle],\n justifySelf: ['justifySelf', passthroughStyle],\n position: ['position', anyValue],\n zIndex: ['zIndex', anyValue],\n top: ['top', dimensionValue],\n bottom: ['bottom', dimensionValue],\n start: [rtl('left', 'right'), dimensionValue],\n end: [rtl('right', 'left'), dimensionValue],\n left: ['left', dimensionValue],\n right: ['right', dimensionValue],\n order: ['order', anyValue],\n flex: ['flex', flexValue],\n flexGrow: ['flexGrow', passthroughStyle],\n flexShrink: ['flexShrink', passthroughStyle],\n flexBasis: ['flexBasis', passthroughStyle],\n gridArea: ['gridArea', passthroughStyle],\n gridColumn: ['gridColumn', passthroughStyle],\n gridColumnEnd: ['gridColumnEnd', passthroughStyle],\n gridColumnStart: ['gridColumnStart', passthroughStyle],\n gridRow: ['gridRow', passthroughStyle],\n gridRowEnd: ['gridRowEnd', passthroughStyle],\n gridRowStart: ['gridRowStart', passthroughStyle]\n};\n\nexport const viewStyleProps: StyleHandlers = {\n ...baseStyleProps,\n backgroundColor: ['backgroundColor', backgroundColorValue],\n borderWidth: ['borderWidth', borderSizeValue],\n borderStartWidth: [rtl('borderLeftWidth', 'borderRightWidth'), borderSizeValue],\n borderEndWidth: [rtl('borderRightWidth', 'borderLeftWidth'), borderSizeValue],\n borderLeftWidth: ['borderLeftWidth', borderSizeValue],\n borderRightWidth: ['borderRightWidth', borderSizeValue],\n borderTopWidth: ['borderTopWidth', borderSizeValue],\n borderBottomWidth: ['borderBottomWidth', borderSizeValue],\n borderXWidth: [['borderLeftWidth', 'borderRightWidth'], borderSizeValue],\n borderYWidth: [['borderTopWidth', 'borderBottomWidth'], borderSizeValue],\n borderColor: ['borderColor', borderColorValue],\n borderStartColor: [rtl('borderLeftColor', 'borderRightColor'), borderColorValue],\n borderEndColor: [rtl('borderRightColor', 'borderLeftColor'), borderColorValue],\n borderLeftColor: ['borderLeftColor', borderColorValue],\n borderRightColor: ['borderRightColor', borderColorValue],\n borderTopColor: ['borderTopColor', borderColorValue],\n borderBottomColor: ['borderBottomColor', borderColorValue],\n borderXColor: [['borderLeftColor', 'borderRightColor'], borderColorValue],\n borderYColor: [['borderTopColor', 'borderBottomColor'], borderColorValue],\n borderRadius: ['borderRadius', borderRadiusValue],\n borderTopStartRadius: [rtl('borderTopLeftRadius', 'borderTopRightRadius'), borderRadiusValue],\n borderTopEndRadius: [rtl('borderTopRightRadius', 'borderTopLeftRadius'), borderRadiusValue],\n borderBottomStartRadius: [rtl('borderBottomLeftRadius', 'borderBottomRightRadius'), borderRadiusValue],\n borderBottomEndRadius: [rtl('borderBottomRightRadius', 'borderBottomLeftRadius'), borderRadiusValue],\n borderTopLeftRadius: ['borderTopLeftRadius', borderRadiusValue],\n borderTopRightRadius: ['borderTopRightRadius', borderRadiusValue],\n borderBottomLeftRadius: ['borderBottomLeftRadius', borderRadiusValue],\n borderBottomRightRadius: ['borderBottomRightRadius', borderRadiusValue],\n padding: ['padding', dimensionValue],\n paddingStart: [rtl('paddingLeft', 'paddingRight'), dimensionValue],\n paddingEnd: [rtl('paddingRight', 'paddingLeft'), dimensionValue],\n paddingLeft: ['paddingLeft', dimensionValue],\n paddingRight: ['paddingRight', dimensionValue],\n paddingTop: ['paddingTop', dimensionValue],\n paddingBottom: ['paddingBottom', dimensionValue],\n paddingX: [['paddingLeft', 'paddingRight'], dimensionValue],\n paddingY: [['paddingTop', 'paddingBottom'], dimensionValue],\n overflow: ['overflow', passthroughStyle]\n};\n\nconst borderStyleProps = {\n borderWidth: 'borderStyle',\n borderLeftWidth: 'borderLeftStyle',\n borderRightWidth: 'borderRightStyle',\n borderTopWidth: 'borderTopStyle',\n borderBottomWidth: 'borderBottomStyle'\n};\n\nfunction rtl(ltr: string, rtl: string) {\n return (direction: Direction) => (\n direction === 'rtl' ? rtl : ltr\n );\n}\n\nconst UNIT_RE = /(%|px|em|rem|vw|vh|auto|cm|mm|in|pt|pc|ex|ch|rem|vmin|vmax|fr)$/;\nconst FUNC_RE = /^\\s*\\w+\\(/;\nconst SPECTRUM_VARIABLE_RE = /(static-)?size-\\d+|single-line-(height|width)/g;\n\nexport function dimensionValue(value: DimensionValue) {\n if (typeof value === 'number') {\n return value + 'px';\n }\n\n if (!value) {\n return undefined;\n }\n\n if (UNIT_RE.test(value)) {\n return value;\n }\n\n if (FUNC_RE.test(value)) {\n return value.replace(SPECTRUM_VARIABLE_RE, 'var(--spectrum-global-dimension-$&, var(--spectrum-alias-$&))');\n }\n\n return `var(--spectrum-global-dimension-${value}, var(--spectrum-alias-${value}))`;\n}\n\nexport function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]) {\n let responsiveValue = getResponsiveProp(value, matchedBreakpoints);\n if (responsiveValue != null) {\n return dimensionValue(responsiveValue);\n }\n}\n\ntype ColorType = 'default' | 'background' | 'border' | 'icon' | 'status';\nfunction colorValue(value: ColorValue, type: ColorType = 'default', version = 5) {\n if (version > 5) {\n return `var(--spectrum-${value}, var(--spectrum-semantic-${value}-color-${type}))`;\n }\n\n return `var(--spectrum-legacy-color-${value}, var(--spectrum-global-color-${value}, var(--spectrum-semantic-${value}-color-${type})))`;\n}\n\nfunction backgroundColorValue(value: BackgroundColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-background-color-${value}, ${colorValue(value as ColorValue, 'background', version)})`;\n}\n\nfunction borderColorValue(value: BorderColorValue, version = 5) {\n if (!value) {\n return undefined;\n }\n\n if (value === 'default') {\n return 'var(--spectrum-alias-border-color)';\n }\n\n return `var(--spectrum-alias-border-color-${value}, ${colorValue(value as ColorValue, 'border', version)})`;\n}\n\nfunction borderSizeValue(value?: BorderSizeValue | null) {\n return value && value !== 'none'\n ? `var(--spectrum-alias-border-size-${value})`\n : '0';\n}\n\nfunction borderRadiusValue(value: BorderRadiusValue) {\n if (!value) {\n return undefined;\n }\n\n return `var(--spectrum-alias-border-radius-${value})`;\n}\n\nfunction hiddenValue(value: boolean) {\n return value ? 'none' : undefined;\n}\n\nfunction anyValue(value: any) {\n return value;\n}\n\nfunction flexValue(value: boolean | number | string) {\n if (typeof value === 'boolean') {\n return value ? '1' : undefined;\n }\n\n return '' + value;\n}\n\nexport function convertStyleProps<C extends ColorVersion>(props: ViewStyleProps<C>, handlers: StyleHandlers, direction: Direction, matchedBreakpoints: Breakpoint[]) {\n let style: CSSProperties = {};\n for (let key in props) {\n let styleProp = handlers[key];\n if (!styleProp || props[key] == null) {\n continue;\n }\n\n let [name, convert] = styleProp;\n if (typeof name === 'function') {\n name = name(direction);\n }\n\n let prop = getResponsiveProp(props[key], matchedBreakpoints);\n let value = convert(prop, props.colorVersion);\n if (Array.isArray(name)) {\n for (let k of name) {\n style[k] = value;\n }\n } else {\n style[name] = value;\n }\n }\n\n for (let prop in borderStyleProps) {\n if (style[prop]) {\n style[borderStyleProps[prop]] = 'solid';\n style.boxSizing = 'border-box';\n }\n }\n\n return style;\n}\n\ntype StylePropsOptions = {\n matchedBreakpoints?: Breakpoint[]\n};\n\nexport function useStyleProps<T extends StyleProps>(\n props: T,\n handlers: StyleHandlers = baseStyleProps,\n options: StylePropsOptions = {}\n) {\n let {\n UNSAFE_className,\n UNSAFE_style,\n ...otherProps\n } = props;\n let breakpointProvider = useBreakpoint();\n let {direction} = useLocale();\n let {\n matchedBreakpoints = breakpointProvider?.matchedBreakpoints || ['base']\n } = options;\n let styles = convertStyleProps(props, handlers, direction, matchedBreakpoints);\n let style = {...UNSAFE_style, ...styles};\n\n // @ts-ignore\n if (otherProps.className) {\n console.warn(\n 'The className prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_className if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n // @ts-ignore\n if (otherProps.style) {\n console.warn(\n 'The style prop is unsafe and is unsupported in React Spectrum v3. ' +\n 'Please use style props with Spectrum variables, or UNSAFE_style if you absolutely must do something custom. ' +\n 'Note that this may break in future versions due to DOM structure changes.'\n );\n }\n\n let styleProps: HTMLAttributes<HTMLElement> = {\n style,\n className: UNSAFE_className\n };\n\n if (getResponsiveProp(props.isHidden, matchedBreakpoints)) {\n styleProps.hidden = true;\n }\n\n return {\n styleProps\n };\n}\n\nexport function passthroughStyle(value) {\n return value;\n}\n\nexport function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T | undefined {\n if (prop && typeof prop === 'object' && !Array.isArray(prop)) {\n for (let i = 0; i < matchedBreakpoints.length; i++) {\n let breakpoint = matchedBreakpoints[i];\n if (prop[breakpoint] != null) {\n return prop[breakpoint];\n }\n }\n return (prop as ResponsiveProp<T>).base;\n }\n return prop as T;\n}\n"],"names":[],"version":3,"file":"styleProps.module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -15,17 +15,17 @@ interface BreakpointProviderProps {
|
|
|
15
15
|
}
|
|
16
16
|
export function BreakpointProvider(props: BreakpointProviderProps): React.JSX.Element;
|
|
17
17
|
export function useMatchedBreakpoints(breakpoints: Breakpoints): string[];
|
|
18
|
-
export function useBreakpoint(): BreakpointContext;
|
|
18
|
+
export function useBreakpoint(): BreakpointContext | null;
|
|
19
19
|
type Breakpoint = 'base' | 'S' | 'M' | 'L' | string;
|
|
20
20
|
type StyleName = string | string[] | ((dir: Direction) => string);
|
|
21
|
-
type StyleHandler = (value: any, colorVersion?: number) => string;
|
|
21
|
+
type StyleHandler = (value: any, colorVersion?: number) => string | undefined;
|
|
22
22
|
export interface StyleHandlers {
|
|
23
23
|
[key: string]: [StyleName, StyleHandler];
|
|
24
24
|
}
|
|
25
25
|
export const baseStyleProps: StyleHandlers;
|
|
26
26
|
export const viewStyleProps: StyleHandlers;
|
|
27
|
-
export function dimensionValue(value: DimensionValue): string;
|
|
28
|
-
export function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]): string;
|
|
27
|
+
export function dimensionValue(value: DimensionValue): string | undefined;
|
|
28
|
+
export function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]): string | undefined;
|
|
29
29
|
export function convertStyleProps<C extends ColorVersion>(props: ViewStyleProps<C>, handlers: StyleHandlers, direction: Direction, matchedBreakpoints: Breakpoint[]): CSSProperties;
|
|
30
30
|
type StylePropsOptions = {
|
|
31
31
|
matchedBreakpoints?: Breakpoint[];
|
|
@@ -34,7 +34,7 @@ export function useStyleProps<T extends StyleProps>(props: T, handlers?: StyleHa
|
|
|
34
34
|
styleProps: HTMLAttributes<HTMLElement>;
|
|
35
35
|
};
|
|
36
36
|
export function passthroughStyle(value: any): any;
|
|
37
|
-
export function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T;
|
|
37
|
+
export function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T | undefined;
|
|
38
38
|
export let shouldKeepSpectrumClassNames: boolean;
|
|
39
39
|
export function keepSpectrumClassNames(): void;
|
|
40
40
|
export function classNames(cssModule: {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAGA;IACE,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACrC;AAED;IACE,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAKD;IACE,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED,mCAAmC,KAAK,EAAE,uBAAuB,qBAWhE;AAED,sCAAsC,WAAW,EAAE,WAAW,GAAG,MAAM,EAAE,CAoDxE;AAED,
|
|
1
|
+
{"mappings":";;AAGA;IACE,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACrC;AAED;IACE,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAKD;IACE,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,kBAAkB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED,mCAAmC,KAAK,EAAE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CAAC,EAAE,MAAM,CAAA;CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,CAAC,CAMjF;AAED,iCAAiC,SAAS,KAAA,MAKzC;AAED,6BAA6B,KAAK,KAAA,qBAoBjC;AAED,2BAA2B,KAAK,KAAA,qBAgB/B;AC1DD,4BAA4B,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,WAM5E;ACND,qCAAqC,OAAO,CAO3C;ACSD,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC","sources":["packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/BreakpointProvider.tsx","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/styleProps.ts","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/classNames.ts","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/getWrappedElement.tsx","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/useMediaQuery.ts","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/useDOMRef.ts","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/Slots.tsx","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/useHasChild.ts","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/useIsMobileDevice.ts","packages/@react-spectrum/utils/src/packages/@react-spectrum/utils/src/index.ts","packages/@react-spectrum/utils/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/// <reference types=\"css-module-types\" />\n\nexport type {StyleHandlers} from './styleProps';\nexport {shouldKeepSpectrumClassNames, keepSpectrumClassNames, classNames} from './classNames';\nexport {getWrappedElement} from './getWrappedElement';\nexport {useMediaQuery} from './useMediaQuery';\nexport {createDOMRef, createFocusableRef, useDOMRef, useFocusableRef, unwrapDOMRef, useUnwrapDOMRef} from './useDOMRef';\nexport {\n baseStyleProps,\n viewStyleProps,\n dimensionValue,\n responsiveDimensionValue,\n convertStyleProps,\n useStyleProps,\n passthroughStyle,\n getResponsiveProp\n} from './styleProps';\nexport {useSlotProps, cssModuleToSlots, SlotProvider, ClearSlots} from './Slots';\nexport {useHasChild} from './useHasChild';\nexport {useIsMobileDevice} from './useIsMobileDevice';\nexport {useValueEffect} from '@react-aria/utils';\nexport {BreakpointProvider, useMatchedBreakpoints, useBreakpoint} from './BreakpointProvider';\nexport {useResizeObserver} from '@react-aria/utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -24,17 +24,19 @@
|
|
|
24
24
|
"url": "https://github.com/adobe/react-spectrum"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@react-aria/i18n": "^3.12.
|
|
28
|
-
"@react-aria/ssr": "^3.9.
|
|
29
|
-
"@react-aria/utils": "^3.
|
|
30
|
-
"@react-types/shared": "^3.
|
|
27
|
+
"@react-aria/i18n": "^3.12.5",
|
|
28
|
+
"@react-aria/ssr": "^3.9.7",
|
|
29
|
+
"@react-aria/utils": "^3.27.0",
|
|
30
|
+
"@react-types/shared": "^3.27.0",
|
|
31
31
|
"@swc/helpers": "^0.5.0",
|
|
32
32
|
"clsx": "^2.0.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
35
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
36
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
|
38
39
|
"access": "public"
|
|
39
|
-
}
|
|
40
|
-
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
|
|
42
|
+
}
|
|
@@ -12,7 +12,7 @@ interface BreakpointContext {
|
|
|
12
12
|
matchedBreakpoints: string[]
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const Context = React.createContext<BreakpointContext>(null);
|
|
15
|
+
const Context = React.createContext<BreakpointContext | null>(null);
|
|
16
16
|
Context.displayName = 'BreakpointContext';
|
|
17
17
|
|
|
18
18
|
interface BreakpointProviderProps {
|
|
@@ -34,12 +34,12 @@ export function BreakpointProvider(props: BreakpointProviderProps) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function useMatchedBreakpoints(breakpoints: Breakpoints): string[] {
|
|
37
|
-
let entries = Object.entries(breakpoints).sort(([, valueA], [, valueB]) => valueB - valueA);
|
|
37
|
+
let entries = Object.entries(breakpoints).sort(([, valueA], [, valueB]) => valueB! - valueA!);
|
|
38
38
|
let breakpointQueries = entries.map(([, value]) => `(min-width: ${value}px)`);
|
|
39
39
|
|
|
40
40
|
let supportsMatchMedia = typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
41
41
|
let getBreakpointHandler = () => {
|
|
42
|
-
let matched = [];
|
|
42
|
+
let matched: string[] = [];
|
|
43
43
|
for (let i in breakpointQueries) {
|
|
44
44
|
let query = breakpointQueries[i];
|
|
45
45
|
if (window.matchMedia(query).matches) {
|
|
@@ -87,6 +87,6 @@ export function useMatchedBreakpoints(breakpoints: Breakpoints): string[] {
|
|
|
87
87
|
return isSSR ? ['base'] : breakpoint;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export function useBreakpoint()
|
|
90
|
+
export function useBreakpoint() {
|
|
91
91
|
return useContext(Context);
|
|
92
92
|
}
|
package/src/Slots.tsx
CHANGED
|
@@ -17,10 +17,11 @@ interface SlotProps {
|
|
|
17
17
|
slot?: string
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
let SlotContext = React.createContext(null);
|
|
20
|
+
let SlotContext = React.createContext<{} | null>(null);
|
|
21
21
|
|
|
22
22
|
export function useSlotProps<T>(props: T & {id?: string}, defaultSlot?: string): T {
|
|
23
23
|
let slot = (props as SlotProps).slot || defaultSlot;
|
|
24
|
+
// @ts-ignore TODO why is slot an object and not just string or undefined?
|
|
24
25
|
let {[slot]: slotProps = {}} = useContext(SlotContext) || {};
|
|
25
26
|
|
|
26
27
|
return mergeProps(props, mergeProps(slotProps, {id: props.id}));
|
|
@@ -34,9 +35,10 @@ export function cssModuleToSlots(cssModule) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export function SlotProvider(props) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let
|
|
38
|
+
const emptyObj = useMemo(() => ({}), []);
|
|
39
|
+
|
|
40
|
+
let parentSlots = useContext(SlotContext) || emptyObj;
|
|
41
|
+
let {slots = emptyObj, children} = props;
|
|
40
42
|
|
|
41
43
|
// Merge props for each slot from parent context and props
|
|
42
44
|
let value = useMemo(() =>
|
|
@@ -56,6 +58,9 @@ export function SlotProvider(props) {
|
|
|
56
58
|
|
|
57
59
|
export function ClearSlots(props) {
|
|
58
60
|
let {children, ...otherProps} = props;
|
|
61
|
+
|
|
62
|
+
const emptyObj = useMemo(() => ({}), []);
|
|
63
|
+
|
|
59
64
|
let content = children;
|
|
60
65
|
if (React.Children.toArray(children).length <= 1) {
|
|
61
66
|
if (typeof children === 'function') { // need to know if the node is a string or something else that react can render that doesn't get props
|
|
@@ -63,7 +68,7 @@ export function ClearSlots(props) {
|
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
return (
|
|
66
|
-
<SlotContext.Provider value={
|
|
71
|
+
<SlotContext.Provider value={emptyObj}>
|
|
67
72
|
{content}
|
|
68
73
|
</SlotContext.Provider>
|
|
69
74
|
);
|
package/src/classNames.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function keepSpectrumClassNames() {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function classNames(cssModule: {[key: string]: string}, ...values: Array<string | Object | undefined>): string {
|
|
27
|
-
let classes = [];
|
|
27
|
+
let classes: Array<{} | undefined> = [];
|
|
28
28
|
for (let value of values) {
|
|
29
29
|
if (typeof value === 'object' && value) {
|
|
30
30
|
let mapped = {};
|
package/src/styleProps.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {useLocale} from '@react-aria/i18n';
|
|
|
17
17
|
|
|
18
18
|
type Breakpoint = 'base' | 'S' | 'M' | 'L' | string;
|
|
19
19
|
type StyleName = string | string[] | ((dir: Direction) => string);
|
|
20
|
-
type StyleHandler = (value: any, colorVersion?: number) => string;
|
|
20
|
+
type StyleHandler = (value: any, colorVersion?: number) => string | undefined;
|
|
21
21
|
export interface StyleHandlers {
|
|
22
22
|
[key: string]: [StyleName, StyleHandler]
|
|
23
23
|
}
|
|
@@ -144,8 +144,10 @@ export function dimensionValue(value: DimensionValue) {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
export function responsiveDimensionValue(value: Responsive<DimensionValue>, matchedBreakpoints: Breakpoint[]) {
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
let responsiveValue = getResponsiveProp(value, matchedBreakpoints);
|
|
148
|
+
if (responsiveValue != null) {
|
|
149
|
+
return dimensionValue(responsiveValue);
|
|
150
|
+
}
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
type ColorType = 'default' | 'background' | 'border' | 'icon' | 'status';
|
|
@@ -299,7 +301,7 @@ export function passthroughStyle(value) {
|
|
|
299
301
|
return value;
|
|
300
302
|
}
|
|
301
303
|
|
|
302
|
-
export function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T {
|
|
304
|
+
export function getResponsiveProp<T>(prop: Responsive<T>, matchedBreakpoints: Breakpoint[]): T | undefined {
|
|
303
305
|
if (prop && typeof prop === 'object' && !Array.isArray(prop)) {
|
|
304
306
|
for (let i = 0; i < matchedBreakpoints.length; i++) {
|
|
305
307
|
let breakpoint = matchedBreakpoints[i];
|