@oslokommune/punkt-react 19.20.0 → 20.0.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 +59 -0
- package/README.md +3 -2
- package/dist/components/card/Card.js +77 -70
- package/dist/components/checkbox/Checkbox.js +1 -1
- package/dist/components/inputwrapper/InputWrapper.js +1 -1
- package/dist/components/link/Link.d.ts +0 -1
- package/dist/components/link/Link.js +10 -12
- package/dist/components/linkcard/LinkCard.d.ts +1 -1
- package/dist/components/linkcard/LinkCard.js +23 -20
- package/dist/components/messagebox/Messagebox.js +29 -28
- package/dist/components/radio/RadioButton.js +1 -1
- package/dist/components/tag/Tag.d.ts +2 -1
- package/dist/components/tag/Tag.js +37 -35
- package/dist/punkt-react.cjs +1 -1
- package/dist/shared-types/card.d.ts +5 -17
- package/dist/shared-types/card.js +9 -8
- package/dist/shared-types/combobox.d.ts +3 -3
- package/dist/shared-types/icon.d.ts +2 -2
- package/dist/shared-types/icon.js +1 -1
- package/dist/shared-types/index.d.ts +9 -8
- package/dist/shared-types/index.js +17 -16
- package/dist/shared-types/linkcard.d.ts +7 -4
- package/dist/shared-types/linkcard.js +9 -0
- package/dist/shared-types/messagebox.d.ts +4 -2
- package/dist/shared-types/messagebox.js +8 -3
- package/dist/shared-types/skin.d.ts +8 -2
- package/package.json +4 -4
- package/src/components/button/Button.test.tsx +1 -1
- package/src/components/card/Card.test.tsx +78 -43
- package/src/components/card/Card.tsx +17 -24
- package/src/components/checkbox/Checkbox.tsx +1 -1
- package/src/components/inputwrapper/InputWrapper.tsx +1 -1
- package/src/components/link/Link.test.tsx +9 -21
- package/src/components/link/Link.tsx +0 -4
- package/src/components/linkcard/LinkCard.test.tsx +20 -9
- package/src/components/linkcard/LinkCard.tsx +5 -11
- package/src/components/messagebox/Messagebox.test.tsx +10 -1
- package/src/components/messagebox/Messagebox.tsx +11 -2
- package/src/components/radio/RadioButton.tsx +1 -1
- package/src/components/tag/Tag.test.tsx +21 -0
- package/src/components/tag/Tag.tsx +6 -2
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { forwardRef, HTMLAttributes, ReactNode, Ref } from 'react'
|
|
5
5
|
import { plural, type IPktStringsProps } from 'shared-strings'
|
|
6
|
-
import { CARD_DEFAULTS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
|
|
6
|
+
import { CARD_DEFAULTS, CARD_LIGHT_ONLY_SKINS, type IPktCardBase, type TCardSkin, type TLayout } from 'shared-types'
|
|
7
7
|
|
|
8
8
|
import { PktHeading } from '../heading/Heading'
|
|
9
|
+
import { PktIcon } from '../icon/Icon'
|
|
9
10
|
import { PktTag } from '../tag/Tag'
|
|
10
11
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
11
12
|
import { withStableKeys } from '../../utils/stableKeys'
|
|
@@ -24,17 +25,13 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
24
25
|
className,
|
|
25
26
|
ariaLabel,
|
|
26
27
|
metaLead,
|
|
27
|
-
borderOnHover = CARD_DEFAULTS.borderOnHover,
|
|
28
28
|
metaTrail,
|
|
29
29
|
layout = CARD_DEFAULTS.layout,
|
|
30
30
|
heading = '',
|
|
31
31
|
headingLevel = CARD_DEFAULTS.headingLevel,
|
|
32
32
|
image,
|
|
33
|
-
imageShape = CARD_DEFAULTS.imageShape,
|
|
34
33
|
imageAspect,
|
|
35
|
-
restrictImageHeight = CARD_DEFAULTS.restrictImageHeight,
|
|
36
34
|
clickCardLink,
|
|
37
|
-
padding = CARD_DEFAULTS.padding,
|
|
38
35
|
openLinkInNewTab = CARD_DEFAULTS.openLinkInNewTab,
|
|
39
36
|
skin = CARD_DEFAULTS.skin,
|
|
40
37
|
subheading = '',
|
|
@@ -51,8 +48,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
51
48
|
'pkt-card': true,
|
|
52
49
|
[`pkt-card--${skin}`]: skin,
|
|
53
50
|
[`pkt-card--${layout}`]: layout,
|
|
54
|
-
|
|
55
|
-
'pkt-card--border-on-hover': borderOnHover,
|
|
51
|
+
'pkt-card--clickable': !!clickCardLink,
|
|
56
52
|
'pkt-card--zoom': zoom,
|
|
57
53
|
})
|
|
58
54
|
|
|
@@ -62,14 +58,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
62
58
|
const renderImage = () => {
|
|
63
59
|
if (!image?.src) return null
|
|
64
60
|
return (
|
|
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
|
+
<div className={classNames('pkt-card__image', imageAspect && `pkt-card__image-aspect-${imageAspect}`)}>
|
|
73
62
|
<img src={image.src} alt={image.alt || ''} />
|
|
74
63
|
</div>
|
|
75
64
|
)
|
|
@@ -102,7 +91,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
102
91
|
const renderHeading = () => {
|
|
103
92
|
if (!heading || clickCardLink) return null
|
|
104
93
|
return (
|
|
105
|
-
<PktHeading className="pkt-card__heading" level={headingLevel} size="medium" weight="
|
|
94
|
+
<PktHeading className="pkt-card__heading" level={headingLevel} size="medium" weight="medium">
|
|
106
95
|
{heading}
|
|
107
96
|
</PktHeading>
|
|
108
97
|
)
|
|
@@ -115,7 +104,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
115
104
|
className="pkt-card__link-heading pkt-card__heading"
|
|
116
105
|
level={headingLevel}
|
|
117
106
|
size="medium"
|
|
118
|
-
weight="
|
|
107
|
+
weight="medium"
|
|
119
108
|
>
|
|
120
109
|
<a
|
|
121
110
|
className="pkt-card__link"
|
|
@@ -125,6 +114,7 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
125
114
|
>
|
|
126
115
|
{heading}
|
|
127
116
|
</a>
|
|
117
|
+
<PktIcon className="pkt-card__link-icon" name="arrow-link" />
|
|
128
118
|
</PktHeading>
|
|
129
119
|
)
|
|
130
120
|
}
|
|
@@ -161,14 +151,17 @@ export const PktCard = forwardRef<HTMLElement, IPktCard>(
|
|
|
161
151
|
ref={ref}
|
|
162
152
|
className={classNames(classes, className)}
|
|
163
153
|
aria-label={clickCardLink ? ariaLabelLenke : ariaLabelVanlig}
|
|
154
|
+
data-mode={CARD_LIGHT_ONLY_SKINS.includes(skin) ? 'light' : undefined}
|
|
164
155
|
>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
156
|
+
<div className="pkt-card__container">
|
|
157
|
+
{renderImage()}
|
|
158
|
+
<div className="pkt-card__wrapper">
|
|
159
|
+
{tagPosition === 'top' && renderTags()}
|
|
160
|
+
{renderHeader()}
|
|
161
|
+
<section className="pkt-card__content">{children}</section>
|
|
162
|
+
{tagPosition === 'bottom' && renderTags()}
|
|
163
|
+
{renderMetadata()}
|
|
164
|
+
</div>
|
|
172
165
|
</div>
|
|
173
166
|
</article>
|
|
174
167
|
)
|
|
@@ -125,7 +125,7 @@ export const PktCheckbox = forwardRef(
|
|
|
125
125
|
<>
|
|
126
126
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
127
127
|
{optionalTag && (
|
|
128
|
-
<span className={tagClasses + ` pkt-tag--blue-
|
|
128
|
+
<span className={tagClasses + ` pkt-tag--blue-pale`}>{optionalText ?? s.forms.optional}</span>
|
|
129
129
|
)}
|
|
130
130
|
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
131
131
|
</>
|
|
@@ -116,7 +116,7 @@ export const PktInputWrapper = forwardRef(
|
|
|
116
116
|
<>
|
|
117
117
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
118
118
|
{optionalTag && (
|
|
119
|
-
<span className={tagClasses + ` pkt-tag--blue-
|
|
119
|
+
<span className={tagClasses + ` pkt-tag--blue-pale`}>{optionalText ?? s.forms.optional}</span>
|
|
120
120
|
)}
|
|
121
121
|
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
122
122
|
</>
|
|
@@ -58,36 +58,24 @@ describe('PktLink', () => {
|
|
|
58
58
|
})
|
|
59
59
|
const icon = document.querySelector('.pkt-link__icon')
|
|
60
60
|
if (iconName) {
|
|
61
|
-
expect(icon).toBeInTheDocument()
|
|
61
|
+
expect(icon).toBeInTheDocument()
|
|
62
62
|
} else {
|
|
63
|
-
expect(icon).not.toBeInTheDocument()
|
|
63
|
+
expect(icon).not.toBeInTheDocument()
|
|
64
64
|
}
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it
|
|
68
|
-
description | external | hasExternalClass | relAttribute
|
|
69
|
-
${'external class and rel when external is true'} | ${true} | ${true} | ${'noopener noreferrer'}
|
|
70
|
-
${'no external class or rel when external is false'} | ${false} | ${false} | ${null}
|
|
71
|
-
${'no external class or rel when external is undefined'} | ${undefined} | ${false} | ${null}
|
|
72
|
-
`('should apply $description', ({ external, hasExternalClass, relAttribute }) => {
|
|
67
|
+
it('passes rel through to the anchor', () => {
|
|
73
68
|
render(
|
|
74
|
-
<PktLink href="/test"
|
|
69
|
+
<PktLink href="/test" rel="noopener noreferrer">
|
|
75
70
|
Test Link
|
|
76
71
|
</PktLink>,
|
|
77
72
|
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (hasExternalClass) {
|
|
81
|
-
expect(link).toHaveClass('pkt-link--external')
|
|
82
|
-
} else {
|
|
83
|
-
expect(link).not.toHaveClass('pkt-link--external')
|
|
84
|
-
}
|
|
73
|
+
expect(screen.getByText('Test Link')).toHaveAttribute('rel', 'noopener noreferrer')
|
|
74
|
+
})
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
expect(link).not.toHaveAttribute('rel')
|
|
90
|
-
}
|
|
76
|
+
it('has no rel by default', () => {
|
|
77
|
+
render(<PktLink href="/test">Test Link</PktLink>)
|
|
78
|
+
expect(screen.getByText('Test Link')).not.toHaveAttribute('rel')
|
|
91
79
|
})
|
|
92
80
|
|
|
93
81
|
it('should apply target attribute', () => {
|
|
@@ -9,7 +9,6 @@ interface IPktLink extends LinkHTMLAttributes<HTMLAnchorElement> {
|
|
|
9
9
|
iconName?: string | undefined
|
|
10
10
|
className?: string | undefined
|
|
11
11
|
iconPosition?: string | undefined
|
|
12
|
-
external?: boolean
|
|
13
12
|
target?: string | undefined
|
|
14
13
|
renderLink?: TRenderLink<ReactNode, AnchorHTMLAttributes<HTMLAnchorElement>>
|
|
15
14
|
}
|
|
@@ -19,7 +18,6 @@ export const PktLink: FC<IPktLink> = ({
|
|
|
19
18
|
iconName,
|
|
20
19
|
className,
|
|
21
20
|
iconPosition,
|
|
22
|
-
external,
|
|
23
21
|
target,
|
|
24
22
|
renderLink,
|
|
25
23
|
children,
|
|
@@ -29,7 +27,6 @@ export const PktLink: FC<IPktLink> = ({
|
|
|
29
27
|
'pkt-link': true,
|
|
30
28
|
'pkt-link--icon-left': (!!iconName && iconPosition === 'left') || !!(iconName && !iconPosition),
|
|
31
29
|
'pkt-link--icon-right': !!iconName && iconPosition === 'right',
|
|
32
|
-
'pkt-link--external': external,
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
const linkChildren = (
|
|
@@ -54,7 +51,6 @@ export const PktLink: FC<IPktLink> = ({
|
|
|
54
51
|
props: {
|
|
55
52
|
...props,
|
|
56
53
|
target,
|
|
57
|
-
rel: external ? 'noopener noreferrer' : undefined,
|
|
58
54
|
},
|
|
59
55
|
})
|
|
60
56
|
}
|
|
@@ -84,16 +84,17 @@ describe('PktLinkCard', () => {
|
|
|
84
84
|
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--green')
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
it('renders with
|
|
87
|
+
it('renders with outlined skin', async () => {
|
|
88
88
|
const { container } = render(
|
|
89
89
|
<div>
|
|
90
|
-
<PktLinkCard title="
|
|
90
|
+
<PktLinkCard title="Outlined" skin="outlined" />
|
|
91
91
|
</div>,
|
|
92
92
|
)
|
|
93
93
|
const linkElement = container.querySelector('.pkt-linkcard')
|
|
94
|
-
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--
|
|
94
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--outlined')
|
|
95
95
|
})
|
|
96
|
-
|
|
96
|
+
|
|
97
|
+
it('keeps the deprecated gray-outline class', async () => {
|
|
97
98
|
const { container } = render(
|
|
98
99
|
<div>
|
|
99
100
|
<PktLinkCard title="Gray outline" skin="gray-outline" />
|
|
@@ -102,6 +103,20 @@ describe('PktLinkCard', () => {
|
|
|
102
103
|
const linkElement = container.querySelector('.pkt-linkcard')
|
|
103
104
|
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--gray-outline')
|
|
104
105
|
})
|
|
106
|
+
|
|
107
|
+
it('keeps light-only skins in light mode', async () => {
|
|
108
|
+
for (const skin of ['white', 'blue', 'green', 'beige'] as const) {
|
|
109
|
+
const { container, unmount } = render(<PktLinkCard title="Lys" skin={skin} />)
|
|
110
|
+
expect(container.querySelector('.pkt-linkcard')).toHaveAttribute('data-mode', 'light')
|
|
111
|
+
unmount()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const skin of ['gray', 'outlined', 'transparent', 'normal', 'gray-outline'] as const) {
|
|
115
|
+
const { container, unmount } = render(<PktLinkCard title="Følger modus" skin={skin} />)
|
|
116
|
+
expect(container.querySelector('.pkt-linkcard')).not.toHaveAttribute('data-mode')
|
|
117
|
+
unmount()
|
|
118
|
+
}
|
|
119
|
+
})
|
|
105
120
|
})
|
|
106
121
|
|
|
107
122
|
describe('openInNewTab strings', () => {
|
|
@@ -123,11 +138,7 @@ describe('PktLinkCard', () => {
|
|
|
123
138
|
|
|
124
139
|
it('uses a custom override from the strings prop', () => {
|
|
125
140
|
const { getByText, queryByText } = render(
|
|
126
|
-
<PktLinkCard
|
|
127
|
-
title="Normal"
|
|
128
|
-
openInNewTab
|
|
129
|
-
strings={{ linkcard: { openInNewTab: 'Opens in a new tab' } }}
|
|
130
|
-
>
|
|
141
|
+
<PktLinkCard title="Normal" openInNewTab strings={{ linkcard: { openInNewTab: 'Opens in a new tab' } }}>
|
|
131
142
|
Content
|
|
132
143
|
</PktLinkCard>,
|
|
133
144
|
)
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { HTMLAttributes, ReactNode } from 'react'
|
|
5
|
-
import type
|
|
5
|
+
import { LINKCARD_LIGHT_ONLY_SKINS, type IPktLinkCardBase, type TLinkCardSkin } from 'shared-types'
|
|
6
6
|
|
|
7
7
|
import { PktIcon } from '../icon/Icon'
|
|
8
8
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
9
9
|
|
|
10
10
|
export type { TLinkCardSkin }
|
|
11
11
|
|
|
12
|
-
export interface IPktLinkCard
|
|
13
|
-
extends IPktLinkCardBase,
|
|
14
|
-
Omit<HTMLAttributes<HTMLAnchorElement>, 'title'> {
|
|
12
|
+
export interface IPktLinkCard extends IPktLinkCardBase, Omit<HTMLAttributes<HTMLAnchorElement>, 'title'> {
|
|
15
13
|
children?: ReactNode
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -22,7 +20,6 @@ export const PktLinkCard = ({
|
|
|
22
20
|
href,
|
|
23
21
|
iconName,
|
|
24
22
|
openInNewTab,
|
|
25
|
-
external,
|
|
26
23
|
className,
|
|
27
24
|
strings,
|
|
28
25
|
...props
|
|
@@ -30,21 +27,18 @@ export const PktLinkCard = ({
|
|
|
30
27
|
const s = usePktStrings(['linkcard'], strings)
|
|
31
28
|
const classes = ['pkt-linkcard', skin && `pkt-linkcard--${skin}`].filter(Boolean).join(' ')
|
|
32
29
|
|
|
33
|
-
const titleClasses = ['pkt-linkcard__title', external && 'pkt-link pkt-link--external'].filter(Boolean).join(' ')
|
|
34
|
-
|
|
35
30
|
return (
|
|
36
31
|
<a
|
|
37
32
|
{...props}
|
|
38
33
|
href={href}
|
|
39
34
|
className={classNames(classes, className)}
|
|
35
|
+
data-mode={skin && LINKCARD_LIGHT_ONLY_SKINS.includes(skin) ? 'light' : undefined}
|
|
40
36
|
target={openInNewTab ? '_blank' : '_self'}
|
|
41
37
|
rel={openInNewTab ? 'noopener noreferrer' : undefined}
|
|
42
38
|
>
|
|
43
39
|
{iconName && <PktIcon className="pkt-link__icon" name={iconName} />}
|
|
44
|
-
{title && <div className=
|
|
45
|
-
{openInNewTab && s.linkcard.openInNewTab ?
|
|
46
|
-
<span className="pkt-sr-only">{s.linkcard.openInNewTab}</span>
|
|
47
|
-
) : null}
|
|
40
|
+
{title && <div className="pkt-linkcard__title">{title}</div>}
|
|
41
|
+
{openInNewTab && s.linkcard.openInNewTab ? <span className="pkt-sr-only">{s.linkcard.openInNewTab}</span> : null}
|
|
48
42
|
<div className="pkt-linkcard__text">{children}</div>
|
|
49
43
|
</a>
|
|
50
44
|
)
|
|
@@ -13,7 +13,8 @@ describe('Messagebox', () => {
|
|
|
13
13
|
it('render with defaults', async () => {
|
|
14
14
|
const { messageBox } = render(<PktMessagebox />)
|
|
15
15
|
|
|
16
|
-
expect(messageBox.className).toEqual('pkt-messagebox pkt-messagebox--
|
|
16
|
+
expect(messageBox.className).toEqual('pkt-messagebox pkt-messagebox--gray')
|
|
17
|
+
expect(messageBox).not.toHaveAttribute('data-mode')
|
|
17
18
|
})
|
|
18
19
|
|
|
19
20
|
it('render with skin', async () => {
|
|
@@ -22,6 +23,14 @@ describe('Messagebox', () => {
|
|
|
22
23
|
expect(messageBox.classList).toContain('pkt-messagebox--green')
|
|
23
24
|
})
|
|
24
25
|
|
|
26
|
+
it('keeps light-only skins in light mode', async () => {
|
|
27
|
+
for (const skin of ['beige', 'blue', 'red', 'green'] as const) {
|
|
28
|
+
const { messageBox, unmount } = render(<PktMessagebox skin={skin} />)
|
|
29
|
+
expect(messageBox).toHaveAttribute('data-mode', 'light')
|
|
30
|
+
unmount()
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
25
34
|
it('render compact', async () => {
|
|
26
35
|
const { messageBox } = render(<PktMessagebox compact />)
|
|
27
36
|
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { FC, HTMLAttributes, ReactNode, useCallback, useState } from 'react'
|
|
5
5
|
import type { IPktStringsProps } from 'shared-strings'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
MESSAGEBOX_DEFAULTS,
|
|
8
|
+
MESSAGEBOX_LIGHT_ONLY_SKINS,
|
|
9
|
+
type IPktMessageboxBase,
|
|
10
|
+
type TMessageboxSkin,
|
|
11
|
+
} from 'shared-types'
|
|
7
12
|
|
|
8
13
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
9
14
|
import { PktIcon } from '../icon/Icon'
|
|
@@ -49,7 +54,11 @@ export const PktMessagebox: FC<IPktMessagebox> = ({
|
|
|
49
54
|
}, [setClosed, onClose])
|
|
50
55
|
|
|
51
56
|
return (
|
|
52
|
-
<div
|
|
57
|
+
<div
|
|
58
|
+
{...props}
|
|
59
|
+
className={classNames(classes, className)}
|
|
60
|
+
data-mode={skin && MESSAGEBOX_LIGHT_ONLY_SKINS.includes(skin) ? 'light' : undefined}
|
|
61
|
+
>
|
|
53
62
|
{closable && (
|
|
54
63
|
<div className={'pkt-messagebox__close'}>
|
|
55
64
|
<button
|
|
@@ -110,7 +110,7 @@ export const PktRadioButton = forwardRef(
|
|
|
110
110
|
<>
|
|
111
111
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
112
112
|
{optionalTag && (
|
|
113
|
-
<span className={tagClasses + ` pkt-tag--blue-
|
|
113
|
+
<span className={tagClasses + ` pkt-tag--blue-pale`}>{optionalText ?? s.forms.optional}</span>
|
|
114
114
|
)}
|
|
115
115
|
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
116
116
|
</>
|
|
@@ -43,6 +43,27 @@ describe('PktTag', () => {
|
|
|
43
43
|
expect(spanElement).toHaveClass('pkt-tag--small')
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
+
it('defaults to the gray skin', async () => {
|
|
47
|
+
const { container } = await render(<PktTag>Tag</PktTag>)
|
|
48
|
+
const spanElement = container.querySelector('span.pkt-tag')
|
|
49
|
+
|
|
50
|
+
expect(spanElement).toHaveClass('pkt-tag--gray')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('renders a forced state class when state is provided', async () => {
|
|
54
|
+
const { container } = await render(<PktTag state="hover">Tag</PktTag>)
|
|
55
|
+
const spanElement = container.querySelector('span.pkt-tag')
|
|
56
|
+
|
|
57
|
+
expect(spanElement).toHaveClass('pkt-tag--hover')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('renders no state class by default', async () => {
|
|
61
|
+
const { container } = await render(<PktTag>Tag</PktTag>)
|
|
62
|
+
const spanElement = container.querySelector('span.pkt-tag')
|
|
63
|
+
|
|
64
|
+
expect(spanElement?.className).not.toContain('pkt-tag--undefined')
|
|
65
|
+
})
|
|
66
|
+
|
|
46
67
|
it('forwardRef works correctly', async () => {
|
|
47
68
|
const ref = createRef<HTMLButtonElement>()
|
|
48
69
|
const { unmount } = await render(
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
useState,
|
|
15
15
|
} from 'react'
|
|
16
16
|
|
|
17
|
-
import type { TPktSizeBase, TTagSkin } from 'shared-types'
|
|
17
|
+
import type { TPktSizeBase, TTagSkin, TTagState } from 'shared-types'
|
|
18
18
|
|
|
19
19
|
import { PktIcon } from '../icon/Icon'
|
|
20
20
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
@@ -22,6 +22,7 @@ import { formatString, type IPktStringsProps } from 'shared-strings'
|
|
|
22
22
|
|
|
23
23
|
interface BasePktTagProps extends IPktStringsProps<'tag'> {
|
|
24
24
|
skin?: TTagSkin
|
|
25
|
+
state?: TTagState
|
|
25
26
|
textStyle?: 'normal-text' | 'thin-text'
|
|
26
27
|
size?: TPktSizeBase
|
|
27
28
|
closeTag?: boolean
|
|
@@ -48,7 +49,8 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
|
|
|
48
49
|
(
|
|
49
50
|
{
|
|
50
51
|
children,
|
|
51
|
-
skin = '
|
|
52
|
+
skin = 'gray',
|
|
53
|
+
state,
|
|
52
54
|
textStyle,
|
|
53
55
|
size = 'medium',
|
|
54
56
|
closeTag,
|
|
@@ -93,6 +95,7 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
|
|
|
93
95
|
'pkt-tag': true,
|
|
94
96
|
[`pkt-tag--${size}`]: !!size,
|
|
95
97
|
[`pkt-tag--${skin}`]: !!skin,
|
|
98
|
+
[`pkt-tag--${state}`]: !!state,
|
|
96
99
|
[`pkt-tag--${textStyle}`]: !!textStyle,
|
|
97
100
|
}
|
|
98
101
|
|
|
@@ -101,6 +104,7 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
|
|
|
101
104
|
[`pkt-tag--${textStyle}`]: !!textStyle,
|
|
102
105
|
[`pkt-tag--${size}`]: !!size,
|
|
103
106
|
[`pkt-tag--${skin}`]: !!skin,
|
|
107
|
+
[`pkt-tag--${state}`]: !!state,
|
|
104
108
|
'pkt-hide': isClosed,
|
|
105
109
|
}
|
|
106
110
|
|