Skip to content

Commit 703ce2c

Browse files
authored
Merge pull request #2035 from navikt/part-stories
Story ReadMore og config Chromatic
2 parents c38603f + 011c9b5 commit 703ce2c

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

.storybook/modes.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const allModes = {
2+
small: {
3+
viewport: 'small',
4+
},
5+
large: {
6+
viewport: 'large',
7+
},
8+
};

.storybook/preview.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import type { Preview } from '@storybook/react';
2+
import { allModes } from '../.storybook/modes';
23
import '../src/global.scss';
34

45
const preview: Preview = {
56
parameters: {
6-
layout: 'centered',
7+
viewport: {
8+
viewports: {
9+
small: { name: 'small', styles: { width: '390px', height: '100%' } },
10+
large: { name: 'large', styles: { width: '820px', height: '100%' } },
11+
},
12+
},
13+
chromatic: {
14+
modes: {
15+
small: allModes['small'],
16+
large: allModes['large'],
17+
},
18+
},
719
},
820
tags: ['autodocs'],
921
};

src/components/parts/PartsMapper.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { AreapageSituationCardPart } from './areapage-situation-card/AreapageSit
5050
import { LoggedinCardPart } from './loggedin-card/LoggedinCardPart';
5151
import { FrontpageContactPart } from './frontpage-contact/FrontpageContactPart';
5252
import { FormDetailsPart } from './form-details/FormDetailsPart';
53-
import { ReadMorePart } from './read-more/ReadMorePart';
53+
import { ReadMorePart } from './readMorePart/ReadMorePart';
5454
import { AccordionPart } from './accordion/AccordionPart';
5555
import { RelatedSituationsPart } from './related-situations/RelatedSituationsPart';
5656

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import { ComponentType } from 'types/component-props/_component-common';
4+
import { PartType } from 'types/component-props/parts';
5+
import { ReadMorePart } from './ReadMorePart';
6+
7+
const meta = {
8+
component: ReadMorePart,
9+
args: { type: ComponentType.Part, descriptor: PartType.ReadMore, path: '' },
10+
} satisfies Meta<typeof ReadMorePart>;
11+
12+
export default meta;
13+
14+
type Story = StoryObj<typeof meta>;
15+
16+
export const Default: Story = {
17+
args: {
18+
config: {
19+
title: 'Read More',
20+
html: {
21+
processedHtml:
22+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
23+
macros: [],
24+
},
25+
},
26+
},
27+
};
28+
29+
export const Opened: Story = {
30+
args: {
31+
config: {
32+
...Default.args.config,
33+
isOpen: true,
34+
},
35+
},
36+
};

src/components/parts/read-more/ReadMorePart.tsx src/components/parts/readMorePart/ReadMorePart.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import styles from './ReadMorePart.module.scss';
1515
export type PartConfigReadMore = {
1616
title: string;
1717
html: ProcessedHtmlProps;
18+
isOpen?: boolean;
1819
};
1920

2021
export const ReadMorePart = ({ config }: PartComponentProps<PartType.ReadMore>) => {
21-
const [isOpen, setIsOpen] = useState(false);
22+
const [isOpen, setIsOpen] = useState(config?.isOpen ?? false);
2223
const divRef = useRef<HTMLDivElement | null>(null);
2324

2425
useShortcuts({

src/types/component-props/parts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { PartConfigPayoutDates } from 'components/parts/payout-dates/PayoutDates
2525
import { PartConfigProductCard } from 'components/parts/product-card/ProductCardPart';
2626
import { PartConfigProductDetails } from 'components/parts/product-details/ProductDetailsPart';
2727
import { PartConfigProviderCard } from 'components/parts/provider-card/ProviderCardPart';
28-
import { PartConfigReadMore } from 'components/parts/read-more/ReadMorePart';
28+
import { PartConfigReadMore } from 'components/parts/readMorePart/ReadMorePart';
2929
import { PartConfigRelatedSituations } from 'components/parts/related-situations/RelatedSituationsPart';
3030
import { PartConfigUserTests } from 'components/parts/user-tests/UserTestsPart';
3131
import { PartConfigUxSignalsWidget } from 'components/parts/uxsignals-widget/UxSignalsWidgetPart';

0 commit comments

Comments
 (0)