@ndlib/component-library 0.0.7-9.1
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 +13 -0
- package/dist/components/composites/Card/Card.stories.js +122 -0
- package/dist/components/composites/Card/Card.test.d.ts +1 -0
- package/dist/components/composites/Card/Card.test.js +37 -0
- package/dist/components/composites/Card/index.d.ts +36 -0
- package/dist/components/composites/Card/index.js +89 -0
- package/dist/components/composites/DragDropList/DragDropList.stories.d.ts +7 -0
- package/dist/components/composites/DragDropList/DragDropList.stories.js +32 -0
- package/dist/components/composites/DragDropList/index.d.ts +25 -0
- package/dist/components/composites/DragDropList/index.js +48 -0
- package/dist/components/composites/DropdownLinks/DropdownLinks.stories.d.ts +8 -0
- package/dist/components/composites/DropdownLinks/DropdownLinks.stories.js +25 -0
- package/dist/components/composites/DropdownLinks/DropdownLinks.test.d.ts +1 -0
- package/dist/components/composites/DropdownLinks/DropdownLinks.test.js +27 -0
- package/dist/components/composites/DropdownLinks/index.d.ts +15 -0
- package/dist/components/composites/DropdownLinks/index.js +28 -0
- package/dist/components/composites/EmptyState/EmptyState.stories.d.ts +10 -0
- package/dist/components/composites/EmptyState/EmptyState.stories.js +31 -0
- package/dist/components/composites/EmptyState/EmptyState.test.d.ts +1 -0
- package/dist/components/composites/EmptyState/EmptyState.test.js +20 -0
- package/dist/components/composites/EmptyState/index.d.ts +15 -0
- package/dist/components/composites/EmptyState/index.js +32 -0
- package/dist/components/composites/Modal/Modal.stories.d.ts +6 -0
- package/dist/components/composites/Modal/Modal.stories.js +40 -0
- package/dist/components/composites/Modal/index.d.ts +21 -0
- package/dist/components/composites/Modal/index.js +64 -0
- package/dist/components/composites/NavMenu/NavMenu.stories.d.ts +6 -0
- package/dist/components/composites/NavMenu/NavMenu.stories.js +12 -0
- package/dist/components/composites/NavMenu/NavMenu.test.d.ts +1 -0
- package/dist/components/composites/NavMenu/NavMenu.test.js +96 -0
- package/dist/components/composites/NavMenu/demo.d.ts +1 -0
- package/dist/components/composites/NavMenu/demo.js +172 -0
- package/dist/components/composites/NavMenu/index.d.ts +5 -0
- package/dist/components/composites/NavMenu/index.js +52 -0
- package/dist/components/composites/Seo/SeoDataDisplay/index.d.ts +2 -0
- package/dist/components/composites/Seo/SeoDataDisplay/index.js +9 -0
- package/dist/components/composites/Seo/index.d.ts +11 -0
- package/dist/components/composites/Seo/index.js +16 -0
- package/dist/components/composites/Seo/seo.stories.d.ts +6 -0
- package/dist/components/composites/Seo/seo.stories.js +12 -0
- package/dist/components/composites/Seo/seo.test.d.ts +1 -0
- package/dist/components/composites/Seo/seo.test.js +56 -0
- package/dist/components/composites/Seo/siteMetadata.d.ts +9 -0
- package/dist/components/composites/Seo/siteMetadata.js +16 -0
- package/dist/components/composites/SnackBar/SnackBar.stories.d.ts +8 -0
- package/dist/components/composites/SnackBar/SnackBar.stories.js +20 -0
- package/dist/components/composites/SnackBar/SnackBar.test.d.ts +1 -0
- package/dist/components/composites/SnackBar/SnackBar.test.js +75 -0
- package/dist/components/composites/SnackBar/examples.d.ts +3 -0
- package/dist/components/composites/SnackBar/examples.js +35 -0
- package/dist/components/composites/SnackBar/index.d.ts +1 -0
- package/dist/components/composites/SnackBar/index.js +45 -0
- package/dist/components/composites/StructuredData/StructuredData.stories.d.ts +6 -0
- package/dist/components/composites/StructuredData/StructuredData.stories.js +12 -0
- package/dist/components/composites/StructuredData/StructuredData.test.d.ts +1 -0
- package/dist/components/composites/StructuredData/StructuredData.test.js +48 -0
- package/dist/components/composites/StructuredData/StructuredDataDisplay/index.d.ts +2 -0
- package/dist/components/composites/StructuredData/StructuredDataDisplay/index.js +37 -0
- package/dist/components/composites/StructuredData/index.d.ts +38 -0
- package/dist/components/composites/StructuredData/index.js +58 -0
- package/dist/components/composites/StructuredData/sdEvent/index.d.ts +13 -0
- package/dist/components/composites/StructuredData/sdEvent/index.js +16 -0
- package/dist/components/composites/StructuredData/sdEvent/makeEventSchema.d.ts +15 -0
- package/dist/components/composites/StructuredData/sdEvent/makeEventSchema.js +16 -0
- package/dist/components/composites/StructuredData/sdNews/index.d.ts +11 -0
- package/dist/components/composites/StructuredData/sdNews/index.js +14 -0
- package/dist/components/composites/StructuredData/sdNews/makeNewsSchema.d.ts +12 -0
- package/dist/components/composites/StructuredData/sdNews/makeNewsSchema.js +11 -0
- package/dist/components/composites/StructuredData/sdWebsite/index.d.ts +8 -0
- package/dist/components/composites/StructuredData/sdWebsite/index.js +11 -0
- package/dist/components/composites/StructuredData/sdWebsite/makeWebPageSchema.d.ts +9 -0
- package/dist/components/composites/StructuredData/sdWebsite/makeWebPageSchema.js +9 -0
- package/dist/components/composites/StructuredData/siteMetadata.d.ts +9 -0
- package/dist/components/composites/StructuredData/siteMetadata.js +12 -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 +61 -0
- package/dist/components/elements/Alerts/index.d.ts +14 -0
- package/dist/components/elements/Alerts/index.js +64 -0
- package/dist/components/elements/ArrowLink/ArrowLink.stories.d.ts +6 -0
- package/dist/components/elements/ArrowLink/ArrowLink.stories.js +12 -0
- package/dist/components/elements/ArrowLink/ArrowLink.test.d.ts +1 -0
- package/dist/components/elements/ArrowLink/ArrowLink.test.js +34 -0
- package/dist/components/elements/ArrowLink/index.d.ts +7 -0
- package/dist/components/elements/ArrowLink/index.js +39 -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 +2 -0
- package/dist/components/elements/BrandingBar/index.js +52 -0
- package/dist/components/elements/Button/Button.stories.d.ts +15 -0
- package/dist/components/elements/Button/Button.stories.js +88 -0
- package/dist/components/elements/Button/Button.test.d.ts +1 -0
- package/dist/components/elements/Button/Button.test.js +39 -0
- package/dist/components/elements/Button/index.d.ts +49 -0
- package/dist/components/elements/Button/index.js +138 -0
- package/dist/components/elements/Dropdown/Dropdown.stories.d.ts +7 -0
- package/dist/components/elements/Dropdown/Dropdown.stories.js +20 -0
- package/dist/components/elements/Dropdown/index.d.ts +24 -0
- package/dist/components/elements/Dropdown/index.js +87 -0
- package/dist/components/elements/Fields/AutoComplete/AutoComplete.stories.d.ts +6 -0
- package/dist/components/elements/Fields/AutoComplete/AutoComplete.stories.js +60 -0
- package/dist/components/elements/Fields/AutoComplete/index.d.ts +11 -0
- package/dist/components/elements/Fields/AutoComplete/index.js +26 -0
- 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 +8 -0
- package/dist/components/elements/Fields/Checkbox/index.js +22 -0
- package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.d.ts +7 -0
- package/dist/components/elements/Fields/CheckboxGroup/CheckboxGroup.stories.js +26 -0
- package/dist/components/elements/Fields/CheckboxGroup/index.d.ts +16 -0
- package/dist/components/elements/Fields/CheckboxGroup/index.js +49 -0
- package/dist/components/elements/Fields/DatePicker/DatePicker.stories.d.ts +8 -0
- package/dist/components/elements/Fields/DatePicker/DatePicker.stories.js +31 -0
- package/dist/components/elements/Fields/DatePicker/index.d.ts +20 -0
- package/dist/components/elements/Fields/DatePicker/index.js +48 -0
- package/dist/components/elements/Fields/MonthPicker/MonthPicker.stories.d.ts +7 -0
- package/dist/components/elements/Fields/MonthPicker/MonthPicker.stories.js +20 -0
- package/dist/components/elements/Fields/MonthPicker/index.d.ts +13 -0
- package/dist/components/elements/Fields/MonthPicker/index.js +24 -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 +8 -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 +8 -0
- package/dist/components/elements/Fields/Select/Select.stories.js +39 -0
- package/dist/components/elements/Fields/Select/index.d.ts +18 -0
- package/dist/components/elements/Fields/Select/index.js +178 -0
- package/dist/components/elements/Fields/TextInput/TextInput.stories.d.ts +9 -0
- package/dist/components/elements/Fields/TextInput/TextInput.stories.js +35 -0
- package/dist/components/elements/Fields/TextInput/index.d.ts +45 -0
- package/dist/components/elements/Fields/TextInput/index.js +119 -0
- package/dist/components/elements/Fields/option.d.ts +16 -0
- package/dist/components/elements/Fields/option.js +3 -0
- package/dist/components/elements/Group/index.d.ts +22 -0
- package/dist/components/elements/Group/index.js +69 -0
- 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 +10 -0
- package/dist/components/elements/Icon/index.js +34 -0
- package/dist/components/elements/Link/Link.stories.d.ts +6 -0
- package/dist/components/elements/Link/Link.stories.js +21 -0
- package/dist/components/elements/Link/Link.test.d.ts +1 -0
- package/dist/components/elements/Link/Link.test.js +58 -0
- package/dist/components/elements/Link/index.d.ts +14 -0
- package/dist/components/elements/Link/index.js +41 -0
- package/dist/components/elements/List/List.stories.d.ts +10 -0
- package/dist/components/elements/List/List.stories.js +37 -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 +27 -0
- package/dist/components/elements/List/index.js +103 -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 +33 -0
- package/dist/components/elements/ListBox/index.js +51 -0
- package/dist/components/elements/Markdown/Markdown.stories.d.ts +10 -0
- package/dist/components/elements/Markdown/Markdown.stories.js +97 -0
- package/dist/components/elements/Markdown/Markdown.test.d.ts +1 -0
- package/dist/components/elements/Markdown/Markdown.test.js +91 -0
- package/dist/components/elements/Markdown/index.d.ts +21 -0
- package/dist/components/elements/Markdown/index.js +75 -0
- package/dist/components/elements/Pill/Pill.stories.d.ts +8 -0
- package/dist/components/elements/Pill/Pill.stories.js +40 -0
- package/dist/components/elements/Pill/Pill.test.d.ts +1 -0
- package/dist/components/elements/Pill/Pill.test.js +18 -0
- package/dist/components/elements/Pill/index.d.ts +21 -0
- package/dist/components/elements/Pill/index.js +117 -0
- package/dist/components/elements/Spinner/Spinner.stories.d.ts +7 -0
- package/dist/components/elements/Spinner/Spinner.stories.js +26 -0
- package/dist/components/elements/Spinner/Spinner.test.d.ts +1 -0
- package/dist/components/elements/Spinner/Spinner.test.js +9 -0
- package/dist/components/elements/Spinner/index.d.ts +14 -0
- package/dist/components/elements/Spinner/index.js +49 -0
- package/dist/components/elements/TabList/TabList.stories.d.ts +6 -0
- package/dist/components/elements/TabList/TabList.stories.js +12 -0
- package/dist/components/elements/TabList/TabList.test.d.ts +1 -0
- package/dist/components/elements/TabList/TabList.test.js +19 -0
- package/dist/components/elements/TabList/example.d.ts +7 -0
- package/dist/components/elements/TabList/example.js +36 -0
- package/dist/components/elements/TabList/index.d.ts +10 -0
- package/dist/components/elements/TabList/index.js +30 -0
- package/dist/components/elements/Table/Table.stories.d.ts +10 -0
- package/dist/components/elements/Table/Table.stories.js +96 -0
- package/dist/components/elements/Table/Table.test.d.ts +1 -0
- package/dist/components/elements/Table/Table.test.js +36 -0
- package/dist/components/elements/Table/index.d.ts +30 -0
- package/dist/components/elements/Table/index.js +100 -0
- package/dist/components/elements/layout/Box.d.ts +9 -0
- package/dist/components/elements/layout/Box.js +3 -0
- package/dist/components/elements/layout/Box.stories.d.ts +6 -0
- package/dist/components/elements/layout/Box.stories.js +12 -0
- package/dist/components/elements/layout/Column.d.ts +8 -0
- package/dist/components/elements/layout/Column.js +19 -0
- package/dist/components/elements/layout/Flex.stories.d.ts +10 -0
- package/dist/components/elements/layout/Flex.stories.js +26 -0
- package/dist/components/elements/layout/Flex.test.d.ts +1 -0
- package/dist/components/elements/layout/Flex.test.js +34 -0
- package/dist/components/elements/layout/Row.d.ts +20 -0
- package/dist/components/elements/layout/Row.js +52 -0
- package/dist/components/elements/text/Heading/Heading.stories.d.ts +8 -0
- package/dist/components/elements/text/Heading/Heading.stories.js +35 -0
- package/dist/components/elements/text/Heading/Heading.test.d.ts +1 -0
- package/dist/components/elements/text/Heading/Heading.test.js +51 -0
- package/dist/components/elements/text/Heading/index.d.ts +20 -0
- package/dist/components/elements/text/Heading/index.js +62 -0
- package/dist/components/elements/text/Inline/Inline.stories.d.ts +6 -0
- package/dist/components/elements/text/Inline/Inline.stories.js +12 -0
- package/dist/components/elements/text/Inline/index.d.ts +6 -0
- package/dist/components/elements/text/Inline/index.js +21 -0
- package/dist/components/elements/text/Label/Label.stories.d.ts +6 -0
- package/dist/components/elements/text/Label/Label.stories.js +20 -0
- package/dist/components/elements/text/Label/Label.test.d.ts +1 -0
- package/dist/components/elements/text/Label/Label.test.js +56 -0
- package/dist/components/elements/text/Label/index.d.ts +20 -0
- package/dist/components/elements/text/Label/index.js +38 -0
- package/dist/components/elements/text/Paragraph/Paragraph.stories.d.ts +6 -0
- package/dist/components/elements/text/Paragraph/Paragraph.stories.js +25 -0
- package/dist/components/elements/text/Paragraph/Paragraph.test.d.ts +1 -0
- package/dist/components/elements/text/Paragraph/Paragraph.test.js +9 -0
- package/dist/components/elements/text/Paragraph/index.d.ts +14 -0
- package/dist/components/elements/text/Paragraph/index.js +29 -0
- package/dist/components/elements/text/ReadMore/ReadMore.stories.d.ts +8 -0
- package/dist/components/elements/text/ReadMore/ReadMore.stories.js +26 -0
- package/dist/components/elements/text/ReadMore/index.d.ts +12 -0
- package/dist/components/elements/text/ReadMore/index.js +71 -0
- package/dist/components/providers/alerts.d.ts +41 -0
- package/dist/components/providers/alerts.js +133 -0
- package/dist/components/providers/componentConfig.d.ts +25 -0
- package/dist/components/providers/componentConfig.js +37 -0
- package/dist/components/providers/dialogs.d.ts +9 -0
- package/dist/components/providers/dialogs.js +32 -0
- package/dist/components/providers/env.d.ts +14 -0
- package/dist/components/providers/env.js +25 -0
- package/dist/components/providers/media.d.ts +8 -0
- package/dist/components/providers/media.js +43 -0
- package/dist/components/providers/menu.d.ts +46 -0
- package/dist/components/providers/menu.js +304 -0
- package/dist/components/providers/snackBar.d.ts +23 -0
- package/dist/components/providers/snackBar.js +53 -0
- package/dist/components/providers/ui.d.ts +18 -0
- package/dist/components/providers/ui.js +16 -0
- package/dist/components/providers/uniqueIds.d.ts +3 -0
- package/dist/components/providers/uniqueIds.js +23 -0
- package/dist/components/providers/uniqueIds.test.d.ts +1 -0
- package/dist/components/providers/uniqueIds.test.js +26 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +51 -0
- package/dist/theme/Color.stories.d.ts +5 -0
- package/dist/theme/Color.stories.js +63 -0
- package/dist/theme/GlobalStyles.d.ts +1 -0
- package/dist/theme/GlobalStyles.js +167 -0
- package/dist/theme/Typography.stories.d.ts +5 -0
- package/dist/theme/Typography.stories.js +44 -0
- package/dist/theme/colors.d.ts +51 -0
- package/dist/theme/colors.js +97 -0
- package/dist/theme/custom.d.ts +11 -0
- package/dist/theme/custom.js +13 -0
- package/dist/theme/index.d.ts +185 -0
- package/dist/theme/index.js +25 -0
- package/dist/theme/spacing.d.ts +0 -0
- package/dist/theme/spacing.js +1 -0
- package/dist/theme/typography.d.ts +100 -0
- package/dist/theme/typography.js +206 -0
- package/dist/utils/hooks/useCheckMidClick.d.ts +8 -0
- package/dist/utils/hooks/useCheckMidClick.js +17 -0
- package/dist/utils/hooks/useCheckMidKeyPress.d.ts +9 -0
- package/dist/utils/hooks/useCheckMidKeyPress.js +23 -0
- package/dist/utils/hooks/useHover.d.ts +7 -0
- package/dist/utils/hooks/useHover.js +12 -0
- package/dist/utils/hooks/useStorage.d.ts +14 -0
- package/dist/utils/hooks/useStorage.js +37 -0
- package/dist/utils/misc.d.ts +14 -0
- package/dist/utils/misc.js +19 -0
- package/dist/utils/sortByKey.d.ts +12 -0
- package/dist/utils/sortByKey.js +20 -0
- package/dist/utils/test.d.ts +2 -0
- package/dist/utils/test.js +9 -0
- package/package.json +98 -0
|
@@ -0,0 +1,117 @@
|
|
|
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 React, { useState } from 'react';
|
|
14
|
+
import { useTheme } from '../../../theme';
|
|
15
|
+
import { COLOR, colors } from '../../../theme/colors';
|
|
16
|
+
import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
|
|
17
|
+
import { Icon } from '../Icon';
|
|
18
|
+
export var PILL_SIZE;
|
|
19
|
+
(function (PILL_SIZE) {
|
|
20
|
+
PILL_SIZE["SM"] = "sm";
|
|
21
|
+
PILL_SIZE["LG"] = "lg";
|
|
22
|
+
})(PILL_SIZE || (PILL_SIZE = {}));
|
|
23
|
+
const typographyMap = {
|
|
24
|
+
[PILL_SIZE.SM]: TYPOGRAPHY_TYPE.PARAGRAPH_XSMALL,
|
|
25
|
+
[PILL_SIZE.LG]: TYPOGRAPHY_TYPE.PARAGRAPH_SMALL,
|
|
26
|
+
};
|
|
27
|
+
const defaultPaddingX = {
|
|
28
|
+
[PILL_SIZE.SM]: 2,
|
|
29
|
+
[PILL_SIZE.LG]: 3,
|
|
30
|
+
};
|
|
31
|
+
const defaultHeight = {
|
|
32
|
+
[PILL_SIZE.SM]: '1.75rem',
|
|
33
|
+
[PILL_SIZE.LG]: '2rem',
|
|
34
|
+
};
|
|
35
|
+
const iconMargin = {
|
|
36
|
+
[PILL_SIZE.SM]: 1,
|
|
37
|
+
[PILL_SIZE.LG]: 1,
|
|
38
|
+
};
|
|
39
|
+
export var PILL_TYPE;
|
|
40
|
+
(function (PILL_TYPE) {
|
|
41
|
+
PILL_TYPE["DEFAULT"] = "default";
|
|
42
|
+
PILL_TYPE["OUTLINE"] = "outline";
|
|
43
|
+
})(PILL_TYPE || (PILL_TYPE = {}));
|
|
44
|
+
export const Pill = React.forwardRef((_a, ref) => {
|
|
45
|
+
var { size: sizeParam, type: typeParam, color, icon, children, sx, onClick } = _a, rest = __rest(_a, ["size", "type", "color", "icon", "children", "sx", "onClick"]);
|
|
46
|
+
const theme = useTheme();
|
|
47
|
+
const [hover, setHover] = useState(false);
|
|
48
|
+
const clickable = onClick !== undefined;
|
|
49
|
+
let bg = COLOR.PRIMARY;
|
|
50
|
+
let hoverBg = COLOR.PRIMARY_HIGHLIGHT;
|
|
51
|
+
let textColor = COLOR.TEXT;
|
|
52
|
+
let hoverTextColor = undefined;
|
|
53
|
+
let borderColor = COLOR.TRANSPARENT;
|
|
54
|
+
const cursor = clickable ? 'pointer' : 'default';
|
|
55
|
+
const hoverShadow = theme.boxShadow.NORMAL;
|
|
56
|
+
const hoverDecoration = undefined;
|
|
57
|
+
const hoverTransform = 'scale(1.03)';
|
|
58
|
+
const type = typeParam || PILL_TYPE.DEFAULT;
|
|
59
|
+
const size = sizeParam || PILL_SIZE.SM;
|
|
60
|
+
const paddingX = defaultPaddingX[size];
|
|
61
|
+
const height = defaultHeight[size];
|
|
62
|
+
if (type === PILL_TYPE.DEFAULT) {
|
|
63
|
+
bg = color || COLOR.PRIMARY;
|
|
64
|
+
hoverBg =
|
|
65
|
+
bg === COLOR.PRIMARY
|
|
66
|
+
? COLOR.PRIMARY_HIGHLIGHT
|
|
67
|
+
: bg === COLOR.SECONDARY
|
|
68
|
+
? COLOR.SECONDARY_HIGHLIGHT
|
|
69
|
+
: bg;
|
|
70
|
+
textColor =
|
|
71
|
+
bg === COLOR.PRIMARY
|
|
72
|
+
? COLOR.TEXT_ON_PRIMARY
|
|
73
|
+
: bg === COLOR.SECONDARY
|
|
74
|
+
? COLOR.TEXT_ON_SECONDARY
|
|
75
|
+
: COLOR.TEXT;
|
|
76
|
+
hoverTextColor = textColor;
|
|
77
|
+
}
|
|
78
|
+
if (type === PILL_TYPE.OUTLINE) {
|
|
79
|
+
bg = COLOR.BACKGROUND;
|
|
80
|
+
hoverBg = COLOR.BACKGROUND;
|
|
81
|
+
textColor = color || COLOR.PRIMARY;
|
|
82
|
+
hoverTextColor = textColor;
|
|
83
|
+
borderColor = textColor;
|
|
84
|
+
}
|
|
85
|
+
const typography = typographyMap[size];
|
|
86
|
+
const typographyStyles = getTypographyStyles(typography);
|
|
87
|
+
const body = children;
|
|
88
|
+
return (_jsxs("button", Object.assign({ ref: ref, tabIndex: onClick ? -1 : 0, onClick: onClick, onMouseEnter: () => {
|
|
89
|
+
setHover(true);
|
|
90
|
+
}, onMouseLeave: () => {
|
|
91
|
+
setHover(false);
|
|
92
|
+
}, sx: Object.assign(Object.assign(Object.assign({}, typographyStyles), { cursor, borderRadius: '1000px', bg: bg || colors.primary, color: textColor, px: paddingX, height: height, border: 'solid 1px', borderColor, display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center', ':hover': clickable
|
|
93
|
+
? {
|
|
94
|
+
bg: hoverBg,
|
|
95
|
+
color: hoverTextColor,
|
|
96
|
+
boxShadow: hoverShadow,
|
|
97
|
+
transform: hoverTransform,
|
|
98
|
+
textDecoration: hoverDecoration,
|
|
99
|
+
}
|
|
100
|
+
: undefined, ':focus': clickable
|
|
101
|
+
? {
|
|
102
|
+
bg: hoverBg,
|
|
103
|
+
color: hoverTextColor,
|
|
104
|
+
boxShadow: hoverShadow,
|
|
105
|
+
cursor: 'pointer',
|
|
106
|
+
transform: hoverTransform,
|
|
107
|
+
textDecoration: hoverDecoration,
|
|
108
|
+
}
|
|
109
|
+
: undefined }), sx) }, rest, { children: [icon && (_jsx(Icon, { icon: icon, size: typographyStyles.fontSize, sx: { mr: iconMargin[size] }, color: hover ? hoverTextColor : textColor })), _jsx("div", Object.assign({ css: {
|
|
110
|
+
flexGrow: 1,
|
|
111
|
+
justifyContent: 'flex-start',
|
|
112
|
+
textOverflow: 'ellipsis',
|
|
113
|
+
whiteSpace: 'nowrap',
|
|
114
|
+
overflow: 'hidden',
|
|
115
|
+
textAlign: 'start',
|
|
116
|
+
} }, { children: body }))] })));
|
|
117
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Spinner } from '.';
|
|
3
|
+
declare const meta: Meta<typeof Spinner>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Spinner>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const CustomColor: Story;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Column, Group, HEADING_SIZE, Heading } from '../../..';
|
|
3
|
+
import { SPINNER_SIZE, Spinner } from '.';
|
|
4
|
+
import { GROUP_TYPE } from '../Group';
|
|
5
|
+
import { COLOR } from '../../../theme/colors';
|
|
6
|
+
const meta = {
|
|
7
|
+
title: 'Elements/Spinner',
|
|
8
|
+
component: Spinner,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
const sizes = [
|
|
13
|
+
{ size: SPINNER_SIZE.LG, label: 'Large' },
|
|
14
|
+
{ size: SPINNER_SIZE.MD, label: 'Medium' },
|
|
15
|
+
{ size: SPINNER_SIZE.SM, label: 'Small' },
|
|
16
|
+
];
|
|
17
|
+
export const Default = {
|
|
18
|
+
render: () => (_jsx(Column, { children: sizes.map((size) => (_jsxs(Group, Object.assign({ type: GROUP_TYPE.REGION }, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, { children: size.label })), _jsx(Spinner, { size: size.size })] })))) })),
|
|
19
|
+
args: {},
|
|
20
|
+
};
|
|
21
|
+
export const CustomColor = {
|
|
22
|
+
render: () => (_jsx(Column, { children: _jsx(Spinner, { color: COLOR.SECONDARY }) })),
|
|
23
|
+
args: {
|
|
24
|
+
children: 'Heading',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '../../../utils/test';
|
|
3
|
+
import { SPINNER_LABEL, Spinner } from '.';
|
|
4
|
+
describe('Button', () => {
|
|
5
|
+
it('renders without throwing an error', () => {
|
|
6
|
+
const { getByLabelText } = render(_jsx(Spinner, {}));
|
|
7
|
+
expect(getByLabelText(SPINNER_LABEL)).toBeInTheDocument();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StyledElementProps } from '../../../theme';
|
|
3
|
+
import { COLOR } from '../../../theme/colors';
|
|
4
|
+
export declare enum SPINNER_SIZE {
|
|
5
|
+
SM = "sm",
|
|
6
|
+
MD = "md",
|
|
7
|
+
LG = "lg"
|
|
8
|
+
}
|
|
9
|
+
export type SpinnerProps = StyledElementProps<HTMLDivElement, {
|
|
10
|
+
size?: SPINNER_SIZE;
|
|
11
|
+
color?: COLOR;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const SPINNER_LABEL = "Loading";
|
|
14
|
+
export declare const Spinner: React.FC<SpinnerProps>;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
import { keyframes } from '@emotion/react';
|
|
14
|
+
import { useTheme } from '../../../theme';
|
|
15
|
+
import { COLOR } from '../../../theme/colors';
|
|
16
|
+
export var SPINNER_SIZE;
|
|
17
|
+
(function (SPINNER_SIZE) {
|
|
18
|
+
SPINNER_SIZE["SM"] = "sm";
|
|
19
|
+
SPINNER_SIZE["MD"] = "md";
|
|
20
|
+
SPINNER_SIZE["LG"] = "lg";
|
|
21
|
+
})(SPINNER_SIZE || (SPINNER_SIZE = {}));
|
|
22
|
+
const spin = keyframes({
|
|
23
|
+
from: {
|
|
24
|
+
transform: 'rotate(0deg)',
|
|
25
|
+
},
|
|
26
|
+
to: {
|
|
27
|
+
transform: 'rotate(360deg)',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const sizeLengthMap = {
|
|
31
|
+
[SPINNER_SIZE.SM]: '1.25rem',
|
|
32
|
+
[SPINNER_SIZE.MD]: '2rem',
|
|
33
|
+
[SPINNER_SIZE.LG]: '3rem',
|
|
34
|
+
};
|
|
35
|
+
export const SPINNER_LABEL = 'Loading';
|
|
36
|
+
export const Spinner = (_a) => {
|
|
37
|
+
var { size: sizeParam, color: colorParam } = _a, rest = __rest(_a, ["size", "color"]);
|
|
38
|
+
const { colors } = useTheme();
|
|
39
|
+
const size = sizeParam || SPINNER_SIZE.MD;
|
|
40
|
+
const color = colors[colorParam || COLOR.PRIMARY];
|
|
41
|
+
return (_jsx("div", Object.assign({ "aria-label": SPINNER_LABEL, sx: {
|
|
42
|
+
animation: `${spin} 1.4s linear 0s infinite normal none running;`,
|
|
43
|
+
borderRadius: '50%',
|
|
44
|
+
height: sizeLengthMap[size],
|
|
45
|
+
width: sizeLengthMap[size],
|
|
46
|
+
border: size === SPINNER_SIZE.LG ? 'solid 6px' : 'solid 4px',
|
|
47
|
+
borderColor: `${color} ${color} transparent`,
|
|
48
|
+
} }, rest)));
|
|
49
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TabList } from './index';
|
|
3
|
+
import { ExampleTabs } from './example';
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Elements/TabList',
|
|
6
|
+
component: TabList,
|
|
7
|
+
tags: ['autodocs'],
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
export const Default = {
|
|
11
|
+
render: () => _jsx(ExampleTabs, {}),
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { items, ExampleTabs } from './example';
|
|
4
|
+
describe('TabList', () => {
|
|
5
|
+
it('renders interactive tabs', () => {
|
|
6
|
+
const { getByRole } = render(_jsx(ExampleTabs, {}));
|
|
7
|
+
expect(getByRole('tablist')).toBeInTheDocument();
|
|
8
|
+
for (const item of items) {
|
|
9
|
+
expect(getByRole('tab', { name: item.label })).toBeInTheDocument();
|
|
10
|
+
}
|
|
11
|
+
const firstTab = getByRole('tab', { name: items[0].label });
|
|
12
|
+
const secondTab = getByRole('tab', { name: items[1].label });
|
|
13
|
+
expect(firstTab).toHaveAttribute('aria-selected', 'true');
|
|
14
|
+
expect(secondTab).toHaveAttribute('aria-selected', 'false');
|
|
15
|
+
fireEvent.click(secondTab);
|
|
16
|
+
expect(firstTab).toHaveAttribute('aria-selected', 'false');
|
|
17
|
+
expect(secondTab).toHaveAttribute('aria-selected', 'true');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TabList, Tab } from '.';
|
|
4
|
+
export const items = [
|
|
5
|
+
{
|
|
6
|
+
id: '1',
|
|
7
|
+
label: 'Items & Requests',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: '2',
|
|
11
|
+
label: 'Courses',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: '3',
|
|
15
|
+
label: 'Checkout',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: '4',
|
|
19
|
+
label: 'History',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: '5',
|
|
23
|
+
label: 'Preferences',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: '6',
|
|
27
|
+
label: 'Reservations',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
const StateManager = ({ children }) => {
|
|
31
|
+
const [selected, setSelected] = React.useState('1');
|
|
32
|
+
return _jsx(_Fragment, { children: children({ selected, setSelected }) });
|
|
33
|
+
};
|
|
34
|
+
export const ExampleTabs = () => (_jsx(StateManager, { children: ({ selected, setSelected }) => (_jsx(TabList, { children: items.map((item) => (_jsx(Tab, Object.assign({ onClick: () => {
|
|
35
|
+
setSelected(item.id);
|
|
36
|
+
}, selected: selected === item.id }, { children: item.label }), item.id))) })) }));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyledElementProps } from '../../../theme';
|
|
3
|
+
type TabListProps = StyledElementProps<HTMLDivElement>;
|
|
4
|
+
export declare const TabList: React.FC<TabListProps>;
|
|
5
|
+
type TabProps = StyledElementProps<HTMLButtonElement, {
|
|
6
|
+
selected?: boolean;
|
|
7
|
+
children: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const Tab: React.FC<TabProps>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
|
|
14
|
+
import { COLOR } from '../../../theme/colors';
|
|
15
|
+
import { useUniqueId } from '../../providers/uniqueIds';
|
|
16
|
+
export const TabList = (_a) => {
|
|
17
|
+
var { children, sx } = _a, props = __rest(_a, ["children", "sx"]);
|
|
18
|
+
return (_jsx("div", Object.assign({ role: "tablist", sx: Object.assign({ flexDirection: 'row' }, sx) }, props, { children: children })));
|
|
19
|
+
};
|
|
20
|
+
export const Tab = (_a) => {
|
|
21
|
+
var { selected, children } = _a, rest = __rest(_a, ["selected", "children"]);
|
|
22
|
+
const typographyStyles = getTypographyStyles(TYPOGRAPHY_TYPE.CONDENSED_TEXT_LARGE);
|
|
23
|
+
const labelId = useUniqueId('tab-label');
|
|
24
|
+
return (_jsx("button", Object.assign({ role: "tab", sx: Object.assign({ height: '3.25rem', boxSizing: 'border-box', px: 4, bg: COLOR.WHITE, color: selected ? COLOR.DARK_GRAY : COLOR.GRAY, border: 'none', borderBottom: selected ? 'solid 3px' : 'solid 1px', borderColor: selected ? COLOR.ND_BLUE_BRIGHT : COLOR.LIGHT_GRAY, cursor: 'pointer' }, typographyStyles), "aria-labelledby": labelId, "aria-selected": selected ? 'true' : 'false' }, rest, { children: _jsx("div", Object.assign({ id: labelId, sx: {
|
|
25
|
+
transform: selected ? 'scale(1.1)' : undefined,
|
|
26
|
+
':hover': {
|
|
27
|
+
transform: selected ? 'scale(1.1)' : 'scale(1.05)',
|
|
28
|
+
},
|
|
29
|
+
} }, { children: children })) })));
|
|
30
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Table } from '.';
|
|
3
|
+
declare const meta: Meta<typeof Table>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Table>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const OmitColumn: Story;
|
|
8
|
+
export declare const ResponsiveColumn: Story;
|
|
9
|
+
export declare const ColumnGroup: Story;
|
|
10
|
+
export declare const Sortable: Story;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Table, TableColumn } from '.';
|
|
3
|
+
import { SORT_DIRECTION, sortByKey } from '../../../utils/sortByKey';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Elements/Table',
|
|
7
|
+
component: Table,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
const data = [
|
|
12
|
+
{
|
|
13
|
+
name: 'Steve Rogers',
|
|
14
|
+
age: 100,
|
|
15
|
+
position: 'Ethics Officer',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'Natasha Romanoff',
|
|
19
|
+
age: 35,
|
|
20
|
+
position: 'Opposition Researcher',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'Thor',
|
|
24
|
+
age: 1500,
|
|
25
|
+
position: 'VP of Thunder',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'Peter Parker',
|
|
29
|
+
age: 18,
|
|
30
|
+
position: 'Web Crawling Expert',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'Kate Bishop',
|
|
34
|
+
age: 22,
|
|
35
|
+
position: 'Trust Fund Recipient',
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
export const Default = {
|
|
39
|
+
render: () => (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
|
|
40
|
+
width: '160px',
|
|
41
|
+
} }), _jsx(TableColumn, Object.assign({ header: "Age", sx: {
|
|
42
|
+
width: '100px',
|
|
43
|
+
} }, { children: (row) => row.age })), _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position }))] }))),
|
|
44
|
+
};
|
|
45
|
+
export const OmitColumn = {
|
|
46
|
+
render: () => {
|
|
47
|
+
const someCondition = false;
|
|
48
|
+
return (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
|
|
49
|
+
width: '160px',
|
|
50
|
+
} }), someCondition ? (_jsx(TableColumn, Object.assign({ header: "Age", sx: {
|
|
51
|
+
width: '100px',
|
|
52
|
+
} }, { children: (row) => row.age }))) : null, _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position }))] })));
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export const ResponsiveColumn = {
|
|
56
|
+
render: () => {
|
|
57
|
+
return (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
|
|
58
|
+
width: '160px',
|
|
59
|
+
} }), _jsx(TableColumn, Object.assign({ breakpoint: 2, header: "Age", sx: {
|
|
60
|
+
width: '100px',
|
|
61
|
+
} }, { children: (row) => row.age })), _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position }))] })));
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
export const ColumnGroup = {
|
|
65
|
+
render: () => {
|
|
66
|
+
return (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
|
|
67
|
+
width: '160px',
|
|
68
|
+
} }), [
|
|
69
|
+
_jsx(TableColumn, Object.assign({ header: "Age", sx: {
|
|
70
|
+
width: '100px',
|
|
71
|
+
} }, { children: (row) => row.age })),
|
|
72
|
+
_jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position })),
|
|
73
|
+
]] })));
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const SortableStory = () => {
|
|
77
|
+
const [sortConfig, setSortConfig] = useState({
|
|
78
|
+
key: 'name',
|
|
79
|
+
direction: SORT_DIRECTION.ASC,
|
|
80
|
+
});
|
|
81
|
+
const sorted = sortByKey({
|
|
82
|
+
items: data,
|
|
83
|
+
config: sortConfig,
|
|
84
|
+
});
|
|
85
|
+
return (_jsxs(Table, Object.assign({ data: sorted, alternateRowColor: true, sortConfig: sortConfig, updateSort: setSortConfig }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sortable: true, sx: {
|
|
86
|
+
width: '160px',
|
|
87
|
+
} }), [
|
|
88
|
+
_jsx(TableColumn, Object.assign({ header: "Age", sortKey: "age", sortable: true, sx: {
|
|
89
|
+
width: '100px',
|
|
90
|
+
} }, { children: (row) => row.age })),
|
|
91
|
+
_jsx(TableColumn, { header: "Occupation", sortable: true, dataKey: "position" }),
|
|
92
|
+
]] })));
|
|
93
|
+
};
|
|
94
|
+
export const Sortable = {
|
|
95
|
+
render: SortableStory,
|
|
96
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const testExample: import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { Table, TableColumn } from '.';
|
|
4
|
+
const data = [
|
|
5
|
+
{
|
|
6
|
+
col1: 'Cell 1-1',
|
|
7
|
+
col2: 'Cell 1-2',
|
|
8
|
+
col3: 'Cell 1-3',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
col1: 'Cell 2-1',
|
|
12
|
+
col2: 'Cell 2-2',
|
|
13
|
+
col3: 'Cell 2-3',
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
export const testExample = (_jsxs(Table, Object.assign({ data: data }, { children: [_jsx(TableColumn, { header: "Column 1", dataKey: "col1" }), _jsx(TableColumn, Object.assign({ header: "Column 2" }, { children: (row) => row.col2 })), _jsx(TableColumn, { dataKey: "col3", header: "Column 3" })] })));
|
|
17
|
+
describe('Table', () => {
|
|
18
|
+
it('renders all headers and cells', () => {
|
|
19
|
+
const { getByText } = render(testExample);
|
|
20
|
+
const headers = ['Column 1', 'Column 2', 'Column 3'];
|
|
21
|
+
const cells = [
|
|
22
|
+
'Cell 1-1',
|
|
23
|
+
'Cell 1-2',
|
|
24
|
+
'Cell 1-3',
|
|
25
|
+
'Cell 2-1',
|
|
26
|
+
'Cell 2-2',
|
|
27
|
+
'Cell 2-3',
|
|
28
|
+
];
|
|
29
|
+
headers.forEach((header) => {
|
|
30
|
+
expect(getByText(header)).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
cells.forEach((cell) => {
|
|
33
|
+
expect(getByText(cell)).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StyledElementProps, StylesProp } from '../../../theme';
|
|
3
|
+
import { SortConfig } from '../../../utils/sortByKey';
|
|
4
|
+
type ColumnRenderFn<RowData> = (data: RowData) => React.ReactNode;
|
|
5
|
+
type ColumnProps<RowData extends object> = {
|
|
6
|
+
header: string;
|
|
7
|
+
sortable?: boolean;
|
|
8
|
+
sortKey?: keyof RowData;
|
|
9
|
+
dataKey?: keyof RowData;
|
|
10
|
+
headerStyles?: StylesProp;
|
|
11
|
+
align?: 'left' | 'center' | 'right';
|
|
12
|
+
alignHeader?: 'left' | 'center' | 'right';
|
|
13
|
+
children?: ColumnRenderFn<RowData>;
|
|
14
|
+
breakpoint?: number;
|
|
15
|
+
sx?: StylesProp;
|
|
16
|
+
};
|
|
17
|
+
type ChildList = ChildList[] | JSX.Element | null | undefined;
|
|
18
|
+
type TableProps<RowData> = StyledElementProps<HTMLTableElement, {
|
|
19
|
+
data: RowData[];
|
|
20
|
+
sortConfig?: SortConfig<RowData>;
|
|
21
|
+
updateSort?: (sortConfig: SortConfig<RowData>) => void;
|
|
22
|
+
children: ChildList[];
|
|
23
|
+
cellStyles?: StylesProp;
|
|
24
|
+
alternateRowColor?: boolean;
|
|
25
|
+
showRowDividers?: boolean;
|
|
26
|
+
showColumnDividers?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
export declare function TableColumn<RowData extends object>(props: ColumnProps<RowData>): null;
|
|
29
|
+
export declare function Table<RowData extends object>(props: TableProps<RowData>): import("react").JSX.Element;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "theme-ui/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { COLOR } from '../../../theme/colors';
|
|
4
|
+
import { useEnvironment } from '../../providers/env';
|
|
5
|
+
import { FONT_SIZE, TYPOGRAPHY_TYPE, typographyStyleMap, } from '../../../theme/typography';
|
|
6
|
+
import { useMediaQuery } from '../../providers/media';
|
|
7
|
+
import { Row } from '../layout/Row';
|
|
8
|
+
import _ArrowDropDown from '@mui/icons-material/ArrowDropDown';
|
|
9
|
+
import _ArrowDropUp from '@mui/icons-material/ArrowDropUp';
|
|
10
|
+
import { importedDefaultComponentShim } from '../../../utils/misc';
|
|
11
|
+
import { Icon } from '../Icon';
|
|
12
|
+
import { SORT_DIRECTION } from '../../../utils/sortByKey';
|
|
13
|
+
const ArrowDropDown = importedDefaultComponentShim(_ArrowDropDown);
|
|
14
|
+
const ArrowDropUp = importedDefaultComponentShim(_ArrowDropUp);
|
|
15
|
+
const useColumnSpec = (children) => {
|
|
16
|
+
const headerList = [];
|
|
17
|
+
const parseHeaders = (children) => {
|
|
18
|
+
children.forEach((child) => {
|
|
19
|
+
if (Array.isArray(child)) {
|
|
20
|
+
parseHeaders(child);
|
|
21
|
+
}
|
|
22
|
+
else if (child) {
|
|
23
|
+
headerList.push(child.props.header);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
parseHeaders(children);
|
|
28
|
+
const columnList = JSON.stringify(headerList);
|
|
29
|
+
return useMemo(() => {
|
|
30
|
+
const columnProps = [];
|
|
31
|
+
const parseColumnProps = (children) => {
|
|
32
|
+
children.forEach((child) => {
|
|
33
|
+
if (Array.isArray(child)) {
|
|
34
|
+
parseColumnProps(child);
|
|
35
|
+
}
|
|
36
|
+
else if (child) {
|
|
37
|
+
columnProps.push(child.props);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
parseColumnProps(children);
|
|
42
|
+
return columnProps;
|
|
43
|
+
}, [columnList]);
|
|
44
|
+
};
|
|
45
|
+
export function TableColumn(props) {
|
|
46
|
+
const { flagInDevelopment } = useEnvironment();
|
|
47
|
+
flagInDevelopment('TableColumn should not be used outside of Table component');
|
|
48
|
+
console.log('We offer this log to you in reverence, oh compiler gods', props);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
export function Table(props) {
|
|
52
|
+
const { role, data, alternateRowColor = true, cellStyles, sx, children, showRowDividers = true, showColumnDividers = false, sortConfig, updateSort, } = props;
|
|
53
|
+
const cellTypographyStyles = typographyStyleMap[TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM];
|
|
54
|
+
const headerTypographyStyles = typographyStyleMap[TYPOGRAPHY_TYPE.CONTROL_MEDIUM];
|
|
55
|
+
const { breakpoint } = useMediaQuery();
|
|
56
|
+
const columnSpec = useColumnSpec(children);
|
|
57
|
+
const getCellStyles = (params) => {
|
|
58
|
+
const { columnProps, rowIndex, columnIndex } = params;
|
|
59
|
+
const isLastColumn = columnIndex === columnSpec.length - 1;
|
|
60
|
+
const isLastRow = rowIndex === data.length - 1;
|
|
61
|
+
const cellAlign = columnProps.align || 'left';
|
|
62
|
+
const styles = Object.assign({ bg: alternateRowColor && rowIndex % 2 === 1
|
|
63
|
+
? COLOR.EXTRA_EXTRA_LIGHT_GRAY
|
|
64
|
+
: COLOR.WHITE, p: 3, borderBottom: showRowDividers && !isLastRow ? '1px solid' : 'none', borderRight: showColumnDividers && !isLastColumn ? '1px solid' : 'none', borderColor: COLOR.LIGHT_GRAY, textAlign: cellAlign }, cellTypographyStyles);
|
|
65
|
+
return Object.assign(Object.assign(Object.assign({}, styles), cellStyles), columnProps.sx);
|
|
66
|
+
};
|
|
67
|
+
return (_jsxs("table", Object.assign({ role: role, sx: sx }, { children: [_jsx("thead", Object.assign({ role: "rowgroup" }, { children: _jsx("tr", { children: columnSpec.map((column, i) => {
|
|
68
|
+
const isLastColumn = i === columnSpec.length - 1;
|
|
69
|
+
if (column.breakpoint && breakpoint < column.breakpoint) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const canSort = sortConfig && column.sortable;
|
|
73
|
+
const sortKey = column.sortKey || column.dataKey;
|
|
74
|
+
const onSort = () => {
|
|
75
|
+
if (canSort) {
|
|
76
|
+
const direction = sortConfig.direction === SORT_DIRECTION.ASC
|
|
77
|
+
? SORT_DIRECTION.DESC
|
|
78
|
+
: SORT_DIRECTION.ASC;
|
|
79
|
+
updateSort &&
|
|
80
|
+
updateSort({ key: sortKey, direction });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return (_jsx("th", Object.assign({ role: "columnheader", sx: Object.assign(Object.assign({ textAlign: column.alignHeader || column.align || 'left', borderBottom: '1px solid', borderRight: showColumnDividers && !isLastColumn ? '1px solid' : 'none', borderColor: COLOR.LIGHT_GRAY, px: 3, pb: 1 }, headerTypographyStyles), column.headerStyles) }, { children: _jsxs(Row, Object.assign({ onClick: onSort, tabIndex: canSort ? 0 : undefined, sx: { cursor: canSort ? 'pointer' : 'default' } }, { children: [column.header, canSort &&
|
|
84
|
+
sortConfig.key === sortKey &&
|
|
85
|
+
(sortConfig.direction === SORT_DIRECTION.ASC ? (_jsx(Icon, { icon: ArrowDropUp, sx: { ml: 1 }, size: FONT_SIZE.MD })) : (_jsx(Icon, { icon: ArrowDropDown, sx: { ml: 1 }, size: FONT_SIZE.MD })))] })) }), i));
|
|
86
|
+
}) }) })), _jsx("tbody", Object.assign({ role: "rowgroup" }, { children: data.map((rowData, rowIndex) => {
|
|
87
|
+
return (_jsx("tr", Object.assign({ role: "row" }, { children: columnSpec.map((column, columnIndex) => {
|
|
88
|
+
if (column.breakpoint && breakpoint < column.breakpoint) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const { children, dataKey } = column;
|
|
92
|
+
const cellStyles = getCellStyles({
|
|
93
|
+
columnProps: column,
|
|
94
|
+
rowIndex,
|
|
95
|
+
columnIndex,
|
|
96
|
+
});
|
|
97
|
+
return (_jsx("td", Object.assign({ sx: cellStyles }, { children: _jsxs(_Fragment, { children: [dataKey ? rowData[dataKey] : null, !dataKey && children && children(rowData)] }) }), columnIndex));
|
|
98
|
+
}) }), rowIndex));
|
|
99
|
+
}) }))] })));
|
|
100
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyledElementProps } from '../../../theme';
|
|
3
|
+
export type BoxProps = StyledElementProps<HTMLDivElement>;
|
|
4
|
+
export declare const Box: React.ForwardRefExoticComponent<{
|
|
5
|
+
sx?: import("../../../theme").StylesProp | undefined;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & object & {
|
|
8
|
+
htmlFor?: string | undefined;
|
|
9
|
+
} & React.RefAttributes<HTMLDivElement>>;
|