diff --git a/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-1-1-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-1-1-1-snap.png new file mode 100644 index 0000000000..657fa53512 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-1-1-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-7-10-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-7-10-1-snap.png new file mode 100644 index 0000000000..2ec599b45d Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-7-10-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-9-10-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-9-10-1-snap.png new file mode 100644 index 0000000000..8e21b276c7 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/data-card-screenshot-test-tsx-data-card-with-aspect-ratio-9-10-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-1-1-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-1-1-1-snap.png new file mode 100644 index 0000000000..a8ba1fbed2 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-1-1-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-7-10-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-7-10-1-snap.png new file mode 100644 index 0000000000..8f22c9c917 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-7-10-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-9-10-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-9-10-1-snap.png new file mode 100644 index 0000000000..b453181654 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/display-data-card-screenshot-test-tsx-display-data-card-with-aspect-ratio-9-10-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-1-1-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-1-1-1-snap.png new file mode 100644 index 0000000000..67062d92b8 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-1-1-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-7-10-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-7-10-1-snap.png new file mode 100644 index 0000000000..2b61a0e96c Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-7-10-1-snap.png differ diff --git a/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-9-10-1-snap.png b/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-9-10-1-snap.png new file mode 100644 index 0000000000..58f85c1a81 Binary files /dev/null and b/src/__screenshot_tests__/__image_snapshots__/snap-card-screenshot-test-tsx-snap-card-with-aspect-ratio-9-10-1-snap.png differ diff --git a/src/__screenshot_tests__/data-card-screenshot-test.tsx b/src/__screenshot_tests__/data-card-screenshot-test.tsx index 118b74c8b9..ec07cd6bd4 100644 --- a/src/__screenshot_tests__/data-card-screenshot-test.tsx +++ b/src/__screenshot_tests__/data-card-screenshot-test.tsx @@ -3,6 +3,7 @@ import {openStoryPage, screen, setRootFontSize} from '../test-utils'; import type {Device} from '../test-utils'; const TESTABLE_DEVICES: Array = ['MOBILE_IOS', 'DESKTOP']; +const ASPECT_RATIO_VALUES = ['1:1', '7:10', '9:10']; test.each(TESTABLE_DEVICES)('DataCard in %s', async (device) => { await openStoryPage({ @@ -93,3 +94,17 @@ test('DataCard without icon, with top actions and too long title', async () => { expect(image).toMatchImageSnapshot(); }); + +test.each(ASPECT_RATIO_VALUES)('DataCard with aspect ratio %s', async (aspectRatio) => { + await openStoryPage({ + id: 'components-cards-data-card--default', + device: 'MOBILE_IOS', + args: {aspectRatio: aspectRatio.replace(':', ' ')}, + }); + + const dataCard = await screen.findByTestId('data-card'); + + const image = await dataCard.screenshot(); + + expect(image).toMatchImageSnapshot(); +}); diff --git a/src/__screenshot_tests__/display-data-card-screenshot-test.tsx b/src/__screenshot_tests__/display-data-card-screenshot-test.tsx index 35753255ae..5b0d7775fc 100644 --- a/src/__screenshot_tests__/display-data-card-screenshot-test.tsx +++ b/src/__screenshot_tests__/display-data-card-screenshot-test.tsx @@ -1,5 +1,7 @@ import {openStoryPage, screen} from '../test-utils'; +const ASPECT_RATIO_VALUES = ['1:1', '7:10', '9:10']; + test('DisplayDataCard', async () => { await openStoryPage({ id: 'components-cards-display-data-card--default', @@ -51,6 +53,20 @@ test('DisplayDataCard with top actions inverse', async () => { expect(image).toMatchImageSnapshot(); }); +test.each(ASPECT_RATIO_VALUES)('DisplayDataCard with aspect ratio %s', async (aspectRatio) => { + await openStoryPage({ + id: 'components-cards-display-data-card--default', + device: 'MOBILE_IOS', + args: {aspectRatio: aspectRatio.replace(':', ' ')}, + }); + + const displayDataCard = await screen.findByTestId('display-data-card'); + + const image = await displayDataCard.screenshot(); + + expect(image).toMatchImageSnapshot(); +}); + test('DisplayDataCard group', async () => { const page = await openStoryPage({ id: 'components-cards-display-data-card--group', diff --git a/src/__screenshot_tests__/snap-card-screenshot-test.tsx b/src/__screenshot_tests__/snap-card-screenshot-test.tsx index 0884b03dee..0a92e7b166 100644 --- a/src/__screenshot_tests__/snap-card-screenshot-test.tsx +++ b/src/__screenshot_tests__/snap-card-screenshot-test.tsx @@ -2,6 +2,8 @@ import {openStoryPage, screen, setRootFontSize} from '../test-utils'; import type {Device, StoryArgs} from '../test-utils'; +const ASPECT_RATIO_VALUES = ['1:1', '7:10', '9:10']; + const renderSnapCard = async ({device, args}: {device: Device; args?: StoryArgs}) => { await openStoryPage({ id: 'components-cards-snap-card--default', @@ -45,6 +47,20 @@ test('SnapCard', async () => { }); }); +test.each(ASPECT_RATIO_VALUES)('SnapCard with aspect ratio %s', async (aspectRatio) => { + await openStoryPage({ + id: 'components-cards-snap-card--default', + device: 'MOBILE_IOS', + args: {aspectRatio: aspectRatio.replace(':', ' ')}, + }); + + const snapCard = await screen.findByTestId('snap-card'); + + const image = await snapCard.screenshot(); + + expect(image).toMatchImageSnapshot(); +}); + test('SnapCard group', async () => { const page = await openStoryPage({ id: 'components-cards-snap-card--group', diff --git a/src/__stories__/data-card-story.tsx b/src/__stories__/data-card-story.tsx index a061c1d78a..1ae5393fc9 100644 --- a/src/__stories__/data-card-story.tsx +++ b/src/__stories__/data-card-story.tsx @@ -15,6 +15,7 @@ import { import {Placeholder} from '../placeholder'; import avatarImg from './images/avatar.jpg'; +import type {AspectRatio} from '../card'; import type {TagType} from '..'; export default { @@ -33,8 +34,11 @@ type DataCardArgs = { actions: 'button' | 'link' | 'button and link' | 'on press'; closable: boolean; withTopAction: boolean; + aspectRatio: AspectRatio; }; +const fixedAspectRatioValues = ['1 1', '16 9', '7 10', '9 10']; + export const Default: StoryComponent = ({ asset = 'icon', headline, @@ -47,6 +51,7 @@ export const Default: StoryComponent = ({ actions = 'button', closable, withTopAction, + aspectRatio, }) => { let icon; if (asset === 'icon') { @@ -76,6 +81,10 @@ export const Default: StoryComponent = ({ buttonLink, }; + const aspectRatioValue = fixedAspectRatioValues.includes(aspectRatio) + ? aspectRatio.replace(' ', ':') + : aspectRatio; + return ( {} : undefined} @@ -87,6 +96,7 @@ export const Default: StoryComponent = ({ description={description} extra={withExtra ? : undefined} {...interactiveActions} + aspectRatio={aspectRatioValue as AspectRatio} dataAttributes={{testid: 'data-card'}} aria-label="Data card label" actions={ @@ -119,6 +129,7 @@ Default.args = { actions: 'button', closable: false, withTopAction: false, + aspectRatio: 'auto', }; Default.argTypes = { asset: { @@ -133,6 +144,18 @@ Default.argTypes = { options: ['button', 'link', 'button and link', 'on press', 'none'], control: {type: 'select'}, }, + aspectRatio: { + options: ['auto', ...fixedAspectRatioValues], + control: { + type: 'select', + labels: { + '1 1': '1:1', + '16 9': '16:9', + '7 10': '7:10', + '9 10': '9:10', + }, + }, + }, }; export const Group: StoryComponent = () => { diff --git a/src/__stories__/display-data-card-story.tsx b/src/__stories__/display-data-card-story.tsx index 454023b871..e811372391 100644 --- a/src/__stories__/display-data-card-story.tsx +++ b/src/__stories__/display-data-card-story.tsx @@ -18,6 +18,7 @@ import { import {Placeholder} from '../placeholder'; import avatarImg from './images/avatar.jpg'; +import type {AspectRatio} from '../card'; import type {TagType} from '..'; export default { @@ -36,8 +37,11 @@ type DisplayDataCardArgs = { withTopAction: boolean; actions: 'button' | 'link' | 'button and link' | 'button and secondary button'; isInverse: boolean; + aspectRatio: AspectRatio; }; +const fixedAspectRatioValues = ['1 1', '16 9', '7 10', '9 10']; + export const Default: StoryComponent = ({ asset = 'icon', headline, @@ -50,6 +54,7 @@ export const Default: StoryComponent = ({ closable, withTopAction, isInverse, + aspectRatio, }) => { let icon; if (asset === 'circle + icon') { @@ -89,6 +94,10 @@ export const Default: StoryComponent = ({ secondaryButton, }; + const aspectRatioValue = fixedAspectRatioValues.includes(aspectRatio) + ? aspectRatio.replace(' ', ':') + : aspectRatio; + return ( = ({ pretitle={pretitle} title={title} description={description} + aspectRatio={aspectRatioValue as AspectRatio} extra={withExtra ? : undefined} {...interactiveActions} dataAttributes={{testid: 'display-data-card'}} @@ -130,6 +140,7 @@ Default.args = { closable: false, withTopAction: false, isInverse: false, + aspectRatio: 'auto', }; Default.argTypes = { asset: { @@ -144,6 +155,18 @@ Default.argTypes = { options: ['button', 'link', 'button and link', 'button and secondary button', 'on press'], control: {type: 'select'}, }, + aspectRatio: { + options: ['auto', '1 1', '16 9', '7 10', '9 10'], + control: { + type: 'select', + labels: { + '1 1': '1:1', + '16 9': '16:9', + '7 10': '7:10', + '9 10': '9:10', + }, + }, + }, }; export const Group: StoryComponent = () => { diff --git a/src/__stories__/snap-card-story.tsx b/src/__stories__/snap-card-story.tsx index d8b0d72289..e045cbcdda 100644 --- a/src/__stories__/snap-card-story.tsx +++ b/src/__stories__/snap-card-story.tsx @@ -14,6 +14,8 @@ import { import {Placeholder} from '../placeholder'; import avatarImg from './images/avatar.jpg'; +import type {AspectRatio} from '../card'; + export default { title: 'Components/Cards/Snap card', }; @@ -25,9 +27,20 @@ type Args = { touchable: boolean; isInverse: boolean; withExtra: boolean; + aspectRatio: AspectRatio; }; -export const Default: StoryComponent = ({asset, title, subtitle, touchable, isInverse, withExtra}) => { +const fixedAspectRatioValues = ['1 1', '16 9', '7 10', '9 10']; + +export const Default: StoryComponent = ({ + asset, + title, + subtitle, + touchable, + isInverse, + withExtra, + aspectRatio, +}) => { const assetToIcon: { [asset in Args['asset']]: React.ReactElement | undefined; } = { @@ -46,6 +59,10 @@ export const Default: StoryComponent = ({asset, title, subtitle, touchable none: undefined, }; + const aspectRatioValue = fixedAspectRatioValues.includes(aspectRatio) + ? aspectRatio.replace(' ', ':') + : aspectRatio; + return ( = ({asset, title, subtitle, touchable } : undefined } + aspectRatio={aspectRatioValue as AspectRatio} /> ); }; @@ -74,12 +92,25 @@ Default.args = { touchable: true, isInverse: false, withExtra: false, + aspectRatio: 'auto', }; Default.argTypes = { asset: { options: ['icon in circle', 'icon', 'image', 'none'], control: {type: 'select'}, }, + aspectRatio: { + options: ['auto', '1 1', '16 9', '7 10', '9 10'], + control: { + type: 'select', + labels: { + '1 1': '1:1', + '16 9': '16:9', + '7 10': '7:10', + '9 10': '9:10', + }, + }, + }, }; export const Group: StoryComponent = () => { diff --git a/src/card.tsx b/src/card.tsx index 2d27b2009d..3de9575b32 100644 --- a/src/card.tsx +++ b/src/card.tsx @@ -119,7 +119,7 @@ export const CardActionsGroup = ({ ); }; -type AspectRatio = '1:1' | '16:9' | '7:10' | '9:10' | 'auto'; +export type AspectRatio = '1:1' | '16:9' | '7:10' | '9:10' | 'auto'; const aspectRatioToNumber = (aspectRatio?: AspectRatio | number): number => { if (!aspectRatio) { @@ -716,6 +716,7 @@ interface DataCardBaseProps { descriptionLinesMax?: number; extra?: React.ReactNode; actions?: Array; + aspectRatio?: AspectRatio | number; children?: void; /** "data-" prefix is automatically added. For example, use "testid" instead of "data-testid" */ dataAttributes?: DataAttributes; @@ -752,6 +753,7 @@ export const DataCard = React.forwardRef( dataAttributes, 'aria-label': ariaLabel, onClose, + aspectRatio, ...touchableProps }, ref @@ -772,8 +774,9 @@ export const DataCard = React.forwardRef( ref={ref} aria-label={ariaLabel} className={styles.touchableContainer} + aspectRatio={aspectRatio} > - + ; @@ -843,6 +847,7 @@ export const SnapCard = React.forwardRef( 'aria-label': ariaLabel, extra, isInverse = false, + aspectRatio, ...touchableProps }, ref @@ -855,8 +860,9 @@ export const SnapCard = React.forwardRef( dataAttributes={{'component-name': 'SnapCard', ...dataAttributes}} ref={ref} className={styles.touchableContainer} + aspectRatio={aspectRatio} > - +