@ndlib/component-library 1.0.4 → 1.0.6
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 +22 -2
- package/dist/components/composites/Card/Card.test.js +36 -1
- package/dist/components/composites/Card/index.d.ts +4 -1
- package/dist/components/composites/Card/index.js +32 -6
- package/dist/theme/colors.d.ts +1 -1
- package/dist/theme/colors.js +1 -1
- package/dist/theme/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ declare const meta: Meta<typeof Card>;
|
|
|
4
4
|
export default meta;
|
|
5
5
|
type Story = StoryObj<typeof Card>;
|
|
6
6
|
export declare const Default: Story;
|
|
7
|
+
export declare const ContainedImage: Story;
|
|
7
8
|
export declare const TruncateHeadline: Story;
|
|
8
9
|
export declare const Horizontal: Story;
|
|
9
10
|
export declare const CustomBackgroundColor: Story;
|
|
@@ -16,7 +16,23 @@ export default meta;
|
|
|
16
16
|
const headlinedCards = [
|
|
17
17
|
{
|
|
18
18
|
headline: 'Exhibit — Printing the Nation: A Century of Irish Book Arts',
|
|
19
|
-
image: 'https://
|
|
19
|
+
image: 'https://strapi-prod-library-website-contentbucket52d4b12c-1whgwwl6746tz.s3.us-east-1.amazonaws.com/14_15_I_Ten_American_Diaries_29a3788848.jpg',
|
|
20
|
+
size: CARD_SIZE.SM,
|
|
21
|
+
sx: {
|
|
22
|
+
width: '500px',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
headline: 'Paws, Hooves, Fins & Feathers',
|
|
27
|
+
image: 'https://strapi-prod-library-website-contentbucket52d4b12c-1whgwwl6746tz.s3.us-east-1.amazonaws.com/RBSC_Spring2020_Rep_2_a88660826b.jpg',
|
|
28
|
+
size: CARD_SIZE.SM,
|
|
29
|
+
sx: {
|
|
30
|
+
width: '500px',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
headline: 'Tracy C. Bergstrom, director of the Specialized Collection Services Program',
|
|
35
|
+
image: 'https://strapi-prod-library-website-contentbucket52d4b12c-1whgwwl6746tz.s3.us-east-1.amazonaws.com/Tracy_News_218x275_1dd180dc80.jpg',
|
|
20
36
|
size: CARD_SIZE.SM,
|
|
21
37
|
sx: {
|
|
22
38
|
width: '500px',
|
|
@@ -24,7 +40,7 @@ const headlinedCards = [
|
|
|
24
40
|
},
|
|
25
41
|
{
|
|
26
42
|
headline: 'One Book, One Michiana Digital Exhibit — Papers Alight: Contextualizing Mike Curato’s Flamer. Other text to make this longer than the other card.',
|
|
27
|
-
image: 'https://images.ctfassets.net/cfblb1f7i85j/2sGpdDbNkl6MPnlem6wq1R/995c786624613b5ff07228e481996385/One.Book.2023-Rep.png
|
|
43
|
+
image: 'https://images.ctfassets.net/cfblb1f7i85j/2sGpdDbNkl6MPnlem6wq1R/995c786624613b5ff07228e481996385/One.Book.2023-Rep.png',
|
|
28
44
|
size: CARD_SIZE.SM,
|
|
29
45
|
sx: {
|
|
30
46
|
width: '500px',
|
|
@@ -85,6 +101,10 @@ export const Default = {
|
|
|
85
101
|
render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i })))) })),
|
|
86
102
|
args: {},
|
|
87
103
|
};
|
|
104
|
+
export const ContainedImage = {
|
|
105
|
+
render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({ containImage: true, containerHeight: '280px' }, props, { key: i })))) })),
|
|
106
|
+
args: {},
|
|
107
|
+
};
|
|
88
108
|
export const TruncateHeadline = {
|
|
89
109
|
render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, truncateHeadlineAfter: 2 })))) })),
|
|
90
110
|
args: {},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { fireEvent } from '@testing-library/react';
|
|
2
|
+
import { fireEvent, screen } from '@testing-library/react';
|
|
3
3
|
import { vi } from 'vitest';
|
|
4
|
+
import { COLOR } from '../../../theme/colors';
|
|
4
5
|
import { render } from '../../../utils/test';
|
|
5
6
|
import { Card } from '.';
|
|
6
7
|
import { KEY_CODES } from '../../../utils/misc';
|
|
@@ -34,4 +35,38 @@ describe('Card', () => {
|
|
|
34
35
|
const { getByLabelText } = render(_jsx(Card, { heading: MOCK_HEADLINE }));
|
|
35
36
|
expect(getByLabelText(MOCK_HEADLINE)).toBeDefined();
|
|
36
37
|
});
|
|
38
|
+
it('renders the image with containImage prop', () => {
|
|
39
|
+
const imageSrc = 'https://via.placeholder.com/150';
|
|
40
|
+
const altText = 'Test Image';
|
|
41
|
+
const containerWidth = '500px';
|
|
42
|
+
const containerHeight = '280px';
|
|
43
|
+
render(_jsx(Card, { image: imageSrc, alt: altText, containImage: true, containerWidth: containerWidth, containerHeight: containerHeight }));
|
|
44
|
+
const imageElement = screen.getByAltText(altText);
|
|
45
|
+
expect(imageElement).toBeInTheDocument();
|
|
46
|
+
expect(imageElement).toHaveStyle({
|
|
47
|
+
width: '100%',
|
|
48
|
+
height: 'auto',
|
|
49
|
+
objectFit: 'scale-down',
|
|
50
|
+
});
|
|
51
|
+
const containerElement = imageElement.closest('div');
|
|
52
|
+
expect(containerElement).toHaveStyle({
|
|
53
|
+
width: containerWidth,
|
|
54
|
+
height: containerHeight,
|
|
55
|
+
backgroundColor: COLOR.ND_SKY_BLUE,
|
|
56
|
+
display: 'flex',
|
|
57
|
+
justifyContent: 'center',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it('renders the image without containImage prop', () => {
|
|
62
|
+
const imageSrc = 'https://via.placeholder.com/150';
|
|
63
|
+
const altText = 'Test Image';
|
|
64
|
+
render(_jsx(Card, { image: imageSrc, alt: altText }));
|
|
65
|
+
const imageElement = screen.getByAltText(altText);
|
|
66
|
+
expect(imageElement).toBeInTheDocument();
|
|
67
|
+
expect(imageElement).toHaveStyle({
|
|
68
|
+
width: '100%',
|
|
69
|
+
height: 'auto',
|
|
70
|
+
});
|
|
71
|
+
});
|
|
37
72
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { StyledElementProps, StylesProp } from '../../../theme';
|
|
2
3
|
import { COLOR } from '../../../theme/colors';
|
|
3
|
-
import React from 'react';
|
|
4
4
|
export declare enum CARD_LAYOUT {
|
|
5
5
|
VERTICAL = "vertical",
|
|
6
6
|
HORIZONTAL = "horizontal"
|
|
@@ -32,6 +32,9 @@ export type CardProps = StyledElementProps<HTMLDivElement, {
|
|
|
32
32
|
raised?: boolean;
|
|
33
33
|
imageHeight?: string;
|
|
34
34
|
imageWidth?: string;
|
|
35
|
+
containerWidth?: string;
|
|
36
|
+
containerHeight?: string;
|
|
37
|
+
containImage?: boolean;
|
|
35
38
|
backgroundColor?: COLOR;
|
|
36
39
|
}, CardChildren>;
|
|
37
40
|
export declare const Card: React.FC<CardProps>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
2
3
|
import { HEADING_SIZE, Heading } from '../../elements/text/Heading';
|
|
3
4
|
import { ReadMore } from '../../elements/text/ReadMore';
|
|
4
5
|
import { useTheme } from '../../../theme';
|
|
@@ -7,7 +8,6 @@ import { Box } from '../../elements/layout/Box';
|
|
|
7
8
|
import { Icon } from '../../elements/Icon';
|
|
8
9
|
import { Column, FONT, FONT_SIZE, Row, TYPOGRAPHY_TYPE } from '../../..';
|
|
9
10
|
import { COLOR } from '../../../theme/colors';
|
|
10
|
-
import React, { useEffect, useState } from 'react';
|
|
11
11
|
import { KEY_CODES } from '../../../utils/misc';
|
|
12
12
|
import { useHover } from '../../../utils/hooks/useHover';
|
|
13
13
|
export var CARD_LAYOUT;
|
|
@@ -52,17 +52,32 @@ 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, alt, layout, onClick, raised, truncateHeadlineAfter, heading, headingStyles, headingIcon, headingAction, backgroundColor, sx, imageHeight: imageHeightProp, imageWidth: imageWidthProp, children, }) => {
|
|
55
|
+
export const Card = ({ size, displayDate, headline, image, alt, layout, onClick, raised, truncateHeadlineAfter, heading, headingStyles, headingIcon, headingAction, backgroundColor, sx, imageHeight: imageHeightProp, imageWidth: imageWidthProp, containImage, containerWidth, containerHeight, 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;
|
|
59
59
|
const { isHovered, anchorElementProps } = useHover();
|
|
60
60
|
const [activeBackground, setActiveBackground] = useState(isHovered ? COLOR.ND_SKY_BLUE : COLOR.BACKGROUND);
|
|
61
|
-
const
|
|
62
|
-
const imageWidth = imageWidthProp || (isVertical ? '100%' : 'auto');
|
|
61
|
+
const [objectFit, setObjectFit] = useState('scale-down');
|
|
63
62
|
useEffect(() => {
|
|
64
63
|
setActiveBackground(isHovered ? COLOR.ND_SKY_BLUE : COLOR.BACKGROUND);
|
|
65
64
|
}, [isHovered]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (image) {
|
|
67
|
+
const img = new Image();
|
|
68
|
+
img.onload = () => {
|
|
69
|
+
if (img.width > img.height) {
|
|
70
|
+
setObjectFit('contain');
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
setObjectFit('scale-down');
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
img.src = image;
|
|
77
|
+
}
|
|
78
|
+
}, [image]);
|
|
79
|
+
const imageHeight = imageHeightProp || (isVertical ? 'auto' : '100%');
|
|
80
|
+
const imageWidth = imageWidthProp || (isVertical ? '100%' : 'auto');
|
|
66
81
|
const contentPaddingY = isVertical ? contentPaddingX : 2;
|
|
67
82
|
const typography = size === CARD_SIZE.SM
|
|
68
83
|
? TYPOGRAPHY_TYPE.HEADLINE_SMALL
|
|
@@ -77,10 +92,21 @@ export const Card = ({ size, displayDate, headline, image, alt, layout, onClick,
|
|
|
77
92
|
borderColor: COLOR.ND_SKY_BLUE_DARK,
|
|
78
93
|
backgroundColor: COLOR.ND_SKY_BLUE,
|
|
79
94
|
}
|
|
80
|
-
: {} }, sx) }, { children: [image && (_jsx("img", { src: image, alt: alt, style: {
|
|
95
|
+
: {} }, sx) }, { children: [image && !containImage && (_jsx("img", { src: image, alt: alt, style: {
|
|
81
96
|
width: imageWidth,
|
|
82
97
|
height: imageHeight,
|
|
83
|
-
} })),
|
|
98
|
+
} })), image && containImage && (_jsx(Box, Object.assign({ sx: {
|
|
99
|
+
width: containerWidth || '500px',
|
|
100
|
+
height: containerHeight || '280px',
|
|
101
|
+
backgroundColor: COLOR.ND_SKY_BLUE,
|
|
102
|
+
display: 'flex',
|
|
103
|
+
justifyContent: 'center',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
} }, { children: _jsx("img", { src: image, alt: alt, style: {
|
|
106
|
+
width: imageWidth,
|
|
107
|
+
height: imageHeight,
|
|
108
|
+
objectFit: objectFit,
|
|
109
|
+
} }) }))), displayDate && _jsx(DateDisplay, { date: displayDate }), heading && (_jsxs(Row, Object.assign({ sx: Object.assign({ bg: COLOR.PRIMARY, color: COLOR.WHITE, width: '100%', px: contentPaddingX, py: 3, justifyContent: 'space-between', alignItems: 'center' }, headingStyles) }, { children: [_jsxs(Row, { children: [headingIcon && (_jsx(Icon, { icon: headingIcon, size: FONT_SIZE.LG, color: COLOR.WHITE, sx: { mr: 2 } })), _jsx(Heading, Object.assign({ size: HEADING_SIZE.SM, sx: {
|
|
84
110
|
color: COLOR.WHITE,
|
|
85
111
|
mt: 0,
|
|
86
112
|
whiteSpace: 'nowrap',
|
package/dist/theme/colors.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare enum COLOR {
|
|
|
27
27
|
ND_GOLD_LIGHT = "ndGoldLight",
|
|
28
28
|
ND_GOLD_DARK = "ndGoldDark",
|
|
29
29
|
ND_GREEN = "ndGreem",
|
|
30
|
-
ND_GREEN_LIGHT = "
|
|
30
|
+
ND_GREEN_LIGHT = "ndGreenLight",
|
|
31
31
|
ND_SKY_BLUE = "ndSkyBlue",
|
|
32
32
|
ND_SKY_BLUE_DARK = "ndSkyBlueDark",
|
|
33
33
|
ND_SKY_BLUE_LIGHT = "ndSkyBlueLight",
|
package/dist/theme/colors.js
CHANGED
|
@@ -28,7 +28,7 @@ export var COLOR;
|
|
|
28
28
|
COLOR["ND_GOLD_LIGHT"] = "ndGoldLight";
|
|
29
29
|
COLOR["ND_GOLD_DARK"] = "ndGoldDark";
|
|
30
30
|
COLOR["ND_GREEN"] = "ndGreem";
|
|
31
|
-
COLOR["ND_GREEN_LIGHT"] = "
|
|
31
|
+
COLOR["ND_GREEN_LIGHT"] = "ndGreenLight";
|
|
32
32
|
COLOR["ND_SKY_BLUE"] = "ndSkyBlue";
|
|
33
33
|
COLOR["ND_SKY_BLUE_DARK"] = "ndSkyBlueDark";
|
|
34
34
|
COLOR["ND_SKY_BLUE_LIGHT"] = "ndSkyBlueLight";
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare const theme: {
|
|
|
45
45
|
ndGoldLight: string;
|
|
46
46
|
ndGoldDark: string;
|
|
47
47
|
ndGreem: string;
|
|
48
|
-
|
|
48
|
+
ndGreenLight: string;
|
|
49
49
|
ndSkyBlue: string;
|
|
50
50
|
ndSkyBlueDark: string;
|
|
51
51
|
ndSkyBlueLight: string;
|
|
@@ -149,7 +149,7 @@ export declare const useTheme: () => {
|
|
|
149
149
|
ndGoldLight: string;
|
|
150
150
|
ndGoldDark: string;
|
|
151
151
|
ndGreem: string;
|
|
152
|
-
|
|
152
|
+
ndGreenLight: string;
|
|
153
153
|
ndSkyBlue: string;
|
|
154
154
|
ndSkyBlueDark: string;
|
|
155
155
|
ndSkyBlueLight: string;
|