@ndlib/component-library 0.0.92 → 0.0.94
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/elements/Dropdown/Dropdown.stories.d.ts +1 -0
- package/dist/components/elements/Dropdown/Dropdown.stories.js +4 -0
- package/dist/components/elements/Dropdown/index.d.ts +2 -0
- package/dist/components/elements/Dropdown/index.js +2 -7
- package/dist/components/elements/Fields/Checkbox/index.d.ts +1 -0
- package/dist/components/elements/Fields/Checkbox/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 +5 -2
- package/dist/components/elements/Fields/CheckboxGroup/index.d.ts +1 -0
- package/dist/components/elements/Fields/CheckboxGroup/index.js +3 -2
- package/dist/components/elements/Fields/Radio/index.d.ts +1 -0
- package/dist/components/elements/Fields/Radio/index.js +3 -3
- package/dist/components/elements/Fields/RadioGroup/RadioGroup.stories.d.ts +1 -0
- package/dist/components/elements/Fields/RadioGroup/RadioGroup.stories.js +4 -1
- package/dist/components/elements/Fields/RadioGroup/index.d.ts +1 -0
- package/dist/components/elements/Fields/RadioGroup/index.js +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { Button } from '../../elements/Button';
|
|
|
4
4
|
import { Box } from '../../elements/layout/Box';
|
|
5
5
|
import { Dropdown } from '.';
|
|
6
6
|
import { Paragraph } from '../text/Paragraph';
|
|
7
|
+
import { Column } from '../layout/Column';
|
|
7
8
|
const meta = {
|
|
8
9
|
title: 'Elements/Dropdown',
|
|
9
10
|
component: Dropdown,
|
|
@@ -18,3 +19,6 @@ export const Default = {
|
|
|
18
19
|
export const MatchWidth = {
|
|
19
20
|
render: () => (_jsx(Box, Object.assign({ sx: { width: '200px', height: '200px' } }, { children: _jsx(Dropdown, { matchWidth: true, renderAnchor: ({ anchorProps }) => (_jsx(Button, Object.assign({}, anchorProps, { rightIcon: ArrowDropDownIcon }, { children: "Open Dropdown" }))), renderDropdown: () => _jsx(Paragraph, { children: lorem }) }) }))),
|
|
20
21
|
};
|
|
22
|
+
export const ForcePlacement = {
|
|
23
|
+
render: () => (_jsx(Column, Object.assign({ sx: { width: '200x', height: '100vh' }, justify: "flex-end" }, { children: _jsx(Dropdown, { allowedPlacements: ['bottom-start'], renderAnchor: ({ anchorProps }) => (_jsx(Button, Object.assign({}, anchorProps, { rightIcon: ArrowDropDownIcon }, { children: "Open Dropdown" }))), renderDropdown: () => _jsx(Paragraph, { children: lorem }) }) }))),
|
|
24
|
+
};
|
|
@@ -13,11 +13,13 @@ type DropdownRenderFn = (params: {
|
|
|
13
13
|
setIsOpen: (isOpen: boolean) => void;
|
|
14
14
|
id: string;
|
|
15
15
|
}) => React.ReactNode;
|
|
16
|
+
type Placement = 'top-start' | 'bottom-start' | 'top-end' | 'bottom-end';
|
|
16
17
|
type DropdownProps = StyledElementProps<HTMLDivElement, {
|
|
17
18
|
renderAnchor: AnchorRenderFn;
|
|
18
19
|
renderDropdown: DropdownRenderFn;
|
|
19
20
|
shouldRenderDropdownContainer?: boolean;
|
|
20
21
|
matchWidth?: boolean;
|
|
22
|
+
allowedPlacements?: Placement[];
|
|
21
23
|
}>;
|
|
22
24
|
export declare const Overlay: React.FC<StyledElementProps<HTMLDivElement>>;
|
|
23
25
|
export declare const Dropdown: React.FC<DropdownProps>;
|
|
@@ -26,7 +26,7 @@ export const Overlay = (props) => (_jsx(Box, Object.assign({}, props, { sx: {
|
|
|
26
26
|
zIndex: Z_INDEX.ELEVATED,
|
|
27
27
|
} })));
|
|
28
28
|
export const Dropdown = (_a) => {
|
|
29
|
-
var { renderAnchor, renderDropdown, matchWidth, shouldRenderDropdownContainer = true } = _a, rest = __rest(_a, ["renderAnchor", "renderDropdown", "matchWidth", "shouldRenderDropdownContainer"]);
|
|
29
|
+
var { renderAnchor, renderDropdown, matchWidth, shouldRenderDropdownContainer = true, allowedPlacements = ['top-start', 'bottom-start', 'top-end', 'bottom-end'] } = _a, rest = __rest(_a, ["renderAnchor", "renderDropdown", "matchWidth", "shouldRenderDropdownContainer", "allowedPlacements"]);
|
|
30
30
|
const [isOpen, setIsOpen] = useState(false);
|
|
31
31
|
const [dropdownMinWidth, setDropdownMinWidth] = useState('0px');
|
|
32
32
|
const [dropdownMaxWidth, setDropdownMaxWidth] = useState();
|
|
@@ -46,12 +46,7 @@ export const Dropdown = (_a) => {
|
|
|
46
46
|
},
|
|
47
47
|
}),
|
|
48
48
|
autoPlacement({
|
|
49
|
-
allowedPlacements
|
|
50
|
-
'top-start',
|
|
51
|
-
'bottom-start',
|
|
52
|
-
'top-end',
|
|
53
|
-
'bottom-end',
|
|
54
|
-
],
|
|
49
|
+
allowedPlacements,
|
|
55
50
|
}),
|
|
56
51
|
],
|
|
57
52
|
});
|
|
@@ -3,6 +3,7 @@ import { StyledElementProps } from '../../../../theme';
|
|
|
3
3
|
type CheckboxProps = StyledElementProps<HTMLInputElement, {
|
|
4
4
|
checked: boolean;
|
|
5
5
|
onChange: (value: boolean) => void;
|
|
6
|
+
disabled?: boolean;
|
|
6
7
|
}, string>;
|
|
7
8
|
export declare const Checkbox: React.FC<CheckboxProps>;
|
|
8
9
|
export {};
|
|
@@ -12,11 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
13
|
import { useTheme } from '../../../../theme';
|
|
14
14
|
export const Checkbox = (_a) => {
|
|
15
|
-
var { checked, onChange, sx } = _a, rest = __rest(_a, ["checked", "onChange", "sx"]);
|
|
15
|
+
var { checked, onChange, disabled, sx } = _a, rest = __rest(_a, ["checked", "onChange", "disabled", "sx"]);
|
|
16
16
|
const theme = useTheme();
|
|
17
17
|
return (_jsx("input", Object.assign({ type: "checkbox", onChange: (e) => {
|
|
18
18
|
onChange(e.target.checked);
|
|
19
|
-
}, checked: checked, sx: Object.assign({ margin: '0px', height: '1.25rem', width: '1.25rem', cursor: 'pointer', ':hover': {
|
|
19
|
+
}, checked: checked, sx: Object.assign({ margin: '0px', height: '1.25rem', width: '1.25rem', cursor: disabled ? 'not-allowed' : 'pointer', ':hover': {
|
|
20
20
|
boxShadow: theme.boxShadow,
|
|
21
|
-
} }, sx) }, rest)));
|
|
21
|
+
} }, sx), disabled: disabled }, rest)));
|
|
22
22
|
};
|
|
@@ -9,14 +9,14 @@ const meta = {
|
|
|
9
9
|
};
|
|
10
10
|
export default meta;
|
|
11
11
|
const options = [
|
|
12
|
-
{ value: 'orange', label: 'Orange' },
|
|
12
|
+
{ value: 'orange', label: 'Orange', disabled: true },
|
|
13
13
|
{ value: 'apple', label: 'Apple' },
|
|
14
14
|
{ value: 'strawberry', label: 'Strawberry' },
|
|
15
15
|
{ value: 'pineapple', label: 'Pineapple' },
|
|
16
16
|
];
|
|
17
17
|
const StatefulCheckboxGroup = (props) => {
|
|
18
18
|
const [checked, setChecked] = useState(new Set());
|
|
19
|
-
return (_jsx(CheckboxGroup, Object.assign({}, props, { checkedOptions: checked, options: options, onChange: setChecked })));
|
|
19
|
+
return (_jsx(CheckboxGroup, Object.assign({}, props, { checkedOptions: checked, options: props.options || options, onChange: setChecked })));
|
|
20
20
|
};
|
|
21
21
|
export const Default = {
|
|
22
22
|
render: () => (_jsx(Row, { children: _jsx(StatefulCheckboxGroup, {}) })),
|
|
@@ -24,3 +24,6 @@ export const Default = {
|
|
|
24
24
|
export const Columns = {
|
|
25
25
|
render: () => (_jsx(Row, { children: _jsx(StatefulCheckboxGroup, { columns: 2 }) })),
|
|
26
26
|
};
|
|
27
|
+
export const Disabled = {
|
|
28
|
+
render: () => (_jsx(Row, { children: _jsx(StatefulCheckboxGroup, { options: options.map((option, i) => (Object.assign(Object.assign({}, option), { disabled: i === 1 ? true : false }))) }) })),
|
|
29
|
+
};
|
|
@@ -18,6 +18,7 @@ import { Group } from '../../Group';
|
|
|
18
18
|
import { GROUP_TYPE } from '../../Group';
|
|
19
19
|
import { Column } from '../../layout/Column';
|
|
20
20
|
import { TYPOGRAPHY_TYPE, getTypographyStyles, } from '../../../../theme/typography';
|
|
21
|
+
import { COLOR } from '../../../../theme/colors';
|
|
21
22
|
export function CheckboxGroup(_a) {
|
|
22
23
|
var { options, checkedOptions, columns: columnsProp, columnStyles, rowStyles, onChange } = _a, rest = __rest(_a, ["options", "checkedOptions", "columns", "columnStyles", "rowStyles", "onChange"]);
|
|
23
24
|
const columns = columnsProp || 1;
|
|
@@ -42,8 +43,8 @@ export function CheckboxGroup(_a) {
|
|
|
42
43
|
updatedSet.delete(option.value);
|
|
43
44
|
}
|
|
44
45
|
onChange(updatedSet);
|
|
45
|
-
}, checked: !!(checkedOptions === null || checkedOptions === void 0 ? void 0 : checkedOptions.has(option.value)), id: labelTargetId, sx: {
|
|
46
|
+
}, checked: !!(checkedOptions === null || checkedOptions === void 0 ? void 0 : checkedOptions.has(option.value)), id: labelTargetId, disabled: option.disabled, sx: {
|
|
46
47
|
mr: 2,
|
|
47
48
|
flexShrink: 0,
|
|
48
|
-
} }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM)) }, { children: option.label }))] }))) }), option.value))) }), index))) })));
|
|
49
|
+
} }), _jsx(Label, Object.assign({ sx: Object.assign(Object.assign({ cursor: option.disabled ? 'not-allowed' : 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM)), { color: option.disabled ? COLOR.GRAY : undefined }) }, { children: option.label }))] }))) }), option.value))) }), index))) })));
|
|
49
50
|
}
|
|
@@ -3,6 +3,7 @@ import { StyledElementProps } from '../../../../theme';
|
|
|
3
3
|
type RadioProps = StyledElementProps<HTMLInputElement, {
|
|
4
4
|
checked: boolean;
|
|
5
5
|
onChange: (value: boolean) => void;
|
|
6
|
+
disabled?: boolean;
|
|
6
7
|
}, string>;
|
|
7
8
|
export declare const Radio: React.FC<RadioProps>;
|
|
8
9
|
export {};
|
|
@@ -12,11 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
13
|
import { useTheme } from '../../../../theme';
|
|
14
14
|
export const Radio = (_a) => {
|
|
15
|
-
var { checked, onChange, sx } = _a, rest = __rest(_a, ["checked", "onChange", "sx"]);
|
|
15
|
+
var { checked, onChange, disabled, sx } = _a, rest = __rest(_a, ["checked", "onChange", "disabled", "sx"]);
|
|
16
16
|
const theme = useTheme();
|
|
17
17
|
return (_jsx("input", Object.assign({ type: "radio", onChange: (e) => {
|
|
18
18
|
onChange(e.target.checked);
|
|
19
|
-
}, checked: checked, sx: Object.assign({ margin: '0px', height: '1.25rem', width: '1.25rem', cursor: 'pointer', ':hover': {
|
|
19
|
+
}, checked: checked, sx: Object.assign({ margin: '0px', height: '1.25rem', width: '1.25rem', cursor: disabled ? 'not-allowed' : 'pointer', ':hover': {
|
|
20
20
|
boxShadow: theme.boxShadow,
|
|
21
|
-
} }, sx) }, rest)));
|
|
21
|
+
} }, sx), disabled: disabled }, rest)));
|
|
22
22
|
};
|
|
@@ -16,8 +16,11 @@ const options = [
|
|
|
16
16
|
];
|
|
17
17
|
const StatefulRadioGroup = (props) => {
|
|
18
18
|
const [checked, setChecked] = useState(new Set());
|
|
19
|
-
return (_jsx(RadioGroup, Object.assign({}, props, { checked: checked, options: options, onChange: setChecked })));
|
|
19
|
+
return (_jsx(RadioGroup, Object.assign({}, props, { checked: checked, options: props.options || options, onChange: setChecked })));
|
|
20
20
|
};
|
|
21
21
|
export const Default = {
|
|
22
22
|
render: () => (_jsx(Row, { children: _jsx(StatefulRadioGroup, {}) })),
|
|
23
23
|
};
|
|
24
|
+
export const Disabled = {
|
|
25
|
+
render: () => (_jsx(Row, { children: _jsx(StatefulRadioGroup, { options: options.map((option, i) => (Object.assign(Object.assign({}, option), { disabled: i === 1 ? true : false }))) }) })),
|
|
26
|
+
};
|
|
@@ -24,5 +24,5 @@ export function RadioGroup(_a) {
|
|
|
24
24
|
}, checked: checked === option.value, id: labelTargetId, sx: {
|
|
25
25
|
mr: 2,
|
|
26
26
|
flexShrink: 0,
|
|
27
|
-
} }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM)) }, { children: option.label }))] }))) }), option.value))) })));
|
|
27
|
+
}, disabled: option.disabled }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: option.disabled ? 'not-allowed' : 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM)) }, { children: option.label }))] }))) }), option.value))) })));
|
|
28
28
|
}
|