-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(ffe-formatters): add storybook examples
- Loading branch information
Showing
20 changed files
with
310 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Meta } from '@storybook/blocks'; | ||
import { Table, TableHead, TableRow, TableDataCell, TableHeaderCell, TableBody, TableCaption } from "@sb1/ffe-tables-react"; | ||
|
||
<Meta title="Formattering/Formattering" /> | ||
# Formateringsprinsipper | ||
|
||
Det finnes mange formateringsprinsipper som er standardisert i Norge, og som bidrar til å øke lesbarheten. I designsystemet har vi komponenter som hjelper med formateringen, så du som utvikler ikke trenger å bekymre deg for at ting ikke vises riktig. | ||
|
||
<Table className="sb-unstyled"> | ||
<TableCaption className="sb-unstyled">Utvalg av ulike formateringer som finnes:</TableCaption> | ||
<TableHead className="sb-unstyled"> | ||
<TableRow className="sb-unstyled"> | ||
<TableHeaderCell className="sb-unstyled">Type</TableHeaderCell> | ||
<TableHeaderCell className="sb-unstyled">Eksempel</TableHeaderCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{[ | ||
{type :'Datoer', eksempel: '12.11.2024'}, | ||
{type :'Tall', eksempel: '100 000'}, | ||
{type :'Valuta', eksempel: 'kr 1 000,–'}, | ||
{type :'Prosenter', eksempel: '7 %'}, | ||
{type :'Kontonummer', eksempel: '1234 56 78901'}, | ||
{type :'Fødselsnummer', eksempel: '123456 78901'}, | ||
{type :'Avstander', eksempel: '50 km'}, | ||
].map((it) => ( | ||
<TableRow className="sb-unstyled" key={it.type}> | ||
<TableDataCell className="sb-unstyled">{it.type}</TableDataCell> | ||
<TableDataCell className="sb-unstyled">{it.eksempel}</TableDataCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
|
22 changes: 22 additions & 0 deletions
22
packages/ffe-formatters/src/formatAccountNumber.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatAccountNumber } from './formatAccountNumber'; | ||
|
||
const Demo: React.FC<{ accountNumber: string }> = ({ accountNumber }) => { | ||
return <>{formatAccountNumber(accountNumber)}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatAccountNumber', | ||
component: Demo, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
accountNumber: '90010012345', | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Canvas, Meta, Controls } from '@storybook/blocks'; | ||
import * as formatCurrencyStories from './formatCurrency.stories'; | ||
|
||
<Meta of={formatCurrencyStories} /> | ||
|
||
# formatCurrency | ||
|
||
`formatCurrency` kan gis et objekt som andre argument for å styre prefix og postfix: | ||
|
||
<Canvas of={formatCurrencyStories.Standard} /> | ||
<Controls of={formatCurrencyStories.Standard} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatCurrency } from './formatCurrency'; | ||
import { Locale } from './types'; | ||
|
||
interface DemoParams { | ||
amount: string | number; | ||
prefix?: string; | ||
postfix?: string; | ||
locale: Locale; | ||
} | ||
|
||
const Demo: React.FC<DemoParams> = ({ amount, postfix, prefix, locale }) => { | ||
return <>{formatCurrency(amount, { locale, postfix, prefix })}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatCurrency', | ||
component: Demo, | ||
argTypes: { | ||
prefix: { control: 'text' }, | ||
postfix: { control: 'text' }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
amount: '1000', | ||
locale: 'nb', | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Canvas, Meta, Controls } from '@storybook/blocks'; | ||
import * as formatDateStories from './formatDate.stories'; | ||
|
||
<Meta of={formatDateStories} /> | ||
|
||
# formatDate | ||
|
||
`formateDate` støtter bare norsk locale, og formaterer Date-objekter og timestamps. | ||
|
||
<Canvas of={formatDateStories.Standard} /> | ||
<Controls of={formatDateStories.Standard} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatDate } from './formatDate'; | ||
|
||
interface DemoParams { | ||
timestamp: Date | number; | ||
} | ||
|
||
const Demo: React.FC<DemoParams> = ({ timestamp }) => { | ||
return <>{formatDate(timestamp)}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatDate', | ||
component: Demo, | ||
argTypes: { | ||
timestamp: { control: 'date' }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
timestamp: new Date(), | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Canvas, Meta, Controls } from '@storybook/blocks'; | ||
import * as formatDistanceStories from './formatDistance.stories'; | ||
|
||
<Meta of={formatDistanceStories} /> | ||
|
||
# formatDistance | ||
|
||
<Canvas of={formatDistanceStories.Standard} /> | ||
<Controls of={formatDistanceStories.Standard} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatDistance } from './formatDistance'; | ||
|
||
interface DemoParams { | ||
distance: string | number; | ||
unit?: string; | ||
} | ||
|
||
const Demo: React.FC<DemoParams> = ({ unit, distance }) => { | ||
return <>{formatDistance(distance, { unit })}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatDistance', | ||
component: Demo, | ||
argTypes: { | ||
unit: { control: 'text' }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
distance: '160 520', | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Canvas, Meta, Controls } from '@storybook/blocks'; | ||
import * as formatFodselsnummerStories from './formatFodselsnummer.stories'; | ||
|
||
<Meta of={formatFodselsnummerStories} /> | ||
|
||
# formatFodselsnummer | ||
|
||
<Canvas of={formatFodselsnummerStories.Standard} /> | ||
<Controls of={formatFodselsnummerStories.Standard} /> |
26 changes: 26 additions & 0 deletions
26
packages/ffe-formatters/src/formatFodselsnummer.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatFodselsnummer } from './formatFodselsnummer'; | ||
|
||
interface DemoParams { | ||
ssn: string; | ||
} | ||
|
||
const Demo: React.FC<DemoParams> = ({ ssn }) => { | ||
return <>{formatFodselsnummer(ssn)}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatFodselsnummer', | ||
component: Demo, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
ssn: '01010112345', | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Canvas, Meta, Controls } from '@storybook/blocks'; | ||
import * as formatNumberStories from './formatNumber.stories'; | ||
|
||
<Meta of={formatNumberStories} /> | ||
|
||
# formatNumber | ||
|
||
Om ingen av de spesialiserte formateringsfunksjonene passer kan du bruke formatNumber. Denne funksjonen utgjør basen i mange av de andre funksjonene. | ||
|
||
<Canvas of={formatNumberStories.Standard} /> | ||
<Controls of={formatNumberStories.Standard} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatNumber } from './formatNumber'; | ||
import { Locale } from './types'; | ||
|
||
interface DemoParams { | ||
number: number | string | null | undefined; | ||
locale: Locale; | ||
decimals?: number; | ||
} | ||
|
||
const Demo: React.FC<DemoParams> = ({ number, ...rest }) => { | ||
return <>{formatNumber(number, { ...rest })}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatNumber', | ||
component: Demo, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
number: '1234567890', | ||
locale: 'nb', | ||
decimals: 2, | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Canvas, Meta, Controls } from '@storybook/blocks'; | ||
import * as formatPercentageStories from './formatPercentage.stories'; | ||
|
||
<Meta of={formatPercentageStories} /> | ||
|
||
# formatPercentage | ||
|
||
`formatPercentage` gir prosenter det riktige mellomrommet mellom tall og % med et non-breaking space. | ||
Runder av til så få desimaler som mulig, med en default cap på to desimaler. Dette kan overstyres i `options`-objektet. | ||
|
||
<Canvas of={formatPercentageStories.Standard} /> | ||
<Controls of={formatPercentageStories.Standard} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
import { formatPercentage } from './formatPercentage'; | ||
|
||
interface DemoParams { | ||
amount: number | string; | ||
minDecimals?: number; | ||
maxDecimals?: number; | ||
} | ||
|
||
const Demo: React.FC<DemoParams> = ({ amount, ...rest }) => { | ||
return <>{formatPercentage(amount, { ...rest })}</>; | ||
}; | ||
|
||
const meta: Meta<typeof Demo> = { | ||
title: 'Formattering/formatPercentage', | ||
component: Demo, | ||
argTypes: { | ||
minDecimals: { control: 'number' }, | ||
maxDecimals: { control: 'number' }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof Demo>; | ||
|
||
export const Standard: Story = { | ||
args: { | ||
amount: '49', | ||
}, | ||
render: args => <Demo {...args} />, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters