@xanui/ui 1.1.63 → 1.1.65
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/Alert/index.cjs +86 -23
- package/Alert/index.cjs.map +1 -1
- package/Alert/index.d.ts +27 -6
- package/Alert/index.js +87 -24
- package/Alert/index.js.map +1 -1
- package/DataFilter/options/NumberFilter.cjs.map +1 -1
- package/DataFilter/options/NumberFilter.js.map +1 -1
- package/InputNumber/index.cjs +25 -21
- package/InputNumber/index.cjs.map +1 -1
- package/InputNumber/index.d.ts +1 -1
- package/InputNumber/index.js +26 -22
- package/InputNumber/index.js.map +1 -1
- package/Layer/index.cjs +7 -6
- package/Layer/index.cjs.map +1 -1
- package/Layer/index.d.ts +7 -3
- package/Layer/index.js +7 -6
- package/Layer/index.js.map +1 -1
- package/Modal/index.cjs +26 -31
- package/Modal/index.cjs.map +1 -1
- package/Modal/index.d.ts +10 -6
- package/Modal/index.js +27 -32
- package/Modal/index.js.map +1 -1
- package/package.json +2 -2
- package/useAlert/index.cjs +0 -94
- package/useAlert/index.cjs.map +0 -1
- package/useAlert/index.d.ts +0 -36
- package/useAlert/index.js +0 -92
- package/useAlert/index.js.map +0 -1
- package/useLayer/index.cjs +0 -38
- package/useLayer/index.cjs.map +0 -1
- package/useLayer/index.d.ts +0 -10
- package/useLayer/index.js +0 -36
- package/useLayer/index.js.map +0 -1
- package/useModal/index.cjs +0 -37
- package/useModal/index.cjs.map +0 -1
- package/useModal/index.d.ts +0 -12
- package/useModal/index.js +0 -35
- package/useModal/index.js.map +0 -1
package/InputNumber/index.js
CHANGED
|
@@ -1,47 +1,51 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import React, {
|
|
3
|
+
import React, { useRef } from 'react';
|
|
4
4
|
import Input from '../Input/index.js';
|
|
5
5
|
import UnfoldMore from '@xanui/icons/UnfoldMore';
|
|
6
6
|
import { useMergeRefs } from '@xanui/core';
|
|
7
7
|
|
|
8
8
|
const InputNumber = React.forwardRef((props, ref) => {
|
|
9
9
|
var _a;
|
|
10
|
-
const [_val, setVal] = useState((_a = props.value) !== null && _a !== void 0 ? _a : "");
|
|
11
10
|
const inputRef = useRef(null);
|
|
12
11
|
const mergeRef = useMergeRefs(inputRef, ref);
|
|
13
|
-
|
|
14
|
-
if (inputRef.current && (props === null || props === void 0 ? void 0 : props.onChange)) {
|
|
15
|
-
let valstr = String(_val);
|
|
16
|
-
inputRef.current.value = valstr.includes(".") ? parseFloat(_val) : parseInt(_val);
|
|
17
|
-
const syntheticEvent = {
|
|
18
|
-
target: inputRef.current,
|
|
19
|
-
currentTarget: inputRef.current,
|
|
20
|
-
};
|
|
21
|
-
props === null || props === void 0 ? void 0 : props.onChange(syntheticEvent);
|
|
22
|
-
}
|
|
23
|
-
}, [_val]);
|
|
24
|
-
const isNumeric = _val === undefined || _val === '' || !isNaN(Number(_val));
|
|
12
|
+
const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));
|
|
25
13
|
const errorProps = {};
|
|
26
14
|
if (!isNumeric) {
|
|
27
15
|
errorProps.error = true;
|
|
28
16
|
errorProps.helperText = "Value must be numeric";
|
|
29
17
|
}
|
|
30
|
-
return (jsx(Input, Object.assign({}, props, errorProps, { ref: mergeRef, endIcon: jsx(UnfoldMore, {}), value:
|
|
18
|
+
return (jsx(Input, Object.assign({}, props, errorProps, { ref: mergeRef, endIcon: jsx(UnfoldMore, {}), value: (_a = props.value) !== null && _a !== void 0 ? _a : "", onKeyDown: (e) => {
|
|
31
19
|
var _a;
|
|
32
20
|
(_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
33
21
|
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
|
|
34
22
|
return;
|
|
35
23
|
e.preventDefault();
|
|
36
|
-
const current = parseFloat(
|
|
37
|
-
|
|
24
|
+
const current = parseFloat(props.value) || 0;
|
|
25
|
+
e.target.value = e.key === 'ArrowUp' ? current + 1 : current - 1;
|
|
26
|
+
(props === null || props === void 0 ? void 0 : props.onChange) && (props === null || props === void 0 ? void 0 : props.onChange(e));
|
|
27
|
+
}, onBlur: (e) => {
|
|
28
|
+
var _a;
|
|
29
|
+
const raw = e.target.value;
|
|
30
|
+
if (raw === "" || raw === ".")
|
|
31
|
+
return;
|
|
32
|
+
const num = parseFloat(raw);
|
|
33
|
+
if (!Number.isNaN(num)) {
|
|
34
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, Object.assign(Object.assign({}, e), { target: Object.assign(Object.assign({}, e.target), { value: num }) }));
|
|
35
|
+
}
|
|
38
36
|
}, onChange: (e) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
37
|
+
var _a, _b;
|
|
38
|
+
let value = e.target.value;
|
|
39
|
+
if (value === "") {
|
|
40
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
41
|
+
return;
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
if (!/^\d*\.?\d*$/.test(value))
|
|
44
|
+
return;
|
|
45
|
+
if (value === ".")
|
|
46
|
+
value = "0.";
|
|
47
|
+
const nextEvent = Object.assign(Object.assign({}, e), { target: Object.assign(Object.assign({}, e.target), { value }) });
|
|
48
|
+
(_b = props === null || props === void 0 ? void 0 : props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, nextEvent);
|
|
45
49
|
} })));
|
|
46
50
|
});
|
|
47
51
|
|
package/InputNumber/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React, {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React, { useRef } from 'react'\nimport Input, { InputProps } from '../Input'\nimport UnfoldMore from '@xanui/icons/UnfoldMore'\nimport { useMergeRefs } from '@xanui/core'\n\nexport type InputNumberProps = Omit<InputProps, \"value\"> & {\n value?: number | \"\";\n}\n\nconst InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {\n const inputRef = useRef<any>(null)\n const mergeRef = useMergeRefs(inputRef, ref)\n const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));\n const errorProps: Partial<InputProps> = {};\n if (!isNumeric) {\n errorProps.error = true;\n errorProps.helperText = \"Value must be numeric\";\n }\n\n return (\n <Input\n {...props}\n {...errorProps}\n ref={mergeRef}\n endIcon={<UnfoldMore />}\n value={props.value ?? \"\" as any}\n onKeyDown={(e: any) => {\n props.onKeyDown?.(e);\n if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown') return;\n e.preventDefault();\n const current = parseFloat(props.value as any) || 0;\n e.target.value = e.key === 'ArrowUp' ? current + 1 : current - 1 as any\n props?.onChange && props?.onChange(e)\n\n }}\n onBlur={(e) => {\n const raw = e.target.value\n if (raw === \"\" || raw === \".\") return\n const num = parseFloat(raw)\n if (!Number.isNaN(num)) {\n props?.onChange?.({\n ...e,\n target: { ...e.target, value: num },\n } as any)\n }\n }}\n\n onChange={(e) => {\n let value = e.target.value\n if (value === \"\") {\n props?.onChange?.(e)\n return\n }\n\n if (!/^\\d*\\.?\\d*$/.test(value)) return\n\n if (value === \".\") value = \"0.\"\n const nextEvent = {\n ...e,\n target: {\n ...e.target,\n value,\n },\n }\n\n props?.onChange?.(nextEvent as any)\n }}\n\n />\n );\n});\n\nexport default InputNumber;\n"],"names":[],"mappings":";;;;;;;AAUA;;AACG;;;;;AAKG;AACA;;AAGH;;AAQS;;;;;;AAKA;AAEH;;AAEG;AACA;;AACA;;;;AAOH;;AAGG;AACA;;;;AAKA;;;;AAGA;;;AAaZ;;"}
|
package/Layer/index.cjs
CHANGED
|
@@ -38,9 +38,13 @@ const Layer = (_a) => {
|
|
|
38
38
|
}, children: children }));
|
|
39
39
|
return (jsxRuntime.jsx(core.Transition, { duration: duration, delay: delay, easing: "smooth", variant: "fade", open: open, children: jsxRuntime.jsx(core.Tag, Object.assign({ baseClass: "layer" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.root, { sxr: Object.assign(Object.assign(Object.assign({}, (_d = slotProps === null || slotProps === void 0 ? void 0 : slotProps.root) === null || _d === void 0 ? void 0 : _d.sx), { position: "fixed", zIndex: 1500 + (zIndex || 0), top: 0, left: 0, bottom: 0, right: 0, width: "100%", height: "100%" }), blurCss), children: onClickOutside ? jsxRuntime.jsx(index$1, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.clickOutside, { onClickOutside: onClickOutside || (() => { }), children: content })) : content })) }));
|
|
40
40
|
};
|
|
41
|
-
Layer.open = (
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
Layer.open = (Children, props) => {
|
|
42
|
+
const InstanceLayer = (_a) => {
|
|
43
|
+
var { children } = _a, props = tslib.__rest(_a, ["children"]);
|
|
44
|
+
return jsxRuntime.jsx(Layer, Object.assign({}, props, { children: children }));
|
|
45
|
+
};
|
|
46
|
+
const l = core.Renderar.render(InstanceLayer, Object.assign(Object.assign({}, props), { open: true, children: typeof Children === "function" ? jsxRuntime.jsx(Children, { open: () => l.updateProps({ open: true }), close: () => l.updateProps({ open: false }) }) : Children, onClosed: () => {
|
|
47
|
+
core.Renderar.unrender(InstanceLayer);
|
|
44
48
|
if (props === null || props === void 0 ? void 0 : props.onClosed) {
|
|
45
49
|
props.onClosed();
|
|
46
50
|
}
|
|
@@ -54,9 +58,6 @@ Layer.open = (children, props) => {
|
|
|
54
58
|
},
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
|
-
Layer.close = () => {
|
|
58
|
-
core.Renderar.unrender(Layer);
|
|
59
|
-
};
|
|
60
61
|
|
|
61
62
|
module.exports = Layer;
|
|
62
63
|
//# sourceMappingURL=index.cjs.map
|
package/Layer/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Layer/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode, useEffect, useState } from 'react'\nimport { Tag, TagProps, useBreakpointProps, useBreakpointPropsType, useInterface, TransitionProps, Transition } from \"@xanui/core\"\nimport useBlurCss from '../useBlurCss';\nimport { Renderar } from \"@xanui/core\";\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\nexport type LayerProps = {\n open: boolean;\n children: ReactNode;\n transition?: TransitionProps['variant'];\n zIndex?: number;\n blur?: useBreakpointPropsType<number>\n blurMode?: useBreakpointPropsType<\"blur\" | \"transparent\">\n onClickOutside?: () => void;\n onOpen?: Function;\n onOpened?: Function;\n onClose?: Function;\n onClosed?: Function;\n slotProps?: {\n root?: Omit<TagProps<\"div\">, \"children\">;\n transition?: Omit<TransitionProps, \"children\" | \"open\" | \"variant\" | \"onClose\" | \"onClosed\" | \"onOpen\" | \"onOpened\">;\n content?: Omit<TagProps<\"div\">, \"children\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nconst Layer = ({ children, open, ...props }: LayerProps) => {\n let [{\n onClickOutside,\n placement,\n transition,\n zIndex,\n blur,\n blurMode,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n slotProps\n }] = useInterface<any>(\"Layer\", props, {})\n\n const _p: any = {}\n if (blur) _p.blur = blur\n if (blurMode) _p.blurMode = blurMode\n const p: any = useBreakpointProps(_p)\n\n blur = p.blur\n blurMode = p.blurMode\n\n const [closed, setClosed] = useState(!open)\n placement = placement || \"bottom-left\"\n const blurCss = blur ? useBlurCss(blur, blurMode) : {}\n\n useEffect(() => {\n if (closed && open) {\n setClosed(false)\n }\n }, [open])\n\n if (closed) return <></>\n let duration = slotProps?.transition?.duration || 300\n let delay = slotProps?.transition?.delay || 0\n\n let content = <Transition\n duration={duration}\n delay={delay}\n easing=\"standard\"\n variant={transition || \"zoomOver\"}\n {...slotProps?.transition}\n open={open}\n onOpen={onOpen}\n onOpened={onOpened}\n onClose={onClose}\n onClosed={() => {\n setClosed(true)\n onClosed && onClosed()\n }}\n >\n {children}\n </Transition>\n\n return (\n <Transition\n duration={duration}\n delay={delay}\n easing=\"smooth\"\n variant={\"fade\"}\n open={open}\n >\n <Tag\n baseClass=\"layer\"\n {...slotProps?.root}\n sxr={{\n ...slotProps?.root?.sx,\n position: \"fixed\",\n zIndex: 1500 + (zIndex || 0),\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n width: \"100%\",\n height: \"100%\",\n ...blurCss\n }}\n >\n {\n onClickOutside ? <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n {content}\n </ClickOutside> : content\n }\n </Tag>\n </Transition>\n )\n}\n\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Layer/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode, useEffect, useState } from 'react'\nimport { Tag, TagProps, useBreakpointProps, useBreakpointPropsType, useInterface, TransitionProps, Transition } from \"@xanui/core\"\nimport useBlurCss from '../useBlurCss';\nimport { Renderar } from \"@xanui/core\";\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\nexport type LayerProps = {\n open: boolean;\n children: ReactNode;\n transition?: TransitionProps['variant'];\n zIndex?: number;\n blur?: useBreakpointPropsType<number>\n blurMode?: useBreakpointPropsType<\"blur\" | \"transparent\">\n onClickOutside?: () => void;\n onOpen?: Function;\n onOpened?: Function;\n onClose?: Function;\n onClosed?: Function;\n slotProps?: {\n root?: Omit<TagProps<\"div\">, \"children\">;\n transition?: Omit<TransitionProps, \"children\" | \"open\" | \"variant\" | \"onClose\" | \"onClosed\" | \"onOpen\" | \"onOpened\">;\n content?: Omit<TagProps<\"div\">, \"children\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nexport type ActionLayerFunctionChildreProps = {\n open: Function,\n close: Function\n}\nexport type ActionLayerChildren = ReactNode | ((props: ActionLayerFunctionChildreProps) => ReactNode)\n\nconst Layer = ({ children, open, ...props }: LayerProps) => {\n let [{\n onClickOutside,\n placement,\n transition,\n zIndex,\n blur,\n blurMode,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n slotProps\n }] = useInterface<any>(\"Layer\", props, {})\n\n const _p: any = {}\n if (blur) _p.blur = blur\n if (blurMode) _p.blurMode = blurMode\n const p: any = useBreakpointProps(_p)\n\n blur = p.blur\n blurMode = p.blurMode\n\n const [closed, setClosed] = useState(!open)\n placement = placement || \"bottom-left\"\n const blurCss = blur ? useBlurCss(blur, blurMode) : {}\n\n useEffect(() => {\n if (closed && open) {\n setClosed(false)\n }\n }, [open])\n\n if (closed) return <></>\n let duration = slotProps?.transition?.duration || 300\n let delay = slotProps?.transition?.delay || 0\n\n let content = <Transition\n duration={duration}\n delay={delay}\n easing=\"standard\"\n variant={transition || \"zoomOver\"}\n {...slotProps?.transition}\n open={open}\n onOpen={onOpen}\n onOpened={onOpened}\n onClose={onClose}\n onClosed={() => {\n setClosed(true)\n onClosed && onClosed()\n }}\n >\n {children}\n </Transition>\n\n return (\n <Transition\n duration={duration}\n delay={delay}\n easing=\"smooth\"\n variant={\"fade\"}\n open={open}\n >\n <Tag\n baseClass=\"layer\"\n {...slotProps?.root}\n sxr={{\n ...slotProps?.root?.sx,\n position: \"fixed\",\n zIndex: 1500 + (zIndex || 0),\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n width: \"100%\",\n height: \"100%\",\n ...blurCss\n }}\n >\n {\n onClickOutside ? <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n {content}\n </ClickOutside> : content\n }\n </Tag>\n </Transition>\n )\n}\n\nLayer.open = (Children: ActionLayerChildren, props?: Partial<Omit<LayerProps, 'children'>>) => {\n const InstanceLayer = ({ children, ...props }: LayerProps) => <Layer {...props} >{children}</Layer>;\n const l = Renderar.render(InstanceLayer as any, {\n ...props,\n open: true,\n children: typeof Children === \"function\" ? <Children\n open={() => l.updateProps({ open: true })}\n close={() => l.updateProps({ open: false })}\n /> : Children,\n onClosed: () => {\n Renderar.unrender(InstanceLayer as any)\n if (props?.onClosed) {\n props.onClosed()\n }\n }\n })\n return {\n open: () => {\n l.updateProps({ open: true })\n },\n close: () => {\n l.updateProps({ open: false })\n },\n }\n}\n\nexport default Layer"],"names":[],"mappings":";;;;;;;;;;AAiCA;;;AACI;;AAeA;AAAU;AACV;AAAc;AACd;AAEA;AACA;;AAGA;AACA;;AAGI;;;AAGJ;AAEA;AAAY;AACZ;AACA;;;;;AAoBA;AAmCJ;AAEA;AACI;AAAuB;AAAuC;;AAC9D;AAQQ;;;;AAIJ;;;;;;;;;AAUR;;"}
|
package/Layer/index.d.ts
CHANGED
|
@@ -22,14 +22,18 @@ type LayerProps = {
|
|
|
22
22
|
clickOutside?: Omit<ClickOutsideProps, "children" | "onClickOutside">;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
type ActionLayerFunctionChildreProps = {
|
|
26
|
+
open: Function;
|
|
27
|
+
close: Function;
|
|
28
|
+
};
|
|
29
|
+
type ActionLayerChildren = ReactNode | ((props: ActionLayerFunctionChildreProps) => ReactNode);
|
|
25
30
|
declare const Layer: {
|
|
26
31
|
({ children, open, ...props }: LayerProps): react_jsx_runtime.JSX.Element;
|
|
27
|
-
open(
|
|
32
|
+
open(Children: ActionLayerChildren, props?: Partial<Omit<LayerProps, "children">>): {
|
|
28
33
|
open: () => void;
|
|
29
34
|
close: () => void;
|
|
30
35
|
};
|
|
31
|
-
close(): void;
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
export { Layer as default };
|
|
35
|
-
export type { LayerProps };
|
|
39
|
+
export type { ActionLayerChildren, ActionLayerFunctionChildreProps, LayerProps };
|
package/Layer/index.js
CHANGED
|
@@ -36,9 +36,13 @@ const Layer = (_a) => {
|
|
|
36
36
|
}, children: children }));
|
|
37
37
|
return (jsx(Transition, { duration: duration, delay: delay, easing: "smooth", variant: "fade", open: open, children: jsx(Tag, Object.assign({ baseClass: "layer" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.root, { sxr: Object.assign(Object.assign(Object.assign({}, (_d = slotProps === null || slotProps === void 0 ? void 0 : slotProps.root) === null || _d === void 0 ? void 0 : _d.sx), { position: "fixed", zIndex: 1500 + (zIndex || 0), top: 0, left: 0, bottom: 0, right: 0, width: "100%", height: "100%" }), blurCss), children: onClickOutside ? jsx(ClickOutside, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.clickOutside, { onClickOutside: onClickOutside || (() => { }), children: content })) : content })) }));
|
|
38
38
|
};
|
|
39
|
-
Layer.open = (
|
|
40
|
-
const
|
|
41
|
-
|
|
39
|
+
Layer.open = (Children, props) => {
|
|
40
|
+
const InstanceLayer = (_a) => {
|
|
41
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
42
|
+
return jsx(Layer, Object.assign({}, props, { children: children }));
|
|
43
|
+
};
|
|
44
|
+
const l = Renderar.render(InstanceLayer, Object.assign(Object.assign({}, props), { open: true, children: typeof Children === "function" ? jsx(Children, { open: () => l.updateProps({ open: true }), close: () => l.updateProps({ open: false }) }) : Children, onClosed: () => {
|
|
45
|
+
Renderar.unrender(InstanceLayer);
|
|
42
46
|
if (props === null || props === void 0 ? void 0 : props.onClosed) {
|
|
43
47
|
props.onClosed();
|
|
44
48
|
}
|
|
@@ -52,9 +56,6 @@ Layer.open = (children, props) => {
|
|
|
52
56
|
},
|
|
53
57
|
};
|
|
54
58
|
};
|
|
55
|
-
Layer.close = () => {
|
|
56
|
-
Renderar.unrender(Layer);
|
|
57
|
-
};
|
|
58
59
|
|
|
59
60
|
export { Layer as default };
|
|
60
61
|
//# sourceMappingURL=index.js.map
|
package/Layer/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Layer/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode, useEffect, useState } from 'react'\nimport { Tag, TagProps, useBreakpointProps, useBreakpointPropsType, useInterface, TransitionProps, Transition } from \"@xanui/core\"\nimport useBlurCss from '../useBlurCss';\nimport { Renderar } from \"@xanui/core\";\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\nexport type LayerProps = {\n open: boolean;\n children: ReactNode;\n transition?: TransitionProps['variant'];\n zIndex?: number;\n blur?: useBreakpointPropsType<number>\n blurMode?: useBreakpointPropsType<\"blur\" | \"transparent\">\n onClickOutside?: () => void;\n onOpen?: Function;\n onOpened?: Function;\n onClose?: Function;\n onClosed?: Function;\n slotProps?: {\n root?: Omit<TagProps<\"div\">, \"children\">;\n transition?: Omit<TransitionProps, \"children\" | \"open\" | \"variant\" | \"onClose\" | \"onClosed\" | \"onOpen\" | \"onOpened\">;\n content?: Omit<TagProps<\"div\">, \"children\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nconst Layer = ({ children, open, ...props }: LayerProps) => {\n let [{\n onClickOutside,\n placement,\n transition,\n zIndex,\n blur,\n blurMode,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n slotProps\n }] = useInterface<any>(\"Layer\", props, {})\n\n const _p: any = {}\n if (blur) _p.blur = blur\n if (blurMode) _p.blurMode = blurMode\n const p: any = useBreakpointProps(_p)\n\n blur = p.blur\n blurMode = p.blurMode\n\n const [closed, setClosed] = useState(!open)\n placement = placement || \"bottom-left\"\n const blurCss = blur ? useBlurCss(blur, blurMode) : {}\n\n useEffect(() => {\n if (closed && open) {\n setClosed(false)\n }\n }, [open])\n\n if (closed) return <></>\n let duration = slotProps?.transition?.duration || 300\n let delay = slotProps?.transition?.delay || 0\n\n let content = <Transition\n duration={duration}\n delay={delay}\n easing=\"standard\"\n variant={transition || \"zoomOver\"}\n {...slotProps?.transition}\n open={open}\n onOpen={onOpen}\n onOpened={onOpened}\n onClose={onClose}\n onClosed={() => {\n setClosed(true)\n onClosed && onClosed()\n }}\n >\n {children}\n </Transition>\n\n return (\n <Transition\n duration={duration}\n delay={delay}\n easing=\"smooth\"\n variant={\"fade\"}\n open={open}\n >\n <Tag\n baseClass=\"layer\"\n {...slotProps?.root}\n sxr={{\n ...slotProps?.root?.sx,\n position: \"fixed\",\n zIndex: 1500 + (zIndex || 0),\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n width: \"100%\",\n height: \"100%\",\n ...blurCss\n }}\n >\n {\n onClickOutside ? <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n {content}\n </ClickOutside> : content\n }\n </Tag>\n </Transition>\n )\n}\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Layer/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode, useEffect, useState } from 'react'\nimport { Tag, TagProps, useBreakpointProps, useBreakpointPropsType, useInterface, TransitionProps, Transition } from \"@xanui/core\"\nimport useBlurCss from '../useBlurCss';\nimport { Renderar } from \"@xanui/core\";\nimport ClickOutside, { ClickOutsideProps } from '../ClickOutside';\n\nexport type LayerProps = {\n open: boolean;\n children: ReactNode;\n transition?: TransitionProps['variant'];\n zIndex?: number;\n blur?: useBreakpointPropsType<number>\n blurMode?: useBreakpointPropsType<\"blur\" | \"transparent\">\n onClickOutside?: () => void;\n onOpen?: Function;\n onOpened?: Function;\n onClose?: Function;\n onClosed?: Function;\n slotProps?: {\n root?: Omit<TagProps<\"div\">, \"children\">;\n transition?: Omit<TransitionProps, \"children\" | \"open\" | \"variant\" | \"onClose\" | \"onClosed\" | \"onOpen\" | \"onOpened\">;\n content?: Omit<TagProps<\"div\">, \"children\">;\n clickOutside?: Omit<ClickOutsideProps, \"children\" | \"onClickOutside\">;\n }\n}\n\nexport type ActionLayerFunctionChildreProps = {\n open: Function,\n close: Function\n}\nexport type ActionLayerChildren = ReactNode | ((props: ActionLayerFunctionChildreProps) => ReactNode)\n\nconst Layer = ({ children, open, ...props }: LayerProps) => {\n let [{\n onClickOutside,\n placement,\n transition,\n zIndex,\n blur,\n blurMode,\n onOpen,\n onOpened,\n onClose,\n onClosed,\n slotProps\n }] = useInterface<any>(\"Layer\", props, {})\n\n const _p: any = {}\n if (blur) _p.blur = blur\n if (blurMode) _p.blurMode = blurMode\n const p: any = useBreakpointProps(_p)\n\n blur = p.blur\n blurMode = p.blurMode\n\n const [closed, setClosed] = useState(!open)\n placement = placement || \"bottom-left\"\n const blurCss = blur ? useBlurCss(blur, blurMode) : {}\n\n useEffect(() => {\n if (closed && open) {\n setClosed(false)\n }\n }, [open])\n\n if (closed) return <></>\n let duration = slotProps?.transition?.duration || 300\n let delay = slotProps?.transition?.delay || 0\n\n let content = <Transition\n duration={duration}\n delay={delay}\n easing=\"standard\"\n variant={transition || \"zoomOver\"}\n {...slotProps?.transition}\n open={open}\n onOpen={onOpen}\n onOpened={onOpened}\n onClose={onClose}\n onClosed={() => {\n setClosed(true)\n onClosed && onClosed()\n }}\n >\n {children}\n </Transition>\n\n return (\n <Transition\n duration={duration}\n delay={delay}\n easing=\"smooth\"\n variant={\"fade\"}\n open={open}\n >\n <Tag\n baseClass=\"layer\"\n {...slotProps?.root}\n sxr={{\n ...slotProps?.root?.sx,\n position: \"fixed\",\n zIndex: 1500 + (zIndex || 0),\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n width: \"100%\",\n height: \"100%\",\n ...blurCss\n }}\n >\n {\n onClickOutside ? <ClickOutside\n {...slotProps?.clickOutside}\n onClickOutside={onClickOutside || (() => { })}\n >\n {content}\n </ClickOutside> : content\n }\n </Tag>\n </Transition>\n )\n}\n\nLayer.open = (Children: ActionLayerChildren, props?: Partial<Omit<LayerProps, 'children'>>) => {\n const InstanceLayer = ({ children, ...props }: LayerProps) => <Layer {...props} >{children}</Layer>;\n const l = Renderar.render(InstanceLayer as any, {\n ...props,\n open: true,\n children: typeof Children === \"function\" ? <Children\n open={() => l.updateProps({ open: true })}\n close={() => l.updateProps({ open: false })}\n /> : Children,\n onClosed: () => {\n Renderar.unrender(InstanceLayer as any)\n if (props?.onClosed) {\n props.onClosed()\n }\n }\n })\n return {\n open: () => {\n l.updateProps({ open: true })\n },\n close: () => {\n l.updateProps({ open: false })\n },\n }\n}\n\nexport default Layer"],"names":[],"mappings":";;;;;;;;AAiCA;;;AACI;;AAeA;AAAU;AACV;AAAc;AACd;AAEA;AACA;;AAGA;AACA;;AAGI;;;AAGJ;AAEA;AAAY;AACZ;AACA;;;;;AAoBA;AAmCJ;AAEA;AACI;AAAuB;AAAuC;;AAC9D;AAQQ;;;;AAIJ;;;;;;;;;AAUR;;"}
|
package/Modal/index.cjs
CHANGED
|
@@ -3,40 +3,38 @@
|
|
|
3
3
|
|
|
4
4
|
var tslib = require('tslib');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
var React = require('react');
|
|
7
|
-
var index = require('../useModal/index.cjs');
|
|
8
6
|
var core = require('@xanui/core');
|
|
7
|
+
var index = require('../Layer/index.cjs');
|
|
9
8
|
|
|
10
|
-
const Modal = (
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const Modal = (props) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
let sizes = {
|
|
12
|
+
xs: 420,
|
|
13
|
+
sm: 760,
|
|
14
|
+
md: 990,
|
|
15
|
+
lg: 1120,
|
|
16
|
+
xl: 1300,
|
|
17
|
+
full: "100%"
|
|
18
|
+
};
|
|
19
|
+
let _c = props || {}, { children, onOpen, size, slotProps } = _c, layerProps = tslib.__rest(_c, ["children", "onOpen", "size", "slotProps"]);
|
|
20
|
+
size = size !== null && size !== void 0 ? size : "xs";
|
|
21
|
+
slotProps = slotProps || {};
|
|
22
|
+
const root = (slotProps === null || slotProps === void 0 ? void 0 : slotProps.root) || {};
|
|
23
|
+
return (jsxRuntime.jsx(index, Object.assign({}, layerProps, { slotProps: Object.assign(Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.layer), { clickOutside: Object.assign({ maxWidth: sizes[size] || size, width: "100%" }, (_a = slotProps === null || slotProps === void 0 ? void 0 : slotProps.layer) === null || _a === void 0 ? void 0 : _a.clickOutside), root: Object.assign({ display: "flex", alignItems: 'center', justifyContent: "center" }, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.layer) === null || _b === void 0 ? void 0 : _b.root) }), children: jsxRuntime.jsx(core.Tag, Object.assign({}, root, { sxr: Object.assign({ maxWidth: sizes[size] || size, width: "100%", radius: 2, bgcolor: "background.primary", shadow: 15 }, root === null || root === void 0 ? void 0 : root.sx), baseClass: 'modal', children: children })) })));
|
|
24
|
+
};
|
|
25
|
+
Modal.open = (Children, props) => {
|
|
26
|
+
const InstanceModal = (_a) => {
|
|
27
|
+
var { children } = _a, props = tslib.__rest(_a, ["children"]);
|
|
28
|
+
return jsxRuntime.jsx(Modal, Object.assign({}, props, { children: children }));
|
|
29
|
+
};
|
|
30
|
+
const m = core.Renderar.render(InstanceModal, Object.assign(Object.assign({ open: true, children: typeof Children === "function" ? jsxRuntime.jsx(Children, { open: () => m.updateProps({ open: true }), close: () => m.updateProps({ open: false }) }) : Children }, props), { onClickOutside: () => {
|
|
14
31
|
if (props === null || props === void 0 ? void 0 : props.onClickOutside) {
|
|
15
32
|
props.onClickOutside();
|
|
16
33
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
portal: {
|
|
20
|
-
container: (ref === null || ref === void 0 ? void 0 : ref.current) || undefined
|
|
21
|
-
}
|
|
34
|
+
else {
|
|
35
|
+
m.updateProps({ open: false });
|
|
22
36
|
}
|
|
23
|
-
}
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
if (open) {
|
|
26
|
-
modal.open();
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
modal.close();
|
|
30
|
-
}
|
|
31
|
-
}, [open]);
|
|
32
|
-
return jsxRuntime.jsx(core.Tag, { ref: ref });
|
|
33
|
-
};
|
|
34
|
-
const ActionModal = (_a) => {
|
|
35
|
-
var { children } = _a, props = tslib.__rest(_a, ["children"]);
|
|
36
|
-
return (jsxRuntime.jsx(Modal, Object.assign({}, props, { children: children })));
|
|
37
|
-
};
|
|
38
|
-
Modal.open = (children, props) => {
|
|
39
|
-
const m = core.Renderar.render(ActionModal, Object.assign(Object.assign({ open: true }, props), { children, onClosed: () => {
|
|
37
|
+
}, onClosed: () => {
|
|
40
38
|
m.unrender();
|
|
41
39
|
if (props === null || props === void 0 ? void 0 : props.onClosed) {
|
|
42
40
|
props.onClosed();
|
|
@@ -51,9 +49,6 @@ Modal.open = (children, props) => {
|
|
|
51
49
|
},
|
|
52
50
|
};
|
|
53
51
|
};
|
|
54
|
-
Modal.close = () => {
|
|
55
|
-
core.Renderar.unrender(ActionModal);
|
|
56
|
-
};
|
|
57
52
|
|
|
58
53
|
module.exports = Modal;
|
|
59
54
|
//# sourceMappingURL=index.cjs.map
|
package/Modal/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Modal/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Modal/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode } from \"react\";\n// import useModal, { UseModalProps } from \"../useModal\";\nimport { Renderar, Tag, TagProps } from \"@xanui/core\";\nimport Layer, { ActionLayerChildren, LayerProps } from \"../Layer\";\n\nexport type ModalProps = Omit<LayerProps, \"slotProps\"> & {\n children: ReactNode;\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\" | \"full\" | number;\n slotProps?: {\n layer?: LayerProps['slotProps'];\n root?: Omit<TagProps<'div'>, \"children\">\n }\n}\n\n\nconst Modal = (props: ModalProps) => {\n let sizes: any = {\n xs: 420,\n sm: 760,\n md: 990,\n lg: 1120,\n xl: 1300,\n full: \"100%\"\n }\n let { children, onOpen, size, slotProps, ...layerProps } = props || {}\n size = size ?? \"xs\"\n slotProps = slotProps || {} as any\n const root: any = slotProps?.root || {}\n\n return (\n <Layer\n {...layerProps}\n slotProps={{\n ...slotProps?.layer,\n clickOutside: {\n maxWidth: sizes[size as any] || size,\n width: \"100%\",\n ...slotProps?.layer?.clickOutside,\n },\n root: {\n display: \"flex\",\n alignItems: 'center',\n justifyContent: \"center\",\n ...slotProps?.layer?.root,\n }\n }}\n >\n <Tag\n {...root}\n sxr={{\n maxWidth: sizes[size as any] || size,\n width: \"100%\",\n radius: 2,\n bgcolor: \"background.primary\",\n shadow: 15,\n ...root?.sx\n }}\n baseClass='modal'\n >\n {children}\n </Tag>\n </Layer>\n )\n}\n\nModal.open = (Children: ActionLayerChildren, props?: Omit<ModalProps, 'children' | \"open\">) => {\n const InstanceModal = ({ children, ...props }: ModalProps) => <Modal {...props} >{children}</Modal>;\n const m = Renderar.render(InstanceModal as any, {\n open: true,\n children: typeof Children === \"function\" ? <Children\n open={() => m.updateProps({ open: true })}\n close={() => m.updateProps({ open: false })}\n /> : Children,\n ...props,\n onClickOutside: () => {\n if (props?.onClickOutside) {\n props.onClickOutside()\n } else {\n m.updateProps({ open: false })\n }\n },\n onClosed: () => {\n m.unrender()\n if (props?.onClosed) {\n props.onClosed()\n }\n }\n })\n\n return {\n open: () => {\n m.updateProps({ open: true })\n },\n close: () => {\n m.updateProps({ open: false })\n },\n }\n};\n\n\nexport default Modal;"],"names":[],"mappings":";;;;;;;;AAgBA;;AACG;AACG;AACA;AACA;AACA;AACA;AACA;;AAEH;;AAEA;AACA;;AAoCH;AAEA;AACG;AAAuB;AAAuC;;AAC9D;;;;;;;AAaG;;;;;AAMA;;;;;;;;;AAWN;;"}
|
package/Modal/index.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { TagProps } from '@xanui/core';
|
|
4
|
+
import { LayerProps, ActionLayerChildren } from '../Layer/index.js';
|
|
4
5
|
|
|
5
|
-
type ModalProps =
|
|
6
|
+
type ModalProps = Omit<LayerProps, "slotProps"> & {
|
|
6
7
|
children: ReactNode;
|
|
7
|
-
|
|
8
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | "full" | number;
|
|
9
|
+
slotProps?: {
|
|
10
|
+
layer?: LayerProps['slotProps'];
|
|
11
|
+
root?: Omit<TagProps<'div'>, "children">;
|
|
12
|
+
};
|
|
8
13
|
};
|
|
9
14
|
declare const Modal: {
|
|
10
|
-
(
|
|
11
|
-
open(
|
|
15
|
+
(props: ModalProps): react_jsx_runtime.JSX.Element;
|
|
16
|
+
open(Children: ActionLayerChildren, props?: Omit<ModalProps, "children" | "open">): {
|
|
12
17
|
open: () => void;
|
|
13
18
|
close: () => void;
|
|
14
19
|
};
|
|
15
|
-
close(): void;
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
export { Modal as default };
|
package/Modal/index.js
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { __rest } from 'tslib';
|
|
3
|
-
import { jsx
|
|
4
|
-
import { useRef, useEffect } from 'react';
|
|
5
|
-
import useModal from '../useModal/index.js';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
6
4
|
import { Tag, Renderar } from '@xanui/core';
|
|
5
|
+
import Layer from '../Layer/index.js';
|
|
7
6
|
|
|
8
|
-
const Modal = (
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const Modal = (props) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
let sizes = {
|
|
10
|
+
xs: 420,
|
|
11
|
+
sm: 760,
|
|
12
|
+
md: 990,
|
|
13
|
+
lg: 1120,
|
|
14
|
+
xl: 1300,
|
|
15
|
+
full: "100%"
|
|
16
|
+
};
|
|
17
|
+
let _c = props || {}, { children, onOpen, size, slotProps } = _c, layerProps = __rest(_c, ["children", "onOpen", "size", "slotProps"]);
|
|
18
|
+
size = size !== null && size !== void 0 ? size : "xs";
|
|
19
|
+
slotProps = slotProps || {};
|
|
20
|
+
const root = (slotProps === null || slotProps === void 0 ? void 0 : slotProps.root) || {};
|
|
21
|
+
return (jsx(Layer, Object.assign({}, layerProps, { slotProps: Object.assign(Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.layer), { clickOutside: Object.assign({ maxWidth: sizes[size] || size, width: "100%" }, (_a = slotProps === null || slotProps === void 0 ? void 0 : slotProps.layer) === null || _a === void 0 ? void 0 : _a.clickOutside), root: Object.assign({ display: "flex", alignItems: 'center', justifyContent: "center" }, (_b = slotProps === null || slotProps === void 0 ? void 0 : slotProps.layer) === null || _b === void 0 ? void 0 : _b.root) }), children: jsx(Tag, Object.assign({}, root, { sxr: Object.assign({ maxWidth: sizes[size] || size, width: "100%", radius: 2, bgcolor: "background.primary", shadow: 15 }, root === null || root === void 0 ? void 0 : root.sx), baseClass: 'modal', children: children })) })));
|
|
22
|
+
};
|
|
23
|
+
Modal.open = (Children, props) => {
|
|
24
|
+
const InstanceModal = (_a) => {
|
|
25
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
26
|
+
return jsx(Modal, Object.assign({}, props, { children: children }));
|
|
27
|
+
};
|
|
28
|
+
const m = Renderar.render(InstanceModal, Object.assign(Object.assign({ open: true, children: typeof Children === "function" ? jsx(Children, { open: () => m.updateProps({ open: true }), close: () => m.updateProps({ open: false }) }) : Children }, props), { onClickOutside: () => {
|
|
12
29
|
if (props === null || props === void 0 ? void 0 : props.onClickOutside) {
|
|
13
30
|
props.onClickOutside();
|
|
14
31
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
portal: {
|
|
18
|
-
container: (ref === null || ref === void 0 ? void 0 : ref.current) || undefined
|
|
19
|
-
}
|
|
32
|
+
else {
|
|
33
|
+
m.updateProps({ open: false });
|
|
20
34
|
}
|
|
21
|
-
}
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (open) {
|
|
24
|
-
modal.open();
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
modal.close();
|
|
28
|
-
}
|
|
29
|
-
}, [open]);
|
|
30
|
-
return jsx(Tag, { ref: ref });
|
|
31
|
-
};
|
|
32
|
-
const ActionModal = (_a) => {
|
|
33
|
-
var { children } = _a, props = __rest(_a, ["children"]);
|
|
34
|
-
return (jsx(Modal, Object.assign({}, props, { children: children })));
|
|
35
|
-
};
|
|
36
|
-
Modal.open = (children, props) => {
|
|
37
|
-
const m = Renderar.render(ActionModal, Object.assign(Object.assign({ open: true }, props), { children, onClosed: () => {
|
|
35
|
+
}, onClosed: () => {
|
|
38
36
|
m.unrender();
|
|
39
37
|
if (props === null || props === void 0 ? void 0 : props.onClosed) {
|
|
40
38
|
props.onClosed();
|
|
@@ -49,9 +47,6 @@ Modal.open = (children, props) => {
|
|
|
49
47
|
},
|
|
50
48
|
};
|
|
51
49
|
};
|
|
52
|
-
Modal.close = () => {
|
|
53
|
-
Renderar.unrender(ActionModal);
|
|
54
|
-
};
|
|
55
50
|
|
|
56
51
|
export { Modal as default };
|
|
57
52
|
//# sourceMappingURL=index.js.map
|
package/Modal/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Modal/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Modal/index.tsx"],"sourcesContent":["\"use client\";\nimport { ReactNode } from \"react\";\n// import useModal, { UseModalProps } from \"../useModal\";\nimport { Renderar, Tag, TagProps } from \"@xanui/core\";\nimport Layer, { ActionLayerChildren, LayerProps } from \"../Layer\";\n\nexport type ModalProps = Omit<LayerProps, \"slotProps\"> & {\n children: ReactNode;\n size?: \"xs\" | \"sm\" | \"md\" | \"lg\" | \"xl\" | \"full\" | number;\n slotProps?: {\n layer?: LayerProps['slotProps'];\n root?: Omit<TagProps<'div'>, \"children\">\n }\n}\n\n\nconst Modal = (props: ModalProps) => {\n let sizes: any = {\n xs: 420,\n sm: 760,\n md: 990,\n lg: 1120,\n xl: 1300,\n full: \"100%\"\n }\n let { children, onOpen, size, slotProps, ...layerProps } = props || {}\n size = size ?? \"xs\"\n slotProps = slotProps || {} as any\n const root: any = slotProps?.root || {}\n\n return (\n <Layer\n {...layerProps}\n slotProps={{\n ...slotProps?.layer,\n clickOutside: {\n maxWidth: sizes[size as any] || size,\n width: \"100%\",\n ...slotProps?.layer?.clickOutside,\n },\n root: {\n display: \"flex\",\n alignItems: 'center',\n justifyContent: \"center\",\n ...slotProps?.layer?.root,\n }\n }}\n >\n <Tag\n {...root}\n sxr={{\n maxWidth: sizes[size as any] || size,\n width: \"100%\",\n radius: 2,\n bgcolor: \"background.primary\",\n shadow: 15,\n ...root?.sx\n }}\n baseClass='modal'\n >\n {children}\n </Tag>\n </Layer>\n )\n}\n\nModal.open = (Children: ActionLayerChildren, props?: Omit<ModalProps, 'children' | \"open\">) => {\n const InstanceModal = ({ children, ...props }: ModalProps) => <Modal {...props} >{children}</Modal>;\n const m = Renderar.render(InstanceModal as any, {\n open: true,\n children: typeof Children === \"function\" ? <Children\n open={() => m.updateProps({ open: true })}\n close={() => m.updateProps({ open: false })}\n /> : Children,\n ...props,\n onClickOutside: () => {\n if (props?.onClickOutside) {\n props.onClickOutside()\n } else {\n m.updateProps({ open: false })\n }\n },\n onClosed: () => {\n m.unrender()\n if (props?.onClosed) {\n props.onClosed()\n }\n }\n })\n\n return {\n open: () => {\n m.updateProps({ open: true })\n },\n close: () => {\n m.updateProps({ open: false })\n },\n }\n};\n\n\nexport default Modal;"],"names":[],"mappings":";;;;;;AAgBA;;AACG;AACG;AACA;AACA;AACA;AACA;AACA;;AAEH;;AAEA;AACA;;AAoCH;AAEA;AACG;AAAuB;AAAuC;;AAC9D;;;;;;;AAaG;;;;;AAMA;;;;;;;;;AAWN;;"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xanui/ui",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.65",
|
|
4
4
|
"description": "Xanui - A React Component Library",
|
|
5
5
|
"private": false,
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@xanui/core": "^1.2.
|
|
7
|
+
"@xanui/core": "^1.2.54",
|
|
8
8
|
"@xanui/icons": "^1.1.12",
|
|
9
9
|
"pretty-class": "^1.0.8",
|
|
10
10
|
"react-state-bucket": "^1.2.17"
|
package/useAlert/index.cjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
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 index$2 = require('../Button/index.cjs');
|
|
8
|
-
var index = require('../useModal/index.cjs');
|
|
9
|
-
var index$1 = require('../Alert/index.cjs');
|
|
10
|
-
var React = require('react');
|
|
11
|
-
|
|
12
|
-
const useAlert = (props) => {
|
|
13
|
-
const [loading, setLoading] = React.useState(false);
|
|
14
|
-
let { content, size, color, direction, variant, closeButton, clickOutsideToClose, okButtonText, cancelButtonText, hideOkButton, hideCancelButton, buttonPlacement, onConfirm, onCancel, transition, blurMode, slotProps } = props, rest = tslib.__rest(props, ["content", "size", "color", "direction", "variant", "closeButton", "clickOutsideToClose", "okButtonText", "cancelButtonText", "hideOkButton", "hideCancelButton", "buttonPlacement", "onConfirm", "onCancel", "transition", "blurMode", "slotProps"]);
|
|
15
|
-
hideOkButton !== null && hideOkButton !== void 0 ? hideOkButton : (hideOkButton = false);
|
|
16
|
-
hideCancelButton !== null && hideCancelButton !== void 0 ? hideCancelButton : (hideCancelButton = false);
|
|
17
|
-
size !== null && size !== void 0 ? size : (size = "small");
|
|
18
|
-
color !== null && color !== void 0 ? color : (color = 'default');
|
|
19
|
-
variant !== null && variant !== void 0 ? variant : (variant = "text");
|
|
20
|
-
direction !== null && direction !== void 0 ? direction : (direction = "column");
|
|
21
|
-
buttonPlacement !== null && buttonPlacement !== void 0 ? buttonPlacement : (buttonPlacement = "end");
|
|
22
|
-
let sx = {};
|
|
23
|
-
switch (buttonPlacement) {
|
|
24
|
-
case "start":
|
|
25
|
-
sx.justifyContent = 'flex-start';
|
|
26
|
-
break;
|
|
27
|
-
case "end":
|
|
28
|
-
sx.justifyContent = 'flex-end';
|
|
29
|
-
break;
|
|
30
|
-
case "between":
|
|
31
|
-
sx.justifyContent = 'space-between';
|
|
32
|
-
break;
|
|
33
|
-
case "full":
|
|
34
|
-
sx = {
|
|
35
|
-
"& button": {
|
|
36
|
-
flex: 1
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
let sizes = {
|
|
42
|
-
small: 320,
|
|
43
|
-
medium: 400,
|
|
44
|
-
large: 600
|
|
45
|
-
};
|
|
46
|
-
let okcolor = color;
|
|
47
|
-
let closecolor = color;
|
|
48
|
-
if (color === 'default') {
|
|
49
|
-
okcolor = 'brand';
|
|
50
|
-
closecolor = 'default';
|
|
51
|
-
variant = 'text';
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
if (variant === 'fill') {
|
|
55
|
-
okcolor = 'default';
|
|
56
|
-
closecolor = 'default';
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
okcolor = color;
|
|
60
|
-
closecolor = 'default';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const modal = index(jsxRuntime.jsxs(index$1, Object.assign({ direction: direction, sx: {
|
|
64
|
-
px: 2,
|
|
65
|
-
py: 1,
|
|
66
|
-
pt: direction === 'row' ? 1 : 2
|
|
67
|
-
}, color: color, variant: variant, onClose: closeButton ? close : undefined }, rest, { children: [typeof content === "function" ? content({
|
|
68
|
-
open: () => modal.open(),
|
|
69
|
-
close: () => modal.close(),
|
|
70
|
-
loading: (is) => setLoading(is),
|
|
71
|
-
isLoading: () => loading
|
|
72
|
-
}) : content, jsxRuntime.jsxs(core.Tag, { sxr: Object.assign({ display: "flex", gap: 1, pt: 4, flexDirection: "row" }, sx), children: [!hideCancelButton && jsxRuntime.jsx(index$2, Object.assign({ disabled: loading, color: closecolor, variant: "fill" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.closeButton, { onClick: async () => {
|
|
73
|
-
setLoading(true);
|
|
74
|
-
onCancel && await onCancel();
|
|
75
|
-
setLoading(false);
|
|
76
|
-
modal.close();
|
|
77
|
-
}, children: cancelButtonText || "Close" })), jsxRuntime.jsx(index$2, Object.assign({ loading: loading, color: okcolor, variant: "fill" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.okButton, { onClick: async () => {
|
|
78
|
-
setLoading(true);
|
|
79
|
-
onConfirm && await onConfirm();
|
|
80
|
-
setLoading(false);
|
|
81
|
-
modal.close();
|
|
82
|
-
}, children: okButtonText || "OK" }))] })] })), Object.assign(Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.modal), { size: sizes[size] || size, blur: 40, blurMode: blurMode || "transparent", transition: transition || "zoom", onClickOutside: async () => {
|
|
83
|
-
if (clickOutsideToClose && !loading) {
|
|
84
|
-
setLoading(true);
|
|
85
|
-
onCancel && await onCancel();
|
|
86
|
-
setLoading(false);
|
|
87
|
-
modal.close();
|
|
88
|
-
}
|
|
89
|
-
} }));
|
|
90
|
-
return Object.assign(Object.assign({}, modal), { loading: (is) => setLoading(is), isLoading: () => loading });
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
module.exports = useAlert;
|
|
94
|
-
//# sourceMappingURL=index.cjs.map
|
package/useAlert/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/useAlert/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { Tag, UseTransitionVariantTypes } from \"@xanui/core\"\nimport Button, { ButtonProps } from \"../Button\";\nimport useModal, { UseModalProps } from \"../useModal\";\nimport Alert, { AlertProps } from \"../Alert\";\nimport React from \"react\";\nexport type UseAlertContentProps = {\n open: () => void;\n close: () => void;\n loading: (is: boolean) => void;\n isLoading: () => boolean;\n}\n\nexport type UseAlertContent = React.ReactElement | ((props: UseAlertContentProps) => React.ReactElement)\n\nexport type UseAlerProps = Omit<AlertProps, 'children' | 'onClose' | 'variant' | \"size\"> & {\n content: string | UseAlertContent,\n size?: \"small\" | \"medium\" | \"large\" | number;\n closeButton?: boolean;\n clickOutsideToClose?: boolean;\n okButtonText?: string;\n cancelButtonText?: string;\n hideOkButton?: boolean;\n hideCancelButton?: boolean;\n buttonPlacement?: \"start\" | \"end\" | \"between\" | \"full\";\n variant?: \"text\" | \"fill\"\n onConfirm?: () => Promise<void> | void;\n onCancel?: () => Promise<void> | void;\n transition?: UseTransitionVariantTypes;\n blurMode?: UseModalProps['blurMode'];\n slotProps?: {\n modal?: UseModalProps;\n okButton?: Omit<ButtonProps, \"children\">;\n closeButton?: Omit<ButtonProps, \"children\">;\n }\n}\n\n\nconst useAlert = (props: UseAlerProps) => {\n const [loading, setLoading] = React.useState(false)\n let {\n content,\n size,\n color,\n direction,\n variant,\n closeButton,\n clickOutsideToClose,\n okButtonText,\n cancelButtonText,\n hideOkButton,\n hideCancelButton,\n buttonPlacement,\n onConfirm,\n onCancel,\n transition,\n blurMode,\n slotProps,\n ...rest\n } = props\n\n hideOkButton ??= false\n hideCancelButton ??= false\n\n size ??= \"small\"\n color ??= 'default'\n variant ??= \"text\"\n direction ??= \"column\"\n buttonPlacement ??= \"end\"\n let sx: any = {};\n\n switch (buttonPlacement) {\n case \"start\":\n sx.justifyContent = 'flex-start'\n break;\n case \"end\":\n sx.justifyContent = 'flex-end'\n break;\n case \"between\":\n sx.justifyContent = 'space-between'\n break;\n case \"full\":\n sx = {\n \"& button\": {\n flex: 1\n }\n }\n break;\n }\n\n let sizes: any = {\n small: 320,\n medium: 400,\n large: 600\n }\n\n let okcolor = color\n let closecolor = color\n if (color === 'default') {\n okcolor = 'brand'\n closecolor = 'default'\n variant = 'text'\n } else {\n if (variant === 'fill') {\n okcolor = 'default'\n closecolor = 'default'\n } else {\n okcolor = color\n closecolor = 'default'\n }\n }\n\n const modal = useModal(<Alert\n direction={direction}\n sx={{\n px: 2,\n py: 1,\n pt: direction === 'row' ? 1 : 2\n }}\n color={color}\n variant={variant}\n onClose={closeButton ? close : undefined}\n {...rest}\n >\n {typeof content === \"function\" ? content({\n open: () => modal.open(),\n close: () => modal.close(),\n loading: (is: boolean) => setLoading(is),\n isLoading: () => loading\n }) : content}\n <Tag\n sxr={{\n display: \"flex\",\n gap: 1,\n pt: 4,\n flexDirection: \"row\",\n ...sx,\n }}\n >\n {!hideCancelButton && <Button\n disabled={loading}\n color={closecolor}\n variant=\"fill\"\n {...slotProps?.closeButton}\n onClick={async () => {\n setLoading(true)\n onCancel && await onCancel()\n setLoading(false)\n modal.close()\n }}\n >{cancelButtonText || \"Close\"}</Button>}\n <Button\n loading={loading}\n color={okcolor}\n variant=\"fill\"\n {...slotProps?.okButton}\n\n onClick={async () => {\n setLoading(true)\n onConfirm && await onConfirm()\n setLoading(false)\n modal.close()\n }}\n >{okButtonText || \"OK\"}</Button>\n </Tag>\n </Alert>, {\n ...slotProps?.modal,\n size: sizes[size] || size,\n blur: 40,\n blurMode: blurMode || \"transparent\",\n transition: transition || \"zoom\",\n onClickOutside: async () => {\n if (clickOutsideToClose && !loading) {\n setLoading(true)\n onCancel && await onCancel()\n setLoading(false)\n modal.close()\n }\n }\n })\n\n return {\n ...modal,\n loading: (is: boolean) => setLoading(is),\n isLoading: () => loading\n }\n}\n\nexport default useAlert"],"names":[],"mappings":";;;;;;;;;;;AAuCA;AACI;AACA;;;;;;;;;;AAgCI;AACI;;AAEJ;AACI;;AAEJ;AACI;;AAEJ;AACI;AACI;AACI;AACH;;;;AAKb;AACI;AACA;AACA;;;;AAKJ;;;;;;AAKI;;;;;;;;;AASJ;AAGQ;AACA;;AAEH;AAOG;AACA;;AAEA;;;AAkBQ;;;AAGJ;;AAUI;;;;AAaR;;AAEI;;;;AAIR;;AAQR;;"}
|
package/useAlert/index.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { UseTransitionVariantTypes } from '@xanui/core';
|
|
2
|
-
import { ButtonProps } from '../Button/index.js';
|
|
3
|
-
import { UseModalProps } from '../useModal/index.js';
|
|
4
|
-
import { AlertProps } from '../Alert/index.js';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
type UseAlertContentProps = {
|
|
8
|
-
open: () => void;
|
|
9
|
-
close: () => void;
|
|
10
|
-
loading: (is: boolean) => void;
|
|
11
|
-
isLoading: () => boolean;
|
|
12
|
-
};
|
|
13
|
-
type UseAlertContent = React.ReactElement | ((props: UseAlertContentProps) => React.ReactElement);
|
|
14
|
-
type UseAlerProps = Omit<AlertProps, 'children' | 'onClose' | 'variant' | "size"> & {
|
|
15
|
-
content: string | UseAlertContent;
|
|
16
|
-
size?: "small" | "medium" | "large" | number;
|
|
17
|
-
closeButton?: boolean;
|
|
18
|
-
clickOutsideToClose?: boolean;
|
|
19
|
-
okButtonText?: string;
|
|
20
|
-
cancelButtonText?: string;
|
|
21
|
-
hideOkButton?: boolean;
|
|
22
|
-
hideCancelButton?: boolean;
|
|
23
|
-
buttonPlacement?: "start" | "end" | "between" | "full";
|
|
24
|
-
variant?: "text" | "fill";
|
|
25
|
-
onConfirm?: () => Promise<void> | void;
|
|
26
|
-
onCancel?: () => Promise<void> | void;
|
|
27
|
-
transition?: UseTransitionVariantTypes;
|
|
28
|
-
blurMode?: UseModalProps['blurMode'];
|
|
29
|
-
slotProps?: {
|
|
30
|
-
modal?: UseModalProps;
|
|
31
|
-
okButton?: Omit<ButtonProps, "children">;
|
|
32
|
-
closeButton?: Omit<ButtonProps, "children">;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type { UseAlerProps, UseAlertContent, UseAlertContentProps };
|