@xanui/ui 1.2.5 → 1.2.7
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/Accordion/index.cjs +5 -5
- package/Accordion/index.cjs.map +1 -1
- package/Accordion/index.d.ts +3 -3
- package/Accordion/index.js +5 -5
- package/Accordion/index.js.map +1 -1
- package/Alert/index.cjs +19 -17
- package/Alert/index.cjs.map +1 -1
- package/Alert/index.d.ts +4 -4
- package/Alert/index.js +19 -17
- package/Alert/index.js.map +1 -1
- package/Autocomplete/index.cjs +2 -2
- package/Autocomplete/index.cjs.map +1 -1
- package/Autocomplete/index.d.ts +7 -7
- package/Autocomplete/index.js +2 -2
- package/Autocomplete/index.js.map +1 -1
- package/Avatar/index.cjs +2 -2
- package/Avatar/index.cjs.map +1 -1
- package/Avatar/index.d.ts +2 -2
- package/Avatar/index.js +2 -2
- package/Avatar/index.js.map +1 -1
- package/AvatarBox/index.cjs +19 -0
- package/AvatarBox/index.cjs.map +1 -0
- package/AvatarBox/index.d.ts +19 -0
- package/AvatarBox/index.js +17 -0
- package/AvatarBox/index.js.map +1 -0
- package/AvatarPicker/index.cjs +80 -0
- package/AvatarPicker/index.cjs.map +1 -0
- package/AvatarPicker/index.d.ts +27 -0
- package/AvatarPicker/index.js +78 -0
- package/AvatarPicker/index.js.map +1 -0
- package/Badge/index.cjs +1 -1
- package/Badge/index.cjs.map +1 -1
- package/Badge/index.d.ts +4 -4
- package/Badge/index.js +1 -1
- package/Badge/index.js.map +1 -1
- package/Box/index.d.ts +2 -2
- package/Button/index.cjs +5 -3
- package/Button/index.cjs.map +1 -1
- package/Button/index.d.ts +2 -2
- package/Button/index.js +5 -3
- package/Button/index.js.map +1 -1
- package/ButtonGroup/index.cjs +3 -2
- package/ButtonGroup/index.cjs.map +1 -1
- package/ButtonGroup/index.d.ts +2 -2
- package/ButtonGroup/index.js +3 -2
- package/ButtonGroup/index.js.map +1 -1
- package/Calendar/index.cjs +10 -10
- package/Calendar/index.cjs.map +1 -1
- package/Calendar/index.js +10 -10
- package/Calendar/index.js.map +1 -1
- package/CalendarInput/index.cjs +1 -1
- package/CalendarInput/index.cjs.map +1 -1
- package/CalendarInput/index.js +1 -1
- package/CalendarInput/index.js.map +1 -1
- package/Carousel/index.cjs +231 -0
- package/Carousel/index.cjs.map +1 -0
- package/Carousel/index.d.ts +28 -0
- package/Carousel/index.js +229 -0
- package/Carousel/index.js.map +1 -0
- package/Checkbox/index.cjs +2 -2
- package/Checkbox/index.cjs.map +1 -1
- package/Checkbox/index.d.ts +2 -2
- package/Checkbox/index.js +2 -2
- package/Checkbox/index.js.map +1 -1
- package/Chip/index.cjs +3 -3
- package/Chip/index.cjs.map +1 -1
- package/Chip/index.d.ts +2 -2
- package/Chip/index.js +3 -3
- package/Chip/index.js.map +1 -1
- package/CircleProgress/index.cjs +10 -10
- package/CircleProgress/index.cjs.map +1 -1
- package/CircleProgress/index.d.ts +2 -2
- package/CircleProgress/index.js +10 -10
- package/CircleProgress/index.js.map +1 -1
- package/ClickOutside/index.cjs +3 -12
- package/ClickOutside/index.cjs.map +1 -1
- package/ClickOutside/index.d.ts +3 -3
- package/ClickOutside/index.js +4 -13
- package/ClickOutside/index.js.map +1 -1
- package/Collaps/index.cjs +5 -5
- package/Collaps/index.cjs.map +1 -1
- package/Collaps/index.d.ts +2 -2
- package/Collaps/index.js +5 -5
- package/Collaps/index.js.map +1 -1
- package/Container/index.d.ts +2 -2
- package/DataFilter/index.d.ts +2 -2
- package/DataFilter/options/DateFilter.cjs +3 -3
- package/DataFilter/options/DateFilter.cjs.map +1 -1
- package/DataFilter/options/DateFilter.js +3 -3
- package/DataFilter/options/DateFilter.js.map +1 -1
- package/DataFilter/options/DateRangeFilter.cjs +2 -2
- package/DataFilter/options/DateRangeFilter.cjs.map +1 -1
- package/DataFilter/options/DateRangeFilter.js +2 -2
- package/DataFilter/options/DateRangeFilter.js.map +1 -1
- package/DataFilter/options/MultiSelectFilter.cjs +3 -3
- package/DataFilter/options/MultiSelectFilter.cjs.map +1 -1
- package/DataFilter/options/MultiSelectFilter.js +3 -3
- package/DataFilter/options/MultiSelectFilter.js.map +1 -1
- package/DataFilter/options/NumberFilter.cjs +2 -2
- package/DataFilter/options/NumberFilter.cjs.map +1 -1
- package/DataFilter/options/NumberFilter.js +2 -2
- package/DataFilter/options/NumberFilter.js.map +1 -1
- package/DataFilter/options/NumberRangeFilter.cjs +2 -2
- package/DataFilter/options/NumberRangeFilter.cjs.map +1 -1
- package/DataFilter/options/NumberRangeFilter.js +2 -2
- package/DataFilter/options/NumberRangeFilter.js.map +1 -1
- package/DataFilter/options/SelectFilter.cjs +3 -3
- package/DataFilter/options/SelectFilter.cjs.map +1 -1
- package/DataFilter/options/SelectFilter.js +3 -3
- package/DataFilter/options/SelectFilter.js.map +1 -1
- package/DataFilter/options/TextFilter.cjs +2 -2
- package/DataFilter/options/TextFilter.cjs.map +1 -1
- package/DataFilter/options/TextFilter.js +2 -2
- package/DataFilter/options/TextFilter.js.map +1 -1
- package/Datatable/FilterBox.cjs +2 -2
- package/Datatable/FilterBox.cjs.map +1 -1
- package/Datatable/FilterBox.js +2 -2
- package/Datatable/FilterBox.js.map +1 -1
- package/Datatable/Row.cjs +2 -2
- package/Datatable/Row.cjs.map +1 -1
- package/Datatable/Row.js +2 -2
- package/Datatable/Row.js.map +1 -1
- package/Datatable/SelectedBox.cjs +2 -2
- package/Datatable/SelectedBox.cjs.map +1 -1
- package/Datatable/SelectedBox.js +2 -2
- package/Datatable/SelectedBox.js.map +1 -1
- package/Datatable/Table.cjs +1 -1
- package/Datatable/Table.cjs.map +1 -1
- package/Datatable/Table.js +1 -1
- package/Datatable/Table.js.map +1 -1
- package/Datatable/TableHead.cjs +3 -3
- package/Datatable/TableHead.cjs.map +1 -1
- package/Datatable/TableHead.js +3 -3
- package/Datatable/TableHead.js.map +1 -1
- package/Datatable/index.cjs +1 -1
- package/Datatable/index.cjs.map +1 -1
- package/Datatable/index.d.ts +2 -2
- package/Datatable/index.js +1 -1
- package/Datatable/index.js.map +1 -1
- package/Divider/index.cjs +3 -3
- package/Divider/index.cjs.map +1 -1
- package/Divider/index.d.ts +2 -2
- package/Divider/index.js +3 -3
- package/Divider/index.js.map +1 -1
- package/Drawer/index.cjs +2 -2
- package/Drawer/index.cjs.map +1 -1
- package/Drawer/index.js +2 -2
- package/Drawer/index.js.map +1 -1
- package/FilePicker/index.cjs +115 -0
- package/FilePicker/index.cjs.map +1 -0
- package/FilePicker/index.d.ts +23 -0
- package/FilePicker/index.js +113 -0
- package/FilePicker/index.js.map +1 -0
- package/Form/index.cjs +1 -1
- package/Form/index.cjs.map +1 -1
- package/Form/index.d.ts +2 -2
- package/Form/index.js +1 -1
- package/Form/index.js.map +1 -1
- package/GalleryPicker/index.cjs +88 -0
- package/GalleryPicker/index.cjs.map +1 -0
- package/GalleryPicker/index.d.ts +26 -0
- package/GalleryPicker/index.js +86 -0
- package/GalleryPicker/index.js.map +1 -0
- package/GridContainer/index.d.ts +2 -2
- package/GridItem/index.d.ts +2 -2
- package/IconButton/index.cjs +6 -3
- package/IconButton/index.cjs.map +1 -1
- package/IconButton/index.d.ts +2 -2
- package/IconButton/index.js +6 -3
- package/IconButton/index.js.map +1 -1
- package/Image/index.cjs +2 -14
- package/Image/index.cjs.map +1 -1
- package/Image/index.d.ts +3 -5
- package/Image/index.js +3 -15
- package/Image/index.js.map +1 -1
- package/Input/index.cjs +10 -10
- package/Input/index.cjs.map +1 -1
- package/Input/index.d.ts +14 -14
- package/Input/index.js +10 -10
- package/Input/index.js.map +1 -1
- package/InputNumber/index.d.ts +2 -2
- package/Label/index.cjs +1 -1
- package/Label/index.cjs.map +1 -1
- package/Label/index.d.ts +2 -2
- package/Label/index.js +1 -1
- package/Label/index.js.map +1 -1
- package/Layer/index.cjs +12 -13
- package/Layer/index.cjs.map +1 -1
- package/Layer/index.d.ts +5 -5
- package/Layer/index.js +13 -14
- package/Layer/index.js.map +1 -1
- package/LineProgress/index.cjs +6 -6
- package/LineProgress/index.cjs.map +1 -1
- package/LineProgress/index.d.ts +2 -2
- package/LineProgress/index.js +6 -6
- package/LineProgress/index.js.map +1 -1
- package/Link/index.cjs +41 -0
- package/Link/index.cjs.map +1 -0
- package/Link/index.d.ts +17 -0
- package/Link/index.js +39 -0
- package/Link/index.js.map +1 -0
- package/List/index.cjs +1 -1
- package/List/index.cjs.map +1 -1
- package/List/index.d.ts +2 -2
- package/List/index.js +1 -1
- package/List/index.js.map +1 -1
- package/ListItem/index.cjs +8 -8
- package/ListItem/index.cjs.map +1 -1
- package/ListItem/index.d.ts +2 -2
- package/ListItem/index.js +8 -8
- package/ListItem/index.js.map +1 -1
- package/LoadingBox/index.cjs +2 -2
- package/LoadingBox/index.cjs.map +1 -1
- package/LoadingBox/index.d.ts +2 -2
- package/LoadingBox/index.js +2 -2
- package/LoadingBox/index.js.map +1 -1
- package/Menu/index.cjs +25 -14
- package/Menu/index.cjs.map +1 -1
- package/Menu/index.d.ts +6 -4
- package/Menu/index.js +25 -14
- package/Menu/index.js.map +1 -1
- package/Modal/index.cjs +5 -5
- package/Modal/index.cjs.map +1 -1
- package/Modal/index.js +5 -5
- package/Modal/index.js.map +1 -1
- package/Option/index.d.ts +2 -2
- package/PasswordInput/index.cjs +21 -0
- package/PasswordInput/index.cjs.map +1 -0
- package/PasswordInput/index.d.ts +11 -0
- package/PasswordInput/index.js +19 -0
- package/PasswordInput/index.js.map +1 -0
- package/Portal/index.cjs +1 -1
- package/Portal/index.cjs.map +1 -1
- package/Portal/index.d.ts +3 -3
- package/Portal/index.js +1 -1
- package/Portal/index.js.map +1 -1
- package/Radio/index.d.ts +2 -2
- package/RangeSlider/index.cjs +158 -0
- package/RangeSlider/index.cjs.map +1 -0
- package/RangeSlider/index.d.ts +24 -0
- package/RangeSlider/index.js +156 -0
- package/RangeSlider/index.js.map +1 -0
- package/Scrollbar/index.cjs +6 -6
- package/Scrollbar/index.cjs.map +1 -1
- package/Scrollbar/index.d.ts +3 -3
- package/Scrollbar/index.js +6 -6
- package/Scrollbar/index.js.map +1 -1
- package/Select/index.cjs +2 -2
- package/Select/index.cjs.map +1 -1
- package/Select/index.d.ts +5 -5
- package/Select/index.js +2 -2
- package/Select/index.js.map +1 -1
- package/Skeleton/index.cjs +7 -5
- package/Skeleton/index.cjs.map +1 -1
- package/Skeleton/index.js +7 -5
- package/Skeleton/index.js.map +1 -1
- package/Stack/index.d.ts +2 -2
- package/Switch/index.cjs +2 -2
- package/Switch/index.cjs.map +1 -1
- package/Switch/index.d.ts +3 -3
- package/Switch/index.js +2 -2
- package/Switch/index.js.map +1 -1
- package/Tab/index.cjs +23 -2
- package/Tab/index.cjs.map +1 -1
- package/Tab/index.d.ts +2 -2
- package/Tab/index.js +25 -4
- package/Tab/index.js.map +1 -1
- package/Table/index.cjs +9 -9
- package/Table/index.cjs.map +1 -1
- package/Table/index.d.ts +2 -2
- package/Table/index.js +9 -9
- package/Table/index.js.map +1 -1
- package/TableBody/index.d.ts +2 -2
- package/TableCell/index.cjs +1 -1
- package/TableCell/index.cjs.map +1 -1
- package/TableCell/index.d.ts +2 -2
- package/TableCell/index.js +1 -1
- package/TableCell/index.js.map +1 -1
- package/TableFooter/index.d.ts +2 -2
- package/TableHead/index.d.ts +2 -2
- package/TablePagination/index.cjs +2 -2
- package/TablePagination/index.cjs.map +1 -1
- package/TablePagination/index.d.ts +2 -2
- package/TablePagination/index.js +2 -2
- package/TablePagination/index.js.map +1 -1
- package/TableRow/index.d.ts +2 -2
- package/Tabs/context.cjs +11 -0
- package/Tabs/context.cjs.map +1 -0
- package/Tabs/context.js +8 -0
- package/Tabs/context.js.map +1 -0
- package/Tabs/index.cjs +83 -168
- package/Tabs/index.cjs.map +1 -1
- package/Tabs/index.d.ts +4 -22
- package/Tabs/index.js +86 -171
- package/Tabs/index.js.map +1 -1
- package/Tabs/types.d.ts +16 -0
- package/Text/index.cjs +1 -1
- package/Text/index.cjs.map +1 -1
- package/Text/index.d.ts +2 -2
- package/Text/index.js +1 -1
- package/Text/index.js.map +1 -1
- package/Toast/index.cjs +15 -16
- package/Toast/index.cjs.map +1 -1
- package/Toast/index.js +16 -17
- package/Toast/index.js.map +1 -1
- package/Tooltip/index.cjs +2 -2
- package/Tooltip/index.cjs.map +1 -1
- package/Tooltip/index.js +2 -2
- package/Tooltip/index.js.map +1 -1
- package/ViewBox/index.d.ts +2 -2
- package/index.cjs +124 -110
- package/index.cjs.map +1 -1
- package/index.d.ts +8 -1
- package/index.js +8 -1
- package/index.js.map +1 -1
- package/package.json +3 -4
- package/readme.md +1 -1
- package/useBlurCss/index.cjs +1 -2
- package/useBlurCss/index.cjs.map +1 -1
- package/useBlurCss/index.js +1 -2
- package/useBlurCss/index.js.map +1 -1
- package/useContextMenu/index.cjs +2 -2
- package/useContextMenu/index.cjs.map +1 -1
- package/useContextMenu/index.d.ts +1 -1
- package/useContextMenu/index.js +2 -2
- package/useContextMenu/index.js.map +1 -1
- package/Paper/index.cjs +0 -16
- package/Paper/index.cjs.map +0 -1
- package/Paper/index.d.ts +0 -8
- package/Paper/index.js +0 -14
- package/Paper/index.js.map +0 -1
package/Divider/index.cjs
CHANGED
|
@@ -18,13 +18,13 @@ const Divider = React.forwardRef((_a, ref) => {
|
|
|
18
18
|
_p.size = size;
|
|
19
19
|
const p = core.useBreakpointProps(_p);
|
|
20
20
|
direction = (_b = p.direction) !== null && _b !== void 0 ? _b : "horizental";
|
|
21
|
-
color = (_c = p.color) !== null && _c !== void 0 ? _c :
|
|
21
|
+
color = (_c = p.color) !== null && _c !== void 0 ? _c : 'surface';
|
|
22
22
|
size = (_d = p.size) !== null && _d !== void 0 ? _d : 1;
|
|
23
23
|
let isHori = direction === 'horizental';
|
|
24
|
-
return (jsxRuntime.jsx(core.Tag, Object.assign({}, rest, { baseClass: 'divider', sxr: {
|
|
24
|
+
return (jsxRuntime.jsx(core.Tag, Object.assign({}, rest, { baseClass: 'surface.divider', sxr: {
|
|
25
25
|
width: isHori ? "100%" : size,
|
|
26
26
|
height: isHori ? size : "100%",
|
|
27
|
-
bgcolor: color === '
|
|
27
|
+
bgcolor: color === 'surface' ? `surface.light` : `${color}.light`,
|
|
28
28
|
}, ref: ref, children: children })));
|
|
29
29
|
});
|
|
30
30
|
|
package/Divider/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Divider/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\n\n\nexport type DividerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"color\"> & {\n direction?: useBreakpointPropsType<\"verticle\" | \"horizental\">;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n size?: useBreakpointPropsType<number>;\n}\n\nconst Divider = React.forwardRef(<T extends TagComponentType = \"div\">({ children, direction, color, size, ...rest }: DividerProps<T>, ref: React.Ref<any>) => {\n const _p: any = {}\n if (direction) _p.direction = direction\n if (color) _p.color = color\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n direction = p.direction ?? \"horizental\"\n color = p.color ?? \
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Divider/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\n\n\nexport type DividerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"color\"> & {\n direction?: useBreakpointPropsType<\"verticle\" | \"horizental\">;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n size?: useBreakpointPropsType<number>;\n}\n\nconst Divider = React.forwardRef(<T extends TagComponentType = \"div\">({ children, direction, color, size, ...rest }: DividerProps<T>, ref: React.Ref<any>) => {\n const _p: any = {}\n if (direction) _p.direction = direction\n if (color) _p.color = color\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n direction = p.direction ?? \"horizental\"\n color = p.color ?? 'surface'\n size = p.size ?? 1\n\n let isHori = direction === 'horizental'\n\n return (\n <Tag\n {...rest}\n baseClass='surface.divider'\n sxr={{\n width: isHori ? \"100%\" : size,\n height: isHori ? size : \"100%\",\n bgcolor: color === 'surface' ? `surface.light` : `${color}.light`,\n }}\n ref={ref}\n >{children}</Tag>\n )\n})\n\nexport default Divider\n\n"],"names":[],"mappings":";;;;;;;;AAWA;;AAAsE;;AAElE;AAAe;AACf;AAAW;AACX;AAAU;AACV;AACA;AACA;AACA;AAEA;;;;AASY;AACH;AAIb;;"}
|
package/Divider/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React__default from 'react';
|
|
2
2
|
import { TagComponentType, TagProps, useBreakpointPropsType, UseColorTemplateColor } from '@xanui/core';
|
|
3
3
|
|
|
4
4
|
type DividerProps<T extends TagComponentType = "div"> = Omit<TagProps<T>, "color"> & {
|
|
@@ -6,7 +6,7 @@ type DividerProps<T extends TagComponentType = "div"> = Omit<TagProps<T>, "color
|
|
|
6
6
|
color?: useBreakpointPropsType<UseColorTemplateColor>;
|
|
7
7
|
size?: useBreakpointPropsType<number>;
|
|
8
8
|
};
|
|
9
|
-
declare const Divider:
|
|
9
|
+
declare const Divider: React__default.ForwardRefExoticComponent<Omit<DividerProps<TagComponentType>, "ref"> & React__default.RefAttributes<any>>;
|
|
10
10
|
|
|
11
11
|
export { Divider as default };
|
|
12
12
|
export type { DividerProps };
|
package/Divider/index.js
CHANGED
|
@@ -16,13 +16,13 @@ const Divider = React.forwardRef((_a, ref) => {
|
|
|
16
16
|
_p.size = size;
|
|
17
17
|
const p = useBreakpointProps(_p);
|
|
18
18
|
direction = (_b = p.direction) !== null && _b !== void 0 ? _b : "horizental";
|
|
19
|
-
color = (_c = p.color) !== null && _c !== void 0 ? _c :
|
|
19
|
+
color = (_c = p.color) !== null && _c !== void 0 ? _c : 'surface';
|
|
20
20
|
size = (_d = p.size) !== null && _d !== void 0 ? _d : 1;
|
|
21
21
|
let isHori = direction === 'horizental';
|
|
22
|
-
return (jsx(Tag, Object.assign({}, rest, { baseClass: 'divider', sxr: {
|
|
22
|
+
return (jsx(Tag, Object.assign({}, rest, { baseClass: 'surface.divider', sxr: {
|
|
23
23
|
width: isHori ? "100%" : size,
|
|
24
24
|
height: isHori ? size : "100%",
|
|
25
|
-
bgcolor: color === '
|
|
25
|
+
bgcolor: color === 'surface' ? `surface.light` : `${color}.light`,
|
|
26
26
|
}, ref: ref, children: children })));
|
|
27
27
|
});
|
|
28
28
|
|
package/Divider/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Divider/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\n\n\nexport type DividerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"color\"> & {\n direction?: useBreakpointPropsType<\"verticle\" | \"horizental\">;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n size?: useBreakpointPropsType<number>;\n}\n\nconst Divider = React.forwardRef(<T extends TagComponentType = \"div\">({ children, direction, color, size, ...rest }: DividerProps<T>, ref: React.Ref<any>) => {\n const _p: any = {}\n if (direction) _p.direction = direction\n if (color) _p.color = color\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n direction = p.direction ?? \"horizental\"\n color = p.color ?? \
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Divider/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\n\n\nexport type DividerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"color\"> & {\n direction?: useBreakpointPropsType<\"verticle\" | \"horizental\">;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n size?: useBreakpointPropsType<number>;\n}\n\nconst Divider = React.forwardRef(<T extends TagComponentType = \"div\">({ children, direction, color, size, ...rest }: DividerProps<T>, ref: React.Ref<any>) => {\n const _p: any = {}\n if (direction) _p.direction = direction\n if (color) _p.color = color\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n direction = p.direction ?? \"horizental\"\n color = p.color ?? 'surface'\n size = p.size ?? 1\n\n let isHori = direction === 'horizental'\n\n return (\n <Tag\n {...rest}\n baseClass='surface.divider'\n sxr={{\n width: isHori ? \"100%\" : size,\n height: isHori ? size : \"100%\",\n bgcolor: color === 'surface' ? `surface.light` : `${color}.light`,\n }}\n ref={ref}\n >{children}</Tag>\n )\n})\n\nexport default Divider\n\n"],"names":[],"mappings":";;;;;;AAWA;;AAAsE;;AAElE;AAAe;AACf;AAAW;AACX;AAAU;AACV;AACA;AACA;AACA;AAEA;;;;AASY;AACH;AAIb;;"}
|
package/Drawer/index.cjs
CHANGED
|
@@ -46,12 +46,12 @@ const Drawer = (_a) => {
|
|
|
46
46
|
}, children: jsxRuntime.jsx(index$1, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.clickOutside, { onClickOutside: onClickOutside || (() => { }), children: jsxRuntime.jsx(core.Tag, { sxr: {
|
|
47
47
|
width: isSide ? _size : "100%",
|
|
48
48
|
height: isSide ? "100%" : _size,
|
|
49
|
-
bgcolor: "
|
|
49
|
+
bgcolor: "surface.main",
|
|
50
50
|
shadow: 20
|
|
51
51
|
}, baseClass: 'drawer-content', children: children }) })) })) })));
|
|
52
52
|
};
|
|
53
53
|
Drawer.open = (children, props) => {
|
|
54
|
-
const d = core.Renderar.render(Drawer, Object.assign(Object.assign({ open: true }, props), { children,
|
|
54
|
+
const d = core.Renderar.render(Drawer, Object.assign(Object.assign({ open: true }, props), { children, onExited: () => {
|
|
55
55
|
d.unrender();
|
|
56
56
|
}, onClickOutside: () => {
|
|
57
57
|
if (props === null || props === void 0 ? void 0 : props.onClickOutside) {
|
package/Drawer/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Drawer/index.tsx"],"sourcesContent":["\"use client\";\nimport { Renderar, Tag, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport Layer, { LayerProps } from '../Layer';\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\n\nexport type DrawerProps = Omit<LayerProps, \"transition\" | \"slotProps\"> & {\n placement?: useBreakpointPropsType<\"left\" | \"right\" | \"bottom\" | \"top\">;\n size?: useBreakpointPropsType<number | \"small\" | \"medium\" | \"large\">;\n onClickOutside?: () => void;\n slotProps?: {\n layer?: Partial<Omit<LayerProps, \"children\">>\n root?: TagProps<\"div\">;\n content?: TagProps<\"div\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nconst getVariant = (placement?: any) => {\n switch (placement) {\n case \"right\":\n return \"fadeLeft\"\n case \"top\":\n return \"fadeDown\"\n case \"bottom\":\n return \"fadeUp\"\n default:\n return \"fadeRight\"\n }\n}\n\nconst Drawer = ({ children, placement, size, slotProps, onClickOutside, ...layerProps }: DrawerProps) => {\n const _p: any = {}\n if (placement) _p.placement = placement\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n\n placement = p.placement ?? 'left'\n size = p.size || \"medium\"\n\n let isSide = placement === 'left' || placement === 'right'\n let sizes: any = {\n small: 220,\n medium: 330,\n large: 440\n }\n\n let _size = sizes[size as any] || size\n\n return (\n <Layer\n {...layerProps}\n {...slotProps?.layer}\n transition={getVariant(placement)}\n >\n <Tag\n {...slotProps?.root}\n baseClass='drawer'\n sxr={{\n width: \"100vw\",\n height: \"100vh\",\n display: \"flex\",\n direction: isSide ? \"row\" : \"column\" as any,\n justifyContent: placement === 'left' || placement === 'top' ? \"flex-start\" : \"flex-end\"\n }}\n >\n <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n <Tag\n sxr={{\n width: isSide ? _size : \"100%\",\n height: isSide ? \"100%\" : _size,\n bgcolor: \"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Drawer/index.tsx"],"sourcesContent":["\"use client\";\nimport { Renderar, Tag, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport Layer, { LayerProps } from '../Layer';\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\n\nexport type DrawerProps = Omit<LayerProps, \"transition\" | \"slotProps\"> & {\n placement?: useBreakpointPropsType<\"left\" | \"right\" | \"bottom\" | \"top\">;\n size?: useBreakpointPropsType<number | \"small\" | \"medium\" | \"large\">;\n onClickOutside?: () => void;\n slotProps?: {\n layer?: Partial<Omit<LayerProps, \"children\">>\n root?: TagProps<\"div\">;\n content?: TagProps<\"div\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nconst getVariant = (placement?: any) => {\n switch (placement) {\n case \"right\":\n return \"fadeLeft\"\n case \"top\":\n return \"fadeDown\"\n case \"bottom\":\n return \"fadeUp\"\n default:\n return \"fadeRight\"\n }\n}\n\nconst Drawer = ({ children, placement, size, slotProps, onClickOutside, ...layerProps }: DrawerProps) => {\n const _p: any = {}\n if (placement) _p.placement = placement\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n\n placement = p.placement ?? 'left'\n size = p.size || \"medium\"\n\n let isSide = placement === 'left' || placement === 'right'\n let sizes: any = {\n small: 220,\n medium: 330,\n large: 440\n }\n\n let _size = sizes[size as any] || size\n\n return (\n <Layer\n {...layerProps}\n {...slotProps?.layer}\n transition={getVariant(placement)}\n\n >\n <Tag\n {...slotProps?.root}\n baseClass='drawer'\n sxr={{\n width: \"100vw\",\n height: \"100vh\",\n display: \"flex\",\n direction: isSide ? \"row\" : \"column\" as any,\n justifyContent: placement === 'left' || placement === 'top' ? \"flex-start\" : \"flex-end\"\n }}\n >\n <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n <Tag\n sxr={{\n width: isSide ? _size : \"100%\",\n height: isSide ? \"100%\" : _size,\n bgcolor: \"surface.main\",\n shadow: 20\n }}\n baseClass='drawer-content'\n >\n {children}\n </Tag>\n </ClickOutside>\n </Tag>\n </Layer>\n )\n}\n\n\nDrawer.open = (children: DrawerProps[\"children\"], props?: Omit<DrawerProps, \"children\" | \"open\">) => {\n const d = Renderar.render(Drawer as any, {\n open: true,\n ...props,\n children,\n onExited: () => {\n d.unrender()\n },\n onClickOutside: () => {\n if (props?.onClickOutside) {\n props.onClickOutside()\n } else {\n d.updateProps({ open: false })\n }\n }\n })\n\n return {\n open: () => {\n d.updateProps({ open: true })\n },\n close: () => {\n d.updateProps({ open: false })\n },\n }\n}\n\nDrawer.close = () => {\n Renderar.unrender(Drawer as any)\n}\n\nexport default Drawer"],"names":[],"mappings":";;;;;;;;;AAkBA;;AAEQ;AACI;AACJ;AACI;AACJ;AACI;AACJ;AACI;;AAEZ;AAEA;;AAAgB;;AAEZ;AAAe;AACf;AAAU;AACV;AAEA;AACA;;AAGA;AACI;AACA;AACA;;;AAKJ;AAWgB;AACA;AACA;;AAEA;;;;AAWQ;AACA;;AAU5B;AAGA;AACI;;AAMI;;;;;;;AAOA;;;;;;;;;AAWR;AAEA;AACI;AACJ;;"}
|
package/Drawer/index.js
CHANGED
|
@@ -44,12 +44,12 @@ const Drawer = (_a) => {
|
|
|
44
44
|
}, children: jsx(ClickOutside, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.clickOutside, { onClickOutside: onClickOutside || (() => { }), children: jsx(Tag, { sxr: {
|
|
45
45
|
width: isSide ? _size : "100%",
|
|
46
46
|
height: isSide ? "100%" : _size,
|
|
47
|
-
bgcolor: "
|
|
47
|
+
bgcolor: "surface.main",
|
|
48
48
|
shadow: 20
|
|
49
49
|
}, baseClass: 'drawer-content', children: children }) })) })) })));
|
|
50
50
|
};
|
|
51
51
|
Drawer.open = (children, props) => {
|
|
52
|
-
const d = Renderar.render(Drawer, Object.assign(Object.assign({ open: true }, props), { children,
|
|
52
|
+
const d = Renderar.render(Drawer, Object.assign(Object.assign({ open: true }, props), { children, onExited: () => {
|
|
53
53
|
d.unrender();
|
|
54
54
|
}, onClickOutside: () => {
|
|
55
55
|
if (props === null || props === void 0 ? void 0 : props.onClickOutside) {
|
package/Drawer/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Drawer/index.tsx"],"sourcesContent":["\"use client\";\nimport { Renderar, Tag, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport Layer, { LayerProps } from '../Layer';\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\n\nexport type DrawerProps = Omit<LayerProps, \"transition\" | \"slotProps\"> & {\n placement?: useBreakpointPropsType<\"left\" | \"right\" | \"bottom\" | \"top\">;\n size?: useBreakpointPropsType<number | \"small\" | \"medium\" | \"large\">;\n onClickOutside?: () => void;\n slotProps?: {\n layer?: Partial<Omit<LayerProps, \"children\">>\n root?: TagProps<\"div\">;\n content?: TagProps<\"div\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nconst getVariant = (placement?: any) => {\n switch (placement) {\n case \"right\":\n return \"fadeLeft\"\n case \"top\":\n return \"fadeDown\"\n case \"bottom\":\n return \"fadeUp\"\n default:\n return \"fadeRight\"\n }\n}\n\nconst Drawer = ({ children, placement, size, slotProps, onClickOutside, ...layerProps }: DrawerProps) => {\n const _p: any = {}\n if (placement) _p.placement = placement\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n\n placement = p.placement ?? 'left'\n size = p.size || \"medium\"\n\n let isSide = placement === 'left' || placement === 'right'\n let sizes: any = {\n small: 220,\n medium: 330,\n large: 440\n }\n\n let _size = sizes[size as any] || size\n\n return (\n <Layer\n {...layerProps}\n {...slotProps?.layer}\n transition={getVariant(placement)}\n >\n <Tag\n {...slotProps?.root}\n baseClass='drawer'\n sxr={{\n width: \"100vw\",\n height: \"100vh\",\n display: \"flex\",\n direction: isSide ? \"row\" : \"column\" as any,\n justifyContent: placement === 'left' || placement === 'top' ? \"flex-start\" : \"flex-end\"\n }}\n >\n <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n <Tag\n sxr={{\n width: isSide ? _size : \"100%\",\n height: isSide ? \"100%\" : _size,\n bgcolor: \"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Drawer/index.tsx"],"sourcesContent":["\"use client\";\nimport { Renderar, Tag, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport Layer, { LayerProps } from '../Layer';\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\n\nexport type DrawerProps = Omit<LayerProps, \"transition\" | \"slotProps\"> & {\n placement?: useBreakpointPropsType<\"left\" | \"right\" | \"bottom\" | \"top\">;\n size?: useBreakpointPropsType<number | \"small\" | \"medium\" | \"large\">;\n onClickOutside?: () => void;\n slotProps?: {\n layer?: Partial<Omit<LayerProps, \"children\">>\n root?: TagProps<\"div\">;\n content?: TagProps<\"div\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nconst getVariant = (placement?: any) => {\n switch (placement) {\n case \"right\":\n return \"fadeLeft\"\n case \"top\":\n return \"fadeDown\"\n case \"bottom\":\n return \"fadeUp\"\n default:\n return \"fadeRight\"\n }\n}\n\nconst Drawer = ({ children, placement, size, slotProps, onClickOutside, ...layerProps }: DrawerProps) => {\n const _p: any = {}\n if (placement) _p.placement = placement\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n\n placement = p.placement ?? 'left'\n size = p.size || \"medium\"\n\n let isSide = placement === 'left' || placement === 'right'\n let sizes: any = {\n small: 220,\n medium: 330,\n large: 440\n }\n\n let _size = sizes[size as any] || size\n\n return (\n <Layer\n {...layerProps}\n {...slotProps?.layer}\n transition={getVariant(placement)}\n\n >\n <Tag\n {...slotProps?.root}\n baseClass='drawer'\n sxr={{\n width: \"100vw\",\n height: \"100vh\",\n display: \"flex\",\n direction: isSide ? \"row\" : \"column\" as any,\n justifyContent: placement === 'left' || placement === 'top' ? \"flex-start\" : \"flex-end\"\n }}\n >\n <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n <Tag\n sxr={{\n width: isSide ? _size : \"100%\",\n height: isSide ? \"100%\" : _size,\n bgcolor: \"surface.main\",\n shadow: 20\n }}\n baseClass='drawer-content'\n >\n {children}\n </Tag>\n </ClickOutside>\n </Tag>\n </Layer>\n )\n}\n\n\nDrawer.open = (children: DrawerProps[\"children\"], props?: Omit<DrawerProps, \"children\" | \"open\">) => {\n const d = Renderar.render(Drawer as any, {\n open: true,\n ...props,\n children,\n onExited: () => {\n d.unrender()\n },\n onClickOutside: () => {\n if (props?.onClickOutside) {\n props.onClickOutside()\n } else {\n d.updateProps({ open: false })\n }\n }\n })\n\n return {\n open: () => {\n d.updateProps({ open: true })\n },\n close: () => {\n d.updateProps({ open: false })\n },\n }\n}\n\nDrawer.close = () => {\n Renderar.unrender(Drawer as any)\n}\n\nexport default Drawer"],"names":[],"mappings":";;;;;;;AAkBA;;AAEQ;AACI;AACJ;AACI;AACJ;AACI;AACJ;AACI;;AAEZ;AAEA;;AAAgB;;AAEZ;AAAe;AACf;AAAU;AACV;AAEA;AACA;;AAGA;AACI;AACA;AACA;;;AAKJ;AAWgB;AACA;AACA;;AAEA;;;;AAWQ;AACA;;AAU5B;AAGA;AACI;;AAMI;;;;;;;AAOA;;;;;;;;;AAWR;AAEA;AACI;AACJ;;"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib = require('tslib');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var core = require('@xanui/core');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
|
|
9
|
+
const FilePicker$1 = (_a, ref) => {
|
|
10
|
+
var _b;
|
|
11
|
+
var { children, multiple, action, accept, maxFileLimits, maxFileSize, onChange, onDragOver, onDragLeave, onError } = _a, props = tslib.__rest(_a, ["children", "multiple", "action", "accept", "maxFileLimits", "maxFileSize", "onChange", "onDragOver", "onDragLeave", "onError"]);
|
|
12
|
+
const bp = core.useBreakpointProps({ action });
|
|
13
|
+
action = (_b = bp.action) !== null && _b !== void 0 ? _b : "both";
|
|
14
|
+
const _props = {};
|
|
15
|
+
const handleFiles = (files) => {
|
|
16
|
+
const fileArray = Array.from(files);
|
|
17
|
+
// multiple
|
|
18
|
+
if (!multiple && fileArray.length > 1) {
|
|
19
|
+
onError && onError({
|
|
20
|
+
message: "Multiple file upload is not allowed.",
|
|
21
|
+
file: fileArray[1]
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// limit
|
|
26
|
+
if (maxFileLimits && fileArray.length > maxFileLimits) {
|
|
27
|
+
onError && onError({
|
|
28
|
+
message: `File limit exceeded. Maximum allowed is ${maxFileLimits}.`,
|
|
29
|
+
file: fileArray[maxFileLimits]
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// accept
|
|
34
|
+
if (accept && accept.length > 0) {
|
|
35
|
+
for (const file of fileArray) {
|
|
36
|
+
const isAccepted = accept.some((type) => {
|
|
37
|
+
if (type === '*/*')
|
|
38
|
+
return true;
|
|
39
|
+
if (type.endsWith('/*')) {
|
|
40
|
+
const mainType = type.split('/')[0];
|
|
41
|
+
return file.type.startsWith(mainType + '/');
|
|
42
|
+
}
|
|
43
|
+
return file.name.endsWith(type);
|
|
44
|
+
});
|
|
45
|
+
if (!isAccepted) {
|
|
46
|
+
onError && onError({
|
|
47
|
+
message: `File type not accepted: ${file.name}`,
|
|
48
|
+
file
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// size
|
|
55
|
+
if (maxFileSize) {
|
|
56
|
+
for (const file of fileArray) {
|
|
57
|
+
if (file.size > maxFileSize * 1024) {
|
|
58
|
+
onError && onError({
|
|
59
|
+
message: `File size exceeds the limit of ${maxFileSize} KB: ${file.name}`,
|
|
60
|
+
file
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onChange && onChange(fileArray);
|
|
67
|
+
};
|
|
68
|
+
const clickProps = {
|
|
69
|
+
onClick: () => {
|
|
70
|
+
const input = document.createElement('input');
|
|
71
|
+
input.type = 'file';
|
|
72
|
+
if (multiple) {
|
|
73
|
+
input.multiple = true;
|
|
74
|
+
}
|
|
75
|
+
if (accept && accept.length > 0) {
|
|
76
|
+
input.accept = accept.join(',');
|
|
77
|
+
}
|
|
78
|
+
input.onchange = (e) => {
|
|
79
|
+
handleFiles(e.target.files);
|
|
80
|
+
};
|
|
81
|
+
input.click();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const dropProps = {
|
|
85
|
+
onDragOver: (e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
onDragOver && onDragOver(e);
|
|
88
|
+
},
|
|
89
|
+
onDragLeave: (e) => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
onDragLeave && onDragLeave(e);
|
|
92
|
+
},
|
|
93
|
+
onDrop: (e) => {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
handleFiles(e.dataTransfer.files);
|
|
96
|
+
onDragLeave && onDragLeave(e);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
switch (action) {
|
|
100
|
+
case "click":
|
|
101
|
+
Object.assign(_props, clickProps);
|
|
102
|
+
break;
|
|
103
|
+
case "drop":
|
|
104
|
+
Object.assign(_props, dropProps);
|
|
105
|
+
break;
|
|
106
|
+
case "both":
|
|
107
|
+
Object.assign(_props, Object.assign(Object.assign({}, clickProps), dropProps));
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return (jsxRuntime.jsx(core.Tag, Object.assign({}, props, _props, { baseClass: 'file-picker', ref: ref, children: children })));
|
|
111
|
+
};
|
|
112
|
+
var FilePicker = React.forwardRef(FilePicker$1);
|
|
113
|
+
|
|
114
|
+
module.exports = FilePicker;
|
|
115
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/FilePicker/index.tsx"],"sourcesContent":["\"use client\"\nimport { Tag, TagComponentType, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport React from 'react';\n\nexport type FilePickerError = { message: string, file: File }\n\nexport type FilePickerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, 'accept' | \"onChange\" | \"onError\" | \"multiple\"> & {\n children?: React.ReactNode;\n multiple?: boolean;\n accept?: string[] // ['.png', '.jpg'] or ['image/*']\n maxFileSize?: number; // in kb\n maxFileLimits?: number;\n action?: useBreakpointPropsType<\"click\" | \"drop\" | \"both\">;\n onChange?: (files: File[]) => void;\n onDragOver?: (e: React.DragEvent) => void;\n onDragLeave?: (e: React.DragEvent) => void;\n onError?: (error: FilePickerError) => void;\n};\n\n\nconst FilePicker = <T extends TagComponentType = \"div\">({ children, multiple, action, accept, maxFileLimits, maxFileSize, onChange, onDragOver, onDragLeave, onError, ...props }: FilePickerProps<T>, ref: React.Ref<T>) => {\n\n const bp: any = useBreakpointProps({ action })\n action = bp.action ?? \"both\"\n const _props: any = {}\n\n const handleFiles = (files: FileList) => {\n const fileArray = Array.from(files);\n\n // multiple\n if (!multiple && fileArray.length > 1) {\n onError && onError({\n message: \"Multiple file upload is not allowed.\",\n file: fileArray[1]\n });\n return;\n }\n\n // limit\n if (maxFileLimits && fileArray.length > maxFileLimits) {\n onError && onError({\n message: `File limit exceeded. Maximum allowed is ${maxFileLimits}.`,\n file: fileArray[maxFileLimits]\n });\n return;\n }\n\n // accept\n if (accept && accept.length > 0) {\n for (const file of fileArray) {\n const isAccepted = accept.some((type) => {\n if (type === '*/*') return true;\n if (type.endsWith('/*')) {\n const mainType = type.split('/')[0];\n return file.type.startsWith(mainType + '/');\n }\n return file.name.endsWith(type);\n });\n if (!isAccepted) {\n onError && onError({\n message: `File type not accepted: ${file.name}`,\n file\n });\n return;\n }\n }\n }\n\n // size\n if (maxFileSize) {\n for (const file of fileArray) {\n if (file.size > maxFileSize * 1024) {\n onError && onError({\n message: `File size exceeds the limit of ${maxFileSize} KB: ${file.name}`,\n file\n });\n return;\n }\n }\n }\n onChange && onChange(fileArray);\n }\n\n\n const clickProps = {\n onClick: () => {\n const input = document.createElement('input');\n input.type = 'file';\n if (multiple) {\n input.multiple = true;\n }\n if (accept && accept.length > 0) {\n input.accept = accept.join(',');\n }\n input.onchange = (e: any) => {\n handleFiles(e.target.files);\n };\n input.click();\n }\n }\n\n const dropProps = {\n onDragOver: (e: React.DragEvent) => {\n e.preventDefault();\n onDragOver && onDragOver(e);\n },\n onDragLeave: (e: React.DragEvent) => {\n e.preventDefault();\n onDragLeave && onDragLeave(e);\n },\n onDrop: (e: React.DragEvent) => {\n e.preventDefault();\n handleFiles(e.dataTransfer.files);\n onDragLeave && onDragLeave(e);\n }\n }\n\n switch (action) {\n case \"click\":\n Object.assign(_props, clickProps);\n break;\n case \"drop\":\n Object.assign(_props, dropProps);\n break;\n case \"both\":\n Object.assign(_props, { ...clickProps, ...dropProps });\n break;\n }\n\n return (\n <Tag\n {...props}\n {..._props}\n baseClass='file-picker'\n ref={ref}\n >\n {children}\n </Tag>\n )\n}\n\nexport default React.forwardRef(FilePicker);"],"names":[],"mappings":";;;;;;;;AAoBA;;;;AAGG;;AAGA;;;;;AAMS;AACA;AACF;;;;;;;AAQE;AACF;;;;;AAMD;;;AAE0B;AACpB;;;;;AAKH;;;AAGM;;AAEF;;;;;;;AAQP;;;AAGS;;AAEF;;;;;AAKV;AACH;AAGA;;;AAGM;;AAEG;;;;;AAKH;AACG;AACH;;;;AAKN;AACG;;AAEG;;AAEH;;AAEG;;AAEH;;AAEG;AACA;;;;AAKH;AACG;;AAEH;AACG;;AAEH;;;;AAKH;AAUH;AAEA;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TagComponentType, TagProps, useBreakpointPropsType } from '@xanui/core';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
type FilePickerError = {
|
|
5
|
+
message: string;
|
|
6
|
+
file: File;
|
|
7
|
+
};
|
|
8
|
+
type FilePickerProps<T extends TagComponentType = "div"> = Omit<TagProps<T>, 'accept' | "onChange" | "onError" | "multiple"> & {
|
|
9
|
+
children?: React__default.ReactNode;
|
|
10
|
+
multiple?: boolean;
|
|
11
|
+
accept?: string[];
|
|
12
|
+
maxFileSize?: number;
|
|
13
|
+
maxFileLimits?: number;
|
|
14
|
+
action?: useBreakpointPropsType<"click" | "drop" | "both">;
|
|
15
|
+
onChange?: (files: File[]) => void;
|
|
16
|
+
onDragOver?: (e: React__default.DragEvent) => void;
|
|
17
|
+
onDragLeave?: (e: React__default.DragEvent) => void;
|
|
18
|
+
onError?: (error: FilePickerError) => void;
|
|
19
|
+
};
|
|
20
|
+
declare const _default: React__default.ForwardRefExoticComponent<Omit<FilePickerProps<TagComponentType>, "ref"> & React__default.RefAttributes<"symbol" | "object" | "cite" | "data" | "form" | "label" | "pattern" | "span" | "summary" | "slot" | "style" | "title" | "div" | "filter" | "small" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "big" | "text" | "button" | "p" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "blockquote" | "body" | "br" | "canvas" | "caption" | "center" | "code" | "col" | "colgroup" | "datalist" | "dd" | "del" | "details" | "dfn" | "dialog" | "dl" | "dt" | "em" | "embed" | "fieldset" | "figcaption" | "figure" | "footer" | "head" | "header" | "hgroup" | "hr" | "html" | "i" | "iframe" | "img" | "input" | "ins" | "kbd" | "keygen" | "legend" | "li" | "link" | "main" | "map" | "mark" | "menu" | "menuitem" | "meta" | "meter" | "nav" | "noindex" | "noscript" | "ol" | "optgroup" | "option" | "output" | "param" | "picture" | "pre" | "progress" | "q" | "rp" | "rt" | "ruby" | "s" | "samp" | "search" | "script" | "section" | "select" | "source" | "strong" | "sub" | "sup" | "table" | "template" | "tbody" | "td" | "textarea" | "tfoot" | "th" | "thead" | "time" | "tr" | "track" | "u" | "ul" | "var" | "video" | "wbr" | "webview" | "svg" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "g" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "switch" | "textPath" | "tspan" | "use" | "view" | React__default.ComponentClass<any, any> | React__default.FunctionComponent<any>>>;
|
|
21
|
+
|
|
22
|
+
export { _default as default };
|
|
23
|
+
export type { FilePickerError, FilePickerProps };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { __rest } from 'tslib';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useBreakpointProps, Tag } from '@xanui/core';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
const FilePicker = (_a, ref) => {
|
|
8
|
+
var _b;
|
|
9
|
+
var { children, multiple, action, accept, maxFileLimits, maxFileSize, onChange, onDragOver, onDragLeave, onError } = _a, props = __rest(_a, ["children", "multiple", "action", "accept", "maxFileLimits", "maxFileSize", "onChange", "onDragOver", "onDragLeave", "onError"]);
|
|
10
|
+
const bp = useBreakpointProps({ action });
|
|
11
|
+
action = (_b = bp.action) !== null && _b !== void 0 ? _b : "both";
|
|
12
|
+
const _props = {};
|
|
13
|
+
const handleFiles = (files) => {
|
|
14
|
+
const fileArray = Array.from(files);
|
|
15
|
+
// multiple
|
|
16
|
+
if (!multiple && fileArray.length > 1) {
|
|
17
|
+
onError && onError({
|
|
18
|
+
message: "Multiple file upload is not allowed.",
|
|
19
|
+
file: fileArray[1]
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// limit
|
|
24
|
+
if (maxFileLimits && fileArray.length > maxFileLimits) {
|
|
25
|
+
onError && onError({
|
|
26
|
+
message: `File limit exceeded. Maximum allowed is ${maxFileLimits}.`,
|
|
27
|
+
file: fileArray[maxFileLimits]
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// accept
|
|
32
|
+
if (accept && accept.length > 0) {
|
|
33
|
+
for (const file of fileArray) {
|
|
34
|
+
const isAccepted = accept.some((type) => {
|
|
35
|
+
if (type === '*/*')
|
|
36
|
+
return true;
|
|
37
|
+
if (type.endsWith('/*')) {
|
|
38
|
+
const mainType = type.split('/')[0];
|
|
39
|
+
return file.type.startsWith(mainType + '/');
|
|
40
|
+
}
|
|
41
|
+
return file.name.endsWith(type);
|
|
42
|
+
});
|
|
43
|
+
if (!isAccepted) {
|
|
44
|
+
onError && onError({
|
|
45
|
+
message: `File type not accepted: ${file.name}`,
|
|
46
|
+
file
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// size
|
|
53
|
+
if (maxFileSize) {
|
|
54
|
+
for (const file of fileArray) {
|
|
55
|
+
if (file.size > maxFileSize * 1024) {
|
|
56
|
+
onError && onError({
|
|
57
|
+
message: `File size exceeds the limit of ${maxFileSize} KB: ${file.name}`,
|
|
58
|
+
file
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
onChange && onChange(fileArray);
|
|
65
|
+
};
|
|
66
|
+
const clickProps = {
|
|
67
|
+
onClick: () => {
|
|
68
|
+
const input = document.createElement('input');
|
|
69
|
+
input.type = 'file';
|
|
70
|
+
if (multiple) {
|
|
71
|
+
input.multiple = true;
|
|
72
|
+
}
|
|
73
|
+
if (accept && accept.length > 0) {
|
|
74
|
+
input.accept = accept.join(',');
|
|
75
|
+
}
|
|
76
|
+
input.onchange = (e) => {
|
|
77
|
+
handleFiles(e.target.files);
|
|
78
|
+
};
|
|
79
|
+
input.click();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const dropProps = {
|
|
83
|
+
onDragOver: (e) => {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
onDragOver && onDragOver(e);
|
|
86
|
+
},
|
|
87
|
+
onDragLeave: (e) => {
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
onDragLeave && onDragLeave(e);
|
|
90
|
+
},
|
|
91
|
+
onDrop: (e) => {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
handleFiles(e.dataTransfer.files);
|
|
94
|
+
onDragLeave && onDragLeave(e);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
switch (action) {
|
|
98
|
+
case "click":
|
|
99
|
+
Object.assign(_props, clickProps);
|
|
100
|
+
break;
|
|
101
|
+
case "drop":
|
|
102
|
+
Object.assign(_props, dropProps);
|
|
103
|
+
break;
|
|
104
|
+
case "both":
|
|
105
|
+
Object.assign(_props, Object.assign(Object.assign({}, clickProps), dropProps));
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return (jsx(Tag, Object.assign({}, props, _props, { baseClass: 'file-picker', ref: ref, children: children })));
|
|
109
|
+
};
|
|
110
|
+
var FilePicker$1 = React.forwardRef(FilePicker);
|
|
111
|
+
|
|
112
|
+
export { FilePicker$1 as default };
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/FilePicker/index.tsx"],"sourcesContent":["\"use client\"\nimport { Tag, TagComponentType, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport React from 'react';\n\nexport type FilePickerError = { message: string, file: File }\n\nexport type FilePickerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, 'accept' | \"onChange\" | \"onError\" | \"multiple\"> & {\n children?: React.ReactNode;\n multiple?: boolean;\n accept?: string[] // ['.png', '.jpg'] or ['image/*']\n maxFileSize?: number; // in kb\n maxFileLimits?: number;\n action?: useBreakpointPropsType<\"click\" | \"drop\" | \"both\">;\n onChange?: (files: File[]) => void;\n onDragOver?: (e: React.DragEvent) => void;\n onDragLeave?: (e: React.DragEvent) => void;\n onError?: (error: FilePickerError) => void;\n};\n\n\nconst FilePicker = <T extends TagComponentType = \"div\">({ children, multiple, action, accept, maxFileLimits, maxFileSize, onChange, onDragOver, onDragLeave, onError, ...props }: FilePickerProps<T>, ref: React.Ref<T>) => {\n\n const bp: any = useBreakpointProps({ action })\n action = bp.action ?? \"both\"\n const _props: any = {}\n\n const handleFiles = (files: FileList) => {\n const fileArray = Array.from(files);\n\n // multiple\n if (!multiple && fileArray.length > 1) {\n onError && onError({\n message: \"Multiple file upload is not allowed.\",\n file: fileArray[1]\n });\n return;\n }\n\n // limit\n if (maxFileLimits && fileArray.length > maxFileLimits) {\n onError && onError({\n message: `File limit exceeded. Maximum allowed is ${maxFileLimits}.`,\n file: fileArray[maxFileLimits]\n });\n return;\n }\n\n // accept\n if (accept && accept.length > 0) {\n for (const file of fileArray) {\n const isAccepted = accept.some((type) => {\n if (type === '*/*') return true;\n if (type.endsWith('/*')) {\n const mainType = type.split('/')[0];\n return file.type.startsWith(mainType + '/');\n }\n return file.name.endsWith(type);\n });\n if (!isAccepted) {\n onError && onError({\n message: `File type not accepted: ${file.name}`,\n file\n });\n return;\n }\n }\n }\n\n // size\n if (maxFileSize) {\n for (const file of fileArray) {\n if (file.size > maxFileSize * 1024) {\n onError && onError({\n message: `File size exceeds the limit of ${maxFileSize} KB: ${file.name}`,\n file\n });\n return;\n }\n }\n }\n onChange && onChange(fileArray);\n }\n\n\n const clickProps = {\n onClick: () => {\n const input = document.createElement('input');\n input.type = 'file';\n if (multiple) {\n input.multiple = true;\n }\n if (accept && accept.length > 0) {\n input.accept = accept.join(',');\n }\n input.onchange = (e: any) => {\n handleFiles(e.target.files);\n };\n input.click();\n }\n }\n\n const dropProps = {\n onDragOver: (e: React.DragEvent) => {\n e.preventDefault();\n onDragOver && onDragOver(e);\n },\n onDragLeave: (e: React.DragEvent) => {\n e.preventDefault();\n onDragLeave && onDragLeave(e);\n },\n onDrop: (e: React.DragEvent) => {\n e.preventDefault();\n handleFiles(e.dataTransfer.files);\n onDragLeave && onDragLeave(e);\n }\n }\n\n switch (action) {\n case \"click\":\n Object.assign(_props, clickProps);\n break;\n case \"drop\":\n Object.assign(_props, dropProps);\n break;\n case \"both\":\n Object.assign(_props, { ...clickProps, ...dropProps });\n break;\n }\n\n return (\n <Tag\n {...props}\n {..._props}\n baseClass='file-picker'\n ref={ref}\n >\n {children}\n </Tag>\n )\n}\n\nexport default React.forwardRef(FilePicker);"],"names":[],"mappings":";;;;;;AAoBA;;;;AAGG;;AAGA;;;;;AAMS;AACA;AACF;;;;;;;AAQE;AACF;;;;;AAMD;;;AAE0B;AACpB;;;;;AAKH;;;AAGM;;AAEF;;;;;;;AAQP;;;AAGS;;AAEF;;;;;AAKV;AACH;AAGA;;;AAGM;;AAEG;;;;;AAKH;AACG;AACH;;;;AAKN;AACG;;AAEG;;AAEH;;AAEG;;AAEH;;AAEG;AACA;;;;AAKH;AACG;;AAEH;AACG;;AAEH;;;;AAKH;AAUH;AAEA;;"}
|
package/Form/index.cjs
CHANGED
package/Form/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Form/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useRef } from 'react';\nimport { Tag, TagProps, TagComponentType } from '@xanui/core';\n\nexport type FormProps<T extends TagComponentType = \"form\"> = TagProps<T> & {\n\n}\n\n\nconst Form = React.forwardRef(<T extends TagComponentType = \"form\">({ children, ...rest }: FormProps<T>, ref: React.Ref<any>) => {\n let formRef: any = ref || useRef(null)\n\n const cloneAllChildren: any = (childs: any) => {\n return React.Children.map(childs, (child: any) => {\n let c: any = child;\n if (React.isValidElement(child) && c.props.name) {\n const form = formRef.current\n const formData = new FormData(form);\n return React.cloneElement(child, {\n onChange: () => {\n console.log(formData.get(c.props.name));\n },\n value: formData.get(c.props.name),\n children: cloneAllChildren(c.props.children),\n } as any);\n }\n return child;\n });\n };\n\n return (\n <Tag\n component=\"form\"\n {...rest}\n onSubmit={(e) => {\n e.preventDefault()\n const form = formRef.current\n\n const formData = new FormData(form);\n\n formData.forEach((value, key) => {\n console.log(key + \": \" + value);\n });\n }}\n sxr={{\n bgcolor:
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Form/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useRef } from 'react';\nimport { Tag, TagProps, TagComponentType } from '@xanui/core';\n\nexport type FormProps<T extends TagComponentType = \"form\"> = TagProps<T> & {\n\n}\n\n\nconst Form = React.forwardRef(<T extends TagComponentType = \"form\">({ children, ...rest }: FormProps<T>, ref: React.Ref<any>) => {\n let formRef: any = ref || useRef(null)\n\n const cloneAllChildren: any = (childs: any) => {\n return React.Children.map(childs, (child: any) => {\n let c: any = child;\n if (React.isValidElement(child) && c.props.name) {\n const form = formRef.current\n const formData = new FormData(form);\n return React.cloneElement(child, {\n onChange: () => {\n console.log(formData.get(c.props.name));\n },\n value: formData.get(c.props.name),\n children: cloneAllChildren(c.props.children),\n } as any);\n }\n return child;\n });\n };\n\n return (\n <Tag\n component=\"form\"\n {...rest}\n onSubmit={(e) => {\n e.preventDefault()\n const form = formRef.current\n\n const formData = new FormData(form);\n\n formData.forEach((value, key) => {\n console.log(key + \": \" + value);\n });\n }}\n sxr={{\n bgcolor: 'surface',\n p: 2,\n maxWidth: 400,\n radius: 1,\n }}\n baseClass='form'\n ref={formRef}\n >\n {cloneAllChildren(children)}\n </Tag>\n )\n})\n\nexport default Form\n\n"],"names":[],"mappings":";;;;;;;;AASA;AAAoE;;AAGhE;;;AAGQ;AACI;AACA;AACA;;AAEQ;;;;AAIA;;AAEZ;AACJ;AACJ;AAEA;;AAMY;AAEA;;;AAIA;;AAGA;AACA;AACA;AACA;AACH;AAOb;;"}
|
package/Form/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React__default from 'react';
|
|
2
2
|
import { TagComponentType, TagProps } from '@xanui/core';
|
|
3
3
|
|
|
4
4
|
type FormProps<T extends TagComponentType = "form"> = TagProps<T> & {};
|
|
5
|
-
declare const Form:
|
|
5
|
+
declare const Form: React__default.ForwardRefExoticComponent<Omit<FormProps<TagComponentType>, "ref"> & React__default.RefAttributes<any>>;
|
|
6
6
|
|
|
7
7
|
export { Form as default };
|
|
8
8
|
export type { FormProps };
|
package/Form/index.js
CHANGED
package/Form/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Form/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useRef } from 'react';\nimport { Tag, TagProps, TagComponentType } from '@xanui/core';\n\nexport type FormProps<T extends TagComponentType = \"form\"> = TagProps<T> & {\n\n}\n\n\nconst Form = React.forwardRef(<T extends TagComponentType = \"form\">({ children, ...rest }: FormProps<T>, ref: React.Ref<any>) => {\n let formRef: any = ref || useRef(null)\n\n const cloneAllChildren: any = (childs: any) => {\n return React.Children.map(childs, (child: any) => {\n let c: any = child;\n if (React.isValidElement(child) && c.props.name) {\n const form = formRef.current\n const formData = new FormData(form);\n return React.cloneElement(child, {\n onChange: () => {\n console.log(formData.get(c.props.name));\n },\n value: formData.get(c.props.name),\n children: cloneAllChildren(c.props.children),\n } as any);\n }\n return child;\n });\n };\n\n return (\n <Tag\n component=\"form\"\n {...rest}\n onSubmit={(e) => {\n e.preventDefault()\n const form = formRef.current\n\n const formData = new FormData(form);\n\n formData.forEach((value, key) => {\n console.log(key + \": \" + value);\n });\n }}\n sxr={{\n bgcolor:
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Form/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useRef } from 'react';\nimport { Tag, TagProps, TagComponentType } from '@xanui/core';\n\nexport type FormProps<T extends TagComponentType = \"form\"> = TagProps<T> & {\n\n}\n\n\nconst Form = React.forwardRef(<T extends TagComponentType = \"form\">({ children, ...rest }: FormProps<T>, ref: React.Ref<any>) => {\n let formRef: any = ref || useRef(null)\n\n const cloneAllChildren: any = (childs: any) => {\n return React.Children.map(childs, (child: any) => {\n let c: any = child;\n if (React.isValidElement(child) && c.props.name) {\n const form = formRef.current\n const formData = new FormData(form);\n return React.cloneElement(child, {\n onChange: () => {\n console.log(formData.get(c.props.name));\n },\n value: formData.get(c.props.name),\n children: cloneAllChildren(c.props.children),\n } as any);\n }\n return child;\n });\n };\n\n return (\n <Tag\n component=\"form\"\n {...rest}\n onSubmit={(e) => {\n e.preventDefault()\n const form = formRef.current\n\n const formData = new FormData(form);\n\n formData.forEach((value, key) => {\n console.log(key + \": \" + value);\n });\n }}\n sxr={{\n bgcolor: 'surface',\n p: 2,\n maxWidth: 400,\n radius: 1,\n }}\n baseClass='form'\n ref={formRef}\n >\n {cloneAllChildren(children)}\n </Tag>\n )\n})\n\nexport default Form\n\n"],"names":[],"mappings":";;;;;;AASA;AAAoE;;AAGhE;;;AAGQ;AACI;AACA;AACA;;AAEQ;;;;AAIA;;AAEZ;AACJ;AACJ;AAEA;;AAMY;AAEA;;;AAIA;;AAGA;AACA;AACA;AACA;AACH;AAOb;;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib = require('tslib');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var index$3 = require('../FilePicker/index.cjs');
|
|
8
|
+
var index$1 = require('../Alert/index.cjs');
|
|
9
|
+
var index$2 = require('../Box/index.cjs');
|
|
10
|
+
var index$4 = require('../Button/index.cjs');
|
|
11
|
+
var index$6 = require('../IconButton/index.cjs');
|
|
12
|
+
var index = require('../Stack/index.cjs');
|
|
13
|
+
var index$5 = require('../Text/index.cjs');
|
|
14
|
+
var AddPhotoAlternateOutlined = require('@xanui/icons/AddPhotoAlternateOutlined');
|
|
15
|
+
var DeleteOutline = require('@xanui/icons/DeleteOutline');
|
|
16
|
+
var core = require('@xanui/core');
|
|
17
|
+
|
|
18
|
+
const FileCard = ({ file, onRemove }) => {
|
|
19
|
+
const url = typeof file === "string" ? file : URL.createObjectURL(file);
|
|
20
|
+
return (jsxRuntime.jsxs(index$2, { width: 100, height: 100, border: "1px solid", borderColor: 'surface.divider', radius: 1, overflow: "hidden", position: "relative", children: [jsxRuntime.jsx(index$6, { size: 25, color: "danger", sx: {
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
top: 2,
|
|
23
|
+
right: 2,
|
|
24
|
+
}, onClick: onRemove, children: jsxRuntime.jsx(DeleteOutline, {}) }), jsxRuntime.jsx(index$2, { component: "img", src: url, style: {
|
|
25
|
+
width: '100%',
|
|
26
|
+
height: '100%',
|
|
27
|
+
objectFit: 'cover',
|
|
28
|
+
} })] }));
|
|
29
|
+
};
|
|
30
|
+
const GalleryPicker = React.forwardRef((_a, ref) => {
|
|
31
|
+
var { title, subtitle, icon, value, maxFileLimits, maxFileSize, onSelect, onDelete, onChange, onError, slotProps } = _a, props = tslib.__rest(_a, ["title", "subtitle", "icon", "value", "maxFileLimits", "maxFileSize", "onSelect", "onDelete", "onChange", "onError", "slotProps"]);
|
|
32
|
+
const bp = core.useBreakpointProps({
|
|
33
|
+
title,
|
|
34
|
+
subtitle,
|
|
35
|
+
icon
|
|
36
|
+
});
|
|
37
|
+
title = bp.title;
|
|
38
|
+
subtitle = bp.subtitle;
|
|
39
|
+
icon = bp.icon;
|
|
40
|
+
const [error, setError] = React.useState(null);
|
|
41
|
+
maxFileLimits !== null && maxFileLimits !== void 0 ? maxFileLimits : (maxFileLimits = 10);
|
|
42
|
+
const filePickerProps = Object.assign(Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.filePicker), { multiple: true, accept: ['image/*'], maxFileSize: maxFileSize !== null && maxFileSize !== void 0 ? maxFileSize : 5 * 1024, // 5MB
|
|
43
|
+
maxFileLimits, onChange: (_files) => {
|
|
44
|
+
let all = [...((value || [])), ...(_files || [])];
|
|
45
|
+
if (all.length > maxFileLimits) {
|
|
46
|
+
setError({
|
|
47
|
+
message: `You can upload maximum ${maxFileLimits} files.`,
|
|
48
|
+
file: null
|
|
49
|
+
});
|
|
50
|
+
setTimeout(() => setError(null), 4000);
|
|
51
|
+
all = all.slice(0, 10);
|
|
52
|
+
}
|
|
53
|
+
if (onSelect && _files)
|
|
54
|
+
onSelect(_files, value || []);
|
|
55
|
+
onChange && onChange(all);
|
|
56
|
+
}, onError: (err) => {
|
|
57
|
+
setError(err);
|
|
58
|
+
onError && onError(err);
|
|
59
|
+
setTimeout(() => setError(null), 4000);
|
|
60
|
+
} });
|
|
61
|
+
if (value && value.length > 0) {
|
|
62
|
+
return (jsxRuntime.jsxs(index, { gap: 2, children: [error && jsxRuntime.jsx(index$1, { variant: "fill", color: "danger", mb: 2, icon: jsxRuntime.jsx(index$2, { component: "img", src: URL.createObjectURL(error.file) }), children: error.message }), jsxRuntime.jsxs(index, { direction: "row", gap: 1, flexWrap: "wrap", children: [value.map((file, index) => (jsxRuntime.jsx(FileCard, { file: file, onRemove: () => {
|
|
63
|
+
const newFiles = value.filter((_, i) => i !== index);
|
|
64
|
+
onDelete && onDelete(file);
|
|
65
|
+
onChange && onChange(newFiles.length > 0 ? newFiles : null);
|
|
66
|
+
} }, index))), jsxRuntime.jsxs(index, { width: 100, height: 100, bgcolor: "surface.light", radius: 1, alignItems: "center", overflow: "hidden", border: "1px solid", borderColor: 'surface.divider', children: [jsxRuntime.jsx(index$3, Object.assign({}, filePickerProps, { alignItems: "center", justifyContent: "center", width: "100%", flex: 1, cursor: "pointer", borderBottom: "1px solid", borderColor: "surface.divider", sx: {
|
|
67
|
+
'& svg': {
|
|
68
|
+
opacity: 0.6,
|
|
69
|
+
},
|
|
70
|
+
"&:hover svg": {
|
|
71
|
+
opacity: 1,
|
|
72
|
+
}
|
|
73
|
+
}, children: jsxRuntime.jsx(AddPhotoAlternateOutlined, { fontSize: 28, color: "surface.muted" }) })), jsxRuntime.jsx(index$4, { size: "small", variant: "text", onClick: () => onChange && onChange(null), sx: {
|
|
74
|
+
height: 28,
|
|
75
|
+
}, children: "CLEAR" })] })] })] }));
|
|
76
|
+
}
|
|
77
|
+
return (jsxRuntime.jsxs(core.Tag, Object.assign({}, props, { baseClass: 'gallery-picker', ref: ref, sxr: {
|
|
78
|
+
display: "flex"
|
|
79
|
+
}, children: [error && jsxRuntime.jsx(index$1, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.alert, { variant: "fill", color: "danger", mb: 2, icon: jsxRuntime.jsx(index$2, { component: "img", src: URL.createObjectURL(error.file) }), children: error.message })), jsxRuntime.jsx(index$3, Object.assign({}, filePickerProps, { width: "100%", border: "1px dashed", borderColor: 'surface.divider', radius: 2, alignItems: "center", justifyContent: "center", children: jsxRuntime.jsxs(core.Tag, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.content, { baseClass: 'gallery-picker-content', sxr: {
|
|
80
|
+
display: "flex",
|
|
81
|
+
justifyContent: "center",
|
|
82
|
+
alignItems: "center",
|
|
83
|
+
p: 4,
|
|
84
|
+
}, children: [jsxRuntime.jsx(core.Tag, { mb: 2, children: icon || jsxRuntime.jsx(AddPhotoAlternateOutlined, { fontSize: 38, color: "surface.muted" }) }), jsxRuntime.jsx(index$5, { children: title || "Drag & drop images here or click to upload." }), jsxRuntime.jsx(index$5, { variant: "button", color: "surface.muted", children: subtitle || `Images only · Max ${filePickerProps.maxFileSize / 1024}MB each · Up to ${filePickerProps.maxFileLimits} files.` })] })) }))] })));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
module.exports = GalleryPicker;
|
|
88
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/GalleryPicker/index.tsx"],"sourcesContent":["\"use client\"\nimport React from 'react'\nimport FilePicker, { FilePickerError, FilePickerProps } from '../FilePicker'\nimport Alert, { AlertProps } from \"../Alert\"\nimport Box from \"../Box\"\nimport Button from \"../Button\"\nimport IconButton from \"../IconButton\"\nimport Stack from \"../Stack\"\nimport Text from \"../Text\"\nimport AddPhotoAlternateOutlined from '@xanui/icons/AddPhotoAlternateOutlined'\nimport DeleteOutline from '@xanui/icons/DeleteOutline'\nimport { Tag, TagComponentType, TagProps, useBreakpointProps, useBreakpointPropsType } from '@xanui/core'\n\n\nconst FileCard = ({ file, onRemove }: { file: File | string, onRemove: () => void }) => {\n const url = typeof file === \"string\" ? file : URL.createObjectURL(file);\n\n return (\n <Box\n width={100}\n height={100}\n border=\"1px solid\"\n borderColor='surface.divider'\n radius={1}\n overflow=\"hidden\"\n position=\"relative\"\n >\n <IconButton\n size={25}\n color=\"danger\"\n sx={{\n position: 'absolute',\n top: 2,\n right: 2,\n }}\n onClick={onRemove}\n >\n <DeleteOutline />\n </IconButton>\n <Box\n component=\"img\"\n src={url}\n style={{\n width: '100%',\n height: '100%',\n objectFit: 'cover',\n }}\n />\n </Box>\n )\n}\n\n\nexport type GalleryPickerProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"children\"> & {\n title?: useBreakpointPropsType<string>;\n subtitle?: useBreakpointPropsType<string>;\n icon?: useBreakpointPropsType<React.ReactNode>;\n value?: (File | string)[] | null;\n maxFileSize?: number; // in kb\n maxFileLimits?: number;\n onSelect?: (files: File[], oldFiles: (File | string)[] | null) => void;\n onDelete?: (file: File | string) => void;\n onChange?: (files: (File | string)[] | null) => void;\n onError?: (error: FilePickerError) => void;\n\n slotProps?: {\n alert?: Omit<AlertProps, \"children\" | \"variant\" | \"color\" | \"icon\">;\n filePicker?: Omit<FilePickerProps, \"multiple\" | \"accept\" | \"onChange\">;\n content?: Omit<TagProps, \"children\">;\n }\n}\n\nconst GalleryPicker = React.forwardRef(<T extends TagComponentType = \"div\">({ title, subtitle, icon, value, maxFileLimits, maxFileSize, onSelect, onDelete, onChange, onError, slotProps, ...props }: GalleryPickerProps, ref: React.Ref<T>) => {\n\n const bp: any = useBreakpointProps({\n title,\n subtitle,\n icon\n })\n\n title = bp.title\n subtitle = bp.subtitle\n icon = bp.icon\n\n const [error, setError] = React.useState<FilePickerError | null>(null);\n maxFileLimits ??= 10\n const filePickerProps = {\n ...slotProps?.filePicker,\n multiple: true,\n accept: ['image/*'],\n maxFileSize: maxFileSize ?? 5 * 1024, // 5MB\n maxFileLimits,\n onChange: (_files: File[] | null) => {\n let all = [...((value || [])), ...(_files || [])]\n if (all.length > maxFileLimits) {\n setError({\n message: `You can upload maximum ${maxFileLimits} files.`,\n file: null as any\n });\n setTimeout(() => setError(null), 4000);\n all = all.slice(0, 10);\n }\n if (onSelect && _files) onSelect(_files, value || [])\n onChange && onChange(all);\n },\n onError: (err: FilePickerError) => {\n setError(err);\n onError && onError(err)\n setTimeout(() => setError(null), 4000);\n },\n }\n\n if (value && value.length > 0) {\n return (\n <Stack gap={2}>\n {error && <Alert\n variant={\"fill\"}\n color=\"danger\"\n mb={2}\n icon={<Box\n component={\"img\"}\n src={URL.createObjectURL(error.file)}\n />}\n >\n {error.message}\n </Alert>}\n <Stack direction=\"row\" gap={1} flexWrap=\"wrap\">\n {value.map((file, index) => (\n <FileCard\n key={index}\n file={file}\n onRemove={() => {\n const newFiles = value.filter((_, i) => i !== index);\n onDelete && onDelete(file)\n onChange && onChange(newFiles.length > 0 ? newFiles : null);\n }}\n />\n ))}\n <Stack\n width={100}\n height={100}\n bgcolor=\"surface.light\"\n radius={1}\n alignItems=\"center\"\n overflow={\"hidden\"}\n border=\"1px solid\"\n borderColor='surface.divider'\n >\n <FilePicker\n {...filePickerProps}\n alignItems=\"center\"\n justifyContent=\"center\"\n width={\"100%\"}\n flex={1}\n cursor={\"pointer\"}\n borderBottom={\"1px solid\"}\n borderColor=\"surface.divider\"\n sx={{\n '& svg': {\n opacity: 0.6,\n },\n \"&:hover svg\": {\n opacity: 1,\n }\n }}\n >\n <AddPhotoAlternateOutlined fontSize={28} color=\"surface.muted\" />\n </FilePicker>\n <Button\n size=\"small\"\n variant={\"text\"}\n onClick={() => onChange && onChange(null)}\n sx={{\n height: 28,\n }}\n >CLEAR</Button>\n </Stack>\n </Stack>\n\n </Stack>\n )\n }\n return (\n <Tag\n {...props}\n baseClass='gallery-picker'\n ref={ref}\n sxr={{\n display: \"flex\"\n }}\n >\n {error && <Alert\n {...slotProps?.alert}\n variant={\"fill\"}\n color=\"danger\"\n mb={2}\n icon={<Box\n component={\"img\"}\n src={URL.createObjectURL(error.file)}\n />}\n >\n {error.message}\n </Alert>}\n <FilePicker\n {...filePickerProps}\n width=\"100%\"\n border=\"1px dashed\"\n borderColor='surface.divider'\n radius={2}\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n <Tag\n {...slotProps?.content}\n baseClass='gallery-picker-content'\n sxr={{\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n p: 4,\n }}\n >\n <Tag mb={2}>\n {(icon as any) || <AddPhotoAlternateOutlined fontSize={38} color=\"surface.muted\" />}\n </Tag>\n <Text>{(title as any) || \"Drag & drop images here or click to upload.\"}</Text>\n <Text variant=\"button\" color=\"surface.muted\">\n {\n (subtitle as any) || `Images only · Max ${filePickerProps.maxFileSize / 1024}MB each · Up to ${filePickerProps.maxFileLimits} files.`\n }\n </Text>\n </Tag>\n </FilePicker>\n </Tag>\n )\n})\n\nexport default GalleryPicker"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAcA;AACG;;AAgBY;AACA;AACA;;AAUA;AACA;AACA;;AAKf;AAsBA;;;;;;AAMI;AAED;AACA;AACA;AAEA;;AAEA;AAKG;AAEG;AACA;AACG;;AAEG;AACF;;;;;AAIoB;AACxB;AACH;;AAGG;;AAEH;;AAIA;AAmBkB;AACA;AACA;AACH;AAuBG;AACG;AACF;AACD;AACG;AACF;AACH;AASE;AACF;;AAQnB;AAMS;;AA4BM;AACA;AACA;AACA;;AAgBlB;;"}
|