@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,103 @@
|
|
|
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 from 'react';
|
|
14
|
+
import _CircleIcon from '@mui/icons-material/Circle';
|
|
15
|
+
import _CircleOutlinedIcon from '@mui/icons-material/CircleOutlined';
|
|
16
|
+
import _SquareIcon from '@mui/icons-material/Square';
|
|
17
|
+
import _SquareOutlinedIcon from '@mui/icons-material/SquareOutlined';
|
|
18
|
+
import { COLOR, Label, TYPOGRAPHY_TYPE } from '../../..';
|
|
19
|
+
import { FONT_SIZE, getTypographyStyles } from '../../../theme/typography';
|
|
20
|
+
import { Icon } from '../Icon';
|
|
21
|
+
import { importedDefaultComponentShim } from '../../../utils/misc';
|
|
22
|
+
import { useLinesHeight } from '../text/ReadMore';
|
|
23
|
+
import { Column } from '../layout/Column';
|
|
24
|
+
import { useEnvironment } from '../../providers/env';
|
|
25
|
+
const CircleIcon = importedDefaultComponentShim(_CircleIcon);
|
|
26
|
+
const CircleOutlinedIcon = importedDefaultComponentShim(_CircleOutlinedIcon);
|
|
27
|
+
const SquareIcon = importedDefaultComponentShim(_SquareIcon);
|
|
28
|
+
const SquareOutlinedIcon = importedDefaultComponentShim(_SquareOutlinedIcon);
|
|
29
|
+
export var LIST_SIZE;
|
|
30
|
+
(function (LIST_SIZE) {
|
|
31
|
+
LIST_SIZE["SM"] = "sm";
|
|
32
|
+
LIST_SIZE["MD"] = "md";
|
|
33
|
+
LIST_SIZE["LG"] = "lg";
|
|
34
|
+
})(LIST_SIZE || (LIST_SIZE = {}));
|
|
35
|
+
const marginSizeMap = {
|
|
36
|
+
[LIST_SIZE.SM]: 2,
|
|
37
|
+
[LIST_SIZE.MD]: 3,
|
|
38
|
+
[LIST_SIZE.LG]: 4,
|
|
39
|
+
};
|
|
40
|
+
const iconSizeMap = {
|
|
41
|
+
[LIST_SIZE.SM]: FONT_SIZE.XXS,
|
|
42
|
+
[LIST_SIZE.MD]: FONT_SIZE.XXS,
|
|
43
|
+
[LIST_SIZE.LG]: FONT_SIZE.XS,
|
|
44
|
+
};
|
|
45
|
+
const defaultIcons = [
|
|
46
|
+
CircleIcon,
|
|
47
|
+
CircleOutlinedIcon,
|
|
48
|
+
SquareIcon,
|
|
49
|
+
SquareOutlinedIcon,
|
|
50
|
+
];
|
|
51
|
+
const sizeTypographyMap = {
|
|
52
|
+
[LIST_SIZE.SM]: TYPOGRAPHY_TYPE.CONDENSED_TEXT_SMALL,
|
|
53
|
+
[LIST_SIZE.MD]: TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM,
|
|
54
|
+
[LIST_SIZE.LG]: TYPOGRAPHY_TYPE.CONDENSED_TEXT_LARGE,
|
|
55
|
+
};
|
|
56
|
+
const ListConfigContext = React.createContext({
|
|
57
|
+
size: LIST_SIZE.MD,
|
|
58
|
+
ordered: false,
|
|
59
|
+
icon: CircleIcon,
|
|
60
|
+
iconColor: COLOR.TEXT,
|
|
61
|
+
iconSize: undefined,
|
|
62
|
+
depth: -1,
|
|
63
|
+
});
|
|
64
|
+
const useListConfig = () => React.useContext(ListConfigContext);
|
|
65
|
+
export const List = ({ sx, size: sizeParam, ordered, icon, iconSize: iconSizeParam, iconColor: iconColorParam, children, }) => {
|
|
66
|
+
const { depth: parentDepth, size: parentSize, iconColor: parentIconColor, iconSize: parentIconSize, } = useListConfig();
|
|
67
|
+
const depth = parentDepth + 1;
|
|
68
|
+
const defaultStyles = Object.assign({ listStyleType: 'none' }, getTypographyStyles());
|
|
69
|
+
const defaultIcon = defaultIcons[depth] || CircleIcon;
|
|
70
|
+
const size = sizeParam || parentSize || LIST_SIZE.MD;
|
|
71
|
+
const iconSize = iconSizeParam || parentIconSize || iconSizeMap[size];
|
|
72
|
+
const iconColor = iconColorParam || parentIconColor || COLOR.TEXT;
|
|
73
|
+
return (_jsx(ListConfigContext.Provider, Object.assign({ value: {
|
|
74
|
+
size,
|
|
75
|
+
icon: icon || defaultIcon,
|
|
76
|
+
iconColor,
|
|
77
|
+
iconSize,
|
|
78
|
+
ordered: ordered || false,
|
|
79
|
+
depth,
|
|
80
|
+
} }, { 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 }))) })));
|
|
81
|
+
};
|
|
82
|
+
export const ListItem = (_a) => {
|
|
83
|
+
var { index, sx, icon: iconParam, iconSize: iconSizeParam, iconColor: iconColorParam, onIconClick, onClick, children, iconLabel, tabIndex: tabIndexParam } = _a, rest = __rest(_a, ["index", "sx", "icon", "iconSize", "iconColor", "onIconClick", "onClick", "children", "iconLabel", "tabIndex"]);
|
|
84
|
+
const { ordered, icon: listIcon, iconColor: listIconColor, iconSize: listIconSize, size, depth, } = useListConfig();
|
|
85
|
+
const { flagInDevelopment } = useEnvironment();
|
|
86
|
+
if (onIconClick && !iconLabel) {
|
|
87
|
+
flagInDevelopment('ListItem component with onIconClick should have an iconLabel prop for accessibility');
|
|
88
|
+
}
|
|
89
|
+
const icon = iconParam || listIcon;
|
|
90
|
+
const iconSize = iconSizeParam || listIconSize;
|
|
91
|
+
const iconColor = iconColorParam || listIconColor;
|
|
92
|
+
const typography = sizeTypographyMap[size];
|
|
93
|
+
const typographyStyles = getTypographyStyles(sizeTypographyMap[size]);
|
|
94
|
+
const lineHeight = useLinesHeight({ typography, lines: 1 });
|
|
95
|
+
const tabIndex = tabIndexParam || (onClick ? 0 : undefined);
|
|
96
|
+
console.log('rendering tab index', tabIndex);
|
|
97
|
+
return (_jsxs("li", Object.assign({ sx: Object.assign(Object.assign({ depth, display: 'flex', mt: index === 0 && depth === 0 ? 0 : marginSizeMap[size], ml: 1 }, typographyStyles), sx), tabIndex: tabIndex }, rest, { children: [ordered ? (_jsxs(Label, Object.assign({ standalone: true, sx: { mr: 2 } }, { children: [index + 1, "."] }))) : (_jsx(Column, Object.assign({ sx: { height: lineHeight }, justify: "center" }, { children: _jsx(Icon, { icon: icon, color: iconColor, size: iconSize, onClick: onIconClick, "aria-label": iconLabel, sx: {
|
|
98
|
+
mr: 3,
|
|
99
|
+
alignItems: 'flex-start',
|
|
100
|
+
} }) }))), _jsx("div", Object.assign({ sx: {
|
|
101
|
+
cursor: onClick ? 'pointer' : 'default',
|
|
102
|
+
} }, { children: children }))] })));
|
|
103
|
+
};
|
|
@@ -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,33 @@
|
|
|
1
|
+
import React, { Key } from 'react';
|
|
2
|
+
import { StyledElementProps } from '../../../theme';
|
|
3
|
+
import { BasicOption, RenderOption } from '../Fields/option';
|
|
4
|
+
type ListBoxProps<Value extends Key, Option extends BasicOption<Value>> = StyledElementProps<HTMLDivElement, {
|
|
5
|
+
options: Option[];
|
|
6
|
+
renderOption?: RenderOption<Value, Option>;
|
|
7
|
+
selected?: Value;
|
|
8
|
+
focused?: Value;
|
|
9
|
+
selectOption?: (option: Option) => void;
|
|
10
|
+
onDownPress?: () => void;
|
|
11
|
+
onUpPress?: () => void;
|
|
12
|
+
onSelect?: () => void;
|
|
13
|
+
onBlur?: () => void;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const ListBox: <Value extends React.Key = string, Option extends BasicOption<Value> = any>(props: {
|
|
16
|
+
sx?: import("../../..").StylesProp | undefined;
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & {
|
|
19
|
+
options: Option[];
|
|
20
|
+
renderOption?: RenderOption<Value, Option> | undefined;
|
|
21
|
+
selected?: Value | undefined;
|
|
22
|
+
focused?: Value | undefined;
|
|
23
|
+
selectOption?: ((option: Option) => void) | undefined;
|
|
24
|
+
onDownPress?: (() => void) | undefined;
|
|
25
|
+
onUpPress?: (() => void) | undefined;
|
|
26
|
+
onSelect?: (() => void) | undefined;
|
|
27
|
+
onBlur?: (() => void) | undefined;
|
|
28
|
+
} & {
|
|
29
|
+
htmlFor?: string | undefined;
|
|
30
|
+
} & {
|
|
31
|
+
ref?: React.ForwardedRef<HTMLDivElement> | undefined;
|
|
32
|
+
}) => any;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 React from 'react';
|
|
14
|
+
import { COLOR } from '../../..';
|
|
15
|
+
import { TYPOGRAPHY_TYPE, getTypographyStyles } from '../../../theme/typography';
|
|
16
|
+
import { defaultRenderOption, getOptionId, } from '../Fields/option';
|
|
17
|
+
function ListBoxInner(_a, ref) {
|
|
18
|
+
var { options, renderOption: renderOptionParam, selected, focused, selectOption, sx } = _a, rest = __rest(_a, ["options", "renderOption", "selected", "focused", "selectOption", "sx"]);
|
|
19
|
+
const renderOption = renderOptionParam || defaultRenderOption;
|
|
20
|
+
const typography = getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM);
|
|
21
|
+
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) => {
|
|
22
|
+
console.log(e);
|
|
23
|
+
} }, rest, { children: options.map((option) => (_jsx("div", Object.assign({ id: getOptionId(option.value), "aria-selected": selected === option.value, role: "option", onClick: option.onClick, onMouseDown: () => selectOption && selectOption(option), sx: {
|
|
24
|
+
px: 4,
|
|
25
|
+
py: 3,
|
|
26
|
+
backgroundColor: focused === option.value
|
|
27
|
+
? COLOR.EXTRA_EXTRA_LIGHT_GRAY
|
|
28
|
+
: COLOR.BACKGROUND,
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
borderBottom: 'solid 1px',
|
|
31
|
+
borderBottomColor: COLOR.LIGHT_GRAY,
|
|
32
|
+
color: COLOR.TEXT,
|
|
33
|
+
':last-of-type': {
|
|
34
|
+
borderBottom: 'none',
|
|
35
|
+
borderBottomRightRadius: '4px',
|
|
36
|
+
borderBottomLeftRadius: '4px',
|
|
37
|
+
},
|
|
38
|
+
':first-of-type': {
|
|
39
|
+
borderTopRightRadius: '4px',
|
|
40
|
+
borderTopLeftRadius: '4px',
|
|
41
|
+
},
|
|
42
|
+
':hover': {
|
|
43
|
+
backgroundColor: COLOR.EXTRA_EXTRA_LIGHT_GRAY,
|
|
44
|
+
},
|
|
45
|
+
} }, { children: renderOption({
|
|
46
|
+
option,
|
|
47
|
+
selected: selected === option.value,
|
|
48
|
+
focused: focused === option.value,
|
|
49
|
+
}) }), option.value))) })));
|
|
50
|
+
}
|
|
51
|
+
export const ListBox = React.forwardRef(ListBoxInner);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Markdown } from '.';
|
|
3
|
+
declare const meta: Meta<typeof Markdown>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Markdown>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const WithHtml: Story;
|
|
8
|
+
export declare const CustomizeImages: Story;
|
|
9
|
+
export declare const CustomHtmlSanitize: Story;
|
|
10
|
+
export declare const NoHtml: Story;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DEFAULT_ALLOWED_ATTRIBUTES, DEFAULT_ALLOWED_TAGS, 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
|
+
|
|
17
|
+
# Inline styles
|
|
18
|
+
This paragraph has __bold content__ and **more bold content** and _italic content_ and *more italic content*
|
|
19
|
+
|
|
20
|
+
# Image
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
# Heading 1
|
|
24
|
+
${sampleParagraph}
|
|
25
|
+
|
|
26
|
+
${sampleParagraph}
|
|
27
|
+
|
|
28
|
+
## Heading 2
|
|
29
|
+
${sampleParagraph}
|
|
30
|
+
|
|
31
|
+
### Heading 3
|
|
32
|
+
${sampleParagraph}
|
|
33
|
+
|
|
34
|
+
#### Heading 4
|
|
35
|
+
${sampleParagraph}
|
|
36
|
+
|
|
37
|
+
##### Heading 5
|
|
38
|
+
${sampleParagraph}
|
|
39
|
+
|
|
40
|
+
###### Heading 6
|
|
41
|
+
${sampleParagraph}
|
|
42
|
+
|
|
43
|
+
- List item 1
|
|
44
|
+
- List item 2
|
|
45
|
+
- List item 2.1
|
|
46
|
+
- List item 2.2
|
|
47
|
+
|
|
48
|
+
1. List item 1
|
|
49
|
+
2. List item 2
|
|
50
|
+
3. List item 3
|
|
51
|
+
`;
|
|
52
|
+
export const Default = {
|
|
53
|
+
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
54
|
+
args: {
|
|
55
|
+
content: startingContent,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const htmlContent = `
|
|
59
|
+
## HTML Content
|
|
60
|
+
<p style='color: red;'>hello world </p>
|
|
61
|
+
<img
|
|
62
|
+
style="width: 300px"
|
|
63
|
+
src="https://s3.amazonaws.com/resources.library.nd.edu/images/website/search.banner.fall.jpg"
|
|
64
|
+
></img>
|
|
65
|
+
<a href="https://google.com" class="embedly-card" data-card-width="100px" data-card-controls="0">Embedded content: https://google.com</a>
|
|
66
|
+
<iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FNDLibraries%2Fvideos%2F1673794309311939%2F&show_text=0&width=560" width="560" height="315" style="border:none;overflow:hidden" scrolling="no" frameborder="0" ></iframe>
|
|
67
|
+
`;
|
|
68
|
+
export const WithHtml = {
|
|
69
|
+
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
70
|
+
args: {
|
|
71
|
+
content: htmlContent,
|
|
72
|
+
enableHtml: true,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
export const CustomizeImages = {
|
|
76
|
+
render: (args) => _jsx(Markdown, Object.assign({}, args, { imageStyles: { width: '200px' } })),
|
|
77
|
+
args: {
|
|
78
|
+
content: startingContent,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
export const CustomHtmlSanitize = {
|
|
82
|
+
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
83
|
+
args: {
|
|
84
|
+
enableHtml: true,
|
|
85
|
+
sanitizeHtmlOptions: {
|
|
86
|
+
allowedAttributes: Object.assign(Object.assign({}, DEFAULT_ALLOWED_ATTRIBUTES), { p: ['style'], img: ['src', 'style'] }),
|
|
87
|
+
allowedTags: [...DEFAULT_ALLOWED_TAGS, 'img'],
|
|
88
|
+
},
|
|
89
|
+
content: htmlContent,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
export const NoHtml = {
|
|
93
|
+
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
94
|
+
args: {
|
|
95
|
+
content: htmlContent,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '../../../utils/test';
|
|
3
|
+
import { DEFAULT_ALLOWED_TAGS, 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
|
+
# Image
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
# Heading 1
|
|
12
|
+
|
|
13
|
+
## Heading 2
|
|
14
|
+
|
|
15
|
+
### Heading 3
|
|
16
|
+
|
|
17
|
+
#### Heading 4
|
|
18
|
+
|
|
19
|
+
##### Heading 5
|
|
20
|
+
|
|
21
|
+
###### Heading 6
|
|
22
|
+
|
|
23
|
+
- List item 1
|
|
24
|
+
- List item 2
|
|
25
|
+
- List item 2.1
|
|
26
|
+
- List item 2.2
|
|
27
|
+
|
|
28
|
+
1. List item 1
|
|
29
|
+
2. List item 2
|
|
30
|
+
3. List item 3
|
|
31
|
+
`;
|
|
32
|
+
const htmlMarkdown = `
|
|
33
|
+
## HTML Content
|
|
34
|
+
<p style='color: red;'>hello world</p>
|
|
35
|
+
<p style='color: red;'> </p>
|
|
36
|
+
<script></script>
|
|
37
|
+
<a href="https://google.com" class="embedly-card" data-card-width="100px" data-card-controls="0">Embedded content: https://google.com</a>
|
|
38
|
+
<iframe src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FNDLibraries%2Fvideos%2F1673794309311939%2F&show_text=0&width=560" width="560" height="315" style="border:none;overflow:hidden" scrolling="no" frameborder="0"></iframe>
|
|
39
|
+
<img href="https://google.com"></img>
|
|
40
|
+
`;
|
|
41
|
+
describe('Markdown', () => {
|
|
42
|
+
it('renders alert content', () => {
|
|
43
|
+
const { getAllByRole, getByRole } = render(_jsx(Markdown, { content: testMarkdown }));
|
|
44
|
+
expect(getByRole('heading', {
|
|
45
|
+
name: 'Heading 1',
|
|
46
|
+
level: 1,
|
|
47
|
+
})).toBeInTheDocument();
|
|
48
|
+
expect(getByRole('heading', {
|
|
49
|
+
name: 'Heading 2',
|
|
50
|
+
level: 2,
|
|
51
|
+
})).toBeInTheDocument();
|
|
52
|
+
expect(getByRole('heading', {
|
|
53
|
+
name: 'Heading 3',
|
|
54
|
+
level: 3,
|
|
55
|
+
})).toBeInTheDocument();
|
|
56
|
+
expect(getByRole('heading', {
|
|
57
|
+
name: 'Heading 4',
|
|
58
|
+
level: 4,
|
|
59
|
+
})).toBeInTheDocument();
|
|
60
|
+
expect(getByRole('heading', {
|
|
61
|
+
name: 'Heading 5',
|
|
62
|
+
level: 5,
|
|
63
|
+
})).toBeInTheDocument();
|
|
64
|
+
expect(getByRole('heading', {
|
|
65
|
+
name: 'Heading 6',
|
|
66
|
+
level: 6,
|
|
67
|
+
})).toBeInTheDocument();
|
|
68
|
+
expect(getAllByRole('list')).toHaveLength(3);
|
|
69
|
+
});
|
|
70
|
+
it('renders allowed html when included', () => {
|
|
71
|
+
const { container, getByText, getByRole } = render(_jsx(Markdown, { content: htmlMarkdown, enableHtml: true }));
|
|
72
|
+
expect(getByText('hello world')).toBeDefined();
|
|
73
|
+
expect(getByRole('link')).toBeDefined();
|
|
74
|
+
expect(() => getByText(' ')).toThrow();
|
|
75
|
+
expect(container.getElementsByTagName('script')).toHaveLength(0);
|
|
76
|
+
expect(container.getElementsByTagName('img')).toHaveLength(0);
|
|
77
|
+
expect(container.getElementsByTagName('iframe')).toHaveLength(1);
|
|
78
|
+
});
|
|
79
|
+
it('does not render html when disabled', () => {
|
|
80
|
+
const { container, getByText } = render(_jsx(Markdown, { content: htmlMarkdown }));
|
|
81
|
+
expect(() => getByText('hello world')).toThrow();
|
|
82
|
+
expect(container.getElementsByTagName('script')).toHaveLength(0);
|
|
83
|
+
expect(container.getElementsByTagName('iframe')).toHaveLength(0);
|
|
84
|
+
});
|
|
85
|
+
it('supports customizing html sanitization', () => {
|
|
86
|
+
const { container } = render(_jsx(Markdown, { content: htmlMarkdown, enableHtml: true, sanitizeHtmlOptions: {
|
|
87
|
+
allowedTags: DEFAULT_ALLOWED_TAGS.concat(['img']),
|
|
88
|
+
} }));
|
|
89
|
+
expect(container.getElementsByTagName('img')).toHaveLength(1);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StyledElementProps } from '../../../theme';
|
|
3
|
+
import sanitizeHtml from 'sanitize-html';
|
|
4
|
+
export declare const DEFAULT_ALLOWED_TAGS: string[];
|
|
5
|
+
export declare const DEFAULT_ALLOWED_ATTRIBUTES: {
|
|
6
|
+
iframe: string[];
|
|
7
|
+
a: sanitizeHtml.AllowedAttribute[];
|
|
8
|
+
};
|
|
9
|
+
export declare const DEFAULT_ALLOWED_IFRAME_DOMAINS: string[];
|
|
10
|
+
type MarkdownProps = StyledElementProps<HTMLDivElement, {
|
|
11
|
+
content: string;
|
|
12
|
+
enableHtml?: boolean;
|
|
13
|
+
imageStyles?: React.CSSProperties;
|
|
14
|
+
sanitizeHtmlOptions?: {
|
|
15
|
+
allowedTags?: string[];
|
|
16
|
+
allowedIframeDomains?: string[];
|
|
17
|
+
allowedAttributes?: sanitizeHtml.IOptions['allowedAttributes'];
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
export declare const Markdown: React.FC<MarkdownProps>;
|
|
21
|
+
export {};
|
|
@@ -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 } from "react/jsx-runtime";
|
|
13
|
+
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';
|
|
14
|
+
import rehypeRaw from 'rehype-raw';
|
|
15
|
+
import { List, ListItem } from '../List';
|
|
16
|
+
import { Paragraph } from '../text/Paragraph';
|
|
17
|
+
import { HEADING_SIZE, Heading } from '../text/Heading';
|
|
18
|
+
import { Bold, Italic } from '../text/Inline';
|
|
19
|
+
import { firstChildAltSelector } from '../../../utils/misc';
|
|
20
|
+
import sanitizeHtml from 'sanitize-html';
|
|
21
|
+
export const DEFAULT_ALLOWED_TAGS = sanitizeHtml.defaults.allowedTags.concat([
|
|
22
|
+
'iframe',
|
|
23
|
+
]);
|
|
24
|
+
export const DEFAULT_ALLOWED_ATTRIBUTES = Object.assign(Object.assign({}, sanitizeHtml.defaults.allowedAttributes), { iframe: ['*'], a: sanitizeHtml.defaults.allowedAttributes.a.concat([
|
|
25
|
+
'class',
|
|
26
|
+
'data-card-width',
|
|
27
|
+
'data-card-controls',
|
|
28
|
+
]) });
|
|
29
|
+
export const DEFAULT_ALLOWED_IFRAME_DOMAINS = [
|
|
30
|
+
'facebook.com',
|
|
31
|
+
'youtube.com',
|
|
32
|
+
'nd.edu',
|
|
33
|
+
];
|
|
34
|
+
const headingStyles = {
|
|
35
|
+
mt: 4,
|
|
36
|
+
[firstChildAltSelector]: {
|
|
37
|
+
mt: 0,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const paragraphStyles = {
|
|
41
|
+
mt: 4,
|
|
42
|
+
[firstChildAltSelector]: {
|
|
43
|
+
mt: 0,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export const Markdown = (_a) => {
|
|
47
|
+
var { content, enableHtml, sanitizeHtmlOptions, imageStyles } = _a, rest = __rest(_a, ["content", "enableHtml", "sanitizeHtmlOptions", "imageStyles"]);
|
|
48
|
+
let sanitizedContent = content;
|
|
49
|
+
if (enableHtml) {
|
|
50
|
+
sanitizedContent = sanitizeHtml(content, {
|
|
51
|
+
allowedTags: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedTags) || DEFAULT_ALLOWED_TAGS,
|
|
52
|
+
allowedIframeDomains: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedIframeDomains) ||
|
|
53
|
+
DEFAULT_ALLOWED_IFRAME_DOMAINS,
|
|
54
|
+
allowedAttributes: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedAttributes) || DEFAULT_ALLOWED_ATTRIBUTES,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return (_jsx("div", Object.assign({}, rest, { children: _jsx(ReactMarkdown, Object.assign({ rehypePlugins: enableHtml ? [rehypeRaw] : [], components: {
|
|
58
|
+
h1: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.XL }, props, { standalone: true, sx: headingStyles, "aria-level": 1 }))),
|
|
59
|
+
h2: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG }, props, { standalone: true, sx: headingStyles, "aria-level": 2 }))),
|
|
60
|
+
h3: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, props, { standalone: true, sx: headingStyles, "aria-level": 3 }))),
|
|
61
|
+
h4: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, props, { standalone: true, sx: headingStyles, "aria-level": 4 }))),
|
|
62
|
+
h5: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, props, { standalone: true, sx: headingStyles, "aria-level": 5 }))),
|
|
63
|
+
h6: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.SM }, props, { standalone: true, sx: headingStyles, "aria-level": 6 }))),
|
|
64
|
+
ol: (props) => _jsx(List, Object.assign({}, props, { ordered: true, sx: { mt: 4 } })),
|
|
65
|
+
ul: (props) => _jsx(List, Object.assign({}, props, { sx: { mt: 4 } })),
|
|
66
|
+
li: (_a) => {
|
|
67
|
+
var { index, ordered } = _a, props = __rest(_a, ["index", "ordered"]);
|
|
68
|
+
return (_jsx(ListItem, Object.assign({ index: index }, props)));
|
|
69
|
+
},
|
|
70
|
+
p: (props) => _jsx(Paragraph, Object.assign({}, props, { sx: paragraphStyles })),
|
|
71
|
+
strong: (props) => _jsx(Bold, Object.assign({}, props)),
|
|
72
|
+
em: (props) => _jsx(Italic, Object.assign({}, props)),
|
|
73
|
+
img: (props) => _jsx("img", Object.assign({}, props, { style: imageStyles })),
|
|
74
|
+
} }, { children: sanitizedContent })) })));
|
|
75
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Pill } from '.';
|
|
3
|
+
declare const meta: Meta<typeof Pill>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Pill>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
export declare const Icon: Story;
|
|
8
|
+
export declare const NoAction: Story;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
3
|
+
import { PILL_SIZE, PILL_TYPE, Pill } from '.';
|
|
4
|
+
import { GROUP_TYPE, Group } from '../Group';
|
|
5
|
+
import { HEADING_SIZE, Heading } from '../text/Heading';
|
|
6
|
+
import { Column } from '../layout/Column';
|
|
7
|
+
import { Row } from '../layout/Row';
|
|
8
|
+
const meta = {
|
|
9
|
+
title: 'Elements/Pill',
|
|
10
|
+
component: Pill,
|
|
11
|
+
tags: ['autodocs'],
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
const sizes = [
|
|
15
|
+
{ size: PILL_SIZE.LG, label: 'Large' },
|
|
16
|
+
{ size: PILL_SIZE.SM, label: 'Small' },
|
|
17
|
+
];
|
|
18
|
+
export const Default = {
|
|
19
|
+
render: (args) => (_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 })), _jsxs(Row, Object.assign({ sx: { mt: 2 } }, { children: [_jsx(Pill, Object.assign({}, args, { size: size.size, sx: { mr: 1 } })), _jsx(Pill, Object.assign({}, args, { size: size.size, type: PILL_TYPE.OUTLINE }))] }))] })))) })),
|
|
20
|
+
args: {
|
|
21
|
+
type: PILL_TYPE.DEFAULT,
|
|
22
|
+
children: 'Virtual Event',
|
|
23
|
+
onClick: () => console.log('clicked'),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export const Icon = {
|
|
27
|
+
render: (args) => (_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 })), _jsxs(Row, Object.assign({ sx: { mt: 2 } }, { children: [_jsx(Pill, Object.assign({}, args, { size: size.size, sx: { mr: 1 }, icon: SearchIcon })), _jsx(Pill, Object.assign({}, args, { size: size.size, type: PILL_TYPE.OUTLINE, icon: SearchIcon }))] }))] })))) })),
|
|
28
|
+
args: {
|
|
29
|
+
type: PILL_TYPE.DEFAULT,
|
|
30
|
+
children: 'Virtual Event',
|
|
31
|
+
onClick: () => console.log('clicked'),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export const NoAction = {
|
|
35
|
+
render: (args) => (_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 })), _jsxs(Row, Object.assign({ sx: { mt: 2 } }, { children: [_jsx(Pill, Object.assign({}, args, { size: size.size, sx: { mr: 1 } })), _jsx(Pill, Object.assign({}, args, { size: size.size, type: PILL_TYPE.OUTLINE }))] }))] })))) })),
|
|
36
|
+
args: {
|
|
37
|
+
type: PILL_TYPE.DEFAULT,
|
|
38
|
+
children: 'Virtual Event',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '../../../utils/test';
|
|
3
|
+
import { Pill } from '.';
|
|
4
|
+
import { fireEvent } from '@testing-library/react';
|
|
5
|
+
import { vitest } from 'vitest';
|
|
6
|
+
describe('Pill', () => {
|
|
7
|
+
it('renders children', () => {
|
|
8
|
+
const { getByText } = render(_jsx(Pill, { children: "Test" }));
|
|
9
|
+
expect(getByText('Test')).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
it('responds to onClick handler', () => {
|
|
12
|
+
const onClick = vitest.fn();
|
|
13
|
+
const { getByRole } = render(_jsx(Pill, { onClick: onClick }));
|
|
14
|
+
const button = getByRole('button');
|
|
15
|
+
fireEvent.click(button);
|
|
16
|
+
expect(onClick).toHaveBeenCalled();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { COLOR } from '../../../theme/colors';
|
|
3
|
+
export declare enum PILL_SIZE {
|
|
4
|
+
SM = "sm",
|
|
5
|
+
LG = "lg"
|
|
6
|
+
}
|
|
7
|
+
export declare enum PILL_TYPE {
|
|
8
|
+
DEFAULT = "default",
|
|
9
|
+
OUTLINE = "outline"
|
|
10
|
+
}
|
|
11
|
+
export declare const Pill: React.ForwardRefExoticComponent<{
|
|
12
|
+
sx?: import("../../../theme").StylesProp | undefined;
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "children" | "onChange"> & {
|
|
15
|
+
size?: PILL_SIZE | undefined;
|
|
16
|
+
type?: PILL_TYPE | undefined;
|
|
17
|
+
color?: COLOR | undefined;
|
|
18
|
+
icon?: React.FC<any> | undefined;
|
|
19
|
+
} & {
|
|
20
|
+
htmlFor?: string | undefined;
|
|
21
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|