@osrd-project/ui-core 0.0.80 → 0.0.82

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.
Files changed (52) hide show
  1. package/dist/components/{inputs/ComboBox → ComboBox}/ComboBox.d.ts +8 -1
  2. package/dist/components/Dialog.d.ts +22 -0
  3. package/dist/components/SegmentedControl.d.ts +11 -0
  4. package/dist/components/Select.d.ts +1 -1
  5. package/dist/components/Table/Table.d.ts +15 -0
  6. package/dist/components/Table/tableAmbientThemes.d.ts +22 -0
  7. package/dist/components/{inputs/TextArea.d.ts → TextArea.d.ts} +1 -1
  8. package/dist/index.d.ts +17 -14
  9. package/dist/index.esm.js +197 -55
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/theme.css +274 -62
  12. package/dist/theme.css.map +1 -1
  13. package/package.json +7 -7
  14. /package/dist/components/{buttons/Button.d.ts → Button.d.ts} +0 -0
  15. /package/dist/components/{inputs/Checkbox → Checkbox}/Checkbox.d.ts +0 -0
  16. /package/dist/components/{inputs/Checkbox → Checkbox}/CheckboxList.d.ts +0 -0
  17. /package/dist/components/{inputs/Checkbox → Checkbox}/CheckboxTree.d.ts +0 -0
  18. /package/dist/components/{inputs/Checkbox → Checkbox}/__tests__/utils.spec.d.ts +0 -0
  19. /package/dist/components/{inputs/Checkbox → Checkbox}/index.d.ts +0 -0
  20. /package/dist/components/{inputs/Checkbox → Checkbox}/type.d.ts +0 -0
  21. /package/dist/components/{inputs/Checkbox → Checkbox}/utils.d.ts +0 -0
  22. /package/dist/components/{inputs/ComboBox → ComboBox}/index.d.ts +0 -0
  23. /package/dist/components/{inputs/ComboBox → ComboBox}/useDefaultComboBox.d.ts +0 -0
  24. /package/dist/components/{inputs/datePicker → DatePicker}/Calendar.d.ts +0 -0
  25. /package/dist/components/{inputs/datePicker → DatePicker}/CalendarPicker.d.ts +0 -0
  26. /package/dist/components/{inputs/datePicker → DatePicker}/DatePicker.d.ts +0 -0
  27. /package/dist/components/{inputs/datePicker → DatePicker}/__tests__/useCalendar.spec.d.ts +0 -0
  28. /package/dist/components/{inputs/datePicker → DatePicker}/__tests__/useCalendarPicker.spec.d.ts +0 -0
  29. /package/dist/components/{inputs/datePicker → DatePicker}/__tests__/useDatePicker.spec.d.ts +0 -0
  30. /package/dist/components/{inputs/datePicker → DatePicker}/__tests__/utils.spec.d.ts +0 -0
  31. /package/dist/components/{inputs/datePicker → DatePicker}/index.d.ts +0 -0
  32. /package/dist/components/{inputs/datePicker → DatePicker}/type.d.ts +0 -0
  33. /package/dist/components/{inputs/datePicker → DatePicker}/useCalendar.d.ts +0 -0
  34. /package/dist/components/{inputs/datePicker → DatePicker}/useCalendarPicker.d.ts +0 -0
  35. /package/dist/components/{inputs/datePicker → DatePicker}/useDatePicker.d.ts +0 -0
  36. /package/dist/components/{inputs/datePicker → DatePicker}/utils.d.ts +0 -0
  37. /package/dist/components/{inputs/FieldWrapper.d.ts → FieldWrapper.d.ts} +0 -0
  38. /package/dist/components/{inputs/Hint.d.ts → Hint.d.ts} +0 -0
  39. /package/dist/components/{inputs/Input.d.ts → Input.d.ts} +0 -0
  40. /package/dist/components/{Modal.d.ts → InputModal.d.ts} +0 -0
  41. /package/dist/components/{inputs/InputStatusIcon.d.ts → InputStatusIcon.d.ts} +0 -0
  42. /package/dist/components/{inputs/Label.d.ts → Label.d.ts} +0 -0
  43. /package/dist/components/{inputs/PasswordInput.d.ts → PasswordInput.d.ts} +0 -0
  44. /package/dist/components/{inputs/RadioButton.d.ts → RadioButton.d.ts} +0 -0
  45. /package/dist/components/{inputs/RadioGroup.d.ts → RadioGroup.d.ts} +0 -0
  46. /package/dist/components/{inputs/Slider.d.ts → Slider.d.ts} +0 -0
  47. /package/dist/components/{inputs/StatusMessage.d.ts → StatusMessage.d.ts} +0 -0
  48. /package/dist/components/{inputs/TimePicker.d.ts → TimePicker.d.ts} +0 -0
  49. /package/dist/components/{inputs/TokenInput.d.ts → TokenInput.d.ts} +0 -0
  50. /package/dist/components/{inputs/tolerancePicker → TolerancePicker}/TolerancePicker.d.ts +0 -0
  51. /package/dist/components/{inputs/tolerancePicker → TolerancePicker}/ToleranceRangeGrid.d.ts +0 -0
  52. /package/dist/components/{inputs/tolerancePicker → TolerancePicker}/consts.d.ts +0 -0
