@laser-ui/components 1.6.0 → 2.0.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/CHANGELOG.md +16 -0
- package/accordion/Accordion.d.ts +1 -1
- package/accordion/Accordion.js +13 -25
- package/accordion/types.d.ts +1 -0
- package/affix/Affix.d.ts +2 -2
- package/affix/Affix.js +27 -32
- package/affix/types.d.ts +7 -2
- package/alert/Alert.d.ts +1 -1
- package/alert/Alert.js +12 -21
- package/anchor/Anchor.d.ts +2 -4
- package/anchor/Anchor.js +34 -26
- package/anchor/types.d.ts +1 -0
- package/avatar/Avatar.d.ts +1 -1
- package/avatar/Avatar.js +9 -3
- package/badge/Badge.d.ts +1 -1
- package/badge/Badge.js +22 -41
- package/badge/BadgeText.js +12 -26
- package/badge/internal/BadgeNumber.d.ts +2 -2
- package/badge/internal/BadgeNumber.js +34 -24
- package/base-input/BaseInput.d.ts +1 -2
- package/base-input/BaseInput.js +4 -4
- package/base-input/types.d.ts +1 -0
- package/breadcrumb/Breadcrumb.d.ts +1 -1
- package/button/Button.d.ts +1 -2
- package/button/Button.js +18 -22
- package/button/types.d.ts +1 -0
- package/card/Card.d.ts +1 -1
- package/card/CardAction.d.ts +1 -1
- package/card/CardAction.js +3 -4
- package/card/CardActions.d.ts +1 -1
- package/card/CardActions.js +7 -3
- package/card/CardContent.d.ts +1 -1
- package/card/CardHeader.d.ts +1 -1
- package/card/types.d.ts +5 -1
- package/cascader/Cascader.d.ts +2 -4
- package/cascader/Cascader.js +217 -214
- package/cascader/internal/CascaderPanel.d.ts +2 -2
- package/cascader/internal/CascaderPanel.js +21 -7
- package/cascader/internal/CascaderSearchPanel.d.ts +2 -2
- package/cascader/internal/CascaderSearchPanel.js +15 -6
- package/cascader/types.d.ts +3 -3
- package/checkbox/Checkbox.d.ts +1 -1
- package/checkbox/Checkbox.js +4 -5
- package/checkbox/CheckboxGroup.d.ts +1 -1
- package/checkbox/CheckboxGroup.js +8 -7
- package/checkbox/types.d.ts +14 -4
- package/{internal/circular-progress → circular-progress}/CircularProgress.d.ts +1 -1
- package/{internal/circular-progress → circular-progress}/CircularProgress.js +2 -2
- package/compose/Compose.d.ts +1 -1
- package/compose/ComposeItem.d.ts +1 -1
- package/config-provider/ConfigProvider.d.ts +1 -1
- package/config-provider/ConfigProvider.js +3 -3
- package/date-picker/DatePicker.d.ts +2 -2
- package/date-picker/DatePicker.js +116 -98
- package/date-picker/internal/DatePickerPanel.d.ts +2 -1
- package/date-picker/internal/DatePickerPanel.js +4 -4
- package/date-picker/types.d.ts +3 -3
- package/dialog-service.d.ts +9 -6
- package/dialog-service.js +50 -26
- package/drawer/Drawer.d.ts +1 -1
- package/drawer/Drawer.js +83 -92
- package/drawer/DrawerFooter.d.ts +1 -1
- package/drawer/DrawerFooter.js +12 -9
- package/drawer/DrawerHeader.d.ts +1 -1
- package/drawer/DrawerHeader.js +10 -7
- package/drawer/types.d.ts +9 -2
- package/drawer/vars.d.ts +5 -1
- package/drawer/vars.js +1 -1
- package/dropdown/Dropdown.d.ts +2 -4
- package/dropdown/Dropdown.js +83 -104
- package/dropdown/internal/DropdownGroup.d.ts +1 -1
- package/dropdown/internal/DropdownItem.d.ts +1 -1
- package/dropdown/internal/DropdownSub.d.ts +2 -1
- package/dropdown/internal/DropdownSub.js +26 -49
- package/dropdown/types.d.ts +15 -2
- package/empty/Empty.d.ts +1 -1
- package/fab/Fab.d.ts +1 -1
- package/fab/Fab.js +19 -14
- package/fab/FabBacktop.d.ts +1 -1
- package/fab/FabBacktop.js +24 -31
- package/fab/FabButton.d.ts +1 -1
- package/fab/FabButton.js +37 -10
- package/fab/types.d.ts +6 -2
- package/fab/vars.d.ts +14 -0
- package/fab/vars.js +4 -0
- package/form/Form.d.ts +1 -1
- package/form/Form.js +7 -2
- package/form/FormItem.d.ts +1 -1
- package/form/FormItem.js +35 -24
- package/form/internal/FormError.d.ts +3 -2
- package/form/internal/FormError.js +10 -19
- package/hooks/index.d.ts +0 -2
- package/hooks/index.js +0 -2
- package/hooks/useComponentProps.js +2 -2
- package/hooks/useFocusVisible.d.ts +9 -2
- package/hooks/useFocusVisible.js +5 -11
- package/hooks/useLayout.d.ts +2 -2
- package/hooks/useLayout.js +2 -2
- package/hooks/useNamespace.js +2 -2
- package/hooks/useNestedPopup.d.ts +1 -1
- package/hooks/useScopedProps.js +2 -2
- package/hooks/useStyled.js +2 -2
- package/hooks/useTranslation.js +2 -2
- package/icon/Icon.d.ts +1 -1
- package/icon/Icon.js +7 -4
- package/image/Image.d.ts +1 -1
- package/image/Image.js +6 -2
- package/image/ImageAction.d.ts +1 -1
- package/image/ImageAction.js +3 -4
- package/image/ImageLoader.d.ts +1 -1
- package/image/ImagePreview.d.ts +1 -1
- package/image/ImagePreview.js +95 -110
- package/image/types.d.ts +6 -2
- package/input/Input.d.ts +1 -1
- package/input/Input.js +12 -8
- package/input/InputNumber.js +49 -40
- package/input/types.d.ts +3 -5
- package/internal/lazy-loading/LazyLoading.d.ts +3 -0
- package/internal/lazy-loading/LazyLoading.js +9 -0
- package/internal/lazy-loading/index.d.ts +2 -0
- package/internal/lazy-loading/index.js +1 -0
- package/internal/lazy-loading/types.d.ts +7 -0
- package/internal/popup/Popup.d.ts +1 -1
- package/internal/popup/Popup.js +40 -68
- package/internal/popup/types.d.ts +13 -6
- package/internal/portal/Portal.d.ts +1 -1
- package/internal/portal/Portal.js +12 -6
- package/internal/portal/types.d.ts +3 -2
- package/mask/Mask.d.ts +3 -0
- package/mask/Mask.js +31 -0
- package/menu/Menu.d.ts +2 -4
- package/menu/Menu.js +37 -42
- package/menu/internal/MenuGroup.d.ts +1 -1
- package/menu/internal/MenuItem.d.ts +1 -1
- package/menu/internal/MenuItem.js +14 -10
- package/menu/internal/MenuSub.d.ts +2 -1
- package/menu/internal/MenuSub.js +43 -70
- package/menu/types.d.ts +1 -0
- package/modal/Modal.d.ts +1 -1
- package/modal/Modal.js +77 -80
- package/modal/ModalAlert.d.ts +1 -1
- package/modal/ModalFooter.d.ts +1 -1
- package/modal/ModalFooter.js +12 -9
- package/modal/ModalHeader.d.ts +1 -1
- package/modal/ModalHeader.js +10 -7
- package/modal/types.d.ts +9 -2
- package/modal/vars.d.ts +5 -0
- package/modal/vars.js +2 -0
- package/notification/Notification.d.ts +1 -1
- package/notification/Notification.js +44 -71
- package/notification/types.d.ts +1 -0
- package/package.json +2 -2
- package/pagination/Pagination.d.ts +1 -1
- package/pagination/Pagination.js +9 -6
- package/popover/Popover.d.ts +2 -2
- package/popover/Popover.js +82 -118
- package/popover/PopoverFooter.d.ts +1 -1
- package/popover/PopoverFooter.js +12 -9
- package/popover/PopoverHeader.d.ts +1 -1
- package/popover/PopoverHeader.js +10 -7
- package/popover/types.d.ts +18 -4
- package/popover/vars.d.ts +5 -0
- package/popover/vars.js +2 -0
- package/progress/Progress.d.ts +1 -1
- package/radio/Radio.d.ts +1 -1
- package/radio/Radio.js +18 -13
- package/radio/RadioGroup.d.ts +1 -1
- package/radio/RadioGroup.js +12 -7
- package/radio/types.d.ts +16 -4
- package/radio/vars.d.ts +6 -0
- package/radio/vars.js +2 -0
- package/rating/Rating.d.ts +1 -1
- package/rating/internal/RatingStar.d.ts +1 -1
- package/rating/internal/RatingStar.js +23 -21
- package/root/Root.d.ts +1 -1
- package/root/Root.js +1 -1
- package/select/Select.d.ts +2 -4
- package/select/Select.js +245 -243
- package/select/types.d.ts +3 -3
- package/separator/Separator.d.ts +1 -1
- package/skeleton/Skeleton.d.ts +1 -1
- package/slider/Slider.d.ts +1 -1
- package/slider/Slider.js +54 -34
- package/slider/types.d.ts +2 -3
- package/slides/Slides.d.ts +1 -1
- package/slides/Slides.js +8 -3
- package/spinner/Spinner.d.ts +1 -1
- package/spinner/Spinner.js +27 -29
- package/stepper/Stepper.d.ts +1 -1
- package/stepper/Stepper.js +9 -16
- package/switch/Switch.js +33 -24
- package/switch/types.d.ts +2 -3
- package/table/Table.d.ts +1 -1
- package/table/Table.js +14 -10
- package/table/TableEmpty.d.ts +1 -1
- package/table/TableEmpty.js +9 -3
- package/table/TableExpand.d.ts +1 -1
- package/table/TableFilter.d.ts +1 -1
- package/table/TableFilter.js +1 -1
- package/table/TableTd.d.ts +1 -1
- package/table/TableTh.d.ts +1 -1
- package/table/TableThAction.d.ts +1 -1
- package/table/TableThAction.js +3 -4
- package/table/internal/TableCell.d.ts +1 -1
- package/table/internal/TableCell.js +13 -5
- package/table/types.d.ts +9 -2
- package/tabs/Tabs.d.ts +2 -4
- package/tabs/Tabs.js +41 -25
- package/tabs/types.d.ts +1 -0
- package/tag/Tag.d.ts +1 -1
- package/textarea/Textarea.d.ts +1 -1
- package/textarea/Textarea.js +15 -8
- package/textarea/types.d.ts +1 -0
- package/time-picker/TimePicker.d.ts +2 -2
- package/time-picker/TimePicker.js +89 -75
- package/time-picker/internal/TimePickerPanel.d.ts +2 -1
- package/time-picker/internal/TimePickerPanel.js +22 -7
- package/time-picker/types.d.ts +3 -3
- package/timeline/Timeline.d.ts +1 -1
- package/toast/Toast.d.ts +1 -1
- package/toast/Toast.js +44 -72
- package/toast/types.d.ts +1 -0
- package/tooltip/Tooltip.d.ts +2 -2
- package/tooltip/Tooltip.js +50 -74
- package/tooltip/types.d.ts +10 -2
- package/transfer/Transfer.d.ts +1 -1
- package/transfer/internal/TransferPanel.d.ts +1 -1
- package/transfer/internal/TransferPanel.js +7 -2
- package/{internal/transition → transition}/CollapseTransition.d.ts +1 -1
- package/transition/CollapseTransition.js +65 -0
- package/transition/Transition.d.ts +3 -0
- package/transition/Transition.js +148 -0
- package/transition/types.d.ts +29 -0
- package/tree/Tree.d.ts +1 -1
- package/tree/Tree.js +19 -7
- package/tree/internal/TreePanel.d.ts +2 -2
- package/tree/internal/TreePanel.js +32 -26
- package/tree-select/TreeSelect.d.ts +2 -4
- package/tree-select/TreeSelect.js +216 -213
- package/tree-select/internal/TreeSelectSearchPanel.d.ts +2 -2
- package/tree-select/internal/TreeSelectSearchPanel.js +15 -6
- package/tree-select/types.d.ts +3 -3
- package/types.d.ts +1 -1
- package/upload/Upload.d.ts +1 -3
- package/upload/Upload.js +41 -50
- package/upload/UploadAction.d.ts +1 -1
- package/upload/UploadAction.js +19 -16
- package/upload/UploadButton.d.ts +1 -1
- package/upload/UploadButton.js +16 -12
- package/upload/UploadList.d.ts +1 -1
- package/upload/UploadList.js +52 -47
- package/upload/UploadPicture.d.ts +1 -1
- package/upload/UploadPicture.js +47 -53
- package/upload/UploadPictureList.d.ts +1 -1
- package/upload/UploadPictureList.js +52 -47
- package/upload/UploadPreviewAction.d.ts +1 -1
- package/upload/UploadPreviewAction.js +15 -14
- package/upload/hooks.d.ts +2 -0
- package/upload/types.d.ts +27 -6
- package/upload/vars.d.ts +11 -0
- package/upload/vars.js +3 -0
- package/virtual-scroll/VirtualScroll.d.ts +2 -4
- package/virtual-scroll/VirtualScroll.js +13 -21
- package/virtual-scroll/types.d.ts +2 -1
- package/wave/Wave.d.ts +3 -0
- package/{internal/wave → wave}/Wave.js +6 -6
- package/{internal/wave → wave}/types.d.ts +1 -0
- package/wave/types.js +1 -0
- package/hooks/useJSS.d.ts +0 -1
- package/hooks/useJSS.js +0 -15
- package/hooks/useNextTick.d.ts +0 -2
- package/internal/mask/Mask.d.ts +0 -3
- package/internal/mask/Mask.js +0 -36
- package/internal/transition/CollapseTransition.js +0 -101
- package/internal/transition/Transition.d.ts +0 -3
- package/internal/transition/Transition.js +0 -87
- package/internal/transition/types.d.ts +0 -33
- package/internal/wave/Wave.d.ts +0 -3
- /package/{internal/circular-progress → circular-progress}/index.d.ts +0 -0
- /package/{internal/circular-progress → circular-progress}/index.js +0 -0
- /package/{internal/circular-progress → circular-progress}/vars.d.ts +0 -0
- /package/{internal/circular-progress → circular-progress}/vars.js +0 -0
- /package/internal/{mask → lazy-loading}/types.js +0 -0
- /package/{internal/mask → mask}/index.d.ts +0 -0
- /package/{internal/mask → mask}/index.js +0 -0
- /package/{internal/mask → mask}/types.d.ts +0 -0
- /package/{internal/transition → mask}/types.js +0 -0
- /package/{internal/mask → mask}/vars.d.ts +0 -0
- /package/{internal/mask → mask}/vars.js +0 -0
- /package/{internal/transition → transition}/index.d.ts +0 -0
- /package/{internal/transition → transition}/index.js +0 -0
- /package/{internal/wave → transition}/types.js +0 -0
- /package/{hooks/useNextTick.js → upload/hooks.js} +0 -0
- /package/{internal/wave → wave}/index.d.ts +0 -0
- /package/{internal/wave → wave}/index.js +0 -0
- /package/{internal/wave → wave}/vars.d.ts +0 -0
- /package/{internal/wave → wave}/vars.js +0 -0
package/fab/FabButton.js
CHANGED
|
@@ -1,23 +1,50 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { setRef } from '@laser-ui/utils';
|
|
3
4
|
import AddOutlined from '@material-design-icons/svg/outlined/add.svg?react';
|
|
4
|
-
import {
|
|
5
|
-
import { BUTTON_CLASSES } from './vars';
|
|
5
|
+
import { use } from 'react';
|
|
6
|
+
import { BUTTON_CLASSES, FabBacktopContext, FabContext, FabListContext } from './vars';
|
|
7
|
+
import { CircularProgress } from '../circular-progress';
|
|
6
8
|
import { useComponentProps, useStyled } from '../hooks';
|
|
7
9
|
import { Icon } from '../icon';
|
|
8
|
-
import { CircularProgress } from '../internal/circular-progress';
|
|
9
10
|
import { mergeCS } from '../utils';
|
|
10
|
-
export
|
|
11
|
+
export function FabButton(props) {
|
|
11
12
|
var _a;
|
|
12
|
-
const _b = useComponentProps('FabButton', props), { children, styleOverrides, styleProvider, pattern = 'primary', theme = 'primary', loading = false, shape
|
|
13
|
+
const _b = useComponentProps('FabButton', props), { ref, children, styleOverrides, styleProvider, pattern = 'primary', theme = 'primary', loading = false, shape } = _b, restProps = __rest(_b, ["ref", "children", "styleOverrides", "styleProvider", "pattern", "theme", "loading", "shape"]);
|
|
13
14
|
const styled = useStyled(BUTTON_CLASSES, { 'fab-button': styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider['fab-button'] }, styleOverrides);
|
|
15
|
+
const fabContext = use(FabContext);
|
|
16
|
+
const fabListContext = use(FabListContext);
|
|
17
|
+
const fabBacktopContext = use(FabBacktopContext);
|
|
14
18
|
return (_jsxs("button", Object.assign({}, restProps, mergeCS(styled('fab-button', `fab-button.t-${theme}`, `fab-button--${pattern}`, {
|
|
15
|
-
'fab-button.is-expand':
|
|
19
|
+
'fab-button.is-expand': fabContext && fabContext.expand,
|
|
16
20
|
'fab-button.is-loading': loading,
|
|
17
|
-
'fab-button--in-actions':
|
|
21
|
+
'fab-button--in-actions': fabListContext,
|
|
18
22
|
[`fab-button--${shape}`]: shape,
|
|
19
23
|
}), {
|
|
20
24
|
className: restProps.className,
|
|
21
|
-
style: restProps.style,
|
|
22
|
-
}), { ref:
|
|
23
|
-
|
|
25
|
+
style: Object.assign(Object.assign(Object.assign({}, restProps.style), (fabListContext ? { animationDelay: `${fabListContext.index * 33}ms` } : undefined)), (fabBacktopContext && fabBacktopContext.leaved ? { display: 'none' } : undefined)),
|
|
26
|
+
}), { ref: (instance) => {
|
|
27
|
+
const ret = setRef(ref, instance);
|
|
28
|
+
if (fabBacktopContext) {
|
|
29
|
+
fabBacktopContext.ref(instance);
|
|
30
|
+
}
|
|
31
|
+
return () => {
|
|
32
|
+
ret();
|
|
33
|
+
if (fabBacktopContext) {
|
|
34
|
+
fabBacktopContext.ref(null);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, type: (_a = restProps.type) !== null && _a !== void 0 ? _a : 'button', onClick: (e) => {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = restProps.onClick) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
40
|
+
if (fabContext) {
|
|
41
|
+
fabContext.onClick();
|
|
42
|
+
}
|
|
43
|
+
if (fabListContext) {
|
|
44
|
+
fabListContext.onClick();
|
|
45
|
+
}
|
|
46
|
+
if (fabBacktopContext) {
|
|
47
|
+
fabBacktopContext.onClick();
|
|
48
|
+
}
|
|
49
|
+
}, children: [_jsx(Icon, Object.assign({}, styled('fab-button__icon'), { children: _jsx(AddOutlined, {}) })), _jsx("div", Object.assign({}, styled('fab-button__content'), { children: loading ? (_jsx(Icon, { children: _jsx(CircularProgress, {}) })) : (children) }))] })));
|
|
50
|
+
}
|
package/fab/types.d.ts
CHANGED
|
@@ -4,16 +4,20 @@ import type { BaseProps } from '../types';
|
|
|
4
4
|
import type { RefExtra } from '@laser-ui/hooks/useRefExtra';
|
|
5
5
|
export {};
|
|
6
6
|
export interface FabProps extends BaseProps<'fab', typeof CLASSES>, Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
7
|
-
children
|
|
7
|
+
children?: React.ReactNode;
|
|
8
8
|
expand?: boolean;
|
|
9
9
|
defaultExpand?: boolean;
|
|
10
10
|
list?: {
|
|
11
11
|
placement: 'top' | 'right' | 'bottom' | 'left';
|
|
12
|
-
actions: React.
|
|
12
|
+
actions: (React.ReactNode | {
|
|
13
|
+
id: React.Key;
|
|
14
|
+
action: React.ReactNode;
|
|
15
|
+
})[];
|
|
13
16
|
}[];
|
|
14
17
|
onExpandChange?: (expand: boolean) => void;
|
|
15
18
|
}
|
|
16
19
|
export interface FabButtonProps extends BaseProps<'fab-button', typeof BUTTON_CLASSES>, React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
20
|
+
ref?: React.Ref<HTMLButtonElement>;
|
|
17
21
|
pattern?: 'primary' | 'secondary' | 'outline' | 'dashed' | 'text' | 'link';
|
|
18
22
|
theme?: 'primary' | 'success' | 'warning' | 'danger';
|
|
19
23
|
loading?: boolean;
|
package/fab/vars.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export declare const CLASSES: {
|
|
2
3
|
fab: string;
|
|
3
4
|
fab__actions: string;
|
|
@@ -26,3 +27,16 @@ export declare const BUTTON_CLASSES: {
|
|
|
26
27
|
'fab-button__icon': string;
|
|
27
28
|
'fab-button__content': string;
|
|
28
29
|
};
|
|
30
|
+
export declare const FabContext: import("react").Context<{
|
|
31
|
+
expand: boolean;
|
|
32
|
+
onClick: () => void;
|
|
33
|
+
} | undefined>;
|
|
34
|
+
export declare const FabListContext: import("react").Context<{
|
|
35
|
+
index: number;
|
|
36
|
+
onClick: () => void;
|
|
37
|
+
} | undefined>;
|
|
38
|
+
export declare const FabBacktopContext: import("react").Context<{
|
|
39
|
+
ref: React.RefCallback<HTMLElement | null>;
|
|
40
|
+
leaved: boolean;
|
|
41
|
+
onClick: () => void;
|
|
42
|
+
} | undefined>;
|
package/fab/vars.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
1
2
|
export const CLASSES = {
|
|
2
3
|
fab: '^fab',
|
|
3
4
|
fab__actions: '^fab__actions',
|
|
@@ -26,3 +27,6 @@ export const BUTTON_CLASSES = {
|
|
|
26
27
|
'fab-button__icon': '^fab-button__icon',
|
|
27
28
|
'fab-button__content': '^fab-button__content',
|
|
28
29
|
};
|
|
30
|
+
export const FabContext = createContext(undefined);
|
|
31
|
+
export const FabListContext = createContext(undefined);
|
|
32
|
+
export const FabBacktopContext = createContext(undefined);
|
package/form/Form.d.ts
CHANGED
package/form/Form.js
CHANGED
|
@@ -24,7 +24,12 @@ export const Form = (props) => {
|
|
|
24
24
|
return (_jsx("form", Object.assign({}, restProps, mergeCS(styled('form', `form--${size}`), {
|
|
25
25
|
className: restProps.className,
|
|
26
26
|
style: restProps.style,
|
|
27
|
-
}), { ref:
|
|
27
|
+
}), { ref: (instance) => {
|
|
28
|
+
formRef.current = instance;
|
|
29
|
+
return () => {
|
|
30
|
+
formRef.current = null;
|
|
31
|
+
};
|
|
32
|
+
}, onSubmit: (e) => {
|
|
28
33
|
var _a;
|
|
29
34
|
(_a = restProps.onSubmit) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
30
35
|
e.preventDefault();
|
|
@@ -33,7 +38,7 @@ export const Form = (props) => {
|
|
|
33
38
|
var _a;
|
|
34
39
|
(_a = restProps.onReset) === null || _a === void 0 ? void 0 : _a.call(restProps, e);
|
|
35
40
|
e.preventDefault();
|
|
36
|
-
}, children: _jsx(ConfigProvider, { context: { componentSize: size }, children: _jsx(FormContext
|
|
41
|
+
}, children: _jsx(ConfigProvider, { context: { componentSize: size }, children: _jsx(FormContext, { value: {
|
|
37
42
|
vertical,
|
|
38
43
|
labelWidth: labelWidth !== null && labelWidth !== void 0 ? labelWidth : (vertical ? undefined : 'auto'),
|
|
39
44
|
labelWrap: isUndefined(labelWidth) ? false : labelWrap,
|
package/form/FormItem.d.ts
CHANGED
package/form/FormItem.js
CHANGED
|
@@ -6,13 +6,13 @@ import CheckCircleFilled from '@material-design-icons/svg/filled/check_circle.sv
|
|
|
6
6
|
import ErrorFilled from '@material-design-icons/svg/filled/error.svg?react';
|
|
7
7
|
import HelpOutlineOutlined from '@material-design-icons/svg/outlined/help_outline.svg?react';
|
|
8
8
|
import { isBoolean, isFunction, isNull, isNumber, isString, isUndefined } from 'lodash';
|
|
9
|
-
import {
|
|
9
|
+
import { use, useEffect, useId, useRef } from 'react';
|
|
10
10
|
import { FormError } from './internal/FormError';
|
|
11
11
|
import { Validators } from './model/validators';
|
|
12
12
|
import { CLASSES, FormContext, FormGroupContext } from './vars';
|
|
13
|
-
import {
|
|
13
|
+
import { CircularProgress } from '../circular-progress';
|
|
14
|
+
import { useComponentProps, useNamespace, useStyled, useTranslation } from '../hooks';
|
|
14
15
|
import { Icon } from '../icon';
|
|
15
|
-
import { CircularProgress } from '../internal/circular-progress';
|
|
16
16
|
import { Tooltip } from '../tooltip';
|
|
17
17
|
import { mergeCS } from '../utils';
|
|
18
18
|
const ValidateState = {
|
|
@@ -24,11 +24,12 @@ const ValidateState = {
|
|
|
24
24
|
};
|
|
25
25
|
export function FormItem(props) {
|
|
26
26
|
const _a = useComponentProps('FormItem', props), { children, styleOverrides, styleProvider, formControls, label, labelWidth: labelWidthProp, labelWrap: labelWrapProp, labelExtra: labelExtraProp, labelFor, required: requiredProp } = _a, restProps = __rest(_a, ["children", "styleOverrides", "styleProvider", "formControls", "label", "labelWidth", "labelWrap", "labelExtra", "labelFor", "required"]);
|
|
27
|
+
const namespace = useNamespace();
|
|
27
28
|
const styled = useStyled(CLASSES, { form: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.form }, styleOverrides);
|
|
28
29
|
const { t } = useTranslation();
|
|
29
30
|
const forceUpdate = useForceUpdate();
|
|
30
|
-
const formContext =
|
|
31
|
-
const formGroupContext =
|
|
31
|
+
const formContext = use(FormContext);
|
|
32
|
+
const formGroupContext = use(FormGroupContext);
|
|
32
33
|
const divRef = useRef(null);
|
|
33
34
|
const uniqueId = useId();
|
|
34
35
|
const getErrorId = (controlName) => `${controlName}-error-${uniqueId}`;
|
|
@@ -83,9 +84,8 @@ export function FormItem(props) {
|
|
|
83
84
|
}
|
|
84
85
|
return false;
|
|
85
86
|
})();
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const errors = [];
|
|
87
|
+
const [validateState, currentErrors] = (() => {
|
|
88
|
+
const currentErrors = [];
|
|
89
89
|
let validateState = ValidateState.Empty;
|
|
90
90
|
Object.entries(formControls !== null && formControls !== void 0 ? formControls : {}).forEach(([controlName, formErrors]) => {
|
|
91
91
|
const { control } = formControlProviders[controlName];
|
|
@@ -116,11 +116,11 @@ export function FormItem(props) {
|
|
|
116
116
|
let hasError = false;
|
|
117
117
|
if (control.invalid && control.errors) {
|
|
118
118
|
if (isString(formErrors)) {
|
|
119
|
-
|
|
119
|
+
currentErrors.push({ key: controlName, controlName, message: formErrors, invalid: 'error' });
|
|
120
120
|
hasError = true;
|
|
121
121
|
}
|
|
122
122
|
else if (Object.keys(formErrors).length === 2 && 'message' in formErrors && 'invalid' in formErrors) {
|
|
123
|
-
|
|
123
|
+
currentErrors.push(Object.assign({ key: controlName, controlName }, formErrors));
|
|
124
124
|
if (formErrors.invalid === 'error') {
|
|
125
125
|
hasError = true;
|
|
126
126
|
}
|
|
@@ -129,11 +129,11 @@ export function FormItem(props) {
|
|
|
129
129
|
for (const key of Object.keys(control.errors)) {
|
|
130
130
|
if (key in formErrors) {
|
|
131
131
|
if (isString(formErrors[key])) {
|
|
132
|
-
|
|
132
|
+
currentErrors.push({ key: `${controlName}-${key}`, controlName, message: formErrors[key], invalid: 'error' });
|
|
133
133
|
hasError = true;
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
|
-
|
|
136
|
+
currentErrors.push(Object.assign({ key: `${controlName}-${key}`, controlName }, formErrors[key]));
|
|
137
137
|
if (formErrors[key].invalid === 'error') {
|
|
138
138
|
hasError = true;
|
|
139
139
|
}
|
|
@@ -152,27 +152,35 @@ export function FormItem(props) {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
});
|
|
155
|
+
return [validateState, currentErrors];
|
|
156
|
+
})();
|
|
157
|
+
const errorsSaved = useRef(currentErrors);
|
|
158
|
+
{
|
|
155
159
|
const newErrors = [];
|
|
156
|
-
|
|
157
|
-
const index =
|
|
160
|
+
errorsSaved.current.forEach((err) => {
|
|
161
|
+
const index = currentErrors.findIndex((e) => e.key === err.key);
|
|
158
162
|
newErrors.push(Object.assign(err, { hidden: index === -1 }));
|
|
159
163
|
if (index !== -1) {
|
|
160
|
-
|
|
164
|
+
currentErrors.splice(index, 1);
|
|
161
165
|
}
|
|
162
166
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
})();
|
|
167
|
+
errorsSaved.current = newErrors.concat(currentErrors);
|
|
168
|
+
}
|
|
166
169
|
const labelExtra = (() => {
|
|
167
|
-
var _a;
|
|
168
170
|
if (labelExtraProp) {
|
|
169
|
-
|
|
171
|
+
const { title, icon } = isString(labelExtraProp) ? { title: labelExtraProp, icon: undefined } : labelExtraProp;
|
|
172
|
+
return (_jsx(Tooltip, { title: title, children: (tooltipProps) => (_jsx("div", Object.assign({}, tooltipProps, { children: icon !== null && icon !== void 0 ? icon : (_jsx(Icon, { children: _jsx(HelpOutlineOutlined, {}) })) }))) }));
|
|
170
173
|
}
|
|
171
174
|
})();
|
|
172
175
|
return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('form__item'), {
|
|
173
176
|
className: restProps.className,
|
|
174
177
|
style: restProps.style,
|
|
175
|
-
}), { ref:
|
|
178
|
+
}), { ref: (instance) => {
|
|
179
|
+
divRef.current = instance;
|
|
180
|
+
return () => {
|
|
181
|
+
divRef.current = null;
|
|
182
|
+
};
|
|
183
|
+
}, children: _jsxs("div", Object.assign({}, styled('form__item-container'), { children: [labelWidth !== 0 && (_jsx("div", Object.assign({}, mergeCS(styled('form__item-label-wrapper'), {
|
|
176
184
|
style: { width: formContext.vertical ? undefined : labelWidth === 'auto' ? 'var(--label-width)' : labelWidth },
|
|
177
185
|
}), { children: label && (_jsxs("label", Object.assign({}, styled('form__item-label', {
|
|
178
186
|
'form__item-label--wrap': labelWrap,
|
|
@@ -188,7 +196,7 @@ export function FormItem(props) {
|
|
|
188
196
|
},
|
|
189
197
|
}), { children: [_jsx("div", Object.assign({}, styled('form__item-control'), { children: isFunction(children) ? children(formControlProviders) : children })), _jsx("div", Object.assign({}, styled('form__error-container'), { children: (() => {
|
|
190
198
|
const errorsMap = new Map();
|
|
191
|
-
|
|
199
|
+
errorsSaved.current.forEach((err) => {
|
|
192
200
|
if (errorsMap.has(err.controlName)) {
|
|
193
201
|
errorsMap.get(err.controlName).push(err);
|
|
194
202
|
}
|
|
@@ -200,8 +208,11 @@ export function FormItem(props) {
|
|
|
200
208
|
for (const [controlName, errors] of errorsMap) {
|
|
201
209
|
const id = getErrorId(controlName);
|
|
202
210
|
formControlProviders[controlName].inputAria['aria-describedby'] = id;
|
|
203
|
-
nodes.push(_jsx("div", { id: id, children: errors.map((error) => (_jsx(FormError, { styled: styled, visible: !error.hidden, message: error.message, invalid: error.invalid,
|
|
204
|
-
|
|
211
|
+
nodes.push(_jsx("div", { id: id, children: errors.map((error) => (_jsx(FormError, { namespace: namespace, styled: styled, visible: !error.hidden, message: error.message, invalid: error.invalid, onAfterLeave: () => {
|
|
212
|
+
const index = errorsSaved.current.findIndex((e) => e.key === error.key);
|
|
213
|
+
if (index !== -1) {
|
|
214
|
+
errorsSaved.current.splice(index, 1);
|
|
215
|
+
}
|
|
205
216
|
} }, error.key))) }, controlName));
|
|
206
217
|
}
|
|
207
218
|
return nodes;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
import type { Styled } from '../../hooks/useStyled';
|
|
3
3
|
import type { CLASSES } from '../vars';
|
|
4
4
|
interface FormErrorProps {
|
|
5
|
+
namespace: string;
|
|
5
6
|
styled: Styled<typeof CLASSES>;
|
|
6
7
|
visible: boolean;
|
|
7
8
|
message: string;
|
|
8
9
|
invalid: 'warning' | 'error';
|
|
9
|
-
|
|
10
|
+
onAfterLeave: () => void;
|
|
10
11
|
}
|
|
11
|
-
export declare function FormError(props: FormErrorProps):
|
|
12
|
+
export declare function FormError(props: FormErrorProps): React.ReactElement | null;
|
|
12
13
|
export {};
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { CollapseTransition } from '../../
|
|
2
|
+
import { CollapseTransition } from '../../transition';
|
|
3
3
|
import { mergeCS } from '../../utils';
|
|
4
4
|
import { TTANSITION_DURING_FAST } from '../../vars';
|
|
5
5
|
export function FormError(props) {
|
|
6
|
-
const { styled, visible, message, invalid,
|
|
7
|
-
return (_jsx(CollapseTransition, {
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
leaving: {
|
|
17
|
-
opacity: 0,
|
|
18
|
-
transition: ['height', 'padding', 'margin', 'opacity'].map((attr) => `${attr} ${TTANSITION_DURING_FAST}ms linear`).join(', '),
|
|
19
|
-
},
|
|
20
|
-
leaved: { display: 'none' },
|
|
21
|
-
}, skipFirstTransition: false, afterLeave: afterLeave, children: (ref, collapseStyle) => (_jsx("div", Object.assign({}, mergeCS(styled('form__error', `form__error--${invalid}`), {
|
|
22
|
-
style: collapseStyle,
|
|
23
|
-
}), { ref: ref, title: message, children: message }))) }));
|
|
6
|
+
const { namespace, styled, visible, message, invalid, onAfterLeave } = props;
|
|
7
|
+
return (_jsx(CollapseTransition, { height: 0, enter: visible, name: `${namespace}-form-error`, duration: TTANSITION_DURING_FAST, skipFirstTransition: false, onAfterLeave: onAfterLeave, children: (transitionRef, leaved) => (_jsx("div", Object.assign({}, mergeCS(styled('form__error', `form__error--${invalid}`), {
|
|
8
|
+
style: Object.assign({}, (leaved ? { display: 'none' } : undefined)),
|
|
9
|
+
}), { ref: (instance) => {
|
|
10
|
+
transitionRef(instance);
|
|
11
|
+
return () => {
|
|
12
|
+
transitionRef(null);
|
|
13
|
+
};
|
|
14
|
+
}, title: message, children: message }))) }));
|
|
24
15
|
}
|
package/hooks/index.d.ts
CHANGED
|
@@ -4,13 +4,11 @@ export { useControlled } from './useControlled';
|
|
|
4
4
|
export { useDesign } from './useDesign';
|
|
5
5
|
export { useDialogService } from './useDialogService';
|
|
6
6
|
export { useFocusVisible } from './useFocusVisible';
|
|
7
|
-
export { useJSS } from './useJSS';
|
|
8
7
|
export { useLayout } from './useLayout';
|
|
9
8
|
export { useLockScroll } from './useLockScroll';
|
|
10
9
|
export { useMaxIndex } from './useMaxIndex';
|
|
11
10
|
export { useNamespace } from './useNamespace';
|
|
12
11
|
export { useNestedPopup } from './useNestedPopup';
|
|
13
|
-
export { useNextTick } from './useNextTick';
|
|
14
12
|
export { useScopedProps } from './useScopedProps';
|
|
15
13
|
export { useStyled } from './useStyled';
|
|
16
14
|
export { useTranslation } from './useTranslation';
|
package/hooks/index.js
CHANGED
|
@@ -4,13 +4,11 @@ export { useControlled } from './useControlled';
|
|
|
4
4
|
export { useDesign } from './useDesign';
|
|
5
5
|
export { useDialogService } from './useDialogService';
|
|
6
6
|
export { useFocusVisible } from './useFocusVisible';
|
|
7
|
-
export { useJSS } from './useJSS';
|
|
8
7
|
export { useLayout } from './useLayout';
|
|
9
8
|
export { useLockScroll } from './useLockScroll';
|
|
10
9
|
export { useMaxIndex } from './useMaxIndex';
|
|
11
10
|
export { useNamespace } from './useNamespace';
|
|
12
11
|
export { useNestedPopup } from './useNestedPopup';
|
|
13
|
-
export { useNextTick } from './useNextTick';
|
|
14
12
|
export { useScopedProps } from './useScopedProps';
|
|
15
13
|
export { useStyled } from './useStyled';
|
|
16
14
|
export { useTranslation } from './useTranslation';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isUndefined } from 'lodash';
|
|
2
|
-
import {
|
|
2
|
+
import { use } from 'react';
|
|
3
3
|
import { LContext } from '../context';
|
|
4
4
|
export function useComponentProps(component, props) {
|
|
5
5
|
var _a;
|
|
6
|
-
const context =
|
|
6
|
+
const context = use(LContext);
|
|
7
7
|
const defaultProps = (_a = context.componentDefaultProps[component]) !== null && _a !== void 0 ? _a : {};
|
|
8
8
|
const definedProps = {};
|
|
9
9
|
Object.keys(props).forEach((key) => {
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function useFocusVisible(isValidCode: (code: string) => boolean): [
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function useFocusVisible(isValidCode: (code: string) => boolean): [
|
|
3
|
+
boolean,
|
|
4
|
+
{
|
|
5
|
+
onFocus: React.FocusEventHandler<HTMLElement>;
|
|
6
|
+
onBlur: React.FocusEventHandler<HTMLElement>;
|
|
7
|
+
onKeyDown: React.KeyboardEventHandler<HTMLElement>;
|
|
8
|
+
}
|
|
9
|
+
];
|
package/hooks/useFocusVisible.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useAsync, useEvent, useRefExtra } from '@laser-ui/hooks';
|
|
2
|
-
import {
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
3
|
export function useFocusVisible(isValidCode) {
|
|
4
4
|
const windowRef = useRefExtra(() => window);
|
|
5
5
|
const async = useAsync();
|
|
@@ -13,26 +13,20 @@ export function useFocusVisible(isValidCode) {
|
|
|
13
13
|
});
|
|
14
14
|
return [
|
|
15
15
|
focusVisible,
|
|
16
|
-
|
|
17
|
-
onFocus: (
|
|
18
|
-
var _a, _b;
|
|
19
|
-
(_b = (_a = el.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
16
|
+
{
|
|
17
|
+
onFocus: () => {
|
|
20
18
|
if (hadKeyboardEvent.current) {
|
|
21
19
|
setFocusVisible(true);
|
|
22
20
|
}
|
|
23
21
|
},
|
|
24
|
-
onBlur: (
|
|
25
|
-
var _a, _b;
|
|
26
|
-
(_b = (_a = el.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
22
|
+
onBlur: () => {
|
|
27
23
|
setFocusVisible(false);
|
|
28
24
|
},
|
|
29
25
|
onKeyDown: (e) => {
|
|
30
|
-
var _a, _b;
|
|
31
|
-
(_b = (_a = el.props).onKeyDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
32
26
|
if (isValidCode(e.code)) {
|
|
33
27
|
setFocusVisible(true);
|
|
34
28
|
}
|
|
35
29
|
},
|
|
36
|
-
}
|
|
30
|
+
},
|
|
37
31
|
];
|
|
38
32
|
}
|
package/hooks/useLayout.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare function useLayout(): {
|
|
3
|
-
pageScrollRef: import("react").RefObject<HTMLElement>;
|
|
4
|
-
contentResizeRef: import("react").RefObject<HTMLElement>;
|
|
3
|
+
pageScrollRef: import("react").RefObject<HTMLElement | null>;
|
|
4
|
+
contentResizeRef: import("react").RefObject<HTMLElement | null>;
|
|
5
5
|
};
|
package/hooks/useLayout.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useRefExtra } from '@laser-ui/hooks';
|
|
2
|
-
import {
|
|
2
|
+
import { use } from 'react';
|
|
3
3
|
import { LContext } from '../context';
|
|
4
4
|
export function useLayout() {
|
|
5
5
|
var _a, _b;
|
|
6
|
-
const context =
|
|
6
|
+
const context = use(LContext);
|
|
7
7
|
const pageScrollRef = useRefExtra((_a = context.layoutPageScrollEl) !== null && _a !== void 0 ? _a : (() => null));
|
|
8
8
|
const contentResizeRef = useRefExtra((_b = context.layoutContentResizeEl) !== null && _b !== void 0 ? _b : (() => null));
|
|
9
9
|
return { pageScrollRef, contentResizeRef };
|
package/hooks/useNamespace.js
CHANGED
|
@@ -5,7 +5,7 @@ interface PopupId<ID> {
|
|
|
5
5
|
visible: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function useNestedPopup<ID>(): {
|
|
8
|
-
popupIdsRef: import("react").
|
|
8
|
+
popupIdsRef: import("react").RefObject<PopupId<ID>[]>;
|
|
9
9
|
setPopupIds: (value: PopupId<ID>[] | DraftFunction<PopupId<ID>[]>) => void;
|
|
10
10
|
addPopupId: (id: ID) => void;
|
|
11
11
|
removePopupId: (id: ID) => void;
|
package/hooks/useScopedProps.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { use } from 'react';
|
|
2
2
|
import { LContext } from '../context';
|
|
3
3
|
export function useScopedProps(props) {
|
|
4
4
|
var _a, _b;
|
|
5
|
-
const context =
|
|
5
|
+
const context = use(LContext);
|
|
6
6
|
return { size: (_b = (_a = props.size) !== null && _a !== void 0 ? _a : context.componentSize) !== null && _b !== void 0 ? _b : 'medium', disabled: props.disabled || context.componentDisabled };
|
|
7
7
|
}
|
package/hooks/useStyled.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isString, isUndefined } from 'lodash';
|
|
2
|
-
import {
|
|
2
|
+
import { use, useRef } from 'react';
|
|
3
3
|
import { LContext } from '../context';
|
|
4
4
|
export function useStyled(classes, styleProvider, styleOverrides) {
|
|
5
|
-
const context =
|
|
5
|
+
const context = use(LContext);
|
|
6
6
|
const classRoot = {};
|
|
7
7
|
Object.keys(styleProvider).forEach((key) => {
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
package/hooks/useTranslation.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { get } from 'lodash';
|
|
2
|
-
import {
|
|
2
|
+
import { use } from 'react';
|
|
3
3
|
import { RootContext } from '../root/vars';
|
|
4
4
|
export function useTranslation() {
|
|
5
|
-
const context =
|
|
5
|
+
const context = use(RootContext);
|
|
6
6
|
const lang = context.i18nLang;
|
|
7
7
|
return {
|
|
8
8
|
t: (...path) => {
|
package/icon/Icon.d.ts
CHANGED
package/icon/Icon.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { isArray, isNumber, isUndefined } from 'lodash';
|
|
4
|
-
import { cloneElement } from 'react';
|
|
5
4
|
import { CLASSES } from './vars';
|
|
6
5
|
import { useComponentProps, useNamespace, useStyled } from '../hooks';
|
|
7
6
|
import { mergeCS } from '../utils';
|
|
@@ -14,8 +13,12 @@ export function Icon(props) {
|
|
|
14
13
|
return (_jsx("div", Object.assign({}, restProps, mergeCS(styled('icon', { [`icon.t-${theme}`]: theme }), {
|
|
15
14
|
className: restProps.className,
|
|
16
15
|
style: restProps.style,
|
|
17
|
-
}), { children:
|
|
16
|
+
}), { children: _jsx("div", { style: {
|
|
17
|
+
width,
|
|
18
|
+
height,
|
|
19
|
+
transform: isUndefined(rotate) ? (_a = children.props.style) === null || _a === void 0 ? void 0 : _a.transform : `rotate(${rotate}deg)`,
|
|
20
|
+
animation: spin
|
|
18
21
|
? `${namespace}-spin ${spinSpeed}${isNumber(spinSpeed) ? 's' : ''} linear infinite`
|
|
19
|
-
: (_b = children.props.style) === null || _b === void 0 ? void 0 : _b.animation
|
|
20
|
-
|
|
22
|
+
: (_b = children.props.style) === null || _b === void 0 ? void 0 : _b.animation,
|
|
23
|
+
}, children: children }) })));
|
|
21
24
|
}
|
package/image/Image.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ImageAction } from './ImageAction';
|
|
|
4
4
|
import { ImageLoader } from './ImageLoader';
|
|
5
5
|
import { ImagePreview } from './ImagePreview';
|
|
6
6
|
export declare const Image: {
|
|
7
|
-
(props: ImageProps):
|
|
7
|
+
(props: ImageProps): React.ReactElement | null;
|
|
8
8
|
Loader: typeof ImageLoader;
|
|
9
9
|
Action: typeof ImageAction;
|
|
10
10
|
Preview: typeof ImagePreview;
|
package/image/Image.js
CHANGED
|
@@ -2,7 +2,8 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useForceUpdate } from '@laser-ui/hooks';
|
|
4
4
|
import { checkNodeExist } from '@laser-ui/utils';
|
|
5
|
-
import {
|
|
5
|
+
import { has } from 'lodash';
|
|
6
|
+
import { Fragment, useRef } from 'react';
|
|
6
7
|
import { ImageAction } from './ImageAction';
|
|
7
8
|
import { ImageLoader } from './ImageLoader';
|
|
8
9
|
import { ImagePreview } from './ImagePreview';
|
|
@@ -25,7 +26,10 @@ export const Image = (props) => {
|
|
|
25
26
|
return (_jsxs("div", Object.assign({}, restProps, mergeCS(styled('image'), {
|
|
26
27
|
className: restProps.className,
|
|
27
28
|
style: restProps.style,
|
|
28
|
-
}), { children: [dataRef.current.isLoading && checkNodeExist(loading) && loading, dataRef.current.isError && checkNodeExist(error) && error, actions && _jsx("div", Object.assign({}, styled('image__actions'), { children:
|
|
29
|
+
}), { children: [dataRef.current.isLoading && checkNodeExist(loading) && loading, dataRef.current.isError && checkNodeExist(error) && error, actions && (_jsx("div", Object.assign({}, styled('image__actions'), { children: actions.map((node, index) => {
|
|
30
|
+
const { id, action } = (has(node, ['id', 'action']) ? node : { id: index, action: node });
|
|
31
|
+
return _jsx(Fragment, { children: action }, id);
|
|
32
|
+
}) }))), _jsx("img", Object.assign({}, imgProps, mergeCS(styled('image__img'), {
|
|
29
33
|
className: imgProps === null || imgProps === void 0 ? void 0 : imgProps.className,
|
|
30
34
|
style: Object.assign(Object.assign({}, imgProps === null || imgProps === void 0 ? void 0 : imgProps.style), { display: (dataRef.current.isLoading && loading) || (dataRef.current.isError && error) ? 'none' : undefined }),
|
|
31
35
|
}), { onLoadStart: (e) => {
|
package/image/ImageAction.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { ImageActionProps } from './types';
|
|
3
|
-
export declare
|
|
3
|
+
export declare function ImageAction(props: ImageActionProps): React.ReactElement | null;
|
package/image/ImageAction.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef } from 'react';
|
|
4
3
|
import { CLASSES } from './vars';
|
|
5
4
|
import { useComponentProps, useStyled } from '../hooks';
|
|
6
5
|
import { mergeCS } from '../utils';
|
|
7
|
-
export
|
|
6
|
+
export function ImageAction(props) {
|
|
8
7
|
var _a;
|
|
9
|
-
const _b = useComponentProps('ImageAction', props), { children, styleOverrides, styleProvider } = _b, restProps = __rest(_b, ["children", "styleOverrides", "styleProvider"]);
|
|
8
|
+
const _b = useComponentProps('ImageAction', props), { ref, children, styleOverrides, styleProvider } = _b, restProps = __rest(_b, ["ref", "children", "styleOverrides", "styleProvider"]);
|
|
10
9
|
const styled = useStyled(CLASSES, { image: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.image }, styleOverrides);
|
|
11
10
|
return (_jsx("button", Object.assign({}, restProps, mergeCS(styled('image__action'), {
|
|
12
11
|
className: restProps.className,
|
|
13
12
|
style: restProps.style,
|
|
14
13
|
}), { ref: ref, type: (_a = restProps['type']) !== null && _a !== void 0 ? _a : 'button', children: children })));
|
|
15
|
-
}
|
|
14
|
+
}
|
package/image/ImageLoader.d.ts
CHANGED