@xanui/ui 1.1.67 → 1.1.69
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/Autocomplete/index.cjs +44 -31
- package/Autocomplete/index.cjs.map +1 -1
- package/Autocomplete/index.js +45 -32
- package/Autocomplete/index.js.map +1 -1
- package/Chip/index.cjs +8 -4
- package/Chip/index.cjs.map +1 -1
- package/Chip/index.d.ts +3 -0
- package/Chip/index.js +8 -4
- package/Chip/index.js.map +1 -1
- package/Datatable/index.cjs +3 -11
- package/Datatable/index.cjs.map +1 -1
- package/Datatable/index.js +3 -11
- package/Datatable/index.js.map +1 -1
- package/Input/index.cjs +2 -2
- package/Input/index.cjs.map +1 -1
- package/Input/index.js +2 -2
- package/Input/index.js.map +1 -1
- package/package.json +1 -1
package/Autocomplete/index.cjs
CHANGED
|
@@ -18,13 +18,15 @@ const Autocomplete = (_a) => {
|
|
|
18
18
|
const [inputValue, setInputValue] = React.useState("");
|
|
19
19
|
const [timer, setTimer] = React.useState(null);
|
|
20
20
|
const [loading, setLoading] = React.useState(false);
|
|
21
|
+
const [focused, setFocused] = React.useState(false);
|
|
21
22
|
const [open, setOpen] = React.useState(false);
|
|
22
23
|
const menuRef = React.useRef(null);
|
|
23
24
|
getLabel !== null && getLabel !== void 0 ? getLabel : (getLabel = (option) => option.toString());
|
|
24
25
|
multiple !== null && multiple !== void 0 ? multiple : (multiple = false);
|
|
25
|
-
let startIcons = [
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
let startIcons = [];
|
|
27
|
+
if (inputProps.startIcon) {
|
|
28
|
+
startIcons.push(inputProps.startIcon);
|
|
29
|
+
}
|
|
28
30
|
if (!!value && multiple && Array.isArray(value)) {
|
|
29
31
|
value.map((v, index$2) => {
|
|
30
32
|
startIcons.push(jsxRuntime.jsx(index, { size: "small", label: getLabel(v), variant: "fill", color: "default", endIcon: jsxRuntime.jsx(index$1, { size: 20, variant: "text", color: "default", onClick: (e) => {
|
|
@@ -35,27 +37,56 @@ const Autocomplete = (_a) => {
|
|
|
35
37
|
}, children: jsxRuntime.jsx(Close, {}) }) }, index$2));
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
|
-
let endIcons = [
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
let endIcons = [];
|
|
41
|
+
if (inputProps.endIcon) {
|
|
42
|
+
endIcons.push(inputProps.endIcon);
|
|
43
|
+
}
|
|
41
44
|
if (loading) {
|
|
42
45
|
endIcons.push(jsxRuntime.jsx(index$2, { size: "small" }, "auto-complete-loading-icon"));
|
|
43
46
|
}
|
|
44
47
|
else if (!!value && !multiple) {
|
|
45
|
-
endIcons.
|
|
48
|
+
endIcons.unshift(jsxRuntime.jsx(index$1, { variant: "text", color: "default", onClick: (e) => {
|
|
46
49
|
e.stopPropagation();
|
|
47
|
-
onChange && onChange(
|
|
50
|
+
onChange && onChange(null);
|
|
48
51
|
setInputValue("");
|
|
49
52
|
}, children: jsxRuntime.jsx(Close, {}) }, "auto-complete-clear-button"));
|
|
50
53
|
}
|
|
54
|
+
const loadOptions = async () => {
|
|
55
|
+
setLoading(true);
|
|
56
|
+
let results = [];
|
|
57
|
+
if (typeof options === 'function') {
|
|
58
|
+
results = await options(inputValue);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
results = options.filter(option => getLabel(option).toLowerCase().includes(inputValue.toLowerCase()));
|
|
62
|
+
}
|
|
63
|
+
if (!multiple && inputValue) {
|
|
64
|
+
const find = results.find(option => getLabel(option).toLowerCase() == inputValue.toLowerCase());
|
|
65
|
+
onChange && onChange(find || null);
|
|
66
|
+
}
|
|
67
|
+
setOptions(results);
|
|
68
|
+
setOpen(true);
|
|
69
|
+
setLoading(false);
|
|
70
|
+
};
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
if (focused) {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
setTimer(setTimeout(() => {
|
|
75
|
+
loadOptions();
|
|
76
|
+
}, 300));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
setOpen(false);
|
|
80
|
+
}
|
|
81
|
+
}, [focused, inputValue]);
|
|
51
82
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(index$3, Object.assign({}, inputProps, { ref: menuRef, slotProps: {
|
|
52
83
|
rootContainer: Object.assign({ flexWrap: 'wrap' }, (multiple ? { height: "auto", gap: .5 } : {})),
|
|
53
84
|
input: {
|
|
54
|
-
width: multiple ? '
|
|
85
|
+
width: multiple ? 'initial' : '100%',
|
|
55
86
|
flex: 1,
|
|
56
87
|
minWidth: 20,
|
|
57
88
|
}
|
|
58
|
-
}, startIcon: startIcons, endIcon: endIcons, value: inputValue, onKeyDown: (e) => {
|
|
89
|
+
}, startIcon: startIcons.length ? startIcons : undefined, endIcon: endIcons, value: inputValue, onFocus: () => setFocused(true), onKeyDown: (e) => {
|
|
59
90
|
if (inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) {
|
|
60
91
|
inputProps.onKeyDown(e);
|
|
61
92
|
}
|
|
@@ -67,28 +98,8 @@ const Autocomplete = (_a) => {
|
|
|
67
98
|
}, onChange: (e) => {
|
|
68
99
|
const value = e.target.value;
|
|
69
100
|
setInputValue(value);
|
|
70
|
-
if (!value) {
|
|
71
|
-
setOptions([]);
|
|
72
|
-
setOpen(false);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
setOpen(true);
|
|
76
|
-
clearTimeout(timer);
|
|
77
|
-
setTimer(setTimeout(async () => {
|
|
78
|
-
if (typeof options === 'function') {
|
|
79
|
-
setLoading(true);
|
|
80
|
-
const result = await options(value);
|
|
81
|
-
setOptions(result);
|
|
82
|
-
setLoading(false);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
const filtered = options.filter(option => getLabel(option).toLowerCase().includes(value.toLowerCase()));
|
|
86
|
-
setOptions(filtered);
|
|
87
|
-
}
|
|
88
|
-
}, 300));
|
|
89
101
|
} })), jsxRuntime.jsx(index$4, { target: open ? menuRef.current : null, onClickOutside: () => {
|
|
90
|
-
|
|
91
|
-
setInputValue("");
|
|
102
|
+
setFocused(false);
|
|
92
103
|
}, slotProps: {
|
|
93
104
|
content: { minWidth: menuRef.current ? menuRef.current.offsetWidth : 'auto' }
|
|
94
105
|
}, children: jsxRuntime.jsx(index$5, { maxHeight: 400, overflow: "auto", children: _options === null || _options === void 0 ? void 0 : _options.map((option, index) => (renderOption ? jsxRuntime.jsx("div", { children: renderOption(option, {
|
|
@@ -105,6 +116,7 @@ const Autocomplete = (_a) => {
|
|
|
105
116
|
onChange && onChange(newValue);
|
|
106
117
|
}
|
|
107
118
|
else {
|
|
119
|
+
setFocused(false);
|
|
108
120
|
onChange && onChange(option);
|
|
109
121
|
setOpen(false);
|
|
110
122
|
setInputValue(getLabel(option));
|
|
@@ -124,6 +136,7 @@ const Autocomplete = (_a) => {
|
|
|
124
136
|
onChange && onChange(newValue);
|
|
125
137
|
}
|
|
126
138
|
else {
|
|
139
|
+
setFocused(false);
|
|
127
140
|
onChange && onChange(option);
|
|
128
141
|
setOpen(false);
|
|
129
142
|
setInputValue(getLabel(option));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Autocomplete/index.tsx"],"sourcesContent":["import React, { ReactElement } from 'react'\nimport Input from '../Input'\nimport Menu from '../Menu'\nimport List from '../List';\nimport ListItem, { ListItemProps } from '../ListItem';\nimport Chip from '../Chip';\nimport IconButton from '../IconButton';\nimport Close from '@xanui/icons/Close';\nimport CircleProgress from '../CircleProgress';\nimport { useBreakpointPropsType, UseColorTemplateColor } from '@xanui/core';\n\nexport type AutocompleteProps = {\n\n options: any[] | ((text: string) => Promise<any[]>)\n getLabel: (option: any) => string;\n onChange?: (value: any) => void;\n value?: any;\n multiple?: boolean;\n renderOption?: (option: any, props: any) => ReactElement<ListItemProps>\n\n // input props customization\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n\n}\n\nconst Autocomplete = ({ value, onChange, renderOption, options, getLabel, multiple, ...inputProps }: AutocompleteProps) => {\n const [_options, setOptions] = React.useState<any[]>()\n const [inputValue, setInputValue] = React.useState(\"\")\n const [timer, setTimer] = React.useState<any>(null)\n const [loading, setLoading] = React.useState(false)\n const [open, setOpen] = React.useState(false)\n const menuRef = React.useRef<any>(null)\n\n getLabel ??= (option: any) => option.toString();\n multiple ??= false;\n\n let startIcons = [\n inputProps.startIcon\n ]\n\n if (!!value && multiple && Array.isArray(value)) {\n value.map((v: any, index: number) => {\n startIcons.push(<Chip\n key={index}\n size=\"small\"\n label={getLabel!(v)}\n variant={\"fill\"}\n color=\"default\"\n endIcon={<IconButton\n size={20}\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n let newValue = Array.isArray(value) ? [...value] : []\n newValue = newValue.filter((val: any) => getLabel!(val) !== getLabel!(v))\n onChange && onChange(newValue)\n }}\n >\n <Close />\n </IconButton>}\n />)\n })\n }\n\n let endIcons = [\n inputProps.endIcon\n ]\n\n if (loading) {\n endIcons.push(<CircleProgress\n key=\"auto-complete-loading-icon\"\n size=\"small\"\n />)\n } else if (!!value && !multiple) {\n endIcons.push(<IconButton\n key=\"auto-complete-clear-button\"\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n onChange && onChange(undefined)\n setInputValue(\"\")\n }}\n >\n <Close />\n </IconButton>)\n }\n\n\n return (\n <>\n <Input\n {...inputProps as any}\n ref={menuRef}\n slotProps={{\n rootContainer: {\n flexWrap: 'wrap',\n ...(multiple ? { height: \"auto\", gap: .5 } : {})\n },\n input: {\n width: multiple ? 'auto' : '100%',\n flex: 1,\n minWidth: 20,\n }\n }}\n startIcon={startIcons}\n endIcon={endIcons}\n value={inputValue}\n onKeyDown={(e) => {\n if (inputProps?.onKeyDown) {\n inputProps.onKeyDown(e)\n }\n if (multiple && e.key === 'Backspace' && inputValue === \"\" && Array.isArray(value) && value.length > 0) {\n let newValue = [...value]\n newValue.pop()\n onChange && onChange(newValue)\n }\n }}\n onChange={(e) => {\n const value = e.target.value;\n setInputValue(value)\n if (!value) {\n setOptions([])\n setOpen(false)\n return;\n }\n setOpen(true)\n\n clearTimeout(timer)\n setTimer(setTimeout(async () => {\n if (typeof options === 'function') {\n setLoading(true)\n const result = await options(value)\n setOptions(result)\n setLoading(false)\n } else {\n const filtered = options.filter(option => getLabel!(option).toLowerCase().includes(value.toLowerCase()))\n setOptions(filtered)\n }\n }, 300))\n }}\n />\n <Menu\n target={open ? menuRef.current : null}\n onClickOutside={() => {\n setOptions([])\n setInputValue(\"\")\n }}\n slotProps={{\n content: { minWidth: menuRef.current ? menuRef.current.offsetWidth : 'auto' }\n }}\n >\n <List\n maxHeight={400}\n overflow={\"auto\"}\n >\n {_options?.map((option, index) => (\n renderOption ? <div key={\"auto-complete\" + index + getLabel!(option)}>{renderOption(option, {\n onClick: () => {\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }\n })}</div> : <ListItem\n key={index}\n onClick={() => {\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }}\n >\n {getLabel!(option)}\n </ListItem>\n ))}\n </List>\n </Menu>\n </>\n )\n}\n\nexport default Autocomplete\n"],"names":["__rest","index","_jsx","Chip","IconButton","CircleProgress","_jsxs","_Fragment","Input","Menu","List","ListItem"],"mappings":";;;;;;;;;;;;;;AAkDA,MAAM,YAAY,GAAG,CAAC,EAAgG,KAAI;AAApG,IAAA,IAAA,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAA,GAAA,EAAoC,EAA/B,UAAU,GAAAA,YAAA,CAAA,EAAA,EAA3E,wEAA6E,CAAF;IAC9F,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAS;AACtD,IAAA,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;AACtD,IAAA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAM,IAAI,CAAC;AACnD,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AACnD,IAAA,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC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;AAET;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Autocomplete/index.tsx"],"sourcesContent":["import React, { ReactElement, useEffect } from 'react'\nimport Input from '../Input'\nimport Menu from '../Menu'\nimport List from '../List';\nimport ListItem, { ListItemProps } from '../ListItem';\nimport Chip from '../Chip';\nimport IconButton from '../IconButton';\nimport Close from '@xanui/icons/Close';\nimport CircleProgress from '../CircleProgress';\nimport { useBreakpointPropsType, UseColorTemplateColor } from '@xanui/core';\n\nexport type AutocompleteProps = {\n\n options: any[] | ((text: string) => Promise<any[]>)\n getLabel: (option: any) => string;\n onChange?: (value: any) => void;\n value?: any;\n multiple?: boolean;\n renderOption?: (option: any, props: any) => ReactElement<ListItemProps>\n\n // input props customization\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n\n}\n\nconst Autocomplete = ({ value, onChange, renderOption, options, getLabel, multiple, ...inputProps }: AutocompleteProps) => {\n const [_options, setOptions] = React.useState<any[]>()\n const [inputValue, setInputValue] = React.useState(\"\")\n const [timer, setTimer] = React.useState<any>(null)\n const [loading, setLoading] = React.useState(false)\n const [focused, setFocused] = React.useState(false)\n const [open, setOpen] = React.useState(false)\n const menuRef = React.useRef<any>(null)\n\n getLabel ??= (option: any) => option.toString();\n multiple ??= false;\n\n let startIcons = []\n if (inputProps.startIcon) {\n startIcons.push(inputProps.startIcon)\n }\n\n if (!!value && multiple && Array.isArray(value)) {\n value.map((v: any, index: number) => {\n startIcons.push(<Chip\n key={index}\n size=\"small\"\n label={getLabel!(v)}\n variant={\"fill\"}\n color=\"default\"\n endIcon={<IconButton\n size={20}\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n let newValue = Array.isArray(value) ? [...value] : []\n newValue = newValue.filter((val: any) => getLabel!(val) !== getLabel!(v))\n onChange && onChange(newValue)\n }}\n >\n <Close />\n </IconButton>}\n />)\n })\n }\n\n let endIcons = []\n if (inputProps.endIcon) {\n endIcons.push(inputProps.endIcon)\n }\n if (loading) {\n endIcons.push(<CircleProgress\n key=\"auto-complete-loading-icon\"\n size=\"small\"\n />)\n } else if (!!value && !multiple) {\n endIcons.unshift(<IconButton\n key=\"auto-complete-clear-button\"\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n onChange && onChange(null)\n setInputValue(\"\")\n }}\n >\n <Close />\n </IconButton>)\n }\n\n const loadOptions = async () => {\n setLoading(true)\n let results = []\n if (typeof options === 'function') {\n results = await options(inputValue)\n } else {\n results = options.filter(option => getLabel!(option).toLowerCase().includes(inputValue.toLowerCase()))\n }\n if (!multiple && inputValue) {\n const find = results.find(option => getLabel!(option).toLowerCase() == inputValue.toLowerCase())\n onChange && onChange(find || null)\n }\n setOptions(results)\n setOpen(true)\n setLoading(false)\n }\n\n useEffect(() => {\n if (focused) {\n clearTimeout(timer)\n setTimer(setTimeout(() => {\n loadOptions()\n }, 300))\n } else {\n setOpen(false)\n }\n }, [focused, inputValue])\n\n\n return (\n <>\n <Input\n {...inputProps as any}\n ref={menuRef}\n slotProps={{\n rootContainer: {\n flexWrap: 'wrap',\n ...(multiple ? { height: \"auto\", gap: .5 } : {})\n },\n input: {\n width: multiple ? 'initial' : '100%',\n flex: 1,\n minWidth: 20,\n }\n }}\n startIcon={startIcons.length ? startIcons : undefined}\n endIcon={endIcons}\n value={inputValue}\n onFocus={() => setFocused(true)}\n onKeyDown={(e) => {\n if (inputProps?.onKeyDown) {\n inputProps.onKeyDown(e)\n }\n if (multiple && e.key === 'Backspace' && inputValue === \"\" && Array.isArray(value) && value.length > 0) {\n let newValue = [...value]\n newValue.pop()\n onChange && onChange(newValue)\n }\n }}\n onChange={(e) => {\n const value = e.target.value;\n setInputValue(value)\n\n }}\n />\n <Menu\n target={open ? menuRef.current : null}\n onClickOutside={() => {\n setFocused(false)\n }}\n slotProps={{\n content: { minWidth: menuRef.current ? menuRef.current.offsetWidth : 'auto' }\n }}\n >\n <List\n maxHeight={400}\n overflow={\"auto\"}\n >\n {_options?.map((option, index) => (\n renderOption ? <div key={\"auto-complete\" + index + getLabel!(option)}>{renderOption(option, {\n onClick: () => {\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n setFocused(false)\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }\n })}</div> : <ListItem\n key={index}\n onClick={() => {\n\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n setFocused(false)\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }}\n >\n {getLabel!(option)}\n </ListItem>\n ))}\n </List>\n </Menu>\n </>\n )\n}\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AAC,MAAM,CAAC;gCAC5B,OAAO,CAAC,KAAK,CAAC;AACd,gCAAA,aAAa,CAAC,QAAS,CAAC,MAAM,CAAC,CAAC;gCAChC,UAAU,CAAC,EAAE,CAAC;4BACjB;AACH,wBAAA,CAAC,EAAA,QAAA,EAEA,QAAS,CAAC,MAAM,CAAC,EAAA,EArBb,KAAK,CAsBF,CACb,CAAC,EAAA,CACE,EAAA,CACH,CAAA,EAAA,CACP;AAET;;;;"}
|
package/Autocomplete/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from 'tslib';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { useEffect } from 'react';
|
|
4
4
|
import Input from '../Input/index.js';
|
|
5
5
|
import Menu from '../Menu/index.js';
|
|
6
6
|
import List from '../List/index.js';
|
|
@@ -16,13 +16,15 @@ const Autocomplete = (_a) => {
|
|
|
16
16
|
const [inputValue, setInputValue] = React.useState("");
|
|
17
17
|
const [timer, setTimer] = React.useState(null);
|
|
18
18
|
const [loading, setLoading] = React.useState(false);
|
|
19
|
+
const [focused, setFocused] = React.useState(false);
|
|
19
20
|
const [open, setOpen] = React.useState(false);
|
|
20
21
|
const menuRef = React.useRef(null);
|
|
21
22
|
getLabel !== null && getLabel !== void 0 ? getLabel : (getLabel = (option) => option.toString());
|
|
22
23
|
multiple !== null && multiple !== void 0 ? multiple : (multiple = false);
|
|
23
|
-
let startIcons = [
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
let startIcons = [];
|
|
25
|
+
if (inputProps.startIcon) {
|
|
26
|
+
startIcons.push(inputProps.startIcon);
|
|
27
|
+
}
|
|
26
28
|
if (!!value && multiple && Array.isArray(value)) {
|
|
27
29
|
value.map((v, index) => {
|
|
28
30
|
startIcons.push(jsx(Chip, { size: "small", label: getLabel(v), variant: "fill", color: "default", endIcon: jsx(IconButton, { size: 20, variant: "text", color: "default", onClick: (e) => {
|
|
@@ -33,27 +35,56 @@ const Autocomplete = (_a) => {
|
|
|
33
35
|
}, children: jsx(Close, {}) }) }, index));
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
|
-
let endIcons = [
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
let endIcons = [];
|
|
39
|
+
if (inputProps.endIcon) {
|
|
40
|
+
endIcons.push(inputProps.endIcon);
|
|
41
|
+
}
|
|
39
42
|
if (loading) {
|
|
40
43
|
endIcons.push(jsx(CircleProgress, { size: "small" }, "auto-complete-loading-icon"));
|
|
41
44
|
}
|
|
42
45
|
else if (!!value && !multiple) {
|
|
43
|
-
endIcons.
|
|
46
|
+
endIcons.unshift(jsx(IconButton, { variant: "text", color: "default", onClick: (e) => {
|
|
44
47
|
e.stopPropagation();
|
|
45
|
-
onChange && onChange(
|
|
48
|
+
onChange && onChange(null);
|
|
46
49
|
setInputValue("");
|
|
47
50
|
}, children: jsx(Close, {}) }, "auto-complete-clear-button"));
|
|
48
51
|
}
|
|
52
|
+
const loadOptions = async () => {
|
|
53
|
+
setLoading(true);
|
|
54
|
+
let results = [];
|
|
55
|
+
if (typeof options === 'function') {
|
|
56
|
+
results = await options(inputValue);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
results = options.filter(option => getLabel(option).toLowerCase().includes(inputValue.toLowerCase()));
|
|
60
|
+
}
|
|
61
|
+
if (!multiple && inputValue) {
|
|
62
|
+
const find = results.find(option => getLabel(option).toLowerCase() == inputValue.toLowerCase());
|
|
63
|
+
onChange && onChange(find || null);
|
|
64
|
+
}
|
|
65
|
+
setOptions(results);
|
|
66
|
+
setOpen(true);
|
|
67
|
+
setLoading(false);
|
|
68
|
+
};
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (focused) {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
setTimer(setTimeout(() => {
|
|
73
|
+
loadOptions();
|
|
74
|
+
}, 300));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
setOpen(false);
|
|
78
|
+
}
|
|
79
|
+
}, [focused, inputValue]);
|
|
49
80
|
return (jsxs(Fragment, { children: [jsx(Input, Object.assign({}, inputProps, { ref: menuRef, slotProps: {
|
|
50
81
|
rootContainer: Object.assign({ flexWrap: 'wrap' }, (multiple ? { height: "auto", gap: .5 } : {})),
|
|
51
82
|
input: {
|
|
52
|
-
width: multiple ? '
|
|
83
|
+
width: multiple ? 'initial' : '100%',
|
|
53
84
|
flex: 1,
|
|
54
85
|
minWidth: 20,
|
|
55
86
|
}
|
|
56
|
-
}, startIcon: startIcons, endIcon: endIcons, value: inputValue, onKeyDown: (e) => {
|
|
87
|
+
}, startIcon: startIcons.length ? startIcons : undefined, endIcon: endIcons, value: inputValue, onFocus: () => setFocused(true), onKeyDown: (e) => {
|
|
57
88
|
if (inputProps === null || inputProps === void 0 ? void 0 : inputProps.onKeyDown) {
|
|
58
89
|
inputProps.onKeyDown(e);
|
|
59
90
|
}
|
|
@@ -65,28 +96,8 @@ const Autocomplete = (_a) => {
|
|
|
65
96
|
}, onChange: (e) => {
|
|
66
97
|
const value = e.target.value;
|
|
67
98
|
setInputValue(value);
|
|
68
|
-
if (!value) {
|
|
69
|
-
setOptions([]);
|
|
70
|
-
setOpen(false);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
setOpen(true);
|
|
74
|
-
clearTimeout(timer);
|
|
75
|
-
setTimer(setTimeout(async () => {
|
|
76
|
-
if (typeof options === 'function') {
|
|
77
|
-
setLoading(true);
|
|
78
|
-
const result = await options(value);
|
|
79
|
-
setOptions(result);
|
|
80
|
-
setLoading(false);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
const filtered = options.filter(option => getLabel(option).toLowerCase().includes(value.toLowerCase()));
|
|
84
|
-
setOptions(filtered);
|
|
85
|
-
}
|
|
86
|
-
}, 300));
|
|
87
99
|
} })), jsx(Menu, { target: open ? menuRef.current : null, onClickOutside: () => {
|
|
88
|
-
|
|
89
|
-
setInputValue("");
|
|
100
|
+
setFocused(false);
|
|
90
101
|
}, slotProps: {
|
|
91
102
|
content: { minWidth: menuRef.current ? menuRef.current.offsetWidth : 'auto' }
|
|
92
103
|
}, children: jsx(List, { maxHeight: 400, overflow: "auto", children: _options === null || _options === void 0 ? void 0 : _options.map((option, index) => (renderOption ? jsx("div", { children: renderOption(option, {
|
|
@@ -103,6 +114,7 @@ const Autocomplete = (_a) => {
|
|
|
103
114
|
onChange && onChange(newValue);
|
|
104
115
|
}
|
|
105
116
|
else {
|
|
117
|
+
setFocused(false);
|
|
106
118
|
onChange && onChange(option);
|
|
107
119
|
setOpen(false);
|
|
108
120
|
setInputValue(getLabel(option));
|
|
@@ -122,6 +134,7 @@ const Autocomplete = (_a) => {
|
|
|
122
134
|
onChange && onChange(newValue);
|
|
123
135
|
}
|
|
124
136
|
else {
|
|
137
|
+
setFocused(false);
|
|
125
138
|
onChange && onChange(option);
|
|
126
139
|
setOpen(false);
|
|
127
140
|
setInputValue(getLabel(option));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Autocomplete/index.tsx"],"sourcesContent":["import React, { ReactElement } from 'react'\nimport Input from '../Input'\nimport Menu from '../Menu'\nimport List from '../List';\nimport ListItem, { ListItemProps } from '../ListItem';\nimport Chip from '../Chip';\nimport IconButton from '../IconButton';\nimport Close from '@xanui/icons/Close';\nimport CircleProgress from '../CircleProgress';\nimport { useBreakpointPropsType, UseColorTemplateColor } from '@xanui/core';\n\nexport type AutocompleteProps = {\n\n options: any[] | ((text: string) => Promise<any[]>)\n getLabel: (option: any) => string;\n onChange?: (value: any) => void;\n value?: any;\n multiple?: boolean;\n renderOption?: (option: any, props: any) => ReactElement<ListItemProps>\n\n // input props customization\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n\n}\n\nconst Autocomplete = ({ value, onChange, renderOption, options, getLabel, multiple, ...inputProps }: AutocompleteProps) => {\n const [_options, setOptions] = React.useState<any[]>()\n const [inputValue, setInputValue] = React.useState(\"\")\n const [timer, setTimer] = React.useState<any>(null)\n const [loading, setLoading] = React.useState(false)\n const [open, setOpen] = React.useState(false)\n const menuRef = React.useRef<any>(null)\n\n getLabel ??= (option: any) => option.toString();\n multiple ??= false;\n\n let startIcons = [\n inputProps.startIcon\n ]\n\n if (!!value && multiple && Array.isArray(value)) {\n value.map((v: any, index: number) => {\n startIcons.push(<Chip\n key={index}\n size=\"small\"\n label={getLabel!(v)}\n variant={\"fill\"}\n color=\"default\"\n endIcon={<IconButton\n size={20}\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n let newValue = Array.isArray(value) ? [...value] : []\n newValue = newValue.filter((val: any) => getLabel!(val) !== getLabel!(v))\n onChange && onChange(newValue)\n }}\n >\n <Close />\n </IconButton>}\n />)\n })\n }\n\n let endIcons = [\n inputProps.endIcon\n ]\n\n if (loading) {\n endIcons.push(<CircleProgress\n key=\"auto-complete-loading-icon\"\n size=\"small\"\n />)\n } else if (!!value && !multiple) {\n endIcons.push(<IconButton\n key=\"auto-complete-clear-button\"\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n onChange && onChange(undefined)\n setInputValue(\"\")\n }}\n >\n <Close />\n </IconButton>)\n }\n\n\n return (\n <>\n <Input\n {...inputProps as any}\n ref={menuRef}\n slotProps={{\n rootContainer: {\n flexWrap: 'wrap',\n ...(multiple ? { height: \"auto\", gap: .5 } : {})\n },\n input: {\n width: multiple ? 'auto' : '100%',\n flex: 1,\n minWidth: 20,\n }\n }}\n startIcon={startIcons}\n endIcon={endIcons}\n value={inputValue}\n onKeyDown={(e) => {\n if (inputProps?.onKeyDown) {\n inputProps.onKeyDown(e)\n }\n if (multiple && e.key === 'Backspace' && inputValue === \"\" && Array.isArray(value) && value.length > 0) {\n let newValue = [...value]\n newValue.pop()\n onChange && onChange(newValue)\n }\n }}\n onChange={(e) => {\n const value = e.target.value;\n setInputValue(value)\n if (!value) {\n setOptions([])\n setOpen(false)\n return;\n }\n setOpen(true)\n\n clearTimeout(timer)\n setTimer(setTimeout(async () => {\n if (typeof options === 'function') {\n setLoading(true)\n const result = await options(value)\n setOptions(result)\n setLoading(false)\n } else {\n const filtered = options.filter(option => getLabel!(option).toLowerCase().includes(value.toLowerCase()))\n setOptions(filtered)\n }\n }, 300))\n }}\n />\n <Menu\n target={open ? menuRef.current : null}\n onClickOutside={() => {\n setOptions([])\n setInputValue(\"\")\n }}\n slotProps={{\n content: { minWidth: menuRef.current ? menuRef.current.offsetWidth : 'auto' }\n }}\n >\n <List\n maxHeight={400}\n overflow={\"auto\"}\n >\n {_options?.map((option, index) => (\n renderOption ? <div key={\"auto-complete\" + index + getLabel!(option)}>{renderOption(option, {\n onClick: () => {\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }\n })}</div> : <ListItem\n key={index}\n onClick={() => {\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }}\n >\n {getLabel!(option)}\n </ListItem>\n ))}\n </List>\n </Menu>\n </>\n )\n}\n\nexport default Autocomplete\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;;;;AAkDA,MAAM,YAAY,GAAG,CAAC,EAAgG,KAAI;AAApG,IAAA,IAAA,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAA,GAAA,EAAoC,EAA/B,UAAU,GAAA,MAAA,CAAA,EAAA,EAA3E,wEAA6E,CAAF;IAC9F,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAS;AACtD,IAAA,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;AACtD,IAAA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAM,IAAI,CAAC;AACnD,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;AACnD,IAAA,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAM,IAAI,CAAC;AAEvC,IAAA,QAAQ,aAAR,QAAQ,KAAA,MAAA,GAAR,QAAQ,IAAR,QAAQ,GAAK,CAA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,CAAC,QAAS,CAAC,MAAM,CAAC,CAAC;oCAChC,UAAU,CAAC,EAAE,CAAC;gCACjB;4BACH;AACF,yBAAA,CAAC,IAlBuB,eAAe,GAAG,KAAK,GAAG,QAAS,CAAC,MAAM,CAAC,CAkB3D,GAAGA,GAAA,CAAC,QAAQ,IAElB,OAAO,EAAE,MAAK;4BACX,IAAI,QAAQ,EAAE;AACX,gCAAA,IAAI,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE;gCACrD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAM,KAAK,QAAS,CAAC,CAAC,CAAC,KAAK,QAAS,CAAC,MAAM,CAAC,CAAC;gCACzE,IAAI,CAAC,GAAG,EAAE;AACP,oCAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;gCACxB;qCAAO;oCACJ,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAM,KAAK,QAAS,CAAC,CAAC,CAAC,KAAK,QAAS,CAAC,MAAM,CAAC,CAAC;gCAC7E;AACA,gCAAA,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC;4BACjC;iCAAO;AACJ,gCAAA,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC;gCAC5B,OAAO,CAAC,KAAK,CAAC;AACd,gCAAA,aAAa,CAAC,QAAS,CAAC,MAAM,CAAC,CAAC;gCAChC,UAAU,CAAC,EAAE,CAAC;4BACjB;AACH,wBAAA,CAAC,EAAA,QAAA,EAEA,QAAS,CAAC,MAAM,CAAC,EAAA,EAnBb,KAAK,CAoBF,CACb,CAAC,EAAA,CACE,EAAA,CACH,CAAA,EAAA,CACP;AAET;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Autocomplete/index.tsx"],"sourcesContent":["import React, { ReactElement, useEffect } from 'react'\nimport Input from '../Input'\nimport Menu from '../Menu'\nimport List from '../List';\nimport ListItem, { ListItemProps } from '../ListItem';\nimport Chip from '../Chip';\nimport IconButton from '../IconButton';\nimport Close from '@xanui/icons/Close';\nimport CircleProgress from '../CircleProgress';\nimport { useBreakpointPropsType, UseColorTemplateColor } from '@xanui/core';\n\nexport type AutocompleteProps = {\n\n options: any[] | ((text: string) => Promise<any[]>)\n getLabel: (option: any) => string;\n onChange?: (value: any) => void;\n value?: any;\n multiple?: boolean;\n renderOption?: (option: any, props: any) => ReactElement<ListItemProps>\n\n // input props customization\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n\n}\n\nconst Autocomplete = ({ value, onChange, renderOption, options, getLabel, multiple, ...inputProps }: AutocompleteProps) => {\n const [_options, setOptions] = React.useState<any[]>()\n const [inputValue, setInputValue] = React.useState(\"\")\n const [timer, setTimer] = React.useState<any>(null)\n const [loading, setLoading] = React.useState(false)\n const [focused, setFocused] = React.useState(false)\n const [open, setOpen] = React.useState(false)\n const menuRef = React.useRef<any>(null)\n\n getLabel ??= (option: any) => option.toString();\n multiple ??= false;\n\n let startIcons = []\n if (inputProps.startIcon) {\n startIcons.push(inputProps.startIcon)\n }\n\n if (!!value && multiple && Array.isArray(value)) {\n value.map((v: any, index: number) => {\n startIcons.push(<Chip\n key={index}\n size=\"small\"\n label={getLabel!(v)}\n variant={\"fill\"}\n color=\"default\"\n endIcon={<IconButton\n size={20}\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n let newValue = Array.isArray(value) ? [...value] : []\n newValue = newValue.filter((val: any) => getLabel!(val) !== getLabel!(v))\n onChange && onChange(newValue)\n }}\n >\n <Close />\n </IconButton>}\n />)\n })\n }\n\n let endIcons = []\n if (inputProps.endIcon) {\n endIcons.push(inputProps.endIcon)\n }\n if (loading) {\n endIcons.push(<CircleProgress\n key=\"auto-complete-loading-icon\"\n size=\"small\"\n />)\n } else if (!!value && !multiple) {\n endIcons.unshift(<IconButton\n key=\"auto-complete-clear-button\"\n variant={\"text\"}\n color=\"default\"\n onClick={(e) => {\n e.stopPropagation();\n onChange && onChange(null)\n setInputValue(\"\")\n }}\n >\n <Close />\n </IconButton>)\n }\n\n const loadOptions = async () => {\n setLoading(true)\n let results = []\n if (typeof options === 'function') {\n results = await options(inputValue)\n } else {\n results = options.filter(option => getLabel!(option).toLowerCase().includes(inputValue.toLowerCase()))\n }\n if (!multiple && inputValue) {\n const find = results.find(option => getLabel!(option).toLowerCase() == inputValue.toLowerCase())\n onChange && onChange(find || null)\n }\n setOptions(results)\n setOpen(true)\n setLoading(false)\n }\n\n useEffect(() => {\n if (focused) {\n clearTimeout(timer)\n setTimer(setTimeout(() => {\n loadOptions()\n }, 300))\n } else {\n setOpen(false)\n }\n }, [focused, inputValue])\n\n\n return (\n <>\n <Input\n {...inputProps as any}\n ref={menuRef}\n slotProps={{\n rootContainer: {\n flexWrap: 'wrap',\n ...(multiple ? { height: \"auto\", gap: .5 } : {})\n },\n input: {\n width: multiple ? 'initial' : '100%',\n flex: 1,\n minWidth: 20,\n }\n }}\n startIcon={startIcons.length ? startIcons : undefined}\n endIcon={endIcons}\n value={inputValue}\n onFocus={() => setFocused(true)}\n onKeyDown={(e) => {\n if (inputProps?.onKeyDown) {\n inputProps.onKeyDown(e)\n }\n if (multiple && e.key === 'Backspace' && inputValue === \"\" && Array.isArray(value) && value.length > 0) {\n let newValue = [...value]\n newValue.pop()\n onChange && onChange(newValue)\n }\n }}\n onChange={(e) => {\n const value = e.target.value;\n setInputValue(value)\n\n }}\n />\n <Menu\n target={open ? menuRef.current : null}\n onClickOutside={() => {\n setFocused(false)\n }}\n slotProps={{\n content: { minWidth: menuRef.current ? menuRef.current.offsetWidth : 'auto' }\n }}\n >\n <List\n maxHeight={400}\n overflow={\"auto\"}\n >\n {_options?.map((option, index) => (\n renderOption ? <div key={\"auto-complete\" + index + getLabel!(option)}>{renderOption(option, {\n onClick: () => {\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n setFocused(false)\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }\n })}</div> : <ListItem\n key={index}\n onClick={() => {\n\n if (multiple) {\n let newValue = Array.isArray(value) ? [...value] : []\n const has = newValue.find((v: any) => getLabel!(v) === getLabel!(option))\n if (!has) {\n newValue.push(option)\n } else {\n newValue = newValue.filter((v: any) => getLabel!(v) !== getLabel!(option))\n }\n onChange && onChange(newValue)\n } else {\n setFocused(false)\n onChange && onChange(option)\n setOpen(false)\n setInputValue(getLabel!(option))\n setOptions([])\n }\n }}\n >\n {getLabel!(option)}\n </ListItem>\n ))}\n </List>\n </Menu>\n </>\n )\n}\n\nexport default Autocomplete\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;;;;AAkDA,MAAM,YAAY,GAAG,CAAC,EAAgG,KAAI;AAApG,IAAA,IAAA,EAAE,KAAK,EAAE,QAA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ArBb,KAAK,CAsBF,CACb,CAAC,EAAA,CACE,EAAA,CACH,CAAA,EAAA,CACP;AAET;;;;"}
|
package/Chip/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var core = require('@xanui/core');
|
|
|
7
7
|
var index = require('../useCorner/index.cjs');
|
|
8
8
|
|
|
9
9
|
const Chip = React.forwardRef((props, ref) => {
|
|
10
|
-
let [_a] = core.useInterface("Chip", props, {}), { label, variant, startIcon, endIcon, color, corner, size } = _a, rest = tslib.__rest(_a, ["label", "variant", "startIcon", "endIcon", "color", "corner", "size"]);
|
|
10
|
+
let [_a] = core.useInterface("Chip", props, {}), { label, variant, startIcon, endIcon, color, corner, size, slotProps } = _a, rest = tslib.__rest(_a, ["label", "variant", "startIcon", "endIcon", "color", "corner", "size", "slotProps"]);
|
|
11
11
|
const _p = {};
|
|
12
12
|
if (label)
|
|
13
13
|
_p.label = label;
|
|
@@ -23,6 +23,8 @@ const Chip = React.forwardRef((props, ref) => {
|
|
|
23
23
|
_p.corner = corner;
|
|
24
24
|
if (size)
|
|
25
25
|
_p.size = size;
|
|
26
|
+
if (slotProps)
|
|
27
|
+
_p.slotProps = slotProps;
|
|
26
28
|
const p = core.useBreakpointProps(_p);
|
|
27
29
|
label = p.label;
|
|
28
30
|
startIcon = p.startIcon;
|
|
@@ -31,6 +33,7 @@ const Chip = React.forwardRef((props, ref) => {
|
|
|
31
33
|
variant = p.variant || "fill";
|
|
32
34
|
corner = p.corner || "circle";
|
|
33
35
|
size = p.size || "medium";
|
|
36
|
+
slotProps = p.slotProps;
|
|
34
37
|
rest.sx = rest.sx || {};
|
|
35
38
|
const cornerCss = index(corner);
|
|
36
39
|
const template = core.useColorTemplate(color, variant);
|
|
@@ -66,10 +69,11 @@ const Chip = React.forwardRef((props, ref) => {
|
|
|
66
69
|
whiteSpace: "nowrap",
|
|
67
70
|
overflow: "hidden",
|
|
68
71
|
},
|
|
69
|
-
}, baseClass: 'chip', ref: ref, children: [startIcon, jsxRuntime.jsx(core.Tag, { sxr: {
|
|
72
|
+
}, baseClass: 'chip', ref: ref, children: [startIcon, jsxRuntime.jsx(core.Tag, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.label, { baseClass: 'chip-label', sxr: {
|
|
70
73
|
alignItems: "center",
|
|
71
|
-
flexBox: true
|
|
72
|
-
|
|
74
|
+
flexBox: true,
|
|
75
|
+
color: template.primary.color + "!important"
|
|
76
|
+
}, children: label })), endIcon] })));
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
module.exports = Chip;
|
package/Chip/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Chip/index.tsx"],"sourcesContent":["import React, { ReactElement } from 'react';\nimport { Tag, TagProps, TagComponentType, useInterface, useColorTemplate, UseColorTemplateColor, UseColorTemplateType, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport useCorner, { UseCornerTypes } from '../useCorner'\n\n\n\nexport type ChipProps<T extends TagComponentType = 'div'> = Omit<TagProps<T>, \"color\" | \"children\" | \"size\"> & {\n label: useBreakpointPropsType<string | ReactElement>;\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n variant?: useBreakpointPropsType<UseColorTemplateType>;\n corner?: useBreakpointPropsType<UseCornerTypes>;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n}\n\n\nconst Chip = React.forwardRef(<T extends TagComponentType = 'div'>(props: ChipProps<T>, ref: React.Ref<any>) => {\n let [{ label, variant, startIcon, endIcon, color, corner, size, ...rest }] = useInterface<any>(\"Chip\", props, {})\n const _p: any = {}\n if (label) _p.label = label\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (corner) _p.corner = corner\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n\n label = p.label\n startIcon = p.startIcon\n endIcon = p.endIcon\n color = p.color || \"brand\"\n variant = p.variant || \"fill\"\n corner = p.corner || \"circle\"\n size = p.size || \"medium\"\n rest.sx = (rest as any).sx || {};\n\n const cornerCss = useCorner(corner)\n const template = useColorTemplate(color, variant)\n\n const sizes: any = {\n small: {\n height: 24,\n gap: .5,\n px: startIcon || endIcon ? .8 : 1,\n fontSize: \"small\"\n },\n medium: {\n height: 32,\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n fontSize: 'button',\n },\n large: {\n height: 40,\n fontSize: 'text',\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n }\n }\n\n return (\n <Tag\n {...cornerCss}\n {...template.primary}\n {...(sizes[size as any] || {})}\n {...rest}\n sxr={{\n display: \"inline-flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n transition: \"background .3s\",\n overflow: \"hidden\",\n\n \"& > *\": {\n flex: \"0 0 auto\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n },\n }}\n baseClass='chip'\n ref={ref}\n >\n {startIcon}\n <Tag\n sxr={{\n alignItems: \"center\",\n flexBox: true\n }}\n >{label}</Tag>\n {endIcon}\n </Tag>\n )\n})\n\nexport default Chip\n"],"names":["useInterface","__rest","useBreakpointProps","useCorner","useColorTemplate","_jsxs","Tag","_jsx"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Chip/index.tsx"],"sourcesContent":["import React, { ReactElement } from 'react';\nimport { Tag, TagProps, TagComponentType, useInterface, useColorTemplate, UseColorTemplateColor, UseColorTemplateType, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport useCorner, { UseCornerTypes } from '../useCorner'\n\n\n\nexport type ChipProps<T extends TagComponentType = 'div'> = Omit<TagProps<T>, \"color\" | \"children\" | \"size\"> & {\n label: useBreakpointPropsType<string | ReactElement>;\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n variant?: useBreakpointPropsType<UseColorTemplateType>;\n corner?: useBreakpointPropsType<UseCornerTypes>;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n\n slotProps?: {\n label?: Omit<TagProps<\"div\">, \"children\">\n }\n}\n\n\nconst Chip = React.forwardRef(<T extends TagComponentType = 'div'>(props: ChipProps<T>, ref: React.Ref<any>) => {\n let [{ label, variant, startIcon, endIcon, color, corner, size, slotProps, ...rest }] = useInterface<any>(\"Chip\", props, {})\n const _p: any = {}\n if (label) _p.label = label\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (corner) _p.corner = corner\n if (size) _p.size = size\n if (slotProps) _p.slotProps = slotProps\n const p: any = useBreakpointProps(_p)\n\n label = p.label\n startIcon = p.startIcon\n endIcon = p.endIcon\n color = p.color || \"brand\"\n variant = p.variant || \"fill\"\n corner = p.corner || \"circle\"\n size = p.size || \"medium\"\n slotProps = p.slotProps\n rest.sx = (rest as any).sx || {};\n\n const cornerCss = useCorner(corner)\n const template = useColorTemplate(color, variant)\n\n const sizes: any = {\n small: {\n height: 24,\n gap: .5,\n px: startIcon || endIcon ? .8 : 1,\n fontSize: \"small\"\n },\n medium: {\n height: 32,\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n fontSize: 'button',\n },\n large: {\n height: 40,\n fontSize: 'text',\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n }\n }\n\n return (\n <Tag\n {...cornerCss}\n {...template.primary}\n {...(sizes[size as any] || {})}\n {...rest}\n sxr={{\n display: \"inline-flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n transition: \"background .3s\",\n overflow: \"hidden\",\n\n \"& > *\": {\n flex: \"0 0 auto\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n },\n }}\n baseClass='chip'\n ref={ref}\n >\n {startIcon}\n <Tag\n {...slotProps?.label}\n baseClass='chip-label'\n sxr={{\n alignItems: \"center\",\n flexBox: true,\n color: template.primary.color + \"!important\"\n }}\n >{label}</Tag>\n {endIcon}\n </Tag>\n )\n})\n\nexport default Chip\n"],"names":["useInterface","__rest","useBreakpointProps","useCorner","useColorTemplate","_jsxs","Tag","_jsx"],"mappings":";;;;;;;;AAqBA,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAqC,KAAmB,EAAE,GAAmB,KAAI;AAC3G,IAAA,IAAI,CAAA,EAAA,CAAA,GAAoFA,iBAAY,CAAM,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,EAAvH,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAA,GAAA,EAAW,EAAN,IAAI,GAAAC,YAAA,CAAA,EAAA,EAA7E,CAAA,OAAA,EAAA,SAAA,EAAA,WAAA,EAAA,SAAA,EAAA,OAAA,EAAA,QAAA,EAAA,MAAA,EAAA,WAAA,CAA+E,CAAwC;IAC5H,MAAM,EAAE,GAAQ,EAAE;AAClB,IAAA,IAAI,KAAK;AAAE,QAAA,EAAE,CAAC,KAAK,GAAG,KAAK;AAC3B,IAAA,IAAI,SAAS;AAAE,QAAA,EAAE,CAAC,SAAS,GAAG,SAAS;AACvC,IAAA,IAAI,OAAO;AAAE,QAAA,EAAE,CAAC,OAAO,GAAG,OAAO;AACjC,IAAA,IAAI,KAAK;AAAE,QAAA,EAAE,CAAC,KAAK,GAAG,KAAK;AAC3B,IAAA,IAAI,OAAO;AAAE,QAAA,EAAE,CAAC,OAAO,GAAG,OAAO;AACjC,IAAA,IAAI,MAAM;AAAE,QAAA,EAAE,CAAC,MAAM,GAAG,MAAM;AAC9B,IAAA,IAAI,IAAI;AAAE,QAAA,EAAE,CAAC,IAAI,GAAG,IAAI;AACxB,IAAA,IAAI,SAAS;AAAE,QAAA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ACJ;IAED,QACIC,gBAACC,QAAG,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACI,SAAS,EACT,QAAQ,CAAC,OAAO,GACf,KAAK,CAAC,IAAW,CAAC,IAAI,EAAE,GACzB,IAAI,EAAA,EACR,GAAG,EAAE;AACD,YAAA,OAAO,EAAE,aAAa;AACtB,YAAA,aAAa,EAAE,KAAK;AACpB,YAAA,UAAU,EAAE,QAAQ;AACpB,YAAA,UAAU,EAAE,gBAAgB;AAC5B,YAAA,QAAQ,EAAE,QAAQ;AAElB,YAAA,QAAQ,EAAE;AACN,gBAAA,IAAI,EAAE,UAAU;AAChB,gBAAA,YAAY,EAAE,UAAU;AACxB,gBAAA,UAAU,EAAE,QAAQ;AACpB,gBAAA,QAAQ,EAAE,QAAQ;AACrB,aAAA;SACJ,EACD,SAAS,EAAC,MAAM,EAChB,GAAG,EAAE,GAAG,EAAA,QAAA,EAAA,CAEP,SAAS,EACVC,cAAA,CAACD,QAAG,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACI,SAAS,KAAA,IAAA,IAAT,SAAS,KAAA,MAAA,GAAA,MAAA,GAAT,SAAS,CAAE,KAAK,EAAA,EACpB,SAAS,EAAC,YAAY,EACtB,GAAG,EAAE;AACD,oBAAA,UAAU,EAAE,QAAQ;AACpB,oBAAA,OAAO,EAAE,IAAI;AACb,oBAAA,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG;AACnC,iBAAA,EAAA,QAAA,EACH,KAAK,EAAA,CAAA,CAAO,EACb,OAAO,CAAA,EAAA,CAAA,CACN;AAEd,CAAC;;;;"}
|
package/Chip/index.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ type ChipProps<T extends TagComponentType = 'div'> = Omit<TagProps<T>, "color" |
|
|
|
10
10
|
variant?: useBreakpointPropsType<UseColorTemplateType>;
|
|
11
11
|
corner?: useBreakpointPropsType<UseCornerTypes>;
|
|
12
12
|
size?: useBreakpointPropsType<"small" | "medium" | "large">;
|
|
13
|
+
slotProps?: {
|
|
14
|
+
label?: Omit<TagProps<"div">, "children">;
|
|
15
|
+
};
|
|
13
16
|
};
|
|
14
17
|
declare const Chip: React.ForwardRefExoticComponent<Omit<ChipProps<TagComponentType>, "ref"> & React.RefAttributes<any>>;
|
|
15
18
|
|
package/Chip/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { useInterface, useBreakpointProps, useColorTemplate, Tag } from '@xanui/
|
|
|
5
5
|
import useCorner from '../useCorner/index.js';
|
|
6
6
|
|
|
7
7
|
const Chip = React.forwardRef((props, ref) => {
|
|
8
|
-
let [_a] = useInterface("Chip", props, {}), { label, variant, startIcon, endIcon, color, corner, size } = _a, rest = __rest(_a, ["label", "variant", "startIcon", "endIcon", "color", "corner", "size"]);
|
|
8
|
+
let [_a] = useInterface("Chip", props, {}), { label, variant, startIcon, endIcon, color, corner, size, slotProps } = _a, rest = __rest(_a, ["label", "variant", "startIcon", "endIcon", "color", "corner", "size", "slotProps"]);
|
|
9
9
|
const _p = {};
|
|
10
10
|
if (label)
|
|
11
11
|
_p.label = label;
|
|
@@ -21,6 +21,8 @@ const Chip = React.forwardRef((props, ref) => {
|
|
|
21
21
|
_p.corner = corner;
|
|
22
22
|
if (size)
|
|
23
23
|
_p.size = size;
|
|
24
|
+
if (slotProps)
|
|
25
|
+
_p.slotProps = slotProps;
|
|
24
26
|
const p = useBreakpointProps(_p);
|
|
25
27
|
label = p.label;
|
|
26
28
|
startIcon = p.startIcon;
|
|
@@ -29,6 +31,7 @@ const Chip = React.forwardRef((props, ref) => {
|
|
|
29
31
|
variant = p.variant || "fill";
|
|
30
32
|
corner = p.corner || "circle";
|
|
31
33
|
size = p.size || "medium";
|
|
34
|
+
slotProps = p.slotProps;
|
|
32
35
|
rest.sx = rest.sx || {};
|
|
33
36
|
const cornerCss = useCorner(corner);
|
|
34
37
|
const template = useColorTemplate(color, variant);
|
|
@@ -64,10 +67,11 @@ const Chip = React.forwardRef((props, ref) => {
|
|
|
64
67
|
whiteSpace: "nowrap",
|
|
65
68
|
overflow: "hidden",
|
|
66
69
|
},
|
|
67
|
-
}, baseClass: 'chip', ref: ref, children: [startIcon, jsx(Tag, { sxr: {
|
|
70
|
+
}, baseClass: 'chip', ref: ref, children: [startIcon, jsx(Tag, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.label, { baseClass: 'chip-label', sxr: {
|
|
68
71
|
alignItems: "center",
|
|
69
|
-
flexBox: true
|
|
70
|
-
|
|
72
|
+
flexBox: true,
|
|
73
|
+
color: template.primary.color + "!important"
|
|
74
|
+
}, children: label })), endIcon] })));
|
|
71
75
|
});
|
|
72
76
|
|
|
73
77
|
export { Chip as default };
|
package/Chip/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Chip/index.tsx"],"sourcesContent":["import React, { ReactElement } from 'react';\nimport { Tag, TagProps, TagComponentType, useInterface, useColorTemplate, UseColorTemplateColor, UseColorTemplateType, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport useCorner, { UseCornerTypes } from '../useCorner'\n\n\n\nexport type ChipProps<T extends TagComponentType = 'div'> = Omit<TagProps<T>, \"color\" | \"children\" | \"size\"> & {\n label: useBreakpointPropsType<string | ReactElement>;\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n variant?: useBreakpointPropsType<UseColorTemplateType>;\n corner?: useBreakpointPropsType<UseCornerTypes>;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n}\n\n\nconst Chip = React.forwardRef(<T extends TagComponentType = 'div'>(props: ChipProps<T>, ref: React.Ref<any>) => {\n let [{ label, variant, startIcon, endIcon, color, corner, size, ...rest }] = useInterface<any>(\"Chip\", props, {})\n const _p: any = {}\n if (label) _p.label = label\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (corner) _p.corner = corner\n if (size) _p.size = size\n const p: any = useBreakpointProps(_p)\n\n label = p.label\n startIcon = p.startIcon\n endIcon = p.endIcon\n color = p.color || \"brand\"\n variant = p.variant || \"fill\"\n corner = p.corner || \"circle\"\n size = p.size || \"medium\"\n rest.sx = (rest as any).sx || {};\n\n const cornerCss = useCorner(corner)\n const template = useColorTemplate(color, variant)\n\n const sizes: any = {\n small: {\n height: 24,\n gap: .5,\n px: startIcon || endIcon ? .8 : 1,\n fontSize: \"small\"\n },\n medium: {\n height: 32,\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n fontSize: 'button',\n },\n large: {\n height: 40,\n fontSize: 'text',\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n }\n }\n\n return (\n <Tag\n {...cornerCss}\n {...template.primary}\n {...(sizes[size as any] || {})}\n {...rest}\n sxr={{\n display: \"inline-flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n transition: \"background .3s\",\n overflow: \"hidden\",\n\n \"& > *\": {\n flex: \"0 0 auto\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n },\n }}\n baseClass='chip'\n ref={ref}\n >\n {startIcon}\n <Tag\n sxr={{\n alignItems: \"center\",\n flexBox: true\n }}\n >{label}</Tag>\n {endIcon}\n </Tag>\n )\n})\n\nexport default Chip\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Chip/index.tsx"],"sourcesContent":["import React, { ReactElement } from 'react';\nimport { Tag, TagProps, TagComponentType, useInterface, useColorTemplate, UseColorTemplateColor, UseColorTemplateType, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\nimport useCorner, { UseCornerTypes } from '../useCorner'\n\n\n\nexport type ChipProps<T extends TagComponentType = 'div'> = Omit<TagProps<T>, \"color\" | \"children\" | \"size\"> & {\n label: useBreakpointPropsType<string | ReactElement>;\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n variant?: useBreakpointPropsType<UseColorTemplateType>;\n corner?: useBreakpointPropsType<UseCornerTypes>;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n\n slotProps?: {\n label?: Omit<TagProps<\"div\">, \"children\">\n }\n}\n\n\nconst Chip = React.forwardRef(<T extends TagComponentType = 'div'>(props: ChipProps<T>, ref: React.Ref<any>) => {\n let [{ label, variant, startIcon, endIcon, color, corner, size, slotProps, ...rest }] = useInterface<any>(\"Chip\", props, {})\n const _p: any = {}\n if (label) _p.label = label\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (corner) _p.corner = corner\n if (size) _p.size = size\n if (slotProps) _p.slotProps = slotProps\n const p: any = useBreakpointProps(_p)\n\n label = p.label\n startIcon = p.startIcon\n endIcon = p.endIcon\n color = p.color || \"brand\"\n variant = p.variant || \"fill\"\n corner = p.corner || \"circle\"\n size = p.size || \"medium\"\n slotProps = p.slotProps\n rest.sx = (rest as any).sx || {};\n\n const cornerCss = useCorner(corner)\n const template = useColorTemplate(color, variant)\n\n const sizes: any = {\n small: {\n height: 24,\n gap: .5,\n px: startIcon || endIcon ? .8 : 1,\n fontSize: \"small\"\n },\n medium: {\n height: 32,\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n fontSize: 'button',\n },\n large: {\n height: 40,\n fontSize: 'text',\n gap: 1,\n px: startIcon || endIcon ? .8 : 1.5,\n }\n }\n\n return (\n <Tag\n {...cornerCss}\n {...template.primary}\n {...(sizes[size as any] || {})}\n {...rest}\n sxr={{\n display: \"inline-flex\",\n flexDirection: \"row\",\n alignItems: \"center\",\n transition: \"background .3s\",\n overflow: \"hidden\",\n\n \"& > *\": {\n flex: \"0 0 auto\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n },\n }}\n baseClass='chip'\n ref={ref}\n >\n {startIcon}\n <Tag\n {...slotProps?.label}\n baseClass='chip-label'\n sxr={{\n alignItems: \"center\",\n flexBox: true,\n color: template.primary.color + \"!important\"\n }}\n >{label}</Tag>\n {endIcon}\n </Tag>\n )\n})\n\nexport default Chip\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;AAqBA,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAqC,KAAmB,EAAE,GAAmB,KAAI;AAC3G,IAAA,IAAI,CAAA,EAAA,CAAA,GAAoF,YAAY,CAAM,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,EAAvH,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAA,GAAA,EAAW,EAAN,IAAI,GAAA,MAAA,CAAA,EAAA,EAA7E,CAAA,OAAA,EAAA,SAAA,EAAA,WAAA,EAAA,SAAA,EAAA,OAAA,EAAA,QAAA,EAAA,MAAA,EAAA,WAAA,CAA+E,CAAwC;IAC5H,MAAM,EAAE,GAAQ,EAAE;AAClB,IAAA,IAAI,KAAK;AAAE,QAAA,EAAE,CAAC,KAAK,GAAG,KAAK;AAC3B,IAAA,IAAI,SAAS;AAAE,QAAA,EAAE,CAAC,SAAS,GAAG,SAAS;AACvC,IAAA,IAAI,OAAO;AAAE,QAAA,EAAE,CAAC,OAAO,GAAG,OAAO;AACjC,IAAA,IAAI,KAAK;AAAE,QAAA,EAAE,CAAC,KAAK,GAAG,KAAK;AAC3B,IAAA,IAAI,OAAO;AAAE,QAAA,EAAE,CAAC,OAAO,GAAG,OAAO;AACjC,IAAA,IAAI,MAAM;AAAE,QAAA,EAAE,CAAC,MAAM,GAAG,MAAM;AAC9B,IAAA,IAAI,IAAI;AAAE,QAAA,EAAE,CAAC,IAAI,GAAG,IAAI;AACxB,IAAA,IAAI,SAAS;AAAE,QAAA,EAAE,CA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IA,KAAC,GAAG,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACI,SAAS,EACT,QAAQ,CAAC,OAAO,GACf,KAAK,CAAC,IAAW,CAAC,IAAI,EAAE,GACzB,IAAI,EAAA,EACR,GAAG,EAAE;AACD,YAAA,OAAO,EAAE,aAAa;AACtB,YAAA,aAAa,EAAE,KAAK;AACpB,YAAA,UAAU,EAAE,QAAQ;AACpB,YAAA,UAAU,EAAE,gBAAgB;AAC5B,YAAA,QAAQ,EAAE,QAAQ;AAElB,YAAA,QAAQ,EAAE;AACN,gBAAA,IAAI,EAAE,UAAU;AAChB,gBAAA,YAAY,EAAE,UAAU;AACxB,gBAAA,UAAU,EAAE,QAAQ;AACpB,gBAAA,QAAQ,EAAE,QAAQ;AACrB,aAAA;SACJ,EACD,SAAS,EAAC,MAAM,EAChB,GAAG,EAAE,GAAG,EAAA,QAAA,EAAA,CAEP,SAAS,EACVC,GAAA,CAAC,GAAG,EAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACI,SAAS,KAAA,IAAA,IAAT,SAAS,KAAA,MAAA,GAAA,MAAA,GAAT,SAAS,CAAE,KAAK,EAAA,EACpB,SAAS,EAAC,YAAY,EACtB,GAAG,EAAE;AACD,oBAAA,UAAU,EAAE,QAAQ;AACpB,oBAAA,OAAO,EAAE,IAAI;AACb,oBAAA,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG;AACnC,iBAAA,EAAA,QAAA,EACH,KAAK,EAAA,CAAA,CAAO,EACb,OAAO,CAAA,EAAA,CAAA,CACN;AAEd,CAAC;;;;"}
|
package/Datatable/index.cjs
CHANGED
|
@@ -52,17 +52,9 @@ const DataTable = React.forwardRef((props, ref) => {
|
|
|
52
52
|
let { rows, tabs, pagination: { perpages = [30, 50, 100], total = 0 } = {}, state: userState = {}, onChange, fixedHeader, hidePagination, slotProps,
|
|
53
53
|
// skip props for ViewBox
|
|
54
54
|
skeleton, rowAction, disableRow, renderRow, filters, hideCheckbox, hideSearch, columns, compact } = _props, viewBoxProps = tslib.__rest(_props, ["rows", "tabs", "pagination", "state", "onChange", "fixedHeader", "hidePagination", "slotProps", "skeleton", "rowAction", "disableRow", "renderRow", "filters", "hideCheckbox", "hideSearch", "columns", "compact"]);
|
|
55
|
-
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
const userperpage = (_c = userState === null || userState === void 0 ? void 0 : userState.pagination) === null || _c === void 0 ? void 0 : _c.perpage;
|
|
59
|
-
if (userperpage && perpages.includes(userperpage)) {
|
|
60
|
-
perpage = userperpage;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
perpage = (perpages === null || perpages === void 0 ? void 0 : perpages.length) ? perpages[0] : 10;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
55
|
+
const userperpage = (_a = userState === null || userState === void 0 ? void 0 : userState.pagination) === null || _a === void 0 ? void 0 : _a.perpage;
|
|
56
|
+
let perpage = userperpage && perpages.includes(userperpage) ? userperpage : perpages[0];
|
|
57
|
+
let page = (_c = (_b = userState === null || userState === void 0 ? void 0 : userState.pagination) === null || _b === void 0 ? void 0 : _b.page) !== null && _c !== void 0 ? _c : 1;
|
|
66
58
|
const state = {
|
|
67
59
|
selected: (_d = userState === null || userState === void 0 ? void 0 : userState.selected) !== null && _d !== void 0 ? _d : [],
|
|
68
60
|
selectAll: (_e = userState === null || userState === void 0 ? void 0 : userState.selectAll) !== null && _e !== void 0 ? _e : false,
|
package/Datatable/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Datatable/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useMemo } from 'react'\nimport ViewBox from '../ViewBox'\nimport { Tag, useInterface } from '@xanui/core';\nimport SelectedBox from './SelectedBox'\nimport TableArea from './Table'\nimport FilterBox from './FilterBox'\nimport TablePagination, { TablePaginationState } from '../TablePagination'\nimport Stack from '../Stack'\nimport { DatatableProps, DatatableState } from './types';\nimport Skeleton from '../Skeleton';\n\nexport type * from './types';\n\nconst DataTable = React.forwardRef((props: DatatableProps, ref: React.Ref<HTMLDivElement>) => {\n let [p] = useInterface<any>(\"Datatable\", props, {})\n\n let _props = useMemo(() => {\n let np = { ...p }\n\n if (typeof np.skeleton === 'number' || np.skeleton === true) {\n const limit = np.perpages && np.perpages.length > 0 ? np.perpages[0] : 10\n let length = np.skeleton === true ? limit : np.skeleton\n\n if (!np.hideCheckbox) {\n np.columns = [{\n label: '', field: \"__checkbox\", width: 34\n }, ...np.columns]\n }\n\n if (np.rowAction) {\n np.columns = [...np.columns, { label: \"\", field: \"__actions\", width: 34 }]\n }\n\n let columns = np.columns || []\n\n np.rows = []\n for (let i = 0; i < length; i++) {\n let r: any = { id: i }\n for (let col of columns) {\n r[col.field] = \"\"\n }\n np.rows.push(r)\n }\n\n np.renderRow = (r: any) => {\n for (let col of columns) {\n r[col.field] = <Skeleton\n animation={\"wave\"}\n height={16}\n radius={.5}\n width={\"100%\"}\n />\n }\n return r\n }\n np.hideCheckbox = true\n np.rowAction = undefined\n }\n return np\n }, [p])\n\n let {\n rows,\n tabs,\n\n pagination: { perpages = [30, 50, 100], total = 0 } = {},\n state: userState = {},\n onChange,\n\n fixedHeader,\n hidePagination,\n slotProps,\n\n\n // skip props for ViewBox\n skeleton,\n rowAction,\n disableRow,\n renderRow,\n filters,\n hideCheckbox,\n hideSearch,\n columns,\n compact,\n\n ...viewBoxProps\n } = _props\n\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Datatable/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useMemo } from 'react'\nimport ViewBox from '../ViewBox'\nimport { Tag, useInterface } from '@xanui/core';\nimport SelectedBox from './SelectedBox'\nimport TableArea from './Table'\nimport FilterBox from './FilterBox'\nimport TablePagination, { TablePaginationState } from '../TablePagination'\nimport Stack from '../Stack'\nimport { DatatableProps, DatatableState } from './types';\nimport Skeleton from '../Skeleton';\n\nexport type * from './types';\n\nconst DataTable = React.forwardRef((props: DatatableProps, ref: React.Ref<HTMLDivElement>) => {\n let [p] = useInterface<any>(\"Datatable\", props, {})\n\n let _props = useMemo(() => {\n let np = { ...p }\n\n if (typeof np.skeleton === 'number' || np.skeleton === true) {\n const limit = np.perpages && np.perpages.length > 0 ? np.perpages[0] : 10\n let length = np.skeleton === true ? limit : np.skeleton\n\n if (!np.hideCheckbox) {\n np.columns = [{\n label: '', field: \"__checkbox\", width: 34\n }, ...np.columns]\n }\n\n if (np.rowAction) {\n np.columns = [...np.columns, { label: \"\", field: \"__actions\", width: 34 }]\n }\n\n let columns = np.columns || []\n\n np.rows = []\n for (let i = 0; i < length; i++) {\n let r: any = { id: i }\n for (let col of columns) {\n r[col.field] = \"\"\n }\n np.rows.push(r)\n }\n\n np.renderRow = (r: any) => {\n for (let col of columns) {\n r[col.field] = <Skeleton\n animation={\"wave\"}\n height={16}\n radius={.5}\n width={\"100%\"}\n />\n }\n return r\n }\n np.hideCheckbox = true\n np.rowAction = undefined\n }\n return np\n }, [p])\n\n let {\n rows,\n tabs,\n\n pagination: { perpages = [30, 50, 100], total = 0 } = {},\n state: userState = {},\n onChange,\n\n fixedHeader,\n hidePagination,\n slotProps,\n\n\n // skip props for ViewBox\n skeleton,\n rowAction,\n disableRow,\n renderRow,\n filters,\n hideCheckbox,\n hideSearch,\n columns,\n compact,\n\n ...viewBoxProps\n } = _props\n\n const userperpage = userState?.pagination?.perpage\n let perpage = userperpage && perpages.includes(userperpage) ? userperpage : perpages[0]\n let page = userState?.pagination?.page ?? 1\n const state = {\n selected: userState?.selected ?? [],\n selectAll: userState?.selectAll ?? false,\n pagination: {\n page,\n perpage,\n from: page ? (perpage * (page - 1)) + 1 : 1,\n to: page ? perpage * page : perpage,\n },\n tab: tabs ? (userState?.tab ?? tabs[0].value ?? tabs[0].label.toLowerCase()) : \"\",\n search: userState?.search ?? \"\",\n sortable: userState?.sortable ?? {},\n filters: userState?.filters ?? {}\n }\n\n const update = (s: Partial<DatatableState>) => {\n onChange({ ...state, ...s })\n }\n\n return (\n <ViewBox\n height=\"100%\"\n {...viewBoxProps}\n baseClass='datatable'\n ref={ref as any}\n sx={{\n ...viewBoxProps?.sx,\n '& thead': fixedHeader ? {\n position: \"sticky\",\n top: 0,\n bgcolor: \"background.primary\",\n zIndex: 1\n } : {},\n }}\n startContent={(\n <Tag\n baseClass='datatable-header'\n sxr={{\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"space-between\"\n }}\n >\n <SelectedBox {..._props} update={update} state={state} />\n <FilterBox {..._props} update={update} state={state} />\n </Tag>\n )}\n >\n <TableArea\n {..._props}\n update={update}\n state={state}\n />\n <Stack\n p={1}\n alignItems=\"flex-end\"\n >\n {!hidePagination && <TablePagination\n disabled={_props.skeleton ? true : false}\n {...slotProps?.pagination}\n total={total || rows.length}\n page={state.pagination.page}\n perpage={state.pagination.perpage}\n perpages={perpages}\n slotProps={{\n select: {\n size: \"small\",\n }\n }}\n onChange={(state: TablePaginationState) => {\n update({ pagination: state })\n }}\n />}\n </Stack>\n </ViewBox>\n )\n})\n\nexport default DataTable"],"names":[],"mappings":";;;;;;;;;;;;;;;AAcA;;AACI;AAEA;AACI;AAEA;;AAEI;AAEA;;;AAGK;;AAGL;;;AAIA;AAEA;AACA;AACI;AACA;AACI;;AAEJ;;AAGJ;AACI;;;AAQA;AACJ;AACA;AACA;;AAEJ;AACJ;AAEA;;;AA2BA;;AAEA;AACA;;;AAGI;;;AAGI;;AAEH;AACD;;;;;AAMJ;AACI;AACJ;AAEA;AASgB;AACA;AACA;AACA;AACH;AAMO;AACA;AACA;;AAyBA;AACI;AACH;AACJ;AAEG;AACJ;AAKpB;;"}
|
package/Datatable/index.js
CHANGED
|
@@ -50,17 +50,9 @@ const DataTable = React.forwardRef((props, ref) => {
|
|
|
50
50
|
let { rows, tabs, pagination: { perpages = [30, 50, 100], total = 0 } = {}, state: userState = {}, onChange, fixedHeader, hidePagination, slotProps,
|
|
51
51
|
// skip props for ViewBox
|
|
52
52
|
skeleton, rowAction, disableRow, renderRow, filters, hideCheckbox, hideSearch, columns, compact } = _props, viewBoxProps = __rest(_props, ["rows", "tabs", "pagination", "state", "onChange", "fixedHeader", "hidePagination", "slotProps", "skeleton", "rowAction", "disableRow", "renderRow", "filters", "hideCheckbox", "hideSearch", "columns", "compact"]);
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
const userperpage = (_c = userState === null || userState === void 0 ? void 0 : userState.pagination) === null || _c === void 0 ? void 0 : _c.perpage;
|
|
57
|
-
if (userperpage && perpages.includes(userperpage)) {
|
|
58
|
-
perpage = userperpage;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
perpage = (perpages === null || perpages === void 0 ? void 0 : perpages.length) ? perpages[0] : 10;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
53
|
+
const userperpage = (_a = userState === null || userState === void 0 ? void 0 : userState.pagination) === null || _a === void 0 ? void 0 : _a.perpage;
|
|
54
|
+
let perpage = userperpage && perpages.includes(userperpage) ? userperpage : perpages[0];
|
|
55
|
+
let page = (_c = (_b = userState === null || userState === void 0 ? void 0 : userState.pagination) === null || _b === void 0 ? void 0 : _b.page) !== null && _c !== void 0 ? _c : 1;
|
|
64
56
|
const state = {
|
|
65
57
|
selected: (_d = userState === null || userState === void 0 ? void 0 : userState.selected) !== null && _d !== void 0 ? _d : [],
|
|
66
58
|
selectAll: (_e = userState === null || userState === void 0 ? void 0 : userState.selectAll) !== null && _e !== void 0 ? _e : false,
|
package/Datatable/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Datatable/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useMemo } from 'react'\nimport ViewBox from '../ViewBox'\nimport { Tag, useInterface } from '@xanui/core';\nimport SelectedBox from './SelectedBox'\nimport TableArea from './Table'\nimport FilterBox from './FilterBox'\nimport TablePagination, { TablePaginationState } from '../TablePagination'\nimport Stack from '../Stack'\nimport { DatatableProps, DatatableState } from './types';\nimport Skeleton from '../Skeleton';\n\nexport type * from './types';\n\nconst DataTable = React.forwardRef((props: DatatableProps, ref: React.Ref<HTMLDivElement>) => {\n let [p] = useInterface<any>(\"Datatable\", props, {})\n\n let _props = useMemo(() => {\n let np = { ...p }\n\n if (typeof np.skeleton === 'number' || np.skeleton === true) {\n const limit = np.perpages && np.perpages.length > 0 ? np.perpages[0] : 10\n let length = np.skeleton === true ? limit : np.skeleton\n\n if (!np.hideCheckbox) {\n np.columns = [{\n label: '', field: \"__checkbox\", width: 34\n }, ...np.columns]\n }\n\n if (np.rowAction) {\n np.columns = [...np.columns, { label: \"\", field: \"__actions\", width: 34 }]\n }\n\n let columns = np.columns || []\n\n np.rows = []\n for (let i = 0; i < length; i++) {\n let r: any = { id: i }\n for (let col of columns) {\n r[col.field] = \"\"\n }\n np.rows.push(r)\n }\n\n np.renderRow = (r: any) => {\n for (let col of columns) {\n r[col.field] = <Skeleton\n animation={\"wave\"}\n height={16}\n radius={.5}\n width={\"100%\"}\n />\n }\n return r\n }\n np.hideCheckbox = true\n np.rowAction = undefined\n }\n return np\n }, [p])\n\n let {\n rows,\n tabs,\n\n pagination: { perpages = [30, 50, 100], total = 0 } = {},\n state: userState = {},\n onChange,\n\n fixedHeader,\n hidePagination,\n slotProps,\n\n\n // skip props for ViewBox\n skeleton,\n rowAction,\n disableRow,\n renderRow,\n filters,\n hideCheckbox,\n hideSearch,\n columns,\n compact,\n\n ...viewBoxProps\n } = _props\n\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Datatable/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useMemo } from 'react'\nimport ViewBox from '../ViewBox'\nimport { Tag, useInterface } from '@xanui/core';\nimport SelectedBox from './SelectedBox'\nimport TableArea from './Table'\nimport FilterBox from './FilterBox'\nimport TablePagination, { TablePaginationState } from '../TablePagination'\nimport Stack from '../Stack'\nimport { DatatableProps, DatatableState } from './types';\nimport Skeleton from '../Skeleton';\n\nexport type * from './types';\n\nconst DataTable = React.forwardRef((props: DatatableProps, ref: React.Ref<HTMLDivElement>) => {\n let [p] = useInterface<any>(\"Datatable\", props, {})\n\n let _props = useMemo(() => {\n let np = { ...p }\n\n if (typeof np.skeleton === 'number' || np.skeleton === true) {\n const limit = np.perpages && np.perpages.length > 0 ? np.perpages[0] : 10\n let length = np.skeleton === true ? limit : np.skeleton\n\n if (!np.hideCheckbox) {\n np.columns = [{\n label: '', field: \"__checkbox\", width: 34\n }, ...np.columns]\n }\n\n if (np.rowAction) {\n np.columns = [...np.columns, { label: \"\", field: \"__actions\", width: 34 }]\n }\n\n let columns = np.columns || []\n\n np.rows = []\n for (let i = 0; i < length; i++) {\n let r: any = { id: i }\n for (let col of columns) {\n r[col.field] = \"\"\n }\n np.rows.push(r)\n }\n\n np.renderRow = (r: any) => {\n for (let col of columns) {\n r[col.field] = <Skeleton\n animation={\"wave\"}\n height={16}\n radius={.5}\n width={\"100%\"}\n />\n }\n return r\n }\n np.hideCheckbox = true\n np.rowAction = undefined\n }\n return np\n }, [p])\n\n let {\n rows,\n tabs,\n\n pagination: { perpages = [30, 50, 100], total = 0 } = {},\n state: userState = {},\n onChange,\n\n fixedHeader,\n hidePagination,\n slotProps,\n\n\n // skip props for ViewBox\n skeleton,\n rowAction,\n disableRow,\n renderRow,\n filters,\n hideCheckbox,\n hideSearch,\n columns,\n compact,\n\n ...viewBoxProps\n } = _props\n\n const userperpage = userState?.pagination?.perpage\n let perpage = userperpage && perpages.includes(userperpage) ? userperpage : perpages[0]\n let page = userState?.pagination?.page ?? 1\n const state = {\n selected: userState?.selected ?? [],\n selectAll: userState?.selectAll ?? false,\n pagination: {\n page,\n perpage,\n from: page ? (perpage * (page - 1)) + 1 : 1,\n to: page ? perpage * page : perpage,\n },\n tab: tabs ? (userState?.tab ?? tabs[0].value ?? tabs[0].label.toLowerCase()) : \"\",\n search: userState?.search ?? \"\",\n sortable: userState?.sortable ?? {},\n filters: userState?.filters ?? {}\n }\n\n const update = (s: Partial<DatatableState>) => {\n onChange({ ...state, ...s })\n }\n\n return (\n <ViewBox\n height=\"100%\"\n {...viewBoxProps}\n baseClass='datatable'\n ref={ref as any}\n sx={{\n ...viewBoxProps?.sx,\n '& thead': fixedHeader ? {\n position: \"sticky\",\n top: 0,\n bgcolor: \"background.primary\",\n zIndex: 1\n } : {},\n }}\n startContent={(\n <Tag\n baseClass='datatable-header'\n sxr={{\n display: \"flex\",\n flexDirection: \"row\",\n justifyContent: \"space-between\"\n }}\n >\n <SelectedBox {..._props} update={update} state={state} />\n <FilterBox {..._props} update={update} state={state} />\n </Tag>\n )}\n >\n <TableArea\n {..._props}\n update={update}\n state={state}\n />\n <Stack\n p={1}\n alignItems=\"flex-end\"\n >\n {!hidePagination && <TablePagination\n disabled={_props.skeleton ? true : false}\n {...slotProps?.pagination}\n total={total || rows.length}\n page={state.pagination.page}\n perpage={state.pagination.perpage}\n perpages={perpages}\n slotProps={{\n select: {\n size: \"small\",\n }\n }}\n onChange={(state: TablePaginationState) => {\n update({ pagination: state })\n }}\n />}\n </Stack>\n </ViewBox>\n )\n})\n\nexport default DataTable"],"names":[],"mappings":";;;;;;;;;;;;;AAcA;;AACI;AAEA;AACI;AAEA;;AAEI;AAEA;;;AAGK;;AAGL;;;AAIA;AAEA;AACA;AACI;AACA;AACI;;AAEJ;;AAGJ;AACI;;;AAQA;AACJ;AACA;AACA;;AAEJ;AACJ;AAEA;;;AA2BA;;AAEA;AACA;;;AAGI;;;AAGI;;AAEH;AACD;;;;;AAMJ;AACI;AACJ;AAEA;AASgB;AACA;AACA;AACA;AACH;AAMO;AACA;AACA;;AAyBA;AACI;AACH;AACJ;AAEG;AACJ;AAKpB;;"}
|
package/Input/index.cjs
CHANGED
|
@@ -117,7 +117,7 @@ const Input = React.forwardRef((_a, ref) => {
|
|
|
117
117
|
}, "& textarea": {
|
|
118
118
|
resize: "none"
|
|
119
119
|
} }), (!!startIcon && {
|
|
120
|
-
"& :first-child": {
|
|
120
|
+
"& :first-child:not(.xui-input)": {
|
|
121
121
|
height: "100%",
|
|
122
122
|
alignItems: 'center',
|
|
123
123
|
justifyContent: "center",
|
|
@@ -126,7 +126,7 @@ const Input = React.forwardRef((_a, ref) => {
|
|
|
126
126
|
flex: "0 0 auto",
|
|
127
127
|
},
|
|
128
128
|
})), (!!endIcon && {
|
|
129
|
-
"& :last-child": {
|
|
129
|
+
"& :last-child:not(.xui-input)": {
|
|
130
130
|
height: "100%",
|
|
131
131
|
alignItems: 'center',
|
|
132
132
|
justifyContent: "center",
|
package/Input/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/Input/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointPropsType, useInterface, useBreakpointProps, useMergeRefs } from '@xanui/core';\nimport Label, { LabelProps } from '../Label';\n\nexport type InputProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"size\" | \"color\" | \"label\"> & {\n value?: string;\n type?: TagProps<'input'>['type'];\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onChange?: (e: React.ChangeEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n multiline?: boolean;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n\n refs?: {\n inputRoot?: React.Ref<\"div\">;\n label?: React.Ref<\"label\">;\n rootContainer?: React.Ref<\"div\">;\n // startIcon?: React.Ref<ReactElement>;\n // endIcon?: React.Ref<ReactElement>;\n // inputContainer?: React.Ref<\"div\">;\n input?: React.Ref<'input' | 'textarea'>;\n helperText?: React.Ref<\"div\">;\n };\n\n slotProps?: {\n inputRoot?: Omit<TagProps<\"div\">, \"children\">;\n label?: Omit<LabelProps, \"children\">;\n rootContainer?: Omit<TagProps<\"div\">, \"children\">;\n // startIcon?: Omit<TagProps<'div'>, \"children\">;\n // endIcon?: Omit<TagProps<'div'>, \"children\">;\n // inputContainer?: Omit<TagProps<\"div\">, \"children\">;\n helperText?: Omit<TagProps<\"div\">, \"children\">;\n input?: Partial<TagProps<T>>;\n }\n}\n\nconst Input = React.forwardRef(<T extends TagComponentType = \"div\">({ value, refs, ...props }: InputProps<T>, ref?: React.Ref<any>) => {\n let [{\n startIcon,\n endIcon,\n iconPlacement,\n color,\n label,\n name,\n placeholder,\n type,\n readOnly,\n autoFocus,\n autoComplete,\n onFocus,\n onBlur,\n onChange,\n onKeyDown,\n onKeyUp,\n\n focused,\n disabled,\n variant,\n error,\n helperText,\n multiline,\n size,\n rows,\n minRows,\n maxRows,\n fullWidth,\n slotProps,\n\n ...rest\n }, theme] = useInterface<any>(\"Input\", props, {})\n\n const _p: any = {}\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (iconPlacement) _p.iconPlacement = iconPlacement\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (helperText) _p.helperText = helperText\n if (size) _p.size = size\n if (rows) _p.rows = rows\n if (minRows) _p.minRows = minRows\n if (maxRows) _p.maxRows = maxRows\n const p: any = useBreakpointProps(_p)\n startIcon = p.startIcon\n endIcon = p.endIcon\n iconPlacement = p.iconPlacement\n color = p.color ?? \"brand\"\n variant = p.variant ?? \"fill\"\n helperText = p.helperText\n size = p.size ?? 'medium'\n rows = p.rows\n minRows = p.minRows\n maxRows = p.maxRows\n\n iconPlacement ??= multiline ? \"end\" : \"center\"\n if (!value) iconPlacement = 'center'\n\n const [_focused, setFocused] = useState(false)\n let _focus = focused || _focused\n const inputRef = React.useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n const inputMergeRef = useMergeRefs(inputRef, refs?.input as any);\n\n useEffect(() => {\n if (autoFocus) {\n setTimeout(() => {\n inputRef.current?.focus()\n }, 100);\n }\n }, [autoFocus])\n\n let _rows = useMemo(() => {\n if (rows) return rows\n if (value && multiline) {\n let lines = (value as string).split(`\\n`).length\n if (minRows && minRows > lines) {\n return minRows\n } else if (maxRows && maxRows < lines) {\n return maxRows\n } else {\n return lines\n }\n }\n }, [value]) || 1\n\n const sizes: any = {\n small: {\n height: 38,\n gap: .5,\n fontSize: 'button',\n },\n medium: {\n height: 46,\n gap: 1,\n fontSize: \"text\"\n },\n large: {\n height: 52,\n gap: 1,\n fontSize: 'big'\n }\n }\n\n const _size = sizes[size]\n let borderColor = _focus ? color : (variant === \"fill\" ? \"transparent\" : \"divider\")\n borderColor = error ? \"danger.primary\" : borderColor\n let multiprops: any = {}\n if (multiline) {\n multiprops = {\n rows: _rows,\n sx: {\n resize: \"none\"\n }\n }\n }\n\n return (\n <Tag\n width={fullWidth ? \"100%\" : \"auto\"}\n {...rest}\n ref={ref}\n baseClass=\"input-wrapper\"\n sxr={{\n display: 'flex',\n flexDirection: 'column',\n gap: .5,\n }}\n >\n {!!label && <Label {...slotProps?.label} ref={refs?.label}>{label}</Label>}\n <Tag\n {...slotProps?.inputRoot}\n ref={refs?.inputRoot}\n baseClass={'input-root'}\n sxr={{\n width: \"100%\",\n overflow: \"hidden\",\n }}\n >\n <Tag\n {...slotProps?.rootContainer}\n ref={refs?.rootContainer}\n baseClass='input-root-container'\n sxr={{\n width: \"100%\",\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: iconPlacement === 'center' ? iconPlacement : `flex-${iconPlacement}`,\n flexWrap: \"nowrap\",\n transitionProperty: \"border, box-shadow, background\",\n bgcolor: error ? \"danger.soft.primary\" : variant === \"fill\" ? \"background.secondary\" : \"background.primary\",\n border: variant === \"text\" ? 0 : \"1px solid\",\n borderColor: borderColor,\n borderRadius: 1,\n px: 1,\n // py: .5,\n ..._size,\n height: multiline ? \"auto\" : _size.height,\n minHeight: _size.height,\n \"& input:-webkit-autofill,& input:-webkit-autofill:hover, & input:-webkit-autofill:focus,& input:-webkit-autofill:active\": {\n \"-webkit-text-fill-color\": \"text.primary\",\n \"box-shadow\": `0 0 0px 1000px ${variant === \"fill\" ? theme.colors.background.secondary : theme.colors.background.primary} inset`,\n transition: \"background-color 5000s ease-in-out 0s\"\n } as any,\n \"& textarea\": {\n resize: \"none\"\n },\n\n ...(!!startIcon && {\n \"& :first-child\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: \"flex\",\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n }),\n\n ...(!!endIcon && {\n \"& :last-child\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: 'flex',\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n })\n\n }}\n disabled={disabled || false}\n >\n {/* {startIcon && <Tag\n {...slotProps?.startIcon}\n ref={refs?.startIcon}\n flex={\"0 0 auto\"}\n sxr={{\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: \"flex\",\n color: error ? \"danger.primary\" : \"text.secondary\",\n }}\n baseClass=\"input-start-icon\"\n >{startIcon}</Tag>} */}\n {startIcon}\n {/* <Tag\n {...slotProps?.inputContainer}\n ref={refs?.inputContainer}\n baseClass='input-container'\n flex={1}\n sxr={{\n width: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n flex: 1,\n minHeight: _size.height,\n \"& textarea\": {\n resize: \"none\"\n },\n \"& input:-webkit-autofill,& input:-webkit-autofill:hover, & input:-webkit-autofill:focus,& input:-webkit-autofill:active\": {\n \"-webkit-text-fill-color\": \"text.primary\",\n \"box-shadow\": `0 0 0px 1000px ${variant === \"fill\" ? theme.colors.background.secondary : theme.colors.background.primary} inset`,\n transition: \"background-color 5000s ease-in-out 0s\"\n } as any\n }}\n >\n \n </Tag> */}\n <Tag\n {...slotProps?.input}\n ref={inputMergeRef}\n baseClass='input'\n component={multiline ? 'textarea' : 'input'}\n {...multiprops}\n sxr={{\n border: 0,\n outline: 0,\n bgcolor: \"transparent\",\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: _size.fontSize,\n height: multiline ? \"auto\" : _size.height + \"px!important\",\n width: \"100%\",\n maxHeight: 200,\n }}\n value={value}\n onChange={onChange}\n onFocus={(e: any) => {\n focused ?? setFocused(true)\n onFocus && onFocus(e)\n }}\n onBlur={(e: any) => {\n focused ?? setFocused(false)\n onBlur && onBlur(e)\n }}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n name={name}\n placeholder={placeholder}\n type={type}\n readOnly={readOnly}\n autoComplete={autoComplete}\n />\n {/* {endIcon && <Tag\n {...slotProps?.endIcon}\n ref={refs?.endIcon}\n flex={\"0 0 auto\"}\n sxr={{\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: 'flex',\n color: error ? \"danger.primary\" : \"text.secondary\",\n }}\n baseClass=\"input-end-icon\"\n >{endIcon}</Tag>} */}\n {endIcon}\n </Tag>\n {helperText && <Tag\n {...slotProps?.helperText}\n ref={refs?.helperText}\n baseClass=\"input-helper-text\"\n sxr={{\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: \"small\",\n lineHeight: \"text\",\n fontWeight: 'text',\n pl: .5,\n }}\n >{helperText}</Tag>}\n </Tag>\n </Tag>\n )\n})\n\nexport default Input\n"],"names":[],"mappings":";;;;;;;;;AA6DA;;;AACI;;AAmCA;AAAe;AACf;AAAa;AACb;AAAmB;AACnB;AAAW;AACX;AAAa;AACb;AAAgB;AAChB;AAAU;AACV;AAAU;AACV;AAAa;AACb;AAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;;AAGA;;AAEA;;;;;AAKY;;;AAGZ;AAEA;AACI;AAAU;AACV;;AAEI;AACI;;AACG;AACH;;;AAEA;;;AAGZ;AAEA;AACI;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;;AAGL;;;;;AAKI;AACI;AACA;AACI;AACH;;;;AAWG;AACA;AACA;;AASI;AACA;AACH;AAuBW;;AAEA;AACI;AAEJ;AACH;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAiDG;AACA;AACA;;;AAGA;AACA;AACA;AACH;;AAKG;AACJ;;AAGI;AACJ;;AA8BA;AACA;AACA;AACA;AACH;AAKrB;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Input/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointPropsType, useInterface, useBreakpointProps, useMergeRefs } from '@xanui/core';\nimport Label, { LabelProps } from '../Label';\n\nexport type InputProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"size\" | \"color\" | \"label\"> & {\n value?: string;\n type?: TagProps<'input'>['type'];\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onChange?: (e: React.ChangeEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n multiline?: boolean;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n\n refs?: {\n inputRoot?: React.Ref<\"div\">;\n label?: React.Ref<\"label\">;\n rootContainer?: React.Ref<\"div\">;\n // startIcon?: React.Ref<ReactElement>;\n // endIcon?: React.Ref<ReactElement>;\n // inputContainer?: React.Ref<\"div\">;\n input?: React.Ref<'input' | 'textarea'>;\n helperText?: React.Ref<\"div\">;\n };\n\n slotProps?: {\n inputRoot?: Omit<TagProps<\"div\">, \"children\">;\n label?: Omit<LabelProps, \"children\">;\n rootContainer?: Omit<TagProps<\"div\">, \"children\">;\n // startIcon?: Omit<TagProps<'div'>, \"children\">;\n // endIcon?: Omit<TagProps<'div'>, \"children\">;\n // inputContainer?: Omit<TagProps<\"div\">, \"children\">;\n helperText?: Omit<TagProps<\"div\">, \"children\">;\n input?: Partial<TagProps<T>>;\n }\n}\n\nconst Input = React.forwardRef(<T extends TagComponentType = \"div\">({ value, refs, ...props }: InputProps<T>, ref?: React.Ref<any>) => {\n let [{\n startIcon,\n endIcon,\n iconPlacement,\n color,\n label,\n name,\n placeholder,\n type,\n readOnly,\n autoFocus,\n autoComplete,\n onFocus,\n onBlur,\n onChange,\n onKeyDown,\n onKeyUp,\n\n focused,\n disabled,\n variant,\n error,\n helperText,\n multiline,\n size,\n rows,\n minRows,\n maxRows,\n fullWidth,\n slotProps,\n\n ...rest\n }, theme] = useInterface<any>(\"Input\", props, {})\n\n const _p: any = {}\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (iconPlacement) _p.iconPlacement = iconPlacement\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (helperText) _p.helperText = helperText\n if (size) _p.size = size\n if (rows) _p.rows = rows\n if (minRows) _p.minRows = minRows\n if (maxRows) _p.maxRows = maxRows\n const p: any = useBreakpointProps(_p)\n startIcon = p.startIcon\n endIcon = p.endIcon\n iconPlacement = p.iconPlacement\n color = p.color ?? \"brand\"\n variant = p.variant ?? \"fill\"\n helperText = p.helperText\n size = p.size ?? 'medium'\n rows = p.rows\n minRows = p.minRows\n maxRows = p.maxRows\n\n iconPlacement ??= multiline ? \"end\" : \"center\"\n if (!value) iconPlacement = 'center'\n\n const [_focused, setFocused] = useState(false)\n let _focus = focused || _focused\n const inputRef = React.useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n const inputMergeRef = useMergeRefs(inputRef, refs?.input as any);\n\n useEffect(() => {\n if (autoFocus) {\n setTimeout(() => {\n inputRef.current?.focus()\n }, 100);\n }\n }, [autoFocus])\n\n let _rows = useMemo(() => {\n if (rows) return rows\n if (value && multiline) {\n let lines = (value as string).split(`\\n`).length\n if (minRows && minRows > lines) {\n return minRows\n } else if (maxRows && maxRows < lines) {\n return maxRows\n } else {\n return lines\n }\n }\n }, [value]) || 1\n\n const sizes: any = {\n small: {\n height: 38,\n gap: .5,\n fontSize: 'button',\n },\n medium: {\n height: 46,\n gap: 1,\n fontSize: \"text\"\n },\n large: {\n height: 52,\n gap: 1,\n fontSize: 'big'\n }\n }\n\n const _size = sizes[size]\n let borderColor = _focus ? color : (variant === \"fill\" ? \"transparent\" : \"divider\")\n borderColor = error ? \"danger.primary\" : borderColor\n let multiprops: any = {}\n if (multiline) {\n multiprops = {\n rows: _rows,\n sx: {\n resize: \"none\"\n }\n }\n }\n\n return (\n <Tag\n width={fullWidth ? \"100%\" : \"auto\"}\n {...rest}\n ref={ref}\n baseClass=\"input-wrapper\"\n sxr={{\n display: 'flex',\n flexDirection: 'column',\n gap: .5,\n }}\n >\n {!!label && <Label {...slotProps?.label} ref={refs?.label}>{label}</Label>}\n <Tag\n {...slotProps?.inputRoot}\n ref={refs?.inputRoot}\n baseClass={'input-root'}\n sxr={{\n width: \"100%\",\n overflow: \"hidden\",\n }}\n >\n <Tag\n {...slotProps?.rootContainer}\n ref={refs?.rootContainer}\n baseClass='input-root-container'\n sxr={{\n width: \"100%\",\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: iconPlacement === 'center' ? iconPlacement : `flex-${iconPlacement}`,\n flexWrap: \"nowrap\",\n transitionProperty: \"border, box-shadow, background\",\n bgcolor: error ? \"danger.soft.primary\" : variant === \"fill\" ? \"background.secondary\" : \"background.primary\",\n border: variant === \"text\" ? 0 : \"1px solid\",\n borderColor: borderColor,\n borderRadius: 1,\n px: 1,\n // py: .5,\n ..._size,\n height: multiline ? \"auto\" : _size.height,\n minHeight: _size.height,\n \"& input:-webkit-autofill,& input:-webkit-autofill:hover, & input:-webkit-autofill:focus,& input:-webkit-autofill:active\": {\n \"-webkit-text-fill-color\": \"text.primary\",\n \"box-shadow\": `0 0 0px 1000px ${variant === \"fill\" ? theme.colors.background.secondary : theme.colors.background.primary} inset`,\n transition: \"background-color 5000s ease-in-out 0s\"\n } as any,\n \"& textarea\": {\n resize: \"none\"\n },\n\n ...(!!startIcon && {\n \"& :first-child:not(.xui-input)\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: \"flex\",\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n }),\n\n ...(!!endIcon && {\n \"& :last-child:not(.xui-input)\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: 'flex',\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n })\n\n }}\n disabled={disabled || false}\n >\n {startIcon}\n <Tag\n {...slotProps?.input}\n ref={inputMergeRef}\n baseClass='input'\n component={multiline ? 'textarea' : 'input'}\n {...multiprops}\n sxr={{\n border: 0,\n outline: 0,\n bgcolor: \"transparent\",\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: _size.fontSize,\n height: multiline ? \"auto\" : _size.height + \"px!important\",\n width: \"100%\",\n maxHeight: 200,\n }}\n value={value}\n onChange={onChange}\n onFocus={(e: any) => {\n focused ?? setFocused(true)\n onFocus && onFocus(e)\n }}\n onBlur={(e: any) => {\n focused ?? setFocused(false)\n onBlur && onBlur(e)\n }}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n name={name}\n placeholder={placeholder}\n type={type}\n readOnly={readOnly}\n autoComplete={autoComplete}\n />\n {endIcon}\n </Tag>\n {helperText && <Tag\n {...slotProps?.helperText}\n ref={refs?.helperText}\n baseClass=\"input-helper-text\"\n sxr={{\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: \"small\",\n lineHeight: \"text\",\n fontWeight: 'text',\n pl: .5,\n }}\n >{helperText}</Tag>}\n </Tag>\n </Tag>\n )\n})\n\nexport default Input\n"],"names":[],"mappings":";;;;;;;;;AA6DA;;;AACI;;AAmCA;AAAe;AACf;AAAa;AACb;AAAmB;AACnB;AAAW;AACX;AAAa;AACb;AAAgB;AAChB;AAAU;AACV;AAAU;AACV;AAAa;AACb;AAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;;AAGA;;AAEA;;;;;AAKY;;;AAGZ;AAEA;AACI;AAAU;AACV;;AAEI;AACI;;AACG;AACH;;;AAEA;;;AAGZ;AAEA;AACI;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;;AAGL;;;;;AAKI;AACI;AACA;AACI;AACH;;;;AAWG;AACA;AACA;;AASI;AACA;AACH;AAuBW;;AAEA;AACI;AAEJ;AACH;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAaG;AACA;AACA;;;AAGA;AACA;AACA;AACH;;AAKG;AACJ;;AAGI;AACJ;;AAiBA;AACA;AACA;AACA;AACH;AAKrB;;"}
|
package/Input/index.js
CHANGED
|
@@ -115,7 +115,7 @@ const Input = React.forwardRef((_a, ref) => {
|
|
|
115
115
|
}, "& textarea": {
|
|
116
116
|
resize: "none"
|
|
117
117
|
} }), (!!startIcon && {
|
|
118
|
-
"& :first-child": {
|
|
118
|
+
"& :first-child:not(.xui-input)": {
|
|
119
119
|
height: "100%",
|
|
120
120
|
alignItems: 'center',
|
|
121
121
|
justifyContent: "center",
|
|
@@ -124,7 +124,7 @@ const Input = React.forwardRef((_a, ref) => {
|
|
|
124
124
|
flex: "0 0 auto",
|
|
125
125
|
},
|
|
126
126
|
})), (!!endIcon && {
|
|
127
|
-
"& :last-child": {
|
|
127
|
+
"& :last-child:not(.xui-input)": {
|
|
128
128
|
height: "100%",
|
|
129
129
|
alignItems: 'center',
|
|
130
130
|
justifyContent: "center",
|
package/Input/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Input/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointPropsType, useInterface, useBreakpointProps, useMergeRefs } from '@xanui/core';\nimport Label, { LabelProps } from '../Label';\n\nexport type InputProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"size\" | \"color\" | \"label\"> & {\n value?: string;\n type?: TagProps<'input'>['type'];\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onChange?: (e: React.ChangeEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n multiline?: boolean;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n\n refs?: {\n inputRoot?: React.Ref<\"div\">;\n label?: React.Ref<\"label\">;\n rootContainer?: React.Ref<\"div\">;\n // startIcon?: React.Ref<ReactElement>;\n // endIcon?: React.Ref<ReactElement>;\n // inputContainer?: React.Ref<\"div\">;\n input?: React.Ref<'input' | 'textarea'>;\n helperText?: React.Ref<\"div\">;\n };\n\n slotProps?: {\n inputRoot?: Omit<TagProps<\"div\">, \"children\">;\n label?: Omit<LabelProps, \"children\">;\n rootContainer?: Omit<TagProps<\"div\">, \"children\">;\n // startIcon?: Omit<TagProps<'div'>, \"children\">;\n // endIcon?: Omit<TagProps<'div'>, \"children\">;\n // inputContainer?: Omit<TagProps<\"div\">, \"children\">;\n helperText?: Omit<TagProps<\"div\">, \"children\">;\n input?: Partial<TagProps<T>>;\n }\n}\n\nconst Input = React.forwardRef(<T extends TagComponentType = \"div\">({ value, refs, ...props }: InputProps<T>, ref?: React.Ref<any>) => {\n let [{\n startIcon,\n endIcon,\n iconPlacement,\n color,\n label,\n name,\n placeholder,\n type,\n readOnly,\n autoFocus,\n autoComplete,\n onFocus,\n onBlur,\n onChange,\n onKeyDown,\n onKeyUp,\n\n focused,\n disabled,\n variant,\n error,\n helperText,\n multiline,\n size,\n rows,\n minRows,\n maxRows,\n fullWidth,\n slotProps,\n\n ...rest\n }, theme] = useInterface<any>(\"Input\", props, {})\n\n const _p: any = {}\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (iconPlacement) _p.iconPlacement = iconPlacement\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (helperText) _p.helperText = helperText\n if (size) _p.size = size\n if (rows) _p.rows = rows\n if (minRows) _p.minRows = minRows\n if (maxRows) _p.maxRows = maxRows\n const p: any = useBreakpointProps(_p)\n startIcon = p.startIcon\n endIcon = p.endIcon\n iconPlacement = p.iconPlacement\n color = p.color ?? \"brand\"\n variant = p.variant ?? \"fill\"\n helperText = p.helperText\n size = p.size ?? 'medium'\n rows = p.rows\n minRows = p.minRows\n maxRows = p.maxRows\n\n iconPlacement ??= multiline ? \"end\" : \"center\"\n if (!value) iconPlacement = 'center'\n\n const [_focused, setFocused] = useState(false)\n let _focus = focused || _focused\n const inputRef = React.useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n const inputMergeRef = useMergeRefs(inputRef, refs?.input as any);\n\n useEffect(() => {\n if (autoFocus) {\n setTimeout(() => {\n inputRef.current?.focus()\n }, 100);\n }\n }, [autoFocus])\n\n let _rows = useMemo(() => {\n if (rows) return rows\n if (value && multiline) {\n let lines = (value as string).split(`\\n`).length\n if (minRows && minRows > lines) {\n return minRows\n } else if (maxRows && maxRows < lines) {\n return maxRows\n } else {\n return lines\n }\n }\n }, [value]) || 1\n\n const sizes: any = {\n small: {\n height: 38,\n gap: .5,\n fontSize: 'button',\n },\n medium: {\n height: 46,\n gap: 1,\n fontSize: \"text\"\n },\n large: {\n height: 52,\n gap: 1,\n fontSize: 'big'\n }\n }\n\n const _size = sizes[size]\n let borderColor = _focus ? color : (variant === \"fill\" ? \"transparent\" : \"divider\")\n borderColor = error ? \"danger.primary\" : borderColor\n let multiprops: any = {}\n if (multiline) {\n multiprops = {\n rows: _rows,\n sx: {\n resize: \"none\"\n }\n }\n }\n\n return (\n <Tag\n width={fullWidth ? \"100%\" : \"auto\"}\n {...rest}\n ref={ref}\n baseClass=\"input-wrapper\"\n sxr={{\n display: 'flex',\n flexDirection: 'column',\n gap: .5,\n }}\n >\n {!!label && <Label {...slotProps?.label} ref={refs?.label}>{label}</Label>}\n <Tag\n {...slotProps?.inputRoot}\n ref={refs?.inputRoot}\n baseClass={'input-root'}\n sxr={{\n width: \"100%\",\n overflow: \"hidden\",\n }}\n >\n <Tag\n {...slotProps?.rootContainer}\n ref={refs?.rootContainer}\n baseClass='input-root-container'\n sxr={{\n width: \"100%\",\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: iconPlacement === 'center' ? iconPlacement : `flex-${iconPlacement}`,\n flexWrap: \"nowrap\",\n transitionProperty: \"border, box-shadow, background\",\n bgcolor: error ? \"danger.soft.primary\" : variant === \"fill\" ? \"background.secondary\" : \"background.primary\",\n border: variant === \"text\" ? 0 : \"1px solid\",\n borderColor: borderColor,\n borderRadius: 1,\n px: 1,\n // py: .5,\n ..._size,\n height: multiline ? \"auto\" : _size.height,\n minHeight: _size.height,\n \"& input:-webkit-autofill,& input:-webkit-autofill:hover, & input:-webkit-autofill:focus,& input:-webkit-autofill:active\": {\n \"-webkit-text-fill-color\": \"text.primary\",\n \"box-shadow\": `0 0 0px 1000px ${variant === \"fill\" ? theme.colors.background.secondary : theme.colors.background.primary} inset`,\n transition: \"background-color 5000s ease-in-out 0s\"\n } as any,\n \"& textarea\": {\n resize: \"none\"\n },\n\n ...(!!startIcon && {\n \"& :first-child\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: \"flex\",\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n }),\n\n ...(!!endIcon && {\n \"& :last-child\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: 'flex',\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n })\n\n }}\n disabled={disabled || false}\n >\n {/* {startIcon && <Tag\n {...slotProps?.startIcon}\n ref={refs?.startIcon}\n flex={\"0 0 auto\"}\n sxr={{\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: \"flex\",\n color: error ? \"danger.primary\" : \"text.secondary\",\n }}\n baseClass=\"input-start-icon\"\n >{startIcon}</Tag>} */}\n {startIcon}\n {/* <Tag\n {...slotProps?.inputContainer}\n ref={refs?.inputContainer}\n baseClass='input-container'\n flex={1}\n sxr={{\n width: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n flex: 1,\n minHeight: _size.height,\n \"& textarea\": {\n resize: \"none\"\n },\n \"& input:-webkit-autofill,& input:-webkit-autofill:hover, & input:-webkit-autofill:focus,& input:-webkit-autofill:active\": {\n \"-webkit-text-fill-color\": \"text.primary\",\n \"box-shadow\": `0 0 0px 1000px ${variant === \"fill\" ? theme.colors.background.secondary : theme.colors.background.primary} inset`,\n transition: \"background-color 5000s ease-in-out 0s\"\n } as any\n }}\n >\n \n </Tag> */}\n <Tag\n {...slotProps?.input}\n ref={inputMergeRef}\n baseClass='input'\n component={multiline ? 'textarea' : 'input'}\n {...multiprops}\n sxr={{\n border: 0,\n outline: 0,\n bgcolor: \"transparent\",\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: _size.fontSize,\n height: multiline ? \"auto\" : _size.height + \"px!important\",\n width: \"100%\",\n maxHeight: 200,\n }}\n value={value}\n onChange={onChange}\n onFocus={(e: any) => {\n focused ?? setFocused(true)\n onFocus && onFocus(e)\n }}\n onBlur={(e: any) => {\n focused ?? setFocused(false)\n onBlur && onBlur(e)\n }}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n name={name}\n placeholder={placeholder}\n type={type}\n readOnly={readOnly}\n autoComplete={autoComplete}\n />\n {/* {endIcon && <Tag\n {...slotProps?.endIcon}\n ref={refs?.endIcon}\n flex={\"0 0 auto\"}\n sxr={{\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: 'flex',\n color: error ? \"danger.primary\" : \"text.secondary\",\n }}\n baseClass=\"input-end-icon\"\n >{endIcon}</Tag>} */}\n {endIcon}\n </Tag>\n {helperText && <Tag\n {...slotProps?.helperText}\n ref={refs?.helperText}\n baseClass=\"input-helper-text\"\n sxr={{\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: \"small\",\n lineHeight: \"text\",\n fontWeight: 'text',\n pl: .5,\n }}\n >{helperText}</Tag>}\n </Tag>\n </Tag>\n )\n})\n\nexport default Input\n"],"names":[],"mappings":";;;;;;;AA6DA;;;AACI;;AAmCA;AAAe;AACf;AAAa;AACb;AAAmB;AACnB;AAAW;AACX;AAAa;AACb;AAAgB;AAChB;AAAU;AACV;AAAU;AACV;AAAa;AACb;AAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;;AAGA;;AAEA;;;;;AAKY;;;AAGZ;AAEA;AACI;AAAU;AACV;;AAEI;AACI;;AACG;AACH;;;AAEA;;;AAGZ;AAEA;AACI;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;;AAGL;;;;;AAKI;AACI;AACA;AACI;AACH;;;;AAWG;AACA;AACA;;AASI;AACA;AACH;AAuBW;;AAEA;AACI;AAEJ;AACH;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAiDG;AACA;AACA;;;AAGA;AACA;AACA;AACH;;AAKG;AACJ;;AAGI;AACJ;;AA8BA;AACA;AACA;AACA;AACH;AAKrB;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Input/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Tag, TagProps, TagComponentType, UseColorTemplateColor, useBreakpointPropsType, useInterface, useBreakpointProps, useMergeRefs } from '@xanui/core';\nimport Label, { LabelProps } from '../Label';\n\nexport type InputProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"size\" | \"color\" | \"label\"> & {\n value?: string;\n type?: TagProps<'input'>['type'];\n name?: string;\n placeholder?: string;\n readOnly?: boolean;\n autoFocus?: boolean;\n autoComplete?: string;\n label?: useBreakpointPropsType<string>;\n\n onFocus?: (e: React.FocusEvent<any>) => void;\n onBlur?: (e: React.FocusEvent<any>) => void;\n onChange?: (e: React.ChangeEvent<any>) => void;\n onInput?: (e: React.FormEvent<any>) => void;\n onKeyDown?: (e: React.KeyboardEvent<any>) => void;\n onKeyUp?: (e: React.KeyboardEvent<any>) => void;\n\n rows?: useBreakpointPropsType<number>;\n minRows?: useBreakpointPropsType<number>;\n maxRows?: useBreakpointPropsType<number>;\n fullWidth?: boolean;\n\n startIcon?: useBreakpointPropsType<ReactElement>;\n endIcon?: useBreakpointPropsType<ReactElement>;\n iconPlacement?: useBreakpointPropsType<\"start\" | \"center\" | \"end\">;\n focused?: boolean;\n color?: useBreakpointPropsType<Omit<UseColorTemplateColor, \"default\">>;\n variant?: useBreakpointPropsType<\"fill\" | \"outline\" | \"text\">;\n error?: boolean;\n helperText?: useBreakpointPropsType<string>;\n multiline?: boolean;\n size?: useBreakpointPropsType<\"small\" | \"medium\" | \"large\">;\n\n refs?: {\n inputRoot?: React.Ref<\"div\">;\n label?: React.Ref<\"label\">;\n rootContainer?: React.Ref<\"div\">;\n // startIcon?: React.Ref<ReactElement>;\n // endIcon?: React.Ref<ReactElement>;\n // inputContainer?: React.Ref<\"div\">;\n input?: React.Ref<'input' | 'textarea'>;\n helperText?: React.Ref<\"div\">;\n };\n\n slotProps?: {\n inputRoot?: Omit<TagProps<\"div\">, \"children\">;\n label?: Omit<LabelProps, \"children\">;\n rootContainer?: Omit<TagProps<\"div\">, \"children\">;\n // startIcon?: Omit<TagProps<'div'>, \"children\">;\n // endIcon?: Omit<TagProps<'div'>, \"children\">;\n // inputContainer?: Omit<TagProps<\"div\">, \"children\">;\n helperText?: Omit<TagProps<\"div\">, \"children\">;\n input?: Partial<TagProps<T>>;\n }\n}\n\nconst Input = React.forwardRef(<T extends TagComponentType = \"div\">({ value, refs, ...props }: InputProps<T>, ref?: React.Ref<any>) => {\n let [{\n startIcon,\n endIcon,\n iconPlacement,\n color,\n label,\n name,\n placeholder,\n type,\n readOnly,\n autoFocus,\n autoComplete,\n onFocus,\n onBlur,\n onChange,\n onKeyDown,\n onKeyUp,\n\n focused,\n disabled,\n variant,\n error,\n helperText,\n multiline,\n size,\n rows,\n minRows,\n maxRows,\n fullWidth,\n slotProps,\n\n ...rest\n }, theme] = useInterface<any>(\"Input\", props, {})\n\n const _p: any = {}\n if (startIcon) _p.startIcon = startIcon\n if (endIcon) _p.endIcon = endIcon\n if (iconPlacement) _p.iconPlacement = iconPlacement\n if (color) _p.color = color\n if (variant) _p.variant = variant\n if (helperText) _p.helperText = helperText\n if (size) _p.size = size\n if (rows) _p.rows = rows\n if (minRows) _p.minRows = minRows\n if (maxRows) _p.maxRows = maxRows\n const p: any = useBreakpointProps(_p)\n startIcon = p.startIcon\n endIcon = p.endIcon\n iconPlacement = p.iconPlacement\n color = p.color ?? \"brand\"\n variant = p.variant ?? \"fill\"\n helperText = p.helperText\n size = p.size ?? 'medium'\n rows = p.rows\n minRows = p.minRows\n maxRows = p.maxRows\n\n iconPlacement ??= multiline ? \"end\" : \"center\"\n if (!value) iconPlacement = 'center'\n\n const [_focused, setFocused] = useState(false)\n let _focus = focused || _focused\n const inputRef = React.useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n const inputMergeRef = useMergeRefs(inputRef, refs?.input as any);\n\n useEffect(() => {\n if (autoFocus) {\n setTimeout(() => {\n inputRef.current?.focus()\n }, 100);\n }\n }, [autoFocus])\n\n let _rows = useMemo(() => {\n if (rows) return rows\n if (value && multiline) {\n let lines = (value as string).split(`\\n`).length\n if (minRows && minRows > lines) {\n return minRows\n } else if (maxRows && maxRows < lines) {\n return maxRows\n } else {\n return lines\n }\n }\n }, [value]) || 1\n\n const sizes: any = {\n small: {\n height: 38,\n gap: .5,\n fontSize: 'button',\n },\n medium: {\n height: 46,\n gap: 1,\n fontSize: \"text\"\n },\n large: {\n height: 52,\n gap: 1,\n fontSize: 'big'\n }\n }\n\n const _size = sizes[size]\n let borderColor = _focus ? color : (variant === \"fill\" ? \"transparent\" : \"divider\")\n borderColor = error ? \"danger.primary\" : borderColor\n let multiprops: any = {}\n if (multiline) {\n multiprops = {\n rows: _rows,\n sx: {\n resize: \"none\"\n }\n }\n }\n\n return (\n <Tag\n width={fullWidth ? \"100%\" : \"auto\"}\n {...rest}\n ref={ref}\n baseClass=\"input-wrapper\"\n sxr={{\n display: 'flex',\n flexDirection: 'column',\n gap: .5,\n }}\n >\n {!!label && <Label {...slotProps?.label} ref={refs?.label}>{label}</Label>}\n <Tag\n {...slotProps?.inputRoot}\n ref={refs?.inputRoot}\n baseClass={'input-root'}\n sxr={{\n width: \"100%\",\n overflow: \"hidden\",\n }}\n >\n <Tag\n {...slotProps?.rootContainer}\n ref={refs?.rootContainer}\n baseClass='input-root-container'\n sxr={{\n width: \"100%\",\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: iconPlacement === 'center' ? iconPlacement : `flex-${iconPlacement}`,\n flexWrap: \"nowrap\",\n transitionProperty: \"border, box-shadow, background\",\n bgcolor: error ? \"danger.soft.primary\" : variant === \"fill\" ? \"background.secondary\" : \"background.primary\",\n border: variant === \"text\" ? 0 : \"1px solid\",\n borderColor: borderColor,\n borderRadius: 1,\n px: 1,\n // py: .5,\n ..._size,\n height: multiline ? \"auto\" : _size.height,\n minHeight: _size.height,\n \"& input:-webkit-autofill,& input:-webkit-autofill:hover, & input:-webkit-autofill:focus,& input:-webkit-autofill:active\": {\n \"-webkit-text-fill-color\": \"text.primary\",\n \"box-shadow\": `0 0 0px 1000px ${variant === \"fill\" ? theme.colors.background.secondary : theme.colors.background.primary} inset`,\n transition: \"background-color 5000s ease-in-out 0s\"\n } as any,\n \"& textarea\": {\n resize: \"none\"\n },\n\n ...(!!startIcon && {\n \"& :first-child:not(.xui-input)\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: \"flex\",\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n }),\n\n ...(!!endIcon && {\n \"& :last-child:not(.xui-input)\": {\n height: \"100%\",\n alignItems: 'center',\n justifyContent: \"center\",\n display: 'flex',\n color: error ? \"danger.primary\" : \"text.secondary\",\n flex: \"0 0 auto\",\n },\n })\n\n }}\n disabled={disabled || false}\n >\n {startIcon}\n <Tag\n {...slotProps?.input}\n ref={inputMergeRef}\n baseClass='input'\n component={multiline ? 'textarea' : 'input'}\n {...multiprops}\n sxr={{\n border: 0,\n outline: 0,\n bgcolor: \"transparent\",\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: _size.fontSize,\n height: multiline ? \"auto\" : _size.height + \"px!important\",\n width: \"100%\",\n maxHeight: 200,\n }}\n value={value}\n onChange={onChange}\n onFocus={(e: any) => {\n focused ?? setFocused(true)\n onFocus && onFocus(e)\n }}\n onBlur={(e: any) => {\n focused ?? setFocused(false)\n onBlur && onBlur(e)\n }}\n onKeyDown={onKeyDown}\n onKeyUp={onKeyUp}\n name={name}\n placeholder={placeholder}\n type={type}\n readOnly={readOnly}\n autoComplete={autoComplete}\n />\n {endIcon}\n </Tag>\n {helperText && <Tag\n {...slotProps?.helperText}\n ref={refs?.helperText}\n baseClass=\"input-helper-text\"\n sxr={{\n color: error ? \"danger.primary\" : \"text.primary\",\n fontSize: \"small\",\n lineHeight: \"text\",\n fontWeight: 'text',\n pl: .5,\n }}\n >{helperText}</Tag>}\n </Tag>\n </Tag>\n )\n})\n\nexport default Input\n"],"names":[],"mappings":";;;;;;;AA6DA;;;AACI;;AAmCA;AAAe;AACf;AAAa;AACb;AAAmB;AACnB;AAAW;AACX;AAAa;AACb;AAAgB;AAChB;AAAU;AACV;AAAU;AACV;AAAa;AACb;AAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;;AAGA;;AAEA;;;;;AAKY;;;AAGZ;AAEA;AACI;AAAU;AACV;;AAEI;AACI;;AACG;AACH;;;AAEA;;;AAGZ;AAEA;AACI;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;AACD;AACI;AACA;AACA;AACH;;AAGL;;;;;AAKI;AACI;AACA;AACI;AACH;;;;AAWG;AACA;AACA;;AASI;AACA;AACH;AAuBW;;AAEA;AACI;AAEJ;AACH;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAGG;AACI;AACA;AACA;AACA;;AAEA;AACH;AACJ;AAaG;AACA;AACA;;;AAGA;AACA;AACA;AACH;;AAKG;AACJ;;AAGI;AACJ;;AAiBA;AACA;AACA;AACA;AACH;AAKrB;;"}
|