@@ -9,6 +9,13 @@ export type ComboBoxProps<T> = Omit<InputProps, 'value'> & {
9
9
  onSelectSuggestion: (option: T | undefined) => void;
10
10
  resetSuggestions: () => void;
11
11
  testIdPrefix?: string;
12
+ renderListElementComponent?: (params: {
13
+ suggestion: T;
14
+ index: number;
15
+ isActive: boolean;
16
+ isSelected: boolean;
17
+ }) => ReactNode;
18
+ renderFooterItem?: () => ReactNode;
12
19
  };
13
20
  /**
14
21
  * ComboBox component
@@ -16,5 +23,5 @@ export type ComboBoxProps<T> = Omit<InputProps, 'value'> & {
16
23
  * You can use the hook useDefaultComboBox to get the default behavior.
17
24
  * See the stories.
18
25
  */
19
- declare const ComboBox: <T>({ suggestions, customLabel, numberOfSuggestionsToShow, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, testIdPrefix, ...inputProps }: ComboBoxProps<T>) => React.JSX.Element;
26
+ declare const ComboBox: <T>({ suggestions, customLabel, numberOfSuggestionsToShow, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, testIdPrefix, renderListElementComponent, renderFooterItem, ...inputProps }: ComboBoxProps<T>) => React.JSX.Element;
20
27
  export default ComboBox;
