@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
|
@@ -72,6 +72,10 @@ export declare const nb: {
|
|
|
72
72
|
alert: {
|
|
73
73
|
lastUpdated: string;
|
|
74
74
|
};
|
|
75
|
+
card: {
|
|
76
|
+
tagsLabelOne: string;
|
|
77
|
+
tagsLabelOther: string;
|
|
78
|
+
};
|
|
75
79
|
tag: {
|
|
76
80
|
remove: string;
|
|
77
81
|
};
|
|
@@ -90,10 +94,15 @@ export declare const nb: {
|
|
|
90
94
|
representing: string;
|
|
91
95
|
orgNumber: string;
|
|
92
96
|
changeRepresentation: string;
|
|
97
|
+
menuLoading: string;
|
|
98
|
+
menuLoadError: string;
|
|
93
99
|
};
|
|
94
100
|
listbox: {
|
|
95
101
|
searchLabel: string;
|
|
96
102
|
searchPlaceholder: string;
|
|
103
|
+
empty: string;
|
|
104
|
+
addValue: string;
|
|
105
|
+
maxReached: string;
|
|
97
106
|
};
|
|
98
107
|
combobox: {
|
|
99
108
|
noResults: string;
|
|
@@ -117,6 +126,8 @@ export declare const nb: {
|
|
|
117
126
|
dropZoneOpenFileDialogSingle: string;
|
|
118
127
|
dropZoneOpenFileDialogMultipleThumbnail: string;
|
|
119
128
|
dropZoneOpenFileDialogSingleThumbnail: string;
|
|
129
|
+
openFileDialogLabelMultiple: string;
|
|
130
|
+
openFileDialogLabelSingle: string;
|
|
120
131
|
supportedFormatsPrefix: string;
|
|
121
132
|
invalidFormat: string;
|
|
122
133
|
sizeTooLarge: string;
|
|
@@ -131,5 +142,28 @@ export declare const nb: {
|
|
|
131
142
|
srFilesAdded: string;
|
|
132
143
|
srFilesUploadedOfTotal: string;
|
|
133
144
|
srFilesFailedOfTotal: string;
|
|
145
|
+
filename: string;
|
|
146
|
+
uploading: string;
|
|
147
|
+
uploadingFile: string;
|
|
148
|
+
save: string;
|
|
149
|
+
cancel: string;
|
|
150
|
+
cancelUpload: string;
|
|
151
|
+
removeFailed: string;
|
|
152
|
+
removeFailedFile: string;
|
|
153
|
+
remove: string;
|
|
154
|
+
removeFile: string;
|
|
155
|
+
rename: string;
|
|
156
|
+
renameFile: string;
|
|
157
|
+
renameInputLabel: string;
|
|
158
|
+
addComment: string;
|
|
159
|
+
editComment: string;
|
|
160
|
+
saveComment: string;
|
|
161
|
+
deleteComment: string;
|
|
162
|
+
commentPlaceholder: string;
|
|
163
|
+
commentText: string;
|
|
164
|
+
commentTimestamp: string;
|
|
165
|
+
previewPrevious: string;
|
|
166
|
+
previewNext: string;
|
|
167
|
+
previewImageAlt: string;
|
|
134
168
|
};
|
|
135
169
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "19.3.
|
|
3
|
+
"version": "19.3.1",
|
|
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",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
102
102
|
},
|
|
103
103
|
"license": "MIT",
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "40680531212b05400461eaf3ce7eddc3f14edd85"
|
|
105
105
|
}
|
|
@@ -18,7 +18,7 @@ describe('PktAlert', () => {
|
|
|
18
18
|
Hello World
|
|
19
19
|
</PktAlert>,
|
|
20
20
|
)
|
|
21
|
-
fireEvent.click(getByLabelText('
|
|
21
|
+
fireEvent.click(getByLabelText('Lukk'))
|
|
22
22
|
await waitFor(() => {
|
|
23
23
|
expect(onClose).toHaveBeenCalledTimes(1)
|
|
24
24
|
})
|
|
@@ -64,10 +64,10 @@ describe('PktAlert', () => {
|
|
|
64
64
|
${''} | ${undefined}
|
|
65
65
|
${null} | ${undefined}
|
|
66
66
|
${(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)} | ${'<span>Complex <strong>title</strong></span>'}
|
|
67
|
+
<span>
|
|
68
|
+
Complex <strong>title</strong>
|
|
69
|
+
</span>
|
|
70
|
+
)} | ${'<span>Complex <strong>title</strong></span>'}
|
|
71
71
|
`('support complex title %$', async ({ title, expected }) => {
|
|
72
72
|
const { container } = render(<PktAlert title={title}>Alert text</PktAlert>)
|
|
73
73
|
const titleElement = container.querySelector('.pkt-alert__title')
|
|
@@ -84,7 +84,7 @@ export const PktAlert: FC<IPktAlert> = ({
|
|
|
84
84
|
<div className="pkt-alert__close">
|
|
85
85
|
<PktButton
|
|
86
86
|
tabIndex={0}
|
|
87
|
-
aria-label=
|
|
87
|
+
aria-label={s.generic.close}
|
|
88
88
|
size={size}
|
|
89
89
|
type="button"
|
|
90
90
|
skin="tertiary"
|
|
@@ -100,9 +100,7 @@ export const PktAlert: FC<IPktAlert> = ({
|
|
|
100
100
|
|
|
101
101
|
<div className="pkt-alert__text">{children}</div>
|
|
102
102
|
|
|
103
|
-
{date && (
|
|
104
|
-
<div className="pkt-alert__date">{formatString(s.alert.lastUpdated, { date })}</div>
|
|
105
|
-
)}
|
|
103
|
+
{date && <div className="pkt-alert__date">{formatString(s.alert.lastUpdated, { date })}</div>}
|
|
106
104
|
</div>
|
|
107
105
|
</div>
|
|
108
106
|
)
|
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { ForwardedRef, forwardRef, type AnchorHTMLAttributes, type ReactNode } from 'react'
|
|
4
4
|
import { Link } from 'react-router-dom'
|
|
5
|
-
import type {
|
|
6
|
-
IBreadcrumb,
|
|
7
|
-
IPktBreadcrumbsBase,
|
|
8
|
-
TBreadcrumbsNavigationType,
|
|
9
|
-
TRenderLink,
|
|
10
|
-
} from 'shared-types'
|
|
5
|
+
import type { IBreadcrumb, IPktBreadcrumbsBase, TBreadcrumbsNavigationType, TRenderLink } from 'shared-types'
|
|
11
6
|
|
|
12
7
|
import { PktIcon } from '../icon/Icon'
|
|
13
8
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
9
|
+
import { withStableKeys } from '../../utils/stableKeys'
|
|
14
10
|
|
|
15
11
|
export type { IBreadcrumb }
|
|
16
12
|
|
|
@@ -18,8 +14,7 @@ export type { IBreadcrumb }
|
|
|
18
14
|
export type IBreadcrumbs = IBreadcrumb
|
|
19
15
|
|
|
20
16
|
export interface IPktBreadcrumbs
|
|
21
|
-
extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'children'>,
|
|
22
|
-
IPktBreadcrumbsBase {
|
|
17
|
+
extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'children'>, IPktBreadcrumbsBase {
|
|
23
18
|
navigationType?: TBreadcrumbsNavigationType
|
|
24
19
|
renderLink?: TRenderLink<ReactNode, AnchorHTMLAttributes<HTMLAnchorElement>>
|
|
25
20
|
}
|
|
@@ -56,8 +51,8 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
56
51
|
return (
|
|
57
52
|
<nav ref={ref} aria-label={s.breadcrumbs.ariaLabel} className={classes}>
|
|
58
53
|
<ol className="pkt-breadcrumbs__list pkt-breadcrumbs--desktop">
|
|
59
|
-
{slicedBreadcrumbs.map((item, index) => (
|
|
60
|
-
<li key={
|
|
54
|
+
{withStableKeys(slicedBreadcrumbs, (item) => `${item.href}|${item.text}`).map(({ item, key }, index) => (
|
|
55
|
+
<li key={key} className="pkt-breadcrumbs__item">
|
|
61
56
|
{index === slicedBreadcrumbs.length - 1 ? (
|
|
62
57
|
<span className="pkt-breadcrumbs__label" aria-current="true">
|
|
63
58
|
<span className="pkt-breadcrumbs__text">{item.text}</span>
|
|
@@ -68,7 +63,11 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
68
63
|
className: 'pkt-link pkt-link--icon-right pkt-breadcrumbs__label pkt-breadcrumbs__link',
|
|
69
64
|
children: (
|
|
70
65
|
<>
|
|
71
|
-
<PktIcon
|
|
66
|
+
<PktIcon
|
|
67
|
+
className="pkt-icon pkt-breadcrumbs__icon pkt-link__icon"
|
|
68
|
+
name="chevron-thin-right"
|
|
69
|
+
aria-hidden="true"
|
|
70
|
+
/>
|
|
72
71
|
<span className="pkt-breadcrumbs__text">{item.text}</span>
|
|
73
72
|
</>
|
|
74
73
|
),
|
|
@@ -84,7 +83,11 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
84
83
|
className: 'pkt-link pkt-link--icon-left pkt-breadcrumbs--mobile',
|
|
85
84
|
children: (
|
|
86
85
|
<>
|
|
87
|
-
<PktIcon
|
|
86
|
+
<PktIcon
|
|
87
|
+
className="pkt-back-link__icon pkt-icon pkt-link__icon"
|
|
88
|
+
name="chevron-thin-left"
|
|
89
|
+
aria-hidden="true"
|
|
90
|
+
/>
|
|
88
91
|
<span className="pkt-breadcrumbs__text">{backLink.text}</span>
|
|
89
92
|
</>
|
|
90
93
|
),
|
|
@@ -119,9 +119,7 @@ describe('PktCalendar', () => {
|
|
|
119
119
|
expect(grid).toHaveAttribute('aria-multiselectable', 'true')
|
|
120
120
|
|
|
121
121
|
// Select 3 dates - all should work
|
|
122
|
-
const availableDates = container.querySelectorAll(
|
|
123
|
-
'.pkt-calendar__date:not(.pkt-calendar__date--disabled)',
|
|
124
|
-
)
|
|
122
|
+
const availableDates = container.querySelectorAll('.pkt-calendar__date:not(.pkt-calendar__date--disabled)')
|
|
125
123
|
expect(availableDates.length).toBeGreaterThan(3)
|
|
126
124
|
|
|
127
125
|
fireEvent.click(availableDates[0])
|
|
@@ -139,6 +137,23 @@ describe('PktCalendar', () => {
|
|
|
139
137
|
expect(monthTitle?.textContent).toContain('Mars')
|
|
140
138
|
expect(monthTitle?.textContent).toContain('2024')
|
|
141
139
|
})
|
|
140
|
+
|
|
141
|
+
test('selected date takes precedence over currentmonth', () => {
|
|
142
|
+
const { container } = createCalendar({ currentmonth: '2024-03-15', selected: ['2024-08-10'] })
|
|
143
|
+
|
|
144
|
+
const monthTitle = container.querySelector('.pkt-calendar__month-title')
|
|
145
|
+
expect(monthTitle?.textContent).toContain('August')
|
|
146
|
+
expect(monthTitle?.textContent).toContain('2024')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('follows selected date when it changes', () => {
|
|
150
|
+
const { container, rerender } = render(<PktCalendar selected={['2024-08-10']} />)
|
|
151
|
+
rerender(<PktCalendar selected={['2025-01-05']} />)
|
|
152
|
+
|
|
153
|
+
const monthTitle = container.querySelector('.pkt-calendar__month-title')
|
|
154
|
+
expect(monthTitle?.textContent).toContain('Januar')
|
|
155
|
+
expect(monthTitle?.textContent).toContain('2025')
|
|
156
|
+
})
|
|
142
157
|
})
|
|
143
158
|
|
|
144
159
|
describe('Month navigation', () => {
|
|
@@ -172,9 +187,7 @@ describe('PktCalendar', () => {
|
|
|
172
187
|
const nextButton = container.querySelector('.pkt-calendar__next-month')
|
|
173
188
|
expect(nextButton).toBeInTheDocument()
|
|
174
189
|
|
|
175
|
-
const monthSelect = container.querySelector(
|
|
176
|
-
'.pkt-cal-month-picker select',
|
|
177
|
-
) as HTMLSelectElement
|
|
190
|
+
const monthSelect = container.querySelector('.pkt-cal-month-picker select') as HTMLSelectElement
|
|
178
191
|
const initialMonth = monthSelect?.value
|
|
179
192
|
|
|
180
193
|
fireEvent.click(nextButton!)
|
|
@@ -186,16 +199,12 @@ describe('PktCalendar', () => {
|
|
|
186
199
|
test('month navigation updates visible dates', () => {
|
|
187
200
|
const { container } = createCalendar({ withcontrols: true, currentmonth: '2024-06-15' })
|
|
188
201
|
|
|
189
|
-
const initialDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map(
|
|
190
|
-
(el) => el.textContent,
|
|
191
|
-
)
|
|
202
|
+
const initialDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map((el) => el.textContent)
|
|
192
203
|
|
|
193
204
|
const nextButton = container.querySelector('.pkt-calendar__next-month')
|
|
194
205
|
fireEvent.click(nextButton!)
|
|
195
206
|
|
|
196
|
-
const newDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map(
|
|
197
|
-
(el) => el.textContent,
|
|
198
|
-
)
|
|
207
|
+
const newDates = Array.from(container.querySelectorAll('.pkt-calendar__date')).map((el) => el.textContent)
|
|
199
208
|
expect(newDates).not.toEqual(initialDates)
|
|
200
209
|
})
|
|
201
210
|
})
|
|
@@ -236,10 +245,7 @@ describe('PktCalendar', () => {
|
|
|
236
245
|
withcontrols: true,
|
|
237
246
|
strings: {
|
|
238
247
|
dates: {
|
|
239
|
-
months: [
|
|
240
|
-
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
241
|
-
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
|
|
242
|
-
],
|
|
248
|
+
months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
243
249
|
},
|
|
244
250
|
},
|
|
245
251
|
})
|
|
@@ -19,9 +19,7 @@ export const CalendarNav = ({
|
|
|
19
19
|
}: ICalendarNavProps) => {
|
|
20
20
|
const renderMonthNavButton = (direction: 'prev' | 'next') => {
|
|
21
21
|
const isPrev = direction === 'prev'
|
|
22
|
-
const isAllowed = isPrev
|
|
23
|
-
? checkPrevMonthAllowed(year, month, earliest)
|
|
24
|
-
: checkNextMonthAllowed(year, month, latest)
|
|
22
|
+
const isAllowed = isPrev ? checkPrevMonthAllowed(year, month, earliest) : checkNextMonthAllowed(year, month, latest)
|
|
25
23
|
const label = isPrev ? strings.prevMonth : strings.nextMonth
|
|
26
24
|
const iconName = isPrev ? 'chevron-thin-left' : 'chevron-thin-right'
|
|
27
25
|
const btnClassName = isPrev ? 'pkt-calendar__prev-month' : 'pkt-calendar__next-month'
|
|
@@ -43,7 +41,9 @@ export const CalendarNav = ({
|
|
|
43
41
|
'pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only',
|
|
44
42
|
btnClassName,
|
|
45
43
|
!isAllowed && 'pkt-invisible',
|
|
46
|
-
]
|
|
44
|
+
]
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.join(' ')}
|
|
47
47
|
data-disabled={!isAllowed ? 'disabled' : undefined}
|
|
48
48
|
aria-disabled={!isAllowed || undefined}
|
|
49
49
|
tabIndex={isAllowed ? 0 : -1}
|
|
@@ -59,7 +59,9 @@ export const CalendarNav = ({
|
|
|
59
59
|
if (withcontrols) {
|
|
60
60
|
return (
|
|
61
61
|
<div className="pkt-cal-month-picker">
|
|
62
|
-
<label htmlFor={`${componentId}-monthnav`} className="pkt-hide">
|
|
62
|
+
<label htmlFor={`${componentId}-monthnav`} className="pkt-hide">
|
|
63
|
+
{strings.month}
|
|
64
|
+
</label>
|
|
63
65
|
<select
|
|
64
66
|
aria-label={strings.month}
|
|
65
67
|
className="pkt-input pkt-input-compact"
|
|
@@ -71,12 +73,15 @@ export const CalendarNav = ({
|
|
|
71
73
|
}}
|
|
72
74
|
>
|
|
73
75
|
{strings.months.map((monthName, index) => (
|
|
76
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
74
77
|
<option key={index} value={index}>
|
|
75
78
|
{monthName}
|
|
76
79
|
</option>
|
|
77
80
|
))}
|
|
78
81
|
</select>
|
|
79
|
-
<label htmlFor={`${componentId}-yearnav`} className="pkt-hide">
|
|
82
|
+
<label htmlFor={`${componentId}-yearnav`} className="pkt-hide">
|
|
83
|
+
{strings.year}
|
|
84
|
+
</label>
|
|
80
85
|
<input
|
|
81
86
|
aria-label={strings.year}
|
|
82
87
|
className="pkt-input pkt-cal-input-year pkt-input-compact"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useId, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import { formatISODate, newDate, parseISODateString, newDateFromDate, todayInTz } from 'shared-utils/date-utils'
|
|
3
3
|
import { CALENDAR_DEFAULTS, type IDateConstraints, type TDateRangeMap } from 'shared-types/calendar'
|
|
4
4
|
import { isDateExcluded, isDayDisabled as checkDayDisabled } from 'shared-utils/calendar/date-validation'
|
|
@@ -59,10 +59,7 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
|
|
|
59
59
|
[catalog],
|
|
60
60
|
)
|
|
61
61
|
|
|
62
|
-
const todayDate = useMemo(
|
|
63
|
-
() => (todayProp ? parseISODateString(todayProp) : todayInTz()),
|
|
64
|
-
[todayProp],
|
|
65
|
-
)
|
|
62
|
+
const todayDate = useMemo(() => (todayProp ? parseISODateString(todayProp) : todayInTz()), [todayProp])
|
|
66
63
|
|
|
67
64
|
const excludedates = useMemo<Date[]>(() => {
|
|
68
65
|
if (!excludedatesProp) return []
|
|
@@ -75,45 +72,19 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
|
|
|
75
72
|
|
|
76
73
|
const _selected = useMemo(() => convertSelectedToDates(activeSelected), [activeSelected])
|
|
77
74
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const [focusedDate, setFocusedDate] = useState<string | null>(null)
|
|
85
|
-
|
|
86
|
-
const calendarRef = useRef<HTMLDivElement>(null)
|
|
87
|
-
const selectableDatesRef = useRef<{ currentDateISO: string; isDisabled: boolean; tabindex: string }[]>([])
|
|
88
|
-
const tabIndexSetRef = useRef<number>(0)
|
|
89
|
-
const currentmonthtouchedRef = useRef<boolean>(false)
|
|
90
|
-
const initializedRef = useRef<boolean>(false)
|
|
91
|
-
|
|
92
|
-
const dateConstraints = useMemo<IDateConstraints>(
|
|
93
|
-
() => ({ earliest, latest, excludedates, excludeweekdays }),
|
|
94
|
-
[earliest, latest, excludedates, excludeweekdays],
|
|
95
|
-
)
|
|
75
|
+
const resolveInitialMonth = (): Date => {
|
|
76
|
+
const lastSelected =
|
|
77
|
+
activeSelected.length > 0 && activeSelected[0] !== ''
|
|
78
|
+
? parseISODateString(activeSelected[activeSelected.length - 1])
|
|
79
|
+
: null
|
|
80
|
+
if (lastSelected && !isNaN(lastSelected.getTime())) return lastSelected
|
|
96
81
|
|
|
97
|
-
useEffect(() => {
|
|
98
82
|
let effectiveMonth: Date | null = null
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
} else if (typeof currentmonthProp === 'string') {
|
|
104
|
-
effectiveMonth = parseISODateString(currentmonthProp)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!effectiveMonth || isNaN(effectiveMonth.getTime())) {
|
|
109
|
-
if (activeSelected.length > 0 && activeSelected[0] !== '') {
|
|
110
|
-
const d = parseISODateString(activeSelected[activeSelected.length - 1])
|
|
111
|
-
effectiveMonth = isNaN(d.getTime()) ? newDateFromDate(todayDate) : d
|
|
112
|
-
} else {
|
|
113
|
-
effectiveMonth = newDateFromDate(todayDate)
|
|
114
|
-
}
|
|
83
|
+
if (currentmonthProp instanceof Date) {
|
|
84
|
+
effectiveMonth = newDateFromDate(currentmonthProp)
|
|
85
|
+
} else if (typeof currentmonthProp === 'string') {
|
|
86
|
+
effectiveMonth = parseISODateString(currentmonthProp)
|
|
115
87
|
}
|
|
116
|
-
|
|
117
88
|
if (!effectiveMonth || isNaN(effectiveMonth.getTime())) {
|
|
118
89
|
effectiveMonth = newDateFromDate(todayDate)
|
|
119
90
|
}
|
|
@@ -131,34 +102,50 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
|
|
|
131
102
|
effectiveMonth = earliestDate
|
|
132
103
|
}
|
|
133
104
|
}
|
|
105
|
+
return effectiveMonth
|
|
106
|
+
}
|
|
134
107
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
108
|
+
const [year, setYear] = useState<number>(() => resolveInitialMonth().getFullYear())
|
|
109
|
+
const [month, setMonth] = useState<number>(() => resolveInitialMonth().getMonth())
|
|
110
|
+
|
|
111
|
+
const [inRange, setInRange] = useState<TDateRangeMap>(() =>
|
|
112
|
+
range && _selected.length === 2 ? calculateRangeMap(_selected[0], _selected[1]) : {},
|
|
113
|
+
)
|
|
114
|
+
const [rangeHovered, setRangeHovered] = useState<Date | null>(null)
|
|
139
115
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
116
|
+
const [focusedDate, setFocusedDate] = useState<string | null>(null)
|
|
117
|
+
|
|
118
|
+
const calendarRef = useRef<HTMLDivElement>(null)
|
|
119
|
+
const selectableDatesRef = useRef<{ currentDateISO: string; isDisabled: boolean; tabindex: string }[]>([])
|
|
120
|
+
const tabIndexSetRef = useRef<number>(0)
|
|
121
|
+
const [currentmonthTouched, setCurrentmonthTouched] = useState(false)
|
|
144
122
|
|
|
145
|
-
|
|
123
|
+
const [prevActiveSelected, setPrevActiveSelected] = useState(activeSelected)
|
|
124
|
+
if (activeSelected !== prevActiveSelected) {
|
|
125
|
+
setPrevActiveSelected(activeSelected)
|
|
126
|
+
if (!currentmonthTouched && activeSelected.length > 0 && activeSelected[0] !== '') {
|
|
146
127
|
const d = parseISODateString(activeSelected[activeSelected.length - 1])
|
|
147
128
|
if (!isNaN(d.getTime())) {
|
|
148
129
|
setYear(d.getFullYear())
|
|
149
130
|
setMonth(d.getMonth())
|
|
150
131
|
}
|
|
151
132
|
}
|
|
152
|
-
}
|
|
133
|
+
}
|
|
153
134
|
|
|
154
|
-
|
|
155
|
-
|
|
135
|
+
const [prevRangeInput, setPrevRangeInput] = useState({ range, _selected })
|
|
136
|
+
if (range !== prevRangeInput.range || _selected !== prevRangeInput._selected) {
|
|
137
|
+
setPrevRangeInput({ range, _selected })
|
|
156
138
|
if (range && _selected.length === 2) {
|
|
157
139
|
setInRange(calculateRangeMap(_selected[0], _selected[1]))
|
|
158
140
|
} else if (!range || _selected.length < 2) {
|
|
159
141
|
setInRange({})
|
|
160
142
|
}
|
|
161
|
-
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const dateConstraints = useMemo<IDateConstraints>(
|
|
146
|
+
() => ({ earliest, latest, excludedates, excludeweekdays }),
|
|
147
|
+
[earliest, latest, excludedates, excludeweekdays],
|
|
148
|
+
)
|
|
162
149
|
|
|
163
150
|
const updateSelected = useCallback(
|
|
164
151
|
(newSelected: string[]) => {
|
|
@@ -180,7 +167,7 @@ export function useCalendarState(props: IPktCalendar): ICalendarState {
|
|
|
180
167
|
tabIndexSetRef.current = 0
|
|
181
168
|
setFocusedDate(null)
|
|
182
169
|
selectableDatesRef.current = []
|
|
183
|
-
|
|
170
|
+
setCurrentmonthTouched(true)
|
|
184
171
|
}, [])
|
|
185
172
|
|
|
186
173
|
const prevMonth = useCallback(() => {
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { forwardRef, HTMLAttributes, ReactNode, Ref } from 'react'
|
|
5
|
+
import { plural, type IPktStringsProps } from 'shared-strings'
|
|
5
6
|
import { CARD_DEFAULTS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
|
|
6
7
|
|
|
7
8
|
import { PktHeading } from '../heading/Heading'
|
|
8
9
|
import { PktTag } from '../tag/Tag'
|
|
10
|
+
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
11
|
+
import { withStableKeys } from '../../utils/stableKeys'
|
|
9
12
|
|
|
10
13
|
export type { TCardSkin, TLayout }
|
|
11
14
|
|
|
12
|
-
export interface IPktCard extends IPktCardBase, Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
|
15
|
+
export interface IPktCard extends IPktCardBase, Omit<HTMLAttributes<HTMLElement>, 'title'>, IPktStringsProps<'card'> {
|
|
13
16
|
children?: ReactNode
|
|
14
17
|
ref?: Ref<HTMLElement>
|
|
15
18
|
}
|
|
@@ -38,10 +41,12 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
38
41
|
tagPosition = CARD_DEFAULTS.tagPosition,
|
|
39
42
|
zoom = CARD_DEFAULTS.zoom,
|
|
40
43
|
tags = [],
|
|
44
|
+
strings,
|
|
41
45
|
...props
|
|
42
46
|
},
|
|
43
47
|
ref,
|
|
44
48
|
) => {
|
|
49
|
+
const s = usePktStrings(['card'], strings)
|
|
45
50
|
const classes = classNames({
|
|
46
51
|
'pkt-card': true,
|
|
47
52
|
[`pkt-card--${skin}`]: skin,
|
|
@@ -57,7 +62,14 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
57
62
|
const renderImage = () => {
|
|
58
63
|
if (!image?.src) return null
|
|
59
64
|
return (
|
|
60
|
-
<div
|
|
65
|
+
<div
|
|
66
|
+
className={classNames(
|
|
67
|
+
'pkt-card__image',
|
|
68
|
+
`pkt-card__image-${imageShape}`,
|
|
69
|
+
imageAspect && `pkt-card__image-aspect-${imageAspect}`,
|
|
70
|
+
restrictImageHeight && 'pkt-card__image-restricted',
|
|
71
|
+
)}
|
|
72
|
+
>
|
|
61
73
|
<img src={image.src} alt={image.alt || ''} />
|
|
62
74
|
</div>
|
|
63
75
|
)
|
|
@@ -69,11 +81,11 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
69
81
|
<div
|
|
70
82
|
className={classNames('pkt-card__tags', `pkt-card__tags-${tagPosition}`)}
|
|
71
83
|
role="list"
|
|
72
|
-
aria-label={tags.length
|
|
84
|
+
aria-label={plural(tags.length, s.card.tagsLabelOne, s.card.tagsLabelOther)}
|
|
73
85
|
>
|
|
74
|
-
{tags.map((tag,
|
|
86
|
+
{withStableKeys(tags, (tag) => tag.text).map(({ item: tag, key }) => (
|
|
75
87
|
<PktTag
|
|
76
|
-
key={
|
|
88
|
+
key={key}
|
|
77
89
|
role="listitem"
|
|
78
90
|
textStyle="normal-text"
|
|
79
91
|
size="medium"
|
|
@@ -13,11 +13,11 @@ interface IComboboxTagsProps {
|
|
|
13
13
|
|
|
14
14
|
export const ComboboxTags = ({ state, outside = false }: IComboboxTagsProps) => {
|
|
15
15
|
const { values, options, disabled, displayValueAs, handleTagRemove, handleTagKeydown, focusedTagIndex } = state
|
|
16
|
-
const
|
|
16
|
+
const tagElementsRef = useRef<(HTMLButtonElement | null)[]>([])
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
if (!outside && focusedTagIndex >= 0 && focusedTagIndex < values.length) {
|
|
20
|
-
|
|
20
|
+
tagElementsRef.current[focusedTagIndex]?.focus()
|
|
21
21
|
}
|
|
22
22
|
}, [outside, focusedTagIndex, values.length])
|
|
23
23
|
|
|
@@ -59,7 +59,7 @@ export const ComboboxTags = ({ state, outside = false }: IComboboxTagsProps) =>
|
|
|
59
59
|
>
|
|
60
60
|
<PktTag
|
|
61
61
|
ref={(el: HTMLButtonElement | null) => {
|
|
62
|
-
|
|
62
|
+
tagElementsRef.current[index] = el
|
|
63
63
|
}}
|
|
64
64
|
skin={tagSkinColor || 'blue-dark'}
|
|
65
65
|
closeTag
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
+
import { formatString } from 'shared-strings'
|
|
3
4
|
import type { IComboboxState } from './types'
|
|
4
5
|
import { PktIcon } from '../icon/Icon'
|
|
5
6
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
7
|
+
import { withStableKeys } from '../../utils/stableKeys'
|
|
6
8
|
|
|
7
9
|
interface IListboxProps {
|
|
8
10
|
state: IComboboxState
|
|
@@ -76,7 +78,7 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
76
78
|
)}
|
|
77
79
|
{showMaxBanner && (
|
|
78
80
|
<div className="pkt-listbox__banner pkt-listbox__banner--maximum-reached">
|
|
79
|
-
{
|
|
81
|
+
{formatString(s.listbox.maxReached, { selected: selectedCount, max: maxlength })}
|
|
80
82
|
</div>
|
|
81
83
|
)}
|
|
82
84
|
|
|
@@ -98,20 +100,20 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
98
100
|
onKeyDown={handleNewOptionKeydown}
|
|
99
101
|
>
|
|
100
102
|
<PktIcon className="pkt-listbox__banner-icon" name="plus-sign" />
|
|
101
|
-
|
|
103
|
+
{formatString(s.listbox.addValue, { value: addValueText })}
|
|
102
104
|
</div>
|
|
103
105
|
)}
|
|
104
106
|
|
|
105
107
|
{options.length === 0 && filteredOptions.length === 0 && !showUserMessage && (
|
|
106
108
|
<div className="pkt-listbox__banner pkt-listbox__banner--empty">
|
|
107
109
|
<PktIcon className="pkt-listbox__banner-icon" name="exclamation-mark-circle" />
|
|
108
|
-
|
|
110
|
+
{s.listbox.empty}
|
|
109
111
|
</div>
|
|
110
112
|
)}
|
|
111
113
|
</div>
|
|
112
114
|
|
|
113
115
|
<ul className="pkt-listbox__options" role="presentation">
|
|
114
|
-
{filteredOptions.map((option, index) => {
|
|
116
|
+
{withStableKeys(filteredOptions, (option) => option.value).map(({ item: option, key }, index) => {
|
|
115
117
|
const optionClasses = [
|
|
116
118
|
'pkt-listbox__option',
|
|
117
119
|
!multiple && option.selected && 'pkt-listbox__option--selected',
|
|
@@ -124,7 +126,7 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
124
126
|
|
|
125
127
|
return (
|
|
126
128
|
<li
|
|
127
|
-
key={
|
|
129
|
+
key={key}
|
|
128
130
|
className={optionClasses}
|
|
129
131
|
onClick={() => handleOptionClick(option.value)}
|
|
130
132
|
onKeyDown={(e) => handleOptionKeydown(e, option.value)}
|