@ndlib/component-library 0.0.42 → 0.0.44
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/dist/components/composites/Modal/Modal.stories.js +7 -0
- package/dist/components/composites/Modal/index.d.ts +4 -2
- package/dist/components/composites/Modal/index.js +16 -3
- package/dist/components/elements/Button/index.d.ts +1 -1
- package/dist/components/elements/Fields/TextInput/TextInput.stories.d.ts +1 -0
- package/dist/components/elements/Fields/TextInput/TextInput.stories.js +3 -0
- package/dist/components/elements/Fields/TextInput/index.d.ts +2 -0
- package/dist/components/elements/Fields/TextInput/index.js +9 -5
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { StyledElementProps } from '../../../theme';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { ButtonProps } from '../../elements/Button';
|
|
3
4
|
type ModalProps = StyledElementProps<HTMLDivElement, {
|
|
4
5
|
isOpen: boolean;
|
|
5
|
-
close: () => void;
|
|
6
|
+
close: (e: React.MouseEvent) => void;
|
|
6
7
|
heading: string;
|
|
7
8
|
hideHeading?: boolean;
|
|
8
9
|
footer?: React.ReactNode;
|
|
@@ -12,7 +13,8 @@ type ModalProps = StyledElementProps<HTMLDivElement, {
|
|
|
12
13
|
type ModalAction = {
|
|
13
14
|
label: string;
|
|
14
15
|
isPrimary?: boolean;
|
|
15
|
-
|
|
16
|
+
buttonProps?: Partial<ButtonProps>;
|
|
17
|
+
onClick: (e: React.MouseEvent) => void;
|
|
16
18
|
};
|
|
17
19
|
export declare const Modal: React.FC<ModalProps>;
|
|
18
20
|
export {};
|
|
@@ -27,14 +27,27 @@ export const Modal = (_a) => {
|
|
|
27
27
|
const { breakpoint } = useMediaQuery();
|
|
28
28
|
const { modal } = useComponentConfig();
|
|
29
29
|
const theme = useTheme();
|
|
30
|
+
const shouldShowFooter = footer !== undefined || (actions !== undefined && actions.length > 0);
|
|
30
31
|
const modalBody = (_jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION, sx: { my: 0 } }, { children: [!hideHeading && (_jsxs(Row, Object.assign({ justify: "space-between", align: "center", sx: {
|
|
31
32
|
p: 3,
|
|
32
33
|
borderBottom: 'solid 1px',
|
|
33
34
|
borderColor: COLOR.LIGHT_GRAY,
|
|
34
|
-
} }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM, typography: TYPOGRAPHY_TYPE.CONTROL_MEDIUM }, { children: heading })), _jsx(Button, Object.assign({ type: BUTTON_TYPE.TEXT, onClick:
|
|
35
|
+
} }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM, typography: TYPOGRAPHY_TYPE.CONTROL_MEDIUM }, { children: heading })), _jsx(Button, Object.assign({ type: BUTTON_TYPE.TEXT, onClick: (e) => {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
close(e);
|
|
39
|
+
} }, { children: "Close" }))] }))), _jsx(Row, Object.assign({ sx: { p: 3 } }, { children: children })), shouldShowFooter && (_jsxs(Row, Object.assign({ sx: { borderTop: 'solid 1px', borderColor: COLOR.LIGHT_GRAY, p: 3 } }, { children: [footer, actions !== undefined && (_jsx(Row, Object.assign({ sx: { width: '100%', justifyContent: 'flex-end' } }, { children: actions.map((action, index) => (_jsx(Button, Object.assign({ type: action.isPrimary ? BUTTON_TYPE.DEFAULT : BUTTON_TYPE.OUTLINE, onClick: (e) => {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
action.onClick(e);
|
|
43
|
+
}, sx: {
|
|
35
44
|
mr: index < actions.length - 1 ? 1 : 0,
|
|
36
|
-
} }, { children: action.label }), index))) })))] }))] })));
|
|
37
|
-
return (_jsx(ReactModal, Object.assign({ isOpen: isOpen, shouldFocusAfterRender: true, appElement: modal.appElement, onRequestClose:
|
|
45
|
+
} }, action.buttonProps, { children: action.label }), index))) })))] })))] })));
|
|
46
|
+
return (_jsx(ReactModal, Object.assign({ isOpen: isOpen, shouldFocusAfterRender: true, appElement: modal.appElement, onRequestClose: (e) => {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
close(e);
|
|
50
|
+
} }, props, { style: {
|
|
38
51
|
overlay: {
|
|
39
52
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
40
53
|
zIndex: theme.zIndex.MODAL,
|
|
@@ -12,7 +12,7 @@ export declare enum BUTTON_TYPE {
|
|
|
12
12
|
TEXT = "text",
|
|
13
13
|
OUTLINE = "outline"
|
|
14
14
|
}
|
|
15
|
-
type ButtonProps = StyledElementProps<HTMLButtonElement, {
|
|
15
|
+
export type ButtonProps = StyledElementProps<HTMLButtonElement, {
|
|
16
16
|
size?: BUTTON_SIZE;
|
|
17
17
|
type?: BUTTON_TYPE;
|
|
18
18
|
color?: COLOR;
|
|
@@ -30,3 +30,6 @@ export const WithLabel = {
|
|
|
30
30
|
export const Inverted = {
|
|
31
31
|
render: () => (_jsx(Column, Object.assign({ sx: { backgroundColor: COLOR.BLACK, p: 2 } }, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD, sx: { color: COLOR.WHITE } }, { children: size.label })), _jsx(StatefulInput, { inverted: true, size: size.size, leftIcon: SearchIcon, placeholder: "Placeholder", label: "Search", sx: { mt: 2 } })] }))) }))),
|
|
32
32
|
};
|
|
33
|
+
export const Disabled = {
|
|
34
|
+
render: () => (_jsx(Column, Object.assign({ sx: { p: 2 } }, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD, sx: { color: COLOR.WHITE } }, { children: size.label })), _jsx(StatefulInput, { disabled: true, size: size.size, leftIcon: SearchIcon, placeholder: "Placeholder", label: "Search", sx: { mt: 2 } })] }))) }))),
|
|
35
|
+
};
|
|
@@ -23,6 +23,7 @@ export type TextInputProps = StyledElementProps<HTMLInputElement, {
|
|
|
23
23
|
inline?: boolean;
|
|
24
24
|
inverted?: boolean;
|
|
25
25
|
label?: string;
|
|
26
|
+
disabled?: boolean;
|
|
26
27
|
value: string;
|
|
27
28
|
onChange?: (value: string) => void;
|
|
28
29
|
onChangeRaw?: (e: string | React.ChangeEvent) => void;
|
|
@@ -36,6 +37,7 @@ export declare const TextInput: React.ForwardRefExoticComponent<{
|
|
|
36
37
|
inline?: boolean | undefined;
|
|
37
38
|
inverted?: boolean | undefined;
|
|
38
39
|
label?: string | undefined;
|
|
40
|
+
disabled?: boolean | undefined;
|
|
39
41
|
value: string;
|
|
40
42
|
onChange?: ((value: string) => void) | undefined;
|
|
41
43
|
onChangeRaw?: ((e: string | React.ChangeEvent) => void) | undefined;
|
|
@@ -50,7 +50,7 @@ const defaultHeight = {
|
|
|
50
50
|
[INPUT_SIZE.LG]: '3rem',
|
|
51
51
|
};
|
|
52
52
|
export const TextInput = React.forwardRef((_a, ref) => {
|
|
53
|
-
var { value, label, onChange, onChangeRaw, onClick, inline, inverted, size: sizeParam, leftIcon, sx } = _a, rest = __rest(_a, ["value", "label", "onChange", "onChangeRaw", "onClick", "inline", "inverted", "size", "leftIcon", "sx"]);
|
|
53
|
+
var { value, label, onChange, onChangeRaw, onClick, inline, inverted, size: sizeParam, leftIcon, sx, disabled } = _a, rest = __rest(_a, ["value", "label", "onChange", "onChangeRaw", "onClick", "inline", "inverted", "size", "leftIcon", "sx", "disabled"]);
|
|
54
54
|
const id = useUniqueHtmlId('text-input');
|
|
55
55
|
const theme = useTheme();
|
|
56
56
|
const size = sizeParam || INPUT_SIZE.MD;
|
|
@@ -59,9 +59,13 @@ export const TextInput = React.forwardRef((_a, ref) => {
|
|
|
59
59
|
const height = defaultHeight[size];
|
|
60
60
|
const typography = typographyMap[size];
|
|
61
61
|
const typographyStyles = getTypographyStyles(typography);
|
|
62
|
-
const focusStyles =
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const focusStyles = disabled
|
|
63
|
+
? {}
|
|
64
|
+
: {
|
|
65
|
+
boxShadow: inverted
|
|
66
|
+
? theme.boxShadow.INVERTED
|
|
67
|
+
: theme.boxShadow.NORMAL,
|
|
68
|
+
};
|
|
65
69
|
return (_jsxs("div", Object.assign({ ref: ref, onClick: onClick, id: id, sx: Object.assign(Object.assign({ height,
|
|
66
70
|
display, px: paddingX, backgroundColor: inverted ? COLOR.DARK_GRAY : COLOR.WHITE, borderRadius: '4px', flexDirection: 'row', position: 'relative', alignItems: 'center', ':hover': focusStyles, ':focus': focusStyles }, typographyStyles), sx) }, { children: [_jsx("fieldset", Object.assign({ sx: {
|
|
67
71
|
textAlign: 'left',
|
|
@@ -104,7 +108,7 @@ export const TextInput = React.forwardRef((_a, ref) => {
|
|
|
104
108
|
color: inverted ? COLOR.LIGHT_GRAY : COLOR.GRAY,
|
|
105
109
|
}, ':focus': {
|
|
106
110
|
outline: 'none',
|
|
107
|
-
} }) }, rest)), label && (_jsx(Label, Object.assign({ htmlFor: id, typography: labelTypographyMap[size], sx: {
|
|
111
|
+
} }), disabled: disabled }, rest)), label && (_jsx(Label, Object.assign({ htmlFor: id, typography: labelTypographyMap[size], sx: {
|
|
108
112
|
position: 'absolute',
|
|
109
113
|
color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.ND_PROVOST_BLUE,
|
|
110
114
|
left: '0.5rem',
|