@altinn/altinn-components 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/StoryDecorator.tsx +1 -1
- package/.storybook/main.ts +3 -4
- package/.storybook/preview.tsx +28 -0
- package/CHANGELOG.md +14 -0
- package/biome.jsonc +1 -1
- package/lib/components/Attachment/AttachmentLink.stories.ts +1 -1
- package/lib/components/Attachment/AttachmentList.stories.ts +1 -1
- package/lib/components/Button/Button.tsx +13 -10
- package/lib/components/Button/ButtonBase.tsx +1 -1
- package/lib/components/Button/ButtonIcon.tsx +16 -0
- package/lib/components/Button/ButtonLabel.tsx +18 -0
- package/lib/components/Button/Buttons.stories.tsx +64 -0
- package/lib/components/Button/ComboButton.tsx +9 -7
- package/lib/components/Button/IconButton.stories.tsx +47 -0
- package/lib/components/Button/IconButton.tsx +15 -5
- package/lib/components/Button/button.module.css +5 -46
- package/lib/components/Button/buttonBase.module.css +55 -23
- package/lib/components/Button/buttonIcon.module.css +17 -0
- package/lib/components/Button/buttonLabel.module.css +17 -0
- package/lib/components/Button/comboButton.module.css +15 -65
- package/lib/components/Button/iconButton.module.css +21 -4
- package/lib/components/Button/index.ts +2 -0
- package/lib/components/ContextMenu/ContextMenu.stories.ts +49 -0
- package/lib/components/ContextMenu/ContextMenu.tsx +12 -20
- package/lib/components/ContextMenu/ContextMenuBase.tsx +33 -0
- package/lib/components/Dialog/Dialog.stories.ts +12 -5
- package/lib/components/Dialog/Dialog.tsx +2 -0
- package/lib/components/Dialog/DialogGroup.tsx +24 -0
- package/lib/components/Dialog/DialogList.stories.ts +14 -10
- package/lib/components/Dialog/DialogList.tsx +26 -11
- package/lib/components/Dialog/DialogListItem.tsx +12 -2
- package/lib/components/Dialog/DialogListItemBase.tsx +4 -2
- package/lib/components/Dialog/DialogNav.stories.ts +5 -5
- package/lib/components/Dialog/DialogNav.tsx +2 -6
- package/lib/components/Dialog/DialogSelect.tsx +1 -1
- package/lib/components/Dialog/dialogGroup.module.css +35 -0
- package/lib/components/Dropdown/Backdrop.tsx +4 -3
- package/lib/components/Dropdown/DrawerBase.tsx +5 -2
- package/lib/components/Dropdown/DrawerBody.tsx +12 -0
- package/lib/components/Dropdown/DrawerButton.tsx +17 -0
- package/lib/components/Dropdown/DrawerFooter.tsx +12 -0
- package/lib/components/Dropdown/DrawerHeader.tsx +19 -0
- package/lib/components/Dropdown/DrawerOrDropdown.tsx +29 -0
- package/lib/components/Dropdown/DropdownBase.tsx +17 -2
- package/lib/components/Dropdown/backdrop.module.css +3 -0
- package/lib/components/Dropdown/drawerBase.module.css +9 -0
- package/lib/components/Dropdown/drawerBody.module.css +5 -0
- package/lib/components/Dropdown/drawerButton.module.css +6 -0
- package/lib/components/Dropdown/drawerFooter.module.css +13 -0
- package/lib/components/Dropdown/drawerHeader.module.css +17 -0
- package/lib/components/Dropdown/drawerOrDropdown.module.css +19 -0
- package/lib/components/Dropdown/dropdownBase.module.css +20 -4
- package/lib/components/Dropdown/index.ts +7 -1
- package/lib/components/Footer/footerMenu.module.css +5 -0
- package/lib/components/GlobalMenu/AccountButton.tsx +29 -0
- package/lib/components/GlobalMenu/AccountMenu.stories.tsx +65 -0
- package/lib/components/GlobalMenu/AccountMenu.tsx +73 -0
- package/lib/components/GlobalMenu/BackButton.tsx +10 -0
- package/lib/components/GlobalMenu/GlobalMenu.stories.tsx +112 -121
- package/lib/components/GlobalMenu/GlobalMenu.tsx +41 -89
- package/lib/components/GlobalMenu/GlobalMenuBase.tsx +22 -0
- package/lib/components/GlobalMenu/LogoutButton.tsx +19 -0
- package/lib/components/GlobalMenu/globalMenuBase.module.css +39 -0
- package/lib/components/GlobalMenu/index.tsx +1 -1
- package/lib/components/GlobalMenu/logoutButton.module.css +9 -0
- package/lib/components/Header/{Header.stories.ts → Header.stories.tsx} +79 -20
- package/lib/components/Header/Header.tsx +25 -38
- package/lib/components/Header/HeaderBase.tsx +7 -3
- package/lib/components/Header/header.module.css +10 -42
- package/lib/components/Header/headerBase.module.css +43 -0
- package/lib/components/Header/headerButton.module.css +1 -0
- package/lib/components/Layout/Layout.stories.tsx +77 -38
- package/lib/components/Layout/Layout.tsx +5 -3
- package/lib/components/Layout/LayoutBase.tsx +3 -2
- package/lib/components/Layout/layoutBase.module.css +11 -0
- package/lib/components/Layout/layoutBody.module.css +1 -0
- package/lib/components/LayoutAction/ActionHeader.tsx +1 -1
- package/lib/components/LayoutAction/ActionMenu.tsx +2 -4
- package/lib/components/LayoutAction/actionMenu.module.css +3 -0
- package/lib/components/List/List.stories.tsx +43 -0
- package/lib/components/List/List.tsx +6 -6
- package/lib/components/List/ListBase.tsx +6 -6
- package/lib/components/List/ListItem.tsx +4 -1
- package/lib/components/List/ListItemBase.tsx +20 -4
- package/lib/components/List/listBase.module.css +3 -3
- package/lib/components/List/listItemBase.module.css +4 -0
- package/lib/components/Menu/Menu.stories.ts +46 -46
- package/lib/components/Menu/Menu.tsx +3 -102
- package/lib/components/Menu/MenuBase.tsx +47 -3
- package/lib/components/Menu/MenuItem.tsx +8 -4
- package/lib/components/Menu/MenuItemBase.tsx +15 -2
- package/lib/components/Menu/MenuItems.stories.ts +438 -0
- package/lib/components/Menu/MenuItems.tsx +96 -0
- package/lib/components/Menu/MenuOption.tsx +4 -1
- package/lib/components/Menu/index.ts +1 -1
- package/lib/components/Menu/menu.module.css +2 -3
- package/lib/components/Menu/menuBase.module.css +25 -0
- package/lib/components/Menu/menuItemBase.module.css +11 -5
- package/lib/components/Menu/menuItemLabel.module.css +11 -1
- package/lib/components/Menu/menuSearch.module.css +1 -0
- package/lib/components/Meta/MetaItemBase.tsx +1 -1
- package/lib/components/Meta/MetaItemLabel.tsx +1 -1
- package/lib/components/Meta/MetaItemMedia.tsx +1 -1
- package/lib/components/Page/PageBase.tsx +14 -0
- package/lib/components/Page/PageHeader.tsx +21 -0
- package/lib/components/Page/PageHeaderMedia.tsx +25 -0
- package/lib/components/Page/SectionBase.tsx +52 -0
- package/lib/components/Page/SectionFooter.tsx +15 -0
- package/lib/components/Page/SectionHeader.tsx +16 -0
- package/lib/components/Page/index.ts +5 -0
- package/lib/components/Page/pageHeader.module.css +5 -0
- package/lib/components/Page/sectionBase.module.css +82 -0
- package/lib/components/Page/sectionFooter.module.css +8 -0
- package/lib/components/Page/sectionHeader.module.css +9 -0
- package/lib/components/RootProvider/RootProvider.tsx +43 -7
- package/lib/components/Searchbar/Autocomplete.stories.tsx +77 -0
- package/lib/components/Searchbar/Autocomplete.tsx +44 -0
- package/lib/components/Searchbar/AutocompleteBase.tsx +16 -0
- package/lib/components/Searchbar/AutocompleteGroup.tsx +17 -0
- package/lib/components/Searchbar/AutocompleteItem.tsx +23 -0
- package/lib/components/Searchbar/SearchField.tsx +78 -0
- package/lib/components/Searchbar/Searchbar.stories.tsx +151 -0
- package/lib/components/Searchbar/Searchbar.tsx +18 -0
- package/lib/components/Searchbar/SearchbarBase.tsx +23 -0
- package/lib/components/Searchbar/autocompleteBase.module.css +17 -0
- package/lib/components/Searchbar/autocompleteGroup.module.css +3 -0
- package/lib/components/Searchbar/autocompleteItem.module.css +19 -0
- package/lib/components/Searchbar/index.ts +1 -0
- package/lib/components/Searchbar/searchField.module.css +54 -0
- package/lib/components/Searchbar/searchbarBase.module.css +20 -0
- package/lib/components/Toolbar/Toolbar.stories.tsx +10 -10
- package/lib/components/Toolbar/Toolbar.tsx +28 -10
- package/lib/components/Toolbar/ToolbarAdd.tsx +6 -5
- package/lib/components/Toolbar/ToolbarBase.tsx +5 -20
- package/lib/components/Toolbar/ToolbarButton.tsx +1 -1
- package/lib/components/Toolbar/ToolbarFilter.tsx +11 -6
- package/lib/components/Toolbar/ToolbarMenu.tsx +8 -7
- package/lib/components/Toolbar/ToolbarOptions.stories.ts +5 -5
- package/lib/components/Toolbar/ToolbarOptions.tsx +34 -21
- package/lib/components/Toolbar/toolbarAdd.module.css +7 -0
- package/lib/components/Toolbar/toolbarBase.module.css +19 -0
- package/lib/components/Toolbar/toolbarButton.module.css +1 -1
- package/lib/components/Toolbar/toolbarFilter.module.css +25 -0
- package/lib/components/Toolbar/toolbarMenu.module.css +7 -0
- package/lib/components/Typography/Heading.tsx +23 -0
- package/lib/components/Typography/Typography.tsx +8 -5
- package/lib/components/Typography/heading.module.css +21 -0
- package/lib/components/Typography/index.ts +1 -0
- package/lib/components/Typography/typography.module.css +8 -0
- package/lib/components/index.ts +2 -0
- package/lib/hooks/index.ts +3 -0
- package/lib/{components/Menu → hooks}/useEscapeKey.ts +2 -2
- package/lib/hooks/useMenu.tsx +80 -0
- package/lib/index.ts +1 -0
- package/lib/stories/Color/MenuItem.stories.tsx +43 -0
- package/lib/stories/Color/Swatches.stories.tsx +19 -0
- package/lib/stories/Color/Swatches.tsx +42 -0
- package/lib/stories/Color/colors.json +62 -0
- package/lib/stories/Color/swatches.module.css +14 -0
- package/lib/stories/Inbox/BookmarksPage.tsx +52 -0
- package/lib/stories/Inbox/DialogPage.tsx +15 -0
- package/lib/stories/Inbox/Inbox.stories.tsx +55 -0
- package/lib/stories/Inbox/Inbox.tsx +12 -0
- package/lib/stories/Inbox/InboxLayout.tsx +50 -0
- package/lib/stories/Inbox/InboxPage.tsx +50 -0
- package/lib/stories/Inbox/InboxProvider.tsx +136 -0
- package/lib/stories/Inbox/InboxSection.tsx +39 -0
- package/lib/stories/Inbox/InboxToolbar.tsx +94 -0
- package/lib/stories/Inbox/ProfilePage.tsx +35 -0
- package/lib/stories/Inbox/SettingsPage.tsx +19 -0
- package/lib/stories/Inbox/accounts/accounts.ts +24 -0
- package/lib/stories/Inbox/accounts/index.ts +1 -0
- package/lib/stories/Inbox/actionMenu.ts +24 -0
- package/lib/stories/Inbox/dialogs/brreg-completed.json +35 -0
- package/lib/stories/Inbox/dialogs/brreg-draft.json +45 -0
- package/lib/stories/Inbox/dialogs/index.ts +10 -0
- package/lib/stories/Inbox/dialogs/skatt-2023.json +33 -0
- package/lib/stories/Inbox/groupBy.ts +19 -0
- package/lib/stories/Inbox/inboxSection.module.css +19 -0
- package/lib/stories/Inbox/index.ts +15 -0
- package/lib/stories/Inbox/layout/footer.ts +27 -0
- package/lib/stories/Inbox/layout/header.ts +11 -0
- package/lib/stories/Inbox/layout/index.ts +3 -0
- package/lib/stories/Inbox/layout/menu.ts +64 -0
- package/package.json +15 -13
- package/tsconfig.json +7 -2
- package/lib/components/Header/HeaderSearch.stories.ts +0 -20
- package/lib/components/Header/HeaderSearch.tsx +0 -44
- package/lib/components/Header/headerSearch.module.css +0 -30
- package/lib/components/Menu/MenuGroup.tsx +0 -18
- package/lib/components/Menu/__menuItem.module.css +0 -130
- package/lib/components/Toolbar/toolbar.module.css +0 -43
- /package/lib/components/ContextMenu/{contextMenu.module.css → contextMenuBase.module.css} +0 -0
- /package/lib/{components/Menu → hooks}/useClickOutside.ts +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MouseEventHandler, ReactNode } from 'react';
|
|
2
|
+
import { ButtonBase, ButtonLabel } from '../';
|
|
3
|
+
import styles from './drawerButton.module.css';
|
|
4
|
+
|
|
5
|
+
export interface DrawerButtonProps {
|
|
6
|
+
label?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
onClick?: MouseEventHandler;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const DrawerButton = ({ label, children, onClick }: DrawerButtonProps) => {
|
|
12
|
+
return (
|
|
13
|
+
<ButtonBase variant="solid" size="md" className={styles.button} onClick={onClick}>
|
|
14
|
+
<ButtonLabel size="md">{children || label}</ButtonLabel>
|
|
15
|
+
</ButtonBase>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import styles from './drawerFooter.module.css';
|
|
4
|
+
|
|
5
|
+
export interface DrawerFooterProps {
|
|
6
|
+
className?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const DrawerFooter = ({ className, children }: DrawerFooterProps) => {
|
|
11
|
+
return <footer className={cx(styles.footer, className)}>{children}</footer>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import type { MouseEventHandler } from 'react';
|
|
3
|
+
import { IconButton } from '../Button';
|
|
4
|
+
import styles from './drawerHeader.module.css';
|
|
5
|
+
|
|
6
|
+
export interface DrawerHeaderProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
onClose?: MouseEventHandler;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const DrawerHeader = ({ className, title, onClose }: DrawerHeaderProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<header className={cx(styles.header, className)}>
|
|
15
|
+
<h2 className={styles.title}>{title}</h2>
|
|
16
|
+
<IconButton size="sm" icon="x-mark" variant="outline" onClick={onClose} className={styles.close} />
|
|
17
|
+
</header>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MouseEventHandler, ReactNode } from 'react';
|
|
2
|
+
import { DrawerBase, DrawerBody, DrawerButton, DrawerFooter, DrawerHeader, DropdownBase } from '../';
|
|
3
|
+
import type { DrawerButtonProps } from '../';
|
|
4
|
+
import { Backdrop } from './Backdrop';
|
|
5
|
+
import styles from './drawerOrDropdown.module.css';
|
|
6
|
+
|
|
7
|
+
export interface DrawerOrDropdownProps {
|
|
8
|
+
title: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
expanded?: boolean;
|
|
11
|
+
onClose?: MouseEventHandler;
|
|
12
|
+
button?: DrawerButtonProps;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const DrawerOrDropdown = ({ expanded = false, title, onClose, button, children }: DrawerOrDropdownProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
{expanded && <Backdrop onClick={onClose} />}
|
|
19
|
+
<DropdownBase className={styles.dropdown} expanded={expanded}>
|
|
20
|
+
{children}
|
|
21
|
+
</DropdownBase>
|
|
22
|
+
<DrawerBase className={styles.drawer} placement="bottom" expanded={expanded}>
|
|
23
|
+
<DrawerHeader title={title} onClose={onClose} />
|
|
24
|
+
<DrawerBody>{children}</DrawerBody>
|
|
25
|
+
<DrawerFooter>{button && <DrawerButton onClick={button?.onClick}>{button?.label}</DrawerButton>}</DrawerFooter>
|
|
26
|
+
</DrawerBase>
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -2,15 +2,30 @@ import cx from 'classnames';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import styles from './dropdownBase.module.css';
|
|
4
4
|
|
|
5
|
+
export type DropdownPlacement = 'left' | 'right';
|
|
6
|
+
|
|
5
7
|
export interface DropdownBaseProps {
|
|
8
|
+
placement?: DropdownPlacement;
|
|
9
|
+
padding?: boolean;
|
|
6
10
|
expanded?: boolean;
|
|
7
11
|
className?: string;
|
|
8
12
|
children?: ReactNode;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
export const DropdownBase = ({
|
|
15
|
+
export const DropdownBase = ({
|
|
16
|
+
placement = 'left',
|
|
17
|
+
padding = true,
|
|
18
|
+
expanded = false,
|
|
19
|
+
className,
|
|
20
|
+
children,
|
|
21
|
+
}: DropdownBaseProps) => {
|
|
12
22
|
return (
|
|
13
|
-
<div
|
|
23
|
+
<div
|
|
24
|
+
className={cx(styles.dropdown, className)}
|
|
25
|
+
data-placement={placement}
|
|
26
|
+
data-padding={padding}
|
|
27
|
+
aria-expanded={expanded}
|
|
28
|
+
>
|
|
14
29
|
{children}
|
|
15
30
|
</div>
|
|
16
31
|
);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.header {
|
|
2
|
+
position: sticky;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
right: 0;
|
|
6
|
+
padding: 1rem;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
border-bottom: 1px solid var(--theme-border-subtle);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.title {
|
|
14
|
+
font-size: 1.125rem;
|
|
15
|
+
font-weight: 500;
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.dropdown[aria-expanded="true"] {
|
|
2
|
+
display: none;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.drawer[aria-expanded="true"] {
|
|
6
|
+
display: block;
|
|
7
|
+
z-index: 2;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (min-width: 1024px) {
|
|
11
|
+
.drawer[aria-expanded="true"] {
|
|
12
|
+
display: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.dropdown[aria-expanded="true"] {
|
|
16
|
+
display: block;
|
|
17
|
+
z-index: 2;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -5,14 +5,30 @@
|
|
|
5
5
|
.dropdown[aria-expanded="true"] {
|
|
6
6
|
display: block;
|
|
7
7
|
position: absolute;
|
|
8
|
-
right: 0;
|
|
9
8
|
z-index: 2;
|
|
10
9
|
}
|
|
11
10
|
|
|
11
|
+
.dropdown[data-placement="left"] {
|
|
12
|
+
left: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.dropdown[data-placement="right"] {
|
|
16
|
+
right: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.dropdown[data-padding="trur"] {
|
|
20
|
+
padding: 0 0.5rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
.dropdown {
|
|
24
|
+
min-width: 14rem;
|
|
13
25
|
margin-top: 0.5rem;
|
|
14
|
-
padding: 0 0.5rem;
|
|
15
26
|
background-color: var(--neutral-background-default);
|
|
16
|
-
border-radius:
|
|
17
|
-
box-shadow:
|
|
27
|
+
border-radius: 0.375rem;
|
|
28
|
+
box-shadow: var(--ds-shadow-md);
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.drawer .button {
|
|
33
|
+
border-radius: 50%;
|
|
18
34
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export * from './DrawerBase';
|
|
2
1
|
export * from './DropdownBase';
|
|
3
2
|
export * from './Backdrop';
|
|
3
|
+
|
|
4
|
+
export * from './DrawerBase';
|
|
5
|
+
export * from './DrawerHeader';
|
|
6
|
+
export * from './DrawerFooter';
|
|
7
|
+
export * from './DrawerButton';
|
|
8
|
+
export * from './DrawerBody';
|
|
9
|
+
export * from './DrawerOrDropdown';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MenuItemBase, MenuItemLabel, MenuItemMedia } from '../Menu';
|
|
2
|
+
|
|
3
|
+
type Account = {
|
|
4
|
+
type: 'person' | 'company';
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type AccountButtonProps = {
|
|
10
|
+
account: Account;
|
|
11
|
+
description?: string;
|
|
12
|
+
linkText?: string;
|
|
13
|
+
onClick?: () => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const AccountButton = ({ account, linkText, onClick }: AccountButtonProps) => {
|
|
17
|
+
return (
|
|
18
|
+
<MenuItemBase size="lg" onClick={onClick} linkText={linkText} linkIcon="arrow-right">
|
|
19
|
+
<MenuItemMedia
|
|
20
|
+
size="lg"
|
|
21
|
+
avatar={{
|
|
22
|
+
name: account.name,
|
|
23
|
+
type: account.type,
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
<MenuItemLabel size="lg" title={account?.name} description={account?.description} />
|
|
27
|
+
</MenuItemBase>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { AccountMenu } from './AccountMenu';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'GlobalMenu/AccountMenu',
|
|
7
|
+
component: AccountMenu,
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
parameters: {},
|
|
10
|
+
args: {
|
|
11
|
+
accountGroups: {
|
|
12
|
+
primary: {
|
|
13
|
+
title: 'Deg selv og favoritter',
|
|
14
|
+
},
|
|
15
|
+
secondary: {
|
|
16
|
+
title: 'Andre kontoer',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
accounts: [
|
|
20
|
+
{
|
|
21
|
+
groupId: 'primary',
|
|
22
|
+
type: 'person',
|
|
23
|
+
name: 'Aurora Mikalsen',
|
|
24
|
+
selected: true,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
groupId: 'favourites',
|
|
28
|
+
type: 'company',
|
|
29
|
+
name: 'Bergen Bar',
|
|
30
|
+
selected: false,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
groupId: 'secondary',
|
|
34
|
+
type: 'company',
|
|
35
|
+
name: 'Keeperhansker AS',
|
|
36
|
+
selected: false,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
groupId: 'secondary',
|
|
40
|
+
type: 'company',
|
|
41
|
+
name: 'Stadion drift AS',
|
|
42
|
+
selected: false,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
groupId: 'favourites',
|
|
46
|
+
type: 'company',
|
|
47
|
+
name: 'Sportsklubben Brann',
|
|
48
|
+
selected: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
groupId: 'secondary',
|
|
52
|
+
type: 'company',
|
|
53
|
+
name: 'Landslaget',
|
|
54
|
+
selected: false,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
} satisfies Meta<typeof AccountMenu>;
|
|
59
|
+
|
|
60
|
+
export default meta;
|
|
61
|
+
type Story = StoryObj<typeof meta>;
|
|
62
|
+
|
|
63
|
+
export const Default: Story = {
|
|
64
|
+
args: {},
|
|
65
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Menu, type MenuItemGroups, type MenuItemProps, type MenuSearchProps } from '../Menu';
|
|
4
|
+
|
|
5
|
+
export interface AccountSearch extends MenuSearchProps {
|
|
6
|
+
getResultsLabel?: (hits: number) => string;
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AccountMenuItem {
|
|
11
|
+
type: 'person' | 'company';
|
|
12
|
+
name: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
groupId?: string;
|
|
15
|
+
selected?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AccountMenuProps {
|
|
19
|
+
accounts?: AccountMenuItem[];
|
|
20
|
+
accountGroups?: MenuItemGroups;
|
|
21
|
+
accountSearch?: AccountSearch;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const defaultResultLabel = (hits: number) => `${hits} hits`;
|
|
25
|
+
|
|
26
|
+
export const AccountMenu = ({ accounts = [], accountGroups = {}, accountSearch }: AccountMenuProps) => {
|
|
27
|
+
const accountMenu: MenuItemProps[] = accounts.map((account) => ({
|
|
28
|
+
id: account.name,
|
|
29
|
+
groupId: account.groupId || 'search',
|
|
30
|
+
selected: account.selected,
|
|
31
|
+
title: account.name,
|
|
32
|
+
avatar: {
|
|
33
|
+
type: account.type,
|
|
34
|
+
name: account.name,
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
const [filterString, setFilterString] = useState<string>('');
|
|
39
|
+
|
|
40
|
+
const filteredAccountMenu = filterString
|
|
41
|
+
? accountMenu
|
|
42
|
+
.filter((item) => item?.title?.toLowerCase().includes(filterString.toLowerCase()))
|
|
43
|
+
.map((item) => {
|
|
44
|
+
return {
|
|
45
|
+
...item,
|
|
46
|
+
groupId: 'search',
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
: accountMenu;
|
|
50
|
+
|
|
51
|
+
const filterAccountGroups = filterString
|
|
52
|
+
? {
|
|
53
|
+
search: {
|
|
54
|
+
title:
|
|
55
|
+
accountSearch?.getResultsLabel?.(filteredAccountMenu.length) ??
|
|
56
|
+
defaultResultLabel(filteredAccountMenu.length),
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
: accountGroups;
|
|
60
|
+
|
|
61
|
+
const accountSearchItem: MenuSearchProps = {
|
|
62
|
+
name: 'account-search',
|
|
63
|
+
value: filterString,
|
|
64
|
+
placeholder: accountSearch?.placeholder ?? 'Find account',
|
|
65
|
+
onChange: (event: React.ChangeEvent<HTMLInputElement>) => setFilterString(event.target.value),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const accountSwitcher: MenuItemProps[] = [
|
|
69
|
+
...(filteredAccountMenu.length > 0 ? filteredAccountMenu : [{ id: 'search', groupId: 'search', hidden: true }]),
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
return <Menu theme="global" search={accountSearchItem} groups={filterAccountGroups} items={accountSwitcher} />;
|
|
73
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MenuItem } from '../Menu';
|
|
2
|
+
|
|
3
|
+
export interface BackButtonProps {
|
|
4
|
+
label: string;
|
|
5
|
+
onClick?: () => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const BackButton = ({ label, onClick }: BackButtonProps) => {
|
|
9
|
+
return <MenuItem id="back" icon="arrow-left" title={label} onClick={onClick} />;
|
|
10
|
+
};
|