@@ -0,0 +1,22 @@
1
+ import React, { type DialogHTMLAttributes } from 'react';
2
+ type ModalProps = DialogHTMLAttributes<HTMLDialogElement> & {
3
+ fullscreen?: boolean;
4
+ headerClassname?: string;
5
+ bodyClassname?: string;
6
+ footerClassname?: string;
7
+ header: React.ReactNode;
8
+ footer: React.ReactNode;
9
+ };
10
+ /**
11
+ * Display a styled dialog box.
12
+ * You are in charge of its lifecycle (open & close), this componant just display it.
13
+ *
14
+ * Children must be an array of 3 items, where :
15
+ * - the first one is for the header
16
+ * - the second one is for the content
17
+ * - the last is for the footer
18
+ *
19
+ * NB: Inside header, only title tags have the good style (font weight and size)
20
+ */
21
+ declare const Dialog: ({ children, className, fullscreen, header, headerClassname, footer, footerClassname, bodyClassname, ...dialogProps }: ModalProps) => React.JSX.Element;
22
+ export default Dialog;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export type SegmentedControlProps<T> = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'checked'> & {
3
+ options: Array<T>;
4
+ onChange: (option: T) => void;
5
+ value: T;
6
+ getOptionLabel: (option: T) => string;
7
+ getOptionValue: (option: T) => string;
8
+ getOptionIcon?: (option: T) => React.ReactNode;
9
+ };
10
+ declare const SegmentedControl: <T>({ options, onChange, value, getOptionLabel, getOptionValue, getOptionIcon, ...inputProps }: SegmentedControlProps<T>) => React.JSX.Element;
11
+ export default SegmentedControl;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type FieldWrapperProps } from './inputs/FieldWrapper';
2
+ import { type FieldWrapperProps } from './FieldWrapper';
3
3
  export type SelectProps<T> = Omit<React.InputHTMLAttributes<HTMLSelectElement>, 'value' | 'onChange'> & Omit<FieldWrapperProps, 'children'> & {
4
4
  options: Array<T>;
5
5
  value?: T;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { type AmbientVariant } from './tableAmbientThemes';
3
+ interface TableColumn {
4
+ key: string;
5
+ label: string;
6
+ className?: string;
7
+ }
8
+ type TableValue = string | number | boolean | null | undefined;
9
+ interface TableProps {
10
+ columns: Array<TableColumn>;
11
+ data: Array<Record<string, TableValue>>;
12
+ ambientVariant?: AmbientVariant;
13
+ }
14
+ declare const Table: ({ columns, data, ambientVariant }: TableProps) => React.JSX.Element;
15
+ export default Table;
@@ -0,0 +1,22 @@
1
+ export type AmbientVariant = 'A' | 'B' | 'C' | 'D';
2
+ export declare const colors: {
3
+ ambientA5: string;
4
+ ambientA10: string;
5
+ ambientA15: string;
6
+ ambientB5: string;
7
+ ambientB10: string;
8
+ ambientB15: string;
9
+ ambientC5: string;
10
+ ambientC10: string;
11
+ ambientC15: string;
12
+ ambientD5: string;
13
+ ambientD10: string;
14
+ ambientD15: string;
15
+ blackAlpha: string;
16
+ };
17
+ export declare const TABLE_AMBIENT_THEMES: Record<AmbientVariant, {
18
+ mix1: string;
19
+ mix2: string;
20
+ odd: string;
21
+ even: string;
22
+ }>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
  import { type FieldWrapperProps } from './FieldWrapper';
3
3
  export type TextAreaProps = React.InputHTMLAttributes<HTMLTextAreaElement> & Omit<FieldWrapperProps, 'children'>;
4
- declare const TextArea: ({ id, label, value: initialValue, hint, required, disabled, statusWithMessage, maxLength, onChange, onKeyUp, onBlur, ...rest }: TextAreaProps) => React.JSX.Element;
4
+ declare const TextArea: ({ id, label, value, hint, required, disabled, statusWithMessage, maxLength, onChange, onKeyUp, onBlur, ...rest }: TextAreaProps) => React.JSX.Element;
5
5
  export default TextArea;
package/dist/index.d.ts CHANGED
@@ -1,16 +1,19 @@
1
1
  import './styles/main.css';
2
- export { default as Button, ButtonProps } from './components/buttons/Button';
3
- export { default as ComboBox, type ComboBoxProps, useDefaultComboBox, } from './components/inputs/ComboBox';
4
- export { Checkbox, CheckboxList, CheckboxListProps, CheckboxProps, CheckboxesTree, CheckboxesTreeProps, CheckboxTreeItem, } from './components/inputs/Checkbox';
5
- export { DatePicker, type CalendarSlot, type DatePickerProps, type RangeDatePickerProps, type SingleDatePickerProps, } from './components/inputs/datePicker';
6
- export { default as Input, InputProps } from './components/inputs/Input';
7
- export { default as PasswordInput, PasswordInputProps } from './components/inputs/PasswordInput';
8
- export { default as RadioButton, RadioButtonProps } from './components/inputs/RadioButton';
9
- export { default as RadioGroup, RadioGroupProps } from './components/inputs/RadioGroup';
10
- export { type StatusWithMessage } from './components/inputs/StatusMessage';
2
+ export { default as Button, ButtonProps } from './components/Button';
3
+ export { default as ComboBox, type ComboBoxProps, useDefaultComboBox } from './components/ComboBox';
4
+ export { Checkbox, CheckboxList, CheckboxListProps, CheckboxProps, CheckboxesTree, CheckboxesTreeProps, CheckboxTreeItem, } from './components/Checkbox';
5
+ export { DatePicker, type CalendarSlot, type DatePickerProps, type RangeDatePickerProps, type SingleDatePickerProps, } from './components/DatePicker';
6
+ export { default as Input, InputProps } from './components/Input';
7
+ export { default as PasswordInput, PasswordInputProps } from './components/PasswordInput';
8
+ export { default as RadioButton, RadioButtonProps } from './components/RadioButton';
9
+ export { default as RadioGroup, RadioGroupProps } from './components/RadioGroup';
10
+ export { type StatusWithMessage } from './components/StatusMessage';
11
11
  export { default as Select, SelectProps } from './components/Select';
12
- export { default as TextArea, TextAreaProps } from './components/inputs/TextArea';
13
- export { default as TimePicker, type TimePickerProps } from './components/inputs/TimePicker';
14
- export { default as Slider, SliderProps } from './components/inputs/Slider';
15
- export { default as TolerancePicker, type TolerancePickerProps, type ToleranceValues, } from './components/inputs/tolerancePicker/TolerancePicker';
16
- export { default as TokenInput, TokenInputProps } from './components/inputs/TokenInput';
12
+ export { default as TextArea, TextAreaProps } from './components/TextArea';
13
+ export { default as TimePicker, type TimePickerProps } from './components/TimePicker';
14
+ export { default as Slider, SliderProps } from './components/Slider';
15
+ export { default as TolerancePicker, type TolerancePickerProps, type ToleranceValues, } from './components/TolerancePicker/TolerancePicker';
16
+ export { default as TokenInput, TokenInputProps } from './components/TokenInput';
17
+ export { default as Table } from './components/Table/Table';
18
+ export { default as Dialog } from './components/Dialog';
19
+ export { default as SegmentedControl, SegmentedControlProps } from './components/SegmentedControl';
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react';
2
- import { Gear, Info, CheckCircle, Alert, Blocked, RequiredInput, X, XCircle, ChevronDown, ChevronLeft, ChevronRight, Calendar as Calendar$1, EyeClosed, Eye } from '@osrd-project/ui-icons';
3
2
  import cx from 'classnames';
3
+ import { Gear, Info, CheckCircle, Alert, Blocked, RequiredInput, X, XCircle, ChevronDown, ChevronLeft, ChevronRight, Calendar as Calendar$1, EyeClosed, Eye } from '@osrd-project/ui-icons';
4
4
 
5
5
  const Button = ({ label, variant = 'Primary', isLoading = false, isDisabled = false, leadingIcon = null, counter = null, size = 'large', onClick, dataTestID, ...btnAttrs }) => {
6
6
  const handleClick = () => {
@@ -10,11 +10,10 @@ const Button = ({ label, variant = 'Primary', isLoading = false, isDisabled = fa
10
10
  };
11
11
  return (React.createElement("button", { ...btnAttrs, className: cx('ui-button flex items-center', btnAttrs.className, variant.toLowerCase(), size.toLowerCase(), {
12
12
  loading: isLoading,
13
- }), "data-testid": dataTestID, onClick: handleClick, disabled: isDisabled || isLoading }, isLoading ? (React.createElement("span", { className: "icon" },
14
- React.createElement(Gear, { variant: "fill", size: "lg" }))) : (React.createElement(React.Fragment, null,
13
+ }), "data-testid": dataTestID, onClick: handleClick, disabled: isDisabled || isLoading },
15
14
  leadingIcon && React.createElement("span", { className: "leading-icon mr-2" }, leadingIcon),
16
15
  label,
17
- counter !== null && React.createElement("span", { className: "counter ml-2" }, counter)))));
16
+ counter !== null && React.createElement("span", { className: "counter ml-2" }, counter)));
18
17
  };
