@react-spectrum/buttongroup 3.5.1-nightly.3599 → 3.5.1-nightly.3600
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/dist/main.js +48 -28
- package/dist/main.js.map +1 -1
- package/dist/module.mjs +48 -28
- package/dist/module.mjs.map +1 -1
- package/package.json +11 -11
package/dist/main.js
CHANGED
|
@@ -12,7 +12,28 @@ function $parcel$interopDefault(a) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
$parcel$export(module.exports, "ButtonGroup", () => $d384d3249418a107$export$69b1032f2ecdf404);
|
|
15
|
-
|
|
15
|
+
/*
|
|
16
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
17
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
19
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
22
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
23
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
24
|
+
* governing permissions and limitations under the License.
|
|
25
|
+
*/ /// <reference types="css-module-types" />
|
|
26
|
+
/*
|
|
27
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
28
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
29
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
30
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
33
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
34
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
35
|
+
* governing permissions and limitations under the License.
|
|
36
|
+
*/
|
|
16
37
|
|
|
17
38
|
|
|
18
39
|
|
|
@@ -36,26 +57,25 @@ $2e9803b3bbead7d0$export$84d9c0e1917a4eaf = "spectrum-ButtonGroup--vertical_b10c
|
|
|
36
57
|
|
|
37
58
|
|
|
38
59
|
function $d384d3249418a107$var$ButtonGroup(props, ref) {
|
|
39
|
-
let { scale: scale } = $fJaYF$reactspectrumprovider.useProvider();
|
|
40
|
-
props = $fJaYF$reactspectrumprovider.useProviderProps(props);
|
|
41
|
-
props = $fJaYF$reactspectrumutils.useSlotProps(props,
|
|
42
|
-
let { children: children , orientation: orientation =
|
|
43
|
-
let { styleProps: styleProps } = $fJaYF$reactspectrumutils.useStyleProps(otherProps);
|
|
44
|
-
let domRef = $fJaYF$reactspectrumutils.useDOMRef(ref);
|
|
45
|
-
let [hasOverflow, setHasOverflow] = $fJaYF$reactariautils.useValueEffect(false);
|
|
46
|
-
let checkForOverflow = $fJaYF$react.useCallback(()=>{
|
|
60
|
+
let { scale: scale } = (0, $fJaYF$reactspectrumprovider.useProvider)();
|
|
61
|
+
props = (0, $fJaYF$reactspectrumprovider.useProviderProps)(props);
|
|
62
|
+
props = (0, $fJaYF$reactspectrumutils.useSlotProps)(props, "buttonGroup");
|
|
63
|
+
let { children: children , orientation: orientation = "horizontal" , isDisabled: isDisabled , align: align = "start" , ...otherProps } = props;
|
|
64
|
+
let { styleProps: styleProps } = (0, $fJaYF$reactspectrumutils.useStyleProps)(otherProps);
|
|
65
|
+
let domRef = (0, $fJaYF$reactspectrumutils.useDOMRef)(ref);
|
|
66
|
+
let [hasOverflow, setHasOverflow] = (0, $fJaYF$reactariautils.useValueEffect)(false);
|
|
67
|
+
let checkForOverflow = (0, $fJaYF$react.useCallback)(()=>{
|
|
47
68
|
let computeHasOverflow = ()=>{
|
|
48
|
-
if (domRef.current && orientation ===
|
|
69
|
+
if (domRef.current && orientation === "horizontal") {
|
|
49
70
|
let buttonGroupChildren = Array.from(domRef.current.children);
|
|
50
71
|
let maxX = domRef.current.offsetWidth + 1; // + 1 to account for rounding errors
|
|
51
72
|
// If any buttons have negative X positions (align="end") or extend beyond
|
|
52
73
|
// the width of the button group (align="start"), then switch to vertical.
|
|
53
|
-
if (buttonGroupChildren.some((child)=>child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX
|
|
54
|
-
)) return true;
|
|
74
|
+
if (buttonGroupChildren.some((child)=>child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX)) return true;
|
|
55
75
|
return false;
|
|
56
76
|
}
|
|
57
77
|
};
|
|
58
|
-
if (orientation ===
|
|
78
|
+
if (orientation === "horizontal") setHasOverflow(function*() {
|
|
59
79
|
// Force to horizontal for measurement.
|
|
60
80
|
yield false;
|
|
61
81
|
// Measure, and update if there is overflow.
|
|
@@ -71,45 +91,45 @@ function $d384d3249418a107$var$ButtonGroup(props, ref) {
|
|
|
71
91
|
]);
|
|
72
92
|
// There are two main reasons we need to remeasure:
|
|
73
93
|
// 1. Internal changes: Check for initial overflow or when orientation/scale/children change (from checkForOverflow dep array)
|
|
74
|
-
$fJaYF$reactariautils.useLayoutEffect(()=>{
|
|
94
|
+
(0, $fJaYF$reactariautils.useLayoutEffect)(()=>{
|
|
75
95
|
checkForOverflow();
|
|
76
96
|
}, [
|
|
77
97
|
checkForOverflow
|
|
78
98
|
]);
|
|
79
99
|
// 2. External changes: buttongroup won't change size due to any parents changing size, so listen to its container for size changes to figure out if we should remeasure
|
|
80
|
-
let parent = $fJaYF$react.useRef();
|
|
81
|
-
$fJaYF$reactariautils.useLayoutEffect(()=>{
|
|
100
|
+
let parent = (0, $fJaYF$react.useRef)();
|
|
101
|
+
(0, $fJaYF$reactariautils.useLayoutEffect)(()=>{
|
|
82
102
|
if (domRef.current) parent.current = domRef.current.parentElement;
|
|
83
103
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
104
|
}, [
|
|
85
105
|
domRef.current
|
|
86
106
|
]);
|
|
87
|
-
$fJaYF$reactspectrumutils.useResizeObserver({
|
|
107
|
+
(0, $fJaYF$reactspectrumutils.useResizeObserver)({
|
|
88
108
|
ref: parent,
|
|
89
109
|
onResize: checkForOverflow
|
|
90
110
|
});
|
|
91
|
-
return
|
|
92
|
-
|
|
111
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($fJaYF$react))).createElement("div", {
|
|
112
|
+
...(0, $fJaYF$reactariautils.filterDOMProps)(otherProps),
|
|
93
113
|
...styleProps,
|
|
94
114
|
ref: domRef,
|
|
95
|
-
className: $fJaYF$reactspectrumutils.classNames((/*@__PURE__*/$parcel$interopDefault($2e9803b3bbead7d0$exports)),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
115
|
+
className: (0, $fJaYF$reactspectrumutils.classNames)((0, (/*@__PURE__*/$parcel$interopDefault($2e9803b3bbead7d0$exports))), "spectrum-ButtonGroup", {
|
|
116
|
+
"spectrum-ButtonGroup--vertical": orientation === "vertical" || hasOverflow,
|
|
117
|
+
"spectrum-ButtonGroup--alignEnd": align === "end",
|
|
118
|
+
"spectrum-ButtonGroup--alignCenter": align === "center"
|
|
99
119
|
}, styleProps.className)
|
|
100
|
-
}, /*#__PURE__*/ ($parcel$interopDefault($fJaYF$react)).createElement($fJaYF$reactspectrumutils.SlotProvider, {
|
|
120
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($fJaYF$react))).createElement((0, $fJaYF$reactspectrumutils.SlotProvider), {
|
|
101
121
|
slots: {
|
|
102
122
|
button: {
|
|
103
|
-
UNSAFE_className: $fJaYF$reactspectrumutils.classNames((/*@__PURE__*/$parcel$interopDefault($2e9803b3bbead7d0$exports)),
|
|
123
|
+
UNSAFE_className: (0, $fJaYF$reactspectrumutils.classNames)((0, (/*@__PURE__*/$parcel$interopDefault($2e9803b3bbead7d0$exports))), "spectrum-ButtonGroup-Button")
|
|
104
124
|
}
|
|
105
125
|
}
|
|
106
|
-
}, /*#__PURE__*/ ($parcel$interopDefault($fJaYF$react)).createElement($fJaYF$reactspectrumprovider.Provider, {
|
|
126
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($fJaYF$react))).createElement((0, $fJaYF$reactspectrumprovider.Provider), {
|
|
107
127
|
isDisabled: isDisabled
|
|
108
|
-
}, children)))
|
|
128
|
+
}, children)));
|
|
109
129
|
}
|
|
110
130
|
/**
|
|
111
131
|
* ButtonGroup handles overflow for a grouping of buttons whose actions are related to each other.
|
|
112
|
-
*/ let $d384d3249418a107$export$69b1032f2ecdf404 = /*#__PURE__*/ ($parcel$interopDefault($fJaYF$react)).forwardRef($d384d3249418a107$var$ButtonGroup);
|
|
132
|
+
*/ let $d384d3249418a107$export$69b1032f2ecdf404 = /*#__PURE__*/ (0, ($parcel$interopDefault($fJaYF$react))).forwardRef($d384d3249418a107$var$ButtonGroup);
|
|
113
133
|
|
|
114
134
|
|
|
115
135
|
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GACD,0CAA0C;ACX1C;;;;;;;;;;CAUC,GAED;;;;;;;;;;;ACZA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAJA,4CAAyC;AACzC,4CAAgD;AAChD,4CAAmD;AACnD,2CAAsD;AACtD,4CAAmD;;;ADuBnD,SAAS,kCAAY,KAA+B,EAAE,GAA2B,EAAE;IACjF,IAAI,SAAC,MAAK,EAAC,GAAG,CAAA,GAAA,wCAAW,AAAD;IACxB,QAAQ,CAAA,GAAA,6CAAe,EAAE;IACzB,QAAQ,CAAA,GAAA,sCAAY,AAAD,EAAE,OAAO;IAE5B,IAAI,YACF,SAAQ,eACR,cAAc,2BACd,WAAU,SACV,QAAQ,UACR,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,uCAAa,AAAD,EAAE;IACjC,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE;IACvB,IAAI,CAAC,aAAa,eAAe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AkC,gBAAgB,cAAc;YAChE,kCAAkC,UAAU;YAC5C,qCAAqC,UAAU;QACjD,GACA,WAAW,SAAS;qBAGxB,0DAAC,CAAA,GAAA,sCAAW;QACV,OAAO;YACL,QAAQ;gBACN,kBAAkB,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,gEAAM,AAAD,GAAG;YACvC;QACF;qBACA,0DAAC,CAAA,GAAA,qCAAO;QAAE,YAAY;OACnB;AAKX;AAEA;;CAEC,GACD,IAAI,0DAAe,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC;;AD3GpC","sources":["packages/@react-spectrum/buttongroup/src/index.ts","packages/@react-spectrum/buttongroup/src/ButtonGroup.tsx","packages/@adobe/spectrum-css-temp/components/buttongroup/vars.css"],"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/// <reference types=\"css-module-types\" />\nexport {ButtonGroup} from './ButtonGroup';\nexport type {SpectrumButtonGroupProps} from '@react-types/buttongroup';\n","/*\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 {\n classNames,\n SlotProvider,\n useDOMRef,\n useResizeObserver,\n useSlotProps,\n useStyleProps\n} from '@react-spectrum/utils';\nimport {DOMRef} from '@react-types/shared';\nimport {filterDOMProps, useLayoutEffect, useValueEffect} from '@react-aria/utils';\nimport {Provider, useProvider, useProviderProps} from '@react-spectrum/provider';\nimport React, {useCallback, useRef} from 'react';\nimport {SpectrumButtonGroupProps} from '@react-types/buttongroup';\nimport styles from '@adobe/spectrum-css-temp/components/buttongroup/vars.css';\n\nfunction ButtonGroup(props: SpectrumButtonGroupProps, ref: DOMRef<HTMLDivElement>) {\n let {scale} = useProvider();\n props = useProviderProps(props);\n props = useSlotProps(props, 'buttonGroup');\n\n let {\n children,\n orientation = 'horizontal',\n isDisabled,\n align = 'start',\n ...otherProps\n } = props;\n\n let {styleProps} = useStyleProps(otherProps);\n let domRef = useDOMRef(ref);\n let [hasOverflow, setHasOverflow] = useValueEffect(false);\n\n let checkForOverflow = useCallback(() => {\n let computeHasOverflow = () => {\n if (domRef.current && orientation === 'horizontal') {\n let buttonGroupChildren = Array.from(domRef.current.children) as HTMLElement[];\n let maxX = domRef.current.offsetWidth + 1; // + 1 to account for rounding errors\n // If any buttons have negative X positions (align=\"end\") or extend beyond\n // the width of the button group (align=\"start\"), then switch to vertical.\n if (buttonGroupChildren.some(child => child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX)) {\n return true;\n }\n return false;\n }\n };\n if (orientation === 'horizontal') {\n setHasOverflow(function* () {\n // Force to horizontal for measurement.\n yield false;\n\n // Measure, and update if there is overflow.\n yield computeHasOverflow();\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [domRef, orientation, scale, setHasOverflow, children]);\n\n // There are two main reasons we need to remeasure:\n // 1. Internal changes: Check for initial overflow or when orientation/scale/children change (from checkForOverflow dep array)\n useLayoutEffect(() => {\n checkForOverflow();\n }, [checkForOverflow]);\n\n // 2. External changes: buttongroup won't change size due to any parents changing size, so listen to its container for size changes to figure out if we should remeasure\n let parent = useRef<HTMLElement>();\n useLayoutEffect(() => {\n if (domRef.current) {\n parent.current = domRef.current.parentElement as HTMLElement;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [domRef.current]);\n useResizeObserver({ref: parent, onResize: checkForOverflow});\n\n return (\n <div\n {...filterDOMProps(otherProps)}\n {...styleProps}\n ref={domRef}\n className={\n classNames(\n styles,\n 'spectrum-ButtonGroup',\n {\n 'spectrum-ButtonGroup--vertical': orientation === 'vertical' || hasOverflow,\n 'spectrum-ButtonGroup--alignEnd': align === 'end',\n 'spectrum-ButtonGroup--alignCenter': align === 'center'\n },\n styleProps.className\n )\n }>\n <SlotProvider\n slots={{\n button: {\n UNSAFE_className: classNames(styles, 'spectrum-ButtonGroup-Button')\n }\n }}>\n <Provider isDisabled={isDisabled}>\n {children}\n </Provider>\n </SlotProvider>\n </div>\n );\n}\n\n/**\n * ButtonGroup handles overflow for a grouping of buttons whose actions are related to each other.\n */\nlet _ButtonGroup = React.forwardRef(ButtonGroup);\nexport {_ButtonGroup as ButtonGroup};\n","/*\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@import './index.css';\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.mjs
CHANGED
|
@@ -10,7 +10,28 @@ function $parcel$interopDefault(a) {
|
|
|
10
10
|
function $parcel$export(e, n, v, s) {
|
|
11
11
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
/*
|
|
14
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
15
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
17
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
21
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
+
* governing permissions and limitations under the License.
|
|
23
|
+
*/ /// <reference types="css-module-types" />
|
|
24
|
+
/*
|
|
25
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
26
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
28
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
29
|
+
*
|
|
30
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
31
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
32
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
33
|
+
* governing permissions and limitations under the License.
|
|
34
|
+
*/
|
|
14
35
|
|
|
15
36
|
|
|
16
37
|
|
|
@@ -34,26 +55,25 @@ $fddc5368d2db28a6$export$84d9c0e1917a4eaf = "spectrum-ButtonGroup--vertical_b10c
|
|
|
34
55
|
|
|
35
56
|
|
|
36
57
|
function $bd4bfa55854eb3bf$var$ButtonGroup(props, ref) {
|
|
37
|
-
let { scale: scale } = $3Yfv0$useProvider();
|
|
38
|
-
props = $3Yfv0$useProviderProps(props);
|
|
39
|
-
props = $3Yfv0$useSlotProps(props,
|
|
40
|
-
let { children: children , orientation: orientation =
|
|
41
|
-
let { styleProps: styleProps } = $3Yfv0$useStyleProps(otherProps);
|
|
42
|
-
let domRef = $3Yfv0$useDOMRef(ref);
|
|
43
|
-
let [hasOverflow, setHasOverflow] = $3Yfv0$useValueEffect(false);
|
|
44
|
-
let checkForOverflow = $3Yfv0$useCallback(()=>{
|
|
58
|
+
let { scale: scale } = (0, $3Yfv0$useProvider)();
|
|
59
|
+
props = (0, $3Yfv0$useProviderProps)(props);
|
|
60
|
+
props = (0, $3Yfv0$useSlotProps)(props, "buttonGroup");
|
|
61
|
+
let { children: children , orientation: orientation = "horizontal" , isDisabled: isDisabled , align: align = "start" , ...otherProps } = props;
|
|
62
|
+
let { styleProps: styleProps } = (0, $3Yfv0$useStyleProps)(otherProps);
|
|
63
|
+
let domRef = (0, $3Yfv0$useDOMRef)(ref);
|
|
64
|
+
let [hasOverflow, setHasOverflow] = (0, $3Yfv0$useValueEffect)(false);
|
|
65
|
+
let checkForOverflow = (0, $3Yfv0$useCallback)(()=>{
|
|
45
66
|
let computeHasOverflow = ()=>{
|
|
46
|
-
if (domRef.current && orientation ===
|
|
67
|
+
if (domRef.current && orientation === "horizontal") {
|
|
47
68
|
let buttonGroupChildren = Array.from(domRef.current.children);
|
|
48
69
|
let maxX = domRef.current.offsetWidth + 1; // + 1 to account for rounding errors
|
|
49
70
|
// If any buttons have negative X positions (align="end") or extend beyond
|
|
50
71
|
// the width of the button group (align="start"), then switch to vertical.
|
|
51
|
-
if (buttonGroupChildren.some((child)=>child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX
|
|
52
|
-
)) return true;
|
|
72
|
+
if (buttonGroupChildren.some((child)=>child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX)) return true;
|
|
53
73
|
return false;
|
|
54
74
|
}
|
|
55
75
|
};
|
|
56
|
-
if (orientation ===
|
|
76
|
+
if (orientation === "horizontal") setHasOverflow(function*() {
|
|
57
77
|
// Force to horizontal for measurement.
|
|
58
78
|
yield false;
|
|
59
79
|
// Measure, and update if there is overflow.
|
|
@@ -69,45 +89,45 @@ function $bd4bfa55854eb3bf$var$ButtonGroup(props, ref) {
|
|
|
69
89
|
]);
|
|
70
90
|
// There are two main reasons we need to remeasure:
|
|
71
91
|
// 1. Internal changes: Check for initial overflow or when orientation/scale/children change (from checkForOverflow dep array)
|
|
72
|
-
$3Yfv0$useLayoutEffect(()=>{
|
|
92
|
+
(0, $3Yfv0$useLayoutEffect)(()=>{
|
|
73
93
|
checkForOverflow();
|
|
74
94
|
}, [
|
|
75
95
|
checkForOverflow
|
|
76
96
|
]);
|
|
77
97
|
// 2. External changes: buttongroup won't change size due to any parents changing size, so listen to its container for size changes to figure out if we should remeasure
|
|
78
|
-
let parent = $3Yfv0$useRef();
|
|
79
|
-
$3Yfv0$useLayoutEffect(()=>{
|
|
98
|
+
let parent = (0, $3Yfv0$useRef)();
|
|
99
|
+
(0, $3Yfv0$useLayoutEffect)(()=>{
|
|
80
100
|
if (domRef.current) parent.current = domRef.current.parentElement;
|
|
81
101
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
102
|
}, [
|
|
83
103
|
domRef.current
|
|
84
104
|
]);
|
|
85
|
-
$3Yfv0$useResizeObserver({
|
|
105
|
+
(0, $3Yfv0$useResizeObserver)({
|
|
86
106
|
ref: parent,
|
|
87
107
|
onResize: checkForOverflow
|
|
88
108
|
});
|
|
89
|
-
return
|
|
90
|
-
|
|
109
|
+
return /*#__PURE__*/ (0, $3Yfv0$react).createElement("div", {
|
|
110
|
+
...(0, $3Yfv0$filterDOMProps)(otherProps),
|
|
91
111
|
...styleProps,
|
|
92
112
|
ref: domRef,
|
|
93
|
-
className: $3Yfv0$classNames((/*@__PURE__*/$parcel$interopDefault($fddc5368d2db28a6$exports)),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
113
|
+
className: (0, $3Yfv0$classNames)((0, (/*@__PURE__*/$parcel$interopDefault($fddc5368d2db28a6$exports))), "spectrum-ButtonGroup", {
|
|
114
|
+
"spectrum-ButtonGroup--vertical": orientation === "vertical" || hasOverflow,
|
|
115
|
+
"spectrum-ButtonGroup--alignEnd": align === "end",
|
|
116
|
+
"spectrum-ButtonGroup--alignCenter": align === "center"
|
|
97
117
|
}, styleProps.className)
|
|
98
|
-
}, /*#__PURE__*/ $3Yfv0$react.createElement($3Yfv0$SlotProvider, {
|
|
118
|
+
}, /*#__PURE__*/ (0, $3Yfv0$react).createElement((0, $3Yfv0$SlotProvider), {
|
|
99
119
|
slots: {
|
|
100
120
|
button: {
|
|
101
|
-
UNSAFE_className: $3Yfv0$classNames((/*@__PURE__*/$parcel$interopDefault($fddc5368d2db28a6$exports)),
|
|
121
|
+
UNSAFE_className: (0, $3Yfv0$classNames)((0, (/*@__PURE__*/$parcel$interopDefault($fddc5368d2db28a6$exports))), "spectrum-ButtonGroup-Button")
|
|
102
122
|
}
|
|
103
123
|
}
|
|
104
|
-
}, /*#__PURE__*/ $3Yfv0$react.createElement($3Yfv0$Provider, {
|
|
124
|
+
}, /*#__PURE__*/ (0, $3Yfv0$react).createElement((0, $3Yfv0$Provider), {
|
|
105
125
|
isDisabled: isDisabled
|
|
106
|
-
}, children)))
|
|
126
|
+
}, children)));
|
|
107
127
|
}
|
|
108
128
|
/**
|
|
109
129
|
* ButtonGroup handles overflow for a grouping of buttons whose actions are related to each other.
|
|
110
|
-
*/ let $bd4bfa55854eb3bf$export$69b1032f2ecdf404 = /*#__PURE__*/ $3Yfv0$react.forwardRef($bd4bfa55854eb3bf$var$ButtonGroup);
|
|
130
|
+
*/ let $bd4bfa55854eb3bf$export$69b1032f2ecdf404 = /*#__PURE__*/ (0, $3Yfv0$react).forwardRef($bd4bfa55854eb3bf$var$ButtonGroup);
|
|
111
131
|
|
|
112
132
|
|
|
113
133
|
|
package/dist/module.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GACD,0CAA0C;ACX1C;;;;;;;;;;CAUC,GAED;;;;;;;;;;;ACZA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAJA,4CAAyC;AACzC,4CAAgD;AAChD,4CAAmD;AACnD,2CAAsD;AACtD,4CAAmD;;;ADuBnD,SAAS,kCAAY,KAA+B,EAAE,GAA2B,EAAE;I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;QACpB,IAAI,OAAO,OAAO,EAChB,OAAO,OAAO,GAAG,OAAO,OAAO,CAAC,aAAa;IAEjD,uDAAuD;IACvD,GAAG;QAAC,OAAO,OAAO;KAAC;IACnB,CAAA,GAAA,wBAAiB,AAAD,EAAE;QAAC,KAAK;QAAQ,UAAU;IAAgB;IAE1D,qBACE,gCAAC;QACE,GAAG,CAAA,GAAA,qBAAc,AAAD,EAAE,WAAW;QAC7B,GAAG,UAAU;QACd,KAAK;QACL,WACE,CAAA,GAAA,iBAAS,EACP,CAAA,GAAA,yDAAM,OAAD,GACL,wBACA;YACE,kCAAkC,gBAAgB,cAAc;YAChE,kCAAkC,UAAU;YAC5C,qCAAqC,UAAU;QACjD,GACA,WAAW,SAAS;qBAGxB,gCAAC,CAAA,GAAA,mBAAW;QACV,OAAO;YACL,QAAQ;gBACN,kBAAkB,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,gEAAM,AAAD,GAAG;YACvC;QACF;qBACA,gCAAC,CAAA,GAAA,eAAO;QAAE,YAAY;OACnB;AAKX;AAEA;;CAEC,GACD,IAAI,0DAAe,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC;;AD3GpC","sources":["packages/@react-spectrum/buttongroup/src/index.ts","packages/@react-spectrum/buttongroup/src/ButtonGroup.tsx","packages/@adobe/spectrum-css-temp/components/buttongroup/vars.css"],"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/// <reference types=\"css-module-types\" />\nexport {ButtonGroup} from './ButtonGroup';\nexport type {SpectrumButtonGroupProps} from '@react-types/buttongroup';\n","/*\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 {\n classNames,\n SlotProvider,\n useDOMRef,\n useResizeObserver,\n useSlotProps,\n useStyleProps\n} from '@react-spectrum/utils';\nimport {DOMRef} from '@react-types/shared';\nimport {filterDOMProps, useLayoutEffect, useValueEffect} from '@react-aria/utils';\nimport {Provider, useProvider, useProviderProps} from '@react-spectrum/provider';\nimport React, {useCallback, useRef} from 'react';\nimport {SpectrumButtonGroupProps} from '@react-types/buttongroup';\nimport styles from '@adobe/spectrum-css-temp/components/buttongroup/vars.css';\n\nfunction ButtonGroup(props: SpectrumButtonGroupProps, ref: DOMRef<HTMLDivElement>) {\n let {scale} = useProvider();\n props = useProviderProps(props);\n props = useSlotProps(props, 'buttonGroup');\n\n let {\n children,\n orientation = 'horizontal',\n isDisabled,\n align = 'start',\n ...otherProps\n } = props;\n\n let {styleProps} = useStyleProps(otherProps);\n let domRef = useDOMRef(ref);\n let [hasOverflow, setHasOverflow] = useValueEffect(false);\n\n let checkForOverflow = useCallback(() => {\n let computeHasOverflow = () => {\n if (domRef.current && orientation === 'horizontal') {\n let buttonGroupChildren = Array.from(domRef.current.children) as HTMLElement[];\n let maxX = domRef.current.offsetWidth + 1; // + 1 to account for rounding errors\n // If any buttons have negative X positions (align=\"end\") or extend beyond\n // the width of the button group (align=\"start\"), then switch to vertical.\n if (buttonGroupChildren.some(child => child.offsetLeft < 0 || child.offsetLeft + child.offsetWidth > maxX)) {\n return true;\n }\n return false;\n }\n };\n if (orientation === 'horizontal') {\n setHasOverflow(function* () {\n // Force to horizontal for measurement.\n yield false;\n\n // Measure, and update if there is overflow.\n yield computeHasOverflow();\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [domRef, orientation, scale, setHasOverflow, children]);\n\n // There are two main reasons we need to remeasure:\n // 1. Internal changes: Check for initial overflow or when orientation/scale/children change (from checkForOverflow dep array)\n useLayoutEffect(() => {\n checkForOverflow();\n }, [checkForOverflow]);\n\n // 2. External changes: buttongroup won't change size due to any parents changing size, so listen to its container for size changes to figure out if we should remeasure\n let parent = useRef<HTMLElement>();\n useLayoutEffect(() => {\n if (domRef.current) {\n parent.current = domRef.current.parentElement as HTMLElement;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [domRef.current]);\n useResizeObserver({ref: parent, onResize: checkForOverflow});\n\n return (\n <div\n {...filterDOMProps(otherProps)}\n {...styleProps}\n ref={domRef}\n className={\n classNames(\n styles,\n 'spectrum-ButtonGroup',\n {\n 'spectrum-ButtonGroup--vertical': orientation === 'vertical' || hasOverflow,\n 'spectrum-ButtonGroup--alignEnd': align === 'end',\n 'spectrum-ButtonGroup--alignCenter': align === 'center'\n },\n styleProps.className\n )\n }>\n <SlotProvider\n slots={{\n button: {\n UNSAFE_className: classNames(styles, 'spectrum-ButtonGroup-Button')\n }\n }}>\n <Provider isDisabled={isDisabled}>\n {children}\n </Provider>\n </SlotProvider>\n </div>\n );\n}\n\n/**\n * ButtonGroup handles overflow for a grouping of buttons whose actions are related to each other.\n */\nlet _ButtonGroup = React.forwardRef(ButtonGroup);\nexport {_ButtonGroup as ButtonGroup};\n","/*\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@import './index.css';\n"],"names":[],"version":3,"file":"module.mjs.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/buttongroup",
|
|
3
|
-
"version": "3.5.1-nightly.
|
|
3
|
+
"version": "3.5.1-nightly.3600+bfce84fee",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -36,17 +36,17 @@
|
|
|
36
36
|
"url": "https://github.com/adobe/react-spectrum"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@react-
|
|
41
|
-
"@react-spectrum/
|
|
42
|
-
"@react-spectrum/
|
|
43
|
-
"@react-
|
|
44
|
-
"@react-types/
|
|
45
|
-
"@
|
|
39
|
+
"@react-aria/utils": "3.0.0-nightly.1900+bfce84fee",
|
|
40
|
+
"@react-spectrum/button": "3.0.0-nightly.1900+bfce84fee",
|
|
41
|
+
"@react-spectrum/text": "3.3.4-nightly.3600+bfce84fee",
|
|
42
|
+
"@react-spectrum/utils": "3.0.0-nightly.1900+bfce84fee",
|
|
43
|
+
"@react-types/buttongroup": "3.2.6-nightly.3600+bfce84fee",
|
|
44
|
+
"@react-types/shared": "3.0.0-nightly.1900+bfce84fee",
|
|
45
|
+
"@swc/helpers": "^0.4.14"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@adobe/spectrum-css-temp": "3.0.0-nightly.
|
|
49
|
-
"@spectrum-icons/workflow": "3.0.0-nightly.
|
|
48
|
+
"@adobe/spectrum-css-temp": "3.0.0-nightly.1900+bfce84fee",
|
|
49
|
+
"@spectrum-icons/workflow": "3.0.0-nightly.1900+bfce84fee"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@react-spectrum/provider": "^3.0.0",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169"
|
|
59
59
|
}
|