@mtes-mct/monitor-ui 6.1.1 → 6.2.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 +7 -0
- package/elements/Button.d.ts +5 -3
- package/elements/IconButton.d.ts +6 -4
- package/index.js +24 -6
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [6.1.1](https://github.com/MTES-MCT/monitor-ui/compare/v6.1.0...v6.1.1) (2023-05-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **formiks:** show error when touched ([f554973](https://github.com/MTES-MCT/monitor-ui/commit/f554973c68901406b08e3adbe37fc49a1407580b))
|
|
7
|
+
|
|
1
8
|
# [6.1.0](https://github.com/MTES-MCT/monitor-ui/compare/v6.0.1...v6.1.0) (2023-05-19)
|
|
2
9
|
|
|
3
10
|
|
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 });
|