Skip to content

Commit

Permalink
update icon sizing and add story
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnusrm committed Oct 2, 2023
1 parent 4111089 commit 8371de3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/react/src/components/Tabs/TabItem/TabItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
}

.tabItem.small {
--fdsc-icon-size: var(--fds-sizing-4);
--fdsc-icon-size: var(--fds-sizing-5);

font: var(--fds-typography-interactive-small);
font-family: var(--fdsc-typography-font-family);
padding: var(--fds-spacing-2) var(--fds-spacing-4);
}

.tabItem.medium {
--fdsc-icon-size: var(--fds-sizing-5);
--fdsc-icon-size: var(--fds-sizing-6);

font: var(--fds-typography-interactive-medium);
font-family: var(--fdsc-typography-font-family);
padding: var(--fds-spacing-3) var(--fds-spacing-5);
}

.tabItem.large {
--fdsc-icon-size: var(--fds-sizing-5);
--fdsc-icon-size: var(--fds-sizing-7);

font: var(--fds-typography-interactive-large);
font-family: var(--fdsc-typography-font-family);
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/components/Tabs/Tabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ import { Tabs } from '@digdir/design-system-react';
## Icons only

<Canvas of={TabsStories.IconsOnly} />

## Controlled

<Canvas of={TabsStories.Controlled} />
50 changes: 46 additions & 4 deletions packages/react/src/components/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import type { Meta, StoryFn, StoryObj } from '@storybook/react';
import React, { useState } from 'react';
import type { Meta, StoryFn } from '@storybook/react';
import * as icons from '@navikt/aksel-icons';

import { Tabs } from '.';

Check warning on line 5 in packages/react/src/components/Tabs/Tabs.stories.tsx

View workflow job for this annotation

GitHub Actions / Builds, lints and tests code

There should be at least one empty line between import groups
import { Button } from '../Button';

Check warning on line 6 in packages/react/src/components/Tabs/Tabs.stories.tsx

View workflow job for this annotation

GitHub Actions / Builds, lints and tests code

`../Button` import should occur before import of `.`

const icon = (
<svg
Expand All @@ -24,8 +25,6 @@ const AkselIcon2 = icons.NewspaperFillIcon;
const AkselIcon3 = icons.BrailleIcon;
const AkselIcon4 = icons.BackpackFillIcon;

type Story = StoryObj<typeof Tabs>;

export default {
title: 'Felles/Tabs',
component: Tabs,
Expand Down Expand Up @@ -88,3 +87,46 @@ export const IconsOnly: StoryFn<typeof Tabs> = () => (
<Tabs.Content value='value3'>content 3</Tabs.Content>
</Tabs>
);

export const Controlled: StoryFn<typeof Tabs> = () => {
const [value, setValue] = useState('value1');

return (
<>
<Button
size='small'
onClick={() => setValue('value3')}
>
Choose Tab 3
</Button>
<Tabs
value={value}
onChange={setValue}
>
<Tabs.List>
<Tabs.Tab
value='value1'
icon={icon}
>
Tab 1
</Tabs.Tab>
<Tabs.Tab
value='value2'
icon={<AkselIcon2 />}
>
Tab 2
</Tabs.Tab>
<Tabs.Tab
value='value3'
icon={<AkselIcon4 />}
>
Tab 3
</Tabs.Tab>
</Tabs.List>
<Tabs.Content value='value1'>content 1</Tabs.Content>
<Tabs.Content value='value2'>content 2</Tabs.Content>
<Tabs.Content value='value3'>content 3</Tabs.Content>
</Tabs>
</>
);
};
5 changes: 4 additions & 1 deletion packages/react/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export type TabsContextProps = {
export const TabsContext = createContext<TabsContextProps>({});

export const Tabs = forwardRef<HTMLDivElement, TabsProps>(
({ children, value, defaultValue, onChange, size, ...rest }, ref) => {
(
{ children, value, defaultValue, onChange, size = 'medium', ...rest },
ref,
) => {
const isControlled = value !== undefined;
const [uncontrolledValue, setUncontrolledValue] = useState<
string | undefined
Expand Down

0 comments on commit 8371de3

Please sign in to comment.