@ndlib/component-library 0.0.10 → 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.
Files changed (131) hide show
  1. package/dist/FontLoader.d.ts +1 -0
  2. package/dist/FontLoader.js +4 -0
  3. package/dist/components/composites/Card/Card.stories.d.ts +9 -0
  4. package/dist/components/composites/Card/Card.stories.js +77 -0
  5. package/dist/components/composites/Card/Card.test.d.ts +1 -0
  6. package/dist/components/composites/Card/Card.test.js +29 -0
  7. package/dist/components/composites/Card/index.d.ts +22 -0
  8. package/dist/components/composites/Card/index.js +71 -0
  9. package/dist/components/elements/Alerts/Alert.stories.d.ts +9 -0
  10. package/dist/components/elements/Alerts/Alert.stories.js +41 -0
  11. package/dist/components/elements/Alerts/Alerts.stories.d.ts +6 -0
  12. package/dist/components/elements/Alerts/Alerts.stories.js +12 -0
  13. package/dist/components/elements/Alerts/Alerts.test.d.ts +1 -0
  14. package/dist/components/elements/Alerts/Alerts.test.js +62 -0
  15. package/dist/components/elements/Alerts/index.d.ts +15 -0
  16. package/dist/components/elements/Alerts/index.js +63 -0
  17. package/dist/components/elements/BrandingBar/BrandingBar.stories.js +1 -1
  18. package/dist/components/elements/BrandingBar/index.js +5 -5
  19. package/dist/components/elements/Button/Button.stories.d.ts +4 -0
  20. package/dist/components/elements/Button/Button.stories.js +42 -9
  21. package/dist/components/elements/Button/Button.test.js +11 -2
  22. package/dist/components/elements/Button/index.d.ts +16 -11
  23. package/dist/components/elements/Button/index.js +84 -34
  24. package/dist/components/elements/Fields/Checkbox/Checkbox.stories.d.ts +6 -0
  25. package/dist/components/elements/Fields/Checkbox/Checkbox.stories.js +17 -0
  26. package/dist/components/elements/Fields/Checkbox/index.d.ts +9 -0
  27. package/dist/components/elements/Fields/Checkbox/index.js +22 -0
  28. package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.d.ts +6 -0
  29. package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.js +23 -0
  30. package/dist/components/elements/Fields/CheckboxGroup/index.d.ts +14 -0
  31. package/dist/components/elements/Fields/CheckboxGroup/index.js +35 -0
  32. package/dist/components/elements/Fields/Radio/Radio.stories.d.ts +6 -0
  33. package/dist/components/elements/Fields/Radio/Radio.stories.js +17 -0
  34. package/dist/components/elements/Fields/Radio/index.d.ts +9 -0
  35. package/dist/components/elements/Fields/Radio/index.js +22 -0
  36. package/dist/components/elements/Fields/RadioGroup/RadioGroup.stories.d.ts +6 -0
  37. package/dist/components/elements/Fields/RadioGroup/RadioGroup.stories.js +23 -0
  38. package/dist/components/elements/Fields/RadioGroup/index.d.ts +14 -0
  39. package/dist/components/elements/Fields/RadioGroup/index.js +28 -0
  40. package/dist/components/elements/Fields/Select/Select.stories.d.ts +6 -0
  41. package/dist/components/elements/Fields/Select/Select.stories.js +32 -0
  42. package/dist/components/elements/Fields/Select/index.d.ts +16 -0
  43. package/dist/components/elements/Fields/Select/index.js +136 -0
  44. package/dist/components/elements/Fields/TextInput/TextInput.stories.d.ts +6 -0
  45. package/dist/components/elements/Fields/TextInput/TextInput.stories.js +25 -0
  46. package/dist/components/elements/Fields/TextInput/index.d.ts +17 -0
  47. package/dist/components/elements/Fields/TextInput/index.js +60 -0
  48. package/dist/components/elements/Fields/option.d.ts +15 -0
  49. package/dist/components/elements/Fields/option.js +3 -0
  50. package/dist/components/elements/Group/index.js +3 -3
  51. package/dist/components/elements/Icon/Icon.stories.d.ts +7 -0
  52. package/dist/components/elements/Icon/Icon.stories.js +29 -0
  53. package/dist/components/elements/Icon/Icon.test.d.ts +1 -0
  54. package/dist/components/elements/Icon/Icon.test.js +26 -0
  55. package/dist/components/elements/Icon/index.d.ts +11 -0
  56. package/dist/components/elements/Icon/index.js +25 -0
  57. package/dist/components/elements/Link/Link.stories.js +3 -3
  58. package/dist/components/elements/Link/Link.test.js +13 -13
  59. package/dist/components/elements/Link/index.d.ts +2 -2
  60. package/dist/components/elements/Link/index.js +4 -4
  61. package/dist/components/elements/List/List.stories.d.ts +9 -0
  62. package/dist/components/elements/List/List.stories.js +31 -0
  63. package/dist/components/elements/List/List.test.d.ts +1 -0
  64. package/dist/components/elements/List/List.test.js +24 -0
  65. package/dist/components/elements/List/index.d.ts +21 -0
  66. package/dist/components/elements/List/index.js +75 -0
  67. package/dist/components/elements/ListBox/Listbox.stories.d.ts +6 -0
  68. package/dist/components/elements/ListBox/Listbox.stories.js +17 -0
  69. package/dist/components/elements/ListBox/index.d.ts +32 -0
  70. package/dist/components/elements/ListBox/index.js +50 -0
  71. package/dist/components/elements/Markdown/Markdown.stories.d.ts +6 -0
  72. package/dist/components/elements/Markdown/Markdown.stories.js +53 -0
  73. package/dist/components/elements/Markdown/Markdown.test.d.ts +1 -0
  74. package/dist/components/elements/Markdown/Markdown.test.js +58 -0
  75. package/dist/components/elements/Markdown/index.d.ts +7 -0
  76. package/dist/components/elements/Markdown/index.js +50 -0
  77. package/dist/components/elements/layout/Box.d.ts +1 -1
  78. package/dist/components/elements/layout/Box.stories.js +1 -1
  79. package/dist/components/elements/layout/Column.d.ts +2 -2
  80. package/dist/components/elements/layout/Column.js +2 -2
  81. package/dist/components/elements/layout/Flex.stories.js +2 -2
  82. package/dist/components/elements/layout/Flex.test.js +2 -2
  83. package/dist/components/elements/layout/Row.d.ts +2 -2
  84. package/dist/components/elements/layout/Row.js +1 -1
  85. package/dist/components/elements/text/Heading/Heading.stories.js +10 -11
  86. package/dist/components/elements/text/Heading/Heading.test.js +1 -1
  87. package/dist/components/elements/text/Heading/index.d.ts +6 -4
  88. package/dist/components/elements/text/Heading/index.js +19 -13
  89. package/dist/components/elements/text/Inline/Inline.stories.d.ts +6 -0
  90. package/dist/components/elements/text/Inline/Inline.stories.js +13 -0
  91. package/dist/components/elements/text/Inline/index.d.ts +7 -0
  92. package/dist/components/elements/text/Inline/index.js +21 -0
  93. package/dist/components/elements/text/Label/Label.stories.js +3 -3
  94. package/dist/components/elements/text/Label/Label.test.js +2 -2
  95. package/dist/components/elements/text/Label/index.d.ts +3 -3
  96. package/dist/components/elements/text/Label/index.js +4 -4
  97. package/dist/components/elements/text/Paragraph/Paragraph.stories.js +2 -2
  98. package/dist/components/elements/text/Paragraph/Paragraph.test.js +1 -1
  99. package/dist/components/elements/text/Paragraph/index.d.ts +2 -2
  100. package/dist/components/elements/text/Paragraph/index.js +2 -2
  101. package/dist/components/providers/alerts.d.ts +41 -0
  102. package/dist/components/providers/alerts.js +133 -0
  103. package/dist/components/providers/componentConfig.d.ts +3 -3
  104. package/dist/components/providers/componentConfig.js +5 -4
  105. package/dist/components/providers/env.d.ts +1 -1
  106. package/dist/components/providers/env.js +3 -3
  107. package/dist/components/providers/theme.js +1 -1
  108. package/dist/components/providers/ui.d.ts +7 -3
  109. package/dist/components/providers/ui.js +8 -6
  110. package/dist/index.d.ts +5 -1
  111. package/dist/index.js +5 -1
  112. package/dist/theme/Color.stories.js +17 -2
  113. package/dist/theme/Typography.stories.d.ts +6 -0
  114. package/dist/theme/Typography.stories.js +43 -0
  115. package/dist/theme/colors.d.ts +11 -1
  116. package/dist/theme/colors.js +20 -0
  117. package/dist/theme/custom.d.ts +3 -0
  118. package/dist/theme/custom.js +5 -0
  119. package/dist/theme/index.d.ts +139 -4
  120. package/dist/theme/index.js +18 -12
  121. package/dist/theme/typography.d.ts +47 -6
  122. package/dist/theme/typography.js +74 -36
  123. package/dist/utils/hooks/useStorage.d.ts +14 -0
  124. package/dist/utils/hooks/useStorage.js +31 -0
  125. package/dist/utils/hooks/useUniqueHtmlId.d.ts +1 -0
  126. package/dist/utils/hooks/useUniqueHtmlId.js +7 -0
  127. package/dist/utils/misc.d.ts +7 -0
  128. package/dist/utils/misc.js +13 -1
  129. package/dist/utils/test.js +3 -1
  130. package/global.css +4 -9
  131. package/package.json +19 -12
