diff --git a/lib/components/MediaCard/MediaCard.stories.tsx b/lib/components/MediaCard/MediaCard.stories.tsx index 4f69141..33d79f6 100644 --- a/lib/components/MediaCard/MediaCard.stories.tsx +++ b/lib/components/MediaCard/MediaCard.stories.tsx @@ -1,5 +1,7 @@ import type { Meta, StoryObj } from '@storybook/react'; +import { useState } from '@storybook/preview-api'; +import { fn } from '@storybook/test'; import { MediaCard } from './MediaCard'; const meta = { @@ -12,15 +14,19 @@ export default meta; type Story = StoryObj; -export const Vertical: Story = { +export const Default: Story = { parameters: { design: { type: 'figma', url: 'https://www.figma.com/design/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?node-id=2217-8529', }, + docs: { + description: { + story: 'MediaCard where there is no favorite-button available', + }, + }, }, args: { - variant: 'vertical', imageSrc: 'https://images.unsplash.com/photo-1523464862212-d6631d073194?q=80&w=260?q=80&w=260', imageAlt: 'Woman standing in front of a colourful wall', label: 'Tulevaisuusmatka', @@ -29,47 +35,37 @@ export const Vertical: Story = { }, }; -export const Horizontal: Story = { +export const AbleToBeFavorited: Story = { parameters: { - design: { - type: 'figma', - url: 'https://www.figma.com/design/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?node-id=2217-8529', + docs: { + description: { + story: 'MediaCard where the favorite status can be toggled.', + }, }, - }, - args: { - variant: 'horizontal', - imageSrc: 'https://images.unsplash.com/photo-1523464862212-d6631d073194?q=80&w=260', - imageAlt: 'Woman standing in front of a colourful wall', - label: 'Tulevaisuusmatka', - description: 'Tulevaisuusmatka on koulutus, joka auttaa sinua löytämään oman polkusi ja tavoitteesi.', - tags: ['Taglorem', 'Loremtag', 'Nonutag'], - }, -}; - -export const VerticalWithRating: Story = { - parameters: { design: { type: 'figma', url: 'https://www.figma.com/design/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?node-id=2217-8529', }, }, - argTypes: { - rating: { - control: { - type: 'range', - min: 0, - max: 5, - step: 1, - }, - }, + render: (args) => { + const [isFavorite, setFavorite] = useState(true); + return ( + setFavorite(!isFavorite)} + /> + ); }, args: { - rating: 3, - variant: 'vertical', imageSrc: 'https://images.unsplash.com/photo-1523464862212-d6631d073194?q=80&w=260?q=80&w=260', imageAlt: 'Woman standing in front of a colourful wall', label: 'Tulevaisuusmatka', description: 'Tulevaisuusmatka on koulutus, joka auttaa sinua löytämään oman polkusi ja tavoitteesi.', tags: ['Taglorem', 'Loremtag', 'Nonutag'], + isFavorite: true, + onFavoriteClick: fn(), + favoriteLabel: 'Poista suosikeista', }, }; diff --git a/lib/components/MediaCard/MediaCard.test.tsx b/lib/components/MediaCard/MediaCard.test.tsx index 5da79da..8dc0463 100644 --- a/lib/components/MediaCard/MediaCard.test.tsx +++ b/lib/components/MediaCard/MediaCard.test.tsx @@ -6,7 +6,6 @@ describe('MediaCard', () => { it('renders the MediaCard component with vertical variant', () => { render( { it('renders the MediaCard component with horizontal variant', () => { render( void; + favoriteLabel: string; + }; + export type MediaCardProps = { - variant?: Variant; imageSrc: string; imageAlt: string; label: string; description: string; tags: string[]; - /** Rating between 0-5*/ - rating?: number; - ratingAriaLabel?: string; -} & LinkComponent; - -const getVariantContainerClassNames = ({ variant }: { variant: Variant }) => { - return cx({ - 'ds-flex ds-flex-col ds-w-[260px] ds-h-[329px]': variant === 'vertical', - 'ds-flex ds-flex-row ds-w-full ds-h-[147px]': variant === 'horizontal', - }); -}; - -const getVariantImageClassNames = ({ variant }: { variant: Variant }) => { - return cx('ds-object-cover', { - 'ds-min-h-[147px]': variant === 'vertical', - 'ds-h-full ds-min-w-[265px]': variant === 'horizontal', - }); -}; +} & LinkComponent & + FavoriteButtonProps; const Tag = ({ label }: { label: string }) => { return
  • {label}
  • ; @@ -71,25 +63,23 @@ const LinkOrDiv = ({ ); }; -interface RatingElementProps { - /** Amount of the rating, possible values between 0-5 */ - amount: number; - ariaLabel: string; -} - -const RatingElement = ({ amount, ariaLabel }: RatingElementProps) => { +const FavoriteButton = ({ isFavorite, favoriteLabel, onFavoriteClick }: FavoriteButtonProps) => { return ( -
    - {Array.from({ length: 5 }).map((_, idx) => ( - // eslint-disable-next-line react/no-array-index-key - - ))} -
    + ); }; export const MediaCard = ({ - variant = 'vertical', imageSrc, imageAlt, label, @@ -97,25 +87,27 @@ export const MediaCard = ({ tags, linkComponent: Link, to, - rating, - ratingAriaLabel, + isFavorite, + onFavoriteClick, + favoriteLabel, }: MediaCardProps) => { - const variantContainerClassNames = getVariantContainerClassNames({ variant }); - const variantImageClassNames = getVariantImageClassNames({ variant }); + const variantImageClassNames = 'ds-object-cover ds-min-h-[147px]'; return ( - + {imageSrc ? ( {imageAlt} ) : ( - + )}
    {label}
    {description}
    - {rating !== undefined && } + {isFavorite !== undefined && ( + + )}
      {tags.map((tag) => ( diff --git a/lib/components/MediaCard/__snapshots__/MediaCard.test.tsx.snap b/lib/components/MediaCard/__snapshots__/MediaCard.test.tsx.snap index 7858819..618512d 100644 --- a/lib/components/MediaCard/__snapshots__/MediaCard.test.tsx.snap +++ b/lib/components/MediaCard/__snapshots__/MediaCard.test.tsx.snap @@ -2,7 +2,7 @@ exports[`MediaCard > renders the MediaCard component with default vertical variant 1`] = `