@ndlib/component-library 1.0.4 → 1.0.5

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.
@@ -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,15 @@ 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://images.ctfassets.net/cfblb1f7i85j/7aCd5Sm86JdtQepGBKDUfy/dcb4d97dd3a1d3ee810e8bcaa82dc715/Spring_Exhibit_2023-Rep.jpg?w=296',
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: 'Tracy C. Bergstrom, director of the Specialized Collection Services Program',
27
+ image: 'https://strapi-prod-library-website-contentbucket52d4b12c-1whgwwl6746tz.s3.us-east-1.amazonaws.com/Tracy_News_218x275_1dd180dc80.jpg',
20
28
  size: CARD_SIZE.SM,
21
29
  sx: {
22
30
  width: '500px',
@@ -24,7 +32,7 @@ const headlinedCards = [
24
32
  },
25
33
  {
26
34
  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?w=296',
35
+ image: 'https://images.ctfassets.net/cfblb1f7i85j/2sGpdDbNkl6MPnlem6wq1R/995c786624613b5ff07228e481996385/One.Book.2023-Rep.png',
28
36
  size: CARD_SIZE.SM,
29
37
  sx: {
30
38
  width: '500px',
@@ -85,6 +93,10 @@ export const Default = {
85
93
  render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i })))) })),
86
94
  args: {},
87
95
  };
96
+ export const ContainedImage = {
97
+ render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({ containImage: true, containerHeight: '280px' }, props, { key: i })))) })),
98
+ args: {},
99
+ };
88
100
  export const TruncateHeadline = {
89
101
  render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, truncateHeadlineAfter: 2 })))) })),
90
102
  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
  });
@@ -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>;
@@ -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, 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;
@@ -77,10 +77,21 @@ export const Card = ({ size, displayDate, headline, image, alt, layout, onClick,
77
77
  borderColor: COLOR.ND_SKY_BLUE_DARK,
78
78
  backgroundColor: COLOR.ND_SKY_BLUE,
79
79
  }
80
- : {} }, sx) }, { children: [image && (_jsx("img", { src: image, alt: alt, style: {
80
+ : {} }, sx) }, { children: [image && !containImage && (_jsx("img", { src: image, alt: alt, style: {
81
81
  width: imageWidth,
82
82
  height: imageHeight,
83
- } })), 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: {
83
+ } })), image && containImage && (_jsx(Box, Object.assign({ sx: {
84
+ width: containerWidth || '500px',
85
+ height: containerHeight || '280px',
86
+ backgroundColor: COLOR.ND_SKY_BLUE,
87
+ display: 'flex',
88
+ justifyContent: 'center',
89
+ alignItems: 'center',
90
+ } }, { children: _jsx("img", { src: image, alt: alt, style: {
91
+ width: imageWidth,
92
+ height: imageHeight,
93
+ objectFit: 'scale-down',
94
+ } }) }))), 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
95
  color: COLOR.WHITE,
85
96
  mt: 0,
86
97
  whiteSpace: 'nowrap',
@@ -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 = "ndGreemLight",
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",
@@ -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"] = "ndGreemLight";
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";
@@ -45,7 +45,7 @@ export declare const theme: {
45
45
  ndGoldLight: string;
46
46
  ndGoldDark: string;
47
47
  ndGreem: string;
48
- ndGreemLight: string;
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
- ndGreemLight: string;
152
+ ndGreenLight: string;
153
153
  ndSkyBlue: string;
154
154
  ndSkyBlueDark: string;
155
155
  ndSkyBlueLight: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [