@ioca/react 1.4.73 → 1.4.75
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/lib/cjs/components/button/toggle.js +11 -18
- package/lib/cjs/components/button/toggle.js.map +1 -1
- package/lib/cjs/components/checkbox/checkbox.js +5 -8
- package/lib/cjs/components/checkbox/checkbox.js.map +1 -1
- package/lib/cjs/components/checkbox/item.js +15 -16
- package/lib/cjs/components/checkbox/item.js.map +1 -1
- package/lib/cjs/components/collapse/collapse.js +11 -13
- package/lib/cjs/components/collapse/collapse.js.map +1 -1
- package/lib/cjs/components/form/field.js +16 -20
- package/lib/cjs/components/form/field.js.map +1 -1
- package/lib/cjs/components/input/input.js +21 -18
- package/lib/cjs/components/input/input.js.map +1 -1
- package/lib/cjs/components/input/number.js +65 -19
- package/lib/cjs/components/input/number.js.map +1 -1
- package/lib/cjs/components/input/range.js +10 -13
- package/lib/cjs/components/input/range.js.map +1 -1
- package/lib/cjs/components/input/textarea.js +4 -7
- package/lib/cjs/components/input/textarea.js.map +1 -1
- package/lib/cjs/components/picker/colors/footer.js +7 -10
- package/lib/cjs/components/picker/colors/footer.js.map +1 -1
- package/lib/cjs/components/picker/colors/index.js +23 -21
- package/lib/cjs/components/picker/colors/index.js.map +1 -1
- package/lib/cjs/components/picker/dates/index.js +9 -12
- package/lib/cjs/components/picker/dates/index.js.map +1 -1
- package/lib/cjs/components/picker/dates/panel.js +29 -35
- package/lib/cjs/components/picker/dates/panel.js.map +1 -1
- package/lib/cjs/components/picker/time/index.js +8 -12
- package/lib/cjs/components/picker/time/index.js.map +1 -1
- package/lib/cjs/components/picker/time/panel.js +38 -21
- package/lib/cjs/components/picker/time/panel.js.map +1 -1
- package/lib/cjs/components/radio/radio.js +4 -7
- package/lib/cjs/components/radio/radio.js.map +1 -1
- package/lib/cjs/components/select/select.js +19 -24
- package/lib/cjs/components/select/select.js.map +1 -1
- package/lib/cjs/components/tabs/tabs.js +80 -79
- package/lib/cjs/components/tabs/tabs.js.map +1 -1
- package/lib/cjs/components/tree/tree.js +24 -26
- package/lib/cjs/components/tree/tree.js.map +1 -1
- package/lib/cjs/components/upload/upload.js +26 -33
- package/lib/cjs/components/upload/upload.js.map +1 -1
- package/lib/css/index.css +1 -1
- package/lib/css/index.css.map +1 -1
- package/lib/es/components/button/toggle.js +12 -19
- package/lib/es/components/button/toggle.js.map +1 -1
- package/lib/es/components/checkbox/checkbox.js +6 -9
- package/lib/es/components/checkbox/checkbox.js.map +1 -1
- package/lib/es/components/checkbox/item.js +16 -17
- package/lib/es/components/checkbox/item.js.map +1 -1
- package/lib/es/components/collapse/collapse.js +12 -14
- package/lib/es/components/collapse/collapse.js.map +1 -1
- package/lib/es/components/form/field.js +17 -21
- package/lib/es/components/form/field.js.map +1 -1
- package/lib/es/components/input/input.js +22 -19
- package/lib/es/components/input/input.js.map +1 -1
- package/lib/es/components/input/number.js +67 -21
- package/lib/es/components/input/number.js.map +1 -1
- package/lib/es/components/input/range.js +11 -14
- package/lib/es/components/input/range.js.map +1 -1
- package/lib/es/components/input/textarea.js +5 -8
- package/lib/es/components/input/textarea.js.map +1 -1
- package/lib/es/components/picker/colors/footer.js +8 -11
- package/lib/es/components/picker/colors/footer.js.map +1 -1
- package/lib/es/components/picker/colors/index.js +24 -22
- package/lib/es/components/picker/colors/index.js.map +1 -1
- package/lib/es/components/picker/dates/index.js +9 -12
- package/lib/es/components/picker/dates/index.js.map +1 -1
- package/lib/es/components/picker/dates/panel.js +30 -36
- package/lib/es/components/picker/dates/panel.js.map +1 -1
- package/lib/es/components/picker/time/index.js +8 -12
- package/lib/es/components/picker/time/index.js.map +1 -1
- package/lib/es/components/picker/time/panel.js +39 -22
- package/lib/es/components/picker/time/panel.js.map +1 -1
- package/lib/es/components/radio/radio.js +5 -8
- package/lib/es/components/radio/radio.js.map +1 -1
- package/lib/es/components/select/select.js +19 -24
- package/lib/es/components/select/select.js.map +1 -1
- package/lib/es/components/tabs/tabs.js +82 -81
- package/lib/es/components/tabs/tabs.js.map +1 -1
- package/lib/es/components/tree/tree.js +25 -27
- package/lib/es/components/tree/tree.js.map +1 -1
- package/lib/es/components/upload/upload.js +27 -34
- package/lib/es/components/upload/upload.js.map +1 -1
- package/lib/index.js +426 -393
- package/package.json +1 -1
|
@@ -1,55 +1,57 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import ColorsPanel from '@rc-component/color-picker';
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
|
-
import { useReactive } from '../../../js/hooks.js';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
5
4
|
import Popup from '../../popup/popup.js';
|
|
6
5
|
import Footer, { ColorMethods } from './footer.js';
|
|
7
6
|
import Handle from './handle.js';
|
|
8
7
|
|
|
9
8
|
function ColorPicker(props) {
|
|
10
9
|
const { value, type = "HEX", disabledAlpha, children, usePanel, handle = "both", placeholder = "Colors", popupProps, onChange, } = props;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
visible: popupProps?.visible,
|
|
16
|
-
});
|
|
10
|
+
const [colorType, setColorType] = useState(type);
|
|
11
|
+
const [colorValue, setColorValue] = useState(value);
|
|
12
|
+
const [syncValue, setSyncValue] = useState(value);
|
|
13
|
+
const [visible, setVisible] = useState(popupProps?.visible);
|
|
17
14
|
const handleChange = (target) => {
|
|
18
|
-
|
|
15
|
+
setSyncValue(target);
|
|
19
16
|
};
|
|
20
17
|
const handleComplete = (target) => {
|
|
21
|
-
const method = ColorMethods[
|
|
18
|
+
const method = ColorMethods[colorType];
|
|
22
19
|
if (target.a !== 1) {
|
|
23
20
|
target.a = parseFloat(target.a.toFixed(3));
|
|
24
21
|
}
|
|
25
|
-
|
|
22
|
+
setColorValue(target[method]?.());
|
|
26
23
|
};
|
|
27
24
|
const handleVisibleChange = (v) => {
|
|
28
|
-
|
|
25
|
+
setVisible(v);
|
|
29
26
|
popupProps?.onVisibleChange?.(v);
|
|
30
27
|
};
|
|
31
28
|
const handleTypeChange = (t) => {
|
|
32
29
|
const method = ColorMethods[t];
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
setColorType(t);
|
|
31
|
+
setColorValue(syncValue?.[method]?.());
|
|
35
32
|
};
|
|
36
33
|
const handleValueChange = (v) => {
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
setColorValue(v);
|
|
35
|
+
setSyncValue(v);
|
|
39
36
|
};
|
|
40
37
|
const handleOk = () => {
|
|
41
|
-
onChange?.(
|
|
42
|
-
|
|
38
|
+
onChange?.(colorValue);
|
|
39
|
+
setVisible(false);
|
|
43
40
|
};
|
|
44
41
|
useEffect(() => {
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
setSyncValue(value);
|
|
43
|
+
setColorValue(value);
|
|
47
44
|
}, [value]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (popupProps?.visible !== undefined) {
|
|
47
|
+
setVisible(popupProps.visible);
|
|
48
|
+
}
|
|
49
|
+
}, [popupProps?.visible]);
|
|
48
50
|
if (usePanel) {
|
|
49
51
|
return jsx(ColorsPanel, { ...props });
|
|
50
52
|
}
|
|
51
|
-
return (jsx(Popup, { trigger: 'click', touchable: true, position: 'bottom', ...popupProps, visible:
|
|
52
|
-
return (jsxs(Fragment, { children: [panel, jsx(Footer, { value:
|
|
53
|
+
return (jsx(Popup, { trigger: 'click', touchable: true, position: 'bottom', ...popupProps, visible: visible, content: jsx(ColorsPanel, { value: syncValue, disabledAlpha: disabledAlpha, panelRender: (panel) => {
|
|
54
|
+
return (jsxs(Fragment, { children: [panel, jsx(Footer, { value: colorValue, type: colorType, onTypeChange: handleTypeChange, onChange: handleValueChange, onOk: handleOk })] }));
|
|
53
55
|
}, onChange: handleChange, onChangeComplete: handleComplete }), onVisibleChange: handleVisibleChange, children: children ?? (jsx(Handle, { color: value, handle: handle, placeholder: placeholder })) }));
|
|
54
56
|
}
|
|
55
57
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/colors/index.tsx"],"sourcesContent":["import ColorsPanel from \"@rc-component/color-picker\";\nimport { useEffect } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/colors/index.tsx"],"sourcesContent":["import ColorsPanel from \"@rc-component/color-picker\";\nimport { useEffect, useState } from \"react\";\nimport Popup from \"../../popup\";\nimport { IColorPicker } from \"../type\";\nimport Footer, { ColorMethods } from \"./footer\";\nimport Handle from \"./handle\";\nimport \"./index.css\";\n\nexport default function ColorPicker(props: IColorPicker) {\n\tconst {\n\t\tvalue,\n\t\ttype = \"HEX\",\n\t\tdisabledAlpha,\n\t\tchildren,\n\t\tusePanel,\n\t\thandle = \"both\",\n\t\tplaceholder = \"Colors\",\n\t\tpopupProps,\n\t\tonChange,\n\t} = props;\n\n\tconst [colorType, setColorType] = useState(type);\n\tconst [colorValue, setColorValue] = useState(value);\n\tconst [syncValue, setSyncValue] = useState(value);\n\tconst [visible, setVisible] = useState<boolean | undefined>(popupProps?.visible);\n\n\tconst handleChange = (target) => {\n\t\tsetSyncValue(target);\n\t};\n\n\tconst handleComplete = (target) => {\n\t\tconst method = ColorMethods[colorType];\n\n\t\tif (target.a !== 1) {\n\t\t\ttarget.a = parseFloat(target.a.toFixed(3));\n\t\t}\n\n\t\tsetColorValue(target[method]?.());\n\t};\n\n\tconst handleVisibleChange = (v: boolean) => {\n\t\tsetVisible(v);\n\t\tpopupProps?.onVisibleChange?.(v);\n\t};\n\n\tconst handleTypeChange = (t) => {\n\t\tconst method = ColorMethods[t];\n\n\t\tsetColorType(t);\n\t\tsetColorValue(syncValue?.[method]?.());\n\t};\n\n\tconst handleValueChange = (v) => {\n\t\tsetColorValue(v);\n\t\tsetSyncValue(v);\n\t};\n\n\tconst handleOk = () => {\n\t\tonChange?.(colorValue);\n\t\tsetVisible(false);\n\t};\n\n\tuseEffect(() => {\n\t\tsetSyncValue(value);\n\t\tsetColorValue(value);\n\t}, [value]);\n\n\tuseEffect(() => {\n\t\tif (popupProps?.visible !== undefined) {\n\t\t\tsetVisible(popupProps.visible);\n\t\t}\n\t}, [popupProps?.visible]);\n\n\tif (usePanel) {\n\t\treturn <ColorsPanel {...props} />;\n\t}\n\n\treturn (\n\t\t<Popup\n\t\t\ttrigger='click'\n\t\t\ttouchable\n\t\t\tposition='bottom'\n\t\t\t{...popupProps}\n\t\t\tvisible={visible}\n\t\t\tcontent={\n\t\t\t\t<ColorsPanel\n\t\t\t\t\tvalue={syncValue}\n\t\t\t\t\tdisabledAlpha={disabledAlpha}\n\t\t\t\t\tpanelRender={(panel) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t{panel}\n\t\t\t\t\t\t\t\t<Footer\n\t\t\t\t\t\t\t\t\tvalue={colorValue}\n\t\t\t\t\t\t\t\t\ttype={colorType}\n\t\t\t\t\t\t\t\t\tonTypeChange={handleTypeChange}\n\t\t\t\t\t\t\t\t\tonChange={handleValueChange}\n\t\t\t\t\t\t\t\t\tonOk={handleOk}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t);\n\t\t\t\t\t}}\n\t\t\t\t\tonChange={handleChange}\n\t\t\t\t\tonChangeComplete={handleComplete}\n\t\t\t\t/>\n\t\t\t}\n\t\t\tonVisibleChange={handleVisibleChange}\n\t\t>\n\t\t\t{children ?? (\n\t\t\t\t<Handle\n\t\t\t\t\tcolor={value}\n\t\t\t\t\thandle={handle}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</Popup>\n\t);\n}\n"],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;AAQc,SAAU,WAAW,CAAC,KAAmB,EAAA;IACtD,MAAM,EACL,KAAK,EACL,IAAI,GAAG,KAAK,EACZ,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,MAAM,GAAG,MAAM,EACf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B,EAAA,QAAA,EAEnC,QAAQ,KACRA,GAAA,CAAC,MAAM,IACN,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EAAA,CACvB,CACF,EAAA,CACM;AAEV;;;;"}
|
|
@@ -4,7 +4,6 @@ import classNames from 'classnames';
|
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
6
6
|
import { useState, useMemo, useEffect } from 'react';
|
|
7
|
-
import { useReactive } from '../../../js/hooks.js';
|
|
8
7
|
import Icon from '../../icon/icon.js';
|
|
9
8
|
import Input from '../../input/input.js';
|
|
10
9
|
import Popup from '../../popup/popup.js';
|
|
@@ -15,29 +14,27 @@ const FORMATTYPES = ["YYYY-MM-DD", "YYYY-M-D", "YYYY/MM/DD", "YYYY/M/D"];
|
|
|
15
14
|
const FORMAT = "YYYY-MM-DD";
|
|
16
15
|
const Datepicker = (props) => {
|
|
17
16
|
const { name, value, weeks, format = FORMAT, placeholder = props.format ?? FORMAT, className, renderDate, renderMonth, renderYear, popupProps, disabledDate, onDateClick, onChange, onBlur, ...restProps } = props;
|
|
18
|
-
const
|
|
19
|
-
value,
|
|
20
|
-
});
|
|
17
|
+
const [inputValue, setInputValue] = useState(value);
|
|
21
18
|
const [active, setActive] = useState(false);
|
|
22
19
|
const dayJsValue = useMemo(() => {
|
|
23
|
-
if (!
|
|
20
|
+
if (!inputValue)
|
|
24
21
|
return null;
|
|
25
|
-
const date = dayjs(
|
|
22
|
+
const date = dayjs(inputValue, format, true);
|
|
26
23
|
if (date.isValid())
|
|
27
24
|
return date;
|
|
28
25
|
return null;
|
|
29
|
-
}, [
|
|
26
|
+
}, [inputValue, format]);
|
|
30
27
|
const handleDateClick = (date) => {
|
|
31
28
|
handleChange(date.format(format));
|
|
32
29
|
};
|
|
33
30
|
const handleChange = (v) => {
|
|
34
|
-
|
|
31
|
+
setInputValue(v);
|
|
35
32
|
onChange?.(v);
|
|
36
33
|
};
|
|
37
34
|
const handleSetDate = () => {
|
|
38
|
-
if (!
|
|
35
|
+
if (!inputValue)
|
|
39
36
|
return;
|
|
40
|
-
const date = dayjs(
|
|
37
|
+
const date = dayjs(inputValue, FORMATTYPES, true);
|
|
41
38
|
if (date.isValid()) {
|
|
42
39
|
handleChange(date.format(format));
|
|
43
40
|
return;
|
|
@@ -53,9 +50,9 @@ const Datepicker = (props) => {
|
|
|
53
50
|
setActive(v);
|
|
54
51
|
};
|
|
55
52
|
useEffect(() => {
|
|
56
|
-
|
|
53
|
+
setInputValue(value);
|
|
57
54
|
}, [value]);
|
|
58
|
-
return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', onVisibleChange: handleVisibleChange, watchResize: true, content: jsx(Panel, { value: dayJsValue, weeks: weeks, renderDate: renderDate, renderMonth: renderMonth, renderYear: renderYear, disabledDate: disabledDate, onDateClick: handleDateClick }), ...popupProps, children: jsx(Input, { value:
|
|
55
|
+
return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', onVisibleChange: handleVisibleChange, watchResize: true, content: jsx(Panel, { value: dayJsValue, weeks: weeks, renderDate: renderDate, renderMonth: renderMonth, renderYear: renderYear, disabledDate: disabledDate, onDateClick: handleDateClick }), ...popupProps, children: jsx(Input, { value: inputValue, append: jsx(Icon, { icon: jsx(CalendarMonthTwotone, {}), className: 'i-datepicker-icon', size: '1em' }), placeholder: placeholder, onChange: handleChange, onBlur: handleBlur, onEnter: handleSetDate, className: classNames("i-datepicker-label", className), ...restProps }) }));
|
|
59
56
|
};
|
|
60
57
|
|
|
61
58
|
export { Datepicker as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/dates/index.tsx"],"sourcesContent":["import { CalendarMonthTwotone } from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport dayjs, { Dayjs } from \"dayjs\";\nimport customParseFormat from \"dayjs/plugin/customParseFormat.js\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/dates/index.tsx"],"sourcesContent":["import { CalendarMonthTwotone } from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport dayjs, { Dayjs } from \"dayjs\";\nimport customParseFormat from \"dayjs/plugin/customParseFormat.js\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport Icon from \"../../icon\";\nimport Input from \"../../input\";\nimport Popup from \"../../popup\";\nimport { IDatePicker } from \"../type\";\nimport \"./index.css\";\nimport Panel from \"./panel\";\n\ndayjs.extend(customParseFormat);\n\nconst FORMATTYPES = [\"YYYY-MM-DD\", \"YYYY-M-D\", \"YYYY/MM/DD\", \"YYYY/M/D\"];\nconst FORMAT = \"YYYY-MM-DD\";\n\nconst Datepicker = (props: IDatePicker) => {\n\tconst {\n\t\tname,\n\t\tvalue,\n\t\tweeks,\n\t\tformat = FORMAT,\n\t\tplaceholder = props.format ?? FORMAT,\n\t\tclassName,\n\t\trenderDate,\n\t\trenderMonth,\n\t\trenderYear,\n\t\tpopupProps,\n\t\tdisabledDate,\n\t\tonDateClick,\n\t\tonChange,\n\t\tonBlur,\n\t\t...restProps\n\t} = props;\n\n\tconst [inputValue, setInputValue] = useState(value);\n\n\tconst [active, setActive] = useState<boolean>(false);\n\n\tconst dayJsValue = useMemo(() => {\n\t\tif (!inputValue) return null;\n\n\t\tconst date = dayjs(inputValue as string, format, true);\n\n\t\tif (date.isValid()) return date;\n\n\t\treturn null;\n\t}, [inputValue, format]);\n\n\tconst handleDateClick = (date: Dayjs) => {\n\t\thandleChange(date.format(format));\n\t};\n\n\tconst handleChange = (v) => {\n\t\tsetInputValue(v);\n\t\tonChange?.(v);\n\t};\n\n\tconst handleSetDate = () => {\n\t\tif (!inputValue) return;\n\n\t\tconst date = dayjs(inputValue as string, FORMATTYPES, true);\n\n\t\tif (date.isValid()) {\n\t\t\thandleChange(date.format(format));\n\t\t\treturn;\n\t\t}\n\n\t\thandleChange(\"\");\n\t};\n\n\tconst handleBlur = (e) => {\n\t\tonBlur?.(e);\n\t\thandleSetDate();\n\t};\n\n\tconst handleVisibleChange = (v) => {\n\t\tpopupProps?.onVisibleChange?.(v);\n\t\tsetActive(v);\n\t};\n\n\tuseEffect(() => {\n\t\tsetInputValue(value);\n\t}, [value]);\n\n\treturn (\n\t\t<Popup\n\t\t\tvisible={active}\n\t\t\ttrigger='click'\n\t\t\tposition='bottom'\n\t\t\tarrow={false}\n\t\t\talign='start'\n\t\t\tonVisibleChange={handleVisibleChange}\n\t\t\twatchResize\n\t\t\tcontent={\n\t\t\t\t<Panel\n\t\t\t\t\tvalue={dayJsValue}\n\t\t\t\t\tweeks={weeks}\n\t\t\t\t\trenderDate={renderDate}\n\t\t\t\t\trenderMonth={renderMonth}\n\t\t\t\t\trenderYear={renderYear}\n\t\t\t\t\tdisabledDate={disabledDate}\n\t\t\t\t\tonDateClick={handleDateClick}\n\t\t\t\t/>\n\t\t\t}\n\t\t\t{...popupProps}\n\t\t>\n\t\t\t<Input\n\t\t\t\tvalue={inputValue}\n\t\t\t\tappend={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={<CalendarMonthTwotone />}\n\t\t\t\t\t\tclassName='i-datepicker-icon'\n\t\t\t\t\t\tsize='1em'\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tplaceholder={placeholder}\n\t\t\t\tonChange={handleChange}\n\t\t\t\tonBlur={handleBlur}\n\t\t\t\tonEnter={handleSetDate}\n\t\t\t\tclassName={classNames(\"i-datepicker-label\", className)}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t</Popup>\n\t);\n};\n\nexport default Datepicker;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAYA,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC;AAE/B,MAAM,WAAW,GAAG,CAAC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC;AACxE,MA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AAM,EAAE,UAAU,EAClB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,UAAU,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAA,GAClD,SAAS,EAAA,CACZ,EAAA,CACK;AAEV;;;;"}
|
|
@@ -3,8 +3,7 @@ import { KeyboardArrowLeftRound, KeyboardArrowRightRound } from '@ricons/materia
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import { throttle } from 'radash';
|
|
6
|
-
import { useRef, useEffect } from 'react';
|
|
7
|
-
import { useReactive } from '../../../js/hooks.js';
|
|
6
|
+
import { useState, useRef, useEffect } from 'react';
|
|
8
7
|
import Icon from '../../icon/icon.js';
|
|
9
8
|
import Helpericon from '../../utils/helpericon/helpericon.js';
|
|
10
9
|
import Dates from './dates.js';
|
|
@@ -16,61 +15,56 @@ const YearMonth = (props) => {
|
|
|
16
15
|
};
|
|
17
16
|
const Panel = (props) => {
|
|
18
17
|
const { value, unitYear, unitMonth, renderDate, renderMonth = (m) => m, renderYear = (y) => y, disabledDate, onDateClick, } = props;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
selectable: false,
|
|
25
|
-
});
|
|
18
|
+
const [today, setToday] = useState(value);
|
|
19
|
+
const [month, setMonth] = useState(value || dayjs());
|
|
20
|
+
const [selectedYear, setSelectedYear] = useState(dayjs());
|
|
21
|
+
const [years, setYears] = useState([]);
|
|
22
|
+
const [selectable, setSelectable] = useState(false);
|
|
26
23
|
const $years = useRef(null);
|
|
27
24
|
const handleOperateMonth = (next) => {
|
|
28
|
-
|
|
25
|
+
setMonth((m) => m[next ? "add" : "subtract"](1, "month"));
|
|
29
26
|
};
|
|
30
27
|
const handleChangeDate = (date) => {
|
|
31
|
-
if (date.isSame(
|
|
28
|
+
if (date.isSame(today, "day"))
|
|
32
29
|
return;
|
|
33
|
-
if (!date.isSame(
|
|
34
|
-
|
|
30
|
+
if (!date.isSame(month, "month")) {
|
|
31
|
+
setMonth(date);
|
|
35
32
|
}
|
|
36
|
-
|
|
33
|
+
setToday(date);
|
|
37
34
|
onDateClick?.(date);
|
|
38
35
|
};
|
|
39
36
|
const handleChangeMonth = (month) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.month(month - 1);
|
|
43
|
-
state.selectable = false;
|
|
37
|
+
setMonth((m) => m.year(selectedYear.year()).month(month - 1));
|
|
38
|
+
setSelectable(false);
|
|
44
39
|
};
|
|
45
40
|
const getMoreYears = throttle({ interval: 100 }, (e) => {
|
|
46
41
|
const isUp = e.deltaY < 0;
|
|
47
|
-
|
|
42
|
+
setYears((ys) => ys.map((y) => y + (isUp ? -1 : 1)));
|
|
48
43
|
});
|
|
49
44
|
useEffect(() => {
|
|
50
|
-
if (!
|
|
45
|
+
if (!selectable)
|
|
51
46
|
return;
|
|
52
|
-
|
|
53
|
-
const y =
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
}, [
|
|
47
|
+
setSelectedYear(month);
|
|
48
|
+
const y = month.year();
|
|
49
|
+
const nextYears = Array.from({ length: 7 }).map((_, i) => y - 3 + i);
|
|
50
|
+
setYears([...nextYears]);
|
|
51
|
+
}, [selectable, month]);
|
|
57
52
|
useEffect(() => {
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
setToday(value);
|
|
54
|
+
setMonth(value || dayjs());
|
|
60
55
|
}, [value]);
|
|
61
|
-
return (jsxs("div", { className: 'i-datepicker', children: [jsxs("div", { className: 'i-datepicker-units', children: [jsx(YearMonth, { value:
|
|
62
|
-
"i-datepicker-active":
|
|
56
|
+
return (jsxs("div", { className: 'i-datepicker', children: [jsxs("div", { className: 'i-datepicker-units', children: [jsx(YearMonth, { value: month, unitYear: unitYear, unitMonth: unitMonth, renderMonth: renderMonth, renderYear: renderYear, onClick: () => setSelectable(true) }), jsx("a", { className: 'ml-auto i-datepicker-action', "data-ripple": true, onClick: () => handleOperateMonth(false), children: jsx(Icon, { icon: jsx(KeyboardArrowLeftRound, {}) }) }), jsx("a", { className: 'i-datepicker-action', "data-ripple": true, onClick: () => handleOperateMonth(true), children: jsx(Icon, { icon: jsx(KeyboardArrowRightRound, {}) }) })] }), jsxs("div", { className: classNames("i-datepicker-ym", {
|
|
57
|
+
"i-datepicker-active": selectable,
|
|
63
58
|
}), children: [jsx(Helpericon, { active: true, className: 'i-datepicker-close', onClick: (e) => {
|
|
64
59
|
e.stopPropagation();
|
|
65
|
-
|
|
66
|
-
} }), jsx("div", { ref: $years, className: 'i-datepicker-years', onWheel: getMoreYears, children:
|
|
67
|
-
"i-datepicker-active": y ===
|
|
68
|
-
}), onClick: () => (
|
|
69
|
-
state.selectedYear.year(y)), children: renderYear(y) }, y))) }), jsx("div", { className: 'i-datepicker-months', children: MONTHS.map((m) => {
|
|
60
|
+
setSelectable(false);
|
|
61
|
+
} }), jsx("div", { ref: $years, className: 'i-datepicker-years', onWheel: getMoreYears, children: years.map((y) => (jsx("a", { className: classNames("i-datepicker-year", {
|
|
62
|
+
"i-datepicker-active": y === selectedYear.year(),
|
|
63
|
+
}), onClick: () => setSelectedYear((sy) => sy.year(y)), children: renderYear(y) }, y))) }), jsx("div", { className: 'i-datepicker-months', children: MONTHS.map((m) => {
|
|
70
64
|
return (jsx("a", { className: classNames("i-datepicker-month", {
|
|
71
|
-
"i-datepicker-active": m ===
|
|
65
|
+
"i-datepicker-active": m === month.month() + 1,
|
|
72
66
|
}), onClick: () => handleChangeMonth(m), children: renderMonth(m) }, m));
|
|
73
|
-
}) })] }), jsx(Dates, { value:
|
|
67
|
+
}) })] }), jsx(Dates, { value: today, month: month, disabledDate: disabledDate, onDateClick: handleChangeDate, renderDate: renderDate })] }));
|
|
74
68
|
};
|
|
75
69
|
|
|
76
70
|
export { Panel as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel.js","sources":["../../../../../packages/components/picker/dates/panel.tsx"],"sourcesContent":["import {\n\tKeyboardArrowLeftRound,\n\tKeyboardArrowRightRound,\n} from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport dayjs, { Dayjs } from \"dayjs\";\nimport { throttle } from \"radash\";\nimport { ReactNode, useEffect, useRef } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"panel.js","sources":["../../../../../packages/components/picker/dates/panel.tsx"],"sourcesContent":["import {\n\tKeyboardArrowLeftRound,\n\tKeyboardArrowRightRound,\n} from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport dayjs, { Dayjs } from \"dayjs\";\nimport { throttle } from \"radash\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport Icon from \"../../icon\";\nimport Helpericon from \"../../utils/helpericon\";\nimport { IBaseDates } from \"../type\";\nimport Dates from \"./dates\";\n\nconst MONTHS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];\n\nconst YearMonth = (\n\tprops: IBaseDates & {\n\t\tonClick?: () => void;\n\t}\n) => {\n\tconst {\n\t\tvalue,\n\t\tunitMonth = \"月\",\n\t\tunitYear = \"年\",\n\t\trenderYear,\n\t\trenderMonth,\n\t\tonClick,\n\t} = props;\n\n\treturn (\n\t\t<a className='i-datepicker-action' data-ripple onClick={onClick}>\n\t\t\t<span>{renderYear?.(value.year())}</span>\n\t\t\t{unitYear}\n\t\t\t<span>{renderMonth?.(value.month() + 1)}</span>\n\t\t\t{unitMonth}\n\t\t</a>\n\t);\n};\n\nconst Panel = (props: IBaseDates) => {\n\tconst {\n\t\tvalue,\n\t\tunitYear,\n\t\tunitMonth,\n\t\trenderDate,\n\t\trenderMonth = (m: ReactNode) => m,\n\t\trenderYear = (y: ReactNode) => y,\n\t\tdisabledDate,\n\t\tonDateClick,\n\t} = props;\n\n\tconst [today, setToday] = useState(value);\n\tconst [month, setMonth] = useState(value || dayjs());\n\tconst [selectedYear, setSelectedYear] = useState(dayjs());\n\tconst [years, setYears] = useState<number[]>([]);\n\tconst [selectable, setSelectable] = useState(false);\n\n\tconst $years = useRef<HTMLDivElement>(null);\n\n\tconst handleOperateMonth = (next: boolean) => {\n\t\tsetMonth((m) => m[next ? \"add\" : \"subtract\"](1, \"month\"));\n\t};\n\n\tconst handleChangeDate = (date: Dayjs) => {\n\t\tif (date.isSame(today, \"day\")) return;\n\n\t\tif (!date.isSame(month, \"month\")) {\n\t\t\tsetMonth(date);\n\t\t}\n\n\t\tsetToday(date);\n\t\tonDateClick?.(date);\n\t};\n\n\tconst handleChangeMonth = (month: number) => {\n\t\tsetMonth((m) => m.year(selectedYear.year()).month(month - 1));\n\t\tsetSelectable(false);\n\t};\n\n\tconst getMoreYears = throttle({ interval: 100 }, (e) => {\n\t\tconst isUp = e.deltaY < 0;\n\n\t\tsetYears((ys) => ys.map((y) => y + (isUp ? -1 : 1)));\n\t});\n\n\tuseEffect(() => {\n\t\tif (!selectable) return;\n\n\t\tsetSelectedYear(month);\n\t\tconst y = month.year();\n\t\tconst nextYears = Array.from({ length: 7 }).map((_, i) => y - 3 + i);\n\n\t\tsetYears([...nextYears]);\n\t}, [selectable, month]);\n\n\tuseEffect(() => {\n\t\tsetToday(value);\n\t\tsetMonth(value || dayjs());\n\t}, [value]);\n\n\treturn (\n\t\t<div className='i-datepicker'>\n\t\t\t<div className='i-datepicker-units'>\n\t\t\t\t<YearMonth\n\t\t\t\t\tvalue={month}\n\t\t\t\t\tunitYear={unitYear}\n\t\t\t\t\tunitMonth={unitMonth}\n\t\t\t\t\trenderMonth={renderMonth}\n\t\t\t\t\trenderYear={renderYear}\n\t\t\t\t\tonClick={() => setSelectable(true)}\n\t\t\t\t/>\n\t\t\t\t<a\n\t\t\t\t\tclassName='ml-auto i-datepicker-action'\n\t\t\t\t\tdata-ripple\n\t\t\t\t\tonClick={() => handleOperateMonth(false)}\n\t\t\t\t>\n\t\t\t\t\t<Icon icon={<KeyboardArrowLeftRound />} />\n\t\t\t\t</a>\n\t\t\t\t<a\n\t\t\t\t\tclassName='i-datepicker-action'\n\t\t\t\t\tdata-ripple\n\t\t\t\t\tonClick={() => handleOperateMonth(true)}\n\t\t\t\t>\n\t\t\t\t\t<Icon icon={<KeyboardArrowRightRound />} />\n\t\t\t\t</a>\n\t\t\t</div>\n\n\t\t\t<div\n\t\t\t\tclassName={classNames(\"i-datepicker-ym\", {\n\t\t\t\t\t\"i-datepicker-active\": selectable,\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t<Helpericon\n\t\t\t\t\tactive\n\t\t\t\t\tclassName='i-datepicker-close'\n\t\t\t\t\tonClick={(e) => {\n\t\t\t\t\t\te.stopPropagation();\n\t\t\t\t\t\tsetSelectable(false);\n\t\t\t\t\t}}\n\t\t\t\t/>\n\n\t\t\t\t<div\n\t\t\t\t\tref={$years}\n\t\t\t\t\tclassName='i-datepicker-years'\n\t\t\t\t\tonWheel={getMoreYears}\n\t\t\t\t>\n\t\t\t\t\t{years.map((y) => (\n\t\t\t\t\t\t<a\n\t\t\t\t\t\t\tkey={y}\n\t\t\t\t\t\t\tclassName={classNames(\"i-datepicker-year\", {\n\t\t\t\t\t\t\t\t\"i-datepicker-active\":\n\t\t\t\t\t\t\t\t\ty === selectedYear.year(),\n\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\tonClick={() => setSelectedYear((sy) => sy.year(y))}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{renderYear(y)}\n\t\t\t\t\t\t</a>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\n\t\t\t\t<div className='i-datepicker-months'>\n\t\t\t\t\t{MONTHS.map((m) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<a\n\t\t\t\t\t\t\t\tkey={m}\n\t\t\t\t\t\t\t\tclassName={classNames(\"i-datepicker-month\", {\n\t\t\t\t\t\t\t\t\t\"i-datepicker-active\":\n\t\t\t\t\t\t\t\t\t\tm === month.month() + 1,\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\tonClick={() => handleChangeMonth(m)}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{renderMonth(m)}\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t<Dates\n\t\t\t\tvalue={today}\n\t\t\t\tmonth={month}\n\t\t\t\tdisabledDate={disabledDate}\n\t\t\t\tonDateClick={handleChangeDate}\n\t\t\t\trenderDate={renderDate}\n\t\t\t/>\n\t\t</div>\n\t);\n};\n\nexport default Panel;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AAaA,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AAEtD,MAAM,SAAS,GAAG,CACjB,KAEC,KACE;AACH,IAAA,MAAM,EACL,KAAK,EACL,SAAS,GAAG,GAAG,EACf,QAAQ,GAAG,GAAG,EACd,UAAU,EACV,WAAW,EACX,OAAO,GACP,GAAG,KAAK;AAET,IAAA,QACCA,IAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAC,qBAAqB,uBAAa,OAAO,EAAE,OAAO,EAAA,QAAA,EAAA,CAC9DC,wBAAO,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,EAAA,CAAQ,EACxC,QAAQ,EACTA,GAAA,CAAA,MAAA,EAAA,EAAA,QAAA,EAAO,WAAW,GAAG,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAA,CAAQ,EAC9C,SAAS,CAAA,EAAA,CACP;AAEN,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,KAAiB,KAAI;AACnC,IAAA,MAAM,EACL,KAAK,EACL,QAAQ,EACR,SAAS,EACT,UAAU,EACV,WAAW,GAAG,CAAC,CAAY,KAAK,CAAC,EACjC,UAAU,GAAG,CAAC,CAAY,KAAK,CAAC,EAChC,YAAY,EACZ,WAAW,GACX,GAAG,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,CAAC,CAAC,CAAC,CAAC,EAAA,QAAA,EAEjD,UAAU,CAAC,CAAC,CAAC,IAPT,CAAC,CAQH,CACJ,CAAC,EAAA,CACG,EAENA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,qBAAqB,EAAA,QAAA,EAClC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAI;AACjB,4BAAA,QACCA,GAAA,CAAA,GAAA,EAAA,EAEC,SAAS,EAAE,UAAU,CAAC,oBAAoB,EAAE;oCAC3C,qBAAqB,EACpB,CAAC,KAAK,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC;AACxB,iCAAA,CAAC,EACF,OAAO,EAAE,MAAM,iBAAiB,CAAC,CAAC,CAAC,EAAA,QAAA,EAElC,WAAW,CAAC,CAAC,CAAC,IAPV,CAAC,CAQH;AAEN,wBAAA,CAAC,CAAC,EAAA,CACG,CAAA,EAAA,CACD,EAENA,GAAA,CAAC,KAAK,EAAA,EACL,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,gBAAgB,EAC7B,UAAU,EAAE,UAAU,EAAA,CACrB,CAAA,EAAA,CACG;AAER;;;;"}
|
|
@@ -2,7 +2,6 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { AccessTimeRound } from '@ricons/material';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { useState, useEffect } from 'react';
|
|
5
|
-
import { useReactive } from '../../../js/hooks.js';
|
|
6
5
|
import Icon from '../../icon/icon.js';
|
|
7
6
|
import Input from '../../input/input.js';
|
|
8
7
|
import Popup from '../../popup/popup.js';
|
|
@@ -11,22 +10,19 @@ import Panel from './panel.js';
|
|
|
11
10
|
const FORMAT = "hh:mm:ss";
|
|
12
11
|
function TimePicker(props) {
|
|
13
12
|
const { name, value, format = FORMAT, periods, placeholder = props.format ?? FORMAT, className, renderItem, onChange, onBlur, popupProps, ...restProps } = props;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
safeValue: undefined,
|
|
17
|
-
});
|
|
13
|
+
const [timeValue, setTimeValue] = useState(value);
|
|
14
|
+
const [safeValue, setSafeValue] = useState(undefined);
|
|
18
15
|
const [active, setActive] = useState(false);
|
|
19
16
|
const handleChange = (v) => {
|
|
20
|
-
|
|
17
|
+
setTimeValue(v);
|
|
21
18
|
};
|
|
22
19
|
const handleFallback = (v) => {
|
|
23
|
-
|
|
20
|
+
setSafeValue(v);
|
|
24
21
|
};
|
|
25
22
|
const handleValidTime = () => {
|
|
26
|
-
if (!
|
|
23
|
+
if (!timeValue)
|
|
27
24
|
return;
|
|
28
|
-
|
|
29
|
-
handleChange(state.safeValue);
|
|
25
|
+
setTimeValue(safeValue);
|
|
30
26
|
};
|
|
31
27
|
const handleBlur = (e) => {
|
|
32
28
|
onBlur?.(e);
|
|
@@ -37,9 +33,9 @@ function TimePicker(props) {
|
|
|
37
33
|
setActive(v);
|
|
38
34
|
};
|
|
39
35
|
useEffect(() => {
|
|
40
|
-
|
|
36
|
+
setTimeValue(value);
|
|
41
37
|
}, [value]);
|
|
42
|
-
return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', watchResize: true, ...popupProps, onVisibleChange: handleVisibleChange, content: jsx(Panel, { value:
|
|
38
|
+
return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', watchResize: true, ...popupProps, onVisibleChange: handleVisibleChange, content: jsx(Panel, { value: timeValue, format: format, periods: periods, renderItem: renderItem, onChange: handleChange, onFallback: handleFallback }), children: jsx(Input, { value: timeValue, placeholder: placeholder, append: jsx(Icon, { icon: jsx(AccessTimeRound, {}), className: 'i-timepicker-icon', size: '1em' }), onChange: handleChange, onBlur: handleBlur, className: classNames("i-timepicker-label", className), ...restProps }) }));
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
export { TimePicker as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/time/index.tsx"],"sourcesContent":["import { AccessTimeRound } from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport { useEffect, useState } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../packages/components/picker/time/index.tsx"],"sourcesContent":["import { AccessTimeRound } from \"@ricons/material\";\nimport classNames from \"classnames\";\nimport { useEffect, useState } from \"react\";\nimport Icon from \"../../icon\";\nimport Input from \"../../input\";\nimport Popup from \"../../popup\";\nimport { ITimePicker } from \"../type\";\nimport Panel from \"./panel\";\n\nconst FORMAT = \"hh:mm:ss\";\n\nexport default function TimePicker(props: ITimePicker) {\n\tconst {\n\t\tname,\n\t\tvalue,\n\t\tformat = FORMAT,\n\t\tperiods,\n\t\tplaceholder = props.format ?? FORMAT,\n\t\tclassName,\n\t\trenderItem,\n\t\tonChange,\n\t\tonBlur,\n\t\tpopupProps,\n\t\t...restProps\n\t} = props;\n\tconst [timeValue, setTimeValue] = useState(value);\n\tconst [safeValue, setSafeValue] = useState(undefined);\n\tconst [active, setActive] = useState<boolean>(false);\n\n\tconst handleChange = (v) => {\n\t\tsetTimeValue(v);\n\t};\n\n\tconst handleFallback = (v) => {\n\t\tsetSafeValue(v);\n\t};\n\n\tconst handleValidTime = () => {\n\t\tif (!timeValue) return;\n\n\t\tsetTimeValue(safeValue);\n\t};\n\n\tconst handleBlur = (e) => {\n\t\tonBlur?.(e);\n\t\thandleValidTime();\n\t};\n\n\tconst handleVisibleChange = (v) => {\n\t\tpopupProps?.onVisibleChange?.(v);\n\t\tsetActive(v);\n\t};\n\n\tuseEffect(() => {\n\t\tsetTimeValue(value);\n\t}, [value]);\n\n\treturn (\n\t\t<Popup\n\t\t\tvisible={active}\n\t\t\ttrigger='click'\n\t\t\tposition='bottom'\n\t\t\tarrow={false}\n\t\t\talign='start'\n\t\t\twatchResize\n\t\t\t{...popupProps}\n\t\t\tonVisibleChange={handleVisibleChange}\n\t\t\tcontent={\n\t\t\t\t<Panel\n\t\t\t\t\tvalue={timeValue}\n\t\t\t\t\tformat={format}\n\t\t\t\t\tperiods={periods}\n\t\t\t\t\trenderItem={renderItem}\n\t\t\t\t\tonChange={handleChange}\n\t\t\t\t\tonFallback={handleFallback}\n\t\t\t\t/>\n\t\t\t}\n\t\t>\n\t\t\t<Input\n\t\t\t\tvalue={timeValue}\n\t\t\t\tplaceholder={placeholder}\n\t\t\t\tappend={\n\t\t\t\t\t<Icon\n\t\t\t\t\t\ticon={<AccessTimeRound />}\n\t\t\t\t\t\tclassName='i-timepicker-icon'\n\t\t\t\t\t\tsize='1em'\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tonChange={handleChange}\n\t\t\t\tonBlur={handleBlur}\n\t\t\t\tclassName={classNames(\"i-timepicker-label\", className)}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t</Popup>\n\t);\n}\n"],"names":["_jsx"],"mappings":";;;;;;;;;AASA,MAAM,MAAM,GAAG,UAAU;AAEX,SAAU,UAAU,CAAC,KAAkB,EAAA;AACpD,IAAA,MAAM,EACL,IAAI,EACJ,KAAK,EACL,MAAM,GAAG,MAAM,EACf,OAAO,EACP,WAAW,GAAG,KAAK,CAAC,MAAM,IAAI,MAAM,EACpC,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,UAAU,EACV,GAAG,SAAS,EACZ,GAAG,KAAK;IACT,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;IACjD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC;IACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC;AAEpD,IAAA,MAAM,YAAY,GAAG,CAAC,CAAC,KAAI;QAC1B,YAAY,CAAC,CAAC,CAAC;AAChB,IAAA,CAAC;AAED,IAAA,MAAM,cAAc,GAAG,CAAC,CAAC,KAAI;QAC5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,UAAU,EAClB,SAAS,EAAE,UAAU,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAA,GAClD,SAAS,EAAA,CACZ,EAAA,CACK;AAEV;;;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useMemo, useEffect } from 'react';
|
|
3
|
-
import { useReactive } from '../../../js/hooks.js';
|
|
2
|
+
import { useState, useMemo, useEffect } from 'react';
|
|
4
3
|
import Items from './item.js';
|
|
5
4
|
|
|
6
5
|
const UnitMaps = {
|
|
@@ -13,12 +12,10 @@ const UnitMaps = {
|
|
|
13
12
|
};
|
|
14
13
|
function Panel(props) {
|
|
15
14
|
const { value, stepH = 1, stepM = 1, stepS = 1, format, periods, renderItem, onChange, onFallback, } = props;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
second: undefined,
|
|
21
|
-
});
|
|
15
|
+
const [period, setPeriod] = useState(undefined);
|
|
16
|
+
const [hour, setHour] = useState(undefined);
|
|
17
|
+
const [minute, setMinute] = useState(undefined);
|
|
18
|
+
const [second, setSecond] = useState(undefined);
|
|
22
19
|
const [hours, minutes, seconds] = useMemo(() => {
|
|
23
20
|
const hasH = format.includes("h");
|
|
24
21
|
const hasM = format.includes("m");
|
|
@@ -34,29 +31,45 @@ function Panel(props) {
|
|
|
34
31
|
: [];
|
|
35
32
|
return [hours, minutes, seconds];
|
|
36
33
|
}, [stepH, stepM, stepS, format, periods]);
|
|
37
|
-
const updateValue = () => {
|
|
34
|
+
const updateValue = (next) => {
|
|
35
|
+
const nextPeriod = next?.period ?? period;
|
|
36
|
+
const nextHour = next?.hour ?? hour;
|
|
37
|
+
const nextMinute = next?.minute ?? minute;
|
|
38
|
+
const nextSecond = next?.second ?? second;
|
|
38
39
|
const reg = /(hh|h){1}|(mm|m){1}|(ss|s){1}/gi;
|
|
39
40
|
let result = format.replace(reg, (pattern) => {
|
|
40
41
|
const p = pattern.toLowerCase();
|
|
41
42
|
const u = UnitMaps[p];
|
|
42
|
-
const n =
|
|
43
|
+
const n = u === "hour"
|
|
44
|
+
? (nextHour ?? 0)
|
|
45
|
+
: u === "minute"
|
|
46
|
+
? (nextMinute ?? 0)
|
|
47
|
+
: (nextSecond ?? 0);
|
|
43
48
|
return p.length > 1 && n < 10 ? `0${n ?? 0}` : n ?? 0;
|
|
44
49
|
});
|
|
45
50
|
if (periods && hours.length > 0) {
|
|
46
|
-
result = `${
|
|
51
|
+
result = `${nextPeriod ?? periods[0]} ${result}`;
|
|
47
52
|
}
|
|
48
53
|
onChange(result);
|
|
49
54
|
};
|
|
50
55
|
const handleSetTime = (v, unit) => {
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
const next = { period, hour, minute, second, [unit]: v };
|
|
57
|
+
if (unit === "period")
|
|
58
|
+
setPeriod(v);
|
|
59
|
+
if (unit === "hour")
|
|
60
|
+
setHour(v);
|
|
61
|
+
if (unit === "minute")
|
|
62
|
+
setMinute(v);
|
|
63
|
+
if (unit === "second")
|
|
64
|
+
setSecond(v);
|
|
65
|
+
updateValue(next);
|
|
53
66
|
};
|
|
54
67
|
useEffect(() => {
|
|
55
68
|
let time = value ?? "";
|
|
56
69
|
if (periods && hours.length > 0 && value) {
|
|
57
70
|
const [p, t] = value.split(" ");
|
|
58
71
|
time = t ?? "";
|
|
59
|
-
|
|
72
|
+
setPeriod(periods.includes(p) ? p : undefined);
|
|
60
73
|
}
|
|
61
74
|
const nums = time.match(/\d+/g) ?? [];
|
|
62
75
|
if (!nums.length) {
|
|
@@ -64,19 +77,23 @@ function Panel(props) {
|
|
|
64
77
|
return;
|
|
65
78
|
}
|
|
66
79
|
let i = 0;
|
|
80
|
+
const parsed = {
|
|
81
|
+
hour: undefined,
|
|
82
|
+
minute: undefined,
|
|
83
|
+
second: undefined,
|
|
84
|
+
};
|
|
67
85
|
const r = format.replace(/(hh|h)+|(mm|m)+|(ss|s)+/gi, (p) => {
|
|
68
86
|
const n = nums[i++] ?? 0;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
o = Math.min(periods ? 11 : 23, n);
|
|
72
|
-
}
|
|
73
|
-
o = Math.min(59, n);
|
|
74
|
-
state[UnitMaps[p]] = o;
|
|
87
|
+
const o = Math.min(59, n);
|
|
88
|
+
parsed[UnitMaps[p]] = o;
|
|
75
89
|
return p.length > 1 && o < 10 ? `0${o}` : o;
|
|
76
90
|
});
|
|
91
|
+
setHour(parsed.hour);
|
|
92
|
+
setMinute(parsed.minute);
|
|
93
|
+
setSecond(parsed.second);
|
|
77
94
|
onFallback(r);
|
|
78
|
-
}, [value]);
|
|
79
|
-
return (jsxs("div", { className: 'i-timepicker', children: [hours.length > 0 && (jsxs(Fragment, { children: [periods && (jsx("div", { className: 'i-timepicker-list', children: jsx(Items, { items: periods, active:
|
|
95
|
+
}, [value, format, hours.length, periods]);
|
|
96
|
+
return (jsxs("div", { className: 'i-timepicker', children: [hours.length > 0 && (jsxs(Fragment, { children: [periods && (jsx("div", { className: 'i-timepicker-list', children: jsx(Items, { items: periods, active: period, onClick: (p) => handleSetTime(p, "period") }) })), jsx("div", { className: 'i-timepicker-list', children: jsx(Items, { items: hours, active: hour, unit: 'hour', renderItem: renderItem, onClick: (h) => handleSetTime(h, "hour") }) })] })), minutes.length > 0 && (jsx("div", { className: 'i-timepicker-list', children: jsx(Items, { items: minutes, active: minute, unit: 'minute', renderItem: renderItem, onClick: (m) => handleSetTime(m, "minute") }) })), seconds.length > 0 && (jsx("div", { className: 'i-timepicker-list', children: jsx(Items, { items: seconds, active: second, unit: 'second', renderItem: renderItem, onClick: (s) => handleSetTime(s, "second") }) }))] }));
|
|
80
97
|
}
|
|
81
98
|
|
|
82
99
|
export { Panel as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel.js","sources":["../../../../../packages/components/picker/time/panel.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport
|
|
1
|
+
{"version":3,"file":"panel.js","sources":["../../../../../packages/components/picker/time/panel.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport \"./index.css\";\nimport Items from \"./item\";\n\nconst UnitMaps = {\n\th: \"hour\",\n\thh: \"hour\",\n\tm: \"minute\",\n\tmm: \"minute\",\n\ts: \"second\",\n\tss: \"second\",\n};\n\nexport default function Panel(props) {\n\tconst {\n\t\tvalue,\n\t\tstepH = 1,\n\t\tstepM = 1,\n\t\tstepS = 1,\n\t\tformat,\n\t\tperiods,\n\t\trenderItem,\n\t\tonChange,\n\t\tonFallback,\n\t} = props;\n\tconst [period, setPeriod] = useState<any>(undefined);\n\tconst [hour, setHour] = useState<any>(undefined);\n\tconst [minute, setMinute] = useState<any>(undefined);\n\tconst [second, setSecond] = useState<any>(undefined);\n\n\tconst [hours, minutes, seconds] = useMemo(() => {\n\t\tconst hasH = format.includes(\"h\");\n\t\tconst hasM = format.includes(\"m\");\n\t\tconst hasS = format.includes(\"s\");\n\t\tconst hours = hasH\n\t\t\t? Array.from(\n\t\t\t\t\t{ length: (periods ? 12 : 24) / stepH },\n\t\t\t\t\t(_, i) => i * stepH\n\t\t\t )\n\t\t\t: [];\n\t\tconst minutes = hasM\n\t\t\t? Array.from({ length: 60 / stepM }, (_, i) => i * stepM)\n\t\t\t: [];\n\t\tconst seconds = hasS\n\t\t\t? Array.from({ length: 60 / stepS }, (_, i) => i * stepS)\n\t\t\t: [];\n\n\t\treturn [hours, minutes, seconds];\n\t}, [stepH, stepM, stepS, format, periods]);\n\n\tconst updateValue = (next?: {\n\t\tperiod?: any;\n\t\thour?: any;\n\t\tminute?: any;\n\t\tsecond?: any;\n\t}) => {\n\t\tconst nextPeriod = next?.period ?? period;\n\t\tconst nextHour = next?.hour ?? hour;\n\t\tconst nextMinute = next?.minute ?? minute;\n\t\tconst nextSecond = next?.second ?? second;\n\n\t\tconst reg = /(hh|h){1}|(mm|m){1}|(ss|s){1}/gi;\n\t\tlet result = format.replace(reg, (pattern) => {\n\t\t\tconst p = pattern.toLowerCase();\n\t\t\tconst u = UnitMaps[p];\n\t\t\tconst n =\n\t\t\t\tu === \"hour\"\n\t\t\t\t\t? (nextHour ?? 0)\n\t\t\t\t\t: u === \"minute\"\n\t\t\t\t\t\t? (nextMinute ?? 0)\n\t\t\t\t\t\t: (nextSecond ?? 0);\n\n\t\t\treturn p.length > 1 && n < 10 ? `0${n ?? 0}` : n ?? 0;\n\t\t});\n\n\t\tif (periods && hours.length > 0) {\n\t\t\tresult = `${nextPeriod ?? periods[0]} ${result}`;\n\t\t}\n\n\t\tonChange(result);\n\t};\n\n\tconst handleSetTime = (v, unit) => {\n\t\tconst next = { period, hour, minute, second, [unit]: v };\n\n\t\tif (unit === \"period\") setPeriod(v);\n\t\tif (unit === \"hour\") setHour(v);\n\t\tif (unit === \"minute\") setMinute(v);\n\t\tif (unit === \"second\") setSecond(v);\n\n\t\tupdateValue(next);\n\t};\n\n\tuseEffect(() => {\n\t\tlet time = value ?? \"\";\n\n\t\tif (periods && hours.length > 0 && value) {\n\t\t\tconst [p, t] = value.split(\" \");\n\t\t\ttime = t ?? \"\";\n\t\t\tsetPeriod(periods.includes(p) ? p : undefined);\n\t\t}\n\n\t\tconst nums = time.match(/\\d+/g) ?? [];\n\n\t\tif (!nums.length) {\n\t\t\tonFallback(\"\");\n\t\t\treturn;\n\t\t}\n\n\t\tlet i = 0;\n\t\tconst parsed = {\n\t\t\thour: undefined,\n\t\t\tminute: undefined,\n\t\t\tsecond: undefined,\n\t\t};\n\t\tconst r = format.replace(/(hh|h)+|(mm|m)+|(ss|s)+/gi, (p) => {\n\t\t\tconst n = nums[i++] ?? 0;\n\t\t\tconst o = Math.min(59, n);\n\t\t\tparsed[UnitMaps[p]] = o;\n\t\t\treturn p.length > 1 && o < 10 ? `0${o}` : o;\n\t\t});\n\n\t\tsetHour(parsed.hour);\n\t\tsetMinute(parsed.minute);\n\t\tsetSecond(parsed.second);\n\t\tonFallback(r);\n\t}, [value, format, hours.length, periods]);\n\n\treturn (\n\t\t<div className='i-timepicker'>\n\t\t\t{hours.length > 0 && (\n\t\t\t\t<>\n\t\t\t\t\t{periods && (\n\t\t\t\t\t\t<div className='i-timepicker-list'>\n\t\t\t\t\t\t\t<Items\n\t\t\t\t\t\t\t\titems={periods}\n\t\t\t\t\t\t\t\tactive={period}\n\t\t\t\t\t\t\t\tonClick={(p) => handleSetTime(p, \"period\")}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t)}\n\t\t\t\t\t<div className='i-timepicker-list'>\n\t\t\t\t\t\t<Items\n\t\t\t\t\t\t\titems={hours}\n\t\t\t\t\t\t\tactive={hour}\n\t\t\t\t\t\t\tunit='hour'\n\t\t\t\t\t\t\trenderItem={renderItem}\n\t\t\t\t\t\t\tonClick={(h) => handleSetTime(h, \"hour\")}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t)}\n\t\t\t{minutes.length > 0 && (\n\t\t\t\t<div className='i-timepicker-list'>\n\t\t\t\t\t<Items\n\t\t\t\t\t\titems={minutes}\n\t\t\t\t\t\tactive={minute}\n\t\t\t\t\t\tunit='minute'\n\t\t\t\t\t\trenderItem={renderItem}\n\t\t\t\t\t\tonClick={(m) => handleSetTime(m, \"minute\")}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t\t{seconds.length > 0 && (\n\t\t\t\t<div className='i-timepicker-list'>\n\t\t\t\t\t<Items\n\t\t\t\t\t\titems={seconds}\n\t\t\t\t\t\tactive={second}\n\t\t\t\t\t\tunit='second'\n\t\t\t\t\t\trenderItem={renderItem}\n\t\t\t\t\t\tonClick={(s) => handleSetTime(s, \"second\")}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;AAIA,MAAM,QAAQ,GAAG;AAChB,IAAA,CAAC,EAAE,MAAM;AACT,IAAA,EAAE,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