@mtes-mct/monitor-ui 2.9.0 → 2.9.1

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.9.0](https://github.com/MTES-MCT/monitor-ui/compare/v2.8.1...v2.9.0) (2023-01-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * **types:** restrict component props types to handle exact optional prop types ([296acf4](https://github.com/MTES-MCT/monitor-ui/commit/296acf48a7c701f85cbee72ceeea4071d60f0ea6))
7
+
1
8
  ## [2.8.1](https://github.com/MTES-MCT/monitor-ui/compare/v2.8.0...v2.8.1) (2023-01-19)
2
9
 
3
10
 
package/index.js CHANGED
@@ -4601,13 +4601,15 @@ function sortDates(dates) {
4601
4601
  function RangeCalendarPicker({ defaultValue, isHistorical, isOpen, onChange }) {
4602
4602
  const boxRef = useRef();
4603
4603
  const selectedFirstDate = useRef();
4604
+ const selectedSecondDate = useRef();
4604
4605
  const { forceUpdate } = useForceUpdate();
4605
4606
  const controlledValue = useMemo(() => (defaultValue ? sortDates(defaultValue) : undefined), [defaultValue]);
4606
4607
  const utcTodayAsDayjs = useMemo(() => getUtcDayjs().endOf('day'), []);
4607
4608
  const disabledDate = useMemo(() => (date) => isHistorical ? getUtcizedDayjs(date).isAfter(utcTodayAsDayjs) : false, [isHistorical, utcTodayAsDayjs]);
4608
4609
  const handleSelect = useCallback((nextDate) => {
4609
- if (!selectedFirstDate.current) {
4610
+ if (!selectedFirstDate.current || selectedSecondDate.current) {
4610
4611
  selectedFirstDate.current = nextDate;
4612
+ selectedSecondDate.current = undefined;
4611
4613
  return;
4612
4614
  }
4613
4615
  const sortedDateRange = sortDates([selectedFirstDate.current, nextDate]);
@@ -4615,6 +4617,7 @@ function RangeCalendarPicker({ defaultValue, isHistorical, isOpen, onChange }) {
4615
4617
  const startDateTuple = getDateTupleFromDate(startDate);
4616
4618
  const endDateTuple = getDateTupleFromDate(endDate);
4617
4619
  const nextDateTupleRange = [startDateTuple, endDateTuple];
4620
+ selectedSecondDate.current = nextDate;
4618
4621
  onChange(nextDateTupleRange);
4619
4622
  }, [onChange]);
4620
4623
  useEffect(() => {
@@ -4915,9 +4918,8 @@ disabled = false, isCompact = false, isHistorical = false, isLabelHidden = false
4915
4918
  selectedLocalizedEndDateTupleRef.current = nextEndDateTuple;
4916
4919
  selectedLocalizedEndTimeTupleRef.current = getTimeTupleFromDate(selectedLocalizedEndDateRef.current);
4917
4920
  closeRangeCalendarPicker();
4918
- forceUpdate();
4919
4921
  submit();
4920
- }, [closeRangeCalendarPicker, forceUpdate, submit, withTime]);
4922
+ }, [closeRangeCalendarPicker, submit, withTime]);
4921
4923
  const handleTimeInputFilled = useCallback((position, nextTimeTuple) => {
4922
4924
  if (position === DateRangePosition.START) {
4923
4925
  // If a start date has already been selected
@@ -5015,16 +5017,16 @@ const ChecboxesBox$1 = styled.div `
5015
5017
  `}
5016
5018
  `;
5017
5019
 
5018
- function MultiSelect({ baseContainer, error, fixedWidth = 5, isLabelHidden = false, isLight = false, label, onChange, options,
5020
+ function MultiSelect({ baseContainer, error, fixedWidth, isLabelHidden = false, isLight = false, label, onChange, options,
5019
5021
  // eslint-disable-next-line @typescript-eslint/naming-convention
5020
5022
  searchable = false, ...originalProps }) {
5021
5023
  // eslint-disable-next-line no-null/no-null
5022
5024
  const boxRef = useRef(null);
5023
- const [isOpen, setIsOpen] = useState(false);
5024
- const { forceUpdate } = useForceUpdate();
5025
+ const [isOpen, setIsOpen] = useState(true);
5025
5026
  const controlledError = useMemo(() => normalizeString(error), [error]);
5026
5027
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
5027
5028
  const key = useMemo(() => `${originalProps.name}-${JSON.stringify(originalProps.defaultValue)}`, [originalProps.defaultValue, originalProps.name]);
5029
+ const { forceUpdate } = useForceUpdate();
5028
5030
  const close = useCallback(() => {
5029
5031
  setIsOpen(false);
5030
5032
  }, []);
@@ -5035,46 +5037,51 @@ searchable = false, ...originalProps }) {
5035
5037
  const normalizedNextValue = !nextValue || !nextValue.length ? undefined : nextValue;
5036
5038
  onChange(normalizedNextValue);
5037
5039
  }, [onChange]);
5038
- const open = useCallback(() => {
5039
- setIsOpen(true);
5040
- }, []);
5040
+ const toggle = useCallback((event) => {
5041
+ let targetElement = event.target;
5042
+ if (targetElement.tagName === 'path') {
5043
+ if (targetElement.parentElement) {
5044
+ targetElement = targetElement.parentElement;
5045
+ }
5046
+ }
5047
+ if (targetElement.classList.contains('rs-picker-toggle') ||
5048
+ targetElement.classList.contains('rs-picker-tag-wrapper') ||
5049
+ targetElement.classList.contains('rs-picker-toggle-caret')) {
5050
+ setIsOpen(!isOpen);
5051
+ }
5052
+ }, [isOpen]);
5041
5053
  useClickOutside(boxRef, close, baseContainer);
5042
5054
  useEffect(() => {
5043
5055
  forceUpdate();
5044
5056
  }, [forceUpdate]);
5045
- return (jsxs(Field$2, { children: [jsx(Label, { hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(Box$1, { ref: boxRef, onClick: open, children: boxRef.current && (jsx(StyledTagPicker, { "$fixedWidth": fixedWidth, "$isLight": isLight, container: boxRef.current, data: options, id: originalProps.name, onChange: handleChange, open: isOpen, searchable: searchable, ...originalProps }, key)) }), hasError && jsx(FieldError, { children: controlledError })] }));
5057
+ return (jsxs(Field$2, { children: [jsx(Label, { hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(Box$1, { ref: boxRef, "$isActive": isOpen, "$isLight": isLight, onClick: toggle, children: boxRef.current && (jsx(TagPicker, { container: boxRef.current, data: options, id: originalProps.name, onChange: handleChange, onClick: toggle, open: isOpen, searchable: searchable, ...originalProps }, key)) }), hasError && jsx(FieldError, { children: controlledError })] }));
5046
5058
  }
5047
- // TODO A width seems to be mandatory in rsuite which is a very dirty behavior.
5048
- // We should hack that.
5049
- const StyledTagPicker = styled(TagPicker) `
5050
- border: 0;
5051
- cursor: pointer;
5052
- width: ${p => p.$fixedWidth}px;
5053
-
5054
- > .rs-picker-toggle {
5055
- background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)} !important;
5056
- cursor: inherit;
5057
- }
5058
- `;
5059
5059
  const Box$1 = styled.div `
5060
5060
  position: relative;
5061
+ width: 100%;
5061
5062
 
5062
5063
  > .rs-picker-input {
5064
+ border: solid 1px ${p => (p.$isActive ? p.theme.color.blueGray[100] : p.theme.color.gainsboro)} !important;
5065
+ cursor: pointer;
5066
+ width: 100%;
5067
+
5068
+ :hover {
5069
+ border: solid 1px ${p => p.theme.color.blueYonder[100]} !important;
5070
+ }
5071
+
5072
+ :active,
5073
+ :focus {
5074
+ border: solid 1px ${p => p.theme.color.blueGray[100]} !important;
5075
+ }
5076
+
5063
5077
  > .rs-picker-toggle {
5064
- border: solid 1px ${p => p.theme.color.gainsboro} !important;
5078
+ background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)} !important;
5079
+ border: 0;
5080
+ cursor: inherit;
5065
5081
  font-size: 13px;
5066
5082
  line-height: 1.3846;
5067
5083
  padding: 5px 40px 5px 8px !important;
5068
5084
 
5069
- :hover {
5070
- border: solid 1px ${p => p.theme.color.blueYonder[100]} !important;
5071
- }
5072
-
5073
- :active,
5074
- :focus {
5075
- border: solid 1px ${p => p.theme.color.blueGray[100]} !important;
5076
- }
5077
-
5078
5085
  > .rs-stack {
5079
5086
  > .rs-stack-item {
5080
5087
  > .rs-picker-toggle-placeholder {
@@ -5103,6 +5110,29 @@ const Box$1 = styled.div `
5103
5110
  }
5104
5111
  }
5105
5112
  }
5113
+
5114
+ > .rs-picker-menu {
5115
+ > .rs-picker-check-menu {
5116
+ margin: 0;
5117
+
5118
+ > div[role='option'] {
5119
+ > .rs-check-item {
5120
+ > .rs-checkbox-checker {
5121
+ > label {
5122
+ font-size: 13px;
5123
+ line-height: 1.3846;
5124
+ padding: 8px 12px 8px 38px;
5125
+
5126
+ > .rs-checkbox-wrapper {
5127
+ left: 12px;
5128
+ top: 10px !important;
5129
+ }
5130
+ }
5131
+ }
5132
+ }
5133
+ }
5134
+ }
5135
+ }
5106
5136
  `;
5107
5137
 
5108
5138
  function MultiRadio({ defaultValue, isInline = false, isLabelHidden = false, isLight = false, label, name, onChange, options }) {
@@ -5251,20 +5281,20 @@ searchable = false, ...originalProps }) {
5251
5281
  setIsOpen(false);
5252
5282
  }, []);
5253
5283
  const handleChange = useCallback((nextValue) => {
5254
- if (!onChange) {
5255
- return;
5284
+ close();
5285
+ if (onChange) {
5286
+ const normalizedNextValue = nextValue ?? undefined;
5287
+ onChange(normalizedNextValue);
5256
5288
  }
5257
- const normalizedNextValue = nextValue ?? undefined;
5258
- onChange(normalizedNextValue);
5259
- }, [onChange]);
5260
- const open = useCallback(() => {
5261
- setIsOpen(true);
5262
- }, []);
5289
+ }, [close, onChange]);
5290
+ const toggle = useCallback(() => {
5291
+ setIsOpen(!isOpen);
5292
+ }, [isOpen]);
5263
5293
  useClickOutside(boxRef, close, baseContainer);
5264
5294
  useEffect(() => {
5265
5295
  forceUpdate();
5266
5296
  }, [forceUpdate]);
5267
- return (jsxs(Field$2, { children: [jsx(Label, { hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(Box, { ref: boxRef, onClick: open, children: boxRef.current && (jsx(StyledSelectPicker, { "$isLight": isLight, container: boxRef.current, data: options, id: originalProps.name,
5297
+ return (jsxs(Field$2, { children: [jsx(Label, { hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(Box, { ref: boxRef, onClick: toggle, children: boxRef.current && (jsx(StyledSelectPicker, { "$isLight": isLight, container: boxRef.current, data: options, id: originalProps.name,
5268
5298
  // The `unknown` type from Rsuite library is wrong. It should be inferred from `data` prop type.
5269
5299
  // `onChange: ((value: unknown, event: React.SyntheticEvent<Element, Event>) => void) | undefined`
5270
5300
  onChange: handleChange, open: isOpen, searchable: searchable, ...originalProps }, key)) }), hasError && jsx(FieldError, { children: controlledError })] }));
@@ -5277,8 +5307,11 @@ const StyledSelectPicker = styled(SelectPicker) `
5277
5307
  `;
5278
5308
  const Box = styled.div `
5279
5309
  position: relative;
5310
+ width: 100%;
5280
5311
 
5281
5312
  > .rs-picker-select {
5313
+ width: 100%;
5314
+
5282
5315
  > .rs-picker-toggle {
5283
5316
  border: solid 1px ${p => p.theme.color.gainsboro} !important;
5284
5317
  font-size: 13px;