@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.
- package/.storybook/main.ts +1 -1
- 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 +16 -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.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 -3
- package/lib/components/Dialog/DialogListItemBase.tsx +4 -2
- package/lib/components/Dialog/DialogNav.stories.ts +5 -5
- package/lib/components/Dialog/DialogNav.tsx +3 -7
- package/lib/components/Dialog/DialogSelect.tsx +1 -1
- package/lib/components/Dialog/dialogGroup.module.css +35 -0
- package/lib/components/Dialog/dialogNav.module.css +12 -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 +5 -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 +15 -3
- package/lib/components/Dropdown/index.ts +7 -1
- package/lib/components/Footer/footerMenu.module.css +5 -0
- package/lib/components/GlobalMenu/GlobalMenu.stories.tsx +9 -9
- package/lib/components/GlobalMenu/GlobalMenu.tsx +5 -5
- package/lib/components/Header/{Header.stories.ts → Header.stories.tsx} +79 -20
- package/lib/components/Header/Header.tsx +24 -42
- 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/History/HistoryAttachments.tsx +22 -0
- package/lib/components/History/HistoryItem.stories.ts +27 -18
- package/lib/components/History/HistoryItem.tsx +7 -15
- package/lib/components/History/HistoryList.stories.ts +34 -22
- package/lib/components/Layout/Layout.stories.tsx +77 -38
- package/lib/components/Layout/Layout.tsx +5 -3
- package/lib/components/Layout/LayoutBase.tsx +4 -3
- package/lib/components/Layout/index.tsx +1 -0
- package/lib/components/Layout/layoutBase.module.css +9 -10
- package/lib/components/Layout/layoutBody.module.css +1 -0
- package/lib/components/Layout/layoutContent.module.css +6 -1
- package/lib/components/Layout/layoutSidebar.module.css +1 -0
- package/lib/components/LayoutAction/ActionFooter.stories.tsx +1 -1
- package/lib/components/LayoutAction/ActionHeader.tsx +2 -2
- package/lib/components/LayoutAction/ActionMenu.stories.tsx +1 -0
- package/lib/components/LayoutAction/ActionMenu.tsx +4 -3
- package/lib/components/LayoutAction/actionMenu.module.css +11 -6
- 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.stories.ts → MenuItem.stories.tsx} +32 -0
- package/lib/components/Menu/MenuItem.tsx +6 -4
- package/lib/components/Menu/MenuItemBase.tsx +8 -1
- 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/{MenuGroup.tsx → __MenuGroup.tsx} +1 -1
- package/lib/components/Menu/{menuItem.module.css → __menuItem.module.css} +0 -6
- 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 +12 -17
- package/lib/components/Menu/menuItemMedia.module.css +2 -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/css/global.css +1 -0
- package/lib/css/theme-global-dark.css +19 -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 +1 -1
- 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/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
|
+
.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:
|
|
17
|
-
box-shadow:
|
|
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';
|
|
@@ -16,14 +16,14 @@ const meta = {
|
|
|
16
16
|
items: [
|
|
17
17
|
{
|
|
18
18
|
id: 'inbox',
|
|
19
|
-
|
|
19
|
+
groupId: 'apps',
|
|
20
20
|
size: 'lg',
|
|
21
21
|
icon: 'inbox',
|
|
22
22
|
label: 'Innboks',
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
id: 'settings',
|
|
26
|
-
|
|
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
|
-
|
|
147
|
+
groupId: 'primary',
|
|
148
148
|
type: 'person',
|
|
149
149
|
name: 'Aurora Mikalsen',
|
|
150
150
|
selected: true,
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
|
-
|
|
153
|
+
groupId: 'favourites',
|
|
154
154
|
type: 'person',
|
|
155
155
|
name: 'Rakel Engelsvik',
|
|
156
156
|
selected: false,
|
|
157
157
|
},
|
|
158
158
|
{
|
|
159
|
-
|
|
159
|
+
groupId: 'favourites',
|
|
160
160
|
type: 'company',
|
|
161
161
|
name: 'Auroras keeperskole',
|
|
162
162
|
selected: false,
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
|
-
|
|
165
|
+
groupId: 'secondary',
|
|
166
166
|
type: 'company',
|
|
167
167
|
name: 'Keeperhansker AS',
|
|
168
168
|
selected: false,
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
|
-
|
|
171
|
+
groupId: 'secondary',
|
|
172
172
|
type: 'company',
|
|
173
173
|
name: 'Stadion drift AS',
|
|
174
174
|
selected: false,
|
|
175
175
|
},
|
|
176
176
|
{
|
|
177
|
-
|
|
177
|
+
groupId: 'secondary',
|
|
178
178
|
type: 'company',
|
|
179
179
|
name: 'Sportsklubben Brann',
|
|
180
180
|
selected: false,
|
|
181
181
|
},
|
|
182
182
|
{
|
|
183
|
-
|
|
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
|
|
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?:
|
|
25
|
+
groups?: MenuItemGroups;
|
|
26
26
|
accounts?: Account[];
|
|
27
|
-
accountGroups?:
|
|
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
|
-
|
|
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',
|
|
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
|
-
|
|
28
|
+
groupId: 'primary',
|
|
26
29
|
type: 'person',
|
|
27
30
|
name: 'Aurora Mikalsen',
|
|
28
31
|
selected: true,
|
|
29
32
|
},
|
|
30
33
|
{
|
|
31
|
-
|
|
34
|
+
groupId: 'favourites',
|
|
32
35
|
type: 'person',
|
|
33
36
|
name: 'Rakel Engelsvik',
|
|
34
37
|
selected: false,
|
|
35
38
|
},
|
|
36
39
|
{
|
|
37
|
-
|
|
40
|
+
groupId: 'favourites',
|
|
38
41
|
type: 'company',
|
|
39
42
|
name: 'Auroras keeperskole',
|
|
40
43
|
selected: false,
|
|
41
44
|
},
|
|
42
45
|
{
|
|
43
|
-
|
|
46
|
+
groupId: 'secondary',
|
|
44
47
|
type: 'company',
|
|
45
48
|
name: 'Keeperhansker AS',
|
|
46
49
|
selected: false,
|
|
47
50
|
},
|
|
48
51
|
{
|
|
49
|
-
|
|
52
|
+
groupId: 'secondary',
|
|
50
53
|
type: 'company',
|
|
51
54
|
name: 'Stadion drift AS',
|
|
52
55
|
selected: false,
|
|
53
56
|
},
|
|
54
57
|
{
|
|
55
|
-
|
|
58
|
+
groupId: 'secondary',
|
|
56
59
|
type: 'company',
|
|
57
60
|
name: 'Sportsklubben Brann',
|
|
58
61
|
selected: false,
|
|
59
62
|
},
|
|
60
63
|
{
|
|
61
|
-
|
|
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
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
139
|
+
groupId: '2',
|
|
140
|
+
href: 'http://www.altinn.no',
|
|
141
|
+
label: 'Skattemelding 2024',
|
|
105
142
|
},
|
|
106
143
|
{
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
3
|
-
import {
|
|
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?:
|
|
15
|
+
search?: SearchbarProps;
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
export const Header = ({ search, menu }: HeaderProps) => {
|
|
26
|
-
const
|
|
27
|
-
const selectedAccount = menu
|
|
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
|
-
|
|
34
|
-
if (expandedType === type) {
|
|
35
|
-
setExpandedType(null);
|
|
36
|
-
} else {
|
|
37
|
-
setExpandedType(type);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
26
|
+
useEscapeKey(closeAll);
|
|
40
27
|
|
|
41
28
|
const onSearchFocus = () => {
|
|
42
|
-
|
|
29
|
+
openId('search');
|
|
43
30
|
};
|
|
44
31
|
|
|
45
|
-
const
|
|
46
|
-
|
|
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={
|
|
64
|
-
expanded={
|
|
46
|
+
onClick={onToggleMenu}
|
|
47
|
+
expanded={currentId === 'menu'}
|
|
65
48
|
label={menu?.menuLabel}
|
|
66
49
|
/>
|
|
67
50
|
{menu && (
|
|
68
|
-
<DropdownBase expanded={
|
|
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
|
-
<
|
|
57
|
+
<Searchbar
|
|
76
58
|
{...search}
|
|
77
59
|
className={styles.search}
|
|
78
|
-
expanded={
|
|
79
|
-
|
|
60
|
+
expanded={currentId === 'search'}
|
|
61
|
+
onClose={onSearchClose}
|
|
80
62
|
onFocus={onSearchFocus}
|
|
81
63
|
/>
|
|
82
64
|
)}
|
|
83
65
|
{menu && (
|
|
84
|
-
<DrawerBase expanded={
|
|
85
|
-
<GlobalMenu {...menu} variant="drawer" expanded={
|
|
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
|
-
|
|
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 = ({
|
|
14
|
+
export const HeaderBase = ({ currentId, className, children, open, onClose }: HeaderBaseProps) => {
|
|
12
15
|
return (
|
|
13
|
-
<header className={cx(styles.header, className)}
|
|
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
|
-
.
|
|
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
|
-
.
|
|
5
|
+
.dropdown[aria-expanded="true"] {
|
|
11
6
|
width: 320px;
|
|
12
7
|
display: none;
|
|
13
8
|
}
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
.
|
|
23
|
-
|
|
17
|
+
.drawer[aria-expanded="true"] {
|
|
18
|
+
display: none;
|
|
24
19
|
}
|
|
25
20
|
|
|
26
|
-
.
|
|
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
|
+
}
|