@oslokommune/punkt-react 19.3.0 → 19.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/components/card/Card.d.ts +2 -1
- package/dist/components/datepicker/types.d.ts +1 -1
- package/dist/components/fileupload/extensions/Comments.d.ts +2 -1
- package/dist/components/fileupload/extensions/Remove.d.ts +2 -1
- package/dist/components/fileupload/extensions/Rename.d.ts +2 -1
- package/dist/components/fileupload/hooks/index.d.ts +1 -0
- package/dist/components/fileupload/hooks/useImageObjectUrl.d.ts +1 -0
- package/dist/components/fileupload/hooks.d.ts +1 -0
- package/dist/components/fileupload/types.d.ts +2 -0
- package/dist/components/header-menu/HeaderMenu.d.ts +3 -2
- package/dist/components/messagebox/Messagebox.d.ts +2 -1
- package/dist/components/modal/Modal.d.ts +2 -1
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1981 -1954
- package/dist/shared-strings/nb.d.ts +34 -0
- package/package.json +2 -2
- package/src/components/alert/Alert.test.tsx +5 -5
- package/src/components/alert/Alert.tsx +2 -4
- package/src/components/breadcrumbs/Breadcrumbs.tsx +15 -12
- package/src/components/calendar/Calendar.core.test.tsx +22 -16
- package/src/components/calendar/CalendarNav.tsx +11 -6
- package/src/components/calendar/useCalendarState.ts +42 -55
- package/src/components/card/Card.tsx +17 -5
- package/src/components/combobox/ComboboxTags.tsx +3 -3
- package/src/components/combobox/Listbox.tsx +7 -5
- package/src/components/combobox/useComboboxState.ts +22 -18
- package/src/components/consent/Consent.tsx +4 -1
- package/src/components/datepicker/DatepickerInputs.tsx +3 -9
- package/src/components/datepicker/types.ts +1 -1
- package/src/components/datepicker/useDatepickerState.ts +22 -17
- package/src/components/fileupload/DropZone.tsx +10 -10
- package/src/components/fileupload/FileUpload.tsx +9 -14
- package/src/components/fileupload/Subcomponents.tsx +78 -84
- package/src/components/fileupload/extensions/Comments.tsx +56 -50
- package/src/components/fileupload/extensions/Remove.tsx +8 -3
- package/src/components/fileupload/extensions/Rename.tsx +12 -8
- package/src/components/fileupload/hooks/index.ts +1 -0
- package/src/components/fileupload/hooks/useImageObjectUrl.ts +15 -0
- package/src/components/fileupload/hooks/useOperationState.ts +9 -16
- package/src/components/fileupload/hooks.ts +1 -0
- package/src/components/fileupload/types.ts +7 -1
- package/src/components/formAttribute.test.tsx +1 -0
- package/src/components/header/HeaderGlobal.tsx +8 -2
- package/src/components/header/HeaderService.test.tsx +5 -2
- package/src/components/header/HeaderService.tsx +5 -5
- package/src/components/header-menu/HeaderMenu.tsx +8 -3
- package/src/components/headerUserMenu/UserMenu.tsx +3 -2
- package/src/components/inputwrapper/InputWrapper.tsx +20 -27
- package/src/components/loader/Loader.tsx +12 -9
- package/src/components/messagebox/Messagebox.tsx +6 -2
- package/src/components/modal/Modal.tsx +13 -9
- package/src/components/searchinput/SearchInput.tsx +10 -6
- package/src/components/tabs/Tabs.test.tsx +1 -1
- package/src/components/tabs/Tabs.tsx +30 -35
- package/src/components/tag/Tag.tsx +7 -6
- package/src/components/textarea/Textarea.test.tsx +9 -0
- package/src/components/textarea/Textarea.tsx +6 -10
- package/src/components/textinput/Textinput.tsx +3 -9
- package/src/components/timepicker/useTimepickerState.ts +25 -21
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useContext, useLayoutEffect, useRef } from 'react'
|
|
2
2
|
|
|
3
|
+
import { formatString, type TPktStrings } from 'shared-strings'
|
|
4
|
+
|
|
3
5
|
import { PktButton } from '../../button/Button'
|
|
4
6
|
import { PktIcon } from '../../icon/Icon'
|
|
5
7
|
import { PktTextarea } from '../../textarea/Textarea'
|
|
@@ -12,7 +14,7 @@ export interface IComment {
|
|
|
12
14
|
timestamp: string
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
const formatTimestamp = (iso: string): string => {
|
|
17
|
+
const formatTimestamp = (iso: string, strings: TPktStrings['fileupload']): string => {
|
|
16
18
|
const date = new Date(iso)
|
|
17
19
|
if (Number.isNaN(date.getTime())) return iso
|
|
18
20
|
const day = String(date.getDate()).padStart(2, '0')
|
|
@@ -20,7 +22,10 @@ const formatTimestamp = (iso: string): string => {
|
|
|
20
22
|
const year = date.getFullYear()
|
|
21
23
|
const hours = String(date.getHours()).padStart(2, '0')
|
|
22
24
|
const minutes = String(date.getMinutes()).padStart(2, '0')
|
|
23
|
-
return
|
|
25
|
+
return formatString(strings.commentTimestamp, {
|
|
26
|
+
date: `${day}.${month}.${year}`,
|
|
27
|
+
time: `${hours}:${minutes}`,
|
|
28
|
+
})
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
const AddComment = ({
|
|
@@ -36,6 +41,7 @@ const AddComment = ({
|
|
|
36
41
|
onAddComment: (comment: IComment) => void
|
|
37
42
|
existingComment?: IComment
|
|
38
43
|
}) => {
|
|
44
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
39
45
|
const inputRef = useRef<HTMLTextAreaElement>(null)
|
|
40
46
|
const isEditing = !!existingComment
|
|
41
47
|
|
|
@@ -56,10 +62,10 @@ const AddComment = ({
|
|
|
56
62
|
<>
|
|
57
63
|
<PktTextarea
|
|
58
64
|
autoFocus
|
|
59
|
-
label={isEditing ?
|
|
65
|
+
label={isEditing ? strings.editComment : strings.addComment}
|
|
60
66
|
name={`comment-${fileItem.fileId}`}
|
|
61
67
|
className="pkt-fileupload__queue-display__item__comment-input"
|
|
62
|
-
placeholder=
|
|
68
|
+
placeholder={strings.commentPlaceholder}
|
|
63
69
|
rows={2}
|
|
64
70
|
id={`comment-${fileItem.fileId}`}
|
|
65
71
|
ref={inputRef}
|
|
@@ -68,10 +74,10 @@ const AddComment = ({
|
|
|
68
74
|
/>
|
|
69
75
|
|
|
70
76
|
<PktButton skin="secondary" size="small" disabled={disabled} onClick={handleAddComment}>
|
|
71
|
-
{isEditing ?
|
|
77
|
+
{isEditing ? strings.saveComment : strings.addComment}
|
|
72
78
|
</PktButton>
|
|
73
79
|
<PktButton skin="tertiary" size="small" disabled={disabled} onClick={closeOperationUi}>
|
|
74
|
-
|
|
80
|
+
{strings.cancel}
|
|
75
81
|
</PktButton>
|
|
76
82
|
</>
|
|
77
83
|
)
|
|
@@ -87,62 +93,59 @@ const ShowComment = ({
|
|
|
87
93
|
disabled: boolean
|
|
88
94
|
onDeleteComment: () => void
|
|
89
95
|
onEditComment: () => void
|
|
90
|
-
}) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
96
|
+
}) => {
|
|
97
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
98
|
+
return (
|
|
99
|
+
<div className="pkt-fileupload__queue-display__item__comments">
|
|
100
|
+
<div className="pkt-fileupload__queue-display__item__comment">
|
|
101
|
+
<div className="pkt-fileupload__queue-display__item__comment__content">
|
|
102
|
+
<span className="pkt-fileupload__queue-display__item__comment__text" aria-label={strings.commentText}>
|
|
103
|
+
{comment.text}
|
|
104
|
+
</span>
|
|
105
|
+
<time className="pkt-fileupload__queue-display__item__comment__time">
|
|
106
|
+
{formatTimestamp(comment.timestamp, strings)}
|
|
107
|
+
</time>
|
|
108
|
+
</div>
|
|
109
|
+
<div className="pkt-fileupload__queue-display__item__comment__actions">
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
className="pkt-fileupload__queue-display__item__comment__action"
|
|
113
|
+
onClick={onEditComment}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
aria-label={strings.editComment}
|
|
116
|
+
>
|
|
117
|
+
<PktIcon name="edit" />
|
|
118
|
+
</button>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
className="pkt-fileupload__queue-display__item__comment__action"
|
|
122
|
+
onClick={onDeleteComment}
|
|
123
|
+
disabled={disabled}
|
|
124
|
+
aria-label={strings.deleteComment}
|
|
125
|
+
>
|
|
126
|
+
<PktIcon name="trash-can" />
|
|
127
|
+
</button>
|
|
128
|
+
</div>
|
|
120
129
|
</div>
|
|
121
130
|
</div>
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
)
|
|
132
|
+
}
|
|
124
133
|
|
|
125
134
|
const CommentHiddenInput = ({ comments }: { comments: IComment[] | undefined }) => {
|
|
126
135
|
const context = useContext(PktFileUploadContext)
|
|
127
|
-
return (
|
|
128
|
-
<input
|
|
129
|
-
type="hidden"
|
|
130
|
-
name={`${context.name}-comments`}
|
|
131
|
-
value={comments ? JSON.stringify(comments) : ''}
|
|
132
|
-
/>
|
|
133
|
-
)
|
|
136
|
+
return <input type="hidden" name={`${context.name}-comments`} value={comments ? JSON.stringify(comments) : ''} />
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
const getComments = (context: TQueueOperationContext): IComment[] =>
|
|
137
140
|
context.getAttribute<IComment[]>(COMMENTS_ATTRIBUTE) ?? []
|
|
138
141
|
|
|
139
|
-
export const addCommentOperation: TQueueItemOperation
|
|
142
|
+
export const addCommentOperation = (strings: TPktStrings['fileupload']): TQueueItemOperation => ({
|
|
140
143
|
id: 'comment',
|
|
141
144
|
title: (fileItem) => {
|
|
142
145
|
const comments = (fileItem.attributes?.[COMMENTS_ATTRIBUTE] as IComment[] | undefined) ?? []
|
|
143
|
-
return comments.length > 0 ? '' :
|
|
146
|
+
return comments.length > 0 ? '' : strings.addComment
|
|
144
147
|
},
|
|
145
|
-
ariaLabel:
|
|
148
|
+
ariaLabel: strings.addComment,
|
|
146
149
|
renderExtendedUI: (context) => {
|
|
147
150
|
const existingComment = getComments(context)[0]
|
|
148
151
|
return (
|
|
@@ -171,6 +174,9 @@ export const addCommentOperation: TQueueItemOperation = {
|
|
|
171
174
|
)
|
|
172
175
|
},
|
|
173
176
|
renderHidden: (context) => (
|
|
174
|
-
<CommentHiddenInput
|
|
177
|
+
<CommentHiddenInput
|
|
178
|
+
key={`comments${context.file.fileId}`}
|
|
179
|
+
comments={context.getAttribute<IComment[]>(COMMENTS_ATTRIBUTE)}
|
|
180
|
+
/>
|
|
175
181
|
),
|
|
176
|
-
}
|
|
182
|
+
})
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { TPktStrings } from 'shared-strings'
|
|
2
|
+
|
|
1
3
|
import type { TFileId, TQueueItemOperation } from '@/components/fileupload/types'
|
|
2
4
|
|
|
3
|
-
export const removeFileOperation = (
|
|
5
|
+
export const removeFileOperation = (
|
|
6
|
+
onFileRemoved: (fileId: TFileId) => void,
|
|
7
|
+
strings: TPktStrings['fileupload'],
|
|
8
|
+
): TQueueItemOperation => ({
|
|
4
9
|
id: 'remove',
|
|
5
|
-
title:
|
|
6
|
-
ariaLabel:
|
|
10
|
+
title: strings.remove,
|
|
11
|
+
ariaLabel: strings.removeFile,
|
|
7
12
|
onClick: ({ file }) => onFileRemoved(file.fileId),
|
|
8
13
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useContext, useId, useRef } from 'react'
|
|
2
2
|
|
|
3
|
+
import type { TPktStrings } from 'shared-strings'
|
|
3
4
|
import { getDisplayFilename } from 'shared-utils/fileupload'
|
|
4
5
|
|
|
5
6
|
import { PktButton } from '../../button/Button'
|
|
@@ -13,6 +14,7 @@ interface IRenameFileProps {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const RenameFile = ({ initialValue, disabled, onSave, onCancel }: IRenameFileProps) => {
|
|
17
|
+
const { strings } = useContext(PktFileUploadContext)
|
|
16
18
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
17
19
|
const inputId = useId()
|
|
18
20
|
|
|
@@ -21,7 +23,7 @@ const RenameFile = ({ initialValue, disabled, onSave, onCancel }: IRenameFilePro
|
|
|
21
23
|
return (
|
|
22
24
|
<>
|
|
23
25
|
<label htmlFor={inputId} className="pkt-sr-only">
|
|
24
|
-
|
|
26
|
+
{strings.renameInputLabel}
|
|
25
27
|
</label>
|
|
26
28
|
<input
|
|
27
29
|
id={inputId}
|
|
@@ -45,10 +47,10 @@ const RenameFile = ({ initialValue, disabled, onSave, onCancel }: IRenameFilePro
|
|
|
45
47
|
}}
|
|
46
48
|
/>
|
|
47
49
|
<PktButton skin="secondary" size="small" disabled={disabled} onClick={save}>
|
|
48
|
-
|
|
50
|
+
{strings.save}
|
|
49
51
|
</PktButton>
|
|
50
52
|
<PktButton skin="tertiary" size="small" disabled={disabled} onClick={onCancel}>
|
|
51
|
-
|
|
53
|
+
{strings.cancel}
|
|
52
54
|
</PktButton>
|
|
53
55
|
</>
|
|
54
56
|
)
|
|
@@ -62,10 +64,10 @@ const RenameHiddenInput = ({ targetFilename }: { targetFilename: string }) => {
|
|
|
62
64
|
const resolveCurrentName = (context: TQueueOperationContext) =>
|
|
63
65
|
context.getAttribute<string>('targetFilename') || getDisplayFilename(context.file, '')
|
|
64
66
|
|
|
65
|
-
export const renameFileOperation: TQueueItemOperation
|
|
67
|
+
export const renameFileOperation = (strings: TPktStrings['fileupload']): TQueueItemOperation => ({
|
|
66
68
|
id: 'rename',
|
|
67
|
-
title:
|
|
68
|
-
ariaLabel:
|
|
69
|
+
title: strings.rename,
|
|
70
|
+
ariaLabel: strings.renameFile,
|
|
69
71
|
renderInlineUI: (context) => (
|
|
70
72
|
<RenameFile
|
|
71
73
|
initialValue={resolveCurrentName(context)}
|
|
@@ -78,5 +80,7 @@ export const renameFileOperation: TQueueItemOperation = {
|
|
|
78
80
|
onCancel={context.close}
|
|
79
81
|
/>
|
|
80
82
|
),
|
|
81
|
-
renderHidden: (context) =>
|
|
82
|
-
}
|
|
83
|
+
renderHidden: (context) => (
|
|
84
|
+
<RenameHiddenInput key={`rename${context.file.fileId}`} targetFilename={resolveCurrentName(context)} />
|
|
85
|
+
),
|
|
86
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useFileAttributes } from './useFileAttributes'
|
|
2
2
|
export { useImagePreview } from './useImagePreview'
|
|
3
|
+
export { useImageObjectUrl } from './useImageObjectUrl'
|
|
3
4
|
export { useOperationState } from './useOperationState'
|
|
4
5
|
export { useRequiredFormValidation } from './useRequiredFormValidation'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useImageObjectUrl = (file: File | undefined): string | null => {
|
|
4
|
+
const [entry, setEntry] = useState<{ file: File; url: string } | null>(null)
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!file?.type.startsWith('image/')) return
|
|
8
|
+
const url = URL.createObjectURL(file)
|
|
9
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
10
|
+
setEntry({ file, url })
|
|
11
|
+
return () => URL.revokeObjectURL(url)
|
|
12
|
+
}, [file])
|
|
13
|
+
|
|
14
|
+
return entry && entry.file === file ? entry.url : null
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import { TFileId, TQueueItemOperation } from '../types'
|
|
4
4
|
|
|
@@ -9,21 +9,14 @@ export const useOperationState = (queueItemOperations: TQueueItemOperation[]) =>
|
|
|
9
9
|
// the stored id would re-activate a freshly-added operation with the same id
|
|
10
10
|
// (e.g. an extension re-mounted). Drop any stale entries on list changes so the
|
|
11
11
|
// activation state can never refer to an operation that no longer exists.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else {
|
|
21
|
-
changed = true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return changed ? next : prev
|
|
25
|
-
})
|
|
26
|
-
}, [queueItemOperations])
|
|
12
|
+
const [prevOperations, setPrevOperations] = useState(queueItemOperations)
|
|
13
|
+
if (queueItemOperations !== prevOperations) {
|
|
14
|
+
setPrevOperations(queueItemOperations)
|
|
15
|
+
const validIds = new Set(queueItemOperations.map((op) => op.id))
|
|
16
|
+
const entries = Object.entries(activatedIds)
|
|
17
|
+
const kept = entries.filter(([, opId]) => validIds.has(opId))
|
|
18
|
+
if (kept.length !== entries.length) setActivatedIds(Object.fromEntries(kept))
|
|
19
|
+
}
|
|
27
20
|
|
|
28
21
|
const getActivated = useCallback(
|
|
29
22
|
(fileId: TFileId): TQueueItemOperation | undefined => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Re-export all hooks from the hooks folder
|
|
2
2
|
export { useFileAttributes } from './hooks/useFileAttributes'
|
|
3
3
|
export { useImagePreview } from './hooks/useImagePreview'
|
|
4
|
+
export { useImageObjectUrl } from './hooks/useImageObjectUrl'
|
|
4
5
|
export { useOperationState } from './hooks/useOperationState'
|
|
5
6
|
export { useRequiredFormValidation } from './hooks/useRequiredFormValidation'
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
TFileUploadStrategy,
|
|
8
8
|
TTransferProgress,
|
|
9
9
|
} from 'shared-types'
|
|
10
|
+
import type { TPktStrings } from 'shared-strings'
|
|
10
11
|
|
|
11
12
|
import { uuidish } from '../../utils/stringutils'
|
|
12
13
|
|
|
@@ -37,7 +38,12 @@ export class FileItem implements IFileItem {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/** Internal context used by queue item operations and hidden inputs. */
|
|
40
|
-
export type TPktFileUploadContext = {
|
|
41
|
+
export type TPktFileUploadContext = {
|
|
42
|
+
name?: string
|
|
43
|
+
multiple: boolean
|
|
44
|
+
id?: string
|
|
45
|
+
strings: TPktStrings['fileupload']
|
|
46
|
+
}
|
|
41
47
|
export const PktFileUploadContext = createContext<TPktFileUploadContext>({} as TPktFileUploadContext)
|
|
42
48
|
|
|
43
49
|
/** The value type for `PktFileUpload` (`value` / `defaultValue`). */
|
|
@@ -410,10 +410,16 @@ export const PktHeaderGlobal = forwardRef(
|
|
|
410
410
|
id={MENU_ID}
|
|
411
411
|
>
|
|
412
412
|
{localeData ? (
|
|
413
|
-
<PktHeaderMenu
|
|
413
|
+
<PktHeaderMenu
|
|
414
|
+
data={effectiveData}
|
|
415
|
+
locale={locale}
|
|
416
|
+
open
|
|
417
|
+
mobileBreakpoint={mobileBreakpoint}
|
|
418
|
+
strings={strings}
|
|
419
|
+
/>
|
|
414
420
|
) : (
|
|
415
421
|
<nav className="pkt-header-menu pkt-header-menu--open">
|
|
416
|
-
<p className="pkt-header-menu__error">
|
|
422
|
+
<p className="pkt-header-menu__error">{headerStrings.menuLoadError}</p>
|
|
417
423
|
</nav>
|
|
418
424
|
)}
|
|
419
425
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@testing-library/jest-dom'
|
|
2
2
|
|
|
3
|
-
import { fireEvent, render, screen } from '@testing-library/react'
|
|
3
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
4
4
|
import { resetPktStrings, setPktStrings } from 'shared-strings'
|
|
5
5
|
import { vi } from 'vitest'
|
|
6
6
|
|
|
@@ -134,7 +134,10 @@ describe('PktHeaderService', () => {
|
|
|
134
134
|
})
|
|
135
135
|
|
|
136
136
|
describe('strings', () => {
|
|
137
|
-
afterEach(() =>
|
|
137
|
+
afterEach(() => {
|
|
138
|
+
cleanup()
|
|
139
|
+
resetPktStrings()
|
|
140
|
+
})
|
|
138
141
|
|
|
139
142
|
it('labels the logo link from the string catalogue', () => {
|
|
140
143
|
const { container } = render(<PktHeaderService serviceName="Svc" />)
|
|
@@ -135,11 +135,11 @@ export const PktHeaderService = forwardRef(
|
|
|
135
135
|
|
|
136
136
|
const [openMenu, setOpenMenu] = useState<'none' | 'slot' | 'search' | 'user'>(openedMenu || 'none')
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
138
|
+
const [prevOpenedMenu, setPrevOpenedMenu] = useState(openedMenu)
|
|
139
|
+
if (openedMenu !== prevOpenedMenu) {
|
|
140
|
+
setPrevOpenedMenu(openedMenu)
|
|
141
|
+
if (openedMenu !== undefined) setOpenMenu(openedMenu)
|
|
142
|
+
}
|
|
143
143
|
|
|
144
144
|
const [alignSlotRight, setAlignSlotRight] = useState(false)
|
|
145
145
|
const [alignSearchRight, setAlignSearchRight] = useState(false)
|
|
@@ -20,9 +20,11 @@ import {
|
|
|
20
20
|
type THeaderFooterApi,
|
|
21
21
|
type THeaderMenuLocale,
|
|
22
22
|
} from 'shared-types'
|
|
23
|
+
import type { IPktStringsProps } from 'shared-strings'
|
|
23
24
|
import { deriveSocialIcon, fetchHeaderFooterData, mapOdsIcon, selectLocaleData } from 'shared-utils/header-footer'
|
|
24
25
|
|
|
25
26
|
import { useElementWidth } from '../../hooks/useElementWidth'
|
|
27
|
+
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
26
28
|
import { PktAccordion } from '../accordion/Accordion'
|
|
27
29
|
import { PktAccordionItem } from '../accordion/AccordionItem'
|
|
28
30
|
import { PktIcon } from '../icon/Icon'
|
|
@@ -36,7 +38,8 @@ export type {
|
|
|
36
38
|
IHeaderMenuServices,
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export interface IPktHeaderMenu
|
|
41
|
+
export interface IPktHeaderMenu
|
|
42
|
+
extends Omit<HTMLAttributes<HTMLElement>, 'onError'>, ISharedPktHeaderMenu, IPktStringsProps<'header'> {
|
|
40
43
|
/** Forwarded to the host element. */
|
|
41
44
|
ref?: Ref<HTMLElement>
|
|
42
45
|
/** Fired when the payload has been fetched (or `data` was supplied). */
|
|
@@ -69,8 +72,10 @@ export const PktHeaderMenu = ({
|
|
|
69
72
|
onDataLoaded,
|
|
70
73
|
onDataError,
|
|
71
74
|
ref,
|
|
75
|
+
strings,
|
|
72
76
|
...rest
|
|
73
77
|
}: IPktHeaderMenu) => {
|
|
78
|
+
const headerStrings = usePktStrings(['header'], strings).header
|
|
74
79
|
const [fetchState, setFetchState] = useState<LoadState>('loading')
|
|
75
80
|
const [fetchedData, setFetchedData] = useState<THeaderFooterApi | undefined>(undefined)
|
|
76
81
|
const loadState: LoadState = data ? 'ready' : fetchState
|
|
@@ -129,7 +134,7 @@ export const PktHeaderMenu = ({
|
|
|
129
134
|
if (loadState === 'loading') {
|
|
130
135
|
return (
|
|
131
136
|
<nav {...rest} ref={setRootRef} className={hostClasses} aria-busy="true">
|
|
132
|
-
<p className="pkt-header-menu__loading">
|
|
137
|
+
<p className="pkt-header-menu__loading">{headerStrings.menuLoading}</p>
|
|
133
138
|
</nav>
|
|
134
139
|
)
|
|
135
140
|
}
|
|
@@ -137,7 +142,7 @@ export const PktHeaderMenu = ({
|
|
|
137
142
|
if (loadState === 'error' || !localeData) {
|
|
138
143
|
return (
|
|
139
144
|
<nav {...rest} ref={setRootRef} className={hostClasses} aria-hidden={!open}>
|
|
140
|
-
<p className="pkt-header-menu__error">
|
|
145
|
+
<p className="pkt-header-menu__error">{headerStrings.menuLoadError}</p>
|
|
141
146
|
</nav>
|
|
142
147
|
)
|
|
143
148
|
}
|
|
@@ -9,6 +9,7 @@ import { usePktStrings } from '../../hooks/usePktStrings'
|
|
|
9
9
|
import { Representing, User, UserMenuItem } from '../header/types'
|
|
10
10
|
import { PktIcon } from '../icon/Icon'
|
|
11
11
|
import { PktLink } from '../link/Link'
|
|
12
|
+
import { withStableKeys } from '../../utils/stableKeys'
|
|
12
13
|
|
|
13
14
|
// Internal type for rendering links/buttons (supports both href and onClick)
|
|
14
15
|
interface IInternalMenuItemBase {
|
|
@@ -74,9 +75,9 @@ const LinkOrButtonComponent = ({ item, className }: { item: TInternalMenuItem; c
|
|
|
74
75
|
const LinkSection = ({ links }: { links: TInternalMenuItem[] }) => {
|
|
75
76
|
return (
|
|
76
77
|
<ul className="pkt-user-menu__sublist">
|
|
77
|
-
{links.map((item,
|
|
78
|
+
{withStableKeys(links, (item) => `${'href' in item ? item.href : ''}|${item.title}`).map(({ item, key }) => {
|
|
78
79
|
return (
|
|
79
|
-
<li key={
|
|
80
|
+
<li key={key} className="pkt-user-menu__subitem">
|
|
80
81
|
<LinkOrButtonComponent item={item} />
|
|
81
82
|
</li>
|
|
82
83
|
)
|
|
@@ -98,38 +98,31 @@ export const PktInputWrapper = forwardRef(
|
|
|
98
98
|
const tagClasses = ['pkt-tag', 'pkt-tag--small', 'pkt-tag--thin-text'].join(' ')
|
|
99
99
|
|
|
100
100
|
const counterExceeded = isCounterExceeded(counterCurrent, counterMaxLength)
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
) : null
|
|
101
|
+
const counterContent = showCounter ? (
|
|
102
|
+
<>
|
|
103
|
+
<div className="pkt-input__counter" aria-hidden="true">
|
|
104
|
+
{counterCurrent}
|
|
105
|
+
{counterMaxLength ? `/${counterMaxLength}` : ''}
|
|
106
|
+
</div>
|
|
107
|
+
<div className="pkt-sr-only" id={counterStatusId(forId)} aria-live="polite">
|
|
108
|
+
{counterExceeded
|
|
109
|
+
? formatString(s.validation.counterExceeded, {
|
|
110
|
+
current: counterCurrent,
|
|
111
|
+
max: counterMaxLength ?? 0,
|
|
112
|
+
})
|
|
113
|
+
: ''}
|
|
114
|
+
</div>
|
|
115
|
+
</>
|
|
116
|
+
) : null
|
|
118
117
|
|
|
119
118
|
const renderTags = () => {
|
|
120
119
|
return (
|
|
121
120
|
<>
|
|
122
121
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
123
122
|
{optionalTag && (
|
|
124
|
-
<span className={tagClasses + ` pkt-tag--blue-light`}>
|
|
125
|
-
{optionalText ?? s.forms.optional}
|
|
126
|
-
</span>
|
|
127
|
-
)}
|
|
128
|
-
{requiredTag && (
|
|
129
|
-
<span className={tagClasses + ` pkt-tag--beige`}>
|
|
130
|
-
{requiredText ?? s.forms.required}
|
|
131
|
-
</span>
|
|
123
|
+
<span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText ?? s.forms.optional}</span>
|
|
132
124
|
)}
|
|
125
|
+
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
133
126
|
</>
|
|
134
127
|
)
|
|
135
128
|
}
|
|
@@ -183,9 +176,9 @@ export const PktInputWrapper = forwardRef(
|
|
|
183
176
|
<>
|
|
184
177
|
{renderLabel()}
|
|
185
178
|
{renderHelptext()}
|
|
186
|
-
{counterTop &&
|
|
179
|
+
{counterTop && counterContent}
|
|
187
180
|
{children}
|
|
188
|
-
{counterBottom &&
|
|
181
|
+
{counterBottom && counterContent}
|
|
189
182
|
{hasError && errorMessage && (
|
|
190
183
|
<div className="pkt-inputwrapper__alert-wrapper">
|
|
191
184
|
<PktAlert skin="error" size={errorAlertSize} aria-live="assertive" role="alert" id={`${forId}-error`}>
|
|
@@ -12,8 +12,7 @@ declare global {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if (typeof window !== 'undefined') {
|
|
15
|
-
window.pktAnimationPath =
|
|
16
|
-
window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
|
|
15
|
+
window.pktAnimationPath = window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export type TPktLoaderVariant = 'blue' | 'rainbow' | 'shapes'
|
|
@@ -78,17 +77,21 @@ export const PktLoader = forwardRef<HTMLDivElement, IPktLoader>(function PktLoad
|
|
|
78
77
|
},
|
|
79
78
|
ref,
|
|
80
79
|
) {
|
|
81
|
-
const [
|
|
80
|
+
const [delayElapsed, setDelayElapsed] = useState(false)
|
|
81
|
+
const [prevDelay, setPrevDelay] = useState(delay)
|
|
82
|
+
if (delay !== prevDelay) {
|
|
83
|
+
setPrevDelay(delay)
|
|
84
|
+
setDelayElapsed(false)
|
|
85
|
+
}
|
|
82
86
|
|
|
83
87
|
useEffect(() => {
|
|
84
|
-
if (delay
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return () => clearTimeout(handle)
|
|
88
|
-
}
|
|
89
|
-
setShouldDisplayLoader(true)
|
|
88
|
+
if (delay <= 0) return
|
|
89
|
+
const handle = setTimeout(() => setDelayElapsed(true), delay)
|
|
90
|
+
return () => clearTimeout(handle)
|
|
90
91
|
}, [delay])
|
|
91
92
|
|
|
93
|
+
const shouldDisplayLoader = delay <= 0 || delayElapsed
|
|
94
|
+
|
|
92
95
|
const classes = classNames(
|
|
93
96
|
'pkt-loader',
|
|
94
97
|
inline ? 'pkt-loader--inline' : 'pkt-loader--box',
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { createRef, FC, HTMLAttributes, ReactNode, useCallback, useState } from 'react'
|
|
5
|
+
import type { IPktStringsProps } from 'shared-strings'
|
|
5
6
|
import type { TMessageboxSkin } from 'shared-types'
|
|
6
7
|
|
|
8
|
+
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
7
9
|
import { PktIcon } from '../icon/Icon'
|
|
8
10
|
|
|
9
11
|
export type { TMessageboxSkin }
|
|
10
12
|
|
|
11
|
-
export interface IPktMessagebox extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
13
|
+
export interface IPktMessagebox extends Omit<HTMLAttributes<HTMLDivElement>, 'title'>, IPktStringsProps<'generic'> {
|
|
12
14
|
skin?: TMessageboxSkin
|
|
13
15
|
title?: ReactNode
|
|
14
16
|
compact?: boolean
|
|
@@ -24,8 +26,10 @@ export const PktMessagebox: FC<IPktMessagebox> = ({
|
|
|
24
26
|
compact,
|
|
25
27
|
closable,
|
|
26
28
|
onClose,
|
|
29
|
+
strings,
|
|
27
30
|
...props
|
|
28
31
|
}: IPktMessagebox) => {
|
|
32
|
+
const s = usePktStrings(['generic'], strings)
|
|
29
33
|
const [closed, setClosed] = useState(false)
|
|
30
34
|
|
|
31
35
|
const classes = {
|
|
@@ -52,7 +56,7 @@ export const PktMessagebox: FC<IPktMessagebox> = ({
|
|
|
52
56
|
<button
|
|
53
57
|
onClick={close}
|
|
54
58
|
className={'pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only'}
|
|
55
|
-
aria-label={
|
|
59
|
+
aria-label={s.generic.close}
|
|
56
60
|
>
|
|
57
61
|
<PktIcon name="close" className="pkt-link__icon" />
|
|
58
62
|
</button>
|