fis-component 0.0.77 → 0.0.78
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/dist/cjs/index.js +23 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/CheckboxGroup/index.d.ts +1 -1
- package/dist/cjs/types/src/components/Input/InputDate/InputDate.stories.d.ts +4 -0
- package/dist/cjs/types/src/components/Input/InputDate/index.d.ts +21 -0
- package/dist/esm/index.js +23 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/CheckboxGroup/index.d.ts +1 -1
- package/dist/esm/types/src/components/Input/InputDate/InputDate.stories.d.ts +4 -0
- package/dist/esm/types/src/components/Input/InputDate/index.d.ts +21 -0
- package/dist/index.d.ts +22 -1
- package/package.json +1 -1
|
@@ -3,3 +3,7 @@ import { InputDateProps } from ".";
|
|
|
3
3
|
declare const _default: Meta;
|
|
4
4
|
export default _default;
|
|
5
5
|
export declare const Default: (args: InputDateProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const YearPicker: (args: InputDateProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const MonthPicker: (args: InputDateProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const QuarterPicker: (args: InputDateProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare const AllModes: (args: InputDateProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InputFieldProps } from "../InputField";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import { InputLabelProps } from "../InputLabel";
|
|
4
|
+
export type DatePickerMode = "date" | "month" | "year" | "quarter";
|
|
4
5
|
export interface InputDateProps extends Omit<InputFieldProps, "value" | "onChange">, Partial<InputLabelProps> {
|
|
5
6
|
className?: string | undefined;
|
|
6
7
|
/**Date value*/
|
|
@@ -22,6 +23,26 @@ export interface InputDateProps extends Omit<InputFieldProps, "value" | "onChang
|
|
|
22
23
|
minDate?: dayjs.Dayjs | undefined;
|
|
23
24
|
/**The maximum selectable date. Dates after this value will be disabled.*/
|
|
24
25
|
maxDate?: dayjs.Dayjs | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Picker mode - determines what user can select
|
|
28
|
+
* - "date": Full date picker (default)
|
|
29
|
+
* - "month": Month picker only
|
|
30
|
+
* - "year": Year picker only
|
|
31
|
+
* - "quarter": Quarter picker only
|
|
32
|
+
*/
|
|
33
|
+
picker?: DatePickerMode;
|
|
34
|
+
/**Allow clear functionality*/
|
|
35
|
+
allowClear?: boolean;
|
|
36
|
+
/**Show today button*/
|
|
37
|
+
showToday?: boolean;
|
|
38
|
+
/**Show time selection*/
|
|
39
|
+
showTime?: boolean;
|
|
40
|
+
/**Auto focus when component mounted*/
|
|
41
|
+
autoFocus?: boolean;
|
|
42
|
+
/**Disabled date function*/
|
|
43
|
+
disabledDate?: (current: dayjs.Dayjs) => boolean;
|
|
44
|
+
/**Custom input format*/
|
|
45
|
+
inputReadOnly?: boolean;
|
|
25
46
|
}
|
|
26
47
|
declare const FISInputDate: import("react").ForwardRefExoticComponent<InputDateProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
27
48
|
export default FISInputDate;
|
package/dist/esm/index.js
CHANGED
|
@@ -71071,9 +71071,23 @@ function mergeRefs(...refs) {
|
|
|
71071
71071
|
}
|
|
71072
71072
|
|
|
71073
71073
|
const FISInputDate = forwardRef((props, ref) => {
|
|
71074
|
-
const { className, value, textLabel = "", iconLabel, required, message = "", disabled, negative, positive, format
|
|
71074
|
+
const { className, value, textLabel = "", iconLabel, required, message = "", disabled, negative, positive, format, onClickIconLabel, onChange, getPopupContainer, minDate, maxDate, picker = "date", allowClear = true, showToday = true, showTime = false, autoFocus = false, disabledDate, inputReadOnly = false, ...restProps } = props;
|
|
71075
|
+
const getDefaultFormat = (pickerMode) => {
|
|
71076
|
+
switch (pickerMode) {
|
|
71077
|
+
case "year":
|
|
71078
|
+
return "YYYY";
|
|
71079
|
+
case "month":
|
|
71080
|
+
return "MM/YYYY";
|
|
71081
|
+
case "quarter":
|
|
71082
|
+
return "YYYY-[Q]Q";
|
|
71083
|
+
case "date":
|
|
71084
|
+
default:
|
|
71085
|
+
return "DD/MM/YYYY";
|
|
71086
|
+
}
|
|
71087
|
+
};
|
|
71088
|
+
const finalFormat = format || getDefaultFormat(picker);
|
|
71075
71089
|
const [open, setOpen] = useState(false);
|
|
71076
|
-
const [inputValue, setInputValue] = useState(value ? dayjs(value).format(
|
|
71090
|
+
const [inputValue, setInputValue] = useState(value ? dayjs(value).format(finalFormat) : "");
|
|
71077
71091
|
const [dateValue, setDateValue] = useState(value ? dayjs(value) : null);
|
|
71078
71092
|
const inputRef = useRef(null);
|
|
71079
71093
|
const mergeRef = mergeRefs(inputRef, ref);
|
|
@@ -71082,28 +71096,30 @@ const FISInputDate = forwardRef((props, ref) => {
|
|
|
71082
71096
|
if (value) {
|
|
71083
71097
|
const newDayjs = dayjs(value);
|
|
71084
71098
|
setDateValue(newDayjs);
|
|
71085
|
-
setInputValue(newDayjs.format(
|
|
71099
|
+
setInputValue(newDayjs.format(finalFormat));
|
|
71086
71100
|
}
|
|
71087
71101
|
else {
|
|
71088
71102
|
setDateValue(null);
|
|
71089
71103
|
setInputValue("");
|
|
71090
71104
|
}
|
|
71091
|
-
}, [value,
|
|
71105
|
+
}, [value, finalFormat]);
|
|
71092
71106
|
const handleOpenChange = (openState) => {
|
|
71093
71107
|
setOpen(openState);
|
|
71094
71108
|
};
|
|
71095
71109
|
const handleChange = (selectedDate) => {
|
|
71096
71110
|
const newDate = selectedDate ? selectedDate.toDate() : null;
|
|
71097
71111
|
setDateValue(selectedDate);
|
|
71098
|
-
setInputValue(selectedDate ? selectedDate.format(
|
|
71112
|
+
setInputValue(selectedDate ? selectedDate.format(finalFormat) : "");
|
|
71099
71113
|
onChange?.(newDate);
|
|
71100
71114
|
setOpen(false);
|
|
71101
71115
|
};
|
|
71102
71116
|
const handleInputChange = (e) => {
|
|
71117
|
+
if (inputReadOnly)
|
|
71118
|
+
return;
|
|
71103
71119
|
const newInputValue = e.target.value;
|
|
71104
71120
|
setInputValue(newInputValue);
|
|
71105
71121
|
// Try to parse the input as a date
|
|
71106
|
-
const parsedDate = dayjs(newInputValue,
|
|
71122
|
+
const parsedDate = dayjs(newInputValue, finalFormat);
|
|
71107
71123
|
if (parsedDate.isValid()) {
|
|
71108
71124
|
setDateValue(parsedDate);
|
|
71109
71125
|
onChange?.(parsedDate.toDate());
|
|
@@ -71114,7 +71130,7 @@ const FISInputDate = forwardRef((props, ref) => {
|
|
|
71114
71130
|
onChange?.(null);
|
|
71115
71131
|
}
|
|
71116
71132
|
};
|
|
71117
|
-
return (jsxs(DivWrapperSC$2, { className: className, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxs(DivInputWrapperSC$1, { children: [jsx(FISInputField, { ...restProps, ref: mergeRef, typeSuffix: "icon", iconSuffix: jsx(DateIcon, {}), value: inputValue, negative: negative, disabled: disabled, onFocus: () => setOpen(true), onChange: handleInputChange, onClickSuffix: () => setOpen(true) }), jsx(HiddenDatePickerSC, { open: open, value: dateValue, onChange: (value) => handleChange(value), onOpenChange: handleOpenChange, format:
|
|
71133
|
+
return (jsxs(DivWrapperSC$2, { className: className, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxs(DivInputWrapperSC$1, { children: [jsx(FISInputField, { ...restProps, ref: mergeRef, typeSuffix: "icon", iconSuffix: jsx(DateIcon, {}), value: inputValue, negative: negative, disabled: disabled, placeholder: restProps.placeholder, readOnly: inputReadOnly, autoFocus: autoFocus, onFocus: () => setOpen(true), onChange: handleInputChange, onClickSuffix: () => setOpen(true) }), jsx(HiddenDatePickerSC, { open: open, value: dateValue, onChange: (value) => handleChange(value), onOpenChange: handleOpenChange, format: finalFormat, getPopupContainer: getPopupContainer, minDate: minDate, maxDate: maxDate, picker: picker, allowClear: allowClear, showToday: showToday, showTime: showTime, disabledDate: disabledDate })] }), message && (jsx(DivHintWrapperSC$1, { children: jsx(SpanHintSC$3, { className: classNames({
|
|
71118
71134
|
disabled,
|
|
71119
71135
|
negative,
|
|
71120
71136
|
positive,
|