@xanui/ui 1.1.62 → 1.1.64
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/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/Select/index.cjs +1 -1
- package/Select/index.cjs.map +1 -1
- package/Select/index.js +1 -1
- package/Select/index.js.map +1 -1
- package/package.json +1 -1
package/InputNumber/index.cjs
CHANGED
|
@@ -9,41 +9,45 @@ var core = require('@xanui/core');
|
|
|
9
9
|
|
|
10
10
|
const InputNumber = React.forwardRef((props, ref) => {
|
|
11
11
|
var _a;
|
|
12
|
-
const [_val, setVal] = React.useState((_a = props.value) !== null && _a !== void 0 ? _a : "");
|
|
13
12
|
const inputRef = React.useRef(null);
|
|
14
13
|
const mergeRef = core.useMergeRefs(inputRef, ref);
|
|
15
|
-
|
|
16
|
-
if (inputRef.current && (props === null || props === void 0 ? void 0 : props.onChange)) {
|
|
17
|
-
let valstr = String(_val);
|
|
18
|
-
inputRef.current.value = valstr.includes(".") ? parseFloat(_val) : parseInt(_val);
|
|
19
|
-
const syntheticEvent = {
|
|
20
|
-
target: inputRef.current,
|
|
21
|
-
currentTarget: inputRef.current,
|
|
22
|
-
};
|
|
23
|
-
props === null || props === void 0 ? void 0 : props.onChange(syntheticEvent);
|
|
24
|
-
}
|
|
25
|
-
}, [_val]);
|
|
26
|
-
const isNumeric = _val === undefined || _val === '' || !isNaN(Number(_val));
|
|
14
|
+
const isNumeric = props.value === undefined || props.value === '' || !isNaN(Number(props.value));
|
|
27
15
|
const errorProps = {};
|
|
28
16
|
if (!isNumeric) {
|
|
29
17
|
errorProps.error = true;
|
|
30
18
|
errorProps.helperText = "Value must be numeric";
|
|
31
19
|
}
|
|
32
|
-
return (jsxRuntime.jsx(index, Object.assign({}, props, errorProps, { ref: mergeRef, endIcon: jsxRuntime.jsx(UnfoldMore, {}), value:
|
|
20
|
+
return (jsxRuntime.jsx(index, Object.assign({}, props, errorProps, { ref: mergeRef, endIcon: jsxRuntime.jsx(UnfoldMore, {}), value: (_a = props.value) !== null && _a !== void 0 ? _a : "", onKeyDown: (e) => {
|
|
33
21
|
var _a;
|
|
34
22
|
(_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
35
23
|
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
|
|
36
24
|
return;
|
|
37
25
|
e.preventDefault();
|
|
38
|
-
const current = parseFloat(
|
|
39
|
-
|
|
26
|
+
const current = parseFloat(props.value) || 0;
|
|
27
|
+
e.target.value = e.key === 'ArrowUp' ? current + 1 : current - 1;
|
|
28
|
+
(props === null || props === void 0 ? void 0 : props.onChange) && (props === null || props === void 0 ? void 0 : props.onChange(e));
|
|
29
|
+
}, onBlur: (e) => {
|
|
30
|
+
var _a;
|
|
31
|
+
const raw = e.target.value;
|
|
32
|
+
if (raw === "" || raw === ".")
|
|
33
|
+
return;
|
|
34
|
+
const num = parseFloat(raw);
|
|
35
|
+
if (!Number.isNaN(num)) {
|
|
36
|
+
(_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 }) }));
|
|
37
|
+
}
|
|
40
38
|
}, onChange: (e) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
39
|
+
var _a, _b;
|
|
40
|
+
let value = e.target.value;
|
|
41
|
+
if (value === "") {
|
|
42
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
43
|
+
return;
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
if (!/^\d*\.?\d*$/.test(value))
|
|
46
|
+
return;
|
|
47
|
+
if (value === ".")
|
|
48
|
+
value = "0.";
|
|
49
|
+
const nextEvent = Object.assign(Object.assign({}, e), { target: Object.assign(Object.assign({}, e.target), { value }) });
|
|
50
|
+
(_b = props === null || props === void 0 ? void 0 : props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, nextEvent);
|
|
47
51
|
} })));
|
|
48
52
|
});
|
|
49
53
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/InputNumber/index.tsx"],"sourcesContent":["\"use client\"\nimport React, {
|
|
1
|
+
{"version":3,"file":"index.cjs","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/InputNumber/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { InputProps } from '../Input/index.js';
|
|
3
3
|
|
|
4
4
|
type InputNumberProps = Omit<InputProps, "value"> & {
|
|
5
|
-
value?: number;
|
|
5
|
+
value?: number | "";
|
|
6
6
|
};
|
|
7
7
|
declare const InputNumber: React.ForwardRefExoticComponent<Omit<InputNumberProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
8
8
|
|
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/Select/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ const Select = React.forwardRef((_a, ref) => {
|
|
|
52
52
|
if (conRef.current.contains(e.target))
|
|
53
53
|
return;
|
|
54
54
|
toggleMenu();
|
|
55
|
-
}, children: jsxRuntime.jsx(index$3, Object.assign({ ref: refs === null || refs === void 0 ? void 0 : refs.list }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.list, { color: color, variant: variant === "outline" ? "fill" : variant, maxHeight: window.innerHeight - 50, overflow: "auto", children: childs })) }))] }));
|
|
55
|
+
}, children: jsxRuntime.jsx(index$3, Object.assign({ ref: refs === null || refs === void 0 ? void 0 : refs.list }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.list, { color: color, variant: variant === "outline" ? "fill" : variant, maxHeight: typeof window === "undefined" ? "auto" : (window === null || window === void 0 ? void 0 : window.innerHeight) - 50, overflow: "auto", children: childs })) }))] }));
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
module.exports = Select;
|
package/Select/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Select/index.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactElement, useMemo, cloneElement, useState, Children, useRef } from 'react'\nimport Input, { InputProps } from '../Input'\nimport List, { ListProps } from '../List'\nimport Menu, { MenuProps } from '../Menu'\nimport Stack from '../Stack'\nimport { OptionProps } from '../Option'\nimport DownIcon from '@xanui/icons/KeyboardArrowDown';\nimport UpIcon from '@xanui/icons/KeyboardArrowUp';\nimport { useInterface, useMergeRefs } from '@xanui/core'\n\n\nexport type SelectProps = Omit<InputProps, \"onChange\" | \"value\" | \"children\" | \"slotProps\"> & {\n value?: string | number;\n onChange?: (value: string | number) => void;\n children: ReactElement<OptionProps> | ReactElement<OptionProps>[];\n\n refs?: {\n input?: React.Ref<any>;\n menu?: React.Ref<any>;\n list?: React.Ref<any>;\n };\n slotProps?: {\n menu?: Omit<MenuProps, 'children' | 'target'>;\n input?: Omit<InputProps, \"onChange\" | \"value\">;\n list?: Omit<ListProps, \"children\">\n }\n}\n\nconst Select = React.forwardRef(({ onChange, value, children, error, helperText, name, refs, ...props }: SelectProps, ref: React.Ref<any>) => {\n let [{ slotProps, color, variant, ...inputProps }] = useInterface<any>(\"Select\", props, {})\n color ??= \"brand\"\n variant ??= \"fill\"\n const [target, setTarget] = useState<any>()\n const conRef = useRef(null)\n const { childs, selectedProps } = useMemo(() => {\n let sProps: any = {}\n const c = Children.map(children, (child: any) => {\n let selected = child.props.value === value\n if (selected) sProps = child.props\n return cloneElement(child, {\n value: undefined,\n selected,\n onClick: () => {\n setTarget(null)\n onChange && onChange(child.props.value)\n }\n })\n })\n return {\n childs: c,\n selectedProps: sProps as OptionProps\n }\n }, [children, value])\n\n const mergeRefs = useMergeRefs(ref, conRef)\n const toggleMenu = () => setTarget(target ? null : conRef.current)\n\n return (\n <>\n <Input\n ref={mergeRefs}\n color={color}\n variant={variant === \"soft\" ? \"fill\" : variant}\n endIcon={<Stack flexDirection=\"row\" component=\"span\" > {(target ? <UpIcon /> : <DownIcon />)}</Stack>}\n readOnly\n value={typeof selectedProps.children === 'string' ? selectedProps.children : value}\n cursor=\"pointer\"\n userSelect=\"none\"\n startIcon={selectedProps.startIcon}\n focused={!!target}\n error={error}\n helperText={helperText}\n name={name}\n {...slotProps?.input}\n {...inputProps}\n refs={{\n input: refs?.input,\n ...slotProps?.input?.refs\n }}\n slotProps={{\n rootContainer: {\n cursor: \"pointer\",\n userSelect: \"none\",\n ...(slotProps?.input?.slotProps?.container || {}),\n onClick: () => {\n if (!target) {\n toggleMenu()\n }\n },\n }\n }}\n />\n <Menu\n ref={refs?.menu}\n target={target}\n placement=\"bottom-left\"\n {...slotProps?.menu}\n slotProps={{\n ...slotProps?.menu?.slotProps,\n content: {\n mt: .5,\n ...slotProps?.menu?.content,\n width: conRef && (conRef?.current as any)?.clientWidth,\n }\n }}\n onClickOutside={(e) => {\n if ((conRef.current as any).contains(e.target)) return;\n toggleMenu()\n }}\n >\n <List\n ref={refs?.list}\n {...slotProps?.list}\n color={color}\n variant={variant === \"outline\" ? \"fill\" : variant}\n maxHeight={window
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Select/index.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactElement, useMemo, cloneElement, useState, Children, useRef } from 'react'\nimport Input, { InputProps } from '../Input'\nimport List, { ListProps } from '../List'\nimport Menu, { MenuProps } from '../Menu'\nimport Stack from '../Stack'\nimport { OptionProps } from '../Option'\nimport DownIcon from '@xanui/icons/KeyboardArrowDown';\nimport UpIcon from '@xanui/icons/KeyboardArrowUp';\nimport { useInterface, useMergeRefs } from '@xanui/core'\n\n\nexport type SelectProps = Omit<InputProps, \"onChange\" | \"value\" | \"children\" | \"slotProps\"> & {\n value?: string | number;\n onChange?: (value: string | number) => void;\n children: ReactElement<OptionProps> | ReactElement<OptionProps>[];\n\n refs?: {\n input?: React.Ref<any>;\n menu?: React.Ref<any>;\n list?: React.Ref<any>;\n };\n slotProps?: {\n menu?: Omit<MenuProps, 'children' | 'target'>;\n input?: Omit<InputProps, \"onChange\" | \"value\">;\n list?: Omit<ListProps, \"children\">\n }\n}\n\nconst Select = React.forwardRef(({ onChange, value, children, error, helperText, name, refs, ...props }: SelectProps, ref: React.Ref<any>) => {\n let [{ slotProps, color, variant, ...inputProps }] = useInterface<any>(\"Select\", props, {})\n color ??= \"brand\"\n variant ??= \"fill\"\n const [target, setTarget] = useState<any>()\n const conRef = useRef(null)\n const { childs, selectedProps } = useMemo(() => {\n let sProps: any = {}\n const c = Children.map(children, (child: any) => {\n let selected = child.props.value === value\n if (selected) sProps = child.props\n return cloneElement(child, {\n value: undefined,\n selected,\n onClick: () => {\n setTarget(null)\n onChange && onChange(child.props.value)\n }\n })\n })\n return {\n childs: c,\n selectedProps: sProps as OptionProps\n }\n }, [children, value])\n\n const mergeRefs = useMergeRefs(ref, conRef)\n const toggleMenu = () => setTarget(target ? null : conRef.current)\n\n return (\n <>\n <Input\n ref={mergeRefs}\n color={color}\n variant={variant === \"soft\" ? \"fill\" : variant}\n endIcon={<Stack flexDirection=\"row\" component=\"span\" > {(target ? <UpIcon /> : <DownIcon />)}</Stack>}\n readOnly\n value={typeof selectedProps.children === 'string' ? selectedProps.children : value}\n cursor=\"pointer\"\n userSelect=\"none\"\n startIcon={selectedProps.startIcon}\n focused={!!target}\n error={error}\n helperText={helperText}\n name={name}\n {...slotProps?.input}\n {...inputProps}\n refs={{\n input: refs?.input,\n ...slotProps?.input?.refs\n }}\n slotProps={{\n rootContainer: {\n cursor: \"pointer\",\n userSelect: \"none\",\n ...(slotProps?.input?.slotProps?.container || {}),\n onClick: () => {\n if (!target) {\n toggleMenu()\n }\n },\n }\n }}\n />\n <Menu\n ref={refs?.menu}\n target={target}\n placement=\"bottom-left\"\n {...slotProps?.menu}\n slotProps={{\n ...slotProps?.menu?.slotProps,\n content: {\n mt: .5,\n ...slotProps?.menu?.content,\n width: conRef && (conRef?.current as any)?.clientWidth,\n }\n }}\n onClickOutside={(e) => {\n if ((conRef.current as any).contains(e.target)) return;\n toggleMenu()\n }}\n >\n <List\n ref={refs?.list}\n {...slotProps?.list}\n color={color}\n variant={variant === \"outline\" ? \"fill\" : variant}\n maxHeight={typeof window === \"undefined\" ? \"auto\" : window?.innerHeight - 50}\n overflow={\"auto\"}\n >\n {childs}\n </List>\n </Menu>\n </>\n )\n})\n\nexport default Select"],"names":[],"mappings":";;;;;;;;;;;;;;AA8BA;;AAAiC;;;;;AAK7B;;;;;AAKQ;AAAc;;AAEV;;;;;;AAMH;AACL;;AAEI;AACA;;AAER;;AAGA;AAEA;AAuBgB;;AAMY;;AAER;AAEP;;;AAiBG;AACJ;AAehB;;"}
|
package/Select/index.js
CHANGED
|
@@ -50,7 +50,7 @@ const Select = React.forwardRef((_a, ref) => {
|
|
|
50
50
|
if (conRef.current.contains(e.target))
|
|
51
51
|
return;
|
|
52
52
|
toggleMenu();
|
|
53
|
-
}, children: jsx(List, Object.assign({ ref: refs === null || refs === void 0 ? void 0 : refs.list }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.list, { color: color, variant: variant === "outline" ? "fill" : variant, maxHeight: window.innerHeight - 50, overflow: "auto", children: childs })) }))] }));
|
|
53
|
+
}, children: jsx(List, Object.assign({ ref: refs === null || refs === void 0 ? void 0 : refs.list }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.list, { color: color, variant: variant === "outline" ? "fill" : variant, maxHeight: typeof window === "undefined" ? "auto" : (window === null || window === void 0 ? void 0 : window.innerHeight) - 50, overflow: "auto", children: childs })) }))] }));
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
export { Select as default };
|
package/Select/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Select/index.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactElement, useMemo, cloneElement, useState, Children, useRef } from 'react'\nimport Input, { InputProps } from '../Input'\nimport List, { ListProps } from '../List'\nimport Menu, { MenuProps } from '../Menu'\nimport Stack from '../Stack'\nimport { OptionProps } from '../Option'\nimport DownIcon from '@xanui/icons/KeyboardArrowDown';\nimport UpIcon from '@xanui/icons/KeyboardArrowUp';\nimport { useInterface, useMergeRefs } from '@xanui/core'\n\n\nexport type SelectProps = Omit<InputProps, \"onChange\" | \"value\" | \"children\" | \"slotProps\"> & {\n value?: string | number;\n onChange?: (value: string | number) => void;\n children: ReactElement<OptionProps> | ReactElement<OptionProps>[];\n\n refs?: {\n input?: React.Ref<any>;\n menu?: React.Ref<any>;\n list?: React.Ref<any>;\n };\n slotProps?: {\n menu?: Omit<MenuProps, 'children' | 'target'>;\n input?: Omit<InputProps, \"onChange\" | \"value\">;\n list?: Omit<ListProps, \"children\">\n }\n}\n\nconst Select = React.forwardRef(({ onChange, value, children, error, helperText, name, refs, ...props }: SelectProps, ref: React.Ref<any>) => {\n let [{ slotProps, color, variant, ...inputProps }] = useInterface<any>(\"Select\", props, {})\n color ??= \"brand\"\n variant ??= \"fill\"\n const [target, setTarget] = useState<any>()\n const conRef = useRef(null)\n const { childs, selectedProps } = useMemo(() => {\n let sProps: any = {}\n const c = Children.map(children, (child: any) => {\n let selected = child.props.value === value\n if (selected) sProps = child.props\n return cloneElement(child, {\n value: undefined,\n selected,\n onClick: () => {\n setTarget(null)\n onChange && onChange(child.props.value)\n }\n })\n })\n return {\n childs: c,\n selectedProps: sProps as OptionProps\n }\n }, [children, value])\n\n const mergeRefs = useMergeRefs(ref, conRef)\n const toggleMenu = () => setTarget(target ? null : conRef.current)\n\n return (\n <>\n <Input\n ref={mergeRefs}\n color={color}\n variant={variant === \"soft\" ? \"fill\" : variant}\n endIcon={<Stack flexDirection=\"row\" component=\"span\" > {(target ? <UpIcon /> : <DownIcon />)}</Stack>}\n readOnly\n value={typeof selectedProps.children === 'string' ? selectedProps.children : value}\n cursor=\"pointer\"\n userSelect=\"none\"\n startIcon={selectedProps.startIcon}\n focused={!!target}\n error={error}\n helperText={helperText}\n name={name}\n {...slotProps?.input}\n {...inputProps}\n refs={{\n input: refs?.input,\n ...slotProps?.input?.refs\n }}\n slotProps={{\n rootContainer: {\n cursor: \"pointer\",\n userSelect: \"none\",\n ...(slotProps?.input?.slotProps?.container || {}),\n onClick: () => {\n if (!target) {\n toggleMenu()\n }\n },\n }\n }}\n />\n <Menu\n ref={refs?.menu}\n target={target}\n placement=\"bottom-left\"\n {...slotProps?.menu}\n slotProps={{\n ...slotProps?.menu?.slotProps,\n content: {\n mt: .5,\n ...slotProps?.menu?.content,\n width: conRef && (conRef?.current as any)?.clientWidth,\n }\n }}\n onClickOutside={(e) => {\n if ((conRef.current as any).contains(e.target)) return;\n toggleMenu()\n }}\n >\n <List\n ref={refs?.list}\n {...slotProps?.list}\n color={color}\n variant={variant === \"outline\" ? \"fill\" : variant}\n maxHeight={window
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Select/index.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactElement, useMemo, cloneElement, useState, Children, useRef } from 'react'\nimport Input, { InputProps } from '../Input'\nimport List, { ListProps } from '../List'\nimport Menu, { MenuProps } from '../Menu'\nimport Stack from '../Stack'\nimport { OptionProps } from '../Option'\nimport DownIcon from '@xanui/icons/KeyboardArrowDown';\nimport UpIcon from '@xanui/icons/KeyboardArrowUp';\nimport { useInterface, useMergeRefs } from '@xanui/core'\n\n\nexport type SelectProps = Omit<InputProps, \"onChange\" | \"value\" | \"children\" | \"slotProps\"> & {\n value?: string | number;\n onChange?: (value: string | number) => void;\n children: ReactElement<OptionProps> | ReactElement<OptionProps>[];\n\n refs?: {\n input?: React.Ref<any>;\n menu?: React.Ref<any>;\n list?: React.Ref<any>;\n };\n slotProps?: {\n menu?: Omit<MenuProps, 'children' | 'target'>;\n input?: Omit<InputProps, \"onChange\" | \"value\">;\n list?: Omit<ListProps, \"children\">\n }\n}\n\nconst Select = React.forwardRef(({ onChange, value, children, error, helperText, name, refs, ...props }: SelectProps, ref: React.Ref<any>) => {\n let [{ slotProps, color, variant, ...inputProps }] = useInterface<any>(\"Select\", props, {})\n color ??= \"brand\"\n variant ??= \"fill\"\n const [target, setTarget] = useState<any>()\n const conRef = useRef(null)\n const { childs, selectedProps } = useMemo(() => {\n let sProps: any = {}\n const c = Children.map(children, (child: any) => {\n let selected = child.props.value === value\n if (selected) sProps = child.props\n return cloneElement(child, {\n value: undefined,\n selected,\n onClick: () => {\n setTarget(null)\n onChange && onChange(child.props.value)\n }\n })\n })\n return {\n childs: c,\n selectedProps: sProps as OptionProps\n }\n }, [children, value])\n\n const mergeRefs = useMergeRefs(ref, conRef)\n const toggleMenu = () => setTarget(target ? null : conRef.current)\n\n return (\n <>\n <Input\n ref={mergeRefs}\n color={color}\n variant={variant === \"soft\" ? \"fill\" : variant}\n endIcon={<Stack flexDirection=\"row\" component=\"span\" > {(target ? <UpIcon /> : <DownIcon />)}</Stack>}\n readOnly\n value={typeof selectedProps.children === 'string' ? selectedProps.children : value}\n cursor=\"pointer\"\n userSelect=\"none\"\n startIcon={selectedProps.startIcon}\n focused={!!target}\n error={error}\n helperText={helperText}\n name={name}\n {...slotProps?.input}\n {...inputProps}\n refs={{\n input: refs?.input,\n ...slotProps?.input?.refs\n }}\n slotProps={{\n rootContainer: {\n cursor: \"pointer\",\n userSelect: \"none\",\n ...(slotProps?.input?.slotProps?.container || {}),\n onClick: () => {\n if (!target) {\n toggleMenu()\n }\n },\n }\n }}\n />\n <Menu\n ref={refs?.menu}\n target={target}\n placement=\"bottom-left\"\n {...slotProps?.menu}\n slotProps={{\n ...slotProps?.menu?.slotProps,\n content: {\n mt: .5,\n ...slotProps?.menu?.content,\n width: conRef && (conRef?.current as any)?.clientWidth,\n }\n }}\n onClickOutside={(e) => {\n if ((conRef.current as any).contains(e.target)) return;\n toggleMenu()\n }}\n >\n <List\n ref={refs?.list}\n {...slotProps?.list}\n color={color}\n variant={variant === \"outline\" ? \"fill\" : variant}\n maxHeight={typeof window === \"undefined\" ? \"auto\" : window?.innerHeight - 50}\n overflow={\"auto\"}\n >\n {childs}\n </List>\n </Menu>\n </>\n )\n})\n\nexport default Select"],"names":[],"mappings":";;;;;;;;;;;;AA8BA;;AAAiC;;;;;AAK7B;;;;;AAKQ;AAAc;;AAEV;;;;;;AAMH;AACL;;AAEI;AACA;;AAER;;AAGA;AAEA;AAuBgB;;AAMY;;AAER;AAEP;;;AAiBG;AACJ;AAehB;;"}
|