@oslokommune/punkt-react 18.4.0 → 18.5.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 +25 -0
- package/dist/components/card/Card.d.ts +6 -2
- package/dist/components/loader/Loader.d.ts +1 -1
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1713 -1701
- package/package.json +4 -4
- package/src/components/breadcrumbs/Breadcrumbs.tsx +2 -2
- package/src/components/card/Card.test.tsx +3 -2
- package/src/components/card/Card.tsx +37 -22
- package/src/components/checkbox/Checkbox.tsx +3 -8
- package/src/components/heading/Heading.tsx +1 -1
- package/src/components/helptext/Helptext.test.tsx +2 -2
- package/src/components/helptext/Helptext.tsx +11 -10
- package/src/components/inputwrapper/InputWrapper.tsx +6 -2
- package/src/components/loader/Loader.tsx +2 -2
- package/src/components/searchinput/SearchInput.tsx +6 -2
- package/src/components/select/Select.tsx +4 -2
- package/src/components/tag/Tag.tsx +4 -4
- package/src/components/textarea/Textarea.tsx +4 -2
- package/src/components/textinput/Textinput.tsx +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.5.1",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@eslint/compat": "^2.1.0",
|
|
45
45
|
"@eslint/eslintrc": "^3.3.5",
|
|
46
46
|
"@eslint/js": "^10.0.1",
|
|
47
|
-
"@oslokommune/punkt-assets": "^18.
|
|
48
|
-
"@oslokommune/punkt-css": "^18.
|
|
47
|
+
"@oslokommune/punkt-assets": "^18.5.1",
|
|
48
|
+
"@oslokommune/punkt-css": "^18.5.1",
|
|
49
49
|
"@testing-library/jest-dom": "^6.9.1",
|
|
50
50
|
"@testing-library/react": "^16.3.2",
|
|
51
51
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "5408e0682e25a98a64f20657a1a1c0a68c0ed3de"
|
|
106
106
|
}
|
|
@@ -68,7 +68,7 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
68
68
|
className: 'pkt-link pkt-link--icon-right pkt-breadcrumbs__label pkt-breadcrumbs__link',
|
|
69
69
|
children: (
|
|
70
70
|
<>
|
|
71
|
-
<PktIcon className="pkt-icon pkt-breadcrumbs__icon pkt-link__icon" name="chevron-thin-right" />
|
|
71
|
+
<PktIcon className="pkt-icon pkt-breadcrumbs__icon pkt-link__icon" name="chevron-thin-right" aria-hidden="true" />
|
|
72
72
|
<span className="pkt-breadcrumbs__text">{item.text}</span>
|
|
73
73
|
</>
|
|
74
74
|
),
|
|
@@ -84,7 +84,7 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
84
84
|
className: 'pkt-link pkt-link--icon-left pkt-breadcrumbs--mobile',
|
|
85
85
|
children: (
|
|
86
86
|
<>
|
|
87
|
-
<PktIcon className="pkt-back-link__icon pkt-icon pkt-link__icon" name="chevron-thin-left" />
|
|
87
|
+
<PktIcon className="pkt-back-link__icon pkt-icon pkt-link__icon" name="chevron-thin-left" aria-hidden="true" />
|
|
88
88
|
<span className="pkt-breadcrumbs__text">{backLink.text}</span>
|
|
89
89
|
</>
|
|
90
90
|
),
|
|
@@ -94,8 +94,9 @@ describe('PktCard', () => {
|
|
|
94
94
|
|
|
95
95
|
test('supports custom className', () => {
|
|
96
96
|
const { container } = render(<PktCard className="custom-class">innhold</PktCard>)
|
|
97
|
-
const
|
|
98
|
-
expect(
|
|
97
|
+
const article = container.querySelector('article')
|
|
98
|
+
expect(article).toHaveClass('custom-class')
|
|
99
|
+
expect(article).toHaveClass('pkt-card')
|
|
99
100
|
})
|
|
100
101
|
})
|
|
101
102
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
|
-
import { forwardRef, HTMLAttributes,
|
|
4
|
+
import { forwardRef, HTMLAttributes, ReactNode, Ref } from 'react'
|
|
5
5
|
import type { TCardSkin, TLayout, TTagSkin } from 'shared-types'
|
|
6
6
|
|
|
7
|
+
import { PktHeading } from '../heading/Heading'
|
|
7
8
|
import { PktTag } from '../tag/Tag'
|
|
8
9
|
|
|
9
10
|
export type { TCardSkin, TLayout }
|
|
10
11
|
type TCardPadding = 'none' | 'default'
|
|
11
12
|
type TCardImageShape = 'square' | 'round'
|
|
13
|
+
type TCardImageAspect = 'auto' | '1-1' | '4-3' | '3-2' | '16-9' | '19-10'
|
|
12
14
|
type TCardTagPosition = 'top' | 'bottom'
|
|
13
15
|
type THeadingLevel = 1 | 2 | 3 | 4 | 5 | 6
|
|
14
16
|
|
|
@@ -23,12 +25,15 @@ export interface IPktCard extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
|
|
23
25
|
ariaLabel?: string
|
|
24
26
|
metaLead?: string | null
|
|
25
27
|
borderOnHover?: boolean
|
|
28
|
+
zoom?: boolean
|
|
26
29
|
metaTrail?: string | null
|
|
27
30
|
layout?: TLayout
|
|
28
31
|
heading?: string
|
|
29
32
|
headingLevel?: THeadingLevel
|
|
30
33
|
image?: { src: string; alt: string }
|
|
31
34
|
imageShape?: TCardImageShape
|
|
35
|
+
imageAspect?: TCardImageAspect
|
|
36
|
+
restrictImageHeight?: boolean
|
|
32
37
|
clickCardLink?: string | null
|
|
33
38
|
padding?: TCardPadding
|
|
34
39
|
openLinkInNewTab?: boolean
|
|
@@ -37,10 +42,10 @@ export interface IPktCard extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
|
|
|
37
42
|
tagPosition?: TCardTagPosition
|
|
38
43
|
tags?: ICardTag[]
|
|
39
44
|
children?: ReactNode
|
|
40
|
-
ref?: Ref<
|
|
45
|
+
ref?: Ref<HTMLElement>
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
export const PktCard = forwardRef<
|
|
48
|
+
export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
44
49
|
(
|
|
45
50
|
{
|
|
46
51
|
children,
|
|
@@ -54,12 +59,15 @@ export const PktCard = forwardRef<HTMLDivElement, IPktCard>(
|
|
|
54
59
|
headingLevel = 3,
|
|
55
60
|
image,
|
|
56
61
|
imageShape = 'square',
|
|
62
|
+
imageAspect,
|
|
63
|
+
restrictImageHeight = false,
|
|
57
64
|
clickCardLink,
|
|
58
65
|
padding = 'default',
|
|
59
66
|
openLinkInNewTab = false,
|
|
60
67
|
skin = 'outlined',
|
|
61
68
|
subheading = '',
|
|
62
69
|
tagPosition = 'top',
|
|
70
|
+
zoom = false,
|
|
63
71
|
tags = [],
|
|
64
72
|
...props
|
|
65
73
|
},
|
|
@@ -71,17 +79,16 @@ export const PktCard = forwardRef<HTMLDivElement, IPktCard>(
|
|
|
71
79
|
[`pkt-card--${layout}`]: layout,
|
|
72
80
|
[`pkt-card--padding-${padding}`]: padding,
|
|
73
81
|
'pkt-card--border-on-hover': borderOnHover,
|
|
82
|
+
'pkt-card--zoom': zoom,
|
|
74
83
|
})
|
|
75
84
|
|
|
76
85
|
const ariaLabelLenke = ariaLabel?.trim() || (heading ? `${heading} lenkekort` : 'lenkekort')
|
|
77
86
|
const ariaLabelVanlig = ariaLabel?.trim() || (heading ? heading : 'kort')
|
|
78
87
|
|
|
79
|
-
const HeadingTag = `h${headingLevel}` as keyof JSX.IntrinsicElements
|
|
80
|
-
|
|
81
88
|
const renderImage = () => {
|
|
82
89
|
if (!image?.src) return null
|
|
83
90
|
return (
|
|
84
|
-
<div className={classNames('pkt-card__image', `pkt-card__image-${imageShape}`)}>
|
|
91
|
+
<div className={classNames('pkt-card__image', `pkt-card__image-${imageShape}`, imageAspect && `pkt-card__image-aspect-${imageAspect}`, restrictImageHeight && 'pkt-card__image-restricted')}>
|
|
85
92
|
<img src={image.src} alt={image.alt || ''} />
|
|
86
93
|
</div>
|
|
87
94
|
)
|
|
@@ -114,16 +121,21 @@ export const PktCard = forwardRef<HTMLDivElement, IPktCard>(
|
|
|
114
121
|
const renderHeading = () => {
|
|
115
122
|
if (!heading || clickCardLink) return null
|
|
116
123
|
return (
|
|
117
|
-
<
|
|
124
|
+
<PktHeading className="pkt-card__heading" level={headingLevel} size="medium" weight="regular">
|
|
118
125
|
{heading}
|
|
119
|
-
</
|
|
126
|
+
</PktHeading>
|
|
120
127
|
)
|
|
121
128
|
}
|
|
122
129
|
|
|
123
130
|
const renderLinkHeading = () => {
|
|
124
131
|
if (!clickCardLink) return null
|
|
125
132
|
return (
|
|
126
|
-
<
|
|
133
|
+
<PktHeading
|
|
134
|
+
className="pkt-card__link-heading pkt-card__heading"
|
|
135
|
+
level={headingLevel}
|
|
136
|
+
size="medium"
|
|
137
|
+
weight="regular"
|
|
138
|
+
>
|
|
127
139
|
<a
|
|
128
140
|
className="pkt-card__link"
|
|
129
141
|
href={clickCardLink}
|
|
@@ -132,7 +144,7 @@ export const PktCard = forwardRef<HTMLDivElement, IPktCard>(
|
|
|
132
144
|
>
|
|
133
145
|
{heading}
|
|
134
146
|
</a>
|
|
135
|
-
</
|
|
147
|
+
</PktHeading>
|
|
136
148
|
)
|
|
137
149
|
}
|
|
138
150
|
|
|
@@ -163,18 +175,21 @@ export const PktCard = forwardRef<HTMLDivElement, IPktCard>(
|
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
return (
|
|
166
|
-
<
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
+
<article
|
|
179
|
+
{...props}
|
|
180
|
+
ref={ref}
|
|
181
|
+
className={classNames(classes, className)}
|
|
182
|
+
aria-label={clickCardLink ? ariaLabelLenke : ariaLabelVanlig}
|
|
183
|
+
>
|
|
184
|
+
{renderImage()}
|
|
185
|
+
<div className="pkt-card__wrapper">
|
|
186
|
+
{tagPosition === 'top' && renderTags()}
|
|
187
|
+
{renderHeader()}
|
|
188
|
+
<section className="pkt-card__content">{children}</section>
|
|
189
|
+
{tagPosition === 'bottom' && renderTags()}
|
|
190
|
+
{renderMetadata()}
|
|
191
|
+
</div>
|
|
192
|
+
</article>
|
|
178
193
|
)
|
|
179
194
|
},
|
|
180
195
|
)
|
|
@@ -82,6 +82,7 @@ export const PktCheckbox = forwardRef(
|
|
|
82
82
|
|
|
83
83
|
const labelClasses = [
|
|
84
84
|
'pkt-input-check__input-label',
|
|
85
|
+
labelPosition === 'left' ? 'pkt-input-check__input-label--left' : '',
|
|
85
86
|
disabled ? 'pkt-input-check__input-label--disabled' : '',
|
|
86
87
|
`pkt-input-check__input-label--${labelPosition}`,
|
|
87
88
|
hideLabel ? 'pkt-sr-only' : '',
|
|
@@ -104,15 +105,9 @@ export const PktCheckbox = forwardRef(
|
|
|
104
105
|
<>
|
|
105
106
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
106
107
|
{optionalTag && (
|
|
107
|
-
<span className={tagClasses + ` pkt-tag--blue-light`}>
|
|
108
|
-
{optionalText ?? s.forms.optional}
|
|
109
|
-
</span>
|
|
110
|
-
)}
|
|
111
|
-
{requiredTag && (
|
|
112
|
-
<span className={tagClasses + ` pkt-tag--beige`}>
|
|
113
|
-
{requiredText ?? s.forms.required}
|
|
114
|
-
</span>
|
|
108
|
+
<span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText ?? s.forms.optional}</span>
|
|
115
109
|
)}
|
|
110
|
+
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
116
111
|
</>
|
|
117
112
|
)
|
|
118
113
|
}
|
|
@@ -69,7 +69,7 @@ export const PktHeading = forwardRef<HTMLHeadingElement, IPktHeading>(function P
|
|
|
69
69
|
const Tag = `h${level}` as 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
|
|
70
70
|
|
|
71
71
|
return (
|
|
72
|
-
<Tag {...rest} ref={ref} className={classes}
|
|
72
|
+
<Tag {...rest} ref={ref} className={classes}>
|
|
73
73
|
{children}
|
|
74
74
|
</Tag>
|
|
75
75
|
)
|
|
@@ -88,11 +88,11 @@ describe('PktHelptext', () => {
|
|
|
88
88
|
expect(onToggle).toHaveBeenLastCalledWith(false)
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
test('
|
|
91
|
+
test('genererer en id på hjelpetekst-diven når forId mangler', () => {
|
|
92
92
|
const { container } = render(<PktHelptext helptext="No id here" />)
|
|
93
93
|
|
|
94
94
|
const helptext = container.querySelector('.pkt-inputwrapper__helptext')
|
|
95
95
|
expect(helptext).toBeInTheDocument()
|
|
96
|
-
expect(helptext
|
|
96
|
+
expect(helptext?.getAttribute('id')).toMatch(/-helptext$/)
|
|
97
97
|
})
|
|
98
98
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
|
-
import { forwardRef, HTMLAttributes, ReactNode, useState } from 'react'
|
|
4
|
+
import { forwardRef, HTMLAttributes, ReactNode, useMemo, useState } from 'react'
|
|
5
|
+
import { uuidish } from 'shared-utils/utils'
|
|
5
6
|
|
|
6
7
|
import { PktIcon } from '../icon/Icon'
|
|
7
8
|
|
|
@@ -18,6 +19,7 @@ export interface IPktHelptextProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
18
19
|
const renderContent = (content: string | ReactNode | undefined): ReactNode => {
|
|
19
20
|
if (content === undefined || content === null || content === '') return null
|
|
20
21
|
if (typeof content === 'string') {
|
|
22
|
+
// eslint-disable-next-line @eslint-react/dom-no-dangerously-set-innerhtml
|
|
21
23
|
return <span dangerouslySetInnerHTML={{ __html: content }} />
|
|
22
24
|
}
|
|
23
25
|
return content
|
|
@@ -28,7 +30,7 @@ export const PktHelptext = forwardRef<HTMLDivElement, IPktHelptextProps>(functio
|
|
|
28
30
|
helptext,
|
|
29
31
|
helptextDropdown,
|
|
30
32
|
helptextDropdownButton,
|
|
31
|
-
forId,
|
|
33
|
+
forId: forIdProp,
|
|
32
34
|
onToggleHelpText,
|
|
33
35
|
className,
|
|
34
36
|
children,
|
|
@@ -38,6 +40,9 @@ export const PktHelptext = forwardRef<HTMLDivElement, IPktHelptextProps>(functio
|
|
|
38
40
|
) {
|
|
39
41
|
const [isOpen, setIsOpen] = useState(false)
|
|
40
42
|
|
|
43
|
+
const generatedId = useMemo(() => uuidish(), [])
|
|
44
|
+
const forId = forIdProp || generatedId
|
|
45
|
+
|
|
41
46
|
const toggle = () => {
|
|
42
47
|
const next = !isOpen
|
|
43
48
|
setIsOpen(next)
|
|
@@ -54,7 +59,7 @@ export const PktHelptext = forwardRef<HTMLDivElement, IPktHelptextProps>(functio
|
|
|
54
59
|
|
|
55
60
|
return (
|
|
56
61
|
<div {...rest} ref={ref} className={containerClasses}>
|
|
57
|
-
<div className="pkt-inputwrapper__helptext" id={
|
|
62
|
+
<div className="pkt-inputwrapper__helptext" id={`${forId}-helptext`}>
|
|
58
63
|
{children && <div className="pkt-contents">{children}</div>}
|
|
59
64
|
{renderContent(helptext)}
|
|
60
65
|
</div>
|
|
@@ -67,12 +72,10 @@ export const PktHelptext = forwardRef<HTMLDivElement, IPktHelptextProps>(functio
|
|
|
67
72
|
aria-controls={`${forId}-helptext-expandable`}
|
|
68
73
|
onClick={toggle}
|
|
69
74
|
>
|
|
70
|
-
<PktIcon
|
|
71
|
-
className="pkt-btn__icon"
|
|
72
|
-
name={isOpen ? 'chevron-thin-up' : 'chevron-thin-down'}
|
|
73
|
-
/>
|
|
75
|
+
<PktIcon className="pkt-btn__icon" name={isOpen ? 'chevron-thin-up' : 'chevron-thin-down'} />
|
|
74
76
|
<span
|
|
75
77
|
className="pkt-btn__text"
|
|
78
|
+
// eslint-disable-next-line @eslint-react/dom-no-dangerously-set-innerhtml
|
|
76
79
|
dangerouslySetInnerHTML={{
|
|
77
80
|
__html: helptextDropdownButton ?? defaultDropdownButton,
|
|
78
81
|
}}
|
|
@@ -82,9 +85,7 @@ export const PktHelptext = forwardRef<HTMLDivElement, IPktHelptextProps>(functio
|
|
|
82
85
|
id={`${forId}-helptext-expandable`}
|
|
83
86
|
className={classNames(
|
|
84
87
|
'pkt-inputwrapper__helptext',
|
|
85
|
-
isOpen
|
|
86
|
-
? 'pkt-inputwrapper__helptext-expandable-open'
|
|
87
|
-
: 'pkt-inputwrapper__helptext-expandable-closed',
|
|
88
|
+
isOpen ? 'pkt-inputwrapper__helptext-expandable-open' : 'pkt-inputwrapper__helptext-expandable-closed',
|
|
88
89
|
)}
|
|
89
90
|
>
|
|
90
91
|
{renderContent(helptextDropdown)}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { ForwardedRef, forwardRef, type ReactNode, RefAttributes } from 'react'
|
|
3
|
+
import { ForwardedRef, forwardRef, type ReactNode, RefAttributes, useMemo } from 'react'
|
|
4
4
|
|
|
5
5
|
import { useFocusModality } from '../../hooks/useFocusModality'
|
|
6
6
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
7
7
|
import { formatString, type IPktStringsProps } from 'shared-strings'
|
|
8
8
|
import { counterStatusId, isCounterExceeded } from 'shared-utils/forms/described-by'
|
|
9
|
+
import { uuidish } from 'shared-utils/utils'
|
|
9
10
|
import { PktAlert } from '../alert/Alert'
|
|
10
11
|
import { PktHelptext } from '../helptext/Helptext'
|
|
11
12
|
|
|
@@ -43,7 +44,7 @@ export interface IPktInputWrapper extends RefAttributes<HTMLElement>, IPktString
|
|
|
43
44
|
export const PktInputWrapper = forwardRef(
|
|
44
45
|
(
|
|
45
46
|
{
|
|
46
|
-
forId,
|
|
47
|
+
forId: forIdProp,
|
|
47
48
|
label,
|
|
48
49
|
helptext,
|
|
49
50
|
helptextDropdown,
|
|
@@ -75,6 +76,9 @@ export const PktInputWrapper = forwardRef(
|
|
|
75
76
|
const focusModality = useFocusModality<HTMLDivElement>(ref)
|
|
76
77
|
const s = usePktStrings(['forms', 'validation'], strings)
|
|
77
78
|
|
|
79
|
+
const generatedId = useMemo(() => uuidish(), [])
|
|
80
|
+
const forId = forIdProp || generatedId
|
|
81
|
+
|
|
78
82
|
const describedBy = ariaDescribedby || (helptext ? `${forId}-helptext` : undefined)
|
|
79
83
|
const showCounter = !!counter
|
|
80
84
|
const counterTop = showCounter && counterPosition === 'top'
|
|
@@ -42,7 +42,7 @@ export interface IPktLoader extends HTMLAttributes<HTMLDivElement> {
|
|
|
42
42
|
*/
|
|
43
43
|
size?: TPktLoaderSize
|
|
44
44
|
/**
|
|
45
|
-
* Loader-variant. Standard er "shapes"
|
|
45
|
+
* Loader-variant. Standard er "rainbow". "shapes" er Oslo-bølgene, "blue" en blå spinner.
|
|
46
46
|
*/
|
|
47
47
|
variant?: TPktLoaderVariant
|
|
48
48
|
/**
|
|
@@ -70,7 +70,7 @@ export const PktLoader = forwardRef<HTMLDivElement, IPktLoader>(function PktLoad
|
|
|
70
70
|
isLoading = true,
|
|
71
71
|
message = null,
|
|
72
72
|
size = 'medium',
|
|
73
|
-
variant = '
|
|
73
|
+
variant = 'rainbow',
|
|
74
74
|
loadingAnimationPath = typeof window !== 'undefined' ? window.pktAnimationPath : undefined,
|
|
75
75
|
className,
|
|
76
76
|
children,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { ChangeEvent, forwardRef, HTMLProps, ReactNode } from 'react'
|
|
3
|
+
import { ChangeEvent, forwardRef, HTMLProps, ReactNode, useMemo } from 'react'
|
|
4
|
+
import { uuidish } from 'shared-utils/utils'
|
|
4
5
|
|
|
5
6
|
import type { IPktSearchInputSuggestion } from 'shared-types/searchinput'
|
|
6
7
|
|
|
@@ -54,7 +55,7 @@ export const PktSearchInput = forwardRef<HTMLInputElement, ISearchInput | ISearc
|
|
|
54
55
|
inputSize = 'medium',
|
|
55
56
|
disabled = false,
|
|
56
57
|
fullwidth = false,
|
|
57
|
-
id,
|
|
58
|
+
id: idProp,
|
|
58
59
|
label,
|
|
59
60
|
name,
|
|
60
61
|
placeholder,
|
|
@@ -94,6 +95,9 @@ export const PktSearchInput = forwardRef<HTMLInputElement, ISearchInput | ISearc
|
|
|
94
95
|
.filter(Boolean)
|
|
95
96
|
.join(' ')
|
|
96
97
|
|
|
98
|
+
const generatedId = useMemo(() => uuidish(), [])
|
|
99
|
+
const id = idProp || generatedId
|
|
100
|
+
|
|
97
101
|
const focusModality = useFocusModality()
|
|
98
102
|
|
|
99
103
|
const wrapperProps = {
|
|
@@ -4,6 +4,7 @@ import { ForwardedRef, forwardRef, ReactNode, SelectHTMLAttributes } from 'react
|
|
|
4
4
|
|
|
5
5
|
import { PktInputWrapper } from '../inputwrapper/InputWrapper'
|
|
6
6
|
import { describedByIds } from 'shared-utils/forms/described-by'
|
|
7
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
7
8
|
import type { IPktStringsProps } from 'shared-strings'
|
|
8
9
|
|
|
9
10
|
export type { IPktSelectOption, TSelectOption } from 'shared-types/select'
|
|
@@ -45,11 +46,11 @@ export const PktSelect = forwardRef(
|
|
|
45
46
|
className,
|
|
46
47
|
disabled = false,
|
|
47
48
|
errorMessage,
|
|
48
|
-
hasError,
|
|
49
|
+
hasError = false,
|
|
49
50
|
helptext,
|
|
50
51
|
helptextDropdown,
|
|
51
52
|
helptextDropdownButton,
|
|
52
|
-
id,
|
|
53
|
+
id: idProp,
|
|
53
54
|
inline = false,
|
|
54
55
|
fullwidth = false,
|
|
55
56
|
label,
|
|
@@ -67,6 +68,7 @@ export const PktSelect = forwardRef(
|
|
|
67
68
|
}: IPktSelectProps,
|
|
68
69
|
ref: ForwardedRef<HTMLSelectElement>,
|
|
69
70
|
) => {
|
|
71
|
+
const id = useGeneratedId(idProp)
|
|
70
72
|
const outerClasses = [className, 'pkt-select'].filter(Boolean).join(' ')
|
|
71
73
|
|
|
72
74
|
return (
|
|
@@ -48,15 +48,15 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
|
|
|
48
48
|
(
|
|
49
49
|
{
|
|
50
50
|
children,
|
|
51
|
-
skin,
|
|
51
|
+
skin = 'blue',
|
|
52
52
|
textStyle,
|
|
53
|
-
size,
|
|
53
|
+
size = 'medium',
|
|
54
54
|
closeTag,
|
|
55
55
|
className,
|
|
56
56
|
iconName,
|
|
57
57
|
ariaLabel,
|
|
58
58
|
onClose,
|
|
59
|
-
type,
|
|
59
|
+
type = 'button',
|
|
60
60
|
'aria-description': ariaDescriptionPropValue,
|
|
61
61
|
strings,
|
|
62
62
|
...props
|
|
@@ -114,7 +114,7 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
|
|
|
114
114
|
aria-description={ariaDescription}
|
|
115
115
|
ref={forwardedRef as ForwardedRef<HTMLButtonElement>}
|
|
116
116
|
>
|
|
117
|
-
{iconName && <PktIcon className={'pkt-tag__icon'} name={iconName} />}
|
|
117
|
+
{iconName && <PktIcon className={'pkt-tag__icon'} name={iconName} aria-hidden="true" />}
|
|
118
118
|
<span ref={spanRef}>{children}</span>
|
|
119
119
|
<PktIcon className={'pkt-tag__close-btn'} name={'close'} />
|
|
120
120
|
</button>
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { PktInputWrapper } from '../inputwrapper/InputWrapper'
|
|
15
15
|
import { TPktInputSize } from 'shared-types/size'
|
|
16
16
|
import { describedByIds } from 'shared-utils/forms/described-by'
|
|
17
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
17
18
|
import type { IPktStringsProps } from 'shared-strings'
|
|
18
19
|
|
|
19
20
|
export interface IPktTextarea
|
|
@@ -56,7 +57,7 @@ export interface IPktTextarea
|
|
|
56
57
|
export const PktTextarea = forwardRef(
|
|
57
58
|
(
|
|
58
59
|
{
|
|
59
|
-
id,
|
|
60
|
+
id: idProp,
|
|
60
61
|
ariaDescribedby,
|
|
61
62
|
ariaLabelledby,
|
|
62
63
|
counter,
|
|
@@ -65,7 +66,7 @@ export const PktTextarea = forwardRef(
|
|
|
65
66
|
className,
|
|
66
67
|
disabled,
|
|
67
68
|
errorMessage,
|
|
68
|
-
hasError,
|
|
69
|
+
hasError = false,
|
|
69
70
|
helptext,
|
|
70
71
|
helptextDropdown,
|
|
71
72
|
helptextDropdownButton,
|
|
@@ -97,6 +98,7 @@ export const PktTextarea = forwardRef(
|
|
|
97
98
|
const showCounter = counter ?? (counterMaxLength ?? 0) > 0
|
|
98
99
|
const outerClasses = [className, 'pkt-textinput', 'pkt-textarea'].filter(Boolean).join(' ')
|
|
99
100
|
|
|
101
|
+
const id = useGeneratedId(idProp)
|
|
100
102
|
const inputId = `${id}-input` // id til input element og sendes inn til htmlFor/forId i InputWrapper
|
|
101
103
|
const labelId = `${inputId}-label` // id til label elementet og sendes inn til aria-labelledby i input (genereres i InputWrapper)
|
|
102
104
|
const labelledBy = ariaLabelledby || labelId
|
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
import { PktIcon } from '../icon/Icon'
|
|
15
15
|
import { PktInputWrapper } from '../inputwrapper/InputWrapper'
|
|
16
16
|
import { describedByIds } from 'shared-utils/forms/described-by'
|
|
17
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
17
18
|
import type { IPktStringsProps } from 'shared-strings'
|
|
18
19
|
|
|
19
|
-
export interface IPktTextinput
|
|
20
|
-
extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms' | 'validation'> {
|
|
20
|
+
export interface IPktTextinput extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms' | 'validation'> {
|
|
21
21
|
id: string
|
|
22
22
|
ariaDescribedby?: string
|
|
23
23
|
ariaLabelledby?: string
|
|
@@ -65,7 +65,7 @@ export interface IPktTextinput
|
|
|
65
65
|
export const PktTextinput = forwardRef(
|
|
66
66
|
(
|
|
67
67
|
{
|
|
68
|
-
id,
|
|
68
|
+
id: idProp,
|
|
69
69
|
ariaDescribedby,
|
|
70
70
|
ariaLabelledby,
|
|
71
71
|
autocomplete = 'off',
|
|
@@ -121,6 +121,7 @@ export const PktTextinput = forwardRef(
|
|
|
121
121
|
|
|
122
122
|
const [counterCurrent, setCounterCurrent] = useState(value?.length || 0)
|
|
123
123
|
|
|
124
|
+
const id = useGeneratedId(idProp)
|
|
124
125
|
const inputId = `${id}` // id til input element og sendes inn til htmlFor i InputWrapper
|
|
125
126
|
const labelId = `${inputId}-label` // id til label elementet og sendes inn til aria-labelledby i input (genereres i InputWrapper)
|
|
126
127
|
const labelledBy = ariaLabelledby || labelId
|