@altinn/altinn-components 0.4.0 → 0.5.0

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/main.ts +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/biome.jsonc +1 -1
  4. package/lib/components/Attachment/AttachmentLink.stories.ts +1 -1
  5. package/lib/components/Attachment/AttachmentList.stories.ts +1 -1
  6. package/lib/components/Button/Button.tsx +13 -10
  7. package/lib/components/Button/ButtonBase.tsx +1 -1
  8. package/lib/components/Button/ButtonIcon.tsx +16 -0
  9. package/lib/components/Button/ButtonLabel.tsx +16 -0
  10. package/lib/components/Button/Buttons.stories.tsx +64 -0
  11. package/lib/components/Button/ComboButton.tsx +9 -7
  12. package/lib/components/Button/IconButton.stories.tsx +47 -0
  13. package/lib/components/Button/IconButton.tsx +15 -5
  14. package/lib/components/Button/button.module.css +5 -46
  15. package/lib/components/Button/buttonBase.module.css +55 -23
  16. package/lib/components/Button/buttonIcon.module.css +17 -0
  17. package/lib/components/Button/buttonLabel.module.css +17 -0
  18. package/lib/components/Button/comboButton.module.css +15 -65
  19. package/lib/components/Button/iconButton.module.css +21 -4
  20. package/lib/components/Button/index.ts +2 -0
  21. package/lib/components/ContextMenu/ContextMenu.stories.ts +49 -0
  22. package/lib/components/ContextMenu/ContextMenu.tsx +12 -20
  23. package/lib/components/ContextMenu/ContextMenuBase.tsx +33 -0
  24. package/lib/components/Dialog/Dialog.tsx +2 -0
  25. package/lib/components/Dialog/DialogGroup.tsx +24 -0
  26. package/lib/components/Dialog/DialogList.stories.ts +14 -10
  27. package/lib/components/Dialog/DialogList.tsx +26 -11
  28. package/lib/components/Dialog/DialogListItem.tsx +12 -3
  29. package/lib/components/Dialog/DialogListItemBase.tsx +4 -2
  30. package/lib/components/Dialog/DialogNav.stories.ts +5 -5
  31. package/lib/components/Dialog/DialogNav.tsx +3 -7
  32. package/lib/components/Dialog/DialogSelect.tsx +1 -1
  33. package/lib/components/Dialog/dialogGroup.module.css +35 -0
  34. package/lib/components/Dialog/dialogNav.module.css +12 -0
  35. package/lib/components/Dropdown/Backdrop.tsx +4 -3
  36. package/lib/components/Dropdown/DrawerBase.tsx +5 -2
  37. package/lib/components/Dropdown/DrawerBody.tsx +12 -0
  38. package/lib/components/Dropdown/DrawerButton.tsx +17 -0
  39. package/lib/components/Dropdown/DrawerFooter.tsx +12 -0
  40. package/lib/components/Dropdown/DrawerHeader.tsx +19 -0
  41. package/lib/components/Dropdown/DrawerOrDropdown.tsx +29 -0
  42. package/lib/components/Dropdown/DropdownBase.tsx +5 -2
  43. package/lib/components/Dropdown/backdrop.module.css +3 -0
  44. package/lib/components/Dropdown/drawerBase.module.css +9 -0
  45. package/lib/components/Dropdown/drawerBody.module.css +5 -0
  46. package/lib/components/Dropdown/drawerButton.module.css +6 -0
  47. package/lib/components/Dropdown/drawerFooter.module.css +13 -0
  48. package/lib/components/Dropdown/drawerHeader.module.css +17 -0
  49. package/lib/components/Dropdown/drawerOrDropdown.module.css +19 -0
  50. package/lib/components/Dropdown/dropdownBase.module.css +15 -3
  51. package/lib/components/Dropdown/index.ts +7 -1
  52. package/lib/components/Footer/footerMenu.module.css +5 -0
  53. package/lib/components/GlobalMenu/GlobalMenu.stories.tsx +9 -9
  54. package/lib/components/GlobalMenu/GlobalMenu.tsx +5 -5
  55. package/lib/components/Header/{Header.stories.ts → Header.stories.tsx} +79 -20
  56. package/lib/components/Header/Header.tsx +24 -42
  57. package/lib/components/Header/HeaderBase.tsx +7 -3
  58. package/lib/components/Header/header.module.css +10 -42
  59. package/lib/components/Header/headerBase.module.css +43 -0
  60. package/lib/components/Header/headerButton.module.css +1 -0
  61. package/lib/components/History/HistoryAttachments.tsx +22 -0
  62. package/lib/components/History/HistoryItem.stories.ts +27 -18
  63. package/lib/components/History/HistoryItem.tsx +7 -15
  64. package/lib/components/History/HistoryList.stories.ts +34 -22
  65. package/lib/components/Layout/Layout.stories.tsx +77 -38
  66. package/lib/components/Layout/Layout.tsx +5 -3
  67. package/lib/components/Layout/LayoutBase.tsx +4 -3
  68. package/lib/components/Layout/index.tsx +1 -0
  69. package/lib/components/Layout/layoutBase.module.css +9 -10
  70. package/lib/components/Layout/layoutBody.module.css +1 -0
  71. package/lib/components/Layout/layoutContent.module.css +6 -1
  72. package/lib/components/Layout/layoutSidebar.module.css +1 -0
  73. package/lib/components/LayoutAction/ActionFooter.stories.tsx +1 -1
  74. package/lib/components/LayoutAction/ActionHeader.tsx +2 -2
  75. package/lib/components/LayoutAction/ActionMenu.stories.tsx +1 -0
  76. package/lib/components/LayoutAction/ActionMenu.tsx +4 -3
  77. package/lib/components/LayoutAction/actionMenu.module.css +11 -6
  78. package/lib/components/List/List.stories.tsx +43 -0
  79. package/lib/components/List/List.tsx +6 -6
  80. package/lib/components/List/ListBase.tsx +6 -6
  81. package/lib/components/List/ListItem.tsx +4 -1
  82. package/lib/components/List/ListItemBase.tsx +20 -4
  83. package/lib/components/List/listBase.module.css +3 -3
  84. package/lib/components/List/listItemBase.module.css +4 -0
  85. package/lib/components/Menu/Menu.stories.ts +46 -46
  86. package/lib/components/Menu/Menu.tsx +3 -102
  87. package/lib/components/Menu/MenuBase.tsx +47 -3
  88. package/lib/components/Menu/{MenuItem.stories.ts → MenuItem.stories.tsx} +32 -0
  89. package/lib/components/Menu/MenuItem.tsx +6 -4
  90. package/lib/components/Menu/MenuItemBase.tsx +8 -1
  91. package/lib/components/Menu/MenuItems.stories.ts +438 -0
  92. package/lib/components/Menu/MenuItems.tsx +96 -0
  93. package/lib/components/Menu/MenuOption.tsx +4 -1
  94. package/lib/components/Menu/{MenuGroup.tsx → __MenuGroup.tsx} +1 -1
  95. package/lib/components/Menu/{menuItem.module.css → __menuItem.module.css} +0 -6
  96. package/lib/components/Menu/index.ts +1 -1
  97. package/lib/components/Menu/menu.module.css +2 -3
  98. package/lib/components/Menu/menuBase.module.css +25 -0
  99. package/lib/components/Menu/menuItemBase.module.css +12 -17
  100. package/lib/components/Menu/menuItemMedia.module.css +2 -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/css/global.css +1 -0
  152. package/lib/css/theme-global-dark.css +19 -0
  153. package/lib/hooks/index.ts +3 -0
  154. package/lib/{components/Menu → hooks}/useEscapeKey.ts +2 -2
  155. package/lib/hooks/useMenu.tsx +80 -0
  156. package/lib/index.ts +1 -0
  157. package/lib/stories/Color/MenuItem.stories.tsx +43 -0
  158. package/lib/stories/Color/Swatches.stories.tsx +19 -0
  159. package/lib/stories/Color/Swatches.tsx +42 -0
  160. package/lib/stories/Color/colors.json +62 -0
  161. package/lib/stories/Color/swatches.module.css +14 -0
  162. package/lib/stories/Inbox/BookmarksPage.tsx +52 -0
  163. package/lib/stories/Inbox/DialogPage.tsx +15 -0
  164. package/lib/stories/Inbox/Inbox.stories.tsx +55 -0
  165. package/lib/stories/Inbox/Inbox.tsx +12 -0
  166. package/lib/stories/Inbox/InboxLayout.tsx +50 -0
  167. package/lib/stories/Inbox/InboxPage.tsx +50 -0
  168. package/lib/stories/Inbox/InboxProvider.tsx +136 -0
  169. package/lib/stories/Inbox/InboxSection.tsx +39 -0
  170. package/lib/stories/Inbox/InboxToolbar.tsx +94 -0
  171. package/lib/stories/Inbox/ProfilePage.tsx +35 -0
  172. package/lib/stories/Inbox/SettingsPage.tsx +19 -0
  173. package/lib/stories/Inbox/accounts/accounts.ts +24 -0
  174. package/lib/stories/Inbox/accounts/index.ts +1 -0
  175. package/lib/stories/Inbox/actionMenu.ts +24 -0
  176. package/lib/stories/Inbox/dialogs/brreg-completed.json +35 -0
  177. package/lib/stories/Inbox/dialogs/brreg-draft.json +45 -0
  178. package/lib/stories/Inbox/dialogs/index.ts +10 -0
  179. package/lib/stories/Inbox/dialogs/skatt-2023.json +33 -0
  180. package/lib/stories/Inbox/groupBy.ts +19 -0
  181. package/lib/stories/Inbox/inboxSection.module.css +19 -0
  182. package/lib/stories/Inbox/index.ts +15 -0
  183. package/lib/stories/Inbox/layout/footer.ts +27 -0
  184. package/lib/stories/Inbox/layout/header.ts +11 -0
  185. package/lib/stories/Inbox/layout/index.ts +3 -0
  186. package/lib/stories/Inbox/layout/menu.ts +64 -0
  187. package/package.json +1 -1
  188. package/tsconfig.json +7 -2
  189. package/lib/components/Header/HeaderSearch.stories.ts +0 -20
  190. package/lib/components/Header/HeaderSearch.tsx +0 -44
  191. package/lib/components/Header/headerSearch.module.css +0 -30
  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
