@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +3 -2
  3. package/dist/components/card/Card.js +77 -70
  4. package/dist/components/checkbox/Checkbox.js +1 -1
  5. package/dist/components/inputwrapper/InputWrapper.js +1 -1
  6. package/dist/components/link/Link.d.ts +0 -1
  7. package/dist/components/link/Link.js +10 -12
  8. package/dist/components/linkcard/LinkCard.d.ts +1 -1
  9. package/dist/components/linkcard/LinkCard.js +23 -20
  10. package/dist/components/messagebox/Messagebox.js +29 -28
  11. package/dist/components/progressbar/Progressbar.d.ts +2 -16
  12. package/dist/components/progressbar/Progressbar.js +49 -42
  13. package/dist/components/radio/RadioButton.js +1 -1
  14. package/dist/components/tag/Tag.d.ts +2 -1
  15. package/dist/components/tag/Tag.js +37 -35
  16. package/dist/punkt-react.cjs +1 -1
  17. package/dist/shared-strings/nb.d.ts +3 -0
  18. package/dist/shared-strings/nb.js +1 -0
  19. package/dist/shared-types/card.d.ts +5 -17
  20. package/dist/shared-types/card.js +9 -8
  21. package/dist/shared-types/combobox.d.ts +3 -3
  22. package/dist/shared-types/icon.d.ts +2 -2
  23. package/dist/shared-types/icon.js +1 -1
  24. package/dist/shared-types/index.d.ts +11 -9
  25. package/dist/shared-types/index.js +17 -15
  26. package/dist/shared-types/linkcard.d.ts +7 -4
  27. package/dist/shared-types/linkcard.js +9 -0
  28. package/dist/shared-types/messagebox.d.ts +4 -2
  29. package/dist/shared-types/messagebox.js +8 -3
  30. package/dist/shared-types/progressbar.d.ts +82 -5
  31. package/dist/shared-types/progressbar.js +14 -0
  32. package/dist/shared-types/skin.d.ts +8 -2
  33. package/package.json +4 -4
  34. package/src/components/button/Button.test.tsx +1 -1
  35. package/src/components/card/Card.test.tsx +78 -43
  36. package/src/components/card/Card.tsx +17 -24
  37. package/src/components/checkbox/Checkbox.tsx +1 -1
  38. package/src/components/inputwrapper/InputWrapper.tsx +1 -1
  39. package/src/components/link/Link.test.tsx +9 -21
  40. package/src/components/link/Link.tsx +0 -4
  41. package/src/components/linkcard/LinkCard.test.tsx +20 -9
  42. package/src/components/linkcard/LinkCard.tsx +5 -11
  43. package/src/components/messagebox/Messagebox.test.tsx +10 -1
  44. package/src/components/messagebox/Messagebox.tsx +11 -2
  45. package/src/components/progressbar/Progressbar.test.tsx +25 -0
  46. package/src/components/progressbar/Progressbar.tsx +30 -40
  47. package/src/components/radio/RadioButton.tsx +1 -1
  48. package/src/components/tag/Tag.test.tsx +21 -0
  49. 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 type {
6
- TAriaLive,
7
- TProgressbarRole,
8
- TProgressbarSkin,
9
- TProgressbarStatusPlacement,
10
- TProgressbarStatusType,
11
- TProgressbarTitlePosition,
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 = 'polite',
35
+ ariaLive = PROGRESSBAR_DEFAULTS.ariaLive,
47
36
  ariaValueText,
48
37
  id,
49
- role = 'progressbar',
50
- skin = 'dark-blue',
51
- statusPlacement = 'following',
52
- statusType = 'none',
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 = 'left',
55
- valueCurrent = 0,
56
- valueMax = 100,
57
- valueMin = 0,
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 currentPercentage =
76
- statusType === 'fraction'
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 = `${valueCurrent} av ${totalSteps}`
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-light`}>{optionalText ?? s.forms.optional}</span>
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 = 'blue',
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