19
18
 
20
19
  const useOutsideClick = (ref, handler) => {
@@ -136,16 +135,13 @@ Input.displayName = 'Input';
136
135
  * You can use the hook useDefaultComboBox to get the default behavior.
137
136
  * See the stories.
138
137
  */
139
- const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, testIdPrefix, ...inputProps }) => {
138
+ const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, value, small, getSuggestionLabel, onChange, onSelectSuggestion, resetSuggestions, testIdPrefix, renderListElementComponent, renderFooterItem, ...inputProps }) => {
140
139
  const [activeSuggestionIndex, setActiveSuggestionIndex] = useState(-1);
141
140
  const [inputValue, setInputValue] = useState('');
142
141
  const [isInputFocused, setIsInputFocused] = useState(false);
143
142
  const suggestionRefs = useRef([]);
144
143
  const inputRef = useRef(null);
145
144
  const wrapperRef = useRef(null);
146
- const focusInput = useCallback(() => {
147
- inputRef.current?.focus();
148
- }, [inputRef]);
149
145
  const removeFocus = () => {
150
146
  setIsInputFocused(false);
151
147
  setActiveSuggestionIndex(-1);
@@ -155,6 +151,15 @@ const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, val
155
151
  resetSuggestions();
156
152
  };
157
153
  /* eslint-disable react-hooks/exhaustive-deps */
154
+ const focusInput = useCallback(() => {
155
+ if (isInputFocused) {
156
+ removeFocus();
157
+ }
158
+ else {
159
+ inputRef.current?.focus();
160
+ }
161
+ }, [inputRef, isInputFocused]);
162
+ /* eslint-disable react-hooks/exhaustive-deps */
158
163
  useEffect(() => {
159
164
  if (value) {
160
165
  setInputValue(getSuggestionLabel(value));
@@ -180,33 +185,43 @@ const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, val
180
185
  removeFocus();
181
186
  };
182
187
  const handleKeyDown = (e) => {
183
- if (e.key === 'ArrowDown') {
184
- setActiveSuggestionIndex((prev) => {
185
- const newIndex = prev < suggestions.length - 1 ? prev + 1 : prev;
186
- if (suggestionRefs.current[newIndex]) {
187
- suggestionRefs.current[newIndex].scrollIntoView({
188
- block: 'nearest',
189
- });
188
+ switch (e.key) {
189
+ case 'ArrowDown': {
190
+ setActiveSuggestionIndex((prev) => {
191
+ const newIndex = prev < suggestions.length - 1 ? prev + 1 : prev;
192
+ suggestionRefs.current[newIndex]?.scrollIntoView({ block: 'nearest' });
193
+ return newIndex;
194
+ });
195
+ break;
196
+ }
197
+ case 'ArrowUp': {
198
+ setActiveSuggestionIndex((prev) => {
199
+ const newIndex = prev > 0 ? prev - 1 : prev;
200
+ suggestionRefs.current[newIndex]?.scrollIntoView({ block: 'nearest' });
201
+ return newIndex;
202
+ });
203
+ break;
204
+ }
205
+ case 'Enter': {
206
+ e.preventDefault();
207
+ if (activeSuggestionIndex >= 0) {
208
+ selectSuggestion(activeSuggestionIndex);
190
209
  }
191
- return newIndex;
192
- });
193
- }
194
- else if (e.key === 'ArrowUp') {
195
- setActiveSuggestionIndex((prev) => {
196
- const newIndex = prev > 0 ? prev - 1 : prev;
197
- if (suggestionRefs.current[newIndex]) {
198
- suggestionRefs.current[newIndex].scrollIntoView({
199
- block: 'nearest',
200
- });
210
+ else if (suggestions.length === 1) {
211
+ selectSuggestion(0);
201
212
  }
202
- return newIndex;
203
- });
204
- }
205
- else if ((e.key === 'Enter' || e.key === 'Tab') && activeSuggestionIndex >= 0) {
206
- selectSuggestion(activeSuggestionIndex);
207
- }
208
- else if (e.key === 'Escape') {
209
- closeSuggestions();
213
+ break;
214
+ }
215
+ case 'Tab': {
216
+ if (activeSuggestionIndex >= 0) {
217
+ selectSuggestion(activeSuggestionIndex);
218
+ }
219
+ break;
220
+ }
221
+ case 'Escape': {
222
+ closeSuggestions();
223
+ break;
224
+ }
210
225
  }
211
226
  };
212
227
  const handleInputFocus = (e) => {
@@ -240,24 +255,41 @@ const ComboBox = ({ suggestions, customLabel, numberOfSuggestionsToShow = 5, val
240
255
  action: focusInput,
241
256
  className: cx('chevron-icon', {
242
257
  disabled: inputProps.disabled,
258
+ open: isInputFocused,
243
259
  }),
244
260
  },
245
261
  ];
246
- }, [inputProps.readOnly, inputProps.disabled, clearInput, value, small, focusInput]);
262
+ }, [
263
+ inputProps.readOnly,
264
+ inputProps.disabled,
265
+ clearInput,
266
+ value,
267
+ small,
268
+ focusInput,
269
+ isInputFocused,
270
+ ]);
247
271
  return (React.createElement("div", { "data-testid": testIdPrefix ? `${testIdPrefix}` : undefined, className: "ui-combo-box", style: { '--number-of-suggestions': numberOfSuggestionsToShow }, ref: wrapperRef },
248
272
  customLabel && React.createElement("label", { htmlFor: inputProps.id }, customLabel),
249
273
  React.createElement(Input, { testIdPrefix: inputProps.id, ...inputProps, ref: inputRef, value: inputValue, onChange: handleInputChange, onKeyDown: handleKeyDown, onFocus: handleInputFocus, withIcons: inputIcons, small: small }),
250
- showSuggestions && (React.createElement("ul", { className: "suggestions-list", "data-testid": testIdPrefix ? `${testIdPrefix}-list` : undefined }, suggestions.map((suggestion, index) => (React.createElement("li", { ref: (el) => {
251
- if (suggestionRefs) {
252
- suggestionRefs.current[index] = el;
253
- }
254
- }, key: `${getSuggestionLabel(suggestion)}-${index}`, "data-testid": testIdPrefix ? `${testIdPrefix}-item` : undefined, className: cx('suggestion-item', {
255
- active: index === activeSuggestionIndex,
256
- selected: value && getSuggestionLabel(value) === getSuggestionLabel(suggestion),
257
- small,
258
- }), onClick: () => selectSuggestion(index), onMouseDown: (e) => e.preventDefault(), onMouseEnter: () => {
259
- setActiveSuggestionIndex(index);
260
- } }, getSuggestionLabel(suggestion))))))));
274
+ showSuggestions && (React.createElement("ul", { className: "suggestions-list", "data-testid": testIdPrefix ? `${testIdPrefix}-list` : undefined, onMouseLeave: () => setActiveSuggestionIndex(-1) },
275
+ suggestions.map((suggestion, index) => (React.createElement("li", { ref: (el) => {
276
+ if (suggestionRefs) {
277
+ suggestionRefs.current[index] = el;
278
+ }
279
+ }, key: `${getSuggestionLabel(suggestion)}-${index}`, "data-testid": testIdPrefix ? `${testIdPrefix}-item` : undefined, className: cx('suggestion-item', {
280
+ active: index === activeSuggestionIndex,
281
+ selected: value && getSuggestionLabel(value) === getSuggestionLabel(suggestion),
282
+ small,
283
+ 'suggestion-item--custom': renderListElementComponent,
284
+ }), onClick: () => selectSuggestion(index), onMouseEnter: () => setActiveSuggestionIndex(index) }, renderListElementComponent
285
+ ? renderListElementComponent({
286
+ suggestion,
287
+ index,
288
+ isActive: index === activeSuggestionIndex,
289
+ isSelected: !!value && getSuggestionLabel(value) === getSuggestionLabel(suggestion),
290
+ })
291
+ : getSuggestionLabel(suggestion)))),
292
+ renderFooterItem && renderFooterItem()))));
261
293
  };