@@ -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,26 @@
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
+
12
19
  .dropdown {
20
+ min-width: 14rem;
13
21
  margin-top: 0.5rem;
14
22
  padding: 0 0.5rem;
15
23
  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);
24
+ border-radius: 0.375rem;
25
+ box-shadow: var(--ds-shadow-md);
26
+ }
27
+
28
+ .drawer .button {
29
+ border-radius: 50%;
18
30
  }
@@ -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;
@@ -16,14 +16,14 @@ const meta = {
16
16
  items: [
17
17
  {
18
18
  id: 'inbox',
19
- group: 'apps',
19
+ groupId: 'apps',
20
20
  size: 'lg',
21
21
  icon: 'inbox',
22
22
  label: 'Innboks',
23
23
  },
24
24
  {
25
25
  id: 'settings',
26
- group: 'apps',
26
+ groupId: 'apps',
27
27
  size: 'lg',
28
28
  icon: 'cog',
29
29
  label: 'Settings',
@@ -144,43 +144,43 @@ export const Accounts: Story = {
144
144
  },
145
145
  accounts: [
146
146
  {
147
- group: 'primary',
147
+ groupId: 'primary',
148
148
  type: 'person',
149
149
  name: 'Aurora Mikalsen',
150
150
  selected: true,
151
151
  },
152
152
  {
153
- group: 'favourites',
153
+ groupId: 'favourites',
154
154
  type: 'person',
155
155
  name: 'Rakel Engelsvik',
156
156
  selected: false,
157
157
  },
158
158
  {
159
- group: 'favourites',
159
+ groupId: 'favourites',
160
160
  type: 'company',
161
161
  name: 'Auroras keeperskole',
162
162
  selected: false,
163
163
  },
164
164
  {
165
- group: 'secondary',
165
+ groupId: 'secondary',
166
166
  type: 'company',
167
167
  name: 'Keeperhansker AS',
168
168
  selected: false,
169
169
  },
170
170
  {
171
- group: 'secondary',
171
+ groupId: 'secondary',
172
172
  type: 'company',
173
173
  name: 'Stadion drift AS',
174
174
  selected: false,
175
175
  },
176
176
  {
177
- group: 'secondary',
177
+ groupId: 'secondary',
178
178
  type: 'company',
179
179
  name: 'Sportsklubben Brann',
180
180
  selected: false,
181
181
  },
182
182
  {
183
- group: 'secondary',
183
+ groupId: 'secondary',
184
184
  type: 'company',
185
185
  name: 'Landslaget',
186
186
  selected: false,
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { type MouseEventHandler, useState } from 'react';
3
3
  import type { AvatarType } from '../Avatar';
4
- import { Menu, type MenuGroups, MenuItem, type MenuItemProps, type MenuSearchProps } from '../Menu';
4
+ import { Menu, MenuItem, type MenuItemGroups, type MenuItemProps, type MenuSearchProps } from '../Menu';
5
5
 
6
6
  export type Account = {
7
7
  type: AvatarType;
@@ -22,9 +22,9 @@ export interface GlobalMenuProps {
22
22
  expanded: boolean;
23
23
  onToggle: MouseEventHandler;
24
24
  items: MenuItemProps[];
25
- groups?: MenuGroups;
25
+ groups?: MenuItemGroups;
26
26
  accounts?: Account[];
27
- accountGroups?: MenuGroups;
27
+ accountGroups?: MenuItemGroups;
28
28
  accountSearch?: AccountSearch;
29
29
  menuLabel?: string;
30
30
  backLabel?: string;
@@ -76,7 +76,7 @@ export const GlobalMenu = ({
76
76
  .map((item) => {
77
77
  return {
78
78
  ...item,
79
- group: 'search',
79
+ groupId: 'search',
80
80
  };
81
81
  })
82
82
  : accountMenu;
@@ -106,7 +106,7 @@ export const GlobalMenu = ({
106
106
  };
107
107
 
108
108
  const accountSwitcher: MenuItemProps[] = [
109
- ...(filteredAccountMenu.length > 0 ? filteredAccountMenu : [{ id: 'search', group: 'search', hidden: true }]),
109
+ ...(filteredAccountMenu.length > 0 ? filteredAccountMenu : [{ id: 'search', groupId: 'search', hidden: true }]),
110
110
  ];
111
111
 
112
112
  if (selectAccount) {
@@ -1,11 +1,14 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
+ import { useState } from 'react';
2
3
  import { Header } from './Header';
3
4
 
4
5
  const meta = {
5
6
  title: 'Header/Header',
6
7
  component: Header,
7
8
  tags: ['autodocs'],
8
- parameters: {},
9
+ parameters: {
10
+ layout: 'fullscreen',
11
+ },
9
12
  args: {
10
13
  expanded: true,
11
14
  search: {
@@ -22,43 +25,43 @@ const meta = {
22
25
  },
23
26
  accounts: [
24
27
  {
25
- group: 'primary',
28
+ groupId: 'primary',
26
29
  type: 'person',
27
30
  name: 'Aurora Mikalsen',
28
31
  selected: true,
29
32
  },
30
33
  {
31
- group: 'favourites',
34
+ groupId: 'favourites',
32
35
  type: 'person',
33
36
  name: 'Rakel Engelsvik',
34
37
  selected: false,
35
38
  },
36
39
  {
37
- group: 'favourites',
40
+ groupId: 'favourites',
38
41
  type: 'company',
39
42
  name: 'Auroras keeperskole',
40
43
  selected: false,
41
44
  },
42
45
  {
43
- group: 'secondary',
46
+ groupId: 'secondary',
44
47
  type: 'company',
45
48
  name: 'Keeperhansker AS',
46
49
  selected: false,
47
50
  },
48
51
  {
49
- group: 'secondary',
52
+ groupId: 'secondary',
50
53
  type: 'company',
51
54
  name: 'Stadion drift AS',
52
55
  selected: false,
53
56
  },
54
57
  {
55
- group: 'secondary',
58
+ groupId: 'secondary',
56
59
  type: 'company',
57
60
  name: 'Sportsklubben Brann',
58
61
  selected: false,
59
62
  },
60
63
  {
61
- group: 'secondary',
64
+ groupId: 'secondary',
62
65
  type: 'company',
63
66
  name: 'Landslaget',
64
67
  selected: false,
@@ -93,21 +96,77 @@ type Story = StoryObj<typeof meta>;
93
96
 
94
97
  export const Default: Story = {};
95
98
 
96
- export const Company: Story = {
97
- args: {
98
- menu: {
99
- ...meta.args?.menu,
100
- accounts: [
99
+ export const ControlledState = (args) => {
100
+ const [q, setQ] = useState<string>('');
101
+ const onChange = (event) => {
102
+ setQ(event.target.value);
103
+ };
104
+
105
+ const scopes = [
106
+ {
107
+ groupId: '1',
108
+ id: 'inbox',
109
+ href: '#',
110
+ label: q
111
+ ? () => {
112
+ return (
113
+ <span>
114
+ <mark>{q}</mark> i innboksen
115
+ </span>
116
+ );
117
+ }
118
+ : 'Alt i innboksen',
119
+ },
120
+ {
121
+ groupId: '1',
122
+ id: 'global',
123
+ href: '#',
124
+ label: q
125
+ ? () => {
126
+ return (
127
+ <span>
128
+ <mark>{q}</mark> i hele Altinn
129
+ </span>
130
+ );
131
+ }
132
+ : 'Alt i hele Altinn',
133
+ },
134
+ ];
135
+
136
+ const suggestions = q
137
+ ? [
101
138
  {
102
- type: 'company',
103
- name: 'Bergen bar',
104
- selected: true,
139
+ groupId: '2',
140
+ href: 'http://www.altinn.no',
141
+ label: 'Skattemelding 2024',
105
142
  },
106
143
  {
107
- type: 'person',
108
- name: 'Aurora Mikalsen',
144
+ groupId: '2',
145
+ href: 'http://www.altinn.no',
146
+ label: 'Skattemelding 2025',
109
147
  },
110
- ],
148
+ ].filter((item) => item.label.toLowerCase().includes((q ?? '').toLowerCase()))
149
+ : [];
150
+
151
+ const autocomplete = {
152
+ groups: {
153
+ 2: {
154
+ title: `${suggestions.length} treff i innboksen`,
155
+ },
111
156
  },
112
- },
157
+ items: [...scopes, ...suggestions],
158
+ };
159
+
160
+ return (
161
+ <Header
162
+ {...args}
163
+ search={{
164
+ ...args.search,
165
+ value: q,
166
+ onChange,
167
+ onClear: () => setQ(''),
168
+ autocomplete,
169
+ }}
170
+ />
171
+ );
113
172
  };
@@ -1,88 +1,70 @@
1
1
  'use client';
2
- import cx from 'classnames';
3
- import { useState } from 'react';
4
- import { Backdrop, DrawerBase, DropdownBase } from '../Dropdown';
2
+ import { useEscapeKey } from '../../hooks';
3
+ import { DrawerBase, DropdownBase } from '../Dropdown';
5
4
  import { GlobalMenu, type GlobalMenuProps } from '../GlobalMenu';
5
+ import { useRootContext } from '../RootProvider';
6
+ import { Searchbar, type SearchbarProps } from '../Searchbar';
6
7
  import { HeaderBase } from './HeaderBase';
7
8
  import { HeaderButton } from './HeaderButton';
8
9
  import { HeaderLogo } from './HeaderLogo';
9
10
  import { HeaderMenu } from './HeaderMenu';
10
- import { HeaderSearch, type HeaderSearchProps } from './HeaderSearch';
11
11
  import styles from './header.module.css';
12
12
 
13
- export type HeaderExpandedType = 'search' | 'menu' | null;
14
-
15
- export interface HeaderAccountProps {
16
- type?: string;
17
- name?: string;
18
- }
19
-
20
13
  export interface HeaderProps {
21
14
  menu: GlobalMenuProps;
22
- search?: HeaderSearchProps;
15
+ search?: SearchbarProps;
23
16
  }
24
17
 
25
18
  export const Header = ({ search, menu }: HeaderProps) => {
26
- const [expandedType, setExpandedType] = useState<HeaderExpandedType | null>(null);
27
- const selectedAccount = menu?.accounts?.find((account) => account.selected);
19
+ const { currentId, toggleId, openId, closeAll } = useRootContext();
20
+ const selectedAccount = menu.accounts?.find((account) => account.selected);
28
21
  const selectedAvatar = selectedAccount && {
29
22
  type: selectedAccount.type,
30
23
  name: selectedAccount.name,
31
24
  };
32
25
 
33
- const onToggle = (type: HeaderExpandedType) => {
34
- if (expandedType === type) {
35
- setExpandedType(null);
36
- } else {
37
- setExpandedType(type);
38
- }
39
- };
26
+ useEscapeKey(closeAll);
40
27
 
41
28
  const onSearchFocus = () => {
42
- setExpandedType('search');
29
+ openId('search');
43
30
  };
44
31
 
45
- const onSearchBlur = () => {
46
- setExpandedType(null);
32
+ const onSearchClose = () => {
33
+ toggleId('search');
34
+ };
35
+
36
+ const onToggleMenu = () => {
37
+ toggleId('menu');
47
38
  };
48
39
 
49
40
  return (
50
- <HeaderBase
51
- className={cx(
52
- styles.header,
53
- expandedType === 'menu' && styles.menuExpanded,
54
- expandedType === 'search' && styles.searchExpanded,
55
- )}
56
- expanded={(expandedType && true) || false}
57
- >
58
- <Backdrop className={styles.backdrop} />
41
+ <HeaderBase currentId={currentId} open={currentId === 'search' || currentId === 'menu'} onClose={closeAll}>
59
42
  <HeaderLogo className={styles.logo} />
60
43
  <HeaderMenu className={styles.menu}>
61
44
  <HeaderButton
62
45
  avatar={selectedAvatar}
63
- onClick={() => onToggle('menu')}
64
- expanded={expandedType === 'menu'}
46
+ onClick={onToggleMenu}
47
+ expanded={currentId === 'menu'}
65
48
  label={menu?.menuLabel}
66
49
  />
67
50
  {menu && (
68
- <DropdownBase expanded={expandedType === 'menu'} className={styles.dropdown}>
51
+ <DropdownBase placement="right" expanded={currentId === 'menu'} className={styles.dropdown}>
69
52
  <GlobalMenu {...menu} variant="dropdown" />
70
53
  </DropdownBase>
71
54
  )}
72
55
  </HeaderMenu>
73
-
74
56
  {search && (
75
- <HeaderSearch
57
+ <Searchbar
76
58
  {...search}
77
59
  className={styles.search}
78
- expanded={expandedType === 'search'}
79
- onBlur={onSearchBlur}
60
+ expanded={currentId === 'search'}
61
+ onClose={onSearchClose}
80
62
  onFocus={onSearchFocus}
81
63
  />
82
64
  )}
83
65
  {menu && (
84
- <DrawerBase expanded={expandedType === 'menu'} className={styles.drawer}>
85
- <GlobalMenu {...menu} variant="drawer" expanded={expandedType === 'menu'} />
66
+ <DrawerBase expanded={currentId === 'menu'} className={styles.drawer}>
67
+ <GlobalMenu {...menu} variant="drawer" expanded={currentId === 'menu'} />
86
68
  </DrawerBase>
87
69
  )}
88
70
  </HeaderBase>
@@ -1,16 +1,20 @@
1
1
  import cx from 'classnames';
2
2
  import type { ReactNode } from 'react';
3
+ import { Backdrop } from '../';
3
4
  import styles from './headerBase.module.css';
4
5
 
5
6
  export interface HeaderBaseProps {
6
- expanded?: boolean;
7
+ currentId?: string;
7
8
  className?: string;
8
9
  children?: ReactNode;
10
+ open?: boolean;
11
+ onClose?: () => void;
9
12
  }
10
13
 
11
- export const HeaderBase = ({ expanded, className, children }: HeaderBaseProps) => {
14
+ export const HeaderBase = ({ currentId, className, children, open, onClose }: HeaderBaseProps) => {
12
15
  return (
13
- <header className={cx(styles.header, className)} aria-expanded={expanded}>
16
+ <header className={cx(styles.header, className)} data-current-id={currentId}>
17
+ {open && <Backdrop className={styles.backdrop} onClick={onClose} />}
14
18
  {children}
15
19
  </header>
16
20
  );
@@ -1,35 +1,26 @@
1
- .backdrop {
2
- display: none;
3
- z-index: 2;
4
- }
5
-
6
- .header .drawer[aria-expanded="true"] {
1
+ .drawer[aria-expanded="true"] {
7
2
  display: block;
8
3
  }
9
4
 
10
- .header .dropdown[aria-expanded="true"] {
5
+ .dropdown[aria-expanded="true"] {
11
6
  width: 320px;
12
7
  display: none;
13
8
  }
14
9
 
15
- /* menu */
16
-
17
- .header.menuExpanded {
18
- background-color: white;
10
+ @media (min-width: 1024px) {
11
+ .dropdown[aria-expanded="true"] {
12
+ display: block;
13
+ }
19
14
  }
20
15
 
21
16
  @media (min-width: 1024px) {
22
- .header.menuExpanded {
23
- background-color: transparent;
17
+ .drawer[aria-expanded="true"] {
18
+ display: none;
24
19
  }
25
20
 
26
- .header.menuExpanded .backdrop {
21
+ .dropdown[aria-expanded="true"] {
27
22
  display: block;
28
23
  }
29
-
30
- .header.menuExpanded .menu {
31
- z-index: 2;
32
- }
33
24
  }
34
25
 
35
26
  /* search */
@@ -38,31 +29,7 @@
38
29
  width: 100%;
39
30
  }
40
31
 
41
- .header.searchExpanded {
42
- margin-top: -72px;
43
- }
44
-
45
- .header.searchExpanded .search {
46
- z-index: 2;
47
- }
48
-
49
- .header.searchExpanded .backdrop {
50
- display: block;
51
- }
52
-
53
32
  @media (min-width: 1024px) {
54
- .header.searchExpanded {
55
- margin-top: 0;
56
- }
57
-
58
- .header .drawer[aria-expanded="true"] {
59
- display: none;
60
- }
61
-
62
- .header .dropdown[aria-expanded="true"] {
63
- display: block;
64
- }
65
-
66
33
  .search {
67
34
  position: absolute;
68
35
  left: 0;
@@ -72,6 +39,7 @@
72
39
  }
73
40
 
74
41
  .search[aria-expanded="true"] {
42
+ z-index: 2;
75
43
  max-width: 640px;
76
44
  }
77
45
  }
@@ -1,4 +1,5 @@
1
1
  .header {
2
+ z-index: 1;
2
3
  display: flex;
3
4
  align-items: center;
4
5
  justify-content: space-between;
@@ -6,3 +7,45 @@
6
7
  gap: 1rem;
7
8
  padding: 1rem;
8
9
  }
10
+
11
+ .backdrop {
12
+ display: none;
13
+ }
14
+
15
+ /* menu */
16
+
17
+ .header[data-current-id="menu"] {
18
+ background-color: white;
19
+ }
20
+
21
+ @media (min-width: 1024px) {
22
+ .header[data-current-id="menu"] {
23
+ background-color: transparent;
24
+ }
25
+
26
+ .header[data-current-id="menu"] .backdrop {
27
+ display: block;
28
+ }
29
+ }
30
+
31
+ /* search */
32
+
33
+ .header {
34
+ transition-property: all;
35
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
36
+ transition-duration: .15s;
37
+ }
38
+
39
+ .header[data-current-id="search"] {
40
+ margin-top: -72px;
41
+ }
42
+
43
+ .header[data-current-id="search"] .backdrop {
44
+ display: block;
45
+ }
46
+
47
+ @media (min-width: 1024px) {
48
+ .header[data-current-id="search"] {
49
+ margin-top: 0;
50
+ }
51
+ }