@@ -0,0 +1,136 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
4
+ import { useFloating, size as sizeMiddleware, offset, autoPlacement, } from '@floating-ui/react';
5
+ import { TYPOGRAPHY_TYPE, getTypographyStyles, } from '../../../../theme/typography';
6
+ import { useTheme } from '../../../../theme';
7
+ import { COLOR } from '../../../..';
8
+ import { INPUT_SIZE } from '../TextInput';
9
+ import { ListBox } from '../../ListBox';
10
+ import { BUTTON_SIZE, BUTTON_TYPE, Button } from '../../Button';
11
+ import { defaultRenderOptionLabel, getOptionId, } from '../option';
12
+ import { useUniqueHtmlId } from '../../../../utils/hooks/useUniqueHtmlId';
13
+ import { KEY_CODES } from '../../../../utils/misc';
14
+ const typographyMap = {
15
+ [INPUT_SIZE.SM]: TYPOGRAPHY_TYPE.PARAGRAPH_SMALL,
16
+ [INPUT_SIZE.MD]: TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM,
17
+ [INPUT_SIZE.LG]: TYPOGRAPHY_TYPE.PARAGRAPH_LARGE,
18
+ };
19
+ const defaultHeight = {
20
+ [INPUT_SIZE.SM]: '2rem',
21
+ [INPUT_SIZE.MD]: '2.5rem',
22
+ [INPUT_SIZE.LG]: '3rem',
23
+ };
24
+ const buttonSizeMap = {
25
+ [INPUT_SIZE.SM]: BUTTON_SIZE.SM,
26
+ [INPUT_SIZE.MD]: BUTTON_SIZE.MD,
27
+ [INPUT_SIZE.LG]: BUTTON_SIZE.LG,
28
+ };
29
+ const DEFAULT_WIDTH = '16rem';
30
+ export function Select({ size: sizeParam, placeholder, leftIcon, value, onSelectOption, options, renderOption, renderOptionLabel: renderOptionLabelParam, sx, }) {
31
+ const theme = useTheme();
32
+ const listboxId = useUniqueHtmlId('select-list-box');
33
+ const [isOpen, setIsOpen] = useState(false);
34
+ const [stagedOptionValue, setStagedOptionValue] = useState();
35
+ const currentOption = useMemo(() => {
36
+ return options.find((option) => option.value === value);
37
+ }, [options, value]);
38
+ const getNextOptionValue = () => {
39
+ if (stagedOptionValue) {
40
+ const currentIndex = options
41
+ .map((option) => option.value)
42
+ .indexOf(stagedOptionValue);
43
+ const nextIndex = Math.min(currentIndex + 1, options.length - 1);
44
+ return options[nextIndex].value;
45
+ }
46
+ else {
47
+ setIsOpen(true);
48
+ return options[0].value;
49
+ }
50
+ };
51
+ const getPrevOptionValue = () => {
52
+ if (stagedOptionValue) {
53
+ const currentIndex = options
54
+ .map((option) => option.value)
55
+ .indexOf(stagedOptionValue);
56
+ const nextIndex = Math.max(currentIndex - 1, 0);
57
+ return options[nextIndex].value;
58
+ }
59
+ else {
60
+ setIsOpen(true);
61
+ return options[options.length - 1].value;
62
+ }
63
+ };
64
+ const [dropdownMinWidth, setDropdownMinWidth] = useState('0px');
65
+ const { refs, floatingStyles } = useFloating({
66
+ placement: 'bottom-start',
67
+ middleware: [
68
+ offset(2),
69
+ sizeMiddleware({
70
+ apply({ rects }) {
71
+ setDropdownMinWidth(`${rects.reference.width}px`);
72
+ },
73
+ }),
74
+ autoPlacement({
75
+ allowedPlacements: ['top-start', 'bottom-start'],
76
+ }),
77
+ ],
78
+ });
79
+ const close = () => {
80
+ setStagedOptionValue(undefined);
81
+ setIsOpen(false);
82
+ };
83
+ const open = () => {
84
+ setStagedOptionValue(stagedOptionValue || value || options[0].value);
85
+ setIsOpen(true);
86
+ };
87
+ const onKeyDown = (e) => {
88
+ if (e.key === KEY_CODES.ARROW_DOWN) {
89
+ const nextValue = getNextOptionValue();
90
+ setStagedOptionValue(nextValue);
91
+ }
92
+ if (e.key === KEY_CODES.ARROW_UP) {
93
+ const prevValue = getPrevOptionValue();
94
+ setStagedOptionValue(prevValue);
95
+ }
96
+ if (e.key === KEY_CODES.ENTER) {
97
+ if (!isOpen) {
98
+ open();
99
+ }
100
+ if (isOpen && stagedOptionValue && onSelectOption) {
101
+ onSelectOption(stagedOptionValue);
102
+ close();
103
+ }
104
+ }
105
+ if (e.key === KEY_CODES.ESCAPE) {
106
+ close();
107
+ }
108
+ };
109
+ const size = sizeParam || INPUT_SIZE.MD;
110
+ const buttonSize = buttonSizeMap[size];
111
+ const height = defaultHeight[size];
112
+ const typography = typographyMap[size];
113
+ const typographyStyles = getTypographyStyles(typography);
114
+ const renderOptionLabel = renderOptionLabelParam || defaultRenderOptionLabel;
115
+ return (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ ref: refs.setReference,
116
+ // A11y attributes
117
+ role: "combobox", "aria-controls": listboxId, "aria-expanded": isOpen, "aria-autocomplete": "none", "aria-activedescendant": isOpen && stagedOptionValue
118
+ ? getOptionId(stagedOptionValue)
119
+ : undefined,
120
+ // Style config
121
+ type: BUTTON_TYPE.OUTLINE, size: buttonSize, onBlur: () => close(), onFocus: () => open(), onKeyDown: onKeyDown, onMouseDown: () => {
122
+ if (!isOpen) {
123
+ open();
124
+ }
125
+ else {
126
+ close();
127
+ }
128
+ }, sx: Object.assign(Object.assign({ height, width: DEFAULT_WIDTH, border: 'solid 1px', borderColor: COLOR.LIGHT_GRAY, borderRadius: '4px', flexDirection: 'row', alignItems: 'center', position: 'relative', ':hover': {
129
+ boxShadow: theme.boxShadow.NORMAL,
130
+ }, ':focus': {
131
+ boxShadow: theme.boxShadow.NORMAL,
132
+ } }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (value) => {
133
+ onSelectOption && onSelectOption(value);
134
+ close();
135
+ }, ref: refs.setFloating, renderOption: renderOption, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { zIndex: 1 }) }))] }));
136
+ }
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { TextInput } from '.';
3
+ declare const meta: Meta<typeof TextInput>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof TextInput>;
6
+ export declare const Default: Story;
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import SearchIcon from '@mui/icons-material/Search';
3
+ import { INPUT_SIZE, TextInput } from '.';
4
+ import { useState } from 'react';
5
+ import { Column } from '../../layout/Column';
6
+ import { Group } from '../../Group';
7
+ import { Heading, HEADING_SIZE } from '../../text/Heading';
8
+ const meta = {
9
+ title: 'Elements/Fields/TextInput',
10
+ component: TextInput,
11
+ tags: ['autodocs'],
12
+ };
13
+ export default meta;
14
+ const sizes = [
15
+ { label: 'Large', size: INPUT_SIZE.LG },
16
+ { label: 'Medium', size: INPUT_SIZE.MD },
17
+ { label: 'Small', size: INPUT_SIZE.SM },
18
+ ];
19
+ const StatefulInput = (props) => {
20
+ const [value, setValue] = useState('');
21
+ return _jsx(TextInput, Object.assign({ value: value, onChange: setValue }, props));
22
+ };
23
+ export const Default = {
24
+ 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: 1 } })] }))) })),
25
+ };
@@ -0,0 +1,17 @@
1
+ /** @jsxImportSource theme-ui */
2
+ import React from 'react';
3
+ import { StyledElementProps } from '../../../../theme';
4
+ export declare enum INPUT_SIZE {
5
+ SM = "sm",
6
+ MD = "md",
7
+ LG = "lg"
8
+ }
9
+ type TextInputProps = StyledElementProps<HTMLInputElement, {
10
+ size?: INPUT_SIZE;
11
+ leftIcon?: React.FC<any>;
12
+ inline?: boolean;
13
+ value: string;
14
+ onChange: (value: string) => void;
15
+ }, string>;
16
+ export declare const TextInput: React.FC<TextInputProps>;
17
+ export {};
@@ -0,0 +1,60 @@
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
+ import { TYPOGRAPHY_TYPE, getIconSize, getTypographyStyles, } from '../../../../theme/typography';
14
+ import { useTheme } from '../../../../theme';
15
+ import { COLOR } from '../../../..';
16
+ import { Icon } from '../../Icon';
17
+ export var INPUT_SIZE;
18
+ (function (INPUT_SIZE) {
19
+ INPUT_SIZE["SM"] = "sm";
20
+ INPUT_SIZE["MD"] = "md";
21
+ INPUT_SIZE["LG"] = "lg";
22
+ })(INPUT_SIZE || (INPUT_SIZE = {}));
23
+ const typographyMap = {
24
+ [INPUT_SIZE.SM]: TYPOGRAPHY_TYPE.PARAGRAPH_SMALL,
25
+ [INPUT_SIZE.MD]: TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM,
26
+ [INPUT_SIZE.LG]: TYPOGRAPHY_TYPE.PARAGRAPH_LARGE,
27
+ };
28
+ const defaultPaddingX = {
29
+ [INPUT_SIZE.SM]: 2,
30
+ [INPUT_SIZE.MD]: 3,
31
+ [INPUT_SIZE.LG]: 3,
32
+ };
33
+ const defaultHeight = {
34
+ [INPUT_SIZE.SM]: '2rem',
35
+ [INPUT_SIZE.MD]: '2.5rem',
36
+ [INPUT_SIZE.LG]: '3rem',
37
+ };
38
+ export const TextInput = (_a) => {
39
+ var { value, onChange, inline, size: sizeParam, leftIcon, sx } = _a, rest = __rest(_a, ["value", "onChange", "inline", "size", "leftIcon", "sx"]);
40
+ const theme = useTheme();
41
+ const size = sizeParam || INPUT_SIZE.MD;
42
+ const display = inline === false ? 'flex' : 'inline-flex';
43
+ const paddingX = defaultPaddingX[size];
44
+ const height = defaultHeight[size];
45
+ const typography = typographyMap[size];
46
+ const typographyStyles = getTypographyStyles(typography);
47
+ return (_jsxs("div", Object.assign({ sx: Object.assign(Object.assign({ height,
48
+ display, px: paddingX, border: 'solid 1px', borderColor: COLOR.LIGHT_GRAY, borderRadius: '4px', flexDirection: 'row', alignItems: 'center', ':hover': {
49
+ boxShadow: theme.boxShadow.NORMAL,
50
+ }, ':focus': {
51
+ boxShadow: theme.boxShadow.NORMAL,
52
+ } }, typographyStyles), sx) }, { children: [leftIcon && (_jsx(Icon, { icon: leftIcon, sx: {
53
+ mr: 2,
54
+ fontSize: getIconSize(typographyStyles.fontSize),
55
+ } })), _jsx("input", Object.assign({ value: value, onChange: (event) => {
56
+ onChange(event.target.value);
57
+ }, sx: Object.assign(Object.assign({ px: 0, py: 0, border: 'none' }, typographyStyles), { ':focus': {
58
+ outline: 'none',
59
+ } }) }, rest))] })));
60
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ export type Key = string | number;
3
+ export interface BasicOption<Value extends Key> {
4
+ value: Value;
5
+ label?: string;
6
+ }
7
+ export type RenderOption<Value extends Key, Option extends BasicOption<Value>> = (params: {
8
+ option: Option;
9
+ selected?: boolean;
10
+ focused?: boolean;
11
+ }) => React.ReactNode;
12
+ export type RenderOptionLabel<Option extends BasicOption<Key>> = (option: Option) => string;
13
+ export declare const getOptionId: (value: Key) => string;
14
+ export declare const defaultRenderOption: RenderOption<Key, any>;
15
+ export declare const defaultRenderOptionLabel: RenderOptionLabel<any>;
@@ -0,0 +1,3 @@
1
+ export const getOptionId = (value) => `option-id-${value}`;
2
+ export const defaultRenderOption = ({ option }) => option.label;
3
+ export const defaultRenderOptionLabel = (option) => option.label;
@@ -22,13 +22,13 @@ export var GROUP_TYPE;
22
22
  const GROUP_TYPE_ROLE_MAP = {
23
23
  [GROUP_TYPE.REGION]: 'region',
24
24
  [GROUP_TYPE.GROUP]: 'group',
25
- [GROUP_TYPE.RAW]: 'group'
25
+ [GROUP_TYPE.RAW]: 'group',
26
26
  };
27
27
  const GroupContext = React.createContext({
28
28
  level: 0,
29
29
  labelId: '',
30
30
  labelTargetId: '',
31
- trackHeadingRendered: () => { }
31
+ trackHeadingRendered: () => { },
32
32
  });
33
33
  export const useGroup = () => React.useContext(GroupContext);
34
34
  export const Group = (_a) => {
@@ -40,7 +40,7 @@ export const Group = (_a) => {
40
40
  const labelId = `group-label-${randomSlug}`;
41
41
  const labelTargetId = `labeled-${randomSlug}`;
42
42
  const headingRenderTracker = useRef({
43
- hasHeadingRendered: false
43
+ hasHeadingRendered: false,
44
44
  });
45
45
  const trackHeadingRendered = () => {
46
46
  headingRenderTracker.current.hasHeadingRendered = true;
@@ -0,0 +1,7 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Icon } from './';
3
+ declare const meta: Meta<typeof Icon>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof Icon>;
6
+ export declare const Default: Story;
7
+ export declare const CustomColor: Story;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { GROUP_TYPE, Group } from '../Group';
3
+ import { HEADING_SIZE, Heading } from '../text/Heading';
4
+ import { Column } from '../layout/Column';
5
+ import { Icon } from './';
6
+ import AccessAlarmIcon from '@mui/icons-material/AccessAlarm';
7
+ import { COLOR } from '../../../theme/colors';
8
+ import { FONT_SIZE } from '../../../theme/typography';
9
+ const meta = {
10
+ title: 'Elements/Icon',
11
+ component: Icon,
12
+ };
13
+ export default meta;
14
+ const sizes = [
15
+ { size: FONT_SIZE.XXL, label: 'XX Large' },
16
+ { size: FONT_SIZE.XL, label: 'X Large' },
17
+ { size: FONT_SIZE.LG, label: 'Large' },
18
+ { size: FONT_SIZE.ML, label: 'Medium Large' },
19
+ { size: FONT_SIZE.MD, label: 'Medium' },
20
+ { size: FONT_SIZE.MS, label: 'Medium Small' },
21
+ { size: FONT_SIZE.SM, label: 'Small' },
22
+ { size: FONT_SIZE.XS, label: 'X Small' },
23
+ ];
24
+ export const Default = {
25
+ render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(Icon, { icon: AccessAlarmIcon, size: size.size })] })))) })),
26
+ };
27
+ export const CustomColor = {
28
+ render: () => (_jsx(Icon, { icon: AccessAlarmIcon, color: COLOR.SECONDARY, size: FONT_SIZE.LG })),
29
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render } from '../../../utils/test';
3
+ import { Icon } from '.';
4
+ import { SPACING } from '../../../theme';
5
+ import { FONT_SIZE, fontSizeMap } from '../../../theme/typography';
6
+ const MockIcon = () => {
7
+ return _jsx("div", { children: "Mock Icon" });
8
+ };
9
+ describe('Icon', () => {
10
+ it('renders component passed to it', () => {
11
+ const { getByText } = render(_jsx(Icon, { icon: MockIcon }));
12
+ expect(getByText('Mock Icon')).toBeInTheDocument();
13
+ });
14
+ it('passes font size to outer wrapper', () => {
15
+ const { container } = render(_jsx(Icon, { icon: MockIcon, size: FONT_SIZE.MD }));
16
+ expect(container.childNodes[0]).toHaveStyle({
17
+ fontSize: fontSizeMap[FONT_SIZE.MD],
18
+ });
19
+ });
20
+ it('passes custom styles to outer wrapper', () => {
21
+ const { container } = render(_jsx(Icon, { icon: MockIcon, sx: { p: 1 } }));
22
+ expect(container.childNodes[0]).toHaveStyle({
23
+ padding: SPACING[1],
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,11 @@
1
+ /** @jsxImportSource theme-ui */
2
+ import React from 'react';
3
+ import { COLOR } from '../../../theme/colors';
4
+ import { StyledElementProps } from '../../../theme';
5
+ import { FONT_SIZE } from '../../../theme/typography';
6
+ export type IconProps = StyledElementProps<HTMLDivElement, {
7
+ icon: React.FC<any>;
8
+ size?: FONT_SIZE;
9
+ color?: COLOR;
10
+ }>;
11
+ export declare const Icon: React.FC<IconProps>;
@@ -0,0 +1,25 @@
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, colors } from '../../../theme/colors';
16
+ export const Icon = (_a) => {
17
+ var { icon, size, color, sx } = _a, rest = __rest(_a, ["icon", "size", "color", "sx"]);
18
+ const InnerComponent = icon;
19
+ return (_jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign({}, sx), { fontSize: size, display: 'flex', alignItems: 'center', justifyContent: 'center' }) }, { children: React.createElement(InnerComponent, {
20
+ fontSize: 'inherit',
21
+ sx: {
22
+ color: colors[color || COLOR.PRIMARY],
23
+ },
24
+ }) })));
25
+ };
@@ -14,8 +14,8 @@ const sizes = [
14
14
  { size: LINK_SIZE.SM, label: 'Small' },
15
15
  ];
16
16
  export const Default = {
17
- render: () => (_jsx(Column, { children: sizes.map(size => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(Link, Object.assign({ size: size.size, to: "/" }, { children: "Click Me" }))] }))) })),
17
+ render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(Link, Object.assign({ size: size.size, to: "/" }, { children: "Click Me" }))] }))) })),
18
18
  args: {
19
- children: "Click Me"
20
- }
19
+ children: 'Click Me',
20
+ },
21
21
  };