262
294
 
263
295
  const normalizeString = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
@@ -792,6 +824,8 @@ function useCalendarPicker({ initialDate, selectedSlot, selectableSlot, numberOf
792
824
  }
793
825
  };
794
826
  useEffect(() => {
827
+ // TODO: fix this lint
828
+ // eslint-disable-next-line react-hooks/set-state-in-effect
795
829
  setActiveDate(initialDate ?? selectedSlot?.start ?? selectableSlot?.start ?? new Date());
796
830
  }, [initialDate, selectedSlot, selectableSlot]);
797
831
  return {
@@ -962,7 +996,7 @@ const InputModal = ({ inputRef, isOpen, onClose, children, testIdPrefix }) => {
962
996
  useOutsideClick(modalRef, onClose);
963
997
  if (!isOpen)
964
998
  return null;
965
- return (React.createElement("div", { className: "ui-modal-overlay" },
999
+ return (React.createElement("div", { className: "ui-input-modal-overlay" },
966
1000
  React.createElement("div", { ref: modalRef, className: "modal-content", style: { top: modalPosition.top, left: modalPosition.left } },
967
1001
  React.createElement("button", { "data-testid": testIdPrefix ? `${testIdPrefix}-close-button` : undefined, className: "close-button", onClick: onClose },
968
1002
  React.createElement(X, { size: "lg" })),
@@ -1008,6 +1042,10 @@ const RadioButton = ({ id, label, value, hint, readOnly, onBlur, onKeyUp, small,
1008
1042
 
1009
1043
  const RadioGroup = ({ label, value, subtitle, readOnly, disabled, options, statusWithMessage, required, small, onChange, }) => {
1010
1044
  const [selectedValue, setSelectedValue] = useState(value);
1045
+ useEffect(() => {
1046
+ setSelectedValue(value);
1047
+ }, [value]);
1048
+ const statusClassname = statusWithMessage?.status ? { [statusWithMessage.status]: true } : {};
1011
1049
  const handleOptionChange = (e, nextOption) => {
1012
1050
  if (!readOnly) {
1013
1051
  setSelectedValue(nextOption.value);
@@ -1015,7 +1053,6 @@ const RadioGroup = ({ label, value, subtitle, readOnly, disabled, options, statu
1015
1053
  onChange?.(nextOption.value);
1016
1054
  }
1017
1055
  };
1018
- const statusClassname = statusWithMessage?.status ? { [statusWithMessage.status]: true } : {};
1019
1056
  return (React.createElement("div", { className: cx('ui-radio-button-wrapper', statusClassname) },
1020
1057
  label && (React.createElement("label", { className: "label" },
1021
1058
  required && (React.createElement("span", { className: "required" },
@@ -1055,14 +1092,9 @@ const Select = ({ id, label, hint, value, options, placeholder, statusWithMessag
1055
1092
  };
1056
1093
 
1057
1094
  const CHAR_COUNT_ERROR_THRESHOLD = 40;
1058
- const TextArea = ({ id, label, value: initialValue, hint, required, disabled, statusWithMessage, maxLength, onChange, onKeyUp, onBlur, ...rest }) => {
1059
- const [value, setValue] = useState(initialValue);
1095
+ const TextArea = ({ id, label, value = '', hint, required, disabled, statusWithMessage, maxLength, onChange, onKeyUp, onBlur, ...rest }) => {
1060
1096
  const charCount = value?.length || 0;
1061
1097
  const { handleKeyUp, handleBlur, isFocusByTab } = useFocusByTab({ onBlur, onKeyUp });
1062
- const handleChange = (e) => {
1063
- setValue(e.target.value);
1064
- onChange?.(e);
1065
- };
1066
1098
  return (React.createElement(FieldWrapper, { id: id, label: label, hint: hint, statusWithMessage: statusWithMessage, disabled: disabled, required: required, className: "ui-text-area-field-wrapper" },
1067
1099
  React.createElement("div", { className: cx('text-area-wrapper', { 'focused-by-tab': isFocusByTab }) },
1068
1100
  maxLength && (React.createElement("div", { className: cx('char-count', {
@@ -1072,7 +1104,7 @@ const TextArea = ({ id, label, value: initialValue, hint, required, disabled, st
1072
1104
  charCount,
1073
1105
  "/",
1074
1106
  maxLength)),
1075
- React.createElement("textarea", { className: cx('text-area', { [statusWithMessage?.status || '']: !!statusWithMessage }), id: id, value: value, disabled: disabled, maxLength: maxLength, onChange: handleChange, onBlur: handleBlur, onKeyUp: handleKeyUp, ...rest }))));
1107
+ React.createElement("textarea", { className: cx('text-area', { [statusWithMessage?.status || '']: !!statusWithMessage }), id: id, value: value, disabled: disabled, maxLength: maxLength, onChange: onChange, onBlur: handleBlur, onKeyUp: handleKeyUp, ...rest }))));
1076
1108
  };
1077
1109
 
1078
1110
  const TimeRange = ({ range, selectedItem, className, onSelectItem }) => (React.createElement("div", { className: "time-grid" }, range.map((item) => (React.createElement("div", { key: item, className: cx(className, { selected: selectedItem === item }), onClick: () => onSelectItem(item) }, item.toString().padStart(2, '0'))))));
@@ -1272,5 +1304,115 @@ const TokenInput = ({ label, tokens: initialTokens }) => {
1272
1304
  React.createElement("input", { type: "text", value: newToken, onChange: (e) => setNewToken(e.target.value), onKeyDown: addToken, className: "token-input", ref: inputRef }))));
1273
1305
  };
1274
1306
 
1275
- export { Button, Checkbox, CheckboxList, CheckboxesTree, ComboBox, DatePicker, Input, PasswordInput, RadioButton, RadioGroup, Select, Slider, TextArea, TimePicker, TokenInput, TolerancePicker, useDefaultComboBox };
1307
+ const colors = {
1308
+ ambientA5: 'rgb(246, 248, 249)',
1309
+ ambientA10: 'rgb(239, 243, 245)',
1310
+ ambientA15: 'rgb(233, 239, 242)',
1311
+ ambientB5: 'rgb(250, 249, 245)',
1312
+ ambientB10: 'rgb(247, 246, 238)',
1313
+ ambientB15: 'rgb(242, 240, 228)',
1314
+ ambientC5: 'rgb(246, 249, 246)',
1315
+ ambientC10: 'rgb(240, 244, 241)',
1316
+ ambientC15: 'rgb(234, 240, 235)',
1317
+ ambientD5: 'rgb(248, 247, 253)',
1318
+ ambientD10: 'rgb(244, 243, 252)',
1319
+ ambientD15: 'rgb(239, 237, 247)',
1320
+ blackAlpha: 'rgba(0, 0, 0)',
1321
+ };
1322
+ const TABLE_AMBIENT_THEMES = {
1323
+ A: {
1324
+ mix1: colors.blackAlpha,
1325
+ mix2: colors.ambientA5,
1326
+ odd: colors.ambientA10,
1327
+ even: colors.ambientA15,
1328
+ },
1329
+ B: {
1330
+ mix1: colors.blackAlpha,
1331
+ mix2: colors.ambientB5,
1332
+ odd: colors.ambientB10,
1333
+ even: colors.ambientB15,
1334
+ },
1335
+ C: {
1336
+ mix1: colors.blackAlpha,
1337
+ mix2: colors.ambientC5,
1338
+ odd: colors.ambientC10,
1339
+ even: colors.ambientC15,
1340
+ },
1341
+ D: {
1342
+ mix1: colors.blackAlpha,
1343
+ mix2: colors.ambientD5,
1344
+ odd: colors.ambientD10,
1345
+ even: colors.ambientD15,
1346
+ },
1347
+ };
1348
+
1349
+ const Table = ({ columns, data, ambientVariant = 'B' }) => {
1350
+ const theme = TABLE_AMBIENT_THEMES[ambientVariant];
1351
+ return (React.createElement("table", { className: "table-container ambient", style: {
1352
+ '--mix-color-1': theme.mix1,
1353
+ '--mix-color-2': theme.mix2,
1354
+ '--row-bg-odd': theme.odd,
1355
+ '--row-bg-even': theme.even,
1356
+ } },
1357
+ React.createElement("thead", null,
1358
+ React.createElement("tr", null, columns.map((col) => (React.createElement("td", { key: col.key, className: col.className }, col.label))))),
1359
+ React.createElement("tbody", null, data.map((row, i) => (React.createElement("tr", { key: i }, columns.map((col) => (React.createElement("td", { key: col.key, className: col.className }, row[col.key])))))))));
1360
+ };
1361
+
1362
+ /**
1363
+ * Display a styled dialog box.
1364
+ * You are in charge of its lifecycle (open & close), this componant just display it.
1365
+ *
1366
+ * Children must be an array of 3 items, where :
1367
+ * - the first one is for the header
1368
+ * - the second one is for the content
1369
+ * - the last is for the footer
1370
+ *
1371
+ * NB: Inside header, only title tags have the good style (font weight and size)
1372
+ */
1373
+ const Dialog = ({ children, className, fullscreen = false, header, headerClassname, footer, footerClassname, bodyClassname, ...dialogProps }) => {
1374
+ const overlayRef = useRef(null);
1375
+ const dialogRef = useRef(null);
1376
+ /**
1377
+ * When the dialog height change
1378
+ * => check if there is a scroll on the overlay and if so add a 'scroll' class on it
1379
+ */
1380
+ useEffect(() => {
1381
+ if (fullscreen)
1382
+ return;
1383
+ if (!overlayRef.current || !dialogRef.current)
1384
+ return;
1385
+ const resizeObserver = new ResizeObserver(() => {
1386
+ if (overlayRef.current) {
1387
+ if (overlayRef.current.scrollHeight > overlayRef.current.clientHeight) {
1388
+ overlayRef.current.classList.add('scroll');
1389
+ }
1390
+ else {
1391
+ overlayRef.current.classList.remove('scroll');
1392
+ }
1393
+ }
1394
+ });
1395
+ resizeObserver.observe(dialogRef.current);
1396
+ return () => resizeObserver.disconnect();
1397
+ }, [overlayRef, dialogRef, fullscreen]);
1398
+ return (React.createElement("div", { ref: overlayRef, className: "ui-dialog-overlay flex items-center justify-center", tabIndex: -1 },
1399
+ React.createElement("dialog", { ref: dialogRef, ...dialogProps, className: cx('dialog-content', className, fullscreen && 'fullscreen'), open: true },
1400
+ React.createElement("header", { className: cx(headerClassname) }, header),
1401
+ React.createElement("section", { className: cx(bodyClassname) }, children),
1402
+ React.createElement("footer", { className: cx(footerClassname) }, footer))));
1403
+ };
1404
+
1405
+ const SegmentedControl = ({ options, onChange, value, getOptionLabel, getOptionValue, getOptionIcon, ...inputProps }) => {
1406
+ const opts = useMemo(() => options.map((e) => ({
1407
+ value: getOptionValue(e),
1408
+ label: getOptionLabel(e),
1409
+ icon: getOptionIcon ? getOptionIcon(e) : null,
1410
+ source: e,
1411
+ })), [options, getOptionValue, getOptionLabel, getOptionIcon]);
1412
+ return (React.createElement("div", { className: "segmented-control" }, opts.map((option) => (React.createElement("label", { key: option.value, className: cx('segmented-control-option', option.value === getOptionValue(value) && 'checked'), title: option.label },
1413
+ React.createElement("div", { className: "segmented-control-option-content" }, option.icon ? option.icon : option.label),
1414
+ React.createElement("input", { ...inputProps, type: "radio", checked: option.value === getOptionValue(value), onChange: () => onChange(option.source) }))))));
1415
+ };
1416
+
1417
+ export { Button, Checkbox, CheckboxList, CheckboxesTree, ComboBox, DatePicker, Dialog, Input, PasswordInput, RadioButton, RadioGroup, SegmentedControl, Select, Slider, Table, TextArea, TimePicker, TokenInput, TolerancePicker, useDefaultComboBox };
1276
1418
  //# sourceMappingURL=index.esm.js.map