Skip to content

Commit

Permalink
Merge pull request #1994 from navikt/utvid-storybook
Browse files Browse the repository at this point in the history
Flere card-stories 🧪
  • Loading branch information
bdahle authored Sep 26, 2024
2 parents b334e3a + 403d3d4 commit a4c4a99
Show file tree
Hide file tree
Showing 12 changed files with 816 additions and 1,724 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],

addons: [
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/addon-mdx-gfm'),
getAbsolutePath('@storybook/addon-storysource'),
getAbsolutePath('storybook-addon-pseudo-states'),
],

framework: {
Expand Down
2,308 changes: 640 additions & 1,668 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,15 @@
"@chromatic-com/storybook": "1.6.1",
"@next/bundle-analyzer": "14.2.4",
"@next/eslint-plugin-next": "14.2.4",
"@storybook/addon-essentials": "8.2.8",
"@storybook/addon-interactions": "8.2.8",
"@storybook/addon-links": "8.2.8",
"@storybook/addon-mdx-gfm": "8.2.8",
"@storybook/addon-onboarding": "8.2.8",
"@storybook/addon-storysource": "8.2.8",
"@storybook/blocks": "8.2.8",
"@storybook/nextjs": "8.2.8",
"@storybook/react": "8.2.8",
"@storybook/test": "8.2.8",
"@storybook/addon-essentials": "8.3.2",
"@storybook/addon-interactions": "8.3.2",
"@storybook/addon-links": "8.3.2",
"@storybook/addon-mdx-gfm": "8.3.2",
"@storybook/addon-storysource": "8.3.2",
"@storybook/blocks": "8.3.2",
"@storybook/nextjs": "8.3.2",
"@storybook/react": "8.3.2",
"@storybook/test": "8.3.2",
"@testing-library/jest-dom": "6.4.6",
"@testing-library/react": "16.0.0",
"@types/jest": "29.5.12",
Expand Down Expand Up @@ -118,7 +117,8 @@
"pino-pretty": "11.2.1",
"prettier": "3.3.2",
"sass": "1.77.6",
"storybook": "8.2.8",
"storybook": "8.3.2",
"storybook-addon-pseudo-states": "4.0.2",
"ts-jest": "29.1.5",
"typescript": "5.5.3",
"typescript-plugin-css-modules": "5.1.0"
Expand Down
57 changes: 57 additions & 0 deletions src/components/_common/card/LargeCardV1/LargeCardV1.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Meta, StoryObj } from '@storybook/react';
import { CardType } from 'types/card';
import { ContentType } from 'types/content-props/_content-common';
import { MediaType } from 'types/media';
import { LargeCardV1 } from './LargeCardV1';

const meta = {
component: LargeCardV1,
args: {
link: { url: '', text: 'LargeCardV1' },
description: 'Description',
tagline: 'Tagline',
type: CardType.Product,
},
} satisfies Meta<typeof LargeCardV1>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};

export const Illustration: Story = {
args: {
illustration: {
type: ContentType.Pictograms,
data: { icons: [{ icon: { type: MediaType.Vector, mediaUrl: 'placeholder' } }] },
},
},
};

export const ProductHover: Story = {
parameters: {
pseudo: { hover: true },
},
};

export const SituationHover: Story = {
args: { type: CardType.Situation },
parameters: {
pseudo: { hover: true },
},
};

export const ThemedArticleHover: Story = {
args: { type: CardType.ThemedArticle },
parameters: {
pseudo: { hover: true },
},
};

export const GuideHover: Story = {
args: { type: CardType.Guide },
parameters: {
pseudo: { hover: true },
},
};
32 changes: 32 additions & 0 deletions src/components/_common/card/LargeCardV2/LargeCardV2.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/react';
import { CardType } from 'types/card';
import { ContentType } from 'types/content-props/_content-common';
import { MediaType } from 'types/media';
import { LargeCardV2 } from './LargeCardV2';

const meta = {
component: LargeCardV2,
} satisfies Meta<typeof LargeCardV2>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
link: { url: '', text: 'LargeCardV2' },
type: CardType.Product,
description: 'Description',
tagline: 'Tagline',
},
};