@@ -1,14 +1,14 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { render } from '../../../utils/test';
3
- import { Link } from ".";
3
+ import { Link } from '.';
4
4
  import { DefaultLink } from '../../providers/componentConfig';
5
5
  const CUSTOM_INTERNAL_TEST_ID = 'internal-link-test-id';
6
6
  const CUSTOM_EXTERNAL_TEST_ID = 'external-link-test-id';
7
7
  const CustomInternalLink = (props) => {
8
- return (_jsx(DefaultLink, Object.assign({ "data-testid": CUSTOM_INTERNAL_TEST_ID }, props)));
8
+ return _jsx(DefaultLink, Object.assign({ "data-testid": CUSTOM_INTERNAL_TEST_ID }, props));
9
9
  };
10
10
  const CustomExternalLink = (props) => {
11
- return (_jsx(DefaultLink, Object.assign({ "data-testid": CUSTOM_EXTERNAL_TEST_ID }, props)));
11
+ return _jsx(DefaultLink, Object.assign({ "data-testid": CUSTOM_EXTERNAL_TEST_ID }, props));
12
12
  };
13
13
  describe('Link', () => {
14
14
  it('renders default external link component without throwing', () => {
@@ -24,9 +24,9 @@ describe('Link', () => {
24
24
  components: {
25
25
  link: {
26
26
  externalLinkComponent: CustomExternalLink,
27
- internalLinkComponent: CustomInternalLink
28
- }
29
- }
27
+ internalLinkComponent: CustomInternalLink,
28
+ },
29
+ },
30
30
  });
31
31
  expect(getByTestId(CUSTOM_EXTERNAL_TEST_ID)).toBeDefined();
32
32
  expect(() => getByTestId(CUSTOM_INTERNAL_TEST_ID)).toThrow();
@@ -36,21 +36,21 @@ describe('Link', () => {
36
36
  components: {
37
37
  link: {
38
38
  externalLinkComponent: CustomExternalLink,
39
- internalLinkComponent: CustomInternalLink
40
- }
41
- }
39
+ internalLinkComponent: CustomInternalLink,
40
+ },
41
+ },
42
42
  });
