@mtes-mct/monitor-ui 2.2.0 → 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,17 @@
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
+
8
+ # [2.2.0](https://github.com/MTES-MCT/monitor-ui/compare/v2.1.1...v2.2.0) (2022-12-15)
9
+
10
+
11
+ ### Features
12
+
13
+ * **elements:** add TagGroup ([#139](https://github.com/MTES-MCT/monitor-ui/issues/139)) ([f12aadb](https://github.com/MTES-MCT/monitor-ui/commit/f12aadb9bdbc684116e19f7c867483d6dc69955a))
14
+
1
15
  ## [2.1.1](https://github.com/MTES-MCT/monitor-ui/compare/v2.1.0...v2.1.1) (2022-12-15)
2
16
 
3
17
 
@@ -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;
@@ -1709,11 +1709,10 @@ const TertiaryTag = styled(Box$7) `
1709
1709
  `;
1710
1710
 
1711
1711
  const TagGroup = styled.div `
1712
+ align-items: center;
1712
1713
  display: flex;
1713
-
1714
- > span:not(:first-child) {
1715
- margin-left: 8px;
1716
- }
1714
+ flex-wrap: wrap;
1715
+ gap: 8px;
1717
1716
  `;
1718
1717
 
1719
1718
  // eslint-lint-disable-next-line @typescript-eslint/naming-convention
@@ -2889,7 +2888,7 @@ function NumberInputWithRef({ defaultValue, max, min, onBack, onClick, onFilled,
2889
2888
  }, [onBack, onNext, onPrevious]);
2890
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)));
2891
2890
  }
2892
- const NumberInput = forwardRef(NumberInputWithRef);
2891
+ const NumberInput$1 = forwardRef(NumberInputWithRef);
2893
2892
  const StyledNumberInput = styled.input `
2894
2893
  background-color: transparent;
2895
2894
  border: 0;
@@ -3029,7 +3028,7 @@ function DateInputWithRef({ defaultValue, isEndDate = false, isForcedFocused, is
3029
3028
  ];
3030
3029
  onChange(nextDateTuple);
3031
3030
  }, [onChange]);
3032
- 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 })] }));
3033
3032
  }
3034
3033
  const DateInput = forwardRef(DateInputWithRef);
3035
3034
  const Box$6 = styled.span `
@@ -3852,7 +3851,7 @@ function TimeInputWithRef({ defaultValue, isLight, isStartDate = false, minutesR
3852
3851
  const nextTimeTuple = [hourInputRef.current.value, minuteInputRef.current.value];
3853
3852
  onChange(nextTimeTuple);
3854
3853
  }, [closeRangedTimePicker, onChange]);
3855
- 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 }))] }));
3856
3855
  }
3857
3856
  const TimeInput = forwardRef(TimeInputWithRef);
3858
3857
  const Box$3 = styled.span `
@@ -4794,6 +4793,26 @@ const ZoneWrapper = styled.div `
4794
4793
  padding: 6px 12px 6px;
4795
4794
  `;
4796
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
+
4797
4816
  function Select({ isLabelHidden = false, isLight = false, label, onChange, options,
4798
4817
  // eslint-disable-next-line @typescript-eslint/naming-convention
4799
4818
  searchable = false, ...originalProps }) {
@@ -4847,7 +4866,7 @@ function TextInput({ isLabelHidden = false, isLight = false, label, onChange, ..
4847
4866
  const normalizedNextValue = nextValue && nextValue.trim().length ? nextValue : undefined;
4848
4867
  onChange(normalizedNextValue);
4849
4868
  }, [onChange]);
4850
- 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)] }));
4851
4870
  }
4852
4871
  const StyledInput = styled(Input) `
4853
4872
  background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
@@ -4913,6 +4932,13 @@ function FormikMultiRadio({ name, ...originalProps }) {
4913
4932
  return jsx(MultiRadio, { defaultValue: defaultValue, name: name, onChange: helpers.setValue, ...originalProps });
4914
4933
  }
4915
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
+
4916
4942
  function FormikSelect({ name, ...originalProps }) {
4917
4943
  const [field, , helpers] = useField(name);
4918
4944
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -4934,5 +4960,5 @@ function FormikTextInput({ name, ...originalProps }) {
4934
4960
  return jsx(TextInput, { defaultValue: defaultValue, name: name, onChange: helpers.setValue, ...originalProps });
4935
4961
  }
4936
4962
 
4937
- 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 };
4938
4964
  //# sourceMappingURL=index.js.map