@osrd-project/ui-core 0.0.74 → 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/components/Modal.d.ts +3 -2
- package/dist/components/inputs/ComboBox/ComboBox.d.ts +2 -1
- package/dist/components/inputs/Input.d.ts +2 -0
- package/dist/components/inputs/PasswordInput.d.ts +1 -0
- package/dist/components/inputs/RadioGroup.d.ts +2 -1
- package/dist/components/inputs/StatusMessage.d.ts +2 -1
- package/dist/components/inputs/TimePicker.d.ts +2 -1
- package/dist/components/inputs/datePicker/CalendarPicker.d.ts +1 -1
- package/dist/components/inputs/datePicker/DatePicker.d.ts +1 -0
- package/dist/components/inputs/datePicker/useCalendar.d.ts +1 -1
- package/dist/components/inputs/datePicker/useDatePicker.d.ts +2 -2
- package/dist/components/inputs/tolerancePicker/TolerancePicker.d.ts +2 -1
- package/dist/hooks/useModalPosition.d.ts +1 -1
- package/dist/hooks/useOutsideClick.d.ts +1 -1
- package/dist/index.esm.js +50 -47
- package/dist/index.esm.js.map +1 -1
- package/dist/theme.css +355 -535
- package/dist/theme.css.map +1 -1
- package/package.json +9 -9
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
type ModalProps = {
|
|
3
|
-
inputRef: React.RefObject<HTMLInputElement>;
|
|
3
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
4
4
|
isOpen: boolean;
|
|
5
5
|
onClose: () => void;
|
|
6
6
|
children: React.ReactNode;
|
|
7
|
+
testIdPrefix?: string;
|
|
7
8
|
};
|
|
8
|
-
declare const InputModal: ({ inputRef, isOpen, onClose, children }: ModalProps) => React.JSX.Element | null;
|
|
9
|
+
declare const InputModal: ({ inputRef, isOpen, onClose, children, testIdPrefix }: ModalProps) => React.JSX.Element | null;
|
|
9
10
|
export default InputModal;
|
|
@@ -8,6 +8,7 @@ export type ComboBoxProps<T> = Omit<InputProps, 'value'> & {
|
|
|
8
8
|
getSuggestionLabel: (option: T) => string;
|
|
9
9
|
onSelectSuggestion: (option: T | undefined) => void;
|
|
10
10
|
resetSuggestions: () => void;
|
|
11
|
+
testIdPrefix?: string;
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* ComboBox component
|
|
@@ -15,5 +16,5 @@ export type ComboBoxProps<T> = Omit<InputProps, 'value'> & {
|
|
|
15
16
|
* You can use the hook useDefaultComboBox to get the default behavior.
|
|
16
17
|
* See the stories.
|
|
17
18
|
*/
|
|
18
|
-
declare const ComboBox: <T>({ suggestions, customLabel, numberOfSuggestionsToShow, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, ...inputProps }: ComboBoxProps<T>) => React.JSX.Element;
|
|
19
|
+
declare const ComboBox: <T>({ suggestions, customLabel, numberOfSuggestionsToShow, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, testIdPrefix, ...inputProps }: ComboBoxProps<T>) => React.JSX.Element;
|
|
19
20
|
export default ComboBox;
|
|
@@ -15,11 +15,13 @@ export type InputProps = React.InputHTMLAttributes<HTMLInputElement> & Omit<Fiel
|
|
|
15
15
|
trailingContent?: InputAffixContent | InputAffixContentWithCallback;
|
|
16
16
|
inputFieldWrapperClassname?: string;
|
|
17
17
|
withIcons?: IconConfig[];
|
|
18
|
+
testIdPrefix?: string;
|
|
18
19
|
};
|
|
19
20
|
declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & Omit<FieldWrapperProps, "children"> & {
|
|
20
21
|
leadingContent?: InputAffixContent | InputAffixContentWithCallback;
|
|
21
22
|
trailingContent?: InputAffixContent | InputAffixContentWithCallback;
|
|
22
23
|
inputFieldWrapperClassname?: string;
|
|
23
24
|
withIcons?: IconConfig[];
|
|
25
|
+
testIdPrefix?: string;
|
|
24
26
|
} & React.RefAttributes<HTMLInputElement>>;
|
|
25
27
|
export default Input;
|
|
@@ -11,6 +11,7 @@ export type RadioGroupProps = {
|
|
|
11
11
|
value?: string;
|
|
12
12
|
options: RadioButtonProps[];
|
|
13
13
|
statusWithMessage?: StatusWithMessage;
|
|
14
|
+
onChange?: (value: string) => void;
|
|
14
15
|
};
|
|
15
|
-
declare const RadioGroup: ({ label, value, subtitle, readOnly, disabled, options, statusWithMessage, required, small, }: RadioGroupProps) => React.JSX.Element;
|
|
16
|
+
declare const RadioGroup: ({ label, value, subtitle, readOnly, disabled, options, statusWithMessage, required, small, onChange, }: RadioGroupProps) => React.JSX.Element;
|
|
16
17
|
export default RadioGroup;
|
|
@@ -11,6 +11,7 @@ export type StatusMessageProps = {
|
|
|
11
11
|
showIcon?: boolean;
|
|
12
12
|
small?: boolean;
|
|
13
13
|
onClose?: () => void;
|
|
14
|
+
testIdPrefix?: string;
|
|
14
15
|
};
|
|
15
|
-
declare const StatusMessage: ({ statusWithMessage, showIcon, small, onClose }: StatusMessageProps) => React.JSX.Element | null;
|
|
16
|
+
declare const StatusMessage: ({ statusWithMessage, showIcon, small, onClose, testIdPrefix, }: StatusMessageProps) => React.JSX.Element | null;
|
|
16
17
|
export default StatusMessage;
|
|
@@ -10,6 +10,7 @@ export type TimePickerProps = Omit<InputProps, 'type' | 'name' | 'value' | 'onCl
|
|
|
10
10
|
minutes: number;
|
|
11
11
|
seconds?: number;
|
|
12
12
|
}) => void;
|
|
13
|
+
testIdPrefix?: string;
|
|
13
14
|
};
|
|
14
|
-
declare const TimePicker: ({ onTimeChange, hours, minutes, seconds, displaySeconds, ...otherProps }: TimePickerProps) => React.JSX.Element;
|
|
15
|
+
declare const TimePicker: ({ onTimeChange, hours, minutes, seconds, displaySeconds, testIdPrefix, ...otherProps }: TimePickerProps) => React.JSX.Element;
|
|
15
16
|
export default TimePicker;
|
|
@@ -7,7 +7,7 @@ export type CalendarPickerPrivateProps = {
|
|
|
7
7
|
top: number;
|
|
8
8
|
left: number;
|
|
9
9
|
};
|
|
10
|
-
calendarPickerRef: React.RefObject<HTMLDivElement>;
|
|
10
|
+
calendarPickerRef: React.RefObject<HTMLDivElement | null>;
|
|
11
11
|
selectableSlot?: CalendarSlot;
|
|
12
12
|
};
|
|
13
13
|
export type CalendarPickerPublicProps = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CalendarProps } from './Calendar';
|
|
2
2
|
export default function useCalendar({ displayedMonthStartDate, selectableSlot, selectedSlot, }: CalendarProps): {
|
|
3
3
|
days: Date[];
|
|
4
|
-
|
|
4
|
+
isToday: (date: Date) => boolean;
|
|
5
5
|
buildDayWrapperClassName: (date: Date) => string;
|
|
6
6
|
isDateSelectable: (date: Date) => boolean;
|
|
7
7
|
};
|
|
@@ -9,8 +9,8 @@ export default function useDatePicker(datePickerProps: DatePickerProps): {
|
|
|
9
9
|
top: number;
|
|
10
10
|
left: number;
|
|
11
11
|
};
|
|
12
|
-
inputRef: import("react").RefObject<HTMLInputElement>;
|
|
13
|
-
calendarPickerRef: import("react").RefObject<HTMLDivElement>;
|
|
12
|
+
inputRef: import("react").RefObject<HTMLInputElement | null>;
|
|
13
|
+
calendarPickerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
14
14
|
setShowPicker: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
15
15
|
handleDayClick: (clickedDate: Date) => void;
|
|
16
16
|
handleInputClick: () => void;
|
|
@@ -8,6 +8,7 @@ export type TolerancePickerProps = Omit<InputProps, 'value'> & {
|
|
|
8
8
|
onToleranceChange: (toleranceValues: ToleranceValues) => void;
|
|
9
9
|
toleranceValues?: ToleranceValues;
|
|
10
10
|
translateWarningMessage?: (invalidTolerance: number) => string;
|
|
11
|
+
testIdPrefix?: string;
|
|
11
12
|
};
|
|
12
|
-
declare const TolerancePicker: ({ onToleranceChange, toleranceValues: { minusTolerance, plusTolerance }, translateWarningMessage, ...inputProps }: TolerancePickerProps) => React.JSX.Element;
|
|
13
|
+
declare const TolerancePicker: ({ onToleranceChange, toleranceValues: { minusTolerance, plusTolerance }, translateWarningMessage, testIdPrefix, ...inputProps }: TolerancePickerProps) => React.JSX.Element;
|
|
13
14
|
export default TolerancePicker;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const useModalPosition: (inputRef: React.RefObject<HTMLInputElement>, modalRef: React.RefObject<HTMLDivElement>, offset?: number) => {
|
|
1
|
+
export declare const useModalPosition: (inputRef: React.RefObject<HTMLInputElement | null>, modalRef: React.RefObject<HTMLDivElement | null>, offset?: number) => {
|
|
2
2
|
modalPosition: {
|
|
3
3
|
top: number;
|
|
4
4
|
left: number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const useOutsideClick: (ref: React.RefObject<HTMLElement>, handler: (event: MouseEvent) => void) => void;
|
|
1
|
+
declare const useOutsideClick: (ref: React.RefObject<HTMLElement | null>, handler: (event: MouseEvent) => void) => void;
|
|
2
2
|
export default useOutsideClick;
|
package/dist/index.esm.js
CHANGED
|
@@ -48,7 +48,7 @@ const Label = ({ htmlFor, text, required, hasHint, disabled, small = false }) =>
|
|
|
48
48
|
React.createElement(RequiredInput, null))),
|
|
49
49
|
React.createElement("label", { className: cx('label', { disabled: disabled }), htmlFor: htmlFor }, text)));
|
|
50
50
|
|
|
51
|
-
const StatusMessage = ({ statusWithMessage, showIcon, small, onClose }) => {
|
|
51
|
+
const StatusMessage = ({ statusWithMessage, showIcon, small, onClose, testIdPrefix, }) => {
|
|
52
52
|
const { tooltip, status, message } = statusWithMessage;
|
|
53
53
|
if (message === undefined)
|
|
54
54
|
return null;
|
|
@@ -60,7 +60,7 @@ const StatusMessage = ({ statusWithMessage, showIcon, small, onClose }) => {
|
|
|
60
60
|
[status]: status,
|
|
61
61
|
}) },
|
|
62
62
|
showIcon && React.createElement(InputStatusIcon, { status: status, small: small }),
|
|
63
|
-
React.createElement("span", { className: cx('status-message', { [status]: status }) }, message),
|
|
63
|
+
React.createElement("span", { "data-testid": testIdPrefix ? `${testIdPrefix}-${status}` : undefined, className: cx('status-message', { [status]: status }) }, message),
|
|
64
64
|
status === 'info' && tooltip && (React.createElement("button", { className: "status-close", onClick: onClose },
|
|
65
65
|
React.createElement(X, { size: "sm" })))));
|
|
66
66
|
};
|
|
@@ -78,7 +78,7 @@ const FieldWrapper = ({ id, label, hint, required, disabled, statusWithMessage,
|
|
|
78
78
|
React.createElement("div", { className: "field-and-status-icon" },
|
|
79
79
|
children,
|
|
80
80
|
statusWithMessage && statusIconPosition === 'next-to-field' && (React.createElement(InputStatusIcon, { status: statusWithMessage.status, small: small, className: "next-to-field" }))),
|
|
81
|
-
statusWithMessage && (React.createElement(StatusMessage, { small: small, statusWithMessage: {
|
|
81
|
+
statusWithMessage && (React.createElement(StatusMessage, { testIdPrefix: "status-message", small: small, statusWithMessage: {
|
|
82
82
|
...statusWithMessage,
|
|
83
83
|
tooltip: statusWithMessage?.tooltip ?? defaultTooltip,
|
|
84
84
|
}, showIcon: statusIconPosition === 'before-status-message', onClose: onCloseStatusMessage })))));
|
|
@@ -109,14 +109,14 @@ const InputAffix = ({ value, type, disabled, readOnly }) => {
|
|
|
109
109
|
return (React.createElement("div", { className: cx(`${type}-content-wrapper`, { disabled, 'read-only': readOnly }), ...wrapperProps },
|
|
110
110
|
React.createElement("span", { className: `${type}-content` }, spanContent)));
|
|
111
111
|
};
|
|
112
|
-
const Input = React.forwardRef(({ id, label, type, hint, leadingContent, trailingContent, required, disabled = false, readOnly = false, statusWithMessage, narrow, inputFieldWrapperClassname = '', small = false, withIcons = [], onKeyUp, onBlur, onCloseStatusMessage, ...rest }, ref) => {
|
|
112
|
+
const Input = React.forwardRef(({ id, label, type, hint, leadingContent, trailingContent, required, disabled = false, readOnly = false, statusWithMessage, narrow, inputFieldWrapperClassname = '', small = false, withIcons = [], onKeyUp, onBlur, onCloseStatusMessage, testIdPrefix, ...rest }, ref) => {
|
|
113
113
|
const { handleKeyUp, handleBlur, isFocusByTab } = useFocusByTab({ onBlur, onKeyUp });
|
|
114
114
|
return (React.createElement(FieldWrapper, { id: id, label: label, hint: hint, statusWithMessage: statusWithMessage, disabled: disabled, required: required, small: small, statusIconPosition: statusWithMessage?.tooltip || narrow ? 'before-status-message' : undefined, narrow: narrow, className: cx('input-field-wrapper', inputFieldWrapperClassname), onCloseStatusMessage: onCloseStatusMessage },
|
|
115
115
|
leadingContent && (React.createElement(InputAffix, { value: leadingContent, type: "leading", disabled: disabled, readOnly: readOnly })),
|
|
116
116
|
React.createElement("div", { className: cx('input-container', {
|
|
117
117
|
'focused-by-tab': isFocusByTab,
|
|
118
118
|
}) },
|
|
119
|
-
React.createElement("input", { ref: ref, className: cx('input', {
|
|
119
|
+
React.createElement("input", { "data-testid": testIdPrefix ? `${testIdPrefix}-input` : undefined, ref: ref, className: cx('input', {
|
|
120
120
|
'with-leading-only': leadingContent && !trailingContent,
|
|
121
121
|
'with-trailing-only': trailingContent && !leadingContent,
|
|
122
122
|
'with-leading-and-trailing': leadingContent && trailingContent,
|
|
@@ -125,7 +125,7 @@ const Input = React.forwardRef(({ id, label, type, hint, leadingContent, trailin
|
|
|
125
125
|
}), id: id, type: type, disabled: disabled, readOnly: readOnly, onKeyUp: handleKeyUp, onBlur: handleBlur, ...rest }),
|
|
126
126
|
React.createElement("div", { className: cx('input-icons', {
|
|
127
127
|
small,
|
|
128
|
-
}) }, withIcons.map((iconConfig, index) => (React.createElement("span", { key: index, className: iconConfig?.className, onClick: iconConfig.action }, iconConfig.icon))))),
|
|
128
|
+
}) }, withIcons.map((iconConfig, index) => (React.createElement("span", { key: index, className: iconConfig?.className, onClick: iconConfig.action, "data-testid": testIdPrefix ? `${testIdPrefix}-icon` : undefined }, iconConfig.icon))))),
|
|
129
129
|
trailingContent && (React.createElement(InputAffix, { value: trailingContent, type: "trailing", disabled: disabled, readOnly: readOnly }))));
|
|
130
130
|
});
|
|
131
131
|
Input.displayName = 'Input';
|
|
@@ -136,7 +136,7 @@ Input.displayName = 'Input';
|
|
|
136
136
|
* You can use the hook useDefaultComboBox to get the default behavior.
|
|
137
137
|
* See the stories.
|
|
138
138
|
*/
|
|
139
|
-
const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, ...inputProps }) => {
|
|
139
|
+
const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, testIdPrefix, ...inputProps }) => {
|
|
140
140
|
const [activeSuggestionIndex, setActiveSuggestionIndex] = useState(-1);
|
|
141
141
|
const [inputValue, setInputValue] = useState('');
|
|
142
142
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
|
@@ -240,10 +240,14 @@ const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, val
|
|
|
240
240
|
}),
|
|
241
241
|
},
|
|
242
242
|
], [value]);
|
|
243
|
-
return (React.createElement("div", { className: "combo-box", style: { '--number-of-suggestions': numberOfSuggestionsToShow }, ref: wrapperRef },
|
|
243
|
+
return (React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}` : undefined, className: "combo-box", style: { '--number-of-suggestions': numberOfSuggestionsToShow }, ref: wrapperRef },
|
|
244
244
|
customLabel && React.createElement("label", { htmlFor: inputProps.id }, customLabel),
|
|
245
|
-
React.createElement(Input, { ...inputProps, ref: inputRef, value: inputValue, onChange: handleInputChange, onKeyDown: handleKeyDown, onFocus: handleInputFocus, withIcons: inputIcons, small: small }),
|
|
246
|
-
showSuggestions && (React.createElement("ul", { className: "suggestions-list" }, suggestions.map((suggestion, index) => (React.createElement("li", { ref: (el) =>
|
|
245
|
+
React.createElement(Input, { testIdPrefix: inputProps.id, ...inputProps, ref: inputRef, value: inputValue, onChange: handleInputChange, onKeyDown: handleKeyDown, onFocus: handleInputFocus, withIcons: inputIcons, small: small }),
|
|
246
|
+
showSuggestions && (React.createElement("ul", { className: "suggestions-list", "data-testid": testIdPrefix ? `${testIdPrefix}-list` : undefined }, suggestions.map((suggestion, index) => (React.createElement("li", { ref: (el) => {
|
|
247
|
+
if (suggestionRefs) {
|
|
248
|
+
suggestionRefs.current[index] = el;
|
|
249
|
+
}
|
|
250
|
+
}, key: `${getSuggestionLabel(suggestion)}-${index}`, "data-testid": testIdPrefix ? `${testIdPrefix}-item` : undefined, className: cx('suggestion-item', {
|
|
247
251
|
active: index === activeSuggestionIndex,
|
|
248
252
|
selected: value && getSuggestionLabel(value) === getSuggestionLabel(suggestion),
|
|
249
253
|
small,
|
|
@@ -305,7 +309,11 @@ const Checkbox = ({ label, small, hint, disabled, checked, readOnly, isIndetermi
|
|
|
305
309
|
return (React.createElement("label", { className: cx('custom-checkbox', { small }) },
|
|
306
310
|
React.createElement("input", {
|
|
307
311
|
//read-only state is not working on checkbox as well explain here : https://stackoverflow.com/a/70375659
|
|
308
|
-
className: cx({ 'read-only': readOnly }), type: "checkbox", checked: checked, disabled: disabled, ref: (input) =>
|
|
312
|
+
className: cx({ 'read-only': readOnly }), type: "checkbox", checked: checked, disabled: disabled, ref: (input) => {
|
|
313
|
+
if (input) {
|
|
314
|
+
input.indeterminate = isIndeterminate;
|
|
315
|
+
}
|
|
316
|
+
}, onClick: handleClick, onBlur: handleBlur, onKeyUp: handleKeyUp, ...rest }),
|
|
309
317
|
React.createElement("span", { className: cx('checkmark', { 'focused-by-tab': isFocusByTab }) }),
|
|
310
318
|
label && React.createElement("div", { className: "label" }, label),
|
|
311
319
|
hint && React.createElement("span", { className: "hint" }, hint)));
|
|
@@ -689,7 +697,9 @@ function validateSlots(selectedSlot, selectableSlot, date) {
|
|
|
689
697
|
}
|
|
690
698
|
|
|
691
699
|
function useCalendar({ displayedMonthStartDate, selectableSlot, selectedSlot, }) {
|
|
692
|
-
const
|
|
700
|
+
const now = new Date();
|
|
701
|
+
now.setHours(0, 0, 0, 0);
|
|
702
|
+
const referenceDate = selectableSlot?.start ?? now;
|
|
693
703
|
referenceDate.setHours(0, 0, 0, 0);
|
|
694
704
|
const displayedYear = displayedMonthStartDate.getFullYear();
|
|
695
705
|
const displayedMonth = displayedMonthStartDate.getMonth();
|
|
@@ -720,40 +730,32 @@ function useCalendar({ displayedMonthStartDate, selectableSlot, selectedSlot, })
|
|
|
720
730
|
}
|
|
721
731
|
return cx('day-wrapper', classNames);
|
|
722
732
|
};
|
|
723
|
-
const isDateSelectable = (date) =>
|
|
724
|
-
// Check if the date is within the selectable interval
|
|
725
|
-
if (!isWithinInterval(date, selectableSlot))
|
|
726
|
-
return false;
|
|
727
|
-
// Check if the date is in the currently displayed month
|
|
728
|
-
if (date.getMonth() !== displayedMonth)
|
|
729
|
-
return false;
|
|
730
|
-
return true;
|
|
731
|
-
};
|
|
733
|
+
const isDateSelectable = (date) => isWithinInterval(date, selectableSlot);
|
|
732
734
|
return {
|
|
733
735
|
days: allDays,
|
|
734
|
-
|
|
736
|
+
isToday: (date) => normalizeDate(date).getTime() === normalizeDate(now).getTime(),
|
|
735
737
|
buildDayWrapperClassName,
|
|
736
738
|
isDateSelectable,
|
|
737
739
|
};
|
|
738
740
|
}
|
|
739
741
|
|
|
740
742
|
const WEEKDAY_LABELS = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
|
|
741
|
-
const Day = ({ date,
|
|
743
|
+
const Day = ({ date, isToday, isSelectable, dayWrapperClassName, onClick }) => (React.createElement("div", { onClick: () => {
|
|
742
744
|
if (isSelectable)
|
|
743
745
|
onClick(date);
|
|
744
746
|
}, className: "day-background" },
|
|
745
747
|
React.createElement("div", { className: dayWrapperClassName },
|
|
746
748
|
React.createElement("span", { className: "day" }, date.getDate()),
|
|
747
|
-
|
|
749
|
+
isToday && React.createElement("span", { className: "current-date-highlight" }))));
|
|
748
750
|
const Calendar = (props) => {
|
|
749
|
-
const { days,
|
|
751
|
+
const { days, isToday, isDateSelectable, buildDayWrapperClassName } = useCalendar(props);
|
|
750
752
|
const { displayedMonthStartDate, onDayClick } = props;
|
|
751
753
|
return (React.createElement("div", { className: "calendar-wrapper" },
|
|
752
754
|
React.createElement("div", { className: "calendar-anatomy" },
|
|
753
755
|
React.createElement("p", { className: "calendar-month-label" }, displayedMonthStartDate.toLocaleString('en-GB', { month: 'short' })),
|
|
754
756
|
React.createElement("div", { className: "calendar-grid-wrapper" },
|
|
755
757
|
React.createElement("div", { className: "calendar-weekday-labels" }, WEEKDAY_LABELS.map((label, index) => (React.createElement("p", { key: `${label}-${index}` }, label)))),
|
|
756
|
-
React.createElement("div", { className: "calendar-days-grid" }, days.map((date) => (React.createElement(Day, { key: date.getTime(), date: date,
|
|
758
|
+
React.createElement("div", { className: "calendar-days-grid" }, days.map((date) => (React.createElement(Day, { key: date.getTime(), date: date, isToday: isToday(date), isSelectable: isDateSelectable(date), dayWrapperClassName: buildDayWrapperClassName(date), onClick: onDayClick }))))))));
|
|
757
759
|
};
|
|
758
760
|
|
|
759
761
|
function useCalendarPicker({ initialDate, selectedSlot, selectableSlot, numberOfMonths = 1, }) {
|
|
@@ -833,11 +835,10 @@ const useModalPosition = (inputRef, modalRef, offset = 3 // Default offset below
|
|
|
833
835
|
// Adjust the top position: place it below the input while considering an offset
|
|
834
836
|
const top = inputRect.bottom - parentRect.top - offset;
|
|
835
837
|
// Center the modal horizontally relative to the input
|
|
836
|
-
|
|
837
|
-
//
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
}
|
|
838
|
+
const modalViewportLeft = inputRect.left + (inputRect.width - modalRect.width) / 2;
|
|
839
|
+
// Keep modal to stay within viewport bounds
|
|
840
|
+
const adjustedViewportLeft = Math.max(0, Math.min(modalViewportLeft, window.innerWidth - modalRect.width));
|
|
841
|
+
const left = adjustedViewportLeft - parentRect.left;
|
|
841
842
|
setModalPosition({ top, left });
|
|
842
843
|
}
|
|
843
844
|
}, [inputRef, modalRef, offset]);
|
|
@@ -940,7 +941,7 @@ function useDatePicker(datePickerProps) {
|
|
|
940
941
|
};
|
|
941
942
|
}
|
|
942
943
|
|
|
943
|
-
const InputModal = ({ inputRef, isOpen, onClose, children }) => {
|
|
944
|
+
const InputModal = ({ inputRef, isOpen, onClose, children, testIdPrefix }) => {
|
|
944
945
|
const modalRef = useRef(null);
|
|
945
946
|
const { modalPosition, calculatePosition } = useModalPosition(inputRef, modalRef);
|
|
946
947
|
useEffect(() => {
|
|
@@ -953,7 +954,7 @@ const InputModal = ({ inputRef, isOpen, onClose, children }) => {
|
|
|
953
954
|
return null;
|
|
954
955
|
return (React.createElement("div", { className: "modal-ui-overlay" },
|
|
955
956
|
React.createElement("div", { ref: modalRef, className: "modal-ui-content", style: { top: modalPosition.top, left: modalPosition.left } },
|
|
956
|
-
React.createElement("button", { className: "close-button", onClick: onClose },
|
|
957
|
+
React.createElement("button", { "data-testid": testIdPrefix ? `${testIdPrefix}-close-button` : undefined, className: "close-button", onClick: onClose },
|
|
957
958
|
React.createElement(X, { size: "lg" })),
|
|
958
959
|
children)));
|
|
959
960
|
};
|
|
@@ -962,15 +963,16 @@ const DatePicker = (props) => {
|
|
|
962
963
|
const { inputValue, statusWithMessage, selectedSlot, showPicker, modalPosition, inputRef, calendarPickerRef, setShowPicker, handleDayClick, handleInputClick, handleInputOnChange, } = useDatePicker(props);
|
|
963
964
|
const { inputFieldWrapperClassname, ...otherInputProps } = props.inputProps;
|
|
964
965
|
const { selectableSlot } = props;
|
|
965
|
-
|
|
966
|
+
const { testIdPrefix } = props;
|
|
967
|
+
return (React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}` : undefined, className: "date-picker" },
|
|
966
968
|
React.createElement("div", null,
|
|
967
|
-
React.createElement(Input, { ...otherInputProps, ref: inputRef, value: inputValue, onClick: handleInputClick, type: "text", trailingContent: {
|
|
969
|
+
React.createElement(Input, { testIdPrefix: testIdPrefix, ...otherInputProps, ref: inputRef, value: inputValue, onClick: handleInputClick, type: "text", trailingContent: {
|
|
968
970
|
content: React.createElement(Calendar$1, null),
|
|
969
971
|
onClickCallback: () => setShowPicker(!showPicker),
|
|
970
972
|
}, inputFieldWrapperClassname: cx('date-picker-input', inputFieldWrapperClassname, {
|
|
971
973
|
'range-mode': props.isRangeMode,
|
|
972
974
|
}), autoComplete: "off", onChange: (e) => handleInputOnChange(e.target.value), statusWithMessage: statusWithMessage })),
|
|
973
|
-
React.createElement(InputModal, { inputRef: inputRef, isOpen: showPicker, onClose: () => setShowPicker(false) },
|
|
975
|
+
React.createElement(InputModal, { inputRef: inputRef, isOpen: showPicker, onClose: () => setShowPicker(false), testIdPrefix: "modal" },
|
|
974
976
|
React.createElement("div", { className: "calendar-picker-wrapper" },
|
|
975
977
|
React.createElement(CalendarPicker, { ...props.calendarPickerProps, selectedSlot: selectedSlot, onDayClick: handleDayClick, modalPosition: modalPosition, calendarPickerRef: calendarPickerRef, selectableSlot: selectableSlot })))));
|
|
976
978
|
};
|
|
@@ -994,12 +996,13 @@ const RadioButton = ({ id, label, value, hint, readOnly, onBlur, onKeyUp, small,
|
|
|
994
996
|
hint && React.createElement("div", { className: "hint" }, hint)));
|
|
995
997
|
};
|
|
996
998
|
|
|
997
|
-
const RadioGroup = ({ label, value, subtitle, readOnly, disabled, options, statusWithMessage, required, small, }) => {
|
|
999
|
+
const RadioGroup = ({ label, value, subtitle, readOnly, disabled, options, statusWithMessage, required, small, onChange, }) => {
|
|
998
1000
|
const [selectedValue, setSelectedValue] = useState(value);
|
|
999
1001
|
const handleOptionChange = (e, nextOption) => {
|
|
1000
1002
|
if (!readOnly) {
|
|
1001
1003
|
setSelectedValue(nextOption.value);
|
|
1002
1004
|
nextOption.onChange?.(e);
|
|
1005
|
+
onChange?.(nextOption.value);
|
|
1003
1006
|
}
|
|
1004
1007
|
};
|
|
1005
1008
|
const statusClassname = statusWithMessage?.status ? { [statusWithMessage.status]: true } : {};
|
|
@@ -1066,7 +1069,7 @@ const TimeRange = ({ range, selectedItem, className, onSelectItem }) => (React.c
|
|
|
1066
1069
|
function formatTimeValue(value, max) {
|
|
1067
1070
|
return Math.max(0, Math.min(max, value)).toString().padStart(2, '0');
|
|
1068
1071
|
}
|
|
1069
|
-
const TimePicker = ({ onTimeChange, hours = 0, minutes = 0, seconds = 0, displaySeconds = false, ...otherProps }) => {
|
|
1072
|
+
const TimePicker = ({ onTimeChange, hours = 0, minutes = 0, seconds = 0, displaySeconds = false, testIdPrefix, ...otherProps }) => {
|
|
1070
1073
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
1071
1074
|
const inputRef = useRef(null);
|
|
1072
1075
|
const incrementMinute = useCallback((increment) => {
|
|
@@ -1125,17 +1128,17 @@ const TimePicker = ({ onTimeChange, hours = 0, minutes = 0, seconds = 0, display
|
|
|
1125
1128
|
const minutesAndSecondsRange = [...Array(12).keys()].map((i) => i * 5);
|
|
1126
1129
|
const openModal = useCallback(() => setIsModalOpen(true), []);
|
|
1127
1130
|
const closeModal = useCallback(() => setIsModalOpen(false), []);
|
|
1128
|
-
return (React.createElement("div", { className: "time-picker" },
|
|
1129
|
-
React.createElement(Input, { ...otherProps, className: cx('input', 'time-input', otherProps.className), type: "time", name: "time", value: selectedTime, onClick: openModal, onChange: handleChange, ref: inputRef, step: displaySeconds ? 1 : 60 }),
|
|
1130
|
-
React.createElement(InputModal, { inputRef: inputRef, isOpen: isModalOpen, onClose: closeModal },
|
|
1131
|
+
return (React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}` : undefined, className: "time-picker" },
|
|
1132
|
+
React.createElement(Input, { testIdPrefix: testIdPrefix ? `${testIdPrefix}` : undefined, ...otherProps, className: cx('input', 'time-input', otherProps.className), type: "time", name: "time", value: selectedTime, onClick: openModal, onChange: handleChange, ref: inputRef, step: displaySeconds ? 1 : 60 }),
|
|
1133
|
+
React.createElement(InputModal, { inputRef: inputRef, isOpen: isModalOpen, onClose: closeModal, testIdPrefix: testIdPrefix ? `${testIdPrefix}-modal` : undefined },
|
|
1131
1134
|
React.createElement("div", { className: "time-picker-container" },
|
|
1132
1135
|
React.createElement(TimeRange, { range: hoursRange, selectedItem: hours, className: "hour", onSelectItem: (h) => onTimeChange({ hours: h, minutes, seconds }) }),
|
|
1133
1136
|
React.createElement("div", { className: "time-separator" }, ":"),
|
|
1134
1137
|
React.createElement("div", { className: "minute-container" },
|
|
1135
1138
|
React.createElement(TimeRange, { range: minutesAndSecondsRange, selectedItem: minutes, className: "minute", onSelectItem: (m) => onTimeChange({ hours, minutes: m, seconds }) }),
|
|
1136
1139
|
React.createElement("div", { className: "minute-buttons" },
|
|
1137
|
-
React.createElement("button", { onClick: () => incrementMinute(-1), className: "minute-button" }, "-1mn"),
|
|
1138
|
-
React.createElement("button", { onClick: () => incrementMinute(1), className: "minute-button" }, "+1mn"))),
|
|
1140
|
+
React.createElement("button", { "data-testid": testIdPrefix ? `${testIdPrefix}-decrement-minute` : undefined, onClick: () => incrementMinute(-1), className: "minute-button" }, "-1mn"),
|
|
1141
|
+
React.createElement("button", { "data-testid": testIdPrefix ? `${testIdPrefix}-increment-minute` : undefined, onClick: () => incrementMinute(1), className: "minute-button" }, "+1mn"))),
|
|
1139
1142
|
displaySeconds && (React.createElement(React.Fragment, null,
|
|
1140
1143
|
React.createElement("div", { className: "time-separator" }, ":"),
|
|
1141
1144
|
React.createElement("div", { className: "second-container" },
|
|
@@ -1201,7 +1204,7 @@ const ToleranceRangeGrid = ({ onSelection, selectedTolerance, toleranceSign, })
|
|
|
1201
1204
|
const TolerancePicker = ({ onToleranceChange, toleranceValues: { minusTolerance, plusTolerance } = {
|
|
1202
1205
|
minusTolerance: TOLERANCE_RANGES[0].value,
|
|
1203
1206
|
plusTolerance: TOLERANCE_RANGES[0].value,
|
|
1204
|
-
}, translateWarningMessage, ...inputProps }) => {
|
|
1207
|
+
}, translateWarningMessage, testIdPrefix, ...inputProps }) => {
|
|
1205
1208
|
const formatToleranceValue = (minusIndex, plusIndex) => `-${TOLERANCE_RANGES[minusIndex]?.label || ''}/+${TOLERANCE_RANGES[plusIndex]?.label || ''}`;
|
|
1206
1209
|
const [showPicker, setShowPicker] = useState(false);
|
|
1207
1210
|
const [inputValue, setInputValue] = useState(formatToleranceValue(0, 0));
|
|
@@ -1223,10 +1226,10 @@ const TolerancePicker = ({ onToleranceChange, toleranceValues: { minusTolerance,
|
|
|
1223
1226
|
}
|
|
1224
1227
|
setInputValue(formatToleranceValue(minusToleranceIndex, plusToleranceIndex));
|
|
1225
1228
|
}, [minusTolerance, plusTolerance]);
|
|
1226
|
-
return (React.createElement("div", { className: "tolerance-picker" },
|
|
1229
|
+
return (React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}` : undefined, className: "tolerance-picker" },
|
|
1227
1230
|
React.createElement("div", null,
|
|
1228
|
-
React.createElement(Input, { ...inputProps, value: inputValue, statusWithMessage: warningStatus, onClick: () => setShowPicker(!showPicker), type: "text", ref: inputRef })),
|
|
1229
|
-
React.createElement(InputModal, { inputRef: inputRef, isOpen: showPicker, onClose: () => setShowPicker(false) },
|
|
1231
|
+
React.createElement(Input, { testIdPrefix: testIdPrefix, ...inputProps, value: inputValue, statusWithMessage: warningStatus, onClick: () => setShowPicker(!showPicker), type: "text", ref: inputRef })),
|
|
1232
|
+
React.createElement(InputModal, { testIdPrefix: "modal", inputRef: inputRef, isOpen: showPicker, onClose: () => setShowPicker(false) },
|
|
1230
1233
|
React.createElement("div", { className: "time-tolerance" },
|
|
1231
1234
|
React.createElement(ToleranceRangeGrid, { onSelection: (e) => onToleranceChange({ minusTolerance: e, plusTolerance }), selectedTolerance: minusTolerance, toleranceSign: "minus" }),
|
|
1232
1235
|
React.createElement("div", { className: "divider" }),
|