@oslokommune/punkt-react 20.2.1 → 20.2.2
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/CHANGELOG.md +5 -0
- package/dist/components/header/HeaderGlobal.js +148 -146
- package/dist/components/header/HeaderService.js +2 -2
- package/dist/components/header/types.d.ts +26 -93
- package/dist/components/header-menu/HeaderMenu.js +108 -106
- package/dist/components/interfaces.d.ts +1 -1
- package/dist/punkt-react.cjs +1 -1
- package/dist/shared-strings/index.d.ts +1 -1
- package/dist/shared-strings/nb.d.ts +1 -0
- package/dist/shared-strings/nb.js +2 -1
- package/dist/shared-strings/resolve.d.ts +9 -0
- package/dist/shared-strings/resolve.js +9 -1
- package/dist/shared-types/header-footer.d.ts +0 -44
- package/dist/shared-types/header.d.ts +214 -10
- package/dist/shared-types/header.js +26 -0
- package/dist/shared-types/index.d.ts +3 -3
- package/dist/shared-types/index.js +24 -23
- package/package.json +2 -2
- package/src/components/header/HeaderGlobal.test.tsx +82 -0
- package/src/components/header/HeaderGlobal.tsx +35 -16
- package/src/components/header/HeaderService.tsx +12 -12
- package/src/components/header/types.ts +37 -97
- package/src/components/header-menu/HeaderMenu.test.tsx +14 -0
- package/src/components/header-menu/HeaderMenu.tsx +7 -2
- package/src/components/interfaces.ts +1 -1
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
export { nb } from './nb';
|
|
10
10
|
export { formatString, plural } from './format';
|
|
11
11
|
export { getPktStrings, resetPktStrings, setPktStrings, subscribePktStrings } from './store';
|
|
12
|
-
export { resolveNamespace, resolveStrings } from './resolve';
|
|
12
|
+
export { resolveNamespace, resolveOverride, resolveStrings } from './resolve';
|
|
13
13
|
export type { IPktStringsProps, TPktStringParams, TPktStrings, TPktStringsNamespace, TPktStringsOverride, TPktStringsShape, TPktStringValue, } from './types';
|
|
14
14
|
export { consentStrings } from './consent';
|
|
@@ -126,7 +126,8 @@ var e = {
|
|
|
126
126
|
orgNumber: "Org.nr. {number}",
|
|
127
127
|
changeRepresentation: "Endre organisasjon",
|
|
128
128
|
menuLoading: "Laster meny…",
|
|
129
|
-
menuLoadError: "Kunne ikke laste meny."
|
|
129
|
+
menuLoadError: "Kunne ikke laste meny.",
|
|
130
|
+
navAriaLabel: "Hovedmeny"
|
|
130
131
|
},
|
|
131
132
|
listbox: {
|
|
132
133
|
searchLabel: "Søk i listen",
|
|
@@ -10,3 +10,12 @@ export declare function resolveNamespace<K extends TPktStringsNamespace>(ns: K,
|
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
12
|
export declare function resolveStrings<NS extends TPktStringsNamespace>(namespaces: readonly NS[], ...layers: Array<TPktStringsOverride | undefined>): Pick<TPktStrings, NS>;
|
|
13
|
+
/**
|
|
14
|
+
* Den overstyrte verdien for én nøkkel, eller `undefined` hvis bare den
|
|
15
|
+
* innebygde teksten finnes. Brukes der en komponent har en annen standardtekst
|
|
16
|
+
* enn katalogen, f.eks. placeholderen i payloaden til den globale headeren, men
|
|
17
|
+
* en overstyring fortsatt skal vinne.
|
|
18
|
+
*
|
|
19
|
+
* Lagene har samme rekkefølge som i `resolveNamespace`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveOverride<K extends TPktStringsNamespace, Key extends keyof TPktStrings[K]>(ns: K, key: Key, ...layers: Array<TPktStringsOverride | undefined>): TPktStrings[K][Key] | undefined;
|
|
@@ -36,4 +36,12 @@ function s(e, ...t) {
|
|
|
36
36
|
for (let r of e) n[r] = o(r, ...t);
|
|
37
37
|
return n;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
function c(e, n, ...r) {
|
|
40
|
+
for (let t of [...r].reverse()) {
|
|
41
|
+
let r = t?.[e]?.[n];
|
|
42
|
+
if (r !== void 0) return r;
|
|
43
|
+
}
|
|
44
|
+
let i = t()[e]?.[n];
|
|
45
|
+
return i === void 0 ? void 0 : i;
|
|
46
|
+
}
|
|
47
|
+
export { o as resolveNamespace, c as resolveOverride, s as resolveStrings };
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* `string & {}` escape hatch so additional locales can be added without
|
|
15
15
|
* a type-level breaking change.
|
|
16
16
|
*/
|
|
17
|
-
import type { Representing, TLogOutButtonPlacement, THeaderPosition, THeaderScrollBehavior, User, UserMenuItem } from './header';
|
|
18
17
|
export type THeaderMenuLocale = 'nb-NO' | 'en-GB' | (string & {});
|
|
19
18
|
/** Documented locale keys — shared runtime source for specs and Preview dropdowns. */
|
|
20
19
|
export declare const HEADER_MENU_LOCALES: readonly ['nb-NO', 'en-GB'];
|
|
@@ -108,49 +107,6 @@ export interface IPktHeaderMenu<IconType = string> {
|
|
|
108
107
|
/** Pixel breakpoint below which sections collapse into accordions. */
|
|
109
108
|
mobileBreakpoint?: number;
|
|
110
109
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Framework-agnostic props for the global (kommune-wide) header
|
|
113
|
-
* (`pkt-header-global` / `PktHeaderGlobal`). Elements narrows the
|
|
114
|
-
* boolean fields to `Booleanish` and React adds callback/className
|
|
115
|
-
* props on top — see each package's `header/types.ts`.
|
|
116
|
-
*/
|
|
117
|
-
export interface IPktHeaderGlobal<IconType = string> {
|
|
118
|
-
/** Endpoint to fetch the header/footer payload from. */
|
|
119
|
-
dataUrl?: string;
|
|
120
|
-
/** Pre-fetched payload. If supplied, the component (and its menu) skips its own fetch. */
|
|
121
|
-
data?: THeaderFooterApi<IconType>;
|
|
122
|
-
/** Locale key to select from the payload. Defaults to `nb-NO`. */
|
|
123
|
-
locale?: THeaderMenuLocale;
|
|
124
|
-
/** Logo link URL. When omitted the logo is rendered without a link. */
|
|
125
|
-
logoLink?: string;
|
|
126
|
-
/** Override the CDN path the logo assets load from. Can also be set
|
|
127
|
-
* globally via `window.pktLogoPath`. */
|
|
128
|
-
logoPath?: string;
|
|
129
|
-
/** Show the search field. Default: true */
|
|
130
|
-
showSearch?: boolean;
|
|
131
|
-
/** Placeholder for the search field. Falls back to the payload's search placeholder, then 'Søk'. */
|
|
132
|
-
searchPlaceholder?: string;
|
|
133
|
-
/** Show the contact link (from the payload's `header.contact`). Default: true */
|
|
134
|
-
showContact?: boolean;
|
|
135
|
-
/** User object for the logged-in user. When set, the user menu is shown. */
|
|
136
|
-
user?: User;
|
|
137
|
-
/** User menu items. */
|
|
138
|
-
userMenu?: UserMenuItem<IconType>[];
|
|
139
|
-
/** Representation object. */
|
|
140
|
-
representing?: Representing;
|
|
141
|
-
/** Allow the user to change representation. */
|
|
142
|
-
canChangeRepresentation?: boolean;
|
|
143
|
-
/** Logout button placement. */
|
|
144
|
-
logOutButtonPlacement?: TLogOutButtonPlacement;
|
|
145
|
-
/** Header position. Default: 'fixed' */
|
|
146
|
-
position?: THeaderPosition;
|
|
147
|
-
/** Scroll behavior. Default: 'hide' */
|
|
148
|
-
scrollBehavior?: THeaderScrollBehavior;
|
|
149
|
-
/** Width below which the header switches to mobile layout. Default: 768 */
|
|
150
|
-
mobileBreakpoint?: number;
|
|
151
|
-
/** Width below which the header switches to tablet layout. Default: 1024 */
|
|
152
|
-
tabletBreakpoint?: number;
|
|
153
|
-
}
|
|
154
110
|
/** Default URL of the live header/footer endpoint. */
|
|
155
111
|
export declare const DEFAULT_HEADER_FOOTER_URL = "https://cdn.web.oslo.kommune.no/header-footer/header-footer.json";
|
|
156
112
|
/** Default logo link for both header variants (unless overridden or hidden). */
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* header.ts
|
|
3
3
|
*
|
|
4
|
-
* Type definitions for header
|
|
5
|
-
*
|
|
4
|
+
* Type definitions and defaults for the header, shared between
|
|
5
|
+
* @oslokommune/punkt-elements and @oslokommune/punkt-react.
|
|
6
|
+
*
|
|
7
|
+
* The value lists are `as const` arrays rather than plain union types, so the
|
|
8
|
+
* values also exist at runtime and the component spec and Preview can use them
|
|
9
|
+
* directly (`type: [...HEADER_POSITIONS]`). The types are derived from the
|
|
10
|
+
* arrays, so there is a single source.
|
|
11
|
+
*
|
|
12
|
+
* Global-header-specific types and defaults live in `header-footer.ts`.
|
|
6
13
|
*/
|
|
14
|
+
import type { IPktStringsProps } from '../shared-strings';
|
|
15
|
+
import { type THeaderFooterApi, type THeaderMenuLocale } from './header-footer';
|
|
7
16
|
/**
|
|
8
17
|
* User object containing information about the logged-in user
|
|
9
18
|
*/
|
|
10
19
|
export interface User {
|
|
11
20
|
/** Full name of the user */
|
|
12
21
|
name: string;
|
|
13
|
-
/**
|
|
22
|
+
/** @deprecated shortname is deprecated and will be removed in a future version */
|
|
14
23
|
shortname?: string;
|
|
15
24
|
/** Last login timestamp (ISO string or Date) */
|
|
16
25
|
lastLoggedIn?: Date | string;
|
|
@@ -21,7 +30,7 @@ export interface User {
|
|
|
21
30
|
export interface Representing {
|
|
22
31
|
/** Name of the organization or entity */
|
|
23
32
|
name: string;
|
|
24
|
-
/**
|
|
33
|
+
/** @deprecated shortname is deprecated and will be removed in a future version */
|
|
25
34
|
shortname?: string;
|
|
26
35
|
/** Organization number */
|
|
27
36
|
orgNumber?: string | number;
|
|
@@ -38,6 +47,16 @@ export interface UserMenuItem<IconType = string> {
|
|
|
38
47
|
/** Link URL or click handler function */
|
|
39
48
|
target: string | (() => void);
|
|
40
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Item in the deprecated `userMenuFooter` prop.
|
|
52
|
+
*
|
|
53
|
+
* An alias of {@link UserMenuItem}: React's original type had no `iconName`,
|
|
54
|
+
* while Elements has always accepted full `UserMenuItem`s. The alias keeps
|
|
55
|
+
* both working without narrowing either package.
|
|
56
|
+
*
|
|
57
|
+
* @deprecated Use `userMenu` with `UserMenuItem` instead.
|
|
58
|
+
*/
|
|
59
|
+
export type UserMenuFooterItem<IconType = string> = UserMenuItem<IconType>;
|
|
41
60
|
/**
|
|
42
61
|
* Internal type for rendering links/buttons (supports both href and onClick)
|
|
43
62
|
* Base interface for discriminated union
|
|
@@ -66,23 +85,208 @@ export type TInternalMenuItem<IconType = string> = InternalMenuLink<IconType> |
|
|
|
66
85
|
* Helper to convert UserMenuItem (with target) to internal format
|
|
67
86
|
*/
|
|
68
87
|
export declare const convertUserMenuItem: <IconType = string>(item: UserMenuItem<IconType>) => TInternalMenuItem<IconType>;
|
|
88
|
+
/**
|
|
89
|
+
* Which header variant `<pkt-header>` / `<PktHeader>` renders: `service` is a
|
|
90
|
+
* customizable header for a single service, `global` is the kommune-wide header.
|
|
91
|
+
* Was defined separately (but identically) in both packages before.
|
|
92
|
+
*/
|
|
93
|
+
export declare const HEADER_TYPES: readonly ['service', 'global'];
|
|
94
|
+
export type THeaderType = (typeof HEADER_TYPES)[number];
|
|
69
95
|
/**
|
|
70
96
|
* Variant for the slot menu button in tablet/mobile mode
|
|
71
97
|
*/
|
|
72
|
-
export
|
|
98
|
+
export declare const SLOT_MENU_VARIANTS: readonly ['icon-only', 'icon-right'];
|
|
99
|
+
export type TSlotMenuVariant = (typeof SLOT_MENU_VARIANTS)[number];
|
|
73
100
|
/**
|
|
74
|
-
*
|
|
101
|
+
* Which menu is open in the service header
|
|
75
102
|
*/
|
|
76
|
-
export
|
|
103
|
+
export declare const HEADER_MENUS: readonly ['none', 'slot', 'search', 'user'];
|
|
104
|
+
export type THeaderMenu = (typeof HEADER_MENUS)[number];
|
|
77
105
|
/**
|
|
78
106
|
* Placement options for the logout button
|
|
79
107
|
*/
|
|
80
|
-
export
|
|
108
|
+
export declare const LOG_OUT_BUTTON_PLACEMENTS: readonly ['userMenu', 'header', 'both', 'none'];
|
|
109
|
+
export type TLogOutButtonPlacement = (typeof LOG_OUT_BUTTON_PLACEMENTS)[number];
|
|
81
110
|
/**
|
|
82
111
|
* Position options for the header
|
|
83
112
|
*/
|
|
84
|
-
export
|
|
113
|
+
export declare const HEADER_POSITIONS: readonly ['fixed', 'sticky', 'relative'];
|
|
114
|
+
export type THeaderPosition = (typeof HEADER_POSITIONS)[number];
|
|
85
115
|
/**
|
|
86
116
|
* Scroll behavior options for the header
|
|
87
117
|
*/
|
|
88
|
-
export
|
|
118
|
+
export declare const HEADER_SCROLL_BEHAVIORS: readonly ['hide', 'none'];
|
|
119
|
+
export type THeaderScrollBehavior = (typeof HEADER_SCROLL_BEHAVIORS)[number];
|
|
120
|
+
/**
|
|
121
|
+
* Props both header variants share. Neither component uses this directly: it
|
|
122
|
+
* is the common ground for {@link IPktHeaderServiceBase} and
|
|
123
|
+
* {@link IPktHeaderGlobalBase}, so a shared prop is declared and documented
|
|
124
|
+
* once.
|
|
125
|
+
*/
|
|
126
|
+
export interface IPktHeaderCommonBase<IconType = string> extends IPktStringsProps<'header'> {
|
|
127
|
+
/** Logo link URL. Default: `DEFAULT_HEADER_LOGO_LINK`. Set to an empty string to render the logo without a link */
|
|
128
|
+
logoLink?: string;
|
|
129
|
+
/** Override the CDN path for the logo. Can also be set globally via `window.pktLogoPath`. */
|
|
130
|
+
logoPath?: string;
|
|
131
|
+
/** User object for the logged-in user. When set, the user menu is shown */
|
|
132
|
+
user?: User;
|
|
133
|
+
/** User menu items displayed in the dropdown */
|
|
134
|
+
userMenu?: UserMenuItem<IconType>[];
|
|
135
|
+
/** Representation object */
|
|
136
|
+
representing?: Representing;
|
|
137
|
+
/** Whether the user can change representation. Shows the "Endre organisasjon" button. Default: false */
|
|
138
|
+
canChangeRepresentation?: boolean;
|
|
139
|
+
/** Where to show the logout button. Default: 'none' */
|
|
140
|
+
logOutButtonPlacement?: TLogOutButtonPlacement;
|
|
141
|
+
/** Show the search field. Default: false for service, true for global */
|
|
142
|
+
showSearch?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Placeholder for the search field. Overrides `header.search` in the string
|
|
145
|
+
* catalogue. Without an override, the service header uses the catalogue and
|
|
146
|
+
* the global header uses the placeholder from the payload.
|
|
147
|
+
* @deprecated Use `strings={{ header: { search: '…' } }}` or `setPktStrings()` instead.
|
|
148
|
+
*/
|
|
149
|
+
searchPlaceholder?: string;
|
|
150
|
+
/** Header position. Default: 'fixed' */
|
|
151
|
+
position?: THeaderPosition;
|
|
152
|
+
/** Scroll behavior. 'hide' hides the header on scroll down. Default: 'hide' */
|
|
153
|
+
scrollBehavior?: THeaderScrollBehavior;
|
|
154
|
+
/** Width in pixels below which the header switches to mobile layout. Default: 768 */
|
|
155
|
+
mobileBreakpoint?: number;
|
|
156
|
+
/** Width in pixels below which the header switches to tablet layout. Default: 1280 for service, 1024 for global */
|
|
157
|
+
tabletBreakpoint?: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Framework-agnostic props for the service header (`pkt-header-service` /
|
|
161
|
+
* `PktHeaderService`): a customizable header for a single service.
|
|
162
|
+
*
|
|
163
|
+
* Elements narrows the boolean fields to `Booleanish` and adds `hasLogOut`,
|
|
164
|
+
* React adds callbacks, `children`, `className` and the deprecated props.
|
|
165
|
+
*/
|
|
166
|
+
export interface IPktHeaderServiceBase<IconType = string> extends IPktHeaderCommonBase<IconType> {
|
|
167
|
+
/** Hide the Oslo logo. Default: false */
|
|
168
|
+
hideLogo?: boolean;
|
|
169
|
+
/** Name of the service displayed in the header */
|
|
170
|
+
serviceName?: string;
|
|
171
|
+
/** Link URL for the service name */
|
|
172
|
+
serviceLink?: string;
|
|
173
|
+
/** Use compact header height. Default: false */
|
|
174
|
+
compact?: boolean;
|
|
175
|
+
/** Controlled value for the search field */
|
|
176
|
+
searchValue?: string;
|
|
177
|
+
/** Which menu is initially open. Default: 'none' */
|
|
178
|
+
openedMenu?: THeaderMenu;
|
|
179
|
+
/** Variant for the slot menu button in tablet/mobile mode. Default: 'icon-only' */
|
|
180
|
+
slotMenuVariant?: TSlotMenuVariant;
|
|
181
|
+
/** Text for the slot menu button. Falls back to `header.menu` in the string catalogue */
|
|
182
|
+
slotMenuText?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Framework-agnostic props for the global (kommune-wide) header
|
|
186
|
+
* (`pkt-header-global` / `PktHeaderGlobal`), whose content comes from the
|
|
187
|
+
* shared header/footer payload.
|
|
188
|
+
*
|
|
189
|
+
* `data` is not generic: the payload's icon names are raw API values that the
|
|
190
|
+
* component maps itself, so only `userMenu` takes `IconType`.
|
|
191
|
+
*/
|
|
192
|
+
export interface IPktHeaderGlobalBase<IconType = string> extends IPktHeaderCommonBase<IconType> {
|
|
193
|
+
/** Endpoint to fetch the header/footer payload from. Default: `DEFAULT_HEADER_FOOTER_URL` */
|
|
194
|
+
dataUrl?: string;
|
|
195
|
+
/** Pre-fetched payload. If supplied, the component (and its menu) skips its own fetch. */
|
|
196
|
+
data?: THeaderFooterApi;
|
|
197
|
+
/** Locale key to select from the payload. Default: 'nb-NO' */
|
|
198
|
+
locale?: THeaderMenuLocale;
|
|
199
|
+
/** Show the contact link (from the payload's `header.contact`). Default: true */
|
|
200
|
+
showContact?: boolean;
|
|
201
|
+
}
|
|
202
|
+
/** Props only the global header reads. */
|
|
203
|
+
export type TPktHeaderGlobalOnlyProps = 'dataUrl' | 'data' | 'locale' | 'showContact';
|
|
204
|
+
/**
|
|
205
|
+
* Props for the `pkt-header` / `PktHeader` dispatcher, which renders either
|
|
206
|
+
* variant based on `type`: the service props plus the props only the global
|
|
207
|
+
* header reads.
|
|
208
|
+
*
|
|
209
|
+
* `showSearch` and `tabletBreakpoint` have a different default per variant
|
|
210
|
+
* (false/1280 for service, true/1024 for global). The dispatcher must not set
|
|
211
|
+
* its own default for these, but leave them undefined and let each variant
|
|
212
|
+
* fall back to its own default. A single default here would silently give one
|
|
213
|
+
* of the variants the wrong value.
|
|
214
|
+
*/
|
|
215
|
+
export interface IPktHeaderBase<IconType = string> extends IPktHeaderServiceBase<IconType>, Pick<IPktHeaderGlobalBase<IconType>, TPktHeaderGlobalOnlyProps> {
|
|
216
|
+
/** Which header variant to render. Default: 'service' */
|
|
217
|
+
type?: THeaderType;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Props documented in `header.spec.ts`: the dispatcher props, plus props that
|
|
221
|
+
* only exist in one framework and the deprecated props, so SpecList can show
|
|
222
|
+
* them with the right markings.
|
|
223
|
+
*/
|
|
224
|
+
export type IHeaderSpecProps = IPktHeaderBase & {
|
|
225
|
+
/** React only. Elements uses the `logo-click` event. */
|
|
226
|
+
logoClick?: (event: MouseEvent) => void;
|
|
227
|
+
/** React only. Elements uses the `service-click` event. */
|
|
228
|
+
serviceClick?: (event: MouseEvent) => void;
|
|
229
|
+
/** Elements only. Tells the element a `log-out` listener is attached. */
|
|
230
|
+
hasLogOut?: boolean;
|
|
231
|
+
/** @deprecated Use `userMenu` instead. */
|
|
232
|
+
userMenuFooter?: UserMenuFooterItem[];
|
|
233
|
+
/** @deprecated Use `userMenu` instead. */
|
|
234
|
+
userOptions?: UserMenuItem[];
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Defaults that are the same for both header variants.
|
|
238
|
+
* Spread into `HEADER_SERVICE_DEFAULTS` and `HEADER_GLOBAL_DEFAULTS`, so a
|
|
239
|
+
* shared value can only be changed in one place.
|
|
240
|
+
*/
|
|
241
|
+
export declare const HEADER_COMMON_DEFAULTS: {
|
|
242
|
+
readonly logoLink: "https://www.oslo.kommune.no";
|
|
243
|
+
readonly canChangeRepresentation: false;
|
|
244
|
+
readonly logOutButtonPlacement: 'none';
|
|
245
|
+
readonly position: 'fixed';
|
|
246
|
+
readonly scrollBehavior: 'hide';
|
|
247
|
+
readonly mobileBreakpoint: 768;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Defaults for the service header, shared by React and Elements.
|
|
251
|
+
*
|
|
252
|
+
* These used to be hardcoded in each component. `showSearch` and
|
|
253
|
+
* `tabletBreakpoint` differ from the global header, which is why the two
|
|
254
|
+
* variants have separate defaults.
|
|
255
|
+
*
|
|
256
|
+
* Left out on purpose:
|
|
257
|
+
* - `logoPath`: resolved at runtime from `window.pktLogoPath`.
|
|
258
|
+
* - `searchPlaceholder`, `slotMenuText`: fall back to the string catalogue.
|
|
259
|
+
*/
|
|
260
|
+
export declare const HEADER_SERVICE_DEFAULTS: {
|
|
261
|
+
readonly logoLink: "https://www.oslo.kommune.no";
|
|
262
|
+
readonly canChangeRepresentation: false;
|
|
263
|
+
readonly logOutButtonPlacement: 'none';
|
|
264
|
+
readonly position: 'fixed';
|
|
265
|
+
readonly scrollBehavior: 'hide';
|
|
266
|
+
readonly mobileBreakpoint: 768;
|
|
267
|
+
readonly type: 'service';
|
|
268
|
+
readonly hideLogo: false;
|
|
269
|
+
readonly compact: false;
|
|
270
|
+
readonly showSearch: false;
|
|
271
|
+
readonly tabletBreakpoint: 1280;
|
|
272
|
+
readonly openedMenu: 'none';
|
|
273
|
+
readonly slotMenuVariant: 'icon-only';
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Defaults for the global header, shared by React and Elements.
|
|
277
|
+
*
|
|
278
|
+
* `dataUrl` is left out: when unset, the components fall back to
|
|
279
|
+
* `DEFAULT_HEADER_FOOTER_URL` at fetch time.
|
|
280
|
+
*/
|
|
281
|
+
export declare const HEADER_GLOBAL_DEFAULTS: {
|
|
282
|
+
readonly logoLink: "https://www.oslo.kommune.no";
|
|
283
|
+
readonly canChangeRepresentation: false;
|
|
284
|
+
readonly logOutButtonPlacement: 'none';
|
|
285
|
+
readonly position: 'fixed';
|
|
286
|
+
readonly scrollBehavior: 'hide';
|
|
287
|
+
readonly mobileBreakpoint: 768;
|
|
288
|
+
readonly locale: 'nb-NO';
|
|
289
|
+
readonly showSearch: true;
|
|
290
|
+
readonly showContact: true;
|
|
291
|
+
readonly tabletBreakpoint: 1024;
|
|
292
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DEFAULT_HEADER_LOGO_LINK as e } from "./header-footer.js";
|
|
2
|
+
// ../../shared-types/header.ts
|
|
3
|
+
var t = {
|
|
4
|
+
logoLink: e,
|
|
5
|
+
canChangeRepresentation: !1,
|
|
6
|
+
logOutButtonPlacement: "none",
|
|
7
|
+
position: "fixed",
|
|
8
|
+
scrollBehavior: "hide",
|
|
9
|
+
mobileBreakpoint: 768
|
|
10
|
+
}, n = {
|
|
11
|
+
...t,
|
|
12
|
+
type: "service",
|
|
13
|
+
hideLogo: !1,
|
|
14
|
+
compact: !1,
|
|
15
|
+
showSearch: !1,
|
|
16
|
+
tabletBreakpoint: 1280,
|
|
17
|
+
openedMenu: "none",
|
|
18
|
+
slotMenuVariant: "icon-only"
|
|
19
|
+
}, r = {
|
|
20
|
+
...t,
|
|
21
|
+
locale: "nb-NO",
|
|
22
|
+
showSearch: !0,
|
|
23
|
+
showContact: !0,
|
|
24
|
+
tabletBreakpoint: 1024
|
|
25
|
+
};
|
|
26
|
+
export { t as HEADER_COMMON_DEFAULTS, r as HEADER_GLOBAL_DEFAULTS, n as HEADER_SERVICE_DEFAULTS };
|
|
@@ -5,10 +5,10 @@ export type { TPktSizeBase, TPktSize, TPktInputSize } from './size';
|
|
|
5
5
|
export { ARIA_LIVE_VALUES, type TAriaBoolean, type TAriaBooleanMixed, type TAriaCurrent, type TAriaHasPopup, type TAriaInvalid, type TAriaLive, type TAriaRelevant, type TAriaSort, type TAriaAutoComplete, type TAriaOrientation, type IAriaAttributes, type TAlertRole, } from './aria';
|
|
6
6
|
export { ALERT_SKINS, ALERT_SIZES, ALERT_DEFAULTS, type TAlertSkin, type TAlertSize, type IAlertSpecProps, } from './alert';
|
|
7
7
|
export type { THeadingLevel, THeadingSize, THeadingWeight } from './heading';
|
|
8
|
-
export type { User, Representing, UserMenuItem, InternalMenuItemBase, InternalMenuLink, InternalMenuButton, TInternalMenuItem, TSlotMenuVariant, THeaderMenu, TLogOutButtonPlacement, THeaderPosition, THeaderScrollBehavior, } from './header';
|
|
9
|
-
export { convertUserMenuItem } from './header';
|
|
8
|
+
export type { User, Representing, UserMenuItem, UserMenuFooterItem, InternalMenuItemBase, InternalMenuLink, InternalMenuButton, TInternalMenuItem, THeaderType, TSlotMenuVariant, THeaderMenu, TLogOutButtonPlacement, THeaderPosition, THeaderScrollBehavior, IPktHeaderCommonBase, IPktHeaderServiceBase, IPktHeaderGlobalBase, IPktHeaderBase, TPktHeaderGlobalOnlyProps, IHeaderSpecProps, } from './header';
|
|
9
|
+
export { convertUserMenuItem, HEADER_TYPES, SLOT_MENU_VARIANTS, HEADER_MENUS, LOG_OUT_BUTTON_PLACEMENTS, HEADER_POSITIONS, HEADER_SCROLL_BEHAVIORS, HEADER_COMMON_DEFAULTS, HEADER_SERVICE_DEFAULTS, HEADER_GLOBAL_DEFAULTS, } from './header';
|
|
10
10
|
export { HEADER_MENU_LOCALES, DEFAULT_HEADER_FOOTER_URL, DEFAULT_HEADER_LOGO_LINK, } from './header-footer';
|
|
11
|
-
export type { THeaderMenuLocale, IHeaderMenuLink, IHeaderMenuIconLink, IHeaderMenuButton, IHeaderMenuServices, IHeaderMenuSection, IMegaMenu, IHeaderFooter, IHeaderFooterLocaleData, THeaderFooterApi, IPktHeaderMenu,
|
|
11
|
+
export type { THeaderMenuLocale, IHeaderMenuLink, IHeaderMenuIconLink, IHeaderMenuButton, IHeaderMenuServices, IHeaderMenuSection, IMegaMenu, IHeaderFooter, IHeaderFooterLocaleData, THeaderFooterApi, IPktHeaderMenu, } from './header-footer';
|
|
12
12
|
export type { IPktFooterLink, IPktFooterColumn, IPktFooterSocialLink, IPktFooterBase, IPktFooterProps, IPktFooterSimpleProps, IFooterSimpleSpecProps, IFooterSpecProps, } from './footer';
|
|
13
13
|
export { DEFAULT_FOOTER_PERSONVERN_URL, DEFAULT_FOOTER_TILGJENGELIGHET_URL } from './footer';
|
|
14
14
|
export { CARD_SKINS, CARD_LIGHT_ONLY_SKINS, CARD_IMAGE_ASPECTS, CARD_TAG_POSITIONS, CARD_TAG_SKIN_OPTIONS, CARD_DEFAULTS, } from './card';
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import "./size.js";
|
|
2
|
-
import { DEFAULT_HEADER_FOOTER_URL as e
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
2
|
+
import { DEFAULT_HEADER_FOOTER_URL as e } from "./header-footer.js";
|
|
3
|
+
import { HEADER_GLOBAL_DEFAULTS as t, HEADER_SERVICE_DEFAULTS as n } from "./header.js";
|
|
4
|
+
import { DEFAULT_FOOTER_PERSONVERN_URL as r, DEFAULT_FOOTER_TILGJENGELIGHET_URL as i } from "./footer.js";
|
|
5
|
+
import { CARD_DEFAULTS as a, CARD_LIGHT_ONLY_SKINS as o } from "./card.js";
|
|
6
|
+
import { CHECKBOX_DEFAULTS as s } from "./checkbox.js";
|
|
7
|
+
import { RADIOBUTTON_DEFAULTS as c } from "./radiobutton.js";
|
|
8
|
+
import { OPTION_GROUP_DEFAULTS as l } from "./option-group.js";
|
|
9
|
+
import { CONSENT_DEFAULTS as u } from "./consent.js";
|
|
10
|
+
import { ANIMATION_DEFAULT_PATH as d, ICON_DEFAULTS as f } from "./icon.js";
|
|
11
|
+
import { LOADER_DEFAULTS as p } from "./loader.js";
|
|
12
|
+
import { ACCORDION_LIGHT_ONLY_SKINS as m } from "./accordion.js";
|
|
13
|
+
import { BUTTON_DEFAULTS as h } from "./button.js";
|
|
14
|
+
import { LINKCARD_LIGHT_ONLY_SKINS as g } from "./linkcard.js";
|
|
15
|
+
import { INPUT_WRAPPER_DEFAULTS as _ } from "./input-wrapper.js";
|
|
16
|
+
import { TEXTAREA_DEFAULTS as v } from "./textarea.js";
|
|
17
|
+
import { TEXTINPUT_DEFAULTS as y } from "./textinput.js";
|
|
18
|
+
import { TAG_DEFAULTS as b } from "./tag.js";
|
|
19
|
+
import { TABS_DEFAULTS as x, TAB_ITEM_DEFAULTS as S } from "./tabs.js";
|
|
20
|
+
import { MESSAGEBOX_DEFAULTS as C, MESSAGEBOX_LIGHT_ONLY_SKINS as w } from "./messagebox.js";
|
|
20
21
|
import "./calendar.js";
|
|
21
|
-
import { DATEPICKER_DEFAULTS as
|
|
22
|
-
import { PROGRESSBAR_DEFAULTS as
|
|
22
|
+
import { DATEPICKER_DEFAULTS as T } from "./datepicker.js";
|
|
23
|
+
import { PROGRESSBAR_DEFAULTS as E } from "./progressbar.js";
|
|
23
24
|
import "./combobox.js";
|
|
24
|
-
import { SELECT_DEFAULTS as
|
|
25
|
-
import { TABLE_DEFAULTS as
|
|
26
|
-
export {
|
|
25
|
+
import { SELECT_DEFAULTS as D } from "./select.js";
|
|
26
|
+
import { TABLE_DEFAULTS as O } from "./table.js";
|
|
27
|
+
export { m as ACCORDION_LIGHT_ONLY_SKINS, d as ANIMATION_DEFAULT_PATH, h as BUTTON_DEFAULTS, a as CARD_DEFAULTS, o as CARD_LIGHT_ONLY_SKINS, s as CHECKBOX_DEFAULTS, u as CONSENT_DEFAULTS, T as DATEPICKER_DEFAULTS, r as DEFAULT_FOOTER_PERSONVERN_URL, i as DEFAULT_FOOTER_TILGJENGELIGHET_URL, e as DEFAULT_HEADER_FOOTER_URL, t as HEADER_GLOBAL_DEFAULTS, n as HEADER_SERVICE_DEFAULTS, f as ICON_DEFAULTS, _ as INPUT_WRAPPER_DEFAULTS, g as LINKCARD_LIGHT_ONLY_SKINS, p as LOADER_DEFAULTS, C as MESSAGEBOX_DEFAULTS, w as MESSAGEBOX_LIGHT_ONLY_SKINS, l as OPTION_GROUP_DEFAULTS, E as PROGRESSBAR_DEFAULTS, c as RADIOBUTTON_DEFAULTS, D as SELECT_DEFAULTS, O as TABLE_DEFAULTS, x as TABS_DEFAULTS, S as TAB_ITEM_DEFAULTS, b as TAG_DEFAULTS, v as TEXTAREA_DEFAULTS, y as TEXTINPUT_DEFAULTS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "20.2.
|
|
3
|
+
"version": "20.2.2",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "c5d1c30d65671d5a45689d59976f28e67559e732"
|
|
106
106
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import '@testing-library/jest-dom'
|
|
2
2
|
|
|
3
3
|
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
4
|
+
import { resetPktStrings, setPktStrings } from 'shared-strings'
|
|
4
5
|
import { EXAMPLE_HEADER_FOOTER_DATA } from 'shared-utils/header-footer'
|
|
5
6
|
import { afterEach, describe, expect, test, vi } from 'vitest'
|
|
6
7
|
|
|
8
|
+
import { PktStringsProvider } from '../strings/PktStringsProvider'
|
|
7
9
|
import { PktHeaderGlobal } from './HeaderGlobal'
|
|
8
10
|
|
|
9
11
|
const renderGlobal = (props = {}) =>
|
|
@@ -260,3 +262,83 @@ describe('PktHeaderGlobal', () => {
|
|
|
260
262
|
expect(onClick).toHaveBeenCalledTimes(1)
|
|
261
263
|
})
|
|
262
264
|
})
|
|
265
|
+
|
|
266
|
+
describe('PktHeaderGlobal – placeholder i søkefeltet', () => {
|
|
267
|
+
afterEach(() => resetPktStrings())
|
|
268
|
+
|
|
269
|
+
const placeholder = (container: HTMLElement) =>
|
|
270
|
+
container.querySelector('input[name="q"]')?.getAttribute('placeholder')
|
|
271
|
+
|
|
272
|
+
test('bruker placeholderen fra payloaden som standard', () => {
|
|
273
|
+
const { container } = renderGlobal(DESKTOP)
|
|
274
|
+
expect(placeholder(container)).toBe('Søk i hele nettstedet')
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
test('strings-propen vinner over payloaden', () => {
|
|
278
|
+
const { container } = renderGlobal({ ...DESKTOP, strings: { header: { search: 'Søk her' } } })
|
|
279
|
+
expect(placeholder(container)).toBe('Søk her')
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
test('PktStringsProvider vinner over payloaden', () => {
|
|
283
|
+
const { container } = render(
|
|
284
|
+
<PktStringsProvider strings={{ header: { search: 'Søk i provider' } }}>
|
|
285
|
+
<PktHeaderGlobal data={EXAMPLE_HEADER_FOOTER_DATA} position="relative" {...DESKTOP} />
|
|
286
|
+
</PktStringsProvider>,
|
|
287
|
+
)
|
|
288
|
+
expect(placeholder(container)).toBe('Søk i provider')
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
test('setPktStrings vinner over payloaden', () => {
|
|
292
|
+
setPktStrings({ header: { search: 'Søk globalt' } })
|
|
293
|
+
const { container } = renderGlobal(DESKTOP)
|
|
294
|
+
expect(placeholder(container)).toBe('Søk globalt')
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('searchPlaceholder vinner over strings', () => {
|
|
298
|
+
const { container } = renderGlobal({
|
|
299
|
+
...DESKTOP,
|
|
300
|
+
searchPlaceholder: 'Utdatert',
|
|
301
|
+
strings: { header: { search: 'Søk her' } },
|
|
302
|
+
})
|
|
303
|
+
expect(placeholder(container)).toBe('Utdatert')
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
describe('PktHeaderGlobal – tekster på menyknapp og søk', () => {
|
|
308
|
+
afterEach(() => resetPktStrings())
|
|
309
|
+
|
|
310
|
+
const EN = { ...DESKTOP, locale: 'en-GB' }
|
|
311
|
+
const menuText = (container: HTMLElement) =>
|
|
312
|
+
container.querySelector('#pkt-header-global-menu-toggle')?.textContent?.trim()
|
|
313
|
+
const searchLabel = (container: HTMLElement) => container.querySelector('input[name="q"]')?.getAttribute('aria-label')
|
|
314
|
+
|
|
315
|
+
test('bruker tekstene fra payloaden som standard', () => {
|
|
316
|
+
const { container } = renderGlobal(EN)
|
|
317
|
+
expect(menuText(container)).toBe('Menu')
|
|
318
|
+
expect(searchLabel(container)).toBe('Search')
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
test('strings-propen vinner over payloaden', () => {
|
|
322
|
+
const { container } = renderGlobal({
|
|
323
|
+
...EN,
|
|
324
|
+
strings: { header: { menu: 'Lenker', search: 'Søk her' } },
|
|
325
|
+
})
|
|
326
|
+
expect(menuText(container)).toBe('Lenker')
|
|
327
|
+
expect(searchLabel(container)).toBe('Søk her')
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
test('PktStringsProvider vinner over payloaden', () => {
|
|
331
|
+
const { container } = render(
|
|
332
|
+
<PktStringsProvider strings={{ header: { menu: 'Lenker' } }}>
|
|
333
|
+
<PktHeaderGlobal data={EXAMPLE_HEADER_FOOTER_DATA} position="relative" {...EN} />
|
|
334
|
+
</PktStringsProvider>,
|
|
335
|
+
)
|
|
336
|
+
expect(menuText(container)).toBe('Lenker')
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
test('setPktStrings vinner over payloaden', () => {
|
|
340
|
+
setPktStrings({ header: { menu: 'Lenker' } })
|
|
341
|
+
const { container } = renderGlobal(EN)
|
|
342
|
+
expect(menuText(container)).toBe('Lenker')
|
|
343
|
+
})
|
|
344
|
+
})
|