@ndlib/component-library 0.0.8 → 0.0.14
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/README.md +101 -0
- package/dist/FontLoader.d.ts +1 -0
- package/dist/FontLoader.js +4 -0
- package/dist/components/composites/Card/Card.stories.d.ts +9 -0
- package/dist/components/composites/Card/Card.stories.js +77 -0
- package/dist/components/composites/Card/Card.test.d.ts +1 -0
- package/dist/components/composites/Card/Card.test.js +29 -0
- package/dist/components/composites/Card/index.d.ts +22 -0
- package/dist/components/composites/Card/index.js +71 -0
- package/dist/components/elements/Alerts/Alert.stories.d.ts +9 -0
- package/dist/components/elements/Alerts/Alert.stories.js +41 -0
- package/dist/components/elements/Alerts/Alerts.stories.d.ts +6 -0
- package/dist/components/elements/Alerts/Alerts.stories.js +12 -0
- package/dist/components/elements/Alerts/Alerts.test.d.ts +1 -0
- package/dist/components/elements/Alerts/Alerts.test.js +62 -0
- package/dist/components/elements/Alerts/index.d.ts +15 -0
- package/dist/components/elements/Alerts/index.js +63 -0
- package/dist/components/elements/BrandingBar/BrandingBar.stories.d.ts +6 -0
- package/dist/components/elements/BrandingBar/BrandingBar.stories.js +11 -0
- package/dist/components/elements/BrandingBar/index.d.ts +1 -0
- package/dist/components/elements/BrandingBar/index.js +52 -0
- package/dist/components/elements/Button/Button.stories.d.ts +4 -0
- package/dist/components/elements/Button/Button.stories.js +42 -9
- package/dist/components/elements/Button/Button.test.js +11 -2
- package/dist/components/elements/Button/index.d.ts +16 -11
- package/dist/components/elements/Button/index.js +84 -34
- package/dist/components/elements/Fields/Checkbox/Checkbox.stories.d.ts +6 -0
- package/dist/components/elements/Fields/Checkbox/Checkbox.stories.js +17 -0
- package/dist/components/elements/Fields/Checkbox/index.d.ts +9 -0
- package/dist/components/elements/Fields/Checkbox/index.js +22 -0
- package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.d.ts +6 -0
- package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.js +23 -0
- package/dist/components/elements/Fields/CheckboxGroup/index.d.ts +14 -0
- package/dist/components/elements/Fields/CheckboxGroup/index.js +35 -0
- package/dist/components/elements/Fields/Radio/Radio.stories.d.ts +6 -0
- package/dist/components/elements/Fields/Radio/Radio.stories.js +17 -0
- package/dist/components/elements/Fields/Radio/index.d.ts +9 -0
- package/dist/components/elements/Fields/Radio/index.js +22 -0
- package/dist/components/elements/Fields/RadioGroup/RadioGroup.stories.d.ts +6 -0
- package/dist/components/elements/Fields/RadioGroup/RadioGroup.stories.js +23 -0
- package/dist/components/elements/Fields/RadioGroup/index.d.ts +14 -0
- package/dist/components/elements/Fields/RadioGroup/index.js +28 -0
- package/dist/components/elements/Fields/Select/Select.stories.d.ts +6 -0
- package/dist/components/elements/Fields/Select/Select.stories.js +32 -0
- package/dist/components/elements/Fields/Select/index.d.ts +16 -0
- package/dist/components/elements/Fields/Select/index.js +136 -0
- package/dist/components/elements/Fields/TextInput/TextInput.stories.d.ts +6 -0
- package/dist/components/elements/Fields/TextInput/TextInput.stories.js +25 -0
- package/dist/components/elements/Fields/TextInput/index.d.ts +17 -0
- package/dist/components/elements/Fields/TextInput/index.js +60 -0
- package/dist/components/elements/Fields/option.d.ts +15 -0
- package/dist/components/elements/Fields/option.js +3 -0
- package/dist/components/elements/Group/index.js +3 -3
- package/dist/components/elements/Icon/Icon.stories.d.ts +7 -0
- package/dist/components/elements/Icon/Icon.stories.js +29 -0
- package/dist/components/elements/Icon/Icon.test.d.ts +1 -0
- package/dist/components/elements/Icon/Icon.test.js +26 -0
- package/dist/components/elements/Icon/index.d.ts +11 -0
- package/dist/components/elements/Icon/index.js +25 -0
- package/dist/components/elements/Link/Link.stories.js +3 -3
- package/dist/components/elements/Link/Link.test.js +13 -13
- package/dist/components/elements/Link/index.d.ts +2 -2
- package/dist/components/elements/Link/index.js +4 -4
- package/dist/components/elements/List/List.stories.d.ts +9 -0
- package/dist/components/elements/List/List.stories.js +31 -0
- package/dist/components/elements/List/List.test.d.ts +1 -0
- package/dist/components/elements/List/List.test.js +24 -0
- package/dist/components/elements/List/index.d.ts +21 -0
- package/dist/components/elements/List/index.js +75 -0
- package/dist/components/elements/ListBox/Listbox.stories.d.ts +6 -0
- package/dist/components/elements/ListBox/Listbox.stories.js +17 -0
- package/dist/components/elements/ListBox/index.d.ts +32 -0
- package/dist/components/elements/ListBox/index.js +50 -0
- package/dist/components/elements/Markdown/Markdown.stories.d.ts +6 -0
- package/dist/components/elements/Markdown/Markdown.stories.js +53 -0
- package/dist/components/elements/Markdown/Markdown.test.d.ts +1 -0
- package/dist/components/elements/Markdown/Markdown.test.js +58 -0
- package/dist/components/elements/Markdown/index.d.ts +7 -0
- package/dist/components/elements/Markdown/index.js +50 -0
- package/dist/components/elements/layout/Box.d.ts +1 -1
- package/dist/components/elements/layout/Box.stories.js +1 -1
- package/dist/components/elements/layout/Column.d.ts +2 -2
- package/dist/components/elements/layout/Column.js +2 -2
- package/dist/components/elements/layout/Flex.stories.js +2 -2
- package/dist/components/elements/layout/Flex.test.js +2 -2
- package/dist/components/elements/layout/Row.d.ts +2 -2
- package/dist/components/elements/layout/Row.js +1 -1
- package/dist/components/elements/text/Heading/Heading.stories.js +10 -11
- package/dist/components/elements/text/Heading/Heading.test.js +1 -1
- package/dist/components/elements/text/Heading/index.d.ts +6 -4
- package/dist/components/elements/text/Heading/index.js +19 -13
- package/dist/components/elements/text/Inline/Inline.stories.d.ts +6 -0
- package/dist/components/elements/text/Inline/Inline.stories.js +13 -0
- package/dist/components/elements/text/Inline/index.d.ts +7 -0
- package/dist/components/elements/text/Inline/index.js +21 -0
- package/dist/components/elements/text/Label/Label.stories.js +3 -3
- package/dist/components/elements/text/Label/Label.test.js +2 -2
- package/dist/components/elements/text/Label/index.d.ts +3 -3
- package/dist/components/elements/text/Label/index.js +4 -4
- package/dist/components/elements/text/Paragraph/Paragraph.stories.js +2 -2
- package/dist/components/elements/text/Paragraph/Paragraph.test.js +1 -1
- package/dist/components/elements/text/Paragraph/index.d.ts +2 -2
- package/dist/components/elements/text/Paragraph/index.js +2 -2
- package/dist/components/providers/alerts.d.ts +41 -0
- package/dist/components/providers/alerts.js +133 -0
- package/dist/components/providers/componentConfig.d.ts +3 -3
- package/dist/components/providers/componentConfig.js +5 -4
- package/dist/components/providers/env.d.ts +1 -1
- package/dist/components/providers/env.js +3 -3
- package/dist/components/providers/theme.js +1 -1
- package/dist/components/providers/ui.d.ts +7 -3
- package/dist/components/providers/ui.js +8 -6
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -1
- package/dist/theme/Color.stories.js +18 -2
- package/dist/theme/Typography.stories.d.ts +6 -0
- package/dist/theme/Typography.stories.js +43 -0
- package/dist/theme/colors.d.ts +12 -1
- package/dist/theme/colors.js +22 -0
- package/dist/theme/custom.d.ts +3 -0
- package/dist/theme/custom.js +5 -0
- package/dist/theme/index.d.ts +139 -4
- package/dist/theme/index.js +18 -12
- package/dist/theme/typography.d.ts +47 -6
- package/dist/theme/typography.js +74 -36
- package/dist/utils/hooks/useStorage.d.ts +14 -0
- package/dist/utils/hooks/useStorage.js +31 -0
- package/dist/utils/hooks/useUniqueHtmlId.d.ts +1 -0
- package/dist/utils/hooks/useUniqueHtmlId.js +7 -0
- package/dist/utils/misc.d.ts +7 -0
- package/dist/utils/misc.js +13 -1
- package/dist/utils/test.js +3 -1
- package/global.css +4 -9
- package/package.json +21 -13
|
@@ -0,0 +1,75 @@
|
|
|
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 "theme-ui/jsx-runtime";
|
|
13
|
+
/** @jsxImportSource theme-ui */
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import CircleIcon from '@mui/icons-material/Circle';
|
|
16
|
+
import CircleOutlinedIcon from '@mui/icons-material/CircleOutlined';
|
|
17
|
+
import SquareIcon from '@mui/icons-material/Square';
|
|
18
|
+
import SquareOutlinedIcon from '@mui/icons-material/SquareOutlined';
|
|
19
|
+
import { COLOR, Label, TYPOGRAPHY_TYPE } from '../../..';
|
|
20
|
+
import { getTypographyStyles } from '../../../theme/typography';
|
|
21
|
+
import { Icon } from '../Icon';
|
|
22
|
+
export var LIST_SIZE;
|
|
23
|
+
(function (LIST_SIZE) {
|
|
24
|
+
LIST_SIZE["SM"] = "sm";
|
|
25
|
+
LIST_SIZE["MD"] = "md";
|
|
26
|
+
LIST_SIZE["LG"] = "lg";
|
|
27
|
+
})(LIST_SIZE || (LIST_SIZE = {}));
|
|
28
|
+
const marginSizeMap = {
|
|
29
|
+
[LIST_SIZE.SM]: 2,
|
|
30
|
+
[LIST_SIZE.MD]: 3,
|
|
31
|
+
[LIST_SIZE.LG]: 4,
|
|
32
|
+
};
|
|
33
|
+
const defaultIcons = [
|
|
34
|
+
CircleIcon,
|
|
35
|
+
CircleOutlinedIcon,
|
|
36
|
+
SquareIcon,
|
|
37
|
+
SquareOutlinedIcon,
|
|
38
|
+
];
|
|
39
|
+
const sizeTypographyMap = {
|
|
40
|
+
[LIST_SIZE.SM]: TYPOGRAPHY_TYPE.PARAGRAPH_SMALL,
|
|
41
|
+
[LIST_SIZE.MD]: TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM,
|
|
42
|
+
[LIST_SIZE.LG]: TYPOGRAPHY_TYPE.PARAGRAPH_LARGE,
|
|
43
|
+
};
|
|
44
|
+
const ListConfigContext = React.createContext({
|
|
45
|
+
size: LIST_SIZE.MD,
|
|
46
|
+
ordered: false,
|
|
47
|
+
icon: CircleIcon,
|
|
48
|
+
iconColor: COLOR.TEXT,
|
|
49
|
+
depth: -1,
|
|
50
|
+
});
|
|
51
|
+
const useListConfig = () => React.useContext(ListConfigContext);
|
|
52
|
+
export const List = ({ sx, size, ordered, icon, iconColor, children, }) => {
|
|
53
|
+
const { depth: parentDepth, size: parentSize, iconColor: parentIconColor, } = useListConfig();
|
|
54
|
+
const depth = parentDepth + 1;
|
|
55
|
+
const defaultStyles = Object.assign({ listStyleType: 'none' }, getTypographyStyles());
|
|
56
|
+
const defaultIcon = defaultIcons[depth] || CircleIcon;
|
|
57
|
+
return (_jsx(ListConfigContext.Provider, Object.assign({ value: {
|
|
58
|
+
size: size || parentSize || LIST_SIZE.MD,
|
|
59
|
+
icon: icon || defaultIcon,
|
|
60
|
+
iconColor: iconColor || parentIconColor || COLOR.TEXT,
|
|
61
|
+
ordered: ordered || false,
|
|
62
|
+
depth,
|
|
63
|
+
} }, { children: ordered ? (_jsx("ul", Object.assign({ sx: Object.assign(Object.assign({}, defaultStyles), sx) }, { children: children }))) : (_jsx("ol", Object.assign({ sx: Object.assign(Object.assign({}, defaultStyles), sx) }, { children: children }))) })));
|
|
64
|
+
};
|
|
65
|
+
export const ListItem = (_a) => {
|
|
66
|
+
var { index, sx, children } = _a, rest = __rest(_a, ["index", "sx", "children"]);
|
|
67
|
+
const { ordered, icon, iconColor, size, depth } = useListConfig();
|
|
68
|
+
const typographyStyles = getTypographyStyles(sizeTypographyMap[size]);
|
|
69
|
+
return (_jsxs("li", Object.assign({ sx: Object.assign(Object.assign({ depth, display: 'flex', mt: index === 0 && depth === 0 ? 0 : marginSizeMap[size], ml: 2 }, typographyStyles), sx) }, rest, { children: [ordered ? (_jsxs(Label, Object.assign({ standalone: true, sx: { mr: 2 } }, { children: [index + 1, "."] }))) : (_jsx(Icon, { icon: icon, color: iconColor, css: {
|
|
70
|
+
marginTop: '5px',
|
|
71
|
+
}, sx: {
|
|
72
|
+
mr: 3,
|
|
73
|
+
alignItems: 'flex-start',
|
|
74
|
+
} })), _jsx("div", { children: children })] })));
|
|
75
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ListBox } from '.';
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Elements/ListBox',
|
|
5
|
+
component: ListBox,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
};
|
|
8
|
+
export default meta;
|
|
9
|
+
const options = [
|
|
10
|
+
{ value: 'orange', label: 'Orange' },
|
|
11
|
+
{ value: 'apple', label: 'Apple' },
|
|
12
|
+
{ value: 'strawberry', label: 'Strawberry' },
|
|
13
|
+
{ value: 'pineapple', label: 'Pineapple' },
|
|
14
|
+
];
|
|
15
|
+
export const Default = {
|
|
16
|
+
render: () => _jsx(ListBox, { options: options }),
|
|
17
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import React, { Key } from 'react';
|
|
3
|
+
import { StyledElementProps } from '../../../theme';
|
|
4
|
+
import { BasicOption, RenderOption } from '../Fields/option';
|
|
5
|
+
type ListBoxProps<Value extends Key, Option extends BasicOption<Value>> = StyledElementProps<HTMLDivElement, {
|
|
6
|
+
options: Option[];
|
|
7
|
+
renderOption?: RenderOption<Value, Option>;
|
|
8
|
+
selected?: Value;
|
|
9
|
+
focused?: Value;
|
|
10
|
+
selectOption?: (value: Value) => void;
|
|
11
|
+
onDownPress?: () => void;
|
|
12
|
+
onUpPress?: () => void;
|
|
13
|
+
onSelect?: () => void;
|
|
14
|
+
onBlur?: () => void;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const ListBox: <Value extends React.Key = string, Option extends BasicOption<Value> = any>(props: {
|
|
17
|
+
sx?: import("../../../theme").StylesProp | undefined;
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
} & React.HTMLAttributes<HTMLDivElement> & {
|
|
20
|
+
options: Option[];
|
|
21
|
+
renderOption?: RenderOption<Value, Option> | undefined;
|
|
22
|
+
selected?: Value | undefined;
|
|
23
|
+
focused?: Value | undefined;
|
|
24
|
+
selectOption?: ((value: Value) => void) | undefined;
|
|
25
|
+
onDownPress?: (() => void) | undefined;
|
|
26
|
+
onUpPress?: (() => void) | undefined;
|
|
27
|
+
onSelect?: (() => void) | undefined;
|
|
28
|
+
onBlur?: (() => void) | undefined;
|
|
29
|
+
} & {
|
|
30
|
+
ref?: React.ForwardedRef<HTMLDivElement> | undefined;
|
|
31
|
+
}) => any;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 } from "theme-ui/jsx-runtime";
|
|
13
|
+
/** @jsxImportSource theme-ui */
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { COLOR } from '../../..';
|
|
16
|
+
import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
|
|
17
|
+
import { defaultRenderOption, getOptionId, } from '../Fields/option';
|
|
18
|
+
function ListBoxInner(_a, ref) {
|
|
19
|
+
var { options, renderOption: renderOptionParam, selected, focused, selectOption, sx } = _a, rest = __rest(_a, ["options", "renderOption", "selected", "focused", "selectOption", "sx"]);
|
|
20
|
+
const renderOption = renderOptionParam || defaultRenderOption;
|
|
21
|
+
const typography = getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM);
|
|
22
|
+
return (_jsx("div", Object.assign({ role: "listbox", ref: ref, sx: Object.assign(Object.assign({ border: 'solid 1px', borderRadius: '4px', borderColor: COLOR.LIGHT_GRAY, backgroundColor: COLOR.BACKGROUND, boxShadow: '0px 0px 8px 2px #dddddd' }, typography), sx), onKeyDown: (e) => {
|
|
23
|
+
console.log(e);
|
|
24
|
+
} }, rest, { children: options.map((option) => (_jsx("div", Object.assign({ id: getOptionId(option.value), "aria-selected": selected === option.value, role: "option", onMouseDown: () => selectOption && selectOption(option.value), sx: {
|
|
25
|
+
px: 4,
|
|
26
|
+
py: 3,
|
|
27
|
+
backgroundColor: focused === option.value ? COLOR.FAINT_GRAY : COLOR.BACKGROUND,
|
|
28
|
+
cursor: 'pointer',
|
|
29
|
+
borderBottom: 'solid 1px',
|
|
30
|
+
borderBottomColor: COLOR.LIGHT_GRAY,
|
|
31
|
+
color: COLOR.TEXT,
|
|
32
|
+
':last-of-type': {
|
|
33
|
+
borderBottom: 'none',
|
|
34
|
+
borderBottomRightRadius: '4px',
|
|
35
|
+
borderBottomLeftRadius: '4px',
|
|
36
|
+
},
|
|
37
|
+
':first-of-type': {
|
|
38
|
+
borderTopRightRadius: '4px',
|
|
39
|
+
borderTopLeftRadius: '4px',
|
|
40
|
+
},
|
|
41
|
+
':hover': {
|
|
42
|
+
backgroundColor: COLOR.FAINT_GRAY,
|
|
43
|
+
},
|
|
44
|
+
} }, { children: renderOption({
|
|
45
|
+
option,
|
|
46
|
+
selected: selected === option.value,
|
|
47
|
+
focused: focused === option.value,
|
|
48
|
+
}) })))) })));
|
|
49
|
+
}
|
|
50
|
+
export const ListBox = React.forwardRef(ListBoxInner);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Markdown } from '.';
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Elements/Markdown',
|
|
5
|
+
component: Markdown,
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
};
|
|
8
|
+
const sampleParagraph = `
|
|
9
|
+
Lorem ipsum dolor sit amet consectetur adipiscing elit, urna consequat felis vehicula class ultricies
|
|
10
|
+
mollis dictumst, aenean non a in donec nulla. Phasellus ante pellentesque erat cum risus consequat
|
|
11
|
+
imperdiet aliquam, integer placerat et turpis mi eros nec lobortis taciti, vehicula nisl
|
|
12
|
+
litora tellus ligula porttitor metus.
|
|
13
|
+
`;
|
|
14
|
+
export default meta;
|
|
15
|
+
const startingContent = `
|
|
16
|
+
# Inline styles
|
|
17
|
+
This paragraph has __bold content__ and **more bold content** and _italic content_ and *more italic content*
|
|
18
|
+
|
|
19
|
+
# Heading 1
|
|
20
|
+
${sampleParagraph}
|
|
21
|
+
|
|
22
|
+
${sampleParagraph}
|
|
23
|
+
|
|
24
|
+
## Heading 2
|
|
25
|
+
${sampleParagraph}
|
|
26
|
+
|
|
27
|
+
### Heading 3
|
|
28
|
+
${sampleParagraph}
|
|
29
|
+
|
|
30
|
+
#### Heading 4
|
|
31
|
+
${sampleParagraph}
|
|
32
|
+
|
|
33
|
+
##### Heading 5
|
|
34
|
+
${sampleParagraph}
|
|
35
|
+
|
|
36
|
+
###### Heading 6
|
|
37
|
+
${sampleParagraph}
|
|
38
|
+
|
|
39
|
+
- List item 1
|
|
40
|
+
- List item 2
|
|
41
|
+
- List item 2.1
|
|
42
|
+
- List item 2.2
|
|
43
|
+
|
|
44
|
+
1. List item 1
|
|
45
|
+
2. List item 2
|
|
46
|
+
3. List item 3
|
|
47
|
+
`;
|
|
48
|
+
export const Default = {
|
|
49
|
+
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
50
|
+
args: {
|
|
51
|
+
content: startingContent,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '../../../utils/test';
|
|
3
|
+
import { Markdown } from '.';
|
|
4
|
+
const testMarkdown = `
|
|
5
|
+
# Inline styles
|
|
6
|
+
This paragraph has __bold content__ and **more bold content** and _italic content_ and *more italic content*
|
|
7
|
+
|
|
8
|
+
# Heading 1
|
|
9
|
+
|
|
10
|
+
## Heading 2
|
|
11
|
+
|
|
12
|
+
### Heading 3
|
|
13
|
+
|
|
14
|
+
#### Heading 4
|
|
15
|
+
|
|
16
|
+
##### Heading 5
|
|
17
|
+
|
|
18
|
+
###### Heading 6
|
|
19
|
+
|
|
20
|
+
- List item 1
|
|
21
|
+
- List item 2
|
|
22
|
+
- List item 2.1
|
|
23
|
+
- List item 2.2
|
|
24
|
+
|
|
25
|
+
1. List item 1
|
|
26
|
+
2. List item 2
|
|
27
|
+
3. List item 3
|
|
28
|
+
`;
|
|
29
|
+
describe('Markdown', () => {
|
|
30
|
+
it('renders alert content', () => {
|
|
31
|
+
const { getAllByRole, getByRole } = render(_jsx(Markdown, { content: testMarkdown }));
|
|
32
|
+
expect(getByRole('heading', {
|
|
33
|
+
name: 'Heading 1',
|
|
34
|
+
level: 1,
|
|
35
|
+
})).toBeInTheDocument();
|
|
36
|
+
expect(getByRole('heading', {
|
|
37
|
+
name: 'Heading 2',
|
|
38
|
+
level: 2,
|
|
39
|
+
})).toBeInTheDocument();
|
|
40
|
+
expect(getByRole('heading', {
|
|
41
|
+
name: 'Heading 3',
|
|
42
|
+
level: 3,
|
|
43
|
+
})).toBeInTheDocument();
|
|
44
|
+
expect(getByRole('heading', {
|
|
45
|
+
name: 'Heading 4',
|
|
46
|
+
level: 4,
|
|
47
|
+
})).toBeInTheDocument();
|
|
48
|
+
expect(getByRole('heading', {
|
|
49
|
+
name: 'Heading 5',
|
|
50
|
+
level: 5,
|
|
51
|
+
})).toBeInTheDocument();
|
|
52
|
+
expect(getByRole('heading', {
|
|
53
|
+
name: 'Heading 6',
|
|
54
|
+
level: 6,
|
|
55
|
+
})).toBeInTheDocument();
|
|
56
|
+
expect(getAllByRole('list')).toHaveLength(3);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
13
|
+
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
|
|
14
|
+
import { List, ListItem } from '../List';
|
|
15
|
+
import { Paragraph } from '../text/Paragraph';
|
|
16
|
+
import { HEADING_SIZE, Heading } from '../text/Heading';
|
|
17
|
+
import { Bold, Italic } from '../text/Inline';
|
|
18
|
+
import { firstChildAltSelector } from '../../../utils/misc';
|
|
19
|
+
const headingStyles = {
|
|
20
|
+
mt: 4,
|
|
21
|
+
[firstChildAltSelector]: {
|
|
22
|
+
mt: 0,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const paragraphStyles = {
|
|
26
|
+
mt: 4,
|
|
27
|
+
[firstChildAltSelector]: {
|
|
28
|
+
mt: 0,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
export const Markdown = (_a) => {
|
|
32
|
+
var { content } = _a, rest = __rest(_a, ["content"]);
|
|
33
|
+
return (_jsx("div", Object.assign({}, rest, { children: _jsx(ReactMarkdown, Object.assign({ components: {
|
|
34
|
+
h1: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.XL }, props, { standalone: true, sx: headingStyles, "aria-level": 1 }))),
|
|
35
|
+
h2: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG }, props, { standalone: true, sx: headingStyles, "aria-level": 2 }))),
|
|
36
|
+
h3: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, props, { standalone: true, sx: headingStyles, "aria-level": 3 }))),
|
|
37
|
+
h4: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, props, { standalone: true, sx: headingStyles, "aria-level": 4 }))),
|
|
38
|
+
h5: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, props, { standalone: true, sx: headingStyles, "aria-level": 5 }))),
|
|
39
|
+
h6: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, props, { standalone: true, sx: headingStyles, "aria-level": 6 }))),
|
|
40
|
+
ol: (props) => _jsx(List, Object.assign({}, props, { ordered: true, sx: { mt: 4 } })),
|
|
41
|
+
ul: (props) => _jsx(List, Object.assign({}, props, { sx: { mt: 4 } })),
|
|
42
|
+
li: (_a) => {
|
|
43
|
+
var { index, ordered } = _a, props = __rest(_a, ["index", "ordered"]);
|
|
44
|
+
return (_jsx(ListItem, Object.assign({ index: index }, props)));
|
|
45
|
+
},
|
|
46
|
+
p: (props) => _jsx(Paragraph, Object.assign({}, props, { sx: paragraphStyles })),
|
|
47
|
+
strong: (props) => _jsx(Bold, Object.assign({}, props)),
|
|
48
|
+
em: (props) => _jsx(Italic, Object.assign({}, props)),
|
|
49
|
+
} }, { children: content })) })));
|
|
50
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
/** @jsxImportSource theme-ui */
|
|
3
|
-
import { StyledElementProps } from
|
|
3
|
+
import { StyledElementProps } from '../../../theme';
|
|
4
4
|
type BoxProps = StyledElementProps<HTMLDivElement>;
|
|
5
5
|
export declare const Box: React.FC<BoxProps>;
|
|
6
6
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
/** @jsxImportSource theme-ui */
|
|
3
|
-
import { StyledElementProps } from
|
|
4
|
-
import { FlexHelperProps } from
|
|
3
|
+
import { StyledElementProps } from '../../../theme';
|
|
4
|
+
import { FlexHelperProps } from './Row';
|
|
5
5
|
type ColumnProps = StyledElementProps<HTMLDivElement, FlexHelperProps>;
|
|
6
6
|
export declare const Column: React.FC<ColumnProps>;
|
|
7
7
|
export {};
|
|
@@ -10,9 +10,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
|
-
import { convertFlexHelperProps } from
|
|
13
|
+
import { convertFlexHelperProps } from './Row';
|
|
14
14
|
export const Column = (_a) => {
|
|
15
15
|
var { sx, children } = _a, rest = __rest(_a, ["sx", "children"]);
|
|
16
16
|
const flexStyles = convertFlexHelperProps(rest);
|
|
17
|
-
return _jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign(Object.assign({}, flexStyles), sx), { display: 'flex', flexDirection: 'column' }) }, { children: children }));
|
|
17
|
+
return (_jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign(Object.assign({}, flexStyles), sx), { display: 'flex', flexDirection: 'column' }) }, { children: children })));
|
|
18
18
|
};
|
|
@@ -6,11 +6,11 @@ import { COLOR } from '../../../theme/colors';
|
|
|
6
6
|
const meta = {
|
|
7
7
|
title: 'Elements/Layout/Flex',
|
|
8
8
|
component: Row,
|
|
9
|
-
tags: ['autodocs']
|
|
9
|
+
tags: ['autodocs'],
|
|
10
10
|
};
|
|
11
11
|
export default meta;
|
|
12
12
|
export const Columns = {
|
|
13
|
-
render: () => (_jsxs(Row, Object.assign({ justify:
|
|
13
|
+
render: () => (_jsxs(Row, Object.assign({ justify: "space-between" }, { children: [_jsx(Column, { children: _jsx(Paragraph, { children: "Column 1" }) }), _jsx(Column, { children: _jsx(Paragraph, { children: "Column 2" }) }), _jsx(Column, { children: _jsx(Paragraph, { children: "Column 3" }) })] }))),
|
|
14
14
|
};
|
|
15
15
|
export const Rows = {
|
|
16
16
|
render: () => (_jsxs(Column, { children: [_jsx(Row, { children: _jsx(Paragraph, { children: "Row 1" }) }), _jsx(Row, { children: _jsx(Paragraph, { children: "Row 2" }) }), _jsx(Row, { children: _jsx(Paragraph, { children: "Row 3" }) })] })),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { render } from '../../../utils/test';
|
|
3
|
-
import { Row } from
|
|
4
|
-
import { Column } from
|
|
3
|
+
import { Row } from './Row';
|
|
4
|
+
import { Column } from './Column';
|
|
5
5
|
describe('Row', () => {
|
|
6
6
|
it('renders without throwing an error', () => {
|
|
7
7
|
const { getByText } = render(_jsx(Row, { children: "Foo" }));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
/** @jsxImportSource theme-ui */
|
|
3
|
-
import { CSSProperties, ThemeUICSSProperties } from
|
|
4
|
-
import { StyledElementProps } from
|
|
3
|
+
import { CSSProperties, ThemeUICSSProperties } from 'theme-ui';
|
|
4
|
+
import { StyledElementProps } from '../../../theme';
|
|
5
5
|
export declare const convertFlexHelperProps: (props: FlexHelperProps) => ThemeUICSSProperties;
|
|
6
6
|
export type FlexHelperProps = {
|
|
7
7
|
grow?: number;
|
|
@@ -40,5 +40,5 @@ export const convertFlexHelperProps = (props) => {
|
|
|
40
40
|
export const Row = (_a) => {
|
|
41
41
|
var { sx, children } = _a, rest = __rest(_a, ["sx", "children"]);
|
|
42
42
|
const flexStyles = convertFlexHelperProps(rest);
|
|
43
|
-
return _jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign(Object.assign({}, flexStyles), sx), { display: 'flex', flexDirection: 'row' }) }, { children: children }));
|
|
43
|
+
return (_jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign(Object.assign({}, flexStyles), sx), { display: 'flex', flexDirection: 'row' }) }, { children: children })));
|
|
44
44
|
};
|
|
@@ -14,24 +14,23 @@ const sizes = [
|
|
|
14
14
|
{ size: HEADING_SIZE.XL, label: 'Extra Large (Default Level 1)' },
|
|
15
15
|
{ size: HEADING_SIZE.LG, label: 'Large (Default Level 2)' },
|
|
16
16
|
{ size: HEADING_SIZE.MD, label: 'Medium (Default Level 3)' },
|
|
17
|
-
{ size: HEADING_SIZE.SM, label: 'Small (Default Level 4)' },
|
|
18
|
-
{ size: HEADING_SIZE.XS, label: 'Extra Small (Default Level 5)' },
|
|
17
|
+
{ size: HEADING_SIZE.SM, label: 'Small (Default Level 4-6)' },
|
|
19
18
|
];
|
|
20
19
|
export const Default = {
|
|
21
|
-
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size }, { children: size.label })) })))) })),
|
|
20
|
+
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size }, { children: size.label })) })))) })),
|
|
22
21
|
args: {
|
|
23
|
-
children:
|
|
24
|
-
}
|
|
22
|
+
children: 'Heading',
|
|
23
|
+
},
|
|
25
24
|
};
|
|
26
25
|
export const Color = {
|
|
27
|
-
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size, sx: { color: COLOR.
|
|
26
|
+
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size, sx: { color: COLOR.TEXT } }, { children: size.label })) })))) })),
|
|
28
27
|
args: {
|
|
29
|
-
children:
|
|
30
|
-
}
|
|
28
|
+
children: 'Heading',
|
|
29
|
+
},
|
|
31
30
|
};
|
|
32
31
|
export const Underline = {
|
|
33
|
-
render: () => (_jsx(Column, { children: sizes.map(size => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size, underline: true }, { children: size.label })) })))) })),
|
|
32
|
+
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsx(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: _jsx(Heading, Object.assign({ size: size.size, underline: true }, { children: size.label })) })))) })),
|
|
34
33
|
args: {
|
|
35
|
-
children:
|
|
36
|
-
}
|
|
34
|
+
children: 'Heading',
|
|
35
|
+
},
|
|
37
36
|
};
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { vi } from 'vitest';
|
|
12
12
|
import { render as _render } from '../../../../utils/test';
|
|
13
|
-
import { Heading } from
|
|
13
|
+
import { Heading } from '.';
|
|
14
14
|
import { GROUP_TYPE, Group } from '../../Group';
|
|
15
15
|
import { ENVIRONMENT } from '../../../providers/env';
|
|
16
16
|
const render = (component) => {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/** @jsxImportSource theme-ui */
|
|
2
|
-
import React from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TYPOGRAPHY_TYPE } from '../../../../theme/typography';
|
|
4
|
+
import { StyledElementProps } from '../../../../theme';
|
|
5
|
+
import { COLOR } from '../../../../theme/colors';
|
|
5
6
|
type HeaderProps = StyledElementProps<HTMLSpanElement, {
|
|
6
7
|
size?: HEADING_SIZE;
|
|
7
8
|
standalone?: boolean;
|
|
8
9
|
underline?: boolean;
|
|
9
10
|
underlineColor?: COLOR;
|
|
11
|
+
typography?: TYPOGRAPHY_TYPE;
|
|
12
|
+
level?: number;
|
|
10
13
|
}>;
|
|
11
14
|
export declare enum HEADING_SIZE {
|
|
12
|
-
XS = "xs",
|
|
13
15
|
SM = "sm",
|
|
14
16
|
MD = "md",
|
|
15
17
|
LG = "lg",
|
|
@@ -11,21 +11,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "theme-ui/jsx-runtime";
|
|
13
13
|
/** @jsxImportSource theme-ui */
|
|
14
|
-
import { useEffect } from
|
|
15
|
-
import { getTypographyStyles, TYPOGRAPHY_TYPE } from
|
|
16
|
-
import { GROUP_TYPE, useGroup } from
|
|
17
|
-
import { COLOR } from
|
|
18
|
-
import { useEnvironment } from
|
|
14
|
+
import { useEffect } from 'react';
|
|
15
|
+
import { getTypographyStyles, TYPOGRAPHY_TYPE, } from '../../../../theme/typography';
|
|
16
|
+
import { GROUP_TYPE, useGroup } from '../../Group';
|
|
17
|
+
import { COLOR } from '../../../../theme/colors';
|
|
18
|
+
import { useEnvironment } from '../../../providers/env';
|
|
19
19
|
export var HEADING_SIZE;
|
|
20
20
|
(function (HEADING_SIZE) {
|
|
21
|
-
HEADING_SIZE["XS"] = "xs";
|
|
22
21
|
HEADING_SIZE["SM"] = "sm";
|
|
23
22
|
HEADING_SIZE["MD"] = "md";
|
|
24
23
|
HEADING_SIZE["LG"] = "lg";
|
|
25
24
|
HEADING_SIZE["XL"] = "xl";
|
|
26
25
|
})(HEADING_SIZE || (HEADING_SIZE = {}));
|
|
27
26
|
const SIZE_TYPOGRAPHY_MAP = {
|
|
28
|
-
[HEADING_SIZE.XS]: TYPOGRAPHY_TYPE.HEADING_XSMALL,
|
|
29
27
|
[HEADING_SIZE.SM]: TYPOGRAPHY_TYPE.HEADING_SMALL,
|
|
30
28
|
[HEADING_SIZE.MD]: TYPOGRAPHY_TYPE.HEADING_MEDIUM,
|
|
31
29
|
[HEADING_SIZE.LG]: TYPOGRAPHY_TYPE.HEADING_LARGE,
|
|
@@ -36,24 +34,32 @@ const LEVEL_TYPOGRAPHY_MAP = {
|
|
|
36
34
|
2: TYPOGRAPHY_TYPE.HEADING_LARGE,
|
|
37
35
|
3: TYPOGRAPHY_TYPE.HEADING_MEDIUM,
|
|
38
36
|
4: TYPOGRAPHY_TYPE.HEADING_SMALL,
|
|
39
|
-
5: TYPOGRAPHY_TYPE.
|
|
37
|
+
5: TYPOGRAPHY_TYPE.HEADING_SMALL,
|
|
38
|
+
6: TYPOGRAPHY_TYPE.HEADING_SMALL,
|
|
40
39
|
};
|
|
41
40
|
export const Heading = (_a) => {
|
|
42
|
-
var { sx, size, standalone, underline, underlineColor } = _a, rest = __rest(_a, ["sx", "size", "standalone", "underline", "underlineColor"]);
|
|
43
|
-
const { level, labelId, type, trackHeadingRendered } = useGroup();
|
|
41
|
+
var { sx, size, standalone, underline, underlineColor, typography: typographyProp, level: levelParam } = _a, rest = __rest(_a, ["sx", "size", "standalone", "underline", "underlineColor", "typography", "level"]);
|
|
42
|
+
const { level: groupLevel, labelId, type, trackHeadingRendered } = useGroup();
|
|
44
43
|
const { flagInDevelopment } = useEnvironment();
|
|
44
|
+
// should prioritize explicitly passed level, eg if coming from markdown
|
|
45
|
+
const level = levelParam || groupLevel;
|
|
45
46
|
useEffect(() => {
|
|
46
47
|
trackHeadingRendered();
|
|
47
48
|
});
|
|
48
49
|
let typography = TYPOGRAPHY_TYPE.HEADING_MEDIUM;
|
|
49
|
-
if (
|
|
50
|
+
if (typographyProp) {
|
|
51
|
+
typography = typographyProp;
|
|
52
|
+
}
|
|
53
|
+
else if (size) {
|
|
50
54
|
typography = SIZE_TYPOGRAPHY_MAP[size];
|
|
51
55
|
}
|
|
52
56
|
else if (level) {
|
|
53
|
-
typography =
|
|
57
|
+
typography =
|
|
58
|
+
LEVEL_TYPOGRAPHY_MAP[level];
|
|
54
59
|
}
|
|
60
|
+
console.log(typography, level, size);
|
|
55
61
|
if (type !== GROUP_TYPE.REGION && !standalone) {
|
|
56
62
|
flagInDevelopment('Heading component should be used within a Group component with property type={GROUP_TYPE.REGION} or given the standalone flag');
|
|
57
63
|
}
|
|
58
|
-
return (_jsx("div", Object.assign({ id: labelId, role: "heading", "aria-level": level, sx: Object.assign(Object.assign({ py: 0, borderBottom: underline ? 'solid 2px' : undefined, borderBottomColor: underlineColor ? underlineColor : COLOR.SECONDARY }, getTypographyStyles(typography)), sx) }, rest)));
|
|
64
|
+
return (_jsx("div", Object.assign({ id: labelId, role: "heading", "aria-level": level, sx: Object.assign(Object.assign({ py: 0, borderBottom: underline ? 'solid 2px' : undefined, borderBottomColor: underlineColor ? underlineColor : COLOR.SECONDARY, color: COLOR.PRIMARY }, getTypographyStyles(typography)), sx) }, rest)));
|
|
59
65
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Bold, Italic } from '.';
|
|
3
|
+
import { Paragraph } from '../Paragraph';
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Elements/Inline',
|
|
6
|
+
component: Bold,
|
|
7
|
+
//👇 Enables auto-generated documentation for the component story
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const Default = {
|
|
12
|
+
render: () => (_jsxs(Paragraph, { children: ["Text with ", _jsx(Bold, { children: "bold content" }), " and ", _jsx(Italic, { children: "italic content" })] })),
|
|
13
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StyledElementProps } from '../../../../theme';
|
|
4
|
+
type InlineProps = StyledElementProps<HTMLSpanElement>;
|
|
5
|
+
export declare const Bold: React.FC<InlineProps>;
|
|
6
|
+
export declare const Italic: React.FC<InlineProps>;
|
|
7
|
+
export {};
|