export const Illustration: Story = {
args: {
...Default.args,
illustration: {
type: ContentType.Pictograms,
data: { icons: [{ icon: { type: MediaType.Vector, mediaUrl: 'placeholder' } }] },
},
},
};
22 changes: 22 additions & 0 deletions src/components/_common/card/MicroCard/MicroCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Meta, StoryObj } from '@storybook/react';
import { CardType } from 'types/card';
import { MicroCard } from './MicroCard';

const meta = {
component: MicroCard,
} satisfies Meta<typeof MicroCard>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
link: { url: '', text: 'MicroCard' },
type: CardType.Product,
},
};

export const Hover: Story = {
parameters: { pseudo: { hover: true } },
args: { ...Default.args },
};
41 changes: 0 additions & 41 deletions src/components/_common/card/MicroCard/MicroCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from 'react';
import { BodyShort } from '@navikt/ds-react';
import { LinkProps } from 'types/link-props';
import { CardSize, CardType } from 'types/card';
import { LenkeBase } from 'components/_common/lenke/LenkeBase';
import { classNames } from 'utils/classnames';
import { CardProps, CardTargetProps, getCardProps } from 'components/_common/card/card-utils';
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
import { usePageContentProps } from 'store/pageContext';
import { useCard } from 'components/_common/card/useCard';

import sharedStyle from 'components/_common/card//Card.module.scss';
Expand All @@ -24,40 +20,3 @@ export const MicroCard = ({ link, type }: { link: LinkProps; type: CardType }) =
</LenkeBase>
);
};

type Props = {
header?: string;
card_list: CardTargetProps[];
};

export const MicroCards = ({ header, card_list }: Props) => {
const content = usePageContentProps();

const cardProps = card_list.reduce<CardProps[]>((acc, card) => {
const props = getCardProps(card, content);
if (props) {
acc.push(props);
}

return acc;
}, []);

if (cardProps.length === 0) {
return <EditorHelp text={'Velg minst én lenke for å aktivere mikrokortene'} />;
}

return (
<>
{header && (
<BodyShort size={'medium'} className={style.header}>
{header}
</BodyShort>
)}
<div className={style.wrapper}>
{cardProps.map((card, index) => (
<MicroCard {...card} key={index} />
))}
</div>
</>
);
};
45 changes: 45 additions & 0 deletions src/components/_common/card/MicroCard/MicroCards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { BodyShort } from '@navikt/ds-react';
import { CardProps, CardTargetProps, getCardProps } from 'components/_common/card/card-utils';
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
import { usePageContentProps } from 'store/pageContext';

import { MicroCard } from './MicroCard';
import style from './MicroCard.module.scss';

type Props = {
header?: string;
card_list: CardTargetProps[];
};

export const MicroCards = ({ header, card_list }: Props) => {
const content = usePageContentProps();

const cardProps = card_list.reduce<CardProps[]>((acc, card) => {
const props = getCardProps(card, content);
if (props) {
acc.push(props);
}

return acc;
}, []);

if (cardProps.length === 0) {
return <EditorHelp text={'Velg minst én lenke for å aktivere mikrokortene'} />;
}

return (
<>
{header && (
<BodyShort size={'medium'} className={style.header}>
{header}
</BodyShort>
)}
<div className={style.wrapper}>
{cardProps.map((card, index) => (
<MicroCard {...card} key={index} />
))}
</div>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ type Story = StoryObj<typeof meta>;

export const Product: Story = {};

export const Situation: Story = {
export const SituationHover: Story = {
parameters: {
pseudo: { hover: true },
},
args: {
type: CardType.Situation,
},
Expand Down
2 changes: 2 additions & 0 deletions src/components/_common/card/MiniCardV2/MiniCardV2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {};

export const Hover: Story = { parameters: { pseudo: { hover: true } } };
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { MacroProductCardMicroProps } from 'types/macro-props/product-card-micro';
import { MicroCards } from 'components/_common/card/MicroCard/MicroCard';
import { MicroCards } from 'components/_common/card/MicroCard/MicroCards';
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';

export const MacroProductCardMicro = ({ config }: MacroProductCardMicroProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { MicroCards } from 'components/_common/card/MicroCard/MicroCard';
import { MicroCards } from 'components/_common/card/MicroCard/MicroCards';
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
import { PartComponentProps, PartType } from 'types/component-props/parts';
import { CardTargetProps } from 'components/_common/card/card-utils';
Expand Down

0 comments on commit a4c4a99

Please sign in to comment.