@mtes-mct/monitor-ui 6.1.1 → 6.2.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 +14 -0
- package/elements/Button.d.ts +5 -3
- package/elements/IconButton.d.ts +6 -4
- package/index.js +28 -10
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [6.2.0](https://github.com/MTES-MCT/monitor-ui/compare/v6.1.1...v6.2.0) (2023-05-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **elements:** add withUnpropagatedClick prop to Button & IconButton ([67943f5](https://github.com/MTES-MCT/monitor-ui/commit/67943f5c2bc9e225a13b0185869fef86bebec069))
|
|
7
|
+
|
|
8
|
+
## [6.1.1](https://github.com/MTES-MCT/monitor-ui/compare/v6.1.0...v6.1.1) (2023-05-21)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **formiks:** show error when touched ([f554973](https://github.com/MTES-MCT/monitor-ui/commit/f554973c68901406b08e3adbe37fc49a1407580b))
|
|
14
|
+
|
|
1
15
|
# [6.1.0](https://github.com/MTES-MCT/monitor-ui/compare/v6.0.1...v6.1.0) (2023-05-19)
|
|
2
16
|
|
|
3
17
|
|
package/elements/Button.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type FunctionComponent } from 'react';
|
|
1
2
|
import { Accent, Size } from '../constants';
|
|
2
|
-
import type
|
|
3
|
-
import type { ButtonHTMLAttributes, FunctionComponent } from 'react';
|
|
3
|
+
import { type IconProps } from '../types';
|
|
4
4
|
export type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> & {
|
|
5
5
|
Icon?: FunctionComponent<IconProps> | undefined;
|
|
6
6
|
accent?: Accent | undefined;
|
|
7
7
|
children?: string | undefined;
|
|
8
8
|
isFullWidth?: boolean | undefined;
|
|
9
9
|
size?: Size | undefined;
|
|
10
|
+
/** Prevent onClick event propagation. */
|
|
11
|
+
withUnpropagatedClick?: boolean | undefined;
|
|
10
12
|
};
|
|
11
|
-
export declare function Button({ accent, children, className, Icon, isFullWidth, size, type, ...nativeProps }: ButtonProps): JSX.Element;
|
|
13
|
+
export declare function Button({ accent, children, className, Icon, isFullWidth, onClick, size, type, withUnpropagatedClick, ...nativeProps }: ButtonProps): JSX.Element;
|
|
12
14
|
export declare const PrimaryButton: import("styled-components").StyledComponent<"button", import("styled-components").DefaultTheme, {}, never>;
|
|
13
15
|
export declare const SecondaryButton: import("styled-components").StyledComponent<"button", import("styled-components").DefaultTheme, {}, never>;
|
|
14
16
|
export declare const TertiaryButton: import("styled-components").StyledComponent<"button", import("styled-components").DefaultTheme, {}, never>;
|
package/elements/IconButton.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type FunctionComponent } from 'react';
|
|
1
2
|
import { Accent, Size } from '../constants';
|
|
2
|
-
import type
|
|
3
|
-
import type { ButtonHTMLAttributes, FunctionComponent } from 'react';
|
|
3
|
+
import { type IconProps } from '../types';
|
|
4
4
|
export type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> & {
|
|
5
5
|
Icon: FunctionComponent<IconProps>;
|
|
6
6
|
accent?: Accent | undefined;
|
|
7
7
|
color?: string | undefined;
|
|
8
|
-
/** In pixels, override `size` prop default values */
|
|
8
|
+
/** In pixels, override `size` prop default values. */
|
|
9
9
|
iconSize?: number | undefined;
|
|
10
10
|
size?: Size | undefined;
|
|
11
|
+
/** Prevent onClick event propagation. */
|
|
12
|
+
withUnpropagatedClick?: boolean | undefined;
|
|
11
13
|
};
|
|
12
|
-
export declare function IconButton({ accent, className, color, Icon, iconSize, size, type, ...nativeProps }: IconButtonProps): JSX.Element;
|
|
14
|
+
export declare function IconButton({ accent, className, color, Icon, iconSize, onClick, size, type, withUnpropagatedClick, ...nativeProps }: IconButtonProps): JSX.Element;
|
package/index.js
CHANGED
|
@@ -2598,17 +2598,26 @@ const ICON_SIZE = {
|
|
|
2598
2598
|
[Size.NORMAL]: 20,
|
|
2599
2599
|
[Size.SMALL]: 12
|
|
2600
2600
|
};
|
|
2601
|
-
function Button({ accent = Accent.PRIMARY, children, className, Icon, isFullWidth = false, size = Size.NORMAL, type = 'button', ...nativeProps }) {
|
|
2601
|
+
function Button({ accent = Accent.PRIMARY, children, className, Icon, isFullWidth = false, onClick, size = Size.NORMAL, type = 'button', withUnpropagatedClick = false, ...nativeProps }) {
|
|
2602
|
+
const handleClick = useCallback((event) => {
|
|
2603
|
+
if (withUnpropagatedClick) {
|
|
2604
|
+
stopMouseEventPropagation(event);
|
|
2605
|
+
}
|
|
2606
|
+
if (onClick) {
|
|
2607
|
+
onClick(event);
|
|
2608
|
+
}
|
|
2609
|
+
}, [onClick, withUnpropagatedClick]);
|
|
2602
2610
|
const commonChildren = useMemo(() => (jsxs(Fragment, { children: [Icon && jsx(Icon, { size: ICON_SIZE[size] }), children && jsx(ButtonLabel, { children: children })] })), [children, Icon, size]);
|
|
2603
2611
|
const commonProps = useMemo(() => ({
|
|
2604
2612
|
as: StyledButton$1,
|
|
2605
2613
|
children: commonChildren,
|
|
2606
2614
|
className: classnames('Element-Button', className),
|
|
2607
2615
|
isFullWidth,
|
|
2616
|
+
onClick: handleClick,
|
|
2608
2617
|
size,
|
|
2609
2618
|
type,
|
|
2610
2619
|
...nativeProps
|
|
2611
|
-
}), [className, commonChildren, isFullWidth, nativeProps, size, type]);
|
|
2620
|
+
}), [className, commonChildren, handleClick, isFullWidth, nativeProps, size, type]);
|
|
2612
2621
|
switch (accent) {
|
|
2613
2622
|
case Accent.SECONDARY:
|
|
2614
2623
|
return jsx(SecondaryButton, { ...commonProps });
|
|
@@ -2734,15 +2743,24 @@ const ICON_SIZE_IN_PX = {
|
|
|
2734
2743
|
[Size.NORMAL]: 20,
|
|
2735
2744
|
[Size.SMALL]: 14
|
|
2736
2745
|
};
|
|
2737
|
-
function IconButton({ accent = Accent.PRIMARY, className, color, Icon, iconSize, size = Size.NORMAL, type = 'button', ...nativeProps }) {
|
|
2738
|
-
const
|
|
2746
|
+
function IconButton({ accent = Accent.PRIMARY, className, color, Icon, iconSize, onClick, size = Size.NORMAL, type = 'button', withUnpropagatedClick = false, ...nativeProps }) {
|
|
2747
|
+
const handleClick = useCallback((event) => {
|
|
2748
|
+
if (withUnpropagatedClick) {
|
|
2749
|
+
stopMouseEventPropagation(event);
|
|
2750
|
+
}
|
|
2751
|
+
if (onClick) {
|
|
2752
|
+
onClick(event);
|
|
2753
|
+
}
|
|
2754
|
+
}, [onClick, withUnpropagatedClick]);
|
|
2755
|
+
const commonChildren = useMemo(() => jsx(Icon, { color: color, size: iconSize || ICON_SIZE_IN_PX[size] }), [color, Icon, iconSize, size]);
|
|
2739
2756
|
const commonProps = useMemo(() => ({
|
|
2740
|
-
children,
|
|
2757
|
+
children: commonChildren,
|
|
2741
2758
|
className: classnames('Element-IconButton', className),
|
|
2759
|
+
onClick: handleClick,
|
|
2742
2760
|
size,
|
|
2743
2761
|
type,
|
|
2744
2762
|
...nativeProps
|
|
2745
|
-
}), [
|
|
2763
|
+
}), [className, commonChildren, handleClick, nativeProps, size, type]);
|
|
2746
2764
|
switch (accent) {
|
|
2747
2765
|
case Accent.SECONDARY:
|
|
2748
2766
|
return jsx(SecondaryButton, { as: StyledButton, ...commonProps });
|
|
@@ -21099,7 +21117,7 @@ function CalendarPicker({ isHistorical, isOpen, onChange, value }) {
|
|
|
21099
21117
|
const { forceUpdate } = useForceUpdate();
|
|
21100
21118
|
const utcTodayAsDayjs = useMemo(() => customDayjs().utc().endOf('day'), []);
|
|
21101
21119
|
const controlledValue = useMemo(() => (value ? getLocalizedDayjs(value).toDate() : undefined), [value]);
|
|
21102
|
-
const
|
|
21120
|
+
const shouldDisableDate = useMemo(() => (date) => date && isHistorical ? getUtcizedDayjs(date).isAfter(utcTodayAsDayjs) : false, [isHistorical, utcTodayAsDayjs]);
|
|
21103
21121
|
const handleSelect = useCallback((nextLocalDate) => {
|
|
21104
21122
|
// We utcize the date picked by the user
|
|
21105
21123
|
const nextUtcDateAsDayjs = getUtcizedDayjs(nextLocalDate);
|
|
@@ -21111,7 +21129,7 @@ function CalendarPicker({ isHistorical, isOpen, onChange, value }) {
|
|
|
21111
21129
|
// and can be used as a container for <RsuiteDatePicker />
|
|
21112
21130
|
forceUpdate();
|
|
21113
21131
|
}, [forceUpdate]);
|
|
21114
|
-
return (jsx(Box$b, { ref: boxRef, onClick: stopMouseEventPropagation, children: boxRef.current && (jsx(DatePicker$1, { container: boxRef.current,
|
|
21132
|
+
return (jsx(Box$b, { ref: boxRef, onClick: stopMouseEventPropagation, children: boxRef.current && (jsx(DatePicker$1, { container: boxRef.current, format: "yyyy-MM-dd", locale: RSUITE_CALENDAR_LOCALE, oneTap: true, onSelect: handleSelect, open: isOpen, ranges: [], shouldDisableDate: shouldDisableDate,
|
|
21115
21133
|
// eslint-disable-next-line no-null/no-null
|
|
21116
21134
|
value: controlledValue ?? null })) }));
|
|
21117
21135
|
}
|
|
@@ -21857,7 +21875,7 @@ function RangeCalendarPicker({ defaultValue, isHistorical, isOpen, onChange }) {
|
|
|
21857
21875
|
const { forceUpdate } = useForceUpdate();
|
|
21858
21876
|
const controlledValue = useMemo(() => (defaultValue ? sortDates(defaultValue) : undefined), [defaultValue]);
|
|
21859
21877
|
const utcTodayAsDayjs = useMemo(() => customDayjs().utc().endOf('day'), []);
|
|
21860
|
-
const
|
|
21878
|
+
const shouldDisableDate = useMemo(() => (date) => isHistorical ? getUtcizedDayjs(date).isAfter(utcTodayAsDayjs) : false, [isHistorical, utcTodayAsDayjs]);
|
|
21861
21879
|
const handleSelect = useCallback((nextLocalDate) => {
|
|
21862
21880
|
// We utcize the date picked by the user
|
|
21863
21881
|
const nextUtcDate = getUtcizedDayjs(nextLocalDate).toDate();
|
|
@@ -21879,7 +21897,7 @@ function RangeCalendarPicker({ defaultValue, isHistorical, isOpen, onChange }) {
|
|
|
21879
21897
|
// and can be used as a container for <RsuiteDateRangePicker />
|
|
21880
21898
|
forceUpdate();
|
|
21881
21899
|
}, [forceUpdate]);
|
|
21882
|
-
return (jsx(Box$6, { ref: boxRef, onClick: stopMouseEventPropagation, children: boxRef.current && (jsx(DateRangePicker$1, { container: boxRef.current,
|
|
21900
|
+
return (jsx(Box$6, { ref: boxRef, onClick: stopMouseEventPropagation, children: boxRef.current && (jsx(DateRangePicker$1, { container: boxRef.current, format: "yyyy-MM-dd", locale: RSUITE_CALENDAR_LOCALE, onSelect: handleSelect, open: isOpen, ranges: [], shouldDisableDate: shouldDisableDate,
|
|
21883
21901
|
// `defaultValue` seems to be immediatly cancelled so we come down to using a controlled `value`
|
|
21884
21902
|
// eslint-disable-next-line no-null/no-null
|
|
21885
21903
|
value: controlledValue ?? null })) }));
|