@ndlib/component-library 0.0.36 → 0.0.38
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/EmptyState/EmptyState.stories.d.ts +1 -0
- package/dist/components/composites/EmptyState/EmptyState.stories.js +8 -2
- package/dist/components/composites/EmptyState/EmptyState.test.js +1 -1
- package/dist/components/composites/EmptyState/index.d.ts +1 -0
- package/dist/components/composites/EmptyState/index.js +2 -2
- package/dist/components/composites/Modal/Modal.stories.d.ts +6 -0
- package/dist/components/composites/Modal/Modal.stories.js +33 -0
- package/dist/components/composites/Modal/index.d.ts +17 -0
- package/dist/components/composites/Modal/index.js +52 -0
- package/dist/components/elements/Button/index.d.ts +2 -0
- package/dist/components/elements/Button/index.js +3 -3
- package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.d.ts +1 -0
- package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.js +3 -0
- package/dist/components/elements/Fields/CheckboxGroup/index.d.ts +3 -1
- package/dist/components/elements/Fields/CheckboxGroup/index.js +29 -14
- package/dist/components/elements/Fields/Select/Select.stories.d.ts +1 -0
- package/dist/components/elements/Fields/Select/Select.stories.js +4 -0
- package/dist/components/elements/Fields/Select/index.d.ts +6 -4
- package/dist/components/elements/Fields/Select/index.js +55 -13
- package/dist/components/elements/Fields/TextInput/TextInput.stories.d.ts +1 -0
- package/dist/components/elements/Fields/TextInput/TextInput.stories.js +5 -1
- package/dist/components/elements/Fields/TextInput/index.d.ts +2 -0
- package/dist/components/elements/Fields/TextInput/index.js +41 -10
- package/dist/components/elements/text/ReadMore/index.js +1 -1
- package/dist/components/providers/componentConfig.d.ts +3 -0
- package/dist/components/providers/componentConfig.js +3 -0
- package/dist/components/providers/dialogs.d.ts +9 -0
- package/dist/components/providers/dialogs.js +32 -0
- package/dist/components/providers/media.d.ts +8 -0
- package/dist/components/providers/media.js +43 -0
- package/dist/components/providers/ui.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/theme/custom.d.ts +4 -2
- package/dist/theme/custom.js +2 -0
- package/package.json +3 -1
- package/dist/utils/hooks/useMediaQuery.d.ts +0 -4
- package/dist/utils/hooks/useMediaQuery.js +0 -29
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { EMPTY_STATE_SIZE, EmptyState } from '.';
|
|
3
3
|
import NotInterestedIcon from '@mui/icons-material/NotInterested';
|
|
4
|
+
import { Link } from '../../elements/Link';
|
|
5
|
+
import { FONT_SIZE } from '../../../theme/typography';
|
|
4
6
|
const meta = {
|
|
5
7
|
title: 'Composites/EmptyState',
|
|
6
8
|
component: EmptyState,
|
|
@@ -16,7 +18,11 @@ export const Small = {
|
|
|
16
18
|
args: {},
|
|
17
19
|
};
|
|
18
20
|
export const CustomMessage = {
|
|
19
|
-
render: () => _jsx(EmptyState, {
|
|
21
|
+
render: () => _jsx(EmptyState, { children: "Custom message" }),
|
|
22
|
+
args: {},
|
|
23
|
+
};
|
|
24
|
+
export const JsxMessage = {
|
|
25
|
+
render: () => (_jsxs(EmptyState, { children: ["Something is wrong.", ' ', _jsx(Link, Object.assign({ to: "/", sx: { fontSize: FONT_SIZE.MD } }, { children: "Click here to fix." }))] })),
|
|
20
26
|
args: {},
|
|
21
27
|
};
|
|
22
28
|
export const CustomIcon = {
|
|
@@ -6,7 +6,7 @@ const MOCK_ICON_TEST_ID = 'mock-icon';
|
|
|
6
6
|
const MockIcon = () => _jsx("div", { "data-testid": MOCK_ICON_TEST_ID });
|
|
7
7
|
describe('EmptyState', () => {
|
|
8
8
|
it('renders passed message', () => {
|
|
9
|
-
const { getByText } = render(_jsx(EmptyState, {
|
|
9
|
+
const { getByText } = render(_jsx(EmptyState, { children: TEST_MESSAGE }));
|
|
10
10
|
expect(getByText(TEST_MESSAGE)).toBeDefined();
|
|
11
11
|
});
|
|
12
12
|
it('renders default message if no message passed', () => {
|
|
@@ -26,7 +26,7 @@ export var EMPTY_STATE_SIZE;
|
|
|
26
26
|
})(EMPTY_STATE_SIZE || (EMPTY_STATE_SIZE = {}));
|
|
27
27
|
export const DEFAULT_MESSAGE = 'No results found.';
|
|
28
28
|
export const EmptyState = (_a) => {
|
|
29
|
-
var { icon,
|
|
29
|
+
var { omitIcon, icon, children, size: sizeProp, sx } = _a, rest = __rest(_a, ["omitIcon", "icon", "children", "size", "sx"]);
|
|
30
30
|
const size = sizeProp || EMPTY_STATE_SIZE.LG;
|
|
31
|
-
return (_jsxs(Column, Object.assign({ sx: Object.assign({ width: '100%', alignItems: 'center', justifyContent: 'center', mt: size === EMPTY_STATE_SIZE.SM ? 3 : 5 }, sx) }, rest, { children: [_jsx(Row, { children: _jsx(Icon, { icon: icon || SearchOffIcon, size: size === EMPTY_STATE_SIZE.SM ? FONT_SIZE.ML : FONT_SIZE.XL, color: COLOR.GRAY }) }), _jsx(Row, Object.assign({ sx: { mt: size === EMPTY_STATE_SIZE.SM ? 0 : 1 } }, { children: _jsx(Paragraph, Object.assign({ sx: { color: COLOR.GRAY }, size: size === EMPTY_STATE_SIZE.SM ? PARAGRAPH_SIZE.MD : PARAGRAPH_SIZE.LG }, { children:
|
|
31
|
+
return (_jsxs(Column, Object.assign({ sx: Object.assign({ width: '100%', alignItems: 'center', justifyContent: 'center', mt: size === EMPTY_STATE_SIZE.SM ? 3 : 5 }, sx) }, rest, { children: [_jsx(Row, { children: omitIcon ? null : (_jsx(Icon, { icon: icon || SearchOffIcon, size: size === EMPTY_STATE_SIZE.SM ? FONT_SIZE.ML : FONT_SIZE.XL, color: COLOR.GRAY })) }), _jsx(Row, Object.assign({ sx: { mt: size === EMPTY_STATE_SIZE.SM ? 0 : 1 } }, { children: _jsx(Paragraph, Object.assign({ sx: { color: COLOR.GRAY }, size: size === EMPTY_STATE_SIZE.SM ? PARAGRAPH_SIZE.MD : PARAGRAPH_SIZE.LG }, { children: children || DEFAULT_MESSAGE })) }))] })));
|
|
32
32
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Modal } from '.';
|
|
3
|
+
import { Button } from '../../elements/Button';
|
|
4
|
+
import { Paragraph } from '../../elements/text/Paragraph';
|
|
5
|
+
import { useDialog } from '../../providers/dialogs';
|
|
6
|
+
import { useTheme } from '../../../theme';
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Composites/Modal',
|
|
9
|
+
component: Modal,
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
const ModalExample = () => {
|
|
14
|
+
const modalId = 'modal-example';
|
|
15
|
+
const { open, close, state } = useDialog(modalId);
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ onClick: open, sx: { position: 'relative', zIndex: theme.zIndex.DROPDOWN } }, { children: "Open Modal" })), _jsx(Modal, Object.assign({ isOpen: state.isOpen, heading: "Heading", close: close, actions: [
|
|
18
|
+
{
|
|
19
|
+
label: 'Secondary',
|
|
20
|
+
isPrimary: false,
|
|
21
|
+
onClick: () => { },
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'Primary',
|
|
25
|
+
isPrimary: true,
|
|
26
|
+
onClick: () => { },
|
|
27
|
+
},
|
|
28
|
+
] }, { children: _jsx(Paragraph, { children: "Modal body goes here" }) }))] }));
|
|
29
|
+
};
|
|
30
|
+
export const Default = {
|
|
31
|
+
render: () => _jsx(ModalExample, {}),
|
|
32
|
+
args: {},
|
|
33
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StyledElementProps } from '../../../theme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type ModalProps = StyledElementProps<HTMLDivElement, {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
close: () => void;
|
|
6
|
+
heading: string;
|
|
7
|
+
hideHeading?: boolean;
|
|
8
|
+
footer?: React.ReactNode;
|
|
9
|
+
actions?: ModalAction[];
|
|
10
|
+
}>;
|
|
11
|
+
type ModalAction = {
|
|
12
|
+
label: string;
|
|
13
|
+
isPrimary?: boolean;
|
|
14
|
+
onClick: () => void;
|
|
15
|
+
};
|
|
16
|
+
export declare const Modal: React.FC<ModalProps>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import _ReactModal from 'react-modal';
|
|
14
|
+
import { importedDefaultComponentShim } from '../../../utils/misc';
|
|
15
|
+
import { useTheme } from '../../../theme';
|
|
16
|
+
import { GROUP_TYPE, Group } from '../../elements/Group';
|
|
17
|
+
import { Row } from '../../elements/layout/Row';
|
|
18
|
+
import { HEADING_SIZE, Heading } from '../../elements/text/Heading';
|
|
19
|
+
import { BUTTON_TYPE, Button } from '../../elements/Button';
|
|
20
|
+
import { COLOR } from '../../../theme/colors';
|
|
21
|
+
import { TYPOGRAPHY_TYPE } from '../../../theme/typography';
|
|
22
|
+
import { useMediaQuery } from '../../providers/media';
|
|
23
|
+
import { useComponentConfig } from '../../providers/componentConfig';
|
|
24
|
+
const ReactModal = importedDefaultComponentShim(_ReactModal);
|
|
25
|
+
export const Modal = (_a) => {
|
|
26
|
+
var { children, heading, hideHeading, isOpen, footer, actions, close } = _a, props = __rest(_a, ["children", "heading", "hideHeading", "isOpen", "footer", "actions", "close"]);
|
|
27
|
+
const { breakpoint } = useMediaQuery();
|
|
28
|
+
const { modal } = useComponentConfig();
|
|
29
|
+
const theme = useTheme();
|
|
30
|
+
return (_jsx(ReactModal, Object.assign({ isOpen: isOpen, shouldFocusAfterRender: true, appElement: modal.appElement, onRequestClose: close }, props, { style: {
|
|
31
|
+
overlay: {
|
|
32
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
33
|
+
zIndex: theme.zIndex.MODAL,
|
|
34
|
+
},
|
|
35
|
+
content: {
|
|
36
|
+
padding: 0,
|
|
37
|
+
minWidth: breakpoint === 0 ? 'calc(100% - 1rem)' : '500px',
|
|
38
|
+
top: '50%',
|
|
39
|
+
left: '50%',
|
|
40
|
+
right: 'auto',
|
|
41
|
+
bottom: 'auto',
|
|
42
|
+
marginRight: '-50%',
|
|
43
|
+
transform: 'translate(-50%, -50%)',
|
|
44
|
+
},
|
|
45
|
+
} }, { children: _jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION, sx: { my: 0 } }, { children: [!hideHeading && (_jsxs(Row, Object.assign({ justify: "space-between", align: "center", sx: {
|
|
46
|
+
p: 3,
|
|
47
|
+
borderBottom: 'solid 1px',
|
|
48
|
+
borderColor: COLOR.LIGHT_GRAY,
|
|
49
|
+
} }, { 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: close }, { children: "Close" }))] }))), _jsx(Row, Object.assign({ sx: { p: 3 } }, { children: children })), _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: action.onClick, sx: {
|
|
50
|
+
mr: index < actions.length - 1 ? 1 : 0,
|
|
51
|
+
} }, { children: action.label }), index))) })))] }))] })) })));
|
|
52
|
+
};
|
|
@@ -24,6 +24,7 @@ type ButtonProps = StyledElementProps<HTMLButtonElement, {
|
|
|
24
24
|
accessibleLabel?: string;
|
|
25
25
|
loading?: boolean;
|
|
26
26
|
disabled?: boolean;
|
|
27
|
+
disableFocusStyles?: boolean;
|
|
27
28
|
}>;
|
|
28
29
|
export declare const Button: React.ForwardRefExoticComponent<{
|
|
29
30
|
sx?: import("../../../theme").StylesProp | undefined;
|
|
@@ -40,6 +41,7 @@ export declare const Button: React.ForwardRefExoticComponent<{
|
|
|
40
41
|
accessibleLabel?: string | undefined;
|
|
41
42
|
loading?: boolean | undefined;
|
|
42
43
|
disabled?: boolean | undefined;
|
|
44
|
+
disableFocusStyles?: boolean | undefined;
|
|
43
45
|
} & {
|
|
44
46
|
htmlFor?: string | undefined;
|
|
45
47
|
} & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -52,7 +52,7 @@ export var BUTTON_TYPE;
|
|
|
52
52
|
// ARROW
|
|
53
53
|
})(BUTTON_TYPE || (BUTTON_TYPE = {}));
|
|
54
54
|
export const Button = React.forwardRef((_a, ref) => {
|
|
55
|
-
var { size: sizeParam, type: typeParam, color, customColor, textColor: textColorParam, primaryIcon, leftIcon, rightIcon, disabled: disabledParam, children, sx, loading } = _a, rest = __rest(_a, ["size", "type", "color", "customColor", "textColor", "primaryIcon", "leftIcon", "rightIcon", "disabled", "children", "sx", "loading"]);
|
|
55
|
+
var { size: sizeParam, type: typeParam, color, customColor, textColor: textColorParam, primaryIcon, leftIcon, rightIcon, disabled: disabledParam, children, sx, loading, disableFocusStyles } = _a, rest = __rest(_a, ["size", "type", "color", "customColor", "textColor", "primaryIcon", "leftIcon", "rightIcon", "disabled", "children", "sx", "loading", "disableFocusStyles"]);
|
|
56
56
|
const disabled = disabledParam || loading;
|
|
57
57
|
const theme = useTheme();
|
|
58
58
|
const { flagInDevelopment } = useEnvironment();
|
|
@@ -88,7 +88,7 @@ export const Button = React.forwardRef((_a, ref) => {
|
|
|
88
88
|
}
|
|
89
89
|
if (type === BUTTON_TYPE.OUTLINE) {
|
|
90
90
|
bg = COLOR.BACKGROUND;
|
|
91
|
-
textColor = color || COLOR.
|
|
91
|
+
textColor = color || COLOR.TEXT;
|
|
92
92
|
borderColor = textColor;
|
|
93
93
|
}
|
|
94
94
|
if (textColorParam) {
|
|
@@ -126,7 +126,7 @@ export const Button = React.forwardRef((_a, ref) => {
|
|
|
126
126
|
: undefined;
|
|
127
127
|
return (_jsxs("button", Object.assign({ ref: ref, tabIndex: disabled ? -1 : 0, disabled: disabled, css: {
|
|
128
128
|
backgroundColor: customColor,
|
|
129
|
-
}, sx: Object.assign(Object.assign({ cursor, bg: customColor ? undefined : bg, color: textColor, px: paddingX, width: width, height: height, border: 'solid 1px', borderRadius: '4px', borderColor, display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', ':hover': hoverStyles, ':focus': hoverStyles }, typographyStyles), sx) }, rest, { children: [leftIcon && (_jsx(Icon, { icon: leftIcon, size: typographyStyles.fontSize, sx: { mr: iconMargin[size] }, color: textColor })), _jsx("div", Object.assign({ css: {
|
|
129
|
+
}, sx: Object.assign(Object.assign({ cursor, bg: customColor ? undefined : bg, color: textColor, px: paddingX, width: width, height: height, border: 'solid 1px', borderRadius: '4px', borderColor, display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', ':hover': !disableFocusStyles ? hoverStyles : {}, ':focus': !disableFocusStyles ? hoverStyles : {} }, typographyStyles), sx) }, rest, { children: [leftIcon && (_jsx(Icon, { icon: leftIcon, size: typographyStyles.fontSize, sx: { mr: iconMargin[size] }, color: textColor })), _jsx("div", Object.assign({ css: {
|
|
130
130
|
flexGrow: 1,
|
|
131
131
|
justifyContent: 'flex-start',
|
|
132
132
|
textOverflow: 'ellipsis',
|
|
@@ -21,3 +21,6 @@ const StatefulCheckboxGroup = (props) => {
|
|
|
21
21
|
export const Default = {
|
|
22
22
|
render: () => (_jsx(Row, { children: _jsx(StatefulCheckboxGroup, {}) })),
|
|
23
23
|
};
|
|
24
|
+
export const Columns = {
|
|
25
|
+
render: () => (_jsx(Row, { children: _jsx(StatefulCheckboxGroup, { columns: 2 }) })),
|
|
26
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { StyledElementProps } from '../../../../theme';
|
|
2
|
+
import { StyledElementProps, StylesProp } from '../../../../theme';
|
|
3
3
|
import { Key } from '../option';
|
|
4
4
|
type Option = {
|
|
5
5
|
value: Key;
|
|
@@ -9,6 +9,8 @@ type CheckboxGroupProps = StyledElementProps<HTMLDivElement, {
|
|
|
9
9
|
onChange: (value: Set<Key>) => void;
|
|
10
10
|
options: Option[];
|
|
11
11
|
checkedOptions?: Set<Key>;
|
|
12
|
+
columnStyles: StylesProp;
|
|
13
|
+
columns?: number;
|
|
12
14
|
}, string>;
|
|
13
15
|
export declare const CheckboxGroup: React.FC<CheckboxGroupProps>;
|
|
14
16
|
export {};
|
|
@@ -10,6 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo } from 'react';
|
|
13
14
|
import { Row } from '../../layout/Row';
|
|
14
15
|
import { Checkbox } from '../Checkbox';
|
|
15
16
|
import { Label } from '../../text/Label';
|
|
@@ -18,18 +19,32 @@ import { GROUP_TYPE } from '../../Group';
|
|
|
18
19
|
import { Column } from '../../layout/Column';
|
|
19
20
|
import { TYPOGRAPHY_TYPE, getTypographyStyles, } from '../../../../theme/typography';
|
|
20
21
|
export const CheckboxGroup = (_a) => {
|
|
21
|
-
var { options, checkedOptions, onChange } = _a, rest = __rest(_a, ["options", "checkedOptions", "onChange"]);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
var { options, checkedOptions, columns: columnsProp, columnStyles, onChange } = _a, rest = __rest(_a, ["options", "checkedOptions", "columns", "columnStyles", "onChange"]);
|
|
23
|
+
const columns = columnsProp || 1;
|
|
24
|
+
const optionsByColumn = useMemo(() => {
|
|
25
|
+
// place first i/n items into first column, next i/n items into second column, etc.
|
|
26
|
+
const optionsByColumn = [];
|
|
27
|
+
for (let i = 0; i < options.length; i++) {
|
|
28
|
+
const maxPerColumn = Math.ceil(options.length / columns);
|
|
29
|
+
const columnIndex = Math.floor(i / maxPerColumn);
|
|
30
|
+
if (optionsByColumn[columnIndex] === undefined) {
|
|
31
|
+
optionsByColumn[columnIndex] = [];
|
|
32
|
+
}
|
|
33
|
+
optionsByColumn[columnIndex].push(options[i]);
|
|
34
|
+
}
|
|
35
|
+
return optionsByColumn;
|
|
36
|
+
}, [options, columns]);
|
|
37
|
+
return (_jsx(Row, Object.assign({}, rest, { children: optionsByColumn.map((options, index) => (_jsx(Column, Object.assign({ grow: 1, sx: Object.assign({ mr: 4 }, columnStyles) }, { children: options.map((option) => (_jsx(Group, Object.assign({ type: GROUP_TYPE.RAW }, { children: ({ labelTargetId }) => (_jsxs(Row, Object.assign({ sx: {
|
|
38
|
+
mb: 3,
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
} }, { children: [_jsx(Checkbox, { onChange: (checked) => {
|
|
41
|
+
const updatedSet = new Set(checkedOptions || []);
|
|
42
|
+
if (checked) {
|
|
43
|
+
updatedSet.add(option.value);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
updatedSet.delete(option.value);
|
|
47
|
+
}
|
|
48
|
+
onChange(updatedSet);
|
|
49
|
+
}, checked: !!(checkedOptions === null || checkedOptions === void 0 ? void 0 : checkedOptions.has(option.value)), id: labelTargetId, sx: { mr: 2 } }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM)) }, { children: option.label }))] }))) }), option.value))) }), index))) })));
|
|
35
50
|
};
|
|
@@ -6,6 +6,7 @@ import { useState } from 'react';
|
|
|
6
6
|
import { Column } from '../../layout/Column';
|
|
7
7
|
import { Group } from '../../Group';
|
|
8
8
|
import { Heading, HEADING_SIZE } from '../../text/Heading';
|
|
9
|
+
import { COLOR } from '../../../../theme/colors';
|
|
9
10
|
const meta = {
|
|
10
11
|
title: 'Elements/Fields/Select',
|
|
11
12
|
component: Select,
|
|
@@ -33,3 +34,6 @@ export const Default = {
|
|
|
33
34
|
export const WithLabel = {
|
|
34
35
|
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulSelect, { size: size.size, leftIcon: AppleIcon, sx: { mt: 2 }, label: "Fruit" })] }))) })),
|
|
35
36
|
};
|
|
37
|
+
export const InvertedColors = {
|
|
38
|
+
render: () => (_jsx(Column, Object.assign({ sx: { backgroundColor: COLOR.BLACK, p: 4 } }, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD, sx: { color: COLOR.WHITE } }, { children: size.label })), _jsx(StatefulSelect, { size: size.size, leftIcon: AppleIcon, sx: { mt: 2 }, inverted: true, label: "Fruit" })] }))) }))),
|
|
39
|
+
};
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { StyledElementProps } from '../../../../theme';
|
|
3
4
|
import { INPUT_SIZE } from '../TextInput';
|
|
4
5
|
import { BasicOption, Key, RenderOption, RenderOptionLabel } from '../option';
|
|
5
6
|
type SelectProps<Value extends Key, Option extends BasicOption<Value>> = StyledElementProps<HTMLSelectElement, {
|
|
6
|
-
placeholder
|
|
7
|
+
placeholder?: string;
|
|
7
8
|
size?: INPUT_SIZE;
|
|
8
9
|
leftIcon?: React.FC<any>;
|
|
9
10
|
value: Value;
|
|
10
11
|
label?: string;
|
|
12
|
+
inverted?: boolean;
|
|
11
13
|
onSelectOption: (value: Value) => void;
|
|
12
14
|
options: Option[];
|
|
13
|
-
renderOption
|
|
14
|
-
renderOptionLabel
|
|
15
|
+
renderOption?: RenderOption<Value, Option>;
|
|
16
|
+
renderOptionLabel?: RenderOptionLabel<Option>;
|
|
15
17
|
}, string>;
|
|
16
|
-
export declare function Select<Value extends Key, Option extends BasicOption<Value>>({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, renderOptionLabel: renderOptionLabelParam, sx, }: SelectProps<Value, Option>):
|
|
18
|
+
export declare function Select<Value extends Key, Option extends BasicOption<Value>>({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, inverted, renderOptionLabel: renderOptionLabelParam, sx, }: SelectProps<Value, Option>): React.JSX.Element;
|
|
17
19
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
2
|
+
/** @jsxImportSource theme-ui */
|
|
2
3
|
import { useMemo, useState } from 'react';
|
|
3
4
|
import _ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
|
|
4
5
|
import { useFloating, size as sizeMiddleware, offset, autoPlacement, } from '@floating-ui/react';
|
|
@@ -30,7 +31,7 @@ const buttonSizeMap = {
|
|
|
30
31
|
[INPUT_SIZE.LG]: BUTTON_SIZE.LG,
|
|
31
32
|
};
|
|
32
33
|
const DEFAULT_WIDTH = '16rem';
|
|
33
|
-
export function Select({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, renderOptionLabel: renderOptionLabelParam, sx, }) {
|
|
34
|
+
export function Select({ size: sizeParam, placeholder, leftIcon, value, label, onSelectOption, options, renderOption, inverted, renderOptionLabel: renderOptionLabelParam, sx, }) {
|
|
34
35
|
const theme = useTheme();
|
|
35
36
|
const listboxId = useUniqueHtmlId('select-list-box');
|
|
36
37
|
const inputId = useUniqueHtmlId('select-input');
|
|
@@ -116,16 +117,56 @@ export function Select({ size: sizeParam, placeholder, leftIcon, value, label, o
|
|
|
116
117
|
const typography = typographyMap[size];
|
|
117
118
|
const typographyStyles = getTypographyStyles(typography);
|
|
118
119
|
const renderOptionLabel = renderOptionLabelParam || defaultRenderOptionLabel;
|
|
119
|
-
|
|
120
|
+
const focusStyles = {
|
|
121
|
+
boxShadow: inverted ? theme.boxShadow.INVERTED : theme.boxShadow.NORMAL,
|
|
122
|
+
};
|
|
123
|
+
return (_jsxs(Box, Object.assign({ sx: {
|
|
124
|
+
width: DEFAULT_WIDTH,
|
|
125
|
+
position: 'relative',
|
|
126
|
+
borderRadius: '4px',
|
|
127
|
+
backgroundColor: inverted ? COLOR.DARK_GRAY : COLOR.WHITE,
|
|
128
|
+
':hover fieldset': focusStyles,
|
|
129
|
+
':focus fieldset': focusStyles,
|
|
130
|
+
} }, { children: [_jsx("fieldset", Object.assign({ sx: {
|
|
131
|
+
textAlign: 'left',
|
|
132
|
+
position: 'absolute',
|
|
133
|
+
inset: '-5px 0px 0px 0px',
|
|
134
|
+
margin: '0px',
|
|
135
|
+
padding: '0px 0.5rem',
|
|
136
|
+
pointerEvents: 'none',
|
|
137
|
+
borderRadius: 'inherit',
|
|
138
|
+
borderStyle: 'solid',
|
|
139
|
+
borderWidth: '1px',
|
|
140
|
+
overflow: 'hidden',
|
|
141
|
+
minWidth: '0%',
|
|
142
|
+
borderColor: inverted ? COLOR.GRAY : COLOR.LIGHT_GRAY,
|
|
143
|
+
zIndex: theme.zIndex.LABEL,
|
|
144
|
+
} }, { children: _jsx("legend", Object.assign({ style: {
|
|
145
|
+
width: 'auto',
|
|
146
|
+
float: 'unset',
|
|
147
|
+
overflow: 'hidden',
|
|
148
|
+
position: 'relative',
|
|
149
|
+
display: 'block',
|
|
150
|
+
padding: '0',
|
|
151
|
+
height: '8px',
|
|
152
|
+
fontSize: '0.75em',
|
|
153
|
+
visibility: 'hidden',
|
|
154
|
+
whiteSpace: 'nowrap',
|
|
155
|
+
} }, { children: label && (_jsx(Label, Object.assign({ standalone: true, sx: {
|
|
156
|
+
px: 1,
|
|
157
|
+
position: 'relative',
|
|
158
|
+
display: 'inline-flex',
|
|
159
|
+
opacity: '0',
|
|
160
|
+
visibility: 'hidden',
|
|
161
|
+
}, typography: labelTypographyMap[size] }, { children: label }))) })) })), _jsx(Label, Object.assign({ htmlFor: inputId, typography: labelTypographyMap[size], sx: {
|
|
120
162
|
position: 'absolute',
|
|
121
|
-
color: COLOR.ND_PROVOST_BLUE,
|
|
122
|
-
backgroundColor: COLOR.WHITE,
|
|
123
163
|
left: '0.5rem',
|
|
124
164
|
lineHeight: 1,
|
|
125
165
|
zIndex: theme.zIndex.LABEL,
|
|
126
|
-
|
|
166
|
+
color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.PRIMARY,
|
|
167
|
+
px: 1,
|
|
127
168
|
top: labelOffsetMap[size],
|
|
128
|
-
} }, { children: label })), _jsx(Button, Object.assign({ ref: refs.setReference,
|
|
169
|
+
} }, { children: label })), _jsx(Button, Object.assign({ ref: refs.setReference, disableFocusStyles: true,
|
|
129
170
|
// A11y attributes
|
|
130
171
|
role: "combobox", "aria-controls": listboxId, "aria-expanded": isOpen, "aria-autocomplete": "none", "aria-activedescendant": isOpen && stagedOptionValue
|
|
131
172
|
? getOptionId(stagedOptionValue)
|
|
@@ -138,14 +179,15 @@ export function Select({ size: sizeParam, placeholder, leftIcon, value, label, o
|
|
|
138
179
|
else {
|
|
139
180
|
close();
|
|
140
181
|
}
|
|
141
|
-
}, sx: Object.assign(Object.assign({ height, width:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (option) => {
|
|
182
|
+
}, color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.TEXT, sx: Object.assign(Object.assign({ height, width: '100%', border: 'solid 0px',
|
|
183
|
+
// borderColor: COLOR.GRAY,
|
|
184
|
+
// borderRadius: '4px',
|
|
185
|
+
flexDirection: 'row', alignItems: 'center', position: 'relative', zIndex: theme.zIndex.NORMAL, background: 'none' }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (option) => {
|
|
146
186
|
onSelectOption && onSelectOption(option.value);
|
|
147
187
|
close();
|
|
148
188
|
}, ref: refs.setFloating, renderOption: renderOption, sx: {
|
|
149
189
|
zIndex: theme.zIndex.DROPDOWN,
|
|
150
|
-
}, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), {
|
|
190
|
+
}, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { boxShadow: inverted
|
|
191
|
+
? theme.boxShadow.INVERTED
|
|
192
|
+
: theme.boxShadow.NORMAL }) }))] })));
|
|
151
193
|
}
|
|
@@ -5,6 +5,7 @@ import { useState } from 'react';
|
|
|
5
5
|
import { Column } from '../../layout/Column';
|
|
6
6
|
import { Group } from '../../Group';
|
|
7
7
|
import { Heading, HEADING_SIZE } from '../../text/Heading';
|
|
8
|
+
import { COLOR } from '../../../../theme/colors';
|
|
8
9
|
const meta = {
|
|
9
10
|
title: 'Elements/Fields/TextInput',
|
|
10
11
|
component: TextInput,
|
|
@@ -24,5 +25,8 @@ export const Default = {
|
|
|
24
25
|
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, placeholder: "Placeholder", sx: { mt: 2 } })] }))) })),
|
|
25
26
|
};
|
|
26
27
|
export const WithLabel = {
|
|
27
|
-
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, label: "Search", sx: { mt: 2 } })] }))) })),
|
|
28
|
+
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(StatefulInput, { size: size.size, leftIcon: SearchIcon, label: "Search", placeholder: "Placeholder", sx: { mt: 2 } })] }))) })),
|
|
29
|
+
};
|
|
30
|
+
export const Inverted = {
|
|
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, { size: size.size, leftIcon: SearchIcon, placeholder: "Placeholder", label: "Search", inverted: true, sx: { mt: 2 } })] }))) }))),
|
|
28
32
|
};
|
|
@@ -21,6 +21,7 @@ export type TextInputProps = StyledElementProps<HTMLInputElement, {
|
|
|
21
21
|
size?: INPUT_SIZE;
|
|
22
22
|
leftIcon?: React.FC<any>;
|
|
23
23
|
inline?: boolean;
|
|
24
|
+
inverted?: boolean;
|
|
24
25
|
label?: string;
|
|
25
26
|
value: string;
|
|
26
27
|
onChange?: (value: string) => void;
|
|
@@ -33,6 +34,7 @@ export declare const TextInput: React.ForwardRefExoticComponent<{
|
|
|
33
34
|
size?: INPUT_SIZE | undefined;
|
|
34
35
|
leftIcon?: React.FC<any> | undefined;
|
|
35
36
|
inline?: boolean | undefined;
|
|
37
|
+
inverted?: boolean | undefined;
|
|
36
38
|
label?: string | undefined;
|
|
37
39
|
value: string;
|
|
38
40
|
onChange?: ((value: string) => 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, size: sizeParam, leftIcon, sx } = _a, rest = __rest(_a, ["value", "label", "onChange", "onChangeRaw", "onClick", "inline", "size", "leftIcon", "sx"]);
|
|
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"]);
|
|
54
54
|
const id = useUniqueHtmlId('text-input');
|
|
55
55
|
const theme = useTheme();
|
|
56
56
|
const size = sizeParam || INPUT_SIZE.MD;
|
|
@@ -59,27 +59,58 @@ 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
|
+
boxShadow: inverted ? theme.boxShadow.INVERTED : theme.boxShadow.NORMAL,
|
|
64
|
+
};
|
|
62
65
|
return (_jsxs("div", Object.assign({ ref: ref, onClick: onClick, id: id, sx: Object.assign(Object.assign({ height,
|
|
63
|
-
display, px: paddingX,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
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
|
+
textAlign: 'left',
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
inset: '-5px 0px 0px 0px',
|
|
70
|
+
margin: '0px',
|
|
71
|
+
padding: '0px 0.5rem',
|
|
72
|
+
pointerEvents: 'none',
|
|
73
|
+
borderRadius: 'inherit',
|
|
74
|
+
borderStyle: 'solid',
|
|
75
|
+
borderWidth: '1px',
|
|
76
|
+
overflow: 'hidden',
|
|
77
|
+
minWidth: '0%',
|
|
78
|
+
borderColor: inverted ? COLOR.GRAY : COLOR.LIGHT_GRAY,
|
|
79
|
+
zIndex: theme.zIndex.LABEL,
|
|
80
|
+
}, "aria-ignore": true }, { children: _jsx("legend", Object.assign({ style: {
|
|
81
|
+
width: 'auto',
|
|
82
|
+
float: 'unset',
|
|
83
|
+
overflow: 'hidden',
|
|
84
|
+
position: 'relative',
|
|
85
|
+
display: 'block',
|
|
86
|
+
padding: '0',
|
|
87
|
+
height: '8px',
|
|
88
|
+
fontSize: '0.75em',
|
|
89
|
+
visibility: 'hidden',
|
|
90
|
+
whiteSpace: 'nowrap',
|
|
91
|
+
} }, { children: label && (_jsx(Label, Object.assign({ standalone: true, "aria-hidden": "true", sx: {
|
|
92
|
+
px: 1,
|
|
93
|
+
position: 'relative',
|
|
94
|
+
display: 'inline-flex',
|
|
95
|
+
opacity: '0',
|
|
96
|
+
visibility: 'hidden',
|
|
97
|
+
}, typography: labelTypographyMap[size] }, { children: label }))) })) })), leftIcon && (_jsx(Icon, { icon: leftIcon, color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.TEXT, sx: {
|
|
68
98
|
mr: 2,
|
|
69
99
|
fontSize: getIconSize(typographyStyles.fontSize),
|
|
70
100
|
} })), _jsx("input", Object.assign({ value: value, onChange: (event) => {
|
|
71
101
|
onChange && onChange(event.target.value);
|
|
72
102
|
onChangeRaw && onChangeRaw(event);
|
|
73
|
-
}, sx: Object.assign(Object.assign({ px: 0, py: 0, width: '100%', border: 'none' }, typographyStyles), { '
|
|
103
|
+
}, sx: Object.assign(Object.assign({ px: 0, py: 0, width: '100%', border: 'none', backgroundColor: inverted ? COLOR.DARK_GRAY : COLOR.WHITE, color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.TEXT }, typographyStyles), { '::placeholder': {
|
|
104
|
+
color: inverted ? COLOR.LIGHT_GRAY : COLOR.GRAY,
|
|
105
|
+
}, ':focus': {
|
|
74
106
|
outline: 'none',
|
|
75
107
|
} }) }, rest)), label && (_jsx(Label, Object.assign({ htmlFor: id, typography: labelTypographyMap[size], sx: {
|
|
76
108
|
position: 'absolute',
|
|
77
|
-
color: COLOR.ND_PROVOST_BLUE,
|
|
78
|
-
backgroundColor: COLOR.WHITE,
|
|
109
|
+
color: inverted ? COLOR.EXTRA_LIGHT_GRAY : COLOR.ND_PROVOST_BLUE,
|
|
79
110
|
left: '0.5rem',
|
|
80
111
|
lineHeight: 1,
|
|
81
112
|
zIndex: theme.zIndex.LABEL,
|
|
82
|
-
px:
|
|
113
|
+
px: 1,
|
|
83
114
|
top: labelOffsetMap[size],
|
|
84
115
|
} }, { children: label })))] })));
|
|
85
116
|
});
|
|
@@ -15,7 +15,7 @@ import React, { useState } from 'react';
|
|
|
15
15
|
import { useTheme } from '../../../../theme';
|
|
16
16
|
import { COLOR, colors } from '../../../../theme/colors';
|
|
17
17
|
import { getTypographyStyles, } from '../../../../theme/typography';
|
|
18
|
-
import { useMediaQuery } from '
|
|
18
|
+
import { useMediaQuery } from '../../../providers/media';
|
|
19
19
|
const ReadMoreLink = (props) => {
|
|
20
20
|
// const theme = useTheme()
|
|
21
21
|
const bg = colors[props.bg || COLOR.BACKGROUND];
|
|
@@ -8,6 +8,9 @@ export type ComponentConfig = {
|
|
|
8
8
|
internalLinkComponent: React.FC<LinkComponentProps>;
|
|
9
9
|
externalLinkComponent: React.FC<LinkComponentProps>;
|
|
10
10
|
};
|
|
11
|
+
modal: {
|
|
12
|
+
appElement: HTMLElement | undefined;
|
|
13
|
+
};
|
|
11
14
|
};
|
|
12
15
|
export type ComponentConfigParam = DeepPartial<ComponentConfig>;
|
|
13
16
|
export type LinkComponentProps = StyledElementProps<HTMLAnchorElement, {
|
|
@@ -25,6 +25,9 @@ const defaultComponentConfig = {
|
|
|
25
25
|
internalLinkComponent: DefaultLink,
|
|
26
26
|
externalLinkComponent: DefaultLink,
|
|
27
27
|
},
|
|
28
|
+
modal: {
|
|
29
|
+
appElement: undefined,
|
|
30
|
+
},
|
|
28
31
|
};
|
|
29
32
|
export const ComponentConfigContext = createContext(defaultComponentConfig);
|
|
30
33
|
export const useComponentConfig = () => useContext(ComponentConfigContext);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
const DialogContext = React.createContext({
|
|
4
|
+
open: () => { },
|
|
5
|
+
close: () => { },
|
|
6
|
+
dialogs: {},
|
|
7
|
+
});
|
|
8
|
+
export const DialogsProvider = ({ children }) => {
|
|
9
|
+
const [dialogs, setDialogs] = React.useState({});
|
|
10
|
+
const open = (key) => {
|
|
11
|
+
setDialogs(Object.assign(Object.assign({}, dialogs), { [key]: { isOpen: true } }));
|
|
12
|
+
};
|
|
13
|
+
const close = (key) => {
|
|
14
|
+
setDialogs(Object.assign(Object.assign({}, dialogs), { [key]: { isOpen: false } }));
|
|
15
|
+
};
|
|
16
|
+
return (_jsx(DialogContext.Provider, Object.assign({ value: {
|
|
17
|
+
dialogs,
|
|
18
|
+
open,
|
|
19
|
+
close,
|
|
20
|
+
} }, { children: children })));
|
|
21
|
+
};
|
|
22
|
+
export const useDialog = (id) => {
|
|
23
|
+
const dialogs = React.useContext(DialogContext);
|
|
24
|
+
const open = () => dialogs.open(id);
|
|
25
|
+
const close = () => dialogs.close(id);
|
|
26
|
+
const state = dialogs.dialogs[id] || { isOpen: false };
|
|
27
|
+
return {
|
|
28
|
+
open,
|
|
29
|
+
close,
|
|
30
|
+
state,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
type MediaContextType = {
|
|
3
|
+
screenSize: number;
|
|
4
|
+
breakpoint: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const MediaSizeProvider: React.FC<PropsWithChildren>;
|
|
7
|
+
export declare const useMediaQuery: () => MediaContextType;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useState, } from 'react';
|
|
3
|
+
import { useTheme } from '../../theme';
|
|
4
|
+
const MediaContext = createContext({
|
|
5
|
+
screenSize: -1,
|
|
6
|
+
breakpoint: -1,
|
|
7
|
+
});
|
|
8
|
+
export const MediaSizeProvider = ({ children, }) => {
|
|
9
|
+
const [renderCount, setRenderCount] = useState(0);
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
const breakpoints = theme.breakpoints.map((bp) => parseInt(bp.slice(0, -2)), [theme]);
|
|
12
|
+
const { screenSize, breakpoint } = useMemo(() => {
|
|
13
|
+
if (typeof window === 'undefined') {
|
|
14
|
+
return {
|
|
15
|
+
screenSize: -1,
|
|
16
|
+
breakpoint: -1,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const screenSize = window.innerWidth;
|
|
20
|
+
const closestBreakpoint = breakpoints.findIndex((bp) => screenSize < bp);
|
|
21
|
+
const breakpoint = closestBreakpoint === -1 ? breakpoints.length : closestBreakpoint;
|
|
22
|
+
return {
|
|
23
|
+
screenSize,
|
|
24
|
+
breakpoint,
|
|
25
|
+
};
|
|
26
|
+
}, [renderCount, breakpoints]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (typeof window === 'undefined')
|
|
29
|
+
return;
|
|
30
|
+
const rerenderOnResize = () => {
|
|
31
|
+
setRenderCount((renderCount) => renderCount + 1);
|
|
32
|
+
};
|
|
33
|
+
window.addEventListener('resize', rerenderOnResize);
|
|
34
|
+
return () => {
|
|
35
|
+
window.removeEventListener('resize', rerenderOnResize);
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
return (_jsx(MediaContext.Provider, Object.assign({ value: {
|
|
39
|
+
breakpoint,
|
|
40
|
+
screenSize,
|
|
41
|
+
} }, { children: children })));
|
|
42
|
+
};
|
|
43
|
+
export const useMediaQuery = () => useContext(MediaContext);
|
|
@@ -5,7 +5,8 @@ import { ThemeProvider } from '../../theme/';
|
|
|
5
5
|
import { AlertsProvider } from './alerts';
|
|
6
6
|
import { FontLoader } from '../../FontLoader';
|
|
7
7
|
import { GlobalStyles } from '../../theme/GlobalStyles';
|
|
8
|
+
import { DialogsProvider } from './dialogs';
|
|
9
|
+
import { MediaSizeProvider } from './media';
|
|
8
10
|
export const UiProvider = ({ env, components, alertsConfig, children, loadFonts, loadGlobalStyles, }) => {
|
|
9
|
-
|
|
10
|
-
return (_jsxs(EnvironmentProvider, Object.assign({ env: env }, { children: [_jsx(ComponentConfigProvider, Object.assign({ config: components || {} }, { children: _jsx(ThemeProvider, { children: _jsx(AlertsProvider, Object.assign({}, alertsConfig, { children: children })) }) })), loadGlobalStyles && _jsx(GlobalStyles, {}), loadFonts && _jsx(FontLoader, {})] })));
|
|
11
|
+
return (_jsxs(EnvironmentProvider, Object.assign({ env: env }, { children: [_jsx(ThemeProvider, { children: _jsx(MediaSizeProvider, { children: _jsx(ComponentConfigProvider, Object.assign({ config: components || {} }, { children: _jsx(DialogsProvider, { children: _jsx(AlertsProvider, Object.assign({}, alertsConfig, { children: children })) }) })) }) }), loadGlobalStyles && _jsx(GlobalStyles, {}), loadFonts && _jsx(FontLoader, {})] })));
|
|
11
12
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -32,8 +32,10 @@ export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
|
|
|
32
32
|
export { NavMenu } from './components/composites/NavMenu';
|
|
33
33
|
export { EmptyState, EMPTY_STATE_SIZE, } from './components/composites/EmptyState';
|
|
34
34
|
export { DropdownLinks } from './components/composites/DropdownLinks';
|
|
35
|
+
export { Modal } from './components/composites/Modal';
|
|
35
36
|
export { UiProvider } from './components/providers/ui';
|
|
36
37
|
export { MenuProvider, useMenu } from './components/providers/menu';
|
|
37
38
|
export { useAlerts, AlertsProvider, ALERT_DOMAIN, } from './components/providers/alerts';
|
|
39
|
+
export { MediaSizeProvider, useMediaQuery } from './components/providers/media';
|
|
40
|
+
export { DialogsProvider, useDialog } from './components/providers/dialogs';
|
|
38
41
|
export { useHover } from './utils/hooks/useHover';
|
|
39
|
-
export { useMediaQuery } from './utils/hooks/useMediaQuery';
|
package/dist/index.js
CHANGED
|
@@ -32,8 +32,10 @@ export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
|
|
|
32
32
|
export { NavMenu } from './components/composites/NavMenu';
|
|
33
33
|
export { EmptyState, EMPTY_STATE_SIZE, } from './components/composites/EmptyState';
|
|
34
34
|
export { DropdownLinks } from './components/composites/DropdownLinks';
|
|
35
|
+
export { Modal } from './components/composites/Modal';
|
|
35
36
|
export { UiProvider } from './components/providers/ui';
|
|
36
37
|
export { MenuProvider, useMenu } from './components/providers/menu';
|
|
37
38
|
export { useAlerts, AlertsProvider, ALERT_DOMAIN, } from './components/providers/alerts';
|
|
39
|
+
export { MediaSizeProvider, useMediaQuery } from './components/providers/media';
|
|
40
|
+
export { DialogsProvider, useDialog } from './components/providers/dialogs';
|
|
38
41
|
export { useHover } from './utils/hooks/useHover';
|
|
39
|
-
export { useMediaQuery } from './utils/hooks/useMediaQuery';
|
package/dist/theme/custom.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export declare enum BOX_SHADOW {
|
|
2
2
|
NORMAL = "0 0 8px #dfdfdf",
|
|
3
|
-
EMPHASIZED = "0 0 12px #d3d3d3"
|
|
3
|
+
EMPHASIZED = "0 0 12px #d3d3d3",
|
|
4
|
+
INVERTED = "0 0 8px #767676"
|
|
4
5
|
}
|
|
5
6
|
export declare enum Z_INDEX {
|
|
6
7
|
NORMAL = 1,
|
|
7
8
|
LABEL = 2,
|
|
8
|
-
DROPDOWN = 3
|
|
9
|
+
DROPDOWN = 3,
|
|
10
|
+
MODAL = 4
|
|
9
11
|
}
|
package/dist/theme/custom.js
CHANGED
|
@@ -3,10 +3,12 @@ export var BOX_SHADOW;
|
|
|
3
3
|
(function (BOX_SHADOW) {
|
|
4
4
|
BOX_SHADOW["NORMAL"] = "0 0 8px #dfdfdf";
|
|
5
5
|
BOX_SHADOW["EMPHASIZED"] = "0 0 12px #d3d3d3";
|
|
6
|
+
BOX_SHADOW["INVERTED"] = "0 0 8px #767676";
|
|
6
7
|
})(BOX_SHADOW || (BOX_SHADOW = {}));
|
|
7
8
|
export var Z_INDEX;
|
|
8
9
|
(function (Z_INDEX) {
|
|
9
10
|
Z_INDEX[Z_INDEX["NORMAL"] = 1] = "NORMAL";
|
|
10
11
|
Z_INDEX[Z_INDEX["LABEL"] = 2] = "LABEL";
|
|
11
12
|
Z_INDEX[Z_INDEX["DROPDOWN"] = 3] = "DROPDOWN";
|
|
13
|
+
Z_INDEX[Z_INDEX["MODAL"] = 4] = "MODAL";
|
|
12
14
|
})(Z_INDEX || (Z_INDEX = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndlib/component-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@types/react": "^18.0.28",
|
|
55
55
|
"@types/react-datepicker": "^4.15.0",
|
|
56
56
|
"@types/react-dom": "^18.0.11",
|
|
57
|
+
"@types/react-modal": "^3.16.0",
|
|
57
58
|
"@types/sanitize-html": "^2.9.0",
|
|
58
59
|
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
59
60
|
"@typescript-eslint/parser": "^5.57.1",
|
|
@@ -82,6 +83,7 @@
|
|
|
82
83
|
"@floating-ui/react": "^0.24.5",
|
|
83
84
|
"react-datepicker": "^4.16.0",
|
|
84
85
|
"react-markdown": "^8.0.7",
|
|
86
|
+
"react-modal": "^3.16.1",
|
|
85
87
|
"rehype-raw": "^6.1.1",
|
|
86
88
|
"sanitize-html": "^2.11.0"
|
|
87
89
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { useTheme } from '../../theme';
|
|
3
|
-
export const useMediaQuery = () => {
|
|
4
|
-
const [screenSize, setScreenSize] = useState(typeof window !== 'undefined' ? window.innerWidth : 0);
|
|
5
|
-
const [breakpoint, setBreakpoint] = useState(undefined);
|
|
6
|
-
const theme = useTheme();
|
|
7
|
-
const breakpoints = theme.breakpoints.map((bp) => parseInt(bp.slice(0, -2)), [theme]);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (typeof window === 'undefined')
|
|
10
|
-
return;
|
|
11
|
-
const handleResize = () => {
|
|
12
|
-
const screenSize = window.innerWidth;
|
|
13
|
-
let closestBreakpoint = breakpoints.findIndex((bp) => screenSize < bp);
|
|
14
|
-
closestBreakpoint =
|
|
15
|
-
closestBreakpoint === -1 ? breakpoints.length : closestBreakpoint;
|
|
16
|
-
setBreakpoint(closestBreakpoint);
|
|
17
|
-
setScreenSize(screenSize);
|
|
18
|
-
};
|
|
19
|
-
window.addEventListener('resize', handleResize);
|
|
20
|
-
handleResize();
|
|
21
|
-
return () => {
|
|
22
|
-
window.removeEventListener('resize', handleResize);
|
|
23
|
-
};
|
|
24
|
-
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
25
|
-
return {
|
|
26
|
-
screenSize,
|
|
27
|
-
breakpoint,
|
|
28
|
-
};
|
|
29
|
-
};
|