@mtes-mct/monitor-ui 2.2.1 → 2.3.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [2.2.1](https://github.com/MTES-MCT/monitor-ui/compare/v2.2.0...v2.2.1) (2022-12-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **elements:** use gap instead of margin in TagGroup ([#142](https://github.com/MTES-MCT/monitor-ui/issues/142)) ([b6d73ea](https://github.com/MTES-MCT/monitor-ui/commit/b6d73eaa1daaf4f7c112dd9e5b6542265a2fbb1c))
7
+
1
8
  # [2.2.0](https://github.com/MTES-MCT/monitor-ui/compare/v2.1.1...v2.2.0) (2022-12-15)
2
9
 
3
10
 
@@ -0,0 +1,11 @@
1
+ import type { InputProps } from 'rsuite';
2
+ import type { Promisable } from 'type-fest';
3
+ export type NumberInputProps = Omit<InputProps, 'as' | 'defaultValue' | 'id' | 'onChange' | 'type' | 'value'> & {
4
+ defaultValue?: number;
5
+ isLabelHidden?: boolean;
6
+ isLight?: boolean;
7
+ label: string;
8
+ name: string;
9
+ onChange?: (nextValue: number | undefined) => Promisable<void>;
10
+ };
11
+ export declare function NumberInput({ isLabelHidden, isLight, label, onChange, ...originalProps }: NumberInputProps): JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import type { InputProps } from 'rsuite';
2
2
  import type { Promisable } from 'type-fest';
3
- export type TextInputProps = Omit<InputProps, 'as' | 'defaultValue' | 'id' | 'onChange' | 'value'> & {
3
+ export type TextInputProps = Omit<InputProps, 'as' | 'defaultValue' | 'id' | 'onChange' | 'type' | 'value'> & {
4
4
  defaultValue?: string;
5
5
  isLabelHidden?: boolean;
6
6
  isLight?: boolean;
@@ -0,0 +1,3 @@
1
+ import type { NumberInputProps } from '../fields/NumberInput';
2
+ export type FormikNumberInputProps = Omit<NumberInputProps, 'defaultValue' | 'onChange'>;
3
+ export declare function FormikNumberInput({ name, ...originalProps }: FormikNumberInputProps): JSX.Element;
package/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export { MultiCheckbox } from './fields/MultiCheckbox';
19
19
  export { MultiSelect } from './fields/MultiSelect';
20
20
  export { MultiRadio } from './fields/MultiRadio';
21
21
  export { MultiZoneEditor } from './fields/MultiZoneEditor';
22
+ export { NumberInput } from './fields/NumberInput';
22
23
  export { Select } from './fields/Select';
23
24
  export { Textarea } from './fields/Textarea';
24
25
  export { TextInput } from './fields/TextInput';
@@ -30,6 +31,7 @@ export { FormikEffect } from './formiks/FormikEffect';
30
31
  export { FormikMultiCheckbox } from './formiks/FormikMultiCheckbox';
31
32
  export { FormikMultiSelect } from './formiks/FormikMultiSelect';
32
33
  export { FormikMultiRadio } from './formiks/FormikMultiRadio';
34
+ export { FormikNumberInput } from './formiks/FormikNumberInput';
33
35
  export { FormikSelect } from './formiks/FormikSelect';
34
36
  export { FormikTextarea } from './formiks/FormikTextarea';
35
37
  export { FormikTextInput } from './formiks/FormikTextInput';
@@ -53,6 +55,7 @@ export type { MultiCheckboxProps } from './fields/MultiCheckbox';
53
55
  export type { MultiSelectProps } from './fields/MultiSelect';
54
56
  export type { MultiRadioProps } from './fields/MultiRadio';
55
57
  export type { MultiZoneEditorProps } from './fields/MultiZoneEditor';
58
+ export type { NumberInputProps } from './fields/NumberInput';
56
59
  export type { SelectProps } from './fields/Select';
57
60
  export type { TextareaProps } from './fields/Textarea';
58
61
  export type { TextInputProps } from './fields/TextInput';
@@ -64,6 +67,7 @@ export type { FormikEffectProps } from './formiks/FormikEffect';
64
67
  export type { FormikMultiCheckboxProps } from './formiks/FormikMultiCheckbox';
65
68
  export type { FormikMultiSelectProps } from './formiks/FormikMultiSelect';
66
69
  export type { FormikMultiRadioProps } from './formiks/FormikMultiRadio';
70
+ export type { FormikNumberInputProps } from './formiks/FormikNumberInput';
67
71
  export type { FormikSelectProps } from './formiks/FormikSelect';
68
72
  export type { FormikTextareaProps } from './formiks/FormikTextarea';
69
73
  export type { FormikTextInputProps } from './formiks/FormikTextInput';
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import styled, { createGlobalStyle, ThemeProvider as ThemeProvider$1, css } from 'styled-components';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { useMemo, useRef, useState, useCallback, useEffect, useReducer, forwardRef, useImperativeHandle } from 'react';
4
- import { Dropdown as Dropdown$1, AutoComplete as AutoComplete$1, Checkbox as Checkbox$1, DateRangePicker as DateRangePicker$1, DatePicker as DatePicker$1, TagPicker, Radio, SelectPicker, Input } from 'rsuite';
4
+ import { Dropdown as Dropdown$1, AutoComplete as AutoComplete$1, Checkbox as Checkbox$1, DateRangePicker as DateRangePicker$1, DatePicker as DatePicker$1, TagPicker, Radio, Input, SelectPicker } from 'rsuite';
5
5
  import { useField, useFormikContext } from 'formik';
6
6
 
7
7
  var Accent;
@@ -2888,7 +2888,7 @@ function NumberInputWithRef({ defaultValue, max, min, onBack, onClick, onFilled,
2888
2888
  }, [onBack, onNext, onPrevious]);
2889
2889
  return (jsx(StyledNumberInput, { ref: inputRef, "$size": size, defaultValue: defaultValue, maxLength: size, onClick: handleClick, onFocus: handleFocus, onInput: handleInput, onKeyDown: handleKeyDown, pattern: "\\d*", placeholder: placeholder, type: "text", ...nativeProps }, String(defaultValue)));
2890
2890
  }
2891
- const NumberInput = forwardRef(NumberInputWithRef);
2891
+ const NumberInput$1 = forwardRef(NumberInputWithRef);
2892
2892
  const StyledNumberInput = styled.input `
2893
2893
  background-color: transparent;
2894
2894
  border: 0;
@@ -3028,7 +3028,7 @@ function DateInputWithRef({ defaultValue, isEndDate = false, isForcedFocused, is
3028
3028
  ];
3029
3029
  onChange(nextDateTuple);
3030
3030
  }, [onChange]);
3031
- return (jsxs(Box$6, { ref: boxSpanRef, "$hasError": hasFormatError || hasValidationError, "$isFocused": isForcedFocused || isFocused, "$isLight": isLight, children: [isStartDate && 'Du ', isEndDate && 'Au ', jsx(NumberInput, { ref: dayInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-day`, defaultValue: defaultValue && formatNumberAsDoubleDigit(defaultValue[2]), max: 31, min: 1, onBack: onBack, onBlur: handleBlur, onClick: onClick, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: () => monthInputRef.current.focus(), onPrevious: onPrevious, size: 2 }), "/", jsx(NumberInput, { ref: monthInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-month`, defaultValue: defaultValue && formatNumberAsDoubleDigit(defaultValue[1]), max: 12, min: 1, onBack: () => dayInputRef.current.focus(), onBlur: handleBlur, onClick: onClick, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: () => yearInputRef.current.focus(), onPrevious: () => dayInputRef.current.focus(), size: 2 }), "/", jsx(NumberInput, { ref: yearInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-year`, defaultValue: defaultValue && defaultValue[0], max: currentUtcYear, min: 2020, onBack: () => monthInputRef.current.focus(), onBlur: handleBlur, onClick: onClick, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: onNext, onPrevious: () => monthInputRef.current.focus(), size: 4 })] }));
3031
+ return (jsxs(Box$6, { ref: boxSpanRef, "$hasError": hasFormatError || hasValidationError, "$isFocused": isForcedFocused || isFocused, "$isLight": isLight, children: [isStartDate && 'Du ', isEndDate && 'Au ', jsx(NumberInput$1, { ref: dayInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-day`, defaultValue: defaultValue && formatNumberAsDoubleDigit(defaultValue[2]), max: 31, min: 1, onBack: onBack, onBlur: handleBlur, onClick: onClick, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: () => monthInputRef.current.focus(), onPrevious: onPrevious, size: 2 }), "/", jsx(NumberInput$1, { ref: monthInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-month`, defaultValue: defaultValue && formatNumberAsDoubleDigit(defaultValue[1]), max: 12, min: 1, onBack: () => dayInputRef.current.focus(), onBlur: handleBlur, onClick: onClick, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: () => yearInputRef.current.focus(), onPrevious: () => dayInputRef.current.focus(), size: 2 }), "/", jsx(NumberInput$1, { ref: yearInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-year`, defaultValue: defaultValue && defaultValue[0], max: currentUtcYear, min: 2020, onBack: () => monthInputRef.current.focus(), onBlur: handleBlur, onClick: onClick, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: onNext, onPrevious: () => monthInputRef.current.focus(), size: 4 })] }));
3032
3032
  }
3033
3033
  const DateInput = forwardRef(DateInputWithRef);
3034
3034
  const Box$6 = styled.span `
@@ -3851,7 +3851,7 @@ function TimeInputWithRef({ defaultValue, isLight, isStartDate = false, minutesR
3851
3851
  const nextTimeTuple = [hourInputRef.current.value, minuteInputRef.current.value];
3852
3852
  onChange(nextTimeTuple);
3853
3853
  }, [closeRangedTimePicker, onChange]);
3854
- return (jsxs(Box$3, { ref: boxSpanRef, "$hasError": hasFormatError || hasValidationError, "$isFocused": isFocused, "$isLight": isLight, children: [jsxs(Fragment, { children: [jsx(NumberInput, { ref: hourInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-hour`, defaultValue: controlledDefaultValue && controlledDefaultValue[0], max: 23, min: 0, onBack: handleBack, onBlur: handleBlur, onClick: openRangedTimePicker, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onInput: handleHourInput, onNext: () => minuteInputRef.current.focus(), onPrevious: onPrevious, size: 2 }), ":", jsx(NumberInput, { ref: minuteInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-minute`, defaultValue: controlledDefaultValue && controlledDefaultValue[1], max: 59, min: 0, onBack: () => hourInputRef.current.focus(), onBlur: handleBlur, onClick: openRangedTimePicker, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: onNext, onPrevious: () => hourInputRef.current.focus(), size: 2 })] }), isRangedTimePickerOpenRef.current && (jsx(RangedTimePicker, { filter: rangedTimePickerFilter, minutesRange: minutesRange, onChange: handleRangedTimePickedChange }))] }));
3854
+ return (jsxs(Box$3, { ref: boxSpanRef, "$hasError": hasFormatError || hasValidationError, "$isFocused": isFocused, "$isLight": isLight, children: [jsxs(Fragment, { children: [jsx(NumberInput$1, { ref: hourInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-hour`, defaultValue: controlledDefaultValue && controlledDefaultValue[0], max: 23, min: 0, onBack: handleBack, onBlur: handleBlur, onClick: openRangedTimePicker, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onInput: handleHourInput, onNext: () => minuteInputRef.current.focus(), onPrevious: onPrevious, size: 2 }), ":", jsx(NumberInput$1, { ref: minuteInputRef, "data-cy": `date-range-picker-${isStartDate ? 'start' : 'end'}-minute`, defaultValue: controlledDefaultValue && controlledDefaultValue[1], max: 59, min: 0, onBack: () => hourInputRef.current.focus(), onBlur: handleBlur, onClick: openRangedTimePicker, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: onNext, onPrevious: () => hourInputRef.current.focus(), size: 2 })] }), isRangedTimePickerOpenRef.current && (jsx(RangedTimePicker, { filter: rangedTimePickerFilter, minutesRange: minutesRange, onChange: handleRangedTimePickedChange }))] }));
3855
3855
  }
3856
3856
  const TimeInput = forwardRef(TimeInputWithRef);
3857
3857
  const Box$3 = styled.span `
@@ -4793,6 +4793,26 @@ const ZoneWrapper = styled.div `
4793
4793
  padding: 6px 12px 6px;
4794
4794
  `;
4795
4795
 
4796
+ function NumberInput({ isLabelHidden = false, isLight = false, label, onChange, ...originalProps }) {
4797
+ const key = useMemo(() => `${originalProps.name}-${JSON.stringify(originalProps.defaultValue)}`, [originalProps.defaultValue, originalProps.name]);
4798
+ const handleChange = useCallback((nextValue) => {
4799
+ if (!onChange) {
4800
+ return;
4801
+ }
4802
+ const normalizedNextValueAsString = nextValue && nextValue.length ? nextValue : undefined;
4803
+ const nextValueAsNumber = Number(normalizedNextValueAsString);
4804
+ const normalizedNextValue = !Number.isNaN(nextValueAsNumber) ? nextValueAsNumber : undefined;
4805
+ onChange(normalizedNextValue);
4806
+ }, [onChange]);
4807
+ return (jsxs(Field$2, { children: [jsx(Label, { htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$2, { "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "number", ...originalProps }, key)] }));
4808
+ }
4809
+ const StyledInput$2 = styled(Input) `
4810
+ background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
4811
+ border: 0;
4812
+ font-size: 13px;
4813
+ width: 100%;
4814
+ `;
4815
+
4796
4816
  function Select({ isLabelHidden = false, isLight = false, label, onChange, options,
4797
4817
  // eslint-disable-next-line @typescript-eslint/naming-convention
4798
4818
  searchable = false, ...originalProps }) {
@@ -4846,7 +4866,7 @@ function TextInput({ isLabelHidden = false, isLight = false, label, onChange, ..
4846
4866
  const normalizedNextValue = nextValue && nextValue.trim().length ? nextValue : undefined;
4847
4867
  onChange(normalizedNextValue);
4848
4868
  }, [onChange]);
4849
- return (jsxs(Field$2, { children: [jsx(Label, { htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput, { "$isLight": isLight, id: originalProps.name, onChange: handleChange, ...originalProps }, key)] }));
4869
+ return (jsxs(Field$2, { children: [jsx(Label, { htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput, { "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "text", ...originalProps }, key)] }));
4850
4870
  }
4851
4871
  const StyledInput = styled(Input) `
4852
4872
  background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
@@ -4912,6 +4932,13 @@ function FormikMultiRadio({ name, ...originalProps }) {
4912
4932
  return jsx(MultiRadio, { defaultValue: defaultValue, name: name, onChange: helpers.setValue, ...originalProps });
4913
4933
  }
4914
4934
 
4935
+ function FormikNumberInput({ name, ...originalProps }) {
4936
+ const [field, , helpers] = useField(name);
4937
+ // eslint-disable-next-line react-hooks/exhaustive-deps
4938
+ const defaultValue = useMemo(() => field.value, []);
4939
+ return jsx(NumberInput, { defaultValue: defaultValue, name: name, onChange: helpers.setValue, ...originalProps });
4940
+ }
4941
+
4915
4942
  function FormikSelect({ name, ...originalProps }) {
4916
4943
  const [field, , helpers] = useField(name);
4917
4944
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -4933,5 +4960,5 @@ function FormikTextInput({ name, ...originalProps }) {
4933
4960
  return jsx(TextInput, { defaultValue: defaultValue, name: name, onChange: helpers.setValue, ...originalProps });
4934
4961
  }
4935
4962
 
4936
- export { Accent, AutoComplete, Button, Checkbox, DatePicker, DateRangePicker, Dropdown, Field$2 as Field, Fieldset, FormikAutoComplete, FormikCheckbox, FormikDatePicker, FormikDateRangePicker, FormikEffect, FormikMultiCheckbox, FormikMultiRadio, FormikMultiSelect, FormikSelect, FormikTextInput, FormikTextarea, GlobalStyle, index as Icon, IconButton, Label, Legend, MultiCheckbox, MultiRadio, MultiSelect, MultiZoneEditor, Select, Size, THEME, Tag$1 as Tag, TagGroup, TextInput, Textarea, ThemeProvider };
4963
+ export { Accent, AutoComplete, Button, Checkbox, DatePicker, DateRangePicker, Dropdown, Field$2 as Field, Fieldset, FormikAutoComplete, FormikCheckbox, FormikDatePicker, FormikDateRangePicker, FormikEffect, FormikMultiCheckbox, FormikMultiRadio, FormikMultiSelect, FormikNumberInput, FormikSelect, FormikTextInput, FormikTextarea, GlobalStyle, index as Icon, IconButton, Label, Legend, MultiCheckbox, MultiRadio, MultiSelect, MultiZoneEditor, NumberInput, Select, Size, THEME, Tag$1 as Tag, TagGroup, TextInput, Textarea, ThemeProvider };
4937
4964
  //# sourceMappingURL=index.js.map