@ndlib/component-library 0.0.99 → 0.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/composites/Card/Card.stories.d.ts +1 -0
- package/dist/components/composites/Card/Card.stories.js +5 -1
- package/dist/components/composites/Card/index.d.ts +1 -0
- package/dist/components/composites/Card/index.js +2 -2
- package/dist/components/elements/Markdown/Markdown.stories.js +2 -0
- package/dist/components/elements/Markdown/Markdown.test.js +7 -2
- package/dist/components/elements/Markdown/index.d.ts +0 -2
- package/dist/components/elements/Markdown/index.js +2 -8
- package/package.json +4 -3
|
@@ -6,6 +6,7 @@ type Story = StoryObj<typeof Card>;
|
|
|
6
6
|
export declare const Default: Story;
|
|
7
7
|
export declare const TruncateHeadline: Story;
|
|
8
8
|
export declare const Horizontal: Story;
|
|
9
|
+
export declare const CustomBackgroundColor: Story;
|
|
9
10
|
export declare const DateCards: Story;
|
|
10
11
|
export declare const Clickable: Story;
|
|
11
12
|
export declare const Raised: Story;
|
|
@@ -93,8 +93,12 @@ export const Horizontal = {
|
|
|
93
93
|
render: () => (_jsx(Column, { children: horizontalCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, layout: CARD_LAYOUT.HORIZONTAL })))) })),
|
|
94
94
|
args: {},
|
|
95
95
|
};
|
|
96
|
+
export const CustomBackgroundColor = {
|
|
97
|
+
render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, backgroundColor: COLOR.ND_SKY_BLUE })))) })),
|
|
98
|
+
args: {},
|
|
99
|
+
};
|
|
96
100
|
export const DateCards = {
|
|
97
|
-
render: () => (_jsx(Column, { children: dateCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, layout: CARD_LAYOUT.HORIZONTAL, sx: { height: '120px' } })))) })),
|
|
101
|
+
render: () => (_jsx(Column, { children: dateCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, layout: CARD_LAYOUT.HORIZONTAL, sx: { height: '120px' }, backgroundColor: COLOR.TRANSPARENT })))) })),
|
|
98
102
|
args: {},
|
|
99
103
|
};
|
|
100
104
|
export const Clickable = {
|
|
@@ -52,7 +52,7 @@ const DateDisplay = ({ date: dateString }) => {
|
|
|
52
52
|
mt: 1,
|
|
53
53
|
} }, { children: MONTH_LABELS[date.getMonth()] }))] })));
|
|
54
54
|
};
|
|
55
|
-
export const Card = ({ size, displayDate, headline, image, layout, onClick, raised, truncateHeadlineAfter, heading, headingStyles, headingIcon, headingAction, sx, imageHeight: imageHeightProp, imageWidth: imageWidthProp, children, }) => {
|
|
55
|
+
export const Card = ({ size, displayDate, headline, image, layout, onClick, raised, truncateHeadlineAfter, heading, headingStyles, headingIcon, headingAction, backgroundColor, sx, imageHeight: imageHeightProp, imageWidth: imageWidthProp, children, }) => {
|
|
56
56
|
const theme = useTheme();
|
|
57
57
|
const contentPaddingX = size === CARD_SIZE.SM ? 3 : 4;
|
|
58
58
|
const isVertical = !layout || layout === CARD_LAYOUT.VERTICAL;
|
|
@@ -71,7 +71,7 @@ export const Card = ({ size, displayDate, headline, image, layout, onClick, rais
|
|
|
71
71
|
if (onClick && e.key === KEY_CODES.ENTER) {
|
|
72
72
|
onClick();
|
|
73
73
|
}
|
|
74
|
-
}, tabIndex: onClick ? 0 : undefined, sx: Object.assign({ boxShadow: raised || heading ? theme.boxShadow.NORMAL : undefined, width: !isVertical && '100%', borderBottom: 'solid 2px', borderColor: COLOR.TRANSPARENT, cursor: onClick ? 'pointer' : undefined, display: 'flex', flexDirection: layout === CARD_LAYOUT.HORIZONTAL ? 'row' : 'column', alignItems: 'flex-start', ':hover,:focus': onClick
|
|
74
|
+
}, tabIndex: onClick ? 0 : undefined, sx: Object.assign({ boxShadow: raised || heading ? theme.boxShadow.NORMAL : undefined, width: !isVertical && '100%', backgroundColor: backgroundColor ? backgroundColor : COLOR.WHITE, borderBottom: 'solid 2px', borderColor: COLOR.TRANSPARENT, cursor: onClick ? 'pointer' : undefined, display: 'flex', flexDirection: layout === CARD_LAYOUT.HORIZONTAL ? 'row' : 'column', alignItems: 'flex-start', ':hover,:focus': onClick
|
|
75
75
|
? {
|
|
76
76
|
transform: 'scale(1.01)',
|
|
77
77
|
borderColor: COLOR.ND_SKY_BLUE_DARK,
|
|
@@ -57,6 +57,8 @@ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
|
57
57
|
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
58
58
|
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
59
59
|
nulla pariatur.
|
|
60
|
+
|
|
61
|
+
https://this-should-be-auto-linked.nd.edu
|
|
60
62
|
`;
|
|
61
63
|
export const Default = {
|
|
62
64
|
render: (args) => _jsx(Markdown, Object.assign({}, args)),
|
|
@@ -35,6 +35,8 @@ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
|
35
35
|
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
36
36
|
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
37
37
|
nulla pariatur.
|
|
38
|
+
|
|
39
|
+
https://this-should-be-auto-linked.nd.edu
|
|
38
40
|
`;
|
|
39
41
|
const htmlMarkdown = `
|
|
40
42
|
## HTML Content
|
|
@@ -74,12 +76,15 @@ describe('Markdown', () => {
|
|
|
74
76
|
name: 'Heading 5',
|
|
75
77
|
level: 6,
|
|
76
78
|
})).toBeInTheDocument();
|
|
79
|
+
expect(getByRole('link', {
|
|
80
|
+
name: 'https://this-should-be-auto-linked.nd.edu',
|
|
81
|
+
})).toBeInTheDocument();
|
|
77
82
|
expect(getAllByRole('list')).toHaveLength(3);
|
|
78
83
|
});
|
|
79
84
|
it('renders allowed html when included', () => {
|
|
80
|
-
const { container, getByText,
|
|
85
|
+
const { container, getByText, getAllByRole } = render(_jsx(Markdown, { content: htmlMarkdown, enableHtml: true }));
|
|
81
86
|
expect(getByText('hello world')).toBeDefined();
|
|
82
|
-
expect(
|
|
87
|
+
expect(getAllByRole('link')).toBeDefined();
|
|
83
88
|
expect(() => getByText(' ')).toThrow();
|
|
84
89
|
expect(container.getElementsByTagName('script')).toHaveLength(0);
|
|
85
90
|
expect(container.getElementsByTagName('img')).toHaveLength(0);
|
|
@@ -6,7 +6,6 @@ export declare const DEFAULT_ALLOWED_ATTRIBUTES: {
|
|
|
6
6
|
iframe: string[];
|
|
7
7
|
a: sanitizeHtml.AllowedAttribute[];
|
|
8
8
|
};
|
|
9
|
-
export declare const DEFAULT_ALLOWED_IFRAME_DOMAINS: string[];
|
|
10
9
|
type MarkdownProps = StyledElementProps<HTMLDivElement, {
|
|
11
10
|
content: string;
|
|
12
11
|
enableHtml?: boolean;
|
|
@@ -14,7 +13,6 @@ type MarkdownProps = StyledElementProps<HTMLDivElement, {
|
|
|
14
13
|
headingLevelOffset?: number;
|
|
15
14
|
sanitizeHtmlOptions?: {
|
|
16
15
|
allowedTags?: string[];
|
|
17
|
-
allowedIframeDomains?: string[];
|
|
18
16
|
allowedAttributes?: sanitizeHtml.IOptions['allowedAttributes'];
|
|
19
17
|
};
|
|
20
18
|
customStyles?: Record<string, StylesProp>;
|
|
@@ -18,6 +18,7 @@ import { HEADING_SIZE, Heading } from '../text/Heading';
|
|
|
18
18
|
import { Bold, Italic } from '../text/Inline';
|
|
19
19
|
import { firstChildAltSelector } from '../../../utils/misc';
|
|
20
20
|
import sanitizeHtml from 'sanitize-html';
|
|
21
|
+
import remarkGfm from 'remark-gfm';
|
|
21
22
|
import { BlockQuote } from '../BlockQuote';
|
|
22
23
|
export const DEFAULT_ALLOWED_TAGS = sanitizeHtml.defaults.allowedTags.concat([
|
|
23
24
|
'iframe',
|
|
@@ -27,11 +28,6 @@ export const DEFAULT_ALLOWED_ATTRIBUTES = Object.assign(Object.assign({}, saniti
|
|
|
27
28
|
'data-card-width',
|
|
28
29
|
'data-card-controls',
|
|
29
30
|
]) });
|
|
30
|
-
export const DEFAULT_ALLOWED_IFRAME_DOMAINS = [
|
|
31
|
-
'facebook.com',
|
|
32
|
-
'youtube.com',
|
|
33
|
-
'nd.edu',
|
|
34
|
-
];
|
|
35
31
|
const dynamicTopMarginStyles = {
|
|
36
32
|
[firstChildAltSelector]: {
|
|
37
33
|
mt: 0,
|
|
@@ -43,12 +39,10 @@ export const Markdown = (_a) => {
|
|
|
43
39
|
if (enableHtml) {
|
|
44
40
|
sanitizedContent = sanitizeHtml(content, {
|
|
45
41
|
allowedTags: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedTags) || DEFAULT_ALLOWED_TAGS,
|
|
46
|
-
allowedIframeDomains: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedIframeDomains) ||
|
|
47
|
-
DEFAULT_ALLOWED_IFRAME_DOMAINS,
|
|
48
42
|
allowedAttributes: (sanitizeHtmlOptions === null || sanitizeHtmlOptions === void 0 ? void 0 : sanitizeHtmlOptions.allowedAttributes) || DEFAULT_ALLOWED_ATTRIBUTES,
|
|
49
43
|
});
|
|
50
44
|
}
|
|
51
|
-
return (_jsx("div", Object.assign({}, rest, { children: _jsx(ReactMarkdown, Object.assign({ rehypePlugins: enableHtml ? [rehypeRaw] : [], components: {
|
|
45
|
+
return (_jsx("div", Object.assign({}, rest, { children: _jsx(ReactMarkdown, Object.assign({ rehypePlugins: enableHtml ? [rehypeRaw, remarkGfm] : [remarkGfm], components: {
|
|
52
46
|
h1: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.XL }, props, { level: props.level + headingLevelOffset, standalone: true, sx: Object.assign(Object.assign({}, dynamicTopMarginStyles), customStyles.h1) }))),
|
|
53
47
|
h2: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG }, props, { level: props.level + headingLevelOffset, standalone: true, sx: Object.assign(Object.assign({}, dynamicTopMarginStyles), customStyles.h2) }))),
|
|
54
48
|
h3: (props) => (_jsx(Heading, Object.assign({ size: HEADING_SIZE.MD }, props, { level: props.level + headingLevelOffset, standalone: true, sx: Object.assign(Object.assign({}, dynamicTopMarginStyles), customStyles.h3) }))),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndlib/component-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.101",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"storybook": "^7.0.17",
|
|
78
78
|
"theme-ui": "^0.16.1",
|
|
79
79
|
"typescript": "^5.0.2",
|
|
80
|
-
"vite": "^4.
|
|
80
|
+
"vite": "^4.5.2",
|
|
81
81
|
"vitest": "^0.31.4"
|
|
82
82
|
},
|
|
83
83
|
"prettier": {
|
|
@@ -92,7 +92,8 @@
|
|
|
92
92
|
"react-markdown": "^8.0.7",
|
|
93
93
|
"react-modal": "^3.16.1",
|
|
94
94
|
"rehype-raw": "^6.1.1",
|
|
95
|
-
"
|
|
95
|
+
"remark-gfm": "^4.0.0",
|
|
96
|
+
"sanitize-html": "^2.12.1",
|
|
96
97
|
"schema-dts": "^1.1.2"
|
|
97
98
|
}
|
|
98
99
|
}
|