@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.
Files changed (194) hide show
  1. package/.storybook/StoryDecorator.tsx +1 -1
  2. package/.storybook/main.ts +3 -4
  3. package/.storybook/preview.tsx +28 -0
  4. package/CHANGELOG.md +14 -0
  5. package/biome.jsonc +1 -1
  6. package/lib/components/Attachment/AttachmentLink.stories.ts +1 -1
  7. package/lib/components/Attachment/AttachmentList.stories.ts +1 -1
  8. package/lib/components/Button/Button.tsx +13 -10
  9. package/lib/components/Button/ButtonBase.tsx +1 -1
  10. package/lib/components/Button/ButtonIcon.tsx +16 -0
  11. package/lib/components/Button/ButtonLabel.tsx +18 -0
  12. package/lib/components/Button/Buttons.stories.tsx +64 -0
  13. package/lib/components/Button/ComboButton.tsx +9 -7
  14. package/lib/components/Button/IconButton.stories.tsx +47 -0
  15. package/lib/components/Button/IconButton.tsx +15 -5
  16. package/lib/components/Button/button.module.css +5 -46
  17. package/lib/components/Button/buttonBase.module.css +55 -23
  18. package/lib/components/Button/buttonIcon.module.css +17 -0
  19. package/lib/components/Button/buttonLabel.module.css +17 -0
  20. package/lib/components/Button/comboButton.module.css +15 -65
  21. package/lib/components/Button/iconButton.module.css +21 -4
  22. package/lib/components/Button/index.ts +2 -0
  23. package/lib/components/ContextMenu/ContextMenu.stories.ts +49 -0
  24. package/lib/components/ContextMenu/ContextMenu.tsx +12 -20
  25. package/lib/components/ContextMenu/ContextMenuBase.tsx +33 -0
  26. package/lib/components/Dialog/Dialog.stories.ts +12 -5
  27. package/lib/components/Dialog/Dialog.tsx +2 -0
  28. package/lib/components/Dialog/DialogGroup.tsx +24 -0
  29. package/lib/components/Dialog/DialogList.stories.ts +14 -10
  30. package/lib/components/Dialog/DialogList.tsx +26 -11
  31. package/lib/components/Dialog/DialogListItem.tsx +12 -2
  32. package/lib/components/Dialog/DialogListItemBase.tsx +4 -2
  33. package/lib/components/Dialog/DialogNav.stories.ts +5 -5
  34. package/lib/components/Dialog/DialogNav.tsx +2 -6
  35. package/lib/components/Dialog/DialogSelect.tsx +1 -1
  36. package/lib/components/Dialog/dialogGroup.module.css +35 -0
  37. package/lib/components/Dropdown/Backdrop.tsx +4 -3
  38. package/lib/components/Dropdown/DrawerBase.tsx +5 -2
  39. package/lib/components/Dropdown/DrawerBody.tsx +12 -0
  40. package/lib/components/Dropdown/DrawerButton.tsx +17 -0
  41. package/lib/components/Dropdown/DrawerFooter.tsx +12 -0
  42. package/lib/components/Dropdown/DrawerHeader.tsx +19 -0
  43. package/lib/components/Dropdown/DrawerOrDropdown.tsx +29 -0
  44. package/lib/components/Dropdown/DropdownBase.tsx +17 -2
  45. package/lib/components/Dropdown/backdrop.module.css +3 -0
  46. package/lib/components/Dropdown/drawerBase.module.css +9 -0
  47. package/lib/components/Dropdown/drawerBody.module.css +5 -0
  48. package/lib/components/Dropdown/drawerButton.module.css +6 -0
  49. package/lib/components/Dropdown/drawerFooter.module.css +13 -0
  50. package/lib/components/Dropdown/drawerHeader.module.css +17 -0
  51. package/lib/components/Dropdown/drawerOrDropdown.module.css +19 -0
  52. package/lib/components/Dropdown/dropdownBase.module.css +20 -4
  53. package/lib/components/Dropdown/index.ts +7 -1
  54. package/lib/components/Footer/footerMenu.module.css +5 -0
  55. package/lib/components/GlobalMenu/AccountButton.tsx +29 -0
  56. package/lib/components/GlobalMenu/AccountMenu.stories.tsx +65 -0
  57. package/lib/components/GlobalMenu/AccountMenu.tsx +73 -0
  58. package/lib/components/GlobalMenu/BackButton.tsx +10 -0
  59. package/lib/components/GlobalMenu/GlobalMenu.stories.tsx +112 -121
  60. package/lib/components/GlobalMenu/GlobalMenu.tsx +41 -89
  61. package/lib/components/GlobalMenu/GlobalMenuBase.tsx +22 -0
  62. package/lib/components/GlobalMenu/LogoutButton.tsx +19 -0
  63. package/lib/components/GlobalMenu/globalMenuBase.module.css +39 -0
  64. package/lib/components/GlobalMenu/index.tsx +1 -1
  65. package/lib/components/GlobalMenu/logoutButton.module.css +9 -0
  66. package/lib/components/Header/{Header.stories.ts → Header.stories.tsx} +79 -20
  67. package/lib/components/Header/Header.tsx +25 -38
  68. package/lib/components/Header/HeaderBase.tsx +7 -3
  69. package/lib/components/Header/header.module.css +10 -42
  70. package/lib/components/Header/headerBase.module.css +43 -0
  71. package/lib/components/Header/headerButton.module.css +1 -0
  72. package/lib/components/Layout/Layout.stories.tsx +77 -38
  73. package/lib/components/Layout/Layout.tsx +5 -3
  74. package/lib/components/Layout/LayoutBase.tsx +3 -2
  75. package/lib/components/Layout/layoutBase.module.css +11 -0
  76. package/lib/components/Layout/layoutBody.module.css +1 -0
  77. package/lib/components/LayoutAction/ActionHeader.tsx +1 -1
  78. package/lib/components/LayoutAction/ActionMenu.tsx +2 -4
  79. package/lib/components/LayoutAction/actionMenu.module.css +3 -0
  80. package/lib/components/List/List.stories.tsx +43 -0
  81. package/lib/components/List/List.tsx +6 -6
  82. package/lib/components/List/ListBase.tsx +6 -6
  83. package/lib/components/List/ListItem.tsx +4 -1
  84. package/lib/components/List/ListItemBase.tsx +20 -4
  85. package/lib/components/List/listBase.module.css +3 -3
  86. package/lib/components/List/listItemBase.module.css +4 -0
  87. package/lib/components/Menu/Menu.stories.ts +46 -46
  88. package/lib/components/Menu/Menu.tsx +3 -102
  89. package/lib/components/Menu/MenuBase.tsx +47 -3
  90. package/lib/components/Menu/MenuItem.tsx +8 -4
  91. package/lib/components/Menu/MenuItemBase.tsx +15 -2
  92. package/lib/components/Menu/MenuItems.stories.ts +438 -0
  93. package/lib/components/Menu/MenuItems.tsx +96 -0
  94. package/lib/components/Menu/MenuOption.tsx +4 -1
  95. package/lib/components/Menu/index.ts +1 -1
  96. package/lib/components/Menu/menu.module.css +2 -3
  97. package/lib/components/Menu/menuBase.module.css +25 -0
  98. package/lib/components/Menu/menuItemBase.module.css +11 -5
  99. package/lib/components/Menu/menuItemLabel.module.css +11 -1
  100. package/lib/components/Menu/menuSearch.module.css +1 -0
  101. package/lib/components/Meta/MetaItemBase.tsx +1 -1
  102. package/lib/components/Meta/MetaItemLabel.tsx +1 -1
  103. package/lib/components/Meta/MetaItemMedia.tsx +1 -1
  104. package/lib/components/Page/PageBase.tsx +14 -0
  105. package/lib/components/Page/PageHeader.tsx +21 -0
  106. package/lib/components/Page/PageHeaderMedia.tsx +25 -0
  107. package/lib/components/Page/SectionBase.tsx +52 -0
  108. package/lib/components/Page/SectionFooter.tsx +15 -0
  109. package/lib/components/Page/SectionHeader.tsx +16 -0
  110. package/lib/components/Page/index.ts +5 -0
  111. package/lib/components/Page/pageHeader.module.css +5 -0
  112. package/lib/components/Page/sectionBase.module.css +82 -0
  113. package/lib/components/Page/sectionFooter.module.css +8 -0
  114. package/lib/components/Page/sectionHeader.module.css +9 -0
  115. package/lib/components/RootProvider/RootProvider.tsx +43 -7
  116. package/lib/components/Searchbar/Autocomplete.stories.tsx +77 -0
  117. package/lib/components/Searchbar/Autocomplete.tsx +44 -0
  118. package/lib/components/Searchbar/AutocompleteBase.tsx +16 -0
  119. package/lib/components/Searchbar/AutocompleteGroup.tsx +17 -0
  120. package/lib/components/Searchbar/AutocompleteItem.tsx +23 -0
  121. package/lib/components/Searchbar/SearchField.tsx +78 -0
  122. package/lib/components/Searchbar/Searchbar.stories.tsx +151 -0
  123. package/lib/components/Searchbar/Searchbar.tsx +18 -0
  124. package/lib/components/Searchbar/SearchbarBase.tsx +23 -0
  125. package/lib/components/Searchbar/autocompleteBase.module.css +17 -0
  126. package/lib/components/Searchbar/autocompleteGroup.module.css +3 -0
  127. package/lib/components/Searchbar/autocompleteItem.module.css +19 -0
  128. package/lib/components/Searchbar/index.ts +1 -0
  129. package/lib/components/Searchbar/searchField.module.css +54 -0
  130. package/lib/components/Searchbar/searchbarBase.module.css +20 -0
  131. package/lib/components/Toolbar/Toolbar.stories.tsx +10 -10
  132. package/lib/components/Toolbar/Toolbar.tsx +28 -10
  133. package/lib/components/Toolbar/ToolbarAdd.tsx +6 -5
  134. package/lib/components/Toolbar/ToolbarBase.tsx +5 -20
  135. package/lib/components/Toolbar/ToolbarButton.tsx +1 -1
  136. package/lib/components/Toolbar/ToolbarFilter.tsx +11 -6
  137. package/lib/components/Toolbar/ToolbarMenu.tsx +8 -7
  138. package/lib/components/Toolbar/ToolbarOptions.stories.ts +5 -5
  139. package/lib/components/Toolbar/ToolbarOptions.tsx +34 -21
  140. package/lib/components/Toolbar/toolbarAdd.module.css +7 -0
  141. package/lib/components/Toolbar/toolbarBase.module.css +19 -0
  142. package/lib/components/Toolbar/toolbarButton.module.css +1 -1
  143. package/lib/components/Toolbar/toolbarFilter.module.css +25 -0
  144. package/lib/components/Toolbar/toolbarMenu.module.css +7 -0
  145. package/lib/components/Typography/Heading.tsx +23 -0
  146. package/lib/components/Typography/Typography.tsx +8 -5
  147. package/lib/components/Typography/heading.module.css +21 -0
  148. package/lib/components/Typography/index.ts +1 -0
  149. package/lib/components/Typography/typography.module.css +8 -0
  150. package/lib/components/index.ts +2 -0
  151. package/lib/hooks/index.ts +3 -0
  152. package/lib/{components/Menu → hooks}/useEscapeKey.ts +2 -2
  153. package/lib/hooks/useMenu.tsx +80 -0
  154. package/lib/index.ts +1 -0
  155. package/lib/stories/Color/MenuItem.stories.tsx +43 -0
  156. package/lib/stories/Color/Swatches.stories.tsx +19 -0
  157. package/lib/stories/Color/Swatches.tsx +42 -0
  158. package/lib/stories/Color/colors.json +62 -0
  159. package/lib/stories/Color/swatches.module.css +14 -0
  160. package/lib/stories/Inbox/BookmarksPage.tsx +52 -0
  161. package/lib/stories/Inbox/DialogPage.tsx +15 -0
  162. package/lib/stories/Inbox/Inbox.stories.tsx +55 -0
  163. package/lib/stories/Inbox/Inbox.tsx +12 -0
  164. package/lib/stories/Inbox/InboxLayout.tsx +50 -0
  165. package/lib/stories/Inbox/InboxPage.tsx +50 -0
  166. package/lib/stories/Inbox/InboxProvider.tsx +136 -0
  167. package/lib/stories/Inbox/InboxSection.tsx +39 -0
  168. package/lib/stories/Inbox/InboxToolbar.tsx +94 -0
  169. package/lib/stories/Inbox/ProfilePage.tsx +35 -0
  170. package/lib/stories/Inbox/SettingsPage.tsx +19 -0
  171. package/lib/stories/Inbox/accounts/accounts.ts +24 -0
  172. package/lib/stories/Inbox/accounts/index.ts +1 -0
  173. package/lib/stories/Inbox/actionMenu.ts +24 -0
  174. package/lib/stories/Inbox/dialogs/brreg-completed.json +35 -0
  175. package/lib/stories/Inbox/dialogs/brreg-draft.json +45 -0
  176. package/lib/stories/Inbox/dialogs/index.ts +10 -0
  177. package/lib/stories/Inbox/dialogs/skatt-2023.json +33 -0
  178. package/lib/stories/Inbox/groupBy.ts +19 -0
  179. package/lib/stories/Inbox/inboxSection.module.css +19 -0
  180. package/lib/stories/Inbox/index.ts +15 -0
  181. package/lib/stories/Inbox/layout/footer.ts +27 -0
  182. package/lib/stories/Inbox/layout/header.ts +11 -0
  183. package/lib/stories/Inbox/layout/index.ts +3 -0
  184. package/lib/stories/Inbox/layout/menu.ts +64 -0
  185. package/package.json +15 -13
  186. package/tsconfig.json +7 -2
  187. package/lib/components/Header/HeaderSearch.stories.ts +0 -20
  188. package/lib/components/Header/HeaderSearch.tsx +0 -44
  189. package/lib/components/Header/headerSearch.module.css +0 -30
  190. package/lib/components/Menu/MenuGroup.tsx +0 -18
  191. package/lib/components/Menu/__menuItem.module.css +0 -130
  192. package/lib/components/Toolbar/toolbar.module.css +0 -43
  193. /package/lib/components/ContextMenu/{contextMenu.module.css → contextMenuBase.module.css} +0 -0
  194. /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 = ({ expanded = false, className, children }: DropdownBaseProps) => {
15
+ export const DropdownBase = ({
16
+ placement = 'left',
17
+ padding = true,
18
+ expanded = false,
19
+ className,
20
+ children,
21
+ }: DropdownBaseProps) => {
12
22
  return (
13
- <div className={cx(styles.dropdown, className)} aria-expanded={expanded}>
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
  );
@@ -1,8 +1,11 @@
1
1
  .backdrop {
2
+ z-index: 1;
2
3
  background-color: rgba(17, 29, 70, 0.25);
3
4
  position: fixed;
4
5
  top: 0;
5
6
  right: 0;
6
7
  bottom: 0;
7
8
  left: 0;
9
+ width: 100%;
10
+ height: 100%;
8
11
  }
@@ -3,6 +3,15 @@
3
3
  }
4
4
 
5
5
  .drawer[aria-expanded="true"] {
6
+ background-color: var(--theme-background-default);
6
7
  display: block;
7
8
  width: 100%;
8
9
  }
10
+
11
+ .drawer[data-placement="bottom"] {
12
+ position: fixed;
13
+ top: 5.5rem;
14
+ bottom: 0;
15
+ left: 0;
16
+ right: 0;
17
+ }
@@ -0,0 +1,5 @@
1
+ .body {
2
+ width: 100%;
3
+ padding: 0 .5em;
4
+ overflow-y: scroll;
5
+ }
@@ -0,0 +1,6 @@
1
+ .button {
2
+ height: 3.5rem; /* lg 56 */
3
+ border-radius: 1.75rem;
4
+ padding: 0 1rem;
5
+ margin: 1rem auto;
6
+ }
@@ -0,0 +1,13 @@
1
+ .footer {
2
+ position: fixed;
3
+ bottom: 0;
4
+ left: 0;
5
+ right: 0;
6
+ display: flex;
7
+ flex-direction: column;
8
+ align-items: center;
9
+ }
10
+
11
+ .footer > * {
12
+ margin: 1rem auto;
13
+ }
@@ -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: 2px;
17
- box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.15), 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.1);
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';
@@ -5,6 +5,11 @@
5
5
  }
6
6
 
7
7
  .list {
8
+ list-style: none;
9
+ padding: 0;
10
+ margin: 0;
11
+ text-indent: 0;
12
+
8
13
  display: flex;
9
14
  flex-direction: column;
10
15
  row-gap: 1rem;
@@ -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
+ };