@mtes-mct/monitor-ui 6.1.0 → 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 +20 -0
- package/elements/Button.d.ts +5 -3
- package/elements/IconButton.d.ts +6 -4
- package/index.js +48 -18
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
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
|
+
|
|
8
|
+
# [6.1.0](https://github.com/MTES-MCT/monitor-ui/compare/v6.0.1...v6.1.0) (2023-05-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **fields:** delete queryMap and queryUrl props ([5e00cb0](https://github.com/MTES-MCT/monitor-ui/commit/5e00cb0baa8dc6937b44a800e24f61d04a258ab7))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* **fields:** add Icon prop to TextInput ([a885011](https://github.com/MTES-MCT/monitor-ui/commit/a885011f2cd0d09034e9d45a54a356b4ffdd7d6c))
|
|
19
|
+
* **icons:** update and add icons ([efd44f2](https://github.com/MTES-MCT/monitor-ui/commit/efd44f243fa2f2914b1c15a755245c99f2c06a76))
|
|
20
|
+
|
|
1
21
|
## [6.0.1](https://github.com/MTES-MCT/monitor-ui/compare/v6.0.0...v6.0.1) (2023-05-19)
|
|
2
22
|
|
|
3
23
|
|
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 });
|
|
@@ -31804,13 +31822,15 @@ const InputBox = styled.div `
|
|
|
31804
31822
|
|
|
31805
31823
|
function FormikSearch({ name, ...originalProps }) {
|
|
31806
31824
|
const [field, meta, helpers] = useField(name);
|
|
31825
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31807
31826
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31808
31827
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31809
|
-
return jsx(Search, { error:
|
|
31828
|
+
return jsx(Search, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31810
31829
|
}
|
|
31811
31830
|
|
|
31812
31831
|
function FormikCheckbox({ name, ...originalProps }) {
|
|
31813
31832
|
const [field, meta, helpers] = useField(name);
|
|
31833
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31814
31834
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31815
31835
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31816
31836
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
@@ -31822,32 +31842,35 @@ function FormikCheckbox({ name, ...originalProps }) {
|
|
|
31822
31842
|
},
|
|
31823
31843
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31824
31844
|
[]);
|
|
31825
|
-
return jsx(Checkbox, { checked: isChecked, error:
|
|
31845
|
+
return jsx(Checkbox, { checked: isChecked, error: error, name: name, onChange: handleChange, ...originalProps });
|
|
31826
31846
|
}
|
|
31827
31847
|
|
|
31828
31848
|
function FormikCoordinatesInput({ name, ...originalProps }) {
|
|
31829
31849
|
const [field, meta, helpers] = useField(name);
|
|
31830
31850
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31831
31851
|
const defaultValue = useMemo(() => field.value, []);
|
|
31852
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31832
31853
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31833
31854
|
const handleChange = useMemo(() => (nextCoordinates) => helpers.setValue(nextCoordinates), []);
|
|
31834
|
-
return jsx(CoordinatesInput, { defaultValue: defaultValue, error:
|
|
31855
|
+
return jsx(CoordinatesInput, { defaultValue: defaultValue, error: error, onChange: handleChange, ...originalProps });
|
|
31835
31856
|
}
|
|
31836
31857
|
|
|
31837
31858
|
const UntypedDatePicker = DatePicker;
|
|
31838
31859
|
function FormikDatePicker({ name, ...originalProps }) {
|
|
31839
31860
|
const [field, meta, helpers] = useField(name);
|
|
31861
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31840
31862
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31841
31863
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31842
|
-
return jsx(UntypedDatePicker, { defaultValue: field.value, error:
|
|
31864
|
+
return jsx(UntypedDatePicker, { defaultValue: field.value, error: error, onChange: handleChange, ...originalProps });
|
|
31843
31865
|
}
|
|
31844
31866
|
|
|
31845
31867
|
const UntypedDateRangePicker = DateRangePicker;
|
|
31846
31868
|
function FormikDateRangePicker({ name, ...originalProps }) {
|
|
31847
31869
|
const [field, meta, helpers] = useField(name);
|
|
31870
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31848
31871
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31849
31872
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31850
|
-
return
|
|
31873
|
+
return jsx(UntypedDateRangePicker, { defaultValue: field.value, error: error, onChange: handleChange, ...originalProps });
|
|
31851
31874
|
}
|
|
31852
31875
|
|
|
31853
31876
|
function FormikEffect({ onChange }) {
|
|
@@ -31860,58 +31883,65 @@ function FormikEffect({ onChange }) {
|
|
|
31860
31883
|
|
|
31861
31884
|
function FormikMultiCheckbox({ name, ...originalProps }) {
|
|
31862
31885
|
const [field, meta, helpers] = useField(name);
|
|
31886
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31863
31887
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31864
31888
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31865
31889
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31866
|
-
return jsx(MultiCheckbox, { error:
|
|
31890
|
+
return jsx(MultiCheckbox, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31867
31891
|
}
|
|
31868
31892
|
|
|
31869
31893
|
function FormikMultiSelect({ name, ...originalProps }) {
|
|
31870
31894
|
const [field, meta, helpers] = useField(name);
|
|
31895
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31871
31896
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31872
31897
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31873
31898
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31874
|
-
return jsx(MultiSelect, { error:
|
|
31899
|
+
return jsx(MultiSelect, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31875
31900
|
}
|
|
31876
31901
|
|
|
31877
31902
|
function FormikMultiRadio({ name, ...originalProps }) {
|
|
31878
31903
|
const [field, meta, helpers] = useField(name);
|
|
31904
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31879
31905
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31880
31906
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31881
31907
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31882
|
-
return jsx(MultiRadio, { error:
|
|
31908
|
+
return jsx(MultiRadio, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31883
31909
|
}
|
|
31884
31910
|
|
|
31885
31911
|
function FormikNumberInput({ name, ...originalProps }) {
|
|
31886
31912
|
const [field, meta, helpers] = useField(name);
|
|
31913
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31887
31914
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31888
31915
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31889
31916
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31890
|
-
return jsx(NumberInput, { error:
|
|
31917
|
+
return jsx(NumberInput, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31891
31918
|
}
|
|
31892
31919
|
|
|
31893
31920
|
function FormikSelect({ name, ...originalProps }) {
|
|
31894
31921
|
const [field, meta, helpers] = useField(name);
|
|
31922
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31895
31923
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31896
31924
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31897
31925
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31898
|
-
return jsx(Select, { error:
|
|
31926
|
+
return jsx(Select, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31899
31927
|
}
|
|
31900
31928
|
|
|
31901
31929
|
function FormikTextarea({ name, ...originalProps }) {
|
|
31902
31930
|
const [field, meta, helpers] = useField(name);
|
|
31931
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31903
31932
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31904
31933
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31905
31934
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31906
|
-
return jsx(Textarea, { error:
|
|
31935
|
+
return jsx(Textarea, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31907
31936
|
}
|
|
31908
31937
|
|
|
31909
31938
|
function FormikTextInput({ name, ...originalProps }) {
|
|
31910
31939
|
const [field, meta, helpers] = useField(name);
|
|
31940
|
+
const error = meta.touched ? meta.error : undefined;
|
|
31911
31941
|
// We don't want to trigger infinite re-rendering since `helpers.setValue` changes after each rendering
|
|
31912
31942
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31913
31943
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
31914
|
-
return jsx(TextInput, { error:
|
|
31944
|
+
return jsx(TextInput, { error: error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
31915
31945
|
}
|
|
31916
31946
|
|
|
31917
31947
|
function useFieldControl(value, onChange, defaultValueWhenUndefined) {
|