43
43
  expect(getByTestId(CUSTOM_INTERNAL_TEST_ID)).toBeDefined();
44
44
  expect(() => getByTestId(CUSTOM_EXTERNAL_TEST_ID)).toThrow();
45
45
  });
46
46
  it('passes styles to custom component', () => {
47
- const { getByTestId } = render((_jsxs(_Fragment, { children: [_jsx(Link, Object.assign({ to: "https://google.com", sx: { mt: 1 } }, { children: "Foo" })), _jsx(Link, Object.assign({ to: "/test/route", sx: { mt: 1 } }, { children: "Foo" }))] })), {
47
+ const { getByTestId } = render(_jsxs(_Fragment, { children: [_jsx(Link, Object.assign({ to: "https://google.com", sx: { mt: 1 } }, { children: "Foo" })), _jsx(Link, Object.assign({ to: "/test/route", sx: { mt: 1 } }, { children: "Foo" }))] }), {
48
48
  components: {
49
49
  link: {
50
50
  externalLinkComponent: CustomExternalLink,
51
- internalLinkComponent: CustomInternalLink
52
- }
53
- }
51
+ internalLinkComponent: CustomInternalLink,
52
+ },
53
+ },
54
54
  });
55
55
  expect(getByTestId(CUSTOM_EXTERNAL_TEST_ID)).toHaveStyle(`margin-top: 0.25rem`);
56
56
  expect(getByTestId(CUSTOM_INTERNAL_TEST_ID)).toHaveStyle(`margin-top: 0.25rem`);
@@ -1,6 +1,6 @@
1
1
  /** @jsxImportSource theme-ui */
2
- import React from "react";
3
- import { StyledElementProps } from "../../../theme";
2
+ import React from 'react';
3
+ import { StyledElementProps } from '../../../theme';
4
4
  type LinkProps = StyledElementProps<HTMLSpanElement, {
5
5
  to: string;
6
6
  size?: LINK_SIZE;
@@ -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 { useComponentConfig } from "../../providers/componentConfig";
14
- import { COLOR } from "../../../theme/colors";
15
- import { TYPOGRAPHY_TYPE, getTypographyStyles } from "../../../theme/typography";
13
+ import { useComponentConfig } from '../../providers/componentConfig';
14
+ import { COLOR } from '../../../theme/colors';
15
+ import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
16
16
  export var LINK_SIZE;
17
17
  (function (LINK_SIZE) {
18
18
  LINK_SIZE["SM"] = "sm";
@@ -22,7 +22,7 @@ export var LINK_SIZE;
22
22
  const SIZE_TYPOGRAPHY_MAP = {
23
23
  [LINK_SIZE.SM]: TYPOGRAPHY_TYPE.CONTROL_SMALL,
24
24
  [LINK_SIZE.MD]: TYPOGRAPHY_TYPE.CONTROL_MEDIUM,
25
- [LINK_SIZE.LG]: TYPOGRAPHY_TYPE.CONTROL_LARGE
25
+ [LINK_SIZE.LG]: TYPOGRAPHY_TYPE.CONTROL_LARGE,
26
26
  };
27
27
  export const Link = (_a) => {
28
28
  var { size, to, sx } = _a, rest = __rest(_a, ["size", "to", "sx"]);
@@ -0,0 +1,9 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { List } from './index';
3
+ declare const meta: Meta<typeof List>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof List>;
6
+ export declare const Default: Story;
7
+ export declare const Sizes: Story;
8
+ export declare const Ordered: Story;
9
+ export declare const CustomIcon: Story;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import ChevronRightIcon from '@mui/icons-material/ChevronRight';
3
+ import { LIST_SIZE, List, ListItem } from './index';
4
+ import { Row } from '../layout/Row';
5
+ import { Column } from '../layout/Column';
6
+ import { HEADING_SIZE, Heading } from '../text/Heading';
7
+ import { GROUP_TYPE, Group } from '../Group';
8
+ import { COLOR } from '../../..';
9
+ const meta = {
10
+ title: 'Elements/List',
11
+ component: List,
12
+ tags: ['autodocs'],
13
+ };
14
+ export default meta;
15
+ export const Default = {
16
+ render: () => (_jsx(Row, { children: _jsxs(List, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "List Item 1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "List Item 2" })), _jsxs(ListItem, Object.assign({ index: 2 }, { children: ["List Item 3", _jsxs(List, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "List Item 3.1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "List Item 3.2" }))] })] }))] }) })),
17
+ };
18
+ const sizes = [
19
+ { size: LIST_SIZE.LG, label: 'Large' },
20
+ { size: LIST_SIZE.MD, label: 'Medium' },
21
+ { size: LIST_SIZE.SM, label: 'Small' },
22
+ ];
23
+ export const Sizes = {
24
+ render: () => (_jsx(Column, { children: sizes.map((size, i) => (_jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION, sx: { mt: 3 } }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, { children: size.label })), _jsx(Row, Object.assign({ sx: { mt: 2 } }, { children: _jsxs(List, Object.assign({ size: size.size }, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "List Item 1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "List Item 2" })), _jsx(ListItem, Object.assign({ index: 2 }, { children: "List Item 3" }))] })) }))] }), i))) })),
25
+ };
26
+ export const Ordered = {
27
+ render: () => (_jsx(Row, { children: _jsxs(List, Object.assign({ icon: ChevronRightIcon, ordered: true }, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "List Item 1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "List Item 2" })), _jsx(ListItem, Object.assign({ index: 2 }, { children: "List Item 3" }))] })) })),
28
+ };
29
+ export const CustomIcon = {
30
+ render: () => (_jsx(Row, { children: _jsxs(List, Object.assign({ icon: ChevronRightIcon, iconColor: COLOR.PRIMARY }, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "List Item 1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "List Item 2" })), _jsx(ListItem, Object.assign({ index: 2 }, { children: "List Item 3" }))] })) })),
31
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { render } from '../../../utils/test';
12
+ import { List, ListItem } from '.';
13
+ const MockIcon = () => _jsx("div", { "data-testid": "mock-icon" });
14
+ describe('List', () => {
15
+ it('renders children inside list', () => {
16
+ const { getByRole, getAllByRole } = render(_jsxs(List, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "Item 1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "Item 2" }))] }));
17
+ expect(getByRole('list')).toBeDefined();
18
+ expect(getAllByRole('listitem')).toHaveLength(2);
19
+ });
20
+ it('renders custom component if provided', () => __awaiter(void 0, void 0, void 0, function* () {
21
+ const { getAllByTestId } = render(_jsxs(List, Object.assign({ icon: MockIcon }, { children: [_jsx(ListItem, Object.assign({ index: 0 }, { children: "Item 1" })), _jsx(ListItem, Object.assign({ index: 1 }, { children: "Item 2" }))] })));
22
+ expect(getAllByTestId('mock-icon')).toHaveLength(2);
23
+ }));
24
+ });
@@ -0,0 +1,21 @@
1
+ /** @jsxImportSource theme-ui */
2
+ import React from 'react';
3
+ import { StyledElementProps } from '../../../theme';
4
+ import { COLOR } from '../../..';
5
+ type ListProps = StyledElementProps<HTMLUListElement, {
6
+ ordered?: boolean;
7
+ size?: LIST_SIZE;
8
+ icon?: React.FC<any>;
9
+ iconColor?: COLOR;
10
+ }>;
11
+ export declare enum LIST_SIZE {
12
+ SM = "sm",
13
+ MD = "md",
14
+ LG = "lg"
15
+ }
16
+ export declare const List: React.FC<ListProps>;
17
+ type ListItemProps = StyledElementProps<HTMLLIElement, {
18
+ index: number;
19
+ }>;
20
+ export declare const ListItem: React.FC<ListItemProps>;
21
+ export {};