@charcoal-ui/react 3.9.1 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DropdownSelector/MenuItem/internals/useMenuItemHandleKeyDown.d.ts.map +1 -1
- package/dist/components/DropdownSelector/MenuList/MenuListContext.d.ts +2 -1
- package/dist/components/DropdownSelector/MenuList/MenuListContext.d.ts.map +1 -1
- package/dist/components/DropdownSelector/MenuList/index.d.ts.map +1 -1
- package/dist/components/DropdownSelector/MenuList/internals/getValuesRecursive.d.ts +2 -1
- package/dist/components/DropdownSelector/MenuList/internals/getValuesRecursive.d.ts.map +1 -1
- package/dist/components/DropdownSelector/index.d.ts +4 -0
- package/dist/components/DropdownSelector/index.d.ts.map +1 -1
- package/dist/components/DropdownSelector/index.story.d.ts +12 -5
- package/dist/components/DropdownSelector/index.story.d.ts.map +1 -1
- package/dist/components/LoadingSpinner/LoadingSpinnerIcon.story.d.ts.map +1 -1
- package/dist/components/LoadingSpinner/index.story.d.ts.map +1 -1
- package/dist/index.cjs.js +44 -23
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +54 -33
- package/dist/index.esm.js.map +1 -1
- package/package.json +9 -7
- package/src/components/DropdownSelector/ListItem/__snapshots__/index.story.storyshot +5 -3
- package/src/components/DropdownSelector/ListItem/index.tsx +5 -1
- package/src/components/DropdownSelector/MenuItem/internals/useMenuItemHandleKeyDown.tsx +29 -18
- package/src/components/DropdownSelector/MenuList/MenuListContext.ts +3 -2
- package/src/components/DropdownSelector/MenuList/__snapshots__/index.story.storyshot +15 -9
- package/src/components/DropdownSelector/MenuList/index.tsx +6 -4
- package/src/components/DropdownSelector/MenuList/internals/getValuesRecursive.tsx +11 -8
- package/src/components/DropdownSelector/__snapshots__/index.story.storyshot +2666 -396
- package/src/components/DropdownSelector/index.story.tsx +264 -103
- package/src/components/DropdownSelector/index.tsx +35 -7
- package/src/components/LoadingSpinner/LoadingSpinnerIcon.story.tsx +1 -0
- package/src/components/LoadingSpinner/index.story.tsx +1 -0
- package/src/components/Modal/__snapshots__/index.story.storyshot +76 -0
package/dist/index.esm.js
CHANGED
|
@@ -1089,7 +1089,7 @@ var LoadingSpinnerIcon = forwardRef14(function LoadingSpinnerIcon2({
|
|
|
1089
1089
|
});
|
|
1090
1090
|
|
|
1091
1091
|
// src/components/DropdownSelector/index.tsx
|
|
1092
|
-
import { useState as useState3, useRef as useRef9 } from "react";
|
|
1092
|
+
import { useState as useState3, useRef as useRef9, useMemo as useMemo3 } from "react";
|
|
1093
1093
|
import styled16, { css as css9 } from "styled-components";
|
|
1094
1094
|
import { disabledSelector as disabledSelector2 } from "@charcoal-ui/utils";
|
|
1095
1095
|
|
|
@@ -1208,7 +1208,7 @@ function findPreviewRecursive(children, value) {
|
|
|
1208
1208
|
}
|
|
1209
1209
|
|
|
1210
1210
|
// src/components/DropdownSelector/MenuList/index.tsx
|
|
1211
|
-
import { useRef as useRef8 } from "react";
|
|
1211
|
+
import { useMemo as useMemo2, useRef as useRef8 } from "react";
|
|
1212
1212
|
import styled15 from "styled-components";
|
|
1213
1213
|
|
|
1214
1214
|
// src/components/DropdownSelector/MenuList/MenuListContext.ts
|
|
@@ -1216,40 +1216,43 @@ import { createContext as createContext6 } from "react";
|
|
|
1216
1216
|
var MenuListContext = createContext6({
|
|
1217
1217
|
root: void 0,
|
|
1218
1218
|
value: "",
|
|
1219
|
-
|
|
1219
|
+
propsArray: [],
|
|
1220
1220
|
setValue: (_v) => {
|
|
1221
1221
|
}
|
|
1222
1222
|
});
|
|
1223
1223
|
|
|
1224
1224
|
// src/components/DropdownSelector/MenuList/internals/getValuesRecursive.tsx
|
|
1225
1225
|
import * as React12 from "react";
|
|
1226
|
-
function getValuesRecursive(children
|
|
1226
|
+
function getValuesRecursive(children) {
|
|
1227
1227
|
const childArray = React12.Children.toArray(children);
|
|
1228
|
+
const propsArray = [];
|
|
1228
1229
|
for (let i = 0; i < childArray.length; i++) {
|
|
1229
1230
|
const child = childArray[i];
|
|
1230
1231
|
if (React12.isValidElement(child)) {
|
|
1231
1232
|
const props = child.props;
|
|
1232
1233
|
if ("value" in props && typeof props.value === "string") {
|
|
1233
|
-
|
|
1234
|
-
|
|
1234
|
+
propsArray.push({
|
|
1235
|
+
disabled: props.disabled,
|
|
1236
|
+
value: props.value
|
|
1237
|
+
});
|
|
1235
1238
|
}
|
|
1236
1239
|
if ("children" in props && props.children) {
|
|
1237
|
-
getValuesRecursive(props.children
|
|
1240
|
+
propsArray.push(...getValuesRecursive(props.children));
|
|
1238
1241
|
}
|
|
1239
1242
|
}
|
|
1240
1243
|
}
|
|
1244
|
+
return propsArray;
|
|
1241
1245
|
}
|
|
1242
1246
|
|
|
1243
1247
|
// src/components/DropdownSelector/MenuList/index.tsx
|
|
1244
1248
|
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
1245
1249
|
function MenuList(props) {
|
|
1246
1250
|
const root = useRef8(null);
|
|
1247
|
-
const
|
|
1248
|
-
getValuesRecursive(props.children, values);
|
|
1251
|
+
const propsArray = useMemo2(() => getValuesRecursive(props.children), [props.children]);
|
|
1249
1252
|
return /* @__PURE__ */ jsx19(StyledUl, { ref: root, children: /* @__PURE__ */ jsx19(MenuListContext.Provider, { value: {
|
|
1250
1253
|
value: props.value ?? "",
|
|
1251
1254
|
root,
|
|
1252
|
-
|
|
1255
|
+
propsArray,
|
|
1253
1256
|
setValue: (v) => {
|
|
1254
1257
|
props.onChange?.(v);
|
|
1255
1258
|
}
|
|
@@ -1261,20 +1264,29 @@ var StyledUl = styled15.ul.withConfig({
|
|
|
1261
1264
|
|
|
1262
1265
|
// src/components/DropdownSelector/index.tsx
|
|
1263
1266
|
import { focusVisibleFocusRingCss as focusVisibleFocusRingCss6 } from "@charcoal-ui/styled";
|
|
1267
|
+
import { useVisuallyHidden as useVisuallyHidden3 } from "@react-aria/visually-hidden";
|
|
1264
1268
|
import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1265
1269
|
var defaultRequiredText = "*\u5FC5\u9808";
|
|
1266
1270
|
function DropdownSelector(props) {
|
|
1267
1271
|
const triggerRef = useRef9(null);
|
|
1268
1272
|
const [isOpen, setIsOpen] = useState3(false);
|
|
1269
1273
|
const preview = findPreviewRecursive(props.children, props.value);
|
|
1274
|
+
const isPlaceholder = useMemo3(() => props.placeholder !== void 0 && preview === void 0, [preview, props.placeholder]);
|
|
1275
|
+
const propsArray = getValuesRecursive(props.children);
|
|
1276
|
+
const {
|
|
1277
|
+
visuallyHiddenProps
|
|
1278
|
+
} = useVisuallyHidden3();
|
|
1270
1279
|
return /* @__PURE__ */ jsxs10(DropdownSelectorRoot, { "aria-disabled": props.disabled, children: [
|
|
1271
1280
|
props.showLabel === true && /* @__PURE__ */ jsx20(DropdownFieldLabel, { label: props.label, required: props.required, requiredText: props.requiredText ?? defaultRequiredText, subLabel: props.subLabel }),
|
|
1281
|
+
/* @__PURE__ */ jsx20("div", { ...visuallyHiddenProps, "aria-hidden": "true", children: /* @__PURE__ */ jsx20("select", { name: props.name, value: props.value, tabIndex: -1, children: propsArray.map((itemProps) => {
|
|
1282
|
+
return /* @__PURE__ */ jsx20("option", { value: itemProps.value, disabled: itemProps.disabled, children: itemProps.value }, itemProps.value);
|
|
1283
|
+
}) }) }),
|
|
1272
1284
|
/* @__PURE__ */ jsxs10(DropdownButton, { invalid: props.invalid, disabled: props.disabled, onClick: () => {
|
|
1273
1285
|
if (props.disabled === true)
|
|
1274
1286
|
return;
|
|
1275
1287
|
setIsOpen(true);
|
|
1276
1288
|
}, ref: triggerRef, type: "button", $active: isOpen, children: [
|
|
1277
|
-
/* @__PURE__ */ jsx20(DropdownButtonText, {
|
|
1289
|
+
/* @__PURE__ */ jsx20(DropdownButtonText, { $isText3: isPlaceholder, children: isPlaceholder ? props.placeholder : preview }),
|
|
1278
1290
|
/* @__PURE__ */ jsx20(DropdownButtonIcon, { name: "16/Menu" })
|
|
1279
1291
|
] }),
|
|
1280
1292
|
isOpen && /* @__PURE__ */ jsx20(DropdownPopover, { isOpen, onClose: () => setIsOpen(false), triggerRef, value: props.value, children: /* @__PURE__ */ jsx20(MenuList, { value: props.value, onChange: (v) => {
|
|
@@ -1299,7 +1311,7 @@ var DropdownButton = styled16.button.withConfig({
|
|
|
1299
1311
|
}) => invalid === true && css9(["&:not(:disabled):not([aria-disabled]),&[aria-disabled='false']{box-shadow:0 0 0 4px rgba(255,43,0,0.32);}"]));
|
|
1300
1312
|
var DropdownButtonText = styled16.span.withConfig({
|
|
1301
1313
|
componentId: "ccl__sc-1vnxmc8-3"
|
|
1302
|
-
})(["text-align:left;font-size:14px;line-height:22px;display:flow-root;color:var(--charcoal-
|
|
1314
|
+
})(["text-align:left;font-size:14px;line-height:22px;display:flow-root;color:var(--charcoal-", ");overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"], (p) => p.$isText3 ? "text3" : "text2");
|
|
1303
1315
|
var DropdownButtonIcon = styled16(Icon_default).withConfig({
|
|
1304
1316
|
componentId: "ccl__sc-1vnxmc8-4"
|
|
1305
1317
|
})(["color:var(--charcoal-text2);"]);
|
|
@@ -1327,7 +1339,7 @@ var StyledLi = styled17.li.withConfig({
|
|
|
1327
1339
|
})(["list-style:none;"]);
|
|
1328
1340
|
var ItemDiv = styled17.div.withConfig({
|
|
1329
1341
|
componentId: "ccl__sc-p1vs75-1"
|
|
1330
|
-
})(["display:flex;align-items:center;min-height:40px;cursor:pointer;outline:none;padding-right:16px;padding-left:16px;&:disabled,&[aria-disabled]:not([aria-disabled='false']){opacity:0.32;cursor:default;}:hover,:focus,:focus-within{background-color:var(--charcoal-surface3);}"]);
|
|
1342
|
+
})(["display:flex;align-items:center;min-height:40px;cursor:pointer;outline:none;padding-right:16px;padding-left:16px;transition:background-color 0.2s;&:disabled,&[aria-disabled]:not([aria-disabled='false']){opacity:0.32;cursor:default;}:hover,:focus,:focus-within{&:not(disabled):not([aria-disabled='true']){background-color:var(--charcoal-surface3);}}"]);
|
|
1331
1343
|
|
|
1332
1344
|
// src/components/DropdownSelector/MenuItem/internals/useMenuItemHandleKeyDown.tsx
|
|
1333
1345
|
import { useCallback as useCallback6, useContext as useContext7 } from "react";
|
|
@@ -1366,7 +1378,7 @@ function useMenuItemHandleKeyDown(value) {
|
|
|
1366
1378
|
const {
|
|
1367
1379
|
setValue,
|
|
1368
1380
|
root,
|
|
1369
|
-
|
|
1381
|
+
propsArray
|
|
1370
1382
|
} = useContext7(MenuListContext);
|
|
1371
1383
|
const setContextValue = useCallback6(() => {
|
|
1372
1384
|
if (value !== void 0)
|
|
@@ -1376,24 +1388,33 @@ function useMenuItemHandleKeyDown(value) {
|
|
|
1376
1388
|
if (e.key === "Enter") {
|
|
1377
1389
|
setContextValue();
|
|
1378
1390
|
} else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
1391
|
+
const isForward = e.key === "ArrowDown";
|
|
1379
1392
|
e.preventDefault();
|
|
1380
|
-
if (!
|
|
1393
|
+
if (!propsArray || value === void 0)
|
|
1381
1394
|
return;
|
|
1382
|
-
const
|
|
1395
|
+
const values = propsArray.map((props) => props.value).filter((v) => v);
|
|
1396
|
+
let index = values.indexOf(value);
|
|
1383
1397
|
if (index === -1)
|
|
1384
1398
|
return;
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
next
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1399
|
+
for (let n = 0; n < values.length; n++) {
|
|
1400
|
+
const focusValue = isForward ? index + 1 >= values.length ? values[0] : values[index + 1] : index - 1 < 0 ? values[values.length - 1] : values[index - 1];
|
|
1401
|
+
const next = root?.current?.querySelector(`[data-key='${focusValue}']`);
|
|
1402
|
+
if (next instanceof HTMLElement) {
|
|
1403
|
+
if (next.ariaDisabled === "true") {
|
|
1404
|
+
index += isForward ? 1 : -1;
|
|
1405
|
+
continue;
|
|
1406
|
+
}
|
|
1407
|
+
next.focus({
|
|
1408
|
+
preventScroll: true
|
|
1409
|
+
});
|
|
1410
|
+
if (root?.current?.parentElement) {
|
|
1411
|
+
handleFocusByKeyBoard(next, root.current.parentElement);
|
|
1412
|
+
}
|
|
1413
|
+
break;
|
|
1393
1414
|
}
|
|
1394
1415
|
}
|
|
1395
1416
|
}
|
|
1396
|
-
}, [setContextValue, value, root
|
|
1417
|
+
}, [setContextValue, propsArray, value, root]);
|
|
1397
1418
|
return [handleKeyDown, setContextValue];
|
|
1398
1419
|
}
|
|
1399
1420
|
|
|
@@ -1455,7 +1476,7 @@ var StyledLi2 = styled19.li.withConfig({
|
|
|
1455
1476
|
})(["display:block;"]);
|
|
1456
1477
|
|
|
1457
1478
|
// src/components/SegmentedControl/index.tsx
|
|
1458
|
-
import { forwardRef as forwardRef15, memo as memo6, useMemo as
|
|
1479
|
+
import { forwardRef as forwardRef15, memo as memo6, useMemo as useMemo4, useRef as useRef10 } from "react";
|
|
1459
1480
|
|
|
1460
1481
|
// ../../node_modules/@react-stately/form/dist/import.mjs
|
|
1461
1482
|
import { createContext as $jcIOw$createContext, useMemo as $jcIOw$useMemo, useContext as $jcIOw$useContext, useState as $jcIOw$useState, useRef as $jcIOw$useRef, useEffect as $jcIOw$useEffect } from "react";
|
|
@@ -1705,7 +1726,7 @@ var useRadioContext = () => {
|
|
|
1705
1726
|
// src/components/SegmentedControl/index.tsx
|
|
1706
1727
|
import { jsx as jsx26, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1707
1728
|
var SegmentedControl = forwardRef15(function SegmentedControlInner(props, ref) {
|
|
1708
|
-
const ariaRadioGroupProps =
|
|
1729
|
+
const ariaRadioGroupProps = useMemo4(() => ({
|
|
1709
1730
|
...props,
|
|
1710
1731
|
isDisabled: props.disabled,
|
|
1711
1732
|
isReadOnly: props.readonly,
|
|
@@ -1716,7 +1737,7 @@ var SegmentedControl = forwardRef15(function SegmentedControlInner(props, ref) {
|
|
|
1716
1737
|
const {
|
|
1717
1738
|
radioGroupProps
|
|
1718
1739
|
} = useRadioGroup(ariaRadioGroupProps, state);
|
|
1719
|
-
const segmentedControlItems =
|
|
1740
|
+
const segmentedControlItems = useMemo4(() => {
|
|
1720
1741
|
return props.data.map((d) => typeof d === "string" ? {
|
|
1721
1742
|
value: d,
|
|
1722
1743
|
label: d
|
|
@@ -1728,7 +1749,7 @@ var SegmentedControl_default = memo6(SegmentedControl);
|
|
|
1728
1749
|
var Segmented = (props) => {
|
|
1729
1750
|
const state = useRadioContext();
|
|
1730
1751
|
const ref = useRef10(null);
|
|
1731
|
-
const ariaRadioProps =
|
|
1752
|
+
const ariaRadioProps = useMemo4(() => ({
|
|
1732
1753
|
value: props.value,
|
|
1733
1754
|
isDisabled: props.disabled,
|
|
1734
1755
|
children: props.children
|
|
@@ -1762,7 +1783,7 @@ var SegmentedLabelInner = styled20.div.withConfig({
|
|
|
1762
1783
|
})(["font-size:14px;line-height:22px;display:flow-root;&::before{display:block;width:0;height:0;content:'';margin-top:-4px;}&::after{display:block;width:0;height:0;content:'';margin-bottom:-4px;}"]);
|
|
1763
1784
|
|
|
1764
1785
|
// src/components/Checkbox/index.tsx
|
|
1765
|
-
import { forwardRef as forwardRef16, memo as memo7, useMemo as
|
|
1786
|
+
import { forwardRef as forwardRef16, memo as memo7, useMemo as useMemo5 } from "react";
|
|
1766
1787
|
import styled21, { css as css11 } from "styled-components";
|
|
1767
1788
|
import { useCheckbox } from "@react-aria/checkbox";
|
|
1768
1789
|
import { useObjectRef as useObjectRef3 } from "@react-aria/utils";
|
|
@@ -1773,7 +1794,7 @@ var Checkbox = forwardRef16(function CheckboxInner({
|
|
|
1773
1794
|
invalid = false,
|
|
1774
1795
|
...props
|
|
1775
1796
|
}, ref) {
|
|
1776
|
-
const ariaCheckboxProps =
|
|
1797
|
+
const ariaCheckboxProps = useMemo5(() => ({
|
|
1777
1798
|
...props,
|
|
1778
1799
|
isInValid: invalid,
|
|
1779
1800
|
isSelected: props.checked,
|
|
@@ -1817,7 +1838,7 @@ var InputLabel = styled21.div.withConfig({
|
|
|
1817
1838
|
})(["color:var(--charcoal-text2);font-size:14px;line-height:20px;"]);
|
|
1818
1839
|
|
|
1819
1840
|
// src/components/TagItem/index.tsx
|
|
1820
|
-
import { forwardRef as forwardRef17, memo as memo8, useMemo as
|
|
1841
|
+
import { forwardRef as forwardRef17, memo as memo8, useMemo as useMemo6 } from "react";
|
|
1821
1842
|
import { useObjectRef as useObjectRef4 } from "@react-aria/utils";
|
|
1822
1843
|
import styled22, { css as css12 } from "styled-components";
|
|
1823
1844
|
import { px as px2 } from "@charcoal-ui/utils";
|
|
@@ -1840,7 +1861,7 @@ var TagItem = forwardRef17(function TagItemInner({
|
|
|
1840
1861
|
...props
|
|
1841
1862
|
}, _ref) {
|
|
1842
1863
|
const ref = useObjectRef4(_ref);
|
|
1843
|
-
const ariaButtonProps =
|
|
1864
|
+
const ariaButtonProps = useMemo6(() => ({
|
|
1844
1865
|
elementType: "a",
|
|
1845
1866
|
isDisabled: disabled,
|
|
1846
1867
|
...props
|