@charcoal-ui/react 4.0.0-beta.2 → 4.0.0-beta.3
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/Button/index.d.ts +9 -1
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Button/index.story.d.ts +4 -6
- package/dist/components/Button/index.story.d.ts.map +1 -1
- package/dist/components/Button/index.test.d.ts +2 -0
- package/dist/components/Button/index.test.d.ts.map +1 -0
- package/dist/components/DropdownSelector/index.d.ts +1 -1
- package/dist/components/DropdownSelector/index.d.ts.map +1 -1
- package/dist/index.cjs.js +11 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +15 -8
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -7
- package/src/components/Button/__snapshots__/index.story.storyshot +11 -49
- package/src/components/Button/__snapshots__/index.test.tsx.snap +11 -0
- package/src/components/Button/index.story.tsx +13 -66
- package/src/components/Button/index.test.tsx +32 -0
- package/src/components/Button/index.tsx +11 -1
- package/src/components/DropdownSelector/__snapshots__/index.story.storyshot +15 -0
- package/src/components/DropdownSelector/index.tsx +19 -4
- package/src/components/Modal/__snapshots__/index.story.storyshot +2 -0
package/dist/index.esm.js
CHANGED
|
@@ -68,11 +68,12 @@ var Button = forwardRef2(function Button2({
|
|
|
68
68
|
className,
|
|
69
69
|
as,
|
|
70
70
|
isActive,
|
|
71
|
+
componentAs,
|
|
71
72
|
...props
|
|
72
73
|
}, ref) {
|
|
73
74
|
const Component = useMemo2(() => as ?? "button", [as]);
|
|
74
75
|
const classNames = useClassNames("charcoal-button", className);
|
|
75
|
-
return /* @__PURE__ */ jsx3(Component, { ...props, className: classNames, "data-variant": variant, "data-size": size, "data-full-width": fullWidth, "data-active": isActive, ref });
|
|
76
|
+
return /* @__PURE__ */ jsx3(Component, { ...props, as: componentAs, className: classNames, "data-variant": variant, "data-size": size, "data-full-width": fullWidth, "data-active": isActive, ref });
|
|
76
77
|
});
|
|
77
78
|
var Button_default = Button;
|
|
78
79
|
|
|
@@ -1046,7 +1047,7 @@ var LoadingSpinnerIcon = forwardRef14(function LoadingSpinnerIcon2({
|
|
|
1046
1047
|
});
|
|
1047
1048
|
|
|
1048
1049
|
// src/components/DropdownSelector/index.tsx
|
|
1049
|
-
import { useState as useState3, useRef as useRef9, useMemo as useMemo5 } from "react";
|
|
1050
|
+
import { useState as useState3, useRef as useRef9, useMemo as useMemo5, useCallback as useCallback6 } from "react";
|
|
1050
1051
|
import styled15, { css as css8 } from "styled-components";
|
|
1051
1052
|
import { disabledSelector as disabledSelector2 } from "@charcoal-ui/utils";
|
|
1052
1053
|
|
|
@@ -1224,7 +1225,10 @@ import { focusVisibleFocusRingCss as focusVisibleFocusRingCss5 } from "@charcoal
|
|
|
1224
1225
|
import { useVisuallyHidden as useVisuallyHidden3 } from "@react-aria/visually-hidden";
|
|
1225
1226
|
import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1226
1227
|
var defaultRequiredText = "*\u5FC5\u9808";
|
|
1227
|
-
function DropdownSelector(
|
|
1228
|
+
function DropdownSelector({
|
|
1229
|
+
onChange,
|
|
1230
|
+
...props
|
|
1231
|
+
}) {
|
|
1228
1232
|
const triggerRef = useRef9(null);
|
|
1229
1233
|
const [isOpen, setIsOpen] = useState3(false);
|
|
1230
1234
|
const preview = findPreviewRecursive(props.children, props.value);
|
|
@@ -1233,9 +1237,12 @@ function DropdownSelector(props) {
|
|
|
1233
1237
|
const {
|
|
1234
1238
|
visuallyHiddenProps
|
|
1235
1239
|
} = useVisuallyHidden3();
|
|
1240
|
+
const handleChange = useCallback6((e) => {
|
|
1241
|
+
onChange(e.target.value);
|
|
1242
|
+
}, [onChange]);
|
|
1236
1243
|
return /* @__PURE__ */ jsxs10(DropdownSelectorRoot, { "aria-disabled": props.disabled, children: [
|
|
1237
1244
|
props.showLabel === true && /* @__PURE__ */ jsx20(DropdownFieldLabel, { label: props.label, required: props.required, requiredText: props.requiredText ?? defaultRequiredText, subLabel: props.subLabel }),
|
|
1238
|
-
/* @__PURE__ */ jsx20("div", { ...visuallyHiddenProps, "aria-hidden": "true", children: /* @__PURE__ */ jsx20("select", { name: props.name, value: props.value, tabIndex: -1, children: propsArray.map((itemProps) => {
|
|
1245
|
+
/* @__PURE__ */ jsx20("div", { ...visuallyHiddenProps, "aria-hidden": "true", children: /* @__PURE__ */ jsx20("select", { name: props.name, value: props.value, onChange: handleChange, tabIndex: -1, children: propsArray.map((itemProps) => {
|
|
1239
1246
|
return /* @__PURE__ */ jsx20("option", { value: itemProps.value, disabled: itemProps.disabled, children: itemProps.value }, itemProps.value);
|
|
1240
1247
|
}) }) }),
|
|
1241
1248
|
/* @__PURE__ */ jsxs10(DropdownButton, { invalid: props.invalid, disabled: props.disabled, onClick: () => {
|
|
@@ -1247,7 +1254,7 @@ function DropdownSelector(props) {
|
|
|
1247
1254
|
/* @__PURE__ */ jsx20(DropdownButtonIcon, { name: "16/Menu" })
|
|
1248
1255
|
] }),
|
|
1249
1256
|
isOpen && /* @__PURE__ */ jsx20(DropdownPopover, { isOpen, onClose: () => setIsOpen(false), triggerRef, value: props.value, children: /* @__PURE__ */ jsx20(MenuList, { value: props.value, onChange: (v) => {
|
|
1250
|
-
|
|
1257
|
+
onChange(v);
|
|
1251
1258
|
setIsOpen(false);
|
|
1252
1259
|
}, children: props.children }) }),
|
|
1253
1260
|
props.assistiveText !== void 0 && /* @__PURE__ */ jsx20(AssertiveText, { invalid: props.invalid, children: props.assistiveText })
|
|
@@ -1299,7 +1306,7 @@ var ItemDiv = styled16.div.withConfig({
|
|
|
1299
1306
|
})(["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);}}"]);
|
|
1300
1307
|
|
|
1301
1308
|
// src/components/DropdownSelector/MenuItem/internals/useMenuItemHandleKeyDown.tsx
|
|
1302
|
-
import { useCallback as
|
|
1309
|
+
import { useCallback as useCallback7, useContext as useContext7 } from "react";
|
|
1303
1310
|
|
|
1304
1311
|
// src/components/DropdownSelector/MenuItem/internals/handleFocusByKeyBoard.tsx
|
|
1305
1312
|
function handleFocusByKeyBoard(element, parent) {
|
|
@@ -1337,11 +1344,11 @@ function useMenuItemHandleKeyDown(value) {
|
|
|
1337
1344
|
root,
|
|
1338
1345
|
propsArray
|
|
1339
1346
|
} = useContext7(MenuListContext);
|
|
1340
|
-
const setContextValue =
|
|
1347
|
+
const setContextValue = useCallback7(() => {
|
|
1341
1348
|
if (value !== void 0)
|
|
1342
1349
|
setValue(value);
|
|
1343
1350
|
}, [value, setValue]);
|
|
1344
|
-
const handleKeyDown =
|
|
1351
|
+
const handleKeyDown = useCallback7((e) => {
|
|
1345
1352
|
if (e.key === "Enter") {
|
|
1346
1353
|
setContextValue();
|
|
1347
1354
|
} else if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|