Skip to content

Commit 5589e91

Browse files
authored
Merge pull request #2445 from SpareBank1/develop_fix-card-types
Develop fix card types
2 parents 6e15e2c + a6b9d15 commit 5589e91

19 files changed

+99
-38
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"react-dom": "^18.2.0",
8383
"rimraf": "^6.0.1",
8484
"storybook": "^8.2.7",
85-
"typescript": "5.4.3"
85+
"typescript": "^5.7.2"
8686
},
8787
"eslintConfig": {
8888
"extends": [

packages/ffe-cards-react/src/CardBase.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React, { ElementType, ForwardedRef } from 'react';
22
import classNames from 'classnames';
33
import { WithCardActionProps, WithCardAction } from './components';
4-
import { BgColor, BgColorDarkmode, ComponentAsPropParams } from './types';
4+
import {
5+
BgColor,
6+
BgColorDarkmode,
7+
ComponentAsPropParams,
8+
CardActionRenderProps,
9+
} from './types';
510
import { fixedForwardRef } from './fixedForwardRef';
611

712
export type CardBaseProps<As extends ElementType = 'div'> = Omit<
@@ -48,7 +53,7 @@ function CardBaseWithForwardRef<As extends ElementType>(
4853
{...(rest as Record<string, unknown>)}
4954
ref={ref}
5055
>
51-
{({ CardAction }) =>
56+
{({ CardAction }: CardActionRenderProps) =>
5257
typeof children === 'function'
5358
? children({ CardAction })
5459
: children

packages/ffe-cards-react/src/GroupCard/GroupCard.stories.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GroupCardElement } from './GroupCardElement';
55
import { GroupCardFooter } from './GroupCardFooter';
66
import { Heading2, Paragraph } from '@sb1/ffe-core-react';
77
import type { StoryObj, Meta } from '@storybook/react';
8+
import { CardRenderProps } from '../types';
89

910
const meta: Meta<typeof GroupCard> = {
1011
title: 'Komponenter/Cards/GroupCard',
@@ -27,7 +28,7 @@ export const Standard: Story = {
2728
<GroupCardElement>Dette er et element i GroupCard</GroupCardElement>
2829
<GroupCardElement>Dette er et element i GroupCard</GroupCardElement>
2930
<GroupCardFooter>
30-
{({ CardAction }) => (
31+
{({ CardAction }: CardRenderProps) => (
3132
<CardAction href="https://design.sparebank1.no">
3233
Vis mer
3334
</CardAction>
@@ -83,7 +84,13 @@ export const WithCardAction: Story = {
8384
<Heading2 lookLike={5}>Tittel på gruppe</Heading2>
8485
</GroupCardTitle>
8586
<GroupCardElement>
86-
{({ CardAction, CardName, Title, Subtext, Text }) => (
87+
{({
88+
CardAction,
89+
CardName,
90+
Title,
91+
Subtext,
92+
Text,
93+
}: CardRenderProps) => (
8794
<>
8895
<CardName>Kortnavn</CardName>
8996
<Title>
@@ -97,7 +104,7 @@ export const WithCardAction: Story = {
97104
)}
98105
</GroupCardElement>
99106
<GroupCardElement>
100-
{({ CardAction }) => (
107+
{({ CardAction }: CardRenderProps) => (
101108
<>
102109
<Heading2>
103110
<CardAction as="button">Knapp</CardAction>
@@ -107,7 +114,7 @@ export const WithCardAction: Story = {
107114
)}
108115
</GroupCardElement>
109116
<GroupCardElement>
110-
{({ CardAction }) => (
117+
{({ CardAction }: CardRenderProps) => (
111118
<>
112119
<Heading2>
113120
<CardAction href="https://design.sparebank1.no">
@@ -119,7 +126,7 @@ export const WithCardAction: Story = {
119126
)}
120127
</GroupCardElement>
121128
<GroupCardFooter>
122-
{({ CardAction }) => (
129+
{({ CardAction }: CardRenderProps) => (
123130
<CardAction href="https://design.sparebank1.no">
124131
Vis mer
125132
</CardAction>

packages/ffe-cards-react/src/GroupCard/GroupCardElement.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React, { ElementType, ForwardedRef } from 'react';
22
import classNames from 'classnames';
33
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
4-
import { CardRenderProps, ComponentAsPropParams } from '../types';
4+
import {
5+
CardRenderProps,
6+
ComponentAsPropParams,
7+
CardActionRenderProps,
8+
} from '../types';
59
import { fixedForwardRef } from '../fixedForwardRef';
610

711
export type GroupCardElementProps<As extends ElementType = 'div'> = Omit<
@@ -39,7 +43,7 @@ function GroupCardElementWithForwardRef<As extends ElementType>(
3943
{...(rest as Record<string, unknown>)}
4044
ref={ref}
4145
>
42-
{({ CardAction }) =>
46+
{({ CardAction }: CardActionRenderProps) =>
4347
typeof children === 'function'
4448
? children({ Text, Subtext, Title, CardName, CardAction })
4549
: children

packages/ffe-cards-react/src/GroupCard/GroupCardFooter.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React, { ElementType, ForwardedRef } from 'react';
22
import classNames from 'classnames';
33
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
4-
import { CardRenderProps, ComponentAsPropParams } from '../types';
4+
import {
5+
CardRenderProps,
6+
ComponentAsPropParams,
7+
CardActionRenderProps,
8+
} from '../types';
59
import { fixedForwardRef } from '../fixedForwardRef';
610

711
export type GroupCardFooterProps<As extends ElementType = 'div'> = Omit<
@@ -30,7 +34,7 @@ function GroupCardFooterWithForwardRef<As extends ElementType>(
3034
{...(rest as Record<string, unknown>)}
3135
ref={ref}
3236
>
33-
{({ CardAction }) =>
37+
{({ CardAction }: CardActionRenderProps) =>
3438
typeof children === 'function'
3539
? children({ Text, Subtext, Title, CardName, CardAction })
3640
: children

packages/ffe-cards-react/src/GroupCard/GroupCardTitle.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React, { ElementType, ForwardedRef } from 'react';
22
import classNames from 'classnames';
33
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
4-
import { CardRenderProps, ComponentAsPropParams } from '../types';
4+
import {
5+
CardRenderProps,
6+
ComponentAsPropParams,
7+
CardActionRenderProps,
8+
} from '../types';
59
import { fixedForwardRef } from '../fixedForwardRef';
610

711
export type GroupCardTitleProps<As extends ElementType = 'div'> = Omit<
@@ -39,7 +43,7 @@ function GroupCardTitleWithForwardRef<As extends ElementType>(
3943
{...(rest as Record<string, unknown>)}
4044
ref={ref}
4145
>
42-
{({ CardAction }) =>
46+
{({ CardAction }: CardActionRenderProps) =>
4347
typeof children === 'function'
4448
? children({ Text, Subtext, Title, CardName, CardAction })
4549
: children

packages/ffe-cards-react/src/IconCard/IconCard.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { ElementType, ForwardedRef, ReactElement } from 'react';
2-
import { CardRenderProps, ComponentAsPropParams } from '../types';
2+
import {
3+
CardRenderProps,
4+
ComponentAsPropParams,
5+
CardActionRenderProps,
6+
} from '../types';
37
import classNames from 'classnames';
48
import { WithCardAction, Text, Subtext, Title, CardName } from '../components';
59
import { fixedForwardRef } from '../fixedForwardRef';
@@ -48,7 +52,7 @@ function IconCardWithForwardRef<As extends ElementType>(
4852
{...(rest as Record<string, unknown>)}
4953
ref={ref}
5054
>
51-
{({ CardAction }) => {
55+
{({ CardAction }: CardActionRenderProps) => {
5256
const bodyElement = (
5357
<div className="ffe-icon-card__body">
5458
{typeof children === 'function'

packages/ffe-cards-react/src/IllustrationCard/IllustrationCard.spec.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { IllustrationCard } from './IllustrationCard';
33
import { render, screen } from '@testing-library/react';
4+
import { CardRenderProps } from '../types';
45

56
const children = <div>Hello world</div>;
67
const TEST_ID = 'test-id';
@@ -54,7 +55,7 @@ describe('IllustrationCard', () => {
5455
<IllustrationCard
5556
data-testid={TEST_ID}
5657
img={illustration}
57-
children={Components => (
58+
children={(Components: CardRenderProps) => (
5859
<Components.Text>Hello world</Components.Text>
5960
)}
6061
/>,

packages/ffe-cards-react/src/IllustrationCard/IllustrationCard.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { ElementType, ForwardedRef, ReactElement } from 'react';
2-
import { CardRenderProps, ComponentAsPropParams } from '../types';
2+
import {
3+
CardRenderProps,
4+
ComponentAsPropParams,
5+
CardActionRenderProps,
6+
} from '../types';
37
import classNames from 'classnames';
48
import { WithCardAction, Text, Subtext, Title, CardName } from '../components';
59
import { fixedForwardRef } from '../fixedForwardRef';
@@ -50,7 +54,7 @@ function IllustrationCardWithForwardRef<As extends ElementType>(
5054
{...(rest as Record<string, unknown>)}
5155
ref={ref}
5256
>
53-
{({ CardAction }) => {
57+
{({ CardAction }: CardActionRenderProps) => {
5458
const illustrationElement = (
5559
<div
5660
className={classNames(

packages/ffe-cards-react/src/ImageCard/ImageCard.spec.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { ImageCard } from './ImageCard';
33
import { render, screen, within } from '@testing-library/react';
4+
import { CardRenderProps } from '../types';
45

56
const children = <div>Hello world</div>;
67
const TEST_ID = 'test-id';
@@ -76,7 +77,7 @@ describe('ImageCard', () => {
7677
data-testid={TEST_ID}
7778
imageAltText="Image alt text"
7879
imageSrc="random/path"
79-
children={Components => (
80+
children={(Components: CardRenderProps) => (
8081
<Components.Text>Hello world</Components.Text>
8182
)}
8283
/>,

packages/ffe-cards-react/src/ImageCard/ImageCard.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { ElementType, ForwardedRef } from 'react';
2-
import { CardRenderProps, ComponentAsPropParams } from '../types';
2+
import {
3+
CardRenderProps,
4+
ComponentAsPropParams,
5+
CardActionRenderProps,
6+
} from '../types';
37
import classNames from 'classnames';
48
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
59
import { fixedForwardRef } from '../fixedForwardRef';
@@ -37,7 +41,7 @@ function ImageCardWithForwardRef<As extends ElementType>(
3741
{...(rest as Record<string, unknown>)}
3842
ref={ref}
3943
>
40-
{({ CardAction }) => (
44+
{({ CardAction }: CardActionRenderProps) => (
4145
<>
4246
<div className="ffe-image-card__image-container">
4347
<div className="ffe-image-card__image-overlay" />

packages/ffe-cards-react/src/StippledCard/StippledCard.spec.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { StippledCard } from './StippledCard';
33
import { Icon } from '@sb1/ffe-icons-react';
44
import { render, screen, within } from '@testing-library/react';
5+
import { CardRenderProps } from '../types';
56

67
const children = <div>Hello world</div>;
78
const TEST_ID = 'test-id';
@@ -52,7 +53,7 @@ describe('StippledCard', () => {
5253
element: <Icon fileUrl="monitoring" size="md" />,
5354
type: 'icon',
5455
}}
55-
children={Components => (
56+
children={(Components: CardRenderProps) => (
5657
<Components.Text>Hello world</Components.Text>
5758
)}
5859
/>,

packages/ffe-cards-react/src/StippledCard/StippledCard.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { ElementType, ForwardedRef, ReactNode } from 'react';
2-
import { CardRenderProps, ComponentAsPropParams } from '../types';
2+
import {
3+
CardRenderProps,
4+
ComponentAsPropParams,
5+
CardActionRenderProps,
6+
} from '../types';
37
import classNames from 'classnames';
48
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
59
import { fixedForwardRef } from '../fixedForwardRef';
@@ -43,7 +47,7 @@ function StippledCardWithForwardRef<As extends ElementType>(
4347
{...(rest as Record<string, unknown>)}
4448
ref={ref}
4549
>
46-
{({ CardAction }) => (
50+
{({ CardAction }: CardActionRenderProps) => (
4751
<>
4852
{img && (
4953
<div

packages/ffe-cards-react/src/TextCard/TextCard.spec.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { TextCard } from './TextCard';
33
import { render, screen } from '@testing-library/react';
4+
import { CardRenderProps } from '../types';
45

56
const children = <div>Hello world</div>;
67
const TEST_ID = 'test-id';
@@ -16,7 +17,7 @@ describe('TextCard', () => {
1617
render(
1718
<TextCard
1819
data-testid={TEST_ID}
19-
children={Components => (
20+
children={(Components: CardRenderProps) => (
2021
<Components.Text>Hello world</Components.Text>
2122
)}
2223
/>,

packages/ffe-cards-react/src/TextCard/TextCard.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React, { ElementType, ForwardedRef } from 'react';
2-
import { CardRenderProps, ComponentAsPropParams } from '../types';
2+
import {
3+
CardRenderProps,
4+
ComponentAsPropParams,
5+
CardActionRenderProps,
6+
} from '../types';
37
import classNames from 'classnames';
48
import { CardName, Subtext, Text, Title, WithCardAction } from '../components';
59
import { fixedForwardRef } from '../fixedForwardRef';
@@ -36,7 +40,7 @@ function TextCardWithForwardRef<As extends ElementType>(
3640
{...(rest as Record<string, unknown>)}
3741
ref={ref}
3842
>
39-
{({ CardAction }) =>
43+
{({ CardAction }: CardActionRenderProps) =>
4044
typeof children === 'function'
4145
? children({ Text, Subtext, Title, CardName, CardAction })
4246
: children

packages/ffe-cards-react/src/components/CardAction.stories.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CardBase } from '../CardBase';
55
import { Heading2, Paragraph } from '@sb1/ffe-core-react';
66
import { Icon } from '@sb1/ffe-icons-react';
77
import { IconCard } from '../IconCard/IconCard';
8+
import { CardActionRenderProps, CardRenderProps } from '../types';
89

910
const Custom: React.FC<React.ComponentProps<'a'>> = props => (
1011
<a {...props}>
@@ -39,7 +40,7 @@ export const Standard: Story = {
3940
},
4041
render: args => (
4142
<CardBase shadow={true}>
42-
{({ CardAction }) => (
43+
{({ CardAction }: CardActionRenderProps) => (
4344
<>
4445
<Heading2>
4546
<CardAction {...args}>Lenke</CardAction>
@@ -58,7 +59,7 @@ export const AsButton: Story = {
5859
},
5960
render: args => (
6061
<CardBase shadow={true}>
61-
{({ CardAction }) => (
62+
{({ CardAction }: CardActionRenderProps) => (
6263
<>
6364
<Heading2>
6465
<CardAction {...args}>Knapp</CardAction>
@@ -79,7 +80,13 @@ export const WithinTitle: Story = {
7980
<IconCard
8081
icon={<Icon fileUrl="icons/open/300/xl/savings.svg" size="xl" />}
8182
>
82-
{({ CardAction, CardName, Title, Subtext, Text }) => (
83+
{({
84+
CardAction,
85+
CardName,
86+
Title,
87+
Subtext,
88+
Text,
89+
}: CardRenderProps) => (
8390
<>
8491
<CardName>Kortnavn</CardName>
8592
<Title>

0 commit comments

Comments
 (0)