@canlooks/can-ui 0.0.58 → 0.0.60
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/cjs/components/avatar/avatarGroup.js +1 -1
- package/dist/cjs/components/bottomNavigation/bottomNavigation.js +9 -8
- package/dist/cjs/components/breadcrumb/breadcrumb.js +8 -7
- package/dist/cjs/components/checkboxBaseGroup/checkboxBaseGroup.js +10 -9
- package/dist/cjs/components/form/form.d.ts +2 -1
- package/dist/cjs/components/form/form.js +2 -3
- package/dist/cjs/components/form/formItem.js +5 -4
- package/dist/cjs/components/menu/menu.js +8 -7
- package/dist/cjs/components/segmented/segmented.js +11 -10
- package/dist/cjs/components/select/select.style.js +1 -1
- package/dist/cjs/components/stepper/stepper.js +10 -9
- package/dist/cjs/components/tabs/lineIndicator.d.ts +1 -2
- package/dist/cjs/components/tabs/lineIndicator.js +10 -8
- package/dist/cjs/components/tabs/tab.js +4 -4
- package/dist/cjs/components/tabs/tabs.d.ts +2 -5
- package/dist/cjs/components/tabs/tabs.js +31 -27
- package/dist/cjs/components/tabs/tabs.style.js +1 -1
- package/dist/cjs/components/timeline/timeline.js +10 -9
- package/dist/cjs/components/toggleButton/toggleButton.js +6 -5
- package/dist/cjs/utils/polyfill.js +3 -3
- package/dist/esm/components/avatar/avatarGroup.js +1 -1
- package/dist/esm/components/bottomNavigation/bottomNavigation.js +3 -2
- package/dist/esm/components/breadcrumb/breadcrumb.js +3 -2
- package/dist/esm/components/checkboxBaseGroup/checkboxBaseGroup.js +3 -2
- package/dist/esm/components/form/form.d.ts +2 -1
- package/dist/esm/components/form/form.js +2 -3
- package/dist/esm/components/form/formItem.js +5 -4
- package/dist/esm/components/menu/menu.js +2 -1
- package/dist/esm/components/segmented/segmented.js +3 -2
- package/dist/esm/components/select/select.style.js +1 -1
- package/dist/esm/components/stepper/stepper.js +3 -2
- package/dist/esm/components/tabs/lineIndicator.d.ts +1 -2
- package/dist/esm/components/tabs/lineIndicator.js +10 -8
- package/dist/esm/components/tabs/tab.js +4 -4
- package/dist/esm/components/tabs/tabs.d.ts +2 -5
- package/dist/esm/components/tabs/tabs.js +16 -12
- package/dist/esm/components/tabs/tabs.style.js +1 -1
- package/dist/esm/components/timeline/timeline.js +2 -1
- package/dist/esm/components/toggleButton/toggleButton.js +2 -1
- package/dist/esm/utils/polyfill.js +3 -3
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ exports.AvatarGroup = (0, react_2.memo)(({ color, size, shape = 'circular', imgP
|
|
|
18
18
|
const isSurplus = total > max;
|
|
19
19
|
const renderItems = () => {
|
|
20
20
|
if (items?.length) {
|
|
21
|
-
return items.slice(0, isSurplus ? max - 1 : max).reverse().map((p, i) => (0, react_1.createElement)(avatar_1.Avatar, { ...commonProps, key: p.key ?? i
|
|
21
|
+
return items.slice(0, isSurplus ? max - 1 : max).reverse().map((p, i) => (0, react_1.createElement)(avatar_1.Avatar, { ...commonProps, ...p, key: p.key ?? i }, p.children));
|
|
22
22
|
}
|
|
23
23
|
return react_2.Children.toArray(props.children).slice(0, isSurplus ? max - 1 : max).reverse().map(child => {
|
|
24
24
|
return (0, react_2.isValidElement)(child)
|
|
@@ -2,27 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BottomNavigation = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const bottomNavigation_style_1 = require("./bottomNavigation.style");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const bottomNavigationItem_1 = require("./bottomNavigationItem");
|
|
9
|
-
exports.BottomNavigation = (0,
|
|
10
|
+
exports.BottomNavigation = (0, react_2.memo)(({ items, showLabelInactive, primaryKey = 'value', labelKey = 'label', defaultValue = 'children', value, onChange, ...props }) => {
|
|
10
11
|
const [innerValue, setInnerValue] = (0, utils_1.useControlled)(defaultValue, value, onChange);
|
|
11
12
|
const renderItems = () => {
|
|
12
13
|
if (items) {
|
|
13
14
|
return items.map((p, i) => {
|
|
14
15
|
const itemValue = p[primaryKey];
|
|
15
|
-
return ((0,
|
|
16
|
+
return ((0, react_1.createElement)(bottomNavigationItem_1.BottomNavigationItem, { ...p, key: p.key ?? itemValue ?? i, value: itemValue, label: p[labelKey], showLabelInactive: p.showLabelInactive ?? showLabelInactive ?? items.length <= 3, active: !(0, utils_1.isUnset)(itemValue) && innerValue.current === itemValue, onClick: e => {
|
|
16
17
|
p.onClick?.(e);
|
|
17
18
|
setInnerValue(itemValue);
|
|
18
|
-
} }
|
|
19
|
+
} }));
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
|
-
showLabelInactive ??=
|
|
22
|
-
return
|
|
23
|
-
if ((0,
|
|
22
|
+
showLabelInactive ??= react_2.Children.count(props.children) <= 3;
|
|
23
|
+
return react_2.Children.map(props.children, c => {
|
|
24
|
+
if ((0, react_2.isValidElement)(c)) {
|
|
24
25
|
const { props } = c;
|
|
25
|
-
return (0,
|
|
26
|
+
return (0, react_2.cloneElement)(c, {
|
|
26
27
|
showLabelInactive: props.showLabelInactive ?? showLabelInactive,
|
|
27
28
|
active: !(0, utils_1.isUnset)(props.value) && innerValue.current === props.value,
|
|
28
29
|
onClick: e => {
|
|
@@ -2,32 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Breadcrumb = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const utils_1 = require("../../utils");
|
|
7
8
|
const breadcrumb_style_1 = require("./breadcrumb.style");
|
|
8
9
|
const button_1 = require("../button");
|
|
9
10
|
const theme_1 = require("../theme");
|
|
10
|
-
exports.Breadcrumb = (0,
|
|
11
|
+
exports.Breadcrumb = (0, react_2.memo)(({ separator = '/', readOnly, items, ...props }) => {
|
|
11
12
|
const { text } = (0, theme_1.useTheme)();
|
|
12
13
|
const renderItems = () => {
|
|
13
14
|
if (items) {
|
|
14
|
-
return items.flatMap(({ icon,
|
|
15
|
+
return items.flatMap(({ icon, ...p }, i) => {
|
|
15
16
|
const isLast = i === items.length - 1;
|
|
16
17
|
return [
|
|
17
|
-
(0,
|
|
18
|
+
(0, react_1.createElement)(button_1.Button, { ...p, key: p.key ?? i, variant: p.variant ?? 'plain', color: p.color ?? (isLast ? text.primary : text.disabled), readOnly: p.readOnly ?? (isLast || readOnly), prefix: p.prefix ?? icon }, p.children),
|
|
18
19
|
...isLast ? [] : [
|
|
19
20
|
(0, jsx_runtime_1.jsx)("span", { className: breadcrumb_style_1.classes.separator, children: separator }, `${breadcrumb_style_1.classes.separator}_${i}`)
|
|
20
21
|
]
|
|
21
22
|
];
|
|
22
23
|
});
|
|
23
24
|
}
|
|
24
|
-
const childrenArr =
|
|
25
|
+
const childrenArr = react_2.Children.toArray(props.children);
|
|
25
26
|
return childrenArr.flatMap((c, i) => {
|
|
26
27
|
const isLast = i === childrenArr.length - 1;
|
|
27
28
|
const ret = [];
|
|
28
|
-
if ((0,
|
|
29
|
+
if ((0, react_2.isValidElement)(c)) {
|
|
29
30
|
const { props } = c;
|
|
30
|
-
ret.push((0,
|
|
31
|
+
ret.push((0, react_2.cloneElement)(c, {
|
|
31
32
|
variant: props.variant ?? 'plain',
|
|
32
33
|
color: props.color ?? (isLast ? text.primary : text.disabled),
|
|
33
34
|
readOnly: props.readOnly ?? (isLast || readOnly),
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CheckboxBaseGroup = void 0;
|
|
4
4
|
exports.useCheckboxBaseGroupContext = useCheckboxBaseGroupContext;
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
6
|
+
const react_1 = require("@emotion/react");
|
|
7
|
+
const react_2 = require("react");
|
|
7
8
|
const flex_1 = require("../flex");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
const checkboxBaseGroup_style_1 = require("./checkboxBaseGroup.style");
|
|
@@ -11,9 +12,9 @@ const checkbox_1 = require("../checkbox");
|
|
|
11
12
|
const radio_1 = require("../radio");
|
|
12
13
|
const theme_1 = require("../theme");
|
|
13
14
|
const selectionContext_1 = require("../selectionContext");
|
|
14
|
-
const CheckboxBaseGroupContext = (0,
|
|
15
|
+
const CheckboxBaseGroupContext = (0, react_2.createContext)({});
|
|
15
16
|
function useCheckboxBaseGroupContext() {
|
|
16
|
-
return (0,
|
|
17
|
+
return (0, react_2.useContext)(CheckboxBaseGroupContext);
|
|
17
18
|
}
|
|
18
19
|
exports.CheckboxBaseGroup = (({ size, color, items, primaryKey = 'value', multiple, defaultValue, value, onChange, ...props }) => {
|
|
19
20
|
const { spacing } = (0, theme_1.useTheme)();
|
|
@@ -23,19 +24,19 @@ exports.CheckboxBaseGroup = (({ size, color, items, primaryKey = 'value', multip
|
|
|
23
24
|
return items.map((p, i) => {
|
|
24
25
|
const Component = multiple ? checkbox_1.Checkbox : radio_1.Radio;
|
|
25
26
|
const itemValue = p[primaryKey];
|
|
26
|
-
return ((0,
|
|
27
|
+
return ((0, react_1.createElement)(Component, { ...p, key: p.key ?? itemValue ?? i, size: p.size ?? size, color: p.color ?? color, checked: (0, utils_1.isSelected)(itemValue, innerValue), onChange: e => {
|
|
27
28
|
p.onChange?.(e);
|
|
28
29
|
toggleSelected(itemValue);
|
|
29
|
-
} }
|
|
30
|
+
} }));
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
-
if (!(0,
|
|
33
|
+
return react_2.Children.map(props.children, c => {
|
|
34
|
+
if (!(0, react_2.isValidElement)(c)) {
|
|
34
35
|
return c;
|
|
35
36
|
}
|
|
36
37
|
const { props } = c;
|
|
37
38
|
const itemValue = props.value;
|
|
38
|
-
return (0,
|
|
39
|
+
return (0, react_2.cloneElement)(c, {
|
|
39
40
|
size: props.size ?? size,
|
|
40
41
|
color: props.color ?? color,
|
|
41
42
|
checked: (0, utils_1.isSelected)(itemValue, innerValue),
|
|
@@ -46,5 +47,5 @@ exports.CheckboxBaseGroup = (({ size, color, items, primaryKey = 'value', multip
|
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
};
|
|
49
|
-
return ((0, jsx_runtime_1.jsx)(flex_1.Flex, { gap: spacing[8], ...props, className: (0, utils_1.clsx)(checkboxBaseGroup_style_1.classes.root, props.className), children: (0, jsx_runtime_1.jsx)(CheckboxBaseGroupContext, { value: (0,
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)(flex_1.Flex, { gap: spacing[8], ...props, className: (0, utils_1.clsx)(checkboxBaseGroup_style_1.classes.root, props.className), children: (0, jsx_runtime_1.jsx)(CheckboxBaseGroupContext, { value: (0, react_2.useMemo)(() => ({ size, color }), [size, color]), children: renderItems() }) }));
|
|
50
51
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Dispatch, ReactElement, ReactNode, Ref, RefObject, SetStateAction, ElementType } from 'react';
|
|
2
|
-
import { Obj, OverridableProps } from '../../types';
|
|
2
|
+
import { Obj, OverridableProps, Size } from '../../types';
|
|
3
3
|
import { FieldPath } from '../../utils';
|
|
4
4
|
import { FieldError, FormItem, FormItemProps, FormItemRef } from './formItem';
|
|
5
5
|
import { FormRelatable } from './formRelatable';
|
|
@@ -11,6 +11,7 @@ export type FormSharedProps = {
|
|
|
11
11
|
requiredMark?: ReactNode;
|
|
12
12
|
/** variant为"grid"或"table"时会渲染Descriptions组件,并传递variant属性,默认为`grid` */
|
|
13
13
|
variant?: 'plain' | 'grid' | 'table';
|
|
14
|
+
size?: Size;
|
|
14
15
|
};
|
|
15
16
|
interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps, DescriptionsSharedProps, GridOwnProps {
|
|
16
17
|
ref?: Ref<FormRef<V> | null>;
|
|
@@ -81,7 +81,6 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
|
|
|
81
81
|
for (const [, item] of itemsContainer.current) {
|
|
82
82
|
item.reset(newValue);
|
|
83
83
|
}
|
|
84
|
-
console.log('after', newValue);
|
|
85
84
|
setFormValue(newValue);
|
|
86
85
|
},
|
|
87
86
|
resetField: field => {
|
|
@@ -93,10 +92,10 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
|
|
|
93
92
|
};
|
|
94
93
|
(0, react_1.useImperativeHandle)(ref, () => formRef.current);
|
|
95
94
|
return ((0, jsx_runtime_1.jsx)(Component, { ...props, ref: wrapperRef, css: form_style_1.style, className: (0, utils_1.clsx)(form_style_1.classes.root, props.className), onSubmit: submitHandler, children: (0, jsx_runtime_1.jsx)(FormContext, { value: (0, react_1.useMemo)(() => ({
|
|
96
|
-
requiredMark, variant,
|
|
95
|
+
requiredMark, variant, size,
|
|
97
96
|
formValue: formValue.current, setFieldValue,
|
|
98
97
|
itemsContainer: itemsContainer.current, formRef
|
|
99
|
-
}), [requiredMark, variant, formValue.current]), children: variant === 'plain'
|
|
98
|
+
}), [requiredMark, variant, size, formValue.current]), children: variant === 'plain'
|
|
100
99
|
? props.children
|
|
101
100
|
: (0, jsx_runtime_1.jsx)(descriptions_1.Descriptions, { ...descriptionsProps, size: size, labelWidth: labelWidth, colon: colon, labelPlacement: labelPlacement, disableMargin: disableMargin, disablePadding: disablePadding, items: items, variant: variant, itemComponent: formItem_1.FormItem, inline: inline, columnCount: columnCount, gap: gap, columnGap: columnGap, rowGap: rowGap, children: props.children }) }) }));
|
|
102
101
|
});
|
|
@@ -8,10 +8,11 @@ const utils_1 = require("../../utils");
|
|
|
8
8
|
const descriptions_1 = require("../descriptions");
|
|
9
9
|
const form_style_1 = require("./form.style");
|
|
10
10
|
const transitionBase_1 = require("../transitionBase");
|
|
11
|
-
const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, ...props }) => {
|
|
11
|
+
const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, size, ...props }) => {
|
|
12
12
|
const { formValue, setFieldValue, itemsContainer, formRef, ...context } = (0, form_1.useFormContext)();
|
|
13
13
|
requiredMark ??= context.requiredMark ?? '*';
|
|
14
14
|
variant ??= context.variant ?? 'grid';
|
|
15
|
+
size ??= context.size;
|
|
15
16
|
/**
|
|
16
17
|
* --------------------------------------------------------------------
|
|
17
18
|
* 字段值
|
|
@@ -137,7 +138,7 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
|
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
: {}, {
|
|
140
|
-
...
|
|
141
|
+
...size && { size },
|
|
141
142
|
...innerError.current ? { color: 'error' } : {}
|
|
142
143
|
}, randomKey.current);
|
|
143
144
|
}
|
|
@@ -155,12 +156,12 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
|
|
|
155
156
|
setFieldValue?.(field, (0, utils_1.getValueOnChange)(e, fieldValue));
|
|
156
157
|
}
|
|
157
158
|
},
|
|
158
|
-
...
|
|
159
|
+
...size && { size },
|
|
159
160
|
...innerError.current && { color: 'error' }
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
return children;
|
|
163
|
-
}, [children,
|
|
164
|
+
}, [children, innerError.current, field, size, randomKey.current]);
|
|
164
165
|
if (noStyle || variant === 'plain') {
|
|
165
166
|
return renderedChildren;
|
|
166
167
|
}
|
|
@@ -3,23 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Menu = void 0;
|
|
4
4
|
exports.useMenuContext = useMenuContext;
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
6
|
+
const react_1 = require("@emotion/react");
|
|
7
|
+
const react_2 = require("react");
|
|
7
8
|
const menu_style_1 = require("./menu.style");
|
|
8
9
|
const menuItem_1 = require("../menuItem");
|
|
9
10
|
const utils_1 = require("../../utils");
|
|
10
11
|
const theme_1 = require("../theme");
|
|
11
12
|
const selectionContext_1 = require("../selectionContext");
|
|
12
|
-
const MenuContext = (0,
|
|
13
|
+
const MenuContext = (0, react_2.createContext)({});
|
|
13
14
|
function useMenuContext() {
|
|
14
15
|
const theme = (0, theme_1.useTheme)();
|
|
15
|
-
const { size = theme.size, ellipsis = true, indent = theme.spacing[8], ...context } = (0,
|
|
16
|
+
const { size = theme.size, ellipsis = true, indent = theme.spacing[8], ...context } = (0, react_2.useContext)(MenuContext);
|
|
16
17
|
return { size, ellipsis, indent, ...context };
|
|
17
18
|
}
|
|
18
|
-
exports.Menu = (0,
|
|
19
|
+
exports.Menu = (0, react_2.memo)(({ items, primaryKey = 'value', labelKey = 'label', childrenKey = 'children', defaultExpanded = [], expanded, onExpandedChange, multiple, defaultValue, value, onChange,
|
|
19
20
|
// 以下属性传递给<MenuItem/>
|
|
20
21
|
size = 'large', showCheckbox, ellipsis, indent, ...props }) => {
|
|
21
22
|
const [innerExpanded, setInnerExpanded] = (0, utils_1.useControlled)(defaultExpanded, expanded);
|
|
22
|
-
const expandedSet = (0,
|
|
23
|
+
const expandedSet = (0, react_2.useMemo)(() => {
|
|
23
24
|
return new Set(innerExpanded.current);
|
|
24
25
|
}, [innerExpanded.current]);
|
|
25
26
|
const setExpanded = (key, isExpand) => {
|
|
@@ -31,9 +32,9 @@ size = 'large', showCheckbox, ellipsis, indent, ...props }) => {
|
|
|
31
32
|
};
|
|
32
33
|
const [innerValue, toggleSelected] = (0, selectionContext_1.useShallowSelection)({ multiple, defaultValue, value, onChange });
|
|
33
34
|
const renderItems = (items) => {
|
|
34
|
-
return items?.map((p, i) => (0,
|
|
35
|
+
return items?.map((p, i) => (0, react_1.createElement)(menuItem_1.MenuItem, { ...p, key: p[primaryKey] ?? i, value: p[primaryKey], label: p[labelKey] }, renderItems(p[childrenKey])));
|
|
35
36
|
};
|
|
36
|
-
return ((0, jsx_runtime_1.jsx)("div", { ...props, css: menu_style_1.style, children: (0, jsx_runtime_1.jsx)(MenuContext, { value: (0,
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)("div", { ...props, css: menu_style_1.style, children: (0, jsx_runtime_1.jsx)(MenuContext, { value: (0, react_2.useMemo)(() => ({
|
|
37
38
|
inMenu: true,
|
|
38
39
|
expandedSet, setExpanded, multiple, selected: innerValue, toggleSelected,
|
|
39
40
|
size, showCheckbox, ellipsis, indent
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Segmented = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const segmented_style_1 = require("./segmented.style");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const SegmentedOption_1 = require("./SegmentedOption");
|
|
9
10
|
const theme_1 = require("../theme");
|
|
10
|
-
exports.Segmented = (0,
|
|
11
|
+
exports.Segmented = (0, react_2.memo)(({ options, orientation = 'horizontal', size, labelKey = 'label', primaryKey = 'value', fullWidth, indicatorColor = 'background.content', defaultValue, value, onChange, readOnly, disabled, ...props }) => {
|
|
11
12
|
const theme = (0, theme_1.useTheme)();
|
|
12
13
|
size ??= theme.size;
|
|
13
|
-
const [animating, setAnimating] = (0,
|
|
14
|
+
const [animating, setAnimating] = (0, react_2.useState)(false);
|
|
14
15
|
const [innerValue, _setInnerValue] = (0, utils_1.useControlled)(defaultValue, value, onChange);
|
|
15
16
|
const setInnerValue = (value) => {
|
|
16
17
|
if (!readOnly && !disabled) {
|
|
@@ -18,7 +19,7 @@ exports.Segmented = (0, react_1.memo)(({ options, orientation = 'horizontal', si
|
|
|
18
19
|
_setInnerValue(value);
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
|
-
const optionRefs = (0,
|
|
22
|
+
const optionRefs = (0, react_2.useRef)(new Map());
|
|
22
23
|
/**
|
|
23
24
|
* 计算指示器的位置
|
|
24
25
|
*/
|
|
@@ -40,7 +41,7 @@ exports.Segmented = (0, react_1.memo)(({ options, orientation = 'horizontal', si
|
|
|
40
41
|
};
|
|
41
42
|
};
|
|
42
43
|
const [indicatorRect, setIndicatorRect] = (0, utils_1.useDerivedState)(fitIndicatorRect, [innerValue.current]);
|
|
43
|
-
(0,
|
|
44
|
+
(0, react_2.useEffect)(() => {
|
|
44
45
|
// 仅首次渲染需要计算
|
|
45
46
|
setIndicatorRect(fitIndicatorRect());
|
|
46
47
|
}, []);
|
|
@@ -49,21 +50,21 @@ exports.Segmented = (0, react_1.memo)(({ options, orientation = 'horizontal', si
|
|
|
49
50
|
return options.map((p, i) => {
|
|
50
51
|
const v = p[primaryKey];
|
|
51
52
|
const active = !(0, utils_1.isUnset)(v) && v === innerValue.current;
|
|
52
|
-
return ((0,
|
|
53
|
+
return ((0, react_1.createElement)(SegmentedOption_1.SegmentedOption, { ...p, key: p.key ?? v ?? i, ref: r => {
|
|
53
54
|
r
|
|
54
55
|
? optionRefs.current.set(v, r)
|
|
55
56
|
: optionRefs.current.delete(v);
|
|
56
57
|
}, value: v, label: p[labelKey], onClick: e => {
|
|
57
58
|
p.onClick?.(e);
|
|
58
59
|
setInnerValue(v);
|
|
59
|
-
}, "data-active": active }
|
|
60
|
+
}, "data-active": active }));
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
|
-
return
|
|
63
|
-
if ((0,
|
|
63
|
+
return react_2.Children.map(props.children, c => {
|
|
64
|
+
if ((0, react_2.isValidElement)(c)) {
|
|
64
65
|
const { value } = c.props;
|
|
65
66
|
const active = !(0, utils_1.isUnset)(value) && value === innerValue.current;
|
|
66
|
-
return (0,
|
|
67
|
+
return (0, react_2.cloneElement)(c, {
|
|
67
68
|
ref: (0, utils_1.cloneRef)(c.ref, (r) => {
|
|
68
69
|
!(0, utils_1.isUnset)(value) && optionRefs.current.set(value, r);
|
|
69
70
|
}),
|
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Stepper = void 0;
|
|
4
4
|
exports.useStepperContext = useStepperContext;
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
6
|
+
const react_1 = require("@emotion/react");
|
|
7
|
+
const react_2 = require("react");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const stepper_style_1 = require("./stepper.style");
|
|
9
10
|
const step_1 = require("./step");
|
|
10
|
-
const StepperContext = (0,
|
|
11
|
+
const StepperContext = (0, react_2.createContext)({});
|
|
11
12
|
function useStepperContext() {
|
|
12
|
-
return (0,
|
|
13
|
+
return (0, react_2.useContext)(StepperContext);
|
|
13
14
|
}
|
|
14
15
|
exports.Stepper = (({ steps, orientation = 'horizontal', defaultValue = 0, value, onChange,
|
|
15
16
|
// 以下为共享属性
|
|
@@ -19,21 +20,21 @@ size, gap = orientation === 'horizontal' ? 15 : 9, color, variant, clickable, la
|
|
|
19
20
|
if (steps) {
|
|
20
21
|
return steps.map((p, i) => {
|
|
21
22
|
const isCurrentStep = i === innerValue.current;
|
|
22
|
-
return ((0,
|
|
23
|
+
return ((0, react_1.createElement)(step_1.Step, { ...p, key: p.key ?? i, step: i, status: p.status ?? (isCurrentStep
|
|
23
24
|
? status ?? 'processing'
|
|
24
25
|
: i < innerValue.current
|
|
25
26
|
? 'finished'
|
|
26
27
|
: 'waiting'), clickable: p.clickable ?? clickable, onClick: e => {
|
|
27
28
|
p.onClick?.(e);
|
|
28
29
|
(p.clickable ?? clickable) && setInnerValue(i);
|
|
29
|
-
}, "data-orientation": orientation }
|
|
30
|
+
}, "data-orientation": orientation }));
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
-
if ((0,
|
|
33
|
+
return react_2.Children.map(props.children, (c, i) => {
|
|
34
|
+
if ((0, react_2.isValidElement)(c)) {
|
|
34
35
|
const isCurrentStep = i === innerValue.current;
|
|
35
36
|
const { props } = c;
|
|
36
|
-
return (0,
|
|
37
|
+
return (0, react_2.cloneElement)(c, {
|
|
37
38
|
step: props.step ?? i,
|
|
38
39
|
status: props.status ?? (isCurrentStep
|
|
39
40
|
? status ?? 'processing'
|
|
@@ -53,7 +54,7 @@ size, gap = orientation === 'horizontal' ? 15 : 9, color, variant, clickable, la
|
|
|
53
54
|
return ((0, jsx_runtime_1.jsx)("div", { ...props, css: stepper_style_1.style, className: (0, utils_1.clsx)(stepper_style_1.classes.root, props.className), "data-orientation": orientation, style: {
|
|
54
55
|
gap,
|
|
55
56
|
...props.style
|
|
56
|
-
}, children: (0, jsx_runtime_1.jsx)(StepperContext, { value: (0,
|
|
57
|
+
}, children: (0, jsx_runtime_1.jsx)(StepperContext, { value: (0, react_2.useMemo)(() => ({
|
|
57
58
|
size, gap, color, variant, clickable, labelPlacement
|
|
58
59
|
}), [
|
|
59
60
|
size, gap, color, variant, clickable, labelPlacement
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ActiveTabRef } from './tabs';
|
|
2
1
|
import { Id } from '../../types';
|
|
3
2
|
export declare function LineIndicator({ value, position, getActiveTab, onTransitionEnd }: {
|
|
4
3
|
value?: Id;
|
|
5
4
|
position: 'top' | 'bottom' | 'left' | 'right';
|
|
6
|
-
getActiveTab():
|
|
5
|
+
getActiveTab(): HTMLDivElement | undefined;
|
|
7
6
|
onTransitionEnd(): void;
|
|
8
7
|
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -6,19 +6,21 @@ const react_1 = require("react");
|
|
|
6
6
|
const tabs_style_1 = require("./tabs.style");
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const theme_1 = require("../theme");
|
|
9
|
+
const tabs_1 = require("./tabs");
|
|
9
10
|
function LineIndicator({ value, position, getActiveTab, onTransitionEnd }) {
|
|
11
|
+
const context = (0, tabs_1.useTabsContext)();
|
|
12
|
+
const [color, setColor] = (0, react_1.useState)(context.color);
|
|
10
13
|
const [boundingRect, setBoundingRect] = (0, react_1.useState)();
|
|
11
|
-
const [color, setColor] = (0, react_1.useState)('primary');
|
|
12
14
|
(0, react_1.useEffect)(() => {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
+
const activeTab = getActiveTab();
|
|
16
|
+
if (!activeTab) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
19
|
if (position === 'top' || position === 'bottom') {
|
|
18
20
|
setBoundingRect({
|
|
19
|
-
width:
|
|
21
|
+
width: activeTab.offsetWidth,
|
|
20
22
|
height: tabs_style_1.indicatorWidth,
|
|
21
|
-
left:
|
|
23
|
+
left: activeTab.offsetLeft,
|
|
22
24
|
...position === 'top'
|
|
23
25
|
? { bottom: 0 }
|
|
24
26
|
: { top: 0 }
|
|
@@ -28,14 +30,14 @@ function LineIndicator({ value, position, getActiveTab, onTransitionEnd }) {
|
|
|
28
30
|
// position === 'left' || position === 'right'
|
|
29
31
|
setBoundingRect({
|
|
30
32
|
width: tabs_style_1.indicatorWidth,
|
|
31
|
-
height:
|
|
32
|
-
top:
|
|
33
|
+
height: activeTab.offsetHeight,
|
|
34
|
+
top: activeTab.offsetTop,
|
|
33
35
|
...position === 'left'
|
|
34
36
|
? { right: 0 }
|
|
35
37
|
: { left: 0 }
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
|
-
setColor(color);
|
|
40
|
+
activeTab.dataset.color && setColor(activeTab.dataset.color);
|
|
39
41
|
}, [value]);
|
|
40
42
|
const theme = (0, theme_1.useTheme)();
|
|
41
43
|
return ((0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.indicator, onTransitionEnd: onTransitionEnd, style: {
|
|
@@ -6,14 +6,14 @@ const react_1 = require("react");
|
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const tabs_style_1 = require("./tabs.style");
|
|
8
8
|
const tabs_1 = require("./tabs");
|
|
9
|
-
exports.Tab = (0, react_1.memo)(({ prefix, suffix, color
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
exports.Tab = (0, react_1.memo)(({ prefix, suffix, color, orientation, label, value, disabled, _active, ...props }) => {
|
|
10
|
+
const { color: contextColor, variant, animating } = (0, tabs_1.useTabsContext)();
|
|
11
|
+
const colorValue = (0, utils_1.useColor)(color ?? contextColor);
|
|
12
12
|
return ((0, jsx_runtime_1.jsxs)("div", { ...props, className: (0, utils_1.clsx)(tabs_style_1.classes.tab, props.className), style: {
|
|
13
13
|
borderColor: variant === 'line' && !animating && _active ? colorValue : void 0,
|
|
14
14
|
color: _active ? colorValue : void 0,
|
|
15
15
|
...props.style
|
|
16
|
-
}, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, onClick: e => {
|
|
16
|
+
}, "data-color": colorValue, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, onClick: e => {
|
|
17
17
|
!disabled && props.onClick?.(e);
|
|
18
18
|
}, children: [!!prefix &&
|
|
19
19
|
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.tabPrefix, children: prefix }), (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.label, children: label }), !!suffix &&
|
|
@@ -9,7 +9,7 @@ export interface TabsProps<T extends TabType = TabType> extends Omit<DivProps, '
|
|
|
9
9
|
variant?: 'line' | 'card';
|
|
10
10
|
color?: ColorPropsValue;
|
|
11
11
|
size?: Size;
|
|
12
|
-
|
|
12
|
+
/** 选项卡的位置,默认为`top` */
|
|
13
13
|
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
14
14
|
justifyContent?: CSSProperties['justifyContent'];
|
|
15
15
|
fullWidth?: boolean;
|
|
@@ -21,11 +21,8 @@ export interface TabsProps<T extends TabType = TabType> extends Omit<DivProps, '
|
|
|
21
21
|
readOnly?: boolean;
|
|
22
22
|
disabled?: boolean;
|
|
23
23
|
}
|
|
24
|
-
export type ActiveTabRef = {
|
|
25
|
-
el: HTMLElement | null;
|
|
26
|
-
color: string;
|
|
27
|
-
};
|
|
28
24
|
export declare function useTabsContext(): {
|
|
25
|
+
color?: ColorPropsValue;
|
|
29
26
|
variant?: TabsProps["variant"];
|
|
30
27
|
animating?: boolean;
|
|
31
28
|
};
|
|
@@ -3,21 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Tabs = void 0;
|
|
4
4
|
exports.useTabsContext = useTabsContext;
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
6
|
+
const react_1 = require("@emotion/react");
|
|
7
|
+
const react_2 = require("react");
|
|
7
8
|
const tabs_style_1 = require("./tabs.style");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
const theme_1 = require("../theme");
|
|
10
11
|
const tab_1 = require("./tab");
|
|
11
12
|
const tabsEllipsis_1 = require("./tabsEllipsis");
|
|
12
13
|
const lineIndicator_1 = require("./lineIndicator");
|
|
13
|
-
const TabsContext = (0,
|
|
14
|
+
const TabsContext = (0, react_2.createContext)({});
|
|
14
15
|
function useTabsContext() {
|
|
15
|
-
return (0,
|
|
16
|
+
return (0, react_2.useContext)(TabsContext);
|
|
16
17
|
}
|
|
17
|
-
exports.Tabs = (0,
|
|
18
|
+
exports.Tabs = (0, react_2.memo)(({ tabs, labelKey = 'label', primaryKey = 'value', variant = 'line', color = 'primary', size, position = 'top', justifyContent = 'flex-start', fullWidth, prefix, suffix, defaultValue, value, onChange, readOnly, disabled, ...props }) => {
|
|
18
19
|
const theme = (0, theme_1.useTheme)();
|
|
19
20
|
size ??= theme.size;
|
|
20
|
-
const [animating, setAnimating] = (0,
|
|
21
|
+
const [animating, setAnimating] = (0, react_2.useState)(false); // TODO 应当考虑value受控的情况,参考anchorList组件
|
|
21
22
|
const [innerValue, _setInnerValue] = (0, utils_1.useControlled)(defaultValue, value, onChange);
|
|
22
23
|
const setInnerValue = (value) => {
|
|
23
24
|
if (!readOnly && !disabled) {
|
|
@@ -29,7 +30,7 @@ exports.Tabs = (0, react_1.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
29
30
|
shouldScroll.current = true;
|
|
30
31
|
setInnerValue(value);
|
|
31
32
|
};
|
|
32
|
-
const tabRefs = (0,
|
|
33
|
+
const tabRefs = (0, react_2.useRef)(new Map());
|
|
33
34
|
const getActiveTab = () => {
|
|
34
35
|
return (0, utils_1.isUnset)(innerValue.current) ? void 0 : tabRefs.current.get(innerValue.current);
|
|
35
36
|
};
|
|
@@ -38,26 +39,25 @@ exports.Tabs = (0, react_1.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
38
39
|
return tabs.map((p, i) => {
|
|
39
40
|
const value = p[primaryKey];
|
|
40
41
|
const active = !(0, utils_1.isUnset)(value) && value === innerValue.current;
|
|
41
|
-
return ((0,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
tabRefs.current.delete(value);
|
|
45
|
-
};
|
|
42
|
+
return ((0, react_1.createElement)(tab_1.Tab, { ...p, key: p.key ?? value ?? i, ref: el => {
|
|
43
|
+
el
|
|
44
|
+
? tabRefs.current.set(value, el)
|
|
45
|
+
: tabRefs.current.delete(value);
|
|
46
46
|
}, value: value, label: p[labelKey], onClick: e => {
|
|
47
47
|
p.onClick?.(e);
|
|
48
48
|
setInnerValue(value);
|
|
49
|
-
}, _active: active }
|
|
49
|
+
}, _active: active }));
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
return
|
|
53
|
-
if ((0,
|
|
54
|
-
const { value,
|
|
52
|
+
return react_2.Children.map(props.children, c => {
|
|
53
|
+
if ((0, react_2.isValidElement)(c)) {
|
|
54
|
+
const { value, onClick } = c.props;
|
|
55
55
|
const active = !(0, utils_1.isUnset)(value) && value === innerValue.current;
|
|
56
|
-
return (0,
|
|
56
|
+
return (0, react_2.cloneElement)(c, {
|
|
57
57
|
ref: (0, utils_1.cloneRef)(c.ref, el => {
|
|
58
58
|
if (!(0, utils_1.isUnset)(value)) {
|
|
59
59
|
el
|
|
60
|
-
? tabRefs.current.set(value,
|
|
60
|
+
? tabRefs.current.set(value, el)
|
|
61
61
|
: tabRefs.current.delete(value);
|
|
62
62
|
}
|
|
63
63
|
}),
|
|
@@ -75,9 +75,9 @@ exports.Tabs = (0, react_1.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
75
75
|
* ----------------------------------------------------------------
|
|
76
76
|
* 滚动
|
|
77
77
|
*/
|
|
78
|
-
const scrollRef = (0,
|
|
79
|
-
const [shadowStart, setShadowStart] = (0,
|
|
80
|
-
const [shadowEnd, setShadowEnd] = (0,
|
|
78
|
+
const scrollRef = (0, react_2.useRef)(null);
|
|
79
|
+
const [shadowStart, setShadowStart] = (0, react_2.useState)(false);
|
|
80
|
+
const [shadowEnd, setShadowEnd] = (0, react_2.useState)(false);
|
|
81
81
|
const setShadow = () => {
|
|
82
82
|
if (position === 'top' || position === 'bottom') {
|
|
83
83
|
const { scrollLeft } = scrollRef.current;
|
|
@@ -90,7 +90,7 @@ exports.Tabs = (0, react_1.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
90
90
|
setShadowEnd(scrollTop < scrollRef.current.scrollHeight - scrollRef.current.clientHeight);
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
|
-
(0,
|
|
93
|
+
(0, react_2.useEffect)(() => {
|
|
94
94
|
const scroller = scrollRef.current;
|
|
95
95
|
const onWheel = (e) => {
|
|
96
96
|
scroller.scrollTo({
|
|
@@ -107,16 +107,20 @@ exports.Tabs = (0, react_1.memo)(({ tabs, labelKey = 'label', primaryKey = 'valu
|
|
|
107
107
|
resizeObserver.disconnect();
|
|
108
108
|
};
|
|
109
109
|
}, [position]);
|
|
110
|
-
const shouldScroll = (0,
|
|
111
|
-
(0,
|
|
110
|
+
const shouldScroll = (0, react_2.useRef)(true);
|
|
111
|
+
(0, react_2.useEffect)(() => {
|
|
112
112
|
if (shouldScroll.current) {
|
|
113
|
-
getActiveTab()?.
|
|
113
|
+
getActiveTab()?.scrollIntoView({ block: 'center', inline: 'center', behavior: 'smooth' });
|
|
114
114
|
shouldScroll.current = false;
|
|
115
115
|
}
|
|
116
116
|
}, [shouldScroll.current]);
|
|
117
|
-
return ((0, jsx_runtime_1.jsxs)("div", { ...props, css: (0, tabs_style_1.useStyle)({ color
|
|
118
|
-
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.prefix, children: prefix }) }), (0, jsx_runtime_1.jsx)("div", { ref: scrollRef, className: tabs_style_1.classes.scroll, onScroll: setShadow, children: (0, jsx_runtime_1.
|
|
119
|
-
|
|
117
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ...props, css: (0, tabs_style_1.useStyle)({ color, variant }), className: (0, utils_1.clsx)(tabs_style_1.classes.root, props.className), "data-size": size, "data-position": position, "data-animating": animating, "data-full-width": fullWidth, "data-read-only": readOnly, "data-disabled": disabled, children: [(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.start, "data-show": shadowStart, children: !!prefix &&
|
|
118
|
+
(0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.prefix, children: prefix }) }), (0, jsx_runtime_1.jsx)("div", { ref: scrollRef, className: tabs_style_1.classes.scroll, onScroll: setShadow, children: (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.scrollWrap, style: { justifyContent }, children: (0, jsx_runtime_1.jsxs)(TabsContext, { value: (0, react_2.useMemo)(() => ({
|
|
119
|
+
color, variant, animating
|
|
120
|
+
}), [
|
|
121
|
+
color, variant, animating
|
|
122
|
+
]), children: [renderTabs(), variant === 'line' &&
|
|
123
|
+
(0, jsx_runtime_1.jsx)(lineIndicator_1.LineIndicator, { value: innerValue.current, position: position, getActiveTab: getActiveTab, onTransitionEnd: () => setAnimating(false) })] }) }) }), (0, jsx_runtime_1.jsx)("div", { className: tabs_style_1.classes.end, "data-show": shadowEnd, children: !!(suffix || shadowStart || shadowEnd) &&
|
|
120
124
|
(0, jsx_runtime_1.jsxs)("div", { className: tabs_style_1.classes.suffix, children: [(shadowStart || shadowEnd) &&
|
|
121
125
|
(0, jsx_runtime_1.jsx)(tabsEllipsis_1.TabsEllipsis, { tabs: tabs, labelKey: labelKey, primaryKey: primaryKey, value: innerValue.current, onToggleSelected: setValueInEllipsis, children: props.children }), suffix] }) })] }));
|
|
122
126
|
});
|
|
@@ -3,30 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Timeline = void 0;
|
|
4
4
|
exports.useTimelineContext = useTimelineContext;
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
6
|
+
const react_1 = require("@emotion/react");
|
|
7
|
+
const react_2 = require("react");
|
|
7
8
|
const timeline_style_1 = require("./timeline.style");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
9
10
|
const timelineItem_1 = require("./timelineItem");
|
|
10
|
-
const TimelineContext = (0,
|
|
11
|
+
const TimelineContext = (0, react_2.createContext)({});
|
|
11
12
|
function useTimelineContext() {
|
|
12
|
-
return (0,
|
|
13
|
+
return (0, react_2.useContext)(TimelineContext);
|
|
13
14
|
}
|
|
14
|
-
exports.Timeline = (0,
|
|
15
|
+
exports.Timeline = (0, react_2.memo)(({ items,
|
|
15
16
|
// 共享属性
|
|
16
17
|
variant = 'outlined', labelPosition = 'end', orientation = 'vertical', color = 'primary', ...props }) => {
|
|
17
18
|
const renderItems = () => {
|
|
18
19
|
if (items) {
|
|
19
20
|
return items.map((p, i) => {
|
|
20
|
-
return ((0,
|
|
21
|
+
return ((0, react_1.createElement)(timelineItem_1.TimelineItem, { ...p, key: p.key ?? i, _index: i }));
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
|
-
return
|
|
24
|
-
if ((0,
|
|
25
|
-
return (0,
|
|
24
|
+
return react_2.Children.map(props.children, (child, _index) => {
|
|
25
|
+
if ((0, react_2.isValidElement)(child)) {
|
|
26
|
+
return (0, react_2.cloneElement)(child, { _index });
|
|
26
27
|
}
|
|
27
28
|
return child;
|
|
28
29
|
});
|
|
29
30
|
};
|
|
30
|
-
return ((0, jsx_runtime_1.jsx)("div", { ...props, css: timeline_style_1.style, className: (0, utils_1.clsx)(timeline_style_1.classes.root, props.className), "data-label-position": labelPosition, "data-orientation": orientation, children: (0, jsx_runtime_1.jsx)(TimelineContext, { value: (0,
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)("div", { ...props, css: timeline_style_1.style, className: (0, utils_1.clsx)(timeline_style_1.classes.root, props.className), "data-label-position": labelPosition, "data-orientation": orientation, children: (0, jsx_runtime_1.jsx)(TimelineContext, { value: (0, react_2.useMemo)(() => ({ variant, labelPosition, color, orientation }), [variant, labelPosition, color, orientation]), children: renderItems() }) }));
|
|
31
32
|
});
|
|
32
33
|
exports.Timeline.Item = timelineItem_1.TimelineItem;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ToggleButton = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const flex_1 = require("../flex");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const toggleButton_style_1 = require("./toggleButton.style");
|
|
@@ -35,13 +36,13 @@ exports.ToggleButton = (({ variant = 'filled', size, color = 'primary', disabled
|
|
|
35
36
|
if (items) {
|
|
36
37
|
return items.map((p, i) => {
|
|
37
38
|
const itemValue = p[primaryKey];
|
|
38
|
-
return ((0,
|
|
39
|
+
return ((0, react_1.createElement)(button_1.Button, { ...p, key: itemValue ?? i, ...makeProps(p, itemValue, (0, utils_1.isSelected)(itemValue, innerValue)) }, p.children));
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
-
if ((0,
|
|
42
|
+
return react_2.Children.map(props.children, c => {
|
|
43
|
+
if ((0, react_2.isValidElement)(c)) {
|
|
43
44
|
const { props } = c;
|
|
44
|
-
return (0,
|
|
45
|
+
return (0, react_2.cloneElement)(c, makeProps(props, props.value, (0, utils_1.isSelected)(props.value, innerValue)));
|
|
45
46
|
}
|
|
46
47
|
return c;
|
|
47
48
|
});
|
|
@@ -4,9 +4,9 @@ Promise.withResolvers ||= function withResolvers() {
|
|
|
4
4
|
if (!this)
|
|
5
5
|
throw new TypeError('Promise.withResolvers called on non-object');
|
|
6
6
|
const out = {};
|
|
7
|
-
out.promise = new this((
|
|
8
|
-
out.resolve =
|
|
9
|
-
out.reject =
|
|
7
|
+
out.promise = new this((resolve, reject) => {
|
|
8
|
+
out.resolve = resolve;
|
|
9
|
+
out.reject = reject;
|
|
10
10
|
});
|
|
11
11
|
return out;
|
|
12
12
|
};
|
|
@@ -15,7 +15,7 @@ export const AvatarGroup = memo(({ color, size, shape = 'circular', imgProps, it
|
|
|
15
15
|
const isSurplus = total > max;
|
|
16
16
|
const renderItems = () => {
|
|
17
17
|
if (items?.length) {
|
|
18
|
-
return items.slice(0, isSurplus ? max - 1 : max).reverse().map((p, i) => _createElement(Avatar, { ...commonProps, key: p.key ?? i
|
|
18
|
+
return items.slice(0, isSurplus ? max - 1 : max).reverse().map((p, i) => _createElement(Avatar, { ...commonProps, ...p, key: p.key ?? i }, p.children));
|
|
19
19
|
}
|
|
20
20
|
return Children.toArray(props.children).slice(0, isSurplus ? max - 1 : max).reverse().map(child => {
|
|
21
21
|
return isValidElement(child)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, isValidElement, memo } from 'react';
|
|
3
4
|
import { classes, style } from './bottomNavigation.style';
|
|
4
5
|
import { clsx, isUnset, useControlled } from '../../utils';
|
|
@@ -9,10 +10,10 @@ export const BottomNavigation = memo(({ items, showLabelInactive, primaryKey = '
|
|
|
9
10
|
if (items) {
|
|
10
11
|
return items.map((p, i) => {
|
|
11
12
|
const itemValue = p[primaryKey];
|
|
12
|
-
return (
|
|
13
|
+
return (_createElement(BottomNavigationItem, { ...p, key: p.key ?? itemValue ?? i, value: itemValue, label: p[labelKey], showLabelInactive: p.showLabelInactive ?? showLabelInactive ?? items.length <= 3, active: !isUnset(itemValue) && innerValue.current === itemValue, onClick: e => {
|
|
13
14
|
p.onClick?.(e);
|
|
14
15
|
setInnerValue(itemValue);
|
|
15
|
-
} }
|
|
16
|
+
} }));
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
19
|
showLabelInactive ??= Children.count(props.children) <= 3;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, isValidElement, memo } from 'react';
|
|
3
4
|
import { clsx } from '../../utils';
|
|
4
5
|
import { classes, style } from './breadcrumb.style';
|
|
@@ -8,10 +9,10 @@ export const Breadcrumb = memo(({ separator = '/', readOnly, items, ...props })
|
|
|
8
9
|
const { text } = useTheme();
|
|
9
10
|
const renderItems = () => {
|
|
10
11
|
if (items) {
|
|
11
|
-
return items.flatMap(({ icon,
|
|
12
|
+
return items.flatMap(({ icon, ...p }, i) => {
|
|
12
13
|
const isLast = i === items.length - 1;
|
|
13
14
|
return [
|
|
14
|
-
|
|
15
|
+
_createElement(Button, { ...p, key: p.key ?? i, variant: p.variant ?? 'plain', color: p.color ?? (isLast ? text.primary : text.disabled), readOnly: p.readOnly ?? (isLast || readOnly), prefix: p.prefix ?? icon }, p.children),
|
|
15
16
|
...isLast ? [] : [
|
|
16
17
|
_jsx("span", { className: classes.separator, children: separator }, `${classes.separator}_${i}`)
|
|
17
18
|
]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, createContext, isValidElement, useContext, useMemo } from 'react';
|
|
3
4
|
import { Flex } from '../flex';
|
|
4
5
|
import { clsx, isSelected } from '../../utils';
|
|
@@ -19,10 +20,10 @@ export const CheckboxBaseGroup = (({ size, color, items, primaryKey = 'value', m
|
|
|
19
20
|
return items.map((p, i) => {
|
|
20
21
|
const Component = multiple ? Checkbox : Radio;
|
|
21
22
|
const itemValue = p[primaryKey];
|
|
22
|
-
return (
|
|
23
|
+
return (_createElement(Component, { ...p, key: p.key ?? itemValue ?? i, size: p.size ?? size, color: p.color ?? color, checked: isSelected(itemValue, innerValue), onChange: e => {
|
|
23
24
|
p.onChange?.(e);
|
|
24
25
|
toggleSelected(itemValue);
|
|
25
|
-
} }
|
|
26
|
+
} }));
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
return Children.map(props.children, c => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Dispatch, ReactElement, ReactNode, Ref, RefObject, SetStateAction, ElementType } from 'react';
|
|
2
|
-
import { Obj, OverridableProps } from '../../types';
|
|
2
|
+
import { Obj, OverridableProps, Size } from '../../types';
|
|
3
3
|
import { FieldPath } from '../../utils';
|
|
4
4
|
import { FieldError, FormItem, FormItemProps, FormItemRef } from './formItem';
|
|
5
5
|
import { FormRelatable } from './formRelatable';
|
|
@@ -11,6 +11,7 @@ export type FormSharedProps = {
|
|
|
11
11
|
requiredMark?: ReactNode;
|
|
12
12
|
/** variant为"grid"或"table"时会渲染Descriptions组件,并传递variant属性,默认为`grid` */
|
|
13
13
|
variant?: 'plain' | 'grid' | 'table';
|
|
14
|
+
size?: Size;
|
|
14
15
|
};
|
|
15
16
|
interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps, DescriptionsSharedProps, GridOwnProps {
|
|
16
17
|
ref?: Ref<FormRef<V> | null>;
|
|
@@ -77,7 +77,6 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
|
|
|
77
77
|
for (const [, item] of itemsContainer.current) {
|
|
78
78
|
item.reset(newValue);
|
|
79
79
|
}
|
|
80
|
-
console.log('after', newValue);
|
|
81
80
|
setFormValue(newValue);
|
|
82
81
|
},
|
|
83
82
|
resetField: field => {
|
|
@@ -89,10 +88,10 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
|
|
|
89
88
|
};
|
|
90
89
|
useImperativeHandle(ref, () => formRef.current);
|
|
91
90
|
return (_jsx(Component, { ...props, ref: wrapperRef, css: style, className: clsx(classes.root, props.className), onSubmit: submitHandler, children: _jsx(FormContext, { value: useMemo(() => ({
|
|
92
|
-
requiredMark, variant,
|
|
91
|
+
requiredMark, variant, size,
|
|
93
92
|
formValue: formValue.current, setFieldValue,
|
|
94
93
|
itemsContainer: itemsContainer.current, formRef
|
|
95
|
-
}), [requiredMark, variant, formValue.current]), children: variant === 'plain'
|
|
94
|
+
}), [requiredMark, variant, size, formValue.current]), children: variant === 'plain'
|
|
96
95
|
? props.children
|
|
97
96
|
: _jsx(Descriptions, { ...descriptionsProps, size: size, labelWidth: labelWidth, colon: colon, labelPlacement: labelPlacement, disableMargin: disableMargin, disablePadding: disablePadding, items: items, variant: variant, itemComponent: FormItem, inline: inline, columnCount: columnCount, gap: gap, columnGap: columnGap, rowGap: rowGap, children: props.children }) }) }));
|
|
98
97
|
});
|
|
@@ -5,10 +5,11 @@ import { clsx, getValueOnChange, queryDeep, stringifyField, useDerivedState, toA
|
|
|
5
5
|
import { DescriptionItem } from '../descriptions';
|
|
6
6
|
import { classes } from './form.style';
|
|
7
7
|
import { Collapse } from '../transitionBase';
|
|
8
|
-
export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, ...props }) => {
|
|
8
|
+
export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, size, ...props }) => {
|
|
9
9
|
const { formValue, setFieldValue, itemsContainer, formRef, ...context } = useFormContext();
|
|
10
10
|
requiredMark ??= context.requiredMark ?? '*';
|
|
11
11
|
variant ??= context.variant ?? 'grid';
|
|
12
|
+
size ??= context.size;
|
|
12
13
|
/**
|
|
13
14
|
* --------------------------------------------------------------------
|
|
14
15
|
* 字段值
|
|
@@ -134,7 +135,7 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
: {}, {
|
|
137
|
-
...
|
|
138
|
+
...size && { size },
|
|
138
139
|
...innerError.current ? { color: 'error' } : {}
|
|
139
140
|
}, randomKey.current);
|
|
140
141
|
}
|
|
@@ -152,12 +153,12 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
|
|
|
152
153
|
setFieldValue?.(field, getValueOnChange(e, fieldValue));
|
|
153
154
|
}
|
|
154
155
|
},
|
|
155
|
-
...
|
|
156
|
+
...size && { size },
|
|
156
157
|
...innerError.current && { color: 'error' }
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
return children;
|
|
160
|
-
}, [children,
|
|
161
|
+
}, [children, innerError.current, field, size, randomKey.current]);
|
|
161
162
|
if (noStyle || variant === 'plain') {
|
|
162
163
|
return renderedChildren;
|
|
163
164
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { createContext, memo, useContext, useMemo } from 'react';
|
|
3
4
|
import { style } from './menu.style';
|
|
4
5
|
import { MenuItem } from '../menuItem';
|
|
@@ -27,7 +28,7 @@ size = 'large', showCheckbox, ellipsis, indent, ...props }) => {
|
|
|
27
28
|
};
|
|
28
29
|
const [innerValue, toggleSelected] = useShallowSelection({ multiple, defaultValue, value, onChange });
|
|
29
30
|
const renderItems = (items) => {
|
|
30
|
-
return items?.map((p, i) =>
|
|
31
|
+
return items?.map((p, i) => _createElement(MenuItem, { ...p, key: p[primaryKey] ?? i, value: p[primaryKey], label: p[labelKey] }, renderItems(p[childrenKey])));
|
|
31
32
|
};
|
|
32
33
|
return (_jsx("div", { ...props, css: style, children: _jsx(MenuContext, { value: useMemo(() => ({
|
|
33
34
|
inMenu: true,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, isValidElement, memo, useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { classes, useStyle } from './segmented.style';
|
|
4
5
|
import { clsx, cloneRef, isUnset, useControlled, useDerivedState } from '../../utils';
|
|
@@ -46,14 +47,14 @@ export const Segmented = memo(({ options, orientation = 'horizontal', size, labe
|
|
|
46
47
|
return options.map((p, i) => {
|
|
47
48
|
const v = p[primaryKey];
|
|
48
49
|
const active = !isUnset(v) && v === innerValue.current;
|
|
49
|
-
return (
|
|
50
|
+
return (_createElement(SegmentedOption, { ...p, key: p.key ?? v ?? i, ref: r => {
|
|
50
51
|
r
|
|
51
52
|
? optionRefs.current.set(v, r)
|
|
52
53
|
: optionRefs.current.delete(v);
|
|
53
54
|
}, value: v, label: p[labelKey], onClick: e => {
|
|
54
55
|
p.onClick?.(e);
|
|
55
56
|
setInnerValue(v);
|
|
56
|
-
}, "data-active": active }
|
|
57
|
+
}, "data-active": active }));
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
return Children.map(props.children, c => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, createContext, isValidElement, useContext, useMemo } from 'react';
|
|
3
4
|
import { clsx, useControlled } from '../../utils';
|
|
4
5
|
import { classes, style } from './stepper.style';
|
|
@@ -15,14 +16,14 @@ size, gap = orientation === 'horizontal' ? 15 : 9, color, variant, clickable, la
|
|
|
15
16
|
if (steps) {
|
|
16
17
|
return steps.map((p, i) => {
|
|
17
18
|
const isCurrentStep = i === innerValue.current;
|
|
18
|
-
return (
|
|
19
|
+
return (_createElement(Step, { ...p, key: p.key ?? i, step: i, status: p.status ?? (isCurrentStep
|
|
19
20
|
? status ?? 'processing'
|
|
20
21
|
: i < innerValue.current
|
|
21
22
|
? 'finished'
|
|
22
23
|
: 'waiting'), clickable: p.clickable ?? clickable, onClick: e => {
|
|
23
24
|
p.onClick?.(e);
|
|
24
25
|
(p.clickable ?? clickable) && setInnerValue(i);
|
|
25
|
-
}, "data-orientation": orientation }
|
|
26
|
+
}, "data-orientation": orientation }));
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
return Children.map(props.children, (c, i) => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ActiveTabRef } from './tabs';
|
|
2
1
|
import { Id } from '../../types';
|
|
3
2
|
export declare function LineIndicator({ value, position, getActiveTab, onTransitionEnd }: {
|
|
4
3
|
value?: Id;
|
|
5
4
|
position: 'top' | 'bottom' | 'left' | 'right';
|
|
6
|
-
getActiveTab():
|
|
5
|
+
getActiveTab(): HTMLDivElement | undefined;
|
|
7
6
|
onTransitionEnd(): void;
|
|
8
7
|
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -3,19 +3,21 @@ import { useEffect, useState } from 'react';
|
|
|
3
3
|
import { classes, indicatorWidth } from './tabs.style';
|
|
4
4
|
import { colorTransfer } from '../../utils';
|
|
5
5
|
import { useTheme } from '../theme';
|
|
6
|
+
import { useTabsContext } from './tabs';
|
|
6
7
|
export function LineIndicator({ value, position, getActiveTab, onTransitionEnd }) {
|
|
8
|
+
const context = useTabsContext();
|
|
9
|
+
const [color, setColor] = useState(context.color);
|
|
7
10
|
const [boundingRect, setBoundingRect] = useState();
|
|
8
|
-
const [color, setColor] = useState('primary');
|
|
9
11
|
useEffect(() => {
|
|
10
|
-
const
|
|
11
|
-
if (!
|
|
12
|
+
const activeTab = getActiveTab();
|
|
13
|
+
if (!activeTab) {
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
14
16
|
if (position === 'top' || position === 'bottom') {
|
|
15
17
|
setBoundingRect({
|
|
16
|
-
width:
|
|
18
|
+
width: activeTab.offsetWidth,
|
|
17
19
|
height: indicatorWidth,
|
|
18
|
-
left:
|
|
20
|
+
left: activeTab.offsetLeft,
|
|
19
21
|
...position === 'top'
|
|
20
22
|
? { bottom: 0 }
|
|
21
23
|
: { top: 0 }
|
|
@@ -25,14 +27,14 @@ export function LineIndicator({ value, position, getActiveTab, onTransitionEnd }
|
|
|
25
27
|
// position === 'left' || position === 'right'
|
|
26
28
|
setBoundingRect({
|
|
27
29
|
width: indicatorWidth,
|
|
28
|
-
height:
|
|
29
|
-
top:
|
|
30
|
+
height: activeTab.offsetHeight,
|
|
31
|
+
top: activeTab.offsetTop,
|
|
30
32
|
...position === 'left'
|
|
31
33
|
? { right: 0 }
|
|
32
34
|
: { left: 0 }
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
|
-
setColor(color);
|
|
37
|
+
activeTab.dataset.color && setColor(activeTab.dataset.color);
|
|
36
38
|
}, [value]);
|
|
37
39
|
const theme = useTheme();
|
|
38
40
|
return (_jsx("div", { className: classes.indicator, onTransitionEnd: onTransitionEnd, style: {
|
|
@@ -3,14 +3,14 @@ import { memo } from 'react';
|
|
|
3
3
|
import { clsx, useColor } from '../../utils';
|
|
4
4
|
import { classes } from './tabs.style';
|
|
5
5
|
import { useTabsContext } from './tabs';
|
|
6
|
-
export const Tab = memo(({ prefix, suffix, color
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
export const Tab = memo(({ prefix, suffix, color, orientation, label, value, disabled, _active, ...props }) => {
|
|
7
|
+
const { color: contextColor, variant, animating } = useTabsContext();
|
|
8
|
+
const colorValue = useColor(color ?? contextColor);
|
|
9
9
|
return (_jsxs("div", { ...props, className: clsx(classes.tab, props.className), style: {
|
|
10
10
|
borderColor: variant === 'line' && !animating && _active ? colorValue : void 0,
|
|
11
11
|
color: _active ? colorValue : void 0,
|
|
12
12
|
...props.style
|
|
13
|
-
}, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, onClick: e => {
|
|
13
|
+
}, "data-color": colorValue, "data-disabled": disabled, "data-orientation": orientation, "data-active": _active, onClick: e => {
|
|
14
14
|
!disabled && props.onClick?.(e);
|
|
15
15
|
}, children: [!!prefix &&
|
|
16
16
|
_jsx("div", { className: classes.tabPrefix, children: prefix }), _jsx("div", { className: classes.label, children: label }), !!suffix &&
|
|
@@ -9,7 +9,7 @@ export interface TabsProps<T extends TabType = TabType> extends Omit<DivProps, '
|
|
|
9
9
|
variant?: 'line' | 'card';
|
|
10
10
|
color?: ColorPropsValue;
|
|
11
11
|
size?: Size;
|
|
12
|
-
|
|
12
|
+
/** 选项卡的位置,默认为`top` */
|
|
13
13
|
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
14
14
|
justifyContent?: CSSProperties['justifyContent'];
|
|
15
15
|
fullWidth?: boolean;
|
|
@@ -21,11 +21,8 @@ export interface TabsProps<T extends TabType = TabType> extends Omit<DivProps, '
|
|
|
21
21
|
readOnly?: boolean;
|
|
22
22
|
disabled?: boolean;
|
|
23
23
|
}
|
|
24
|
-
export type ActiveTabRef = {
|
|
25
|
-
el: HTMLElement | null;
|
|
26
|
-
color: string;
|
|
27
|
-
};
|
|
28
24
|
export declare function useTabsContext(): {
|
|
25
|
+
color?: ColorPropsValue;
|
|
29
26
|
variant?: TabsProps["variant"];
|
|
30
27
|
animating?: boolean;
|
|
31
28
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, createContext, isValidElement, memo, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
4
|
import { classes, useStyle } from './tabs.style';
|
|
4
5
|
import { clsx, cloneRef, isUnset, useControlled } from '../../utils';
|
|
@@ -34,26 +35,25 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', vari
|
|
|
34
35
|
return tabs.map((p, i) => {
|
|
35
36
|
const value = p[primaryKey];
|
|
36
37
|
const active = !isUnset(value) && value === innerValue.current;
|
|
37
|
-
return (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
tabRefs.current.delete(value);
|
|
41
|
-
};
|
|
38
|
+
return (_createElement(Tab, { ...p, key: p.key ?? value ?? i, ref: el => {
|
|
39
|
+
el
|
|
40
|
+
? tabRefs.current.set(value, el)
|
|
41
|
+
: tabRefs.current.delete(value);
|
|
42
42
|
}, value: value, label: p[labelKey], onClick: e => {
|
|
43
43
|
p.onClick?.(e);
|
|
44
44
|
setInnerValue(value);
|
|
45
|
-
}, _active: active }
|
|
45
|
+
}, _active: active }));
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
return Children.map(props.children, c => {
|
|
49
49
|
if (isValidElement(c)) {
|
|
50
|
-
const { value,
|
|
50
|
+
const { value, onClick } = c.props;
|
|
51
51
|
const active = !isUnset(value) && value === innerValue.current;
|
|
52
52
|
return cloneElement(c, {
|
|
53
53
|
ref: cloneRef(c.ref, el => {
|
|
54
54
|
if (!isUnset(value)) {
|
|
55
55
|
el
|
|
56
|
-
? tabRefs.current.set(value,
|
|
56
|
+
? tabRefs.current.set(value, el)
|
|
57
57
|
: tabRefs.current.delete(value);
|
|
58
58
|
}
|
|
59
59
|
}),
|
|
@@ -106,13 +106,17 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', vari
|
|
|
106
106
|
const shouldScroll = useRef(true);
|
|
107
107
|
useEffect(() => {
|
|
108
108
|
if (shouldScroll.current) {
|
|
109
|
-
getActiveTab()?.
|
|
109
|
+
getActiveTab()?.scrollIntoView({ block: 'center', inline: 'center', behavior: 'smooth' });
|
|
110
110
|
shouldScroll.current = false;
|
|
111
111
|
}
|
|
112
112
|
}, [shouldScroll.current]);
|
|
113
|
-
return (_jsxs("div", { ...props, css: useStyle({ color
|
|
114
|
-
_jsx("div", { className: classes.prefix, children: prefix }) }), _jsx("div", { ref: scrollRef, className: classes.scroll, onScroll: setShadow, children:
|
|
115
|
-
|
|
113
|
+
return (_jsxs("div", { ...props, css: useStyle({ color, variant }), className: clsx(classes.root, props.className), "data-size": size, "data-position": position, "data-animating": animating, "data-full-width": fullWidth, "data-read-only": readOnly, "data-disabled": disabled, children: [_jsx("div", { className: classes.start, "data-show": shadowStart, children: !!prefix &&
|
|
114
|
+
_jsx("div", { className: classes.prefix, children: prefix }) }), _jsx("div", { ref: scrollRef, className: classes.scroll, onScroll: setShadow, children: _jsx("div", { className: classes.scrollWrap, style: { justifyContent }, children: _jsxs(TabsContext, { value: useMemo(() => ({
|
|
115
|
+
color, variant, animating
|
|
116
|
+
}), [
|
|
117
|
+
color, variant, animating
|
|
118
|
+
]), children: [renderTabs(), variant === 'line' &&
|
|
119
|
+
_jsx(LineIndicator, { value: innerValue.current, position: position, getActiveTab: getActiveTab, onTransitionEnd: () => setAnimating(false) })] }) }) }), _jsx("div", { className: classes.end, "data-show": shadowEnd, children: !!(suffix || shadowStart || shadowEnd) &&
|
|
116
120
|
_jsxs("div", { className: classes.suffix, children: [(shadowStart || shadowEnd) &&
|
|
117
121
|
_jsx(TabsEllipsis, { tabs: tabs, labelKey: labelKey, primaryKey: primaryKey, value: innerValue.current, onToggleSelected: setValueInEllipsis, children: props.children }), suffix] }) })] }));
|
|
118
122
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, createContext, isValidElement, memo, useContext, useMemo } from 'react';
|
|
3
4
|
import { classes, style } from './timeline.style';
|
|
4
5
|
import { clsx } from '../../utils';
|
|
@@ -13,7 +14,7 @@ variant = 'outlined', labelPosition = 'end', orientation = 'vertical', color = '
|
|
|
13
14
|
const renderItems = () => {
|
|
14
15
|
if (items) {
|
|
15
16
|
return items.map((p, i) => {
|
|
16
|
-
return (
|
|
17
|
+
return (_createElement(TimelineItem, { ...p, key: p.key ?? i, _index: i }));
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
return Children.map(props.children, (child, _index) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, cloneElement, isValidElement } from 'react';
|
|
3
4
|
import { Flex } from '../flex';
|
|
4
5
|
import { clsx, isSelected } from '../../utils';
|
|
@@ -32,7 +33,7 @@ export const ToggleButton = (({ variant = 'filled', size, color = 'primary', dis
|
|
|
32
33
|
if (items) {
|
|
33
34
|
return items.map((p, i) => {
|
|
34
35
|
const itemValue = p[primaryKey];
|
|
35
|
-
return (
|
|
36
|
+
return (_createElement(Button, { ...p, key: itemValue ?? i, ...makeProps(p, itemValue, isSelected(itemValue, innerValue)) }, p.children));
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
return Children.map(props.children, c => {
|
|
@@ -2,9 +2,9 @@ Promise.withResolvers ||= function withResolvers() {
|
|
|
2
2
|
if (!this)
|
|
3
3
|
throw new TypeError('Promise.withResolvers called on non-object');
|
|
4
4
|
const out = {};
|
|
5
|
-
out.promise = new this((
|
|
6
|
-
out.resolve =
|
|
7
|
-
out.reject =
|
|
5
|
+
out.promise = new this((resolve, reject) => {
|
|
6
|
+
out.resolve = resolve;
|
|
7
|
+
out.reject = reject;
|
|
8
8
|
});
|
|
9
9
|
return out;
|
|
10
10
|
};
|