react-better-html 1.1.58 → 1.1.60
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/components/BetterHtmlProvider.js +4 -0
- package/dist/components/InputField.d.ts +8 -1
- package/dist/components/InputField.js +69 -3
- package/dist/components/Label.d.ts +2 -1
- package/dist/components/Label.js +2 -2
- package/dist/utils/hooks.d.ts +7 -0
- package/dist/utils/hooks.js +75 -0
- package/package.json +1 -1
|
@@ -26,6 +26,10 @@ const GlobalStyle = (0, styled_components_1.createGlobalStyle) `
|
|
|
26
26
|
text-decoration: none;
|
|
27
27
|
color: inherit;
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
.react-better-html-no-scrollbar::-webkit-scrollbar {
|
|
31
|
+
display: none;
|
|
32
|
+
}
|
|
29
33
|
`;
|
|
30
34
|
const betterHtmlContext = (0, react_1.createContext)(undefined);
|
|
31
35
|
const useBetterHtmlContext = () => {
|
|
@@ -15,7 +15,9 @@ export type InputFieldProps = {
|
|
|
15
15
|
debounceDelay?: number;
|
|
16
16
|
onChangeValue?: (value: string) => void;
|
|
17
17
|
onClickRightIcon?: () => void;
|
|
18
|
+
holderRef?: React.ForwardedRef<HTMLDivElement>;
|
|
18
19
|
} & OmitProps<React.ComponentProps<"input">, "style" | "ref"> & ComponentStyle & ComponentHoverStyle;
|
|
20
|
+
export type TextareaFieldProps = OmitProps<InputFieldProps, "type"> & OmitProps<React.ComponentProps<"textarea">, "style" | "ref">;
|
|
19
21
|
type InputFieldComponentType = {
|
|
20
22
|
(props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>): React.ReactElement;
|
|
21
23
|
multiline: (props: ComponentPropWithRef<HTMLTextAreaElement, TextareaFieldProps>) => React.ReactElement;
|
|
@@ -23,14 +25,19 @@ type InputFieldComponentType = {
|
|
|
23
25
|
password: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
|
|
24
26
|
search: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
|
|
25
27
|
phoneNumber: (props: ComponentPropWithRef<HTMLInputElement, OmitProps<InputFieldProps, "type">>) => React.ReactElement;
|
|
28
|
+
date: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
|
|
29
|
+
dateTime: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
|
|
30
|
+
time: (props: ComponentPropWithRef<HTMLInputElement, InputFieldProps>) => React.ReactElement;
|
|
26
31
|
};
|
|
27
32
|
declare const InputFieldComponent: InputFieldComponentType;
|
|
28
|
-
export type TextareaFieldProps = OmitProps<InputFieldProps, "type"> & OmitProps<React.ComponentProps<"textarea">, "style" | "ref">;
|
|
29
33
|
declare const InputField: typeof InputFieldComponent & {
|
|
30
34
|
multiline: typeof InputFieldComponent.multiline;
|
|
31
35
|
email: typeof InputFieldComponent.email;
|
|
32
36
|
password: typeof InputFieldComponent.password;
|
|
33
37
|
search: typeof InputFieldComponent.search;
|
|
34
38
|
phoneNumber: typeof InputFieldComponent.phoneNumber;
|
|
39
|
+
date: typeof InputFieldComponent.date;
|
|
40
|
+
dateTime: typeof InputFieldComponent.dateTime;
|
|
41
|
+
time: typeof InputFieldComponent.time;
|
|
35
42
|
};
|
|
36
43
|
export default InputField;
|
|
@@ -47,6 +47,13 @@ const InputElement = styled_components_1.default.input.withConfig({
|
|
|
47
47
|
cursor: not-allowed;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
&[type="date"]::-webkit-calendar-picker-indicator,
|
|
51
|
+
&[type="datetime-local"]::-webkit-calendar-picker-indicator,
|
|
52
|
+
&[type="time"]::-webkit-calendar-picker-indicator {
|
|
53
|
+
display: none;
|
|
54
|
+
-webkit-appearance: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
&.react-better-html-phone-number-holder {
|
|
51
58
|
border-right: none;
|
|
52
59
|
border-top-right-radius: 0px;
|
|
@@ -71,6 +78,15 @@ const InputElement = styled_components_1.default.input.withConfig({
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
&.react-better-html-inputField-dateTime-opened {
|
|
82
|
+
border-bottom-left-radius: 0px;
|
|
83
|
+
border-bottom-right-radius: 0px;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&.react-better-html-inputField-dateTime-opened-late {
|
|
87
|
+
z-index: 1001;
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
${(props) => props.normalStyle}
|
|
75
91
|
|
|
76
92
|
&:hover {
|
|
@@ -111,7 +127,9 @@ const TextareaElement = styled_components_1.default.textarea.withConfig({
|
|
|
111
127
|
${(props) => props.hoverStyle}
|
|
112
128
|
}
|
|
113
129
|
`;
|
|
114
|
-
const
|
|
130
|
+
const hours = Array.from({ length: 24 }, (_, index) => index);
|
|
131
|
+
const minutes = Array.from({ length: 60 }, (_, index) => index);
|
|
132
|
+
const InputFieldComponent = (0, react_1.forwardRef)(function InputField({ label, errorText, infoText, leftIcon, rightIcon, insideInputFieldComponent, withDebounce, debounceDelay = 0.5, onChange, onChangeValue, onClickRightIcon, holderRef, required, placeholder, ...props }, ref) {
|
|
115
133
|
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
116
134
|
const [_, debouncedValue, setDebouncedValue] = (0, hooks_1.useDebounceState)(props.value?.toString() ?? "", debounceDelay);
|
|
117
135
|
const styledComponentStylesWithoutExcluded = (0, hooks_1.useStyledComponentStyles)(props, theme, true);
|
|
@@ -135,7 +153,7 @@ const InputFieldComponent = (0, react_1.forwardRef)(function InputField({ label,
|
|
|
135
153
|
return;
|
|
136
154
|
onChangeValue?.(debouncedValue);
|
|
137
155
|
}, [withDebounce, onChangeValue, debouncedValue]);
|
|
138
|
-
return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { width: "100%", gap: theme.styles.gap / 2, ...styledComponentStylesWithExcluded, children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: required, isError: !!errorText }), (0, jsx_runtime_1.jsxs)(Div_1.default, { position: "relative", width: "100%", children: [leftIcon && ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: leftIcon, position: "absolute", top: 46 / 2, left: theme.styles.space + 1, transform: "translateY(-50%)", pointerEvents: "none", zIndex: props.className?.includes("react-better-html-dropdown-open-late") ? 1002 : 1 })), (0, jsx_runtime_1.jsx)(InputElement, { theme: theme, withLeftIcon: leftIcon !== undefined, withRightIcon: rightIcon !== undefined, required: required, placeholder: placeholder ?? label, onChange: onChangeElement, ...styledComponentStylesWithoutExcluded, ...dataProps, ...ariaProps, ...restProps, ref: ref }), rightIcon ? (onClickRightIcon ? ((0, jsx_runtime_1.jsx)(Button_1.default.icon, { icon: rightIcon, position: "absolute", top: 46 / 2, right: theme.styles.space + 1 - theme.styles.space / 2, transform: "translateY(-50%)", onClick: onClickRightIcon })) : ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: rightIcon, position: "absolute", top: 46 / 2, right: theme.styles.space + 1, transform: "translateY(-50%)", pointerEvents: "none" }))) : undefined, insideInputFieldComponent] }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: errorText || infoText }))] }));
|
|
156
|
+
return ((0, jsx_runtime_1.jsxs)(Div_1.default.column, { width: "100%", gap: theme.styles.gap / 2, ...styledComponentStylesWithExcluded, ref: holderRef, children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: required, isError: !!errorText }), (0, jsx_runtime_1.jsxs)(Div_1.default, { position: "relative", width: "100%", children: [leftIcon && ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: leftIcon, position: "absolute", top: 46 / 2, left: theme.styles.space + 1, transform: "translateY(-50%)", pointerEvents: "none", zIndex: props.className?.includes("react-better-html-dropdown-open-late") ? 1002 : 1 })), (0, jsx_runtime_1.jsx)(InputElement, { theme: theme, withLeftIcon: leftIcon !== undefined, withRightIcon: rightIcon !== undefined, required: required, placeholder: placeholder ?? label, onChange: onChangeElement, ...styledComponentStylesWithoutExcluded, ...dataProps, ...ariaProps, ...restProps, ref: ref }), rightIcon ? (onClickRightIcon ? ((0, jsx_runtime_1.jsx)(Button_1.default.icon, { icon: rightIcon, position: "absolute", top: 46 / 2, right: theme.styles.space + 1 - theme.styles.space / 2, transform: "translateY(-50%)", onClick: onClickRightIcon })) : ((0, jsx_runtime_1.jsx)(Icon_1.default, { name: rightIcon, position: "absolute", top: 46 / 2, right: theme.styles.space + 1, transform: "translateY(-50%)", pointerEvents: "none" }))) : undefined, insideInputFieldComponent] }), (errorText || infoText) && ((0, jsx_runtime_1.jsx)(Text_1.default, { as: "span", display: "block", fontSize: 14, color: errorText ? theme.colors.error : theme.colors.textSecondary, children: errorText || infoText }))] }));
|
|
139
157
|
});
|
|
140
158
|
InputFieldComponent.multiline = (0, react_1.forwardRef)(function Multiline({ label, placeholder, errorText, infoText, leftIcon, rightIcon, onChange, onChangeValue, onClickRightIcon, required, ...props }, ref) {
|
|
141
159
|
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
@@ -193,7 +211,52 @@ InputFieldComponent.phoneNumber = (0, react_1.forwardRef)(function PhoneNumber({
|
|
|
193
211
|
setDropdownValue(country.phoneNumberExtension);
|
|
194
212
|
setInputFieldValue(newValue.slice(country?.phoneNumberExtension.length + 1));
|
|
195
213
|
}, [value]);
|
|
196
|
-
return ((0, jsx_runtime_1.jsxs)(Div_1.default, { children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: props.required, isError: !!props.errorText }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { options: options, renderOption: renderOption, width: 130, withSearch: true, placeholder: "+00", inputFieldClassName: "react-better-html-phone-number-holder", defaultValue: defaultValue, value: dropdownValue, onChange: setDropdownValue, withoutClearButton: true }), (0, jsx_runtime_1.jsx)(InputFieldComponent, { placeholder: "Phone number", className: "react-better-html-phone-number", value: inputFieldValue, onChangeValue: onChangeValueElement, ref: ref, ...props })] })] }));
|
|
214
|
+
return ((0, jsx_runtime_1.jsxs)(Div_1.default, { width: "100%", children: [label && (0, jsx_runtime_1.jsx)(Label_1.default, { text: label, required: props.required, isError: !!props.errorText }), (0, jsx_runtime_1.jsxs)(Div_1.default.row, { children: [(0, jsx_runtime_1.jsx)(Dropdown_1.default, { options: options, renderOption: renderOption, width: 130, minWidth: 116, withSearch: true, placeholder: "+00", inputFieldClassName: "react-better-html-phone-number-holder", defaultValue: defaultValue, value: dropdownValue, onChange: setDropdownValue, withoutClearButton: true }), (0, jsx_runtime_1.jsx)(InputFieldComponent, { placeholder: "Phone number", className: "react-better-html-phone-number", value: inputFieldValue, onChangeValue: onChangeValueElement, ref: ref, ...props })] })] }));
|
|
215
|
+
});
|
|
216
|
+
InputFieldComponent.date = (0, react_1.forwardRef)(function Date({ className, onFocus, onBlur, ...props }, ref) {
|
|
217
|
+
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
218
|
+
const holderRef = (0, react_1.useRef)(null);
|
|
219
|
+
const { internalValue, setInternalValue, inputFieldProps, insideInputFieldComponentProps } = (0, hooks_1.useComponentInputFieldDateProps)(props, holderRef);
|
|
220
|
+
return ((0, jsx_runtime_1.jsx)(InputFieldComponent, { type: "date", insideInputFieldComponent: (0, jsx_runtime_1.jsx)(Div_1.default, { position: "absolute", top: "100%", left: 0, width: "100%", maxHeight: 300, backgroundColor: theme.colors.backgroundContent, borderBottomLeftRadius: theme.styles.borderRadius, borderBottomRightRadius: theme.styles.borderRadius, boxShadow: "0px 10px 20px #00000020", overflowY: "auto", ...insideInputFieldComponentProps, children: "Hello there" }), holderRef: holderRef, ref: ref, ...props, ...inputFieldProps }));
|
|
221
|
+
});
|
|
222
|
+
InputFieldComponent.dateTime = (0, react_1.forwardRef)(function DateTime({ className, onFocus, onBlur, ...props }, ref) {
|
|
223
|
+
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
224
|
+
const holderRef = (0, react_1.useRef)(null);
|
|
225
|
+
const { internalValue, setInternalValue, inputFieldProps, insideInputFieldComponentProps } = (0, hooks_1.useComponentInputFieldDateProps)(props, holderRef);
|
|
226
|
+
return ((0, jsx_runtime_1.jsx)(InputFieldComponent, { type: "datetime-local", insideInputFieldComponent: (0, jsx_runtime_1.jsx)(Div_1.default, { position: "absolute", top: "100%", left: 0, width: "100%", maxHeight: 300, backgroundColor: theme.colors.backgroundContent, borderBottomLeftRadius: theme.styles.borderRadius, borderBottomRightRadius: theme.styles.borderRadius, boxShadow: "0px 10px 20px #00000020", overflowY: "auto", ...insideInputFieldComponentProps, children: "Hello there" }), holderRef: holderRef, ref: ref, ...props, ...inputFieldProps }));
|
|
227
|
+
});
|
|
228
|
+
InputFieldComponent.time = (0, react_1.forwardRef)(function Time({ ...props }, ref) {
|
|
229
|
+
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
230
|
+
const holderRef = (0, react_1.useRef)(null);
|
|
231
|
+
const selectedHourRef = (0, react_1.useRef)(null);
|
|
232
|
+
const selectedMinuteRef = (0, react_1.useRef)(null);
|
|
233
|
+
const { internalValue, setInternalValue, inputFieldProps, insideInputFieldComponentProps, isOpen } = (0, hooks_1.useComponentInputFieldDateProps)(props, holderRef);
|
|
234
|
+
const onClickHour = (0, react_1.useCallback)((hour) => {
|
|
235
|
+
const value = `${hour.toString().padStart(2, "0")}:${internalValue?.toString().split(":")[1] || "00"}`;
|
|
236
|
+
inputFieldProps.onChangeValue?.(value);
|
|
237
|
+
setInternalValue(value);
|
|
238
|
+
}, [internalValue, inputFieldProps.onChangeValue]);
|
|
239
|
+
const onClickMinute = (0, react_1.useCallback)((minute) => {
|
|
240
|
+
const value = `${internalValue?.toString().split(":")[0] || "00"}:${minute.toString().padStart(2, "0")}`;
|
|
241
|
+
inputFieldProps.onChangeValue?.(value);
|
|
242
|
+
setInternalValue(value);
|
|
243
|
+
}, [internalValue, inputFieldProps.onChangeValue]);
|
|
244
|
+
(0, react_1.useEffect)(() => {
|
|
245
|
+
if (isOpen && selectedHourRef.current)
|
|
246
|
+
selectedHourRef.current.scrollIntoView({ block: "nearest", behavior: "instant" });
|
|
247
|
+
if (isOpen && selectedMinuteRef.current)
|
|
248
|
+
selectedMinuteRef.current.scrollIntoView({ block: "nearest", behavior: "instant" });
|
|
249
|
+
}, [isOpen]);
|
|
250
|
+
const valueHour = parseInt(internalValue?.toString().split(":")?.[0]).toString();
|
|
251
|
+
const valueMinute = parseInt(internalValue?.toString().split(":")?.[1]).toString();
|
|
252
|
+
const buttonWidth = 50;
|
|
253
|
+
return ((0, jsx_runtime_1.jsx)(InputFieldComponent, { type: "time", insideInputFieldComponent: (0, jsx_runtime_1.jsx)(Div_1.default, { position: "absolute", top: "100%", left: 0, width: buttonWidth * 2 + 2, height: 300, backgroundColor: theme.colors.backgroundContent, borderBottomLeftRadius: theme.styles.borderRadius, borderBottomRightRadius: theme.styles.borderRadius, boxShadow: "0px 10px 20px #00000020", overflowY: "auto", ...insideInputFieldComponentProps, children: (0, jsx_runtime_1.jsxs)(Div_1.default.row, { height: "100%", children: [(0, jsx_runtime_1.jsx)(Div_1.default, { className: "react-better-html-no-scrollbar", width: buttonWidth, height: "100%", overflowY: "auto", children: hours.map((hour) => {
|
|
254
|
+
const isSelected = hour.toString() === valueHour;
|
|
255
|
+
return ((0, jsx_runtime_1.jsx)(Div_1.default.row, { alignItems: "center", justifyContent: "center", color: isSelected ? theme.colors.base : theme.colors.textPrimary, backgroundColor: isSelected ? theme.colors.primary : theme.colors.backgroundContent, filterHover: "brightness(0.9)", cursor: "pointer", padding: `${theme.styles.space / 2}px ${theme.styles.space + theme.styles.gap}px`, value: hour, onClickWithValue: onClickHour, ref: isSelected ? selectedHourRef : undefined, children: (0, jsx_runtime_1.jsx)(Text_1.default, { textAlign: "center", children: hour.toString().padStart(2, "0") }) }, hour));
|
|
256
|
+
}) }), (0, jsx_runtime_1.jsx)(Div_1.default, { className: "react-better-html-no-scrollbar", width: buttonWidth, height: "100%", overflowY: "auto", children: minutes.map((minute) => {
|
|
257
|
+
const isSelected = minute.toString() === valueMinute;
|
|
258
|
+
return ((0, jsx_runtime_1.jsx)(Div_1.default.row, { alignItems: "center", justifyContent: "center", color: isSelected ? theme.colors.base : theme.colors.textPrimary, backgroundColor: isSelected ? theme.colors.primary : theme.colors.backgroundContent, filterHover: "brightness(0.9)", cursor: "pointer", padding: `${theme.styles.space / 2}px ${theme.styles.space + theme.styles.gap}px`, value: minute, onClickWithValue: onClickMinute, ref: isSelected ? selectedMinuteRef : undefined, children: (0, jsx_runtime_1.jsx)(Text_1.default, { textAlign: "center", children: minute.toString().padStart(2, "0") }) }, minute));
|
|
259
|
+
}) })] }) }), holderRef: holderRef, ref: ref, ...props, ...inputFieldProps, minWidth: buttonWidth * 2 + 2 }));
|
|
197
260
|
});
|
|
198
261
|
const InputField = (0, react_1.memo)(InputFieldComponent);
|
|
199
262
|
InputField.multiline = InputFieldComponent.multiline;
|
|
@@ -201,4 +264,7 @@ InputField.email = InputFieldComponent.email;
|
|
|
201
264
|
InputField.password = InputFieldComponent.password;
|
|
202
265
|
InputField.search = InputFieldComponent.search;
|
|
203
266
|
InputField.phoneNumber = InputFieldComponent.phoneNumber;
|
|
267
|
+
InputField.date = InputFieldComponent.date;
|
|
268
|
+
InputField.dateTime = InputFieldComponent.dateTime;
|
|
269
|
+
InputField.time = InputFieldComponent.time;
|
|
204
270
|
exports.default = InputField;
|
|
@@ -4,7 +4,8 @@ export type LabelProps = {
|
|
|
4
4
|
required?: boolean;
|
|
5
5
|
/** @default false */
|
|
6
6
|
isError?: boolean;
|
|
7
|
+
color?: string;
|
|
7
8
|
};
|
|
8
|
-
declare function Label({ text, required, isError }: LabelProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare function Label({ text, required, isError, color }: LabelProps): import("react/jsx-runtime").JSX.Element;
|
|
9
10
|
declare const _default: import("react").MemoExoticComponent<typeof Label>;
|
|
10
11
|
export default _default;
|
package/dist/components/Label.js
CHANGED
|
@@ -7,8 +7,8 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const Text_1 = __importDefault(require("./Text"));
|
|
9
9
|
const BetterHtmlProvider_1 = require("./BetterHtmlProvider");
|
|
10
|
-
function Label({ text, required, isError }) {
|
|
10
|
+
function Label({ text, required, isError, color }) {
|
|
11
11
|
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
12
|
-
return ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "label", height: 16, fontSize: 14, color: isError ? theme.colors.error : theme.colors.textSecondary, children: [text, required && ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "span", fontSize: 16, color: theme.colors.error, children: [" ", "*"] }))] }));
|
|
12
|
+
return ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "label", height: 16, fontSize: 14, color: isError ? theme.colors.error : color ?? theme.colors.textSecondary, children: [text, required && ((0, jsx_runtime_1.jsxs)(Text_1.default, { as: "span", fontSize: 16, color: theme.colors.error, children: [" ", "*"] }))] }));
|
|
13
13
|
}
|
|
14
14
|
exports.default = (0, react_1.memo)(Label);
|
package/dist/utils/hooks.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ excludeProps?: boolean): {
|
|
|
13
13
|
export declare function useComponentPropsWithPrefix<Props extends Record<string, any>, Prefix extends string>(props: Props, prefix: Prefix): Record<`${Prefix}-${string}`, any>;
|
|
14
14
|
export declare function useComponentPropsWithExcludedStyle<Props extends Record<string, any>>(props: Props): Partial<Props>;
|
|
15
15
|
export declare function useComponentPropsWithoutStyle<Props extends Record<string, any>>(props: Props): Partial<Props>;
|
|
16
|
+
export declare function useComponentInputFieldDateProps(props: InputFieldProps, holderRef: React.RefObject<HTMLDivElement | null>): {
|
|
17
|
+
internalValue: string;
|
|
18
|
+
setInternalValue: React.Dispatch<React.SetStateAction<string>>;
|
|
19
|
+
inputFieldProps: InputFieldProps;
|
|
20
|
+
insideInputFieldComponentProps: InputFieldProps;
|
|
21
|
+
isOpen: boolean;
|
|
22
|
+
};
|
|
16
23
|
export declare function usePageResize(): {
|
|
17
24
|
width: number;
|
|
18
25
|
height: number;
|
package/dist/utils/hooks.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.useStyledComponentStyles = useStyledComponentStyles;
|
|
|
4
4
|
exports.useComponentPropsWithPrefix = useComponentPropsWithPrefix;
|
|
5
5
|
exports.useComponentPropsWithExcludedStyle = useComponentPropsWithExcludedStyle;
|
|
6
6
|
exports.useComponentPropsWithoutStyle = useComponentPropsWithoutStyle;
|
|
7
|
+
exports.useComponentInputFieldDateProps = useComponentInputFieldDateProps;
|
|
7
8
|
exports.usePageResize = usePageResize;
|
|
8
9
|
exports.usePageScroll = usePageScroll;
|
|
9
10
|
exports.useMediaQuery = useMediaQuery;
|
|
@@ -97,6 +98,80 @@ function useComponentPropsWithoutStyle(props) {
|
|
|
97
98
|
return previousValue;
|
|
98
99
|
}, {}), [props]);
|
|
99
100
|
}
|
|
101
|
+
function useComponentInputFieldDateProps(props, holderRef) {
|
|
102
|
+
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
103
|
+
const [isOpen, setIsOpen] = useBooleanState();
|
|
104
|
+
const [isOpenLate, setIsOpenLate] = useBooleanState();
|
|
105
|
+
const [isFocused, setIsFocused] = useBooleanState();
|
|
106
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)(props.value?.toString() ?? "");
|
|
107
|
+
const inputFieldProps = (0, react_1.useMemo)(() => ({
|
|
108
|
+
value: internalValue,
|
|
109
|
+
className: `${isOpen ? "react-better-html-inputField-dateTime-opened" : ""}${isOpenLate ? " react-better-html-inputField-dateTime-opened-late" : ""}${props.className ? ` ${props.className}` : ""}`,
|
|
110
|
+
onClick: (event) => {
|
|
111
|
+
if (props.disabled)
|
|
112
|
+
return;
|
|
113
|
+
setIsOpen.setTrue();
|
|
114
|
+
props.onClick?.(event);
|
|
115
|
+
},
|
|
116
|
+
onFocus: (event) => {
|
|
117
|
+
setIsFocused.setTrue();
|
|
118
|
+
props.onFocus?.(event);
|
|
119
|
+
},
|
|
120
|
+
onBlur: (event) => {
|
|
121
|
+
setIsFocused.setFalse();
|
|
122
|
+
props.onBlur?.(event);
|
|
123
|
+
},
|
|
124
|
+
onChangeValue: (value) => {
|
|
125
|
+
setInternalValue(value);
|
|
126
|
+
props.onChangeValue?.(value);
|
|
127
|
+
},
|
|
128
|
+
}), [props, internalValue, isOpen, isOpenLate]);
|
|
129
|
+
const insideInputFieldComponentProps = (0, react_1.useMemo)(() => ({
|
|
130
|
+
border: `1px solid ${isFocused ? theme.colors.primary : theme.colors.border}`,
|
|
131
|
+
borderTop: "none",
|
|
132
|
+
opacity: !isOpen ? 0 : undefined,
|
|
133
|
+
pointerEvents: !isOpen ? "none" : undefined,
|
|
134
|
+
transform: `translateY(${!isOpen ? -10 : 0}px)`,
|
|
135
|
+
zIndex: 1000,
|
|
136
|
+
transition: theme.styles.transition,
|
|
137
|
+
}), [isOpen, isFocused]);
|
|
138
|
+
(0, react_1.useEffect)(() => {
|
|
139
|
+
if (props.value === undefined || props.value === null)
|
|
140
|
+
return;
|
|
141
|
+
setInternalValue(props.value.toString());
|
|
142
|
+
}, [props.value]);
|
|
143
|
+
(0, react_1.useEffect)(() => {
|
|
144
|
+
if (isOpen) {
|
|
145
|
+
setIsOpenLate.setTrue();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const timeout = setTimeout(setIsOpenLate.setFalse, 0.2 * 1000);
|
|
149
|
+
return () => {
|
|
150
|
+
clearTimeout(timeout);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}, [isOpen]);
|
|
154
|
+
(0, react_1.useEffect)(() => {
|
|
155
|
+
const handleClickOutside = (event) => {
|
|
156
|
+
if (holderRef.current && !holderRef.current.contains(event.target)) {
|
|
157
|
+
setIsOpen.setFalse();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
if (isOpen) {
|
|
161
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
162
|
+
}
|
|
163
|
+
return () => {
|
|
164
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
165
|
+
};
|
|
166
|
+
}, [isOpen]);
|
|
167
|
+
return {
|
|
168
|
+
internalValue,
|
|
169
|
+
setInternalValue,
|
|
170
|
+
inputFieldProps,
|
|
171
|
+
insideInputFieldComponentProps,
|
|
172
|
+
isOpen,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
100
175
|
function usePageResize() {
|
|
101
176
|
const [width, setWidth] = (0, react_1.useState)(window.innerWidth);
|
|
102
177
|
const [height, setHeight] = (0, react_1.useState)(window.innerHeight);
|