@oslokommune/punkt-react 19.19.1 → 20.0.0
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 +67 -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/progressbar/Progressbar.d.ts +2 -16
- package/dist/components/progressbar/Progressbar.js +49 -42
- 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-strings/nb.d.ts +3 -0
- package/dist/shared-strings/nb.js +1 -0
- 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 +11 -9
- package/dist/shared-types/index.js +17 -15
- 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/progressbar.d.ts +82 -5
- package/dist/shared-types/progressbar.js +14 -0
- 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/progressbar/Progressbar.test.tsx +25 -0
- package/src/components/progressbar/Progressbar.tsx +30 -40
- 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
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { forwardRef, HTMLAttributes, Ref, useEffect, useRef, useState } from 'react'
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import {
|
|
6
|
+
PROGRESSBAR_DEFAULTS,
|
|
7
|
+
type IPktProgressbarBase,
|
|
8
|
+
type TProgressbarRole,
|
|
9
|
+
type TProgressbarSkin,
|
|
10
|
+
type TProgressbarStatusPlacement,
|
|
11
|
+
type TProgressbarStatusType,
|
|
12
|
+
type TProgressbarTitlePosition,
|
|
12
13
|
} from 'shared-types'
|
|
14
|
+
import { formatString } from 'shared-strings'
|
|
13
15
|
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
16
|
+
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
14
17
|
|
|
15
18
|
export type {
|
|
16
19
|
TProgressbarRole,
|
|
@@ -20,21 +23,7 @@ export type {
|
|
|
20
23
|
TProgressbarTitlePosition,
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
export interface IPktProgressbar extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'title'> {
|
|
24
|
-
ariaLabel?: string | null
|
|
25
|
-
ariaLabelledby?: string | null
|
|
26
|
-
ariaLive?: TAriaLive
|
|
27
|
-
ariaValueText?: string | null
|
|
28
|
-
id?: string
|
|
29
|
-
role?: TProgressbarRole
|
|
30
|
-
skin?: TProgressbarSkin
|
|
31
|
-
statusPlacement?: TProgressbarStatusPlacement
|
|
32
|
-
statusType?: TProgressbarStatusType
|
|
33
|
-
title?: string | null
|
|
34
|
-
titlePosition?: TProgressbarTitlePosition
|
|
35
|
-
valueCurrent: number
|
|
36
|
-
valueMax?: number
|
|
37
|
-
valueMin?: number
|
|
26
|
+
export interface IPktProgressbar extends IPktProgressbarBase, Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'title'> {
|
|
38
27
|
ref?: Ref<HTMLDivElement>
|
|
39
28
|
}
|
|
40
29
|
|
|
@@ -43,24 +32,26 @@ export const PktProgressbar = forwardRef<HTMLDivElement, IPktProgressbar>(
|
|
|
43
32
|
{
|
|
44
33
|
ariaLabel,
|
|
45
34
|
ariaLabelledby,
|
|
46
|
-
ariaLive =
|
|
35
|
+
ariaLive = PROGRESSBAR_DEFAULTS.ariaLive,
|
|
47
36
|
ariaValueText,
|
|
48
37
|
id,
|
|
49
|
-
role =
|
|
50
|
-
skin =
|
|
51
|
-
statusPlacement =
|
|
52
|
-
statusType =
|
|
38
|
+
role = PROGRESSBAR_DEFAULTS.role,
|
|
39
|
+
skin = PROGRESSBAR_DEFAULTS.skin,
|
|
40
|
+
statusPlacement = PROGRESSBAR_DEFAULTS.statusPlacement,
|
|
41
|
+
statusType = PROGRESSBAR_DEFAULTS.statusType,
|
|
53
42
|
title,
|
|
54
|
-
titlePosition =
|
|
55
|
-
valueCurrent =
|
|
56
|
-
valueMax =
|
|
57
|
-
valueMin =
|
|
43
|
+
titlePosition = PROGRESSBAR_DEFAULTS.titlePosition,
|
|
44
|
+
valueCurrent = PROGRESSBAR_DEFAULTS.valueCurrent,
|
|
45
|
+
valueMax = PROGRESSBAR_DEFAULTS.valueMax,
|
|
46
|
+
valueMin = PROGRESSBAR_DEFAULTS.valueMin,
|
|
47
|
+
strings,
|
|
58
48
|
className,
|
|
59
49
|
...props
|
|
60
50
|
},
|
|
61
51
|
ref,
|
|
62
52
|
) => {
|
|
63
53
|
const progressbarId = useGeneratedId(id)
|
|
54
|
+
const s = usePktStrings(['progressbar'], strings)
|
|
64
55
|
|
|
65
56
|
const labelRef = useRef<HTMLSpanElement>(null)
|
|
66
57
|
const [labelWidth, setLabelWidth] = useState(0)
|
|
@@ -71,18 +62,17 @@ export const PktProgressbar = forwardRef<HTMLDivElement, IPktProgressbar>(
|
|
|
71
62
|
}
|
|
72
63
|
}, [valueCurrent])
|
|
73
64
|
|
|
74
|
-
const totalSteps = valueMax - valueMin
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
? Math.round((valueCurrent / totalSteps) * 100)
|
|
78
|
-
: Math.round(((valueCurrent - valueMin) / totalSteps) * 100)
|
|
65
|
+
const totalSteps: number = valueMax - valueMin
|
|
66
|
+
const currentStep = valueCurrent - valueMin
|
|
67
|
+
const currentPercentage = Math.round((currentStep / totalSteps) * 100)
|
|
79
68
|
|
|
80
|
-
const formattedTitle =
|
|
69
|
+
const formattedTitle = formatString(s.progressbar.fraction, {
|
|
70
|
+
current: currentStep,
|
|
71
|
+
total: totalSteps,
|
|
72
|
+
})
|
|
81
73
|
|
|
82
74
|
const computedAriaValueText =
|
|
83
|
-
statusType === 'fraction' && !ariaValueText
|
|
84
|
-
? `${valueCurrent} av ${valueMax - valueMin}`
|
|
85
|
-
: ariaValueText || undefined
|
|
75
|
+
statusType === 'fraction' && !ariaValueText ? formattedTitle : ariaValueText || undefined
|
|
86
76
|
|
|
87
77
|
const computedAriaLabelledby = !ariaLabel ? ariaLabelledby || `${progressbarId}-title` : undefined
|
|
88
78
|
|
|
@@ -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
|
|