@oslokommune/punkt-react 13.0.4 → 13.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "13.0.4",
3
+ "version": "13.1.0",
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",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@lit-labs/ssr-dom-shim": "^1.2.1",
40
40
  "@lit/react": "^1.0.7",
41
- "@oslokommune/punkt-elements": "^13.0.0",
41
+ "@oslokommune/punkt-elements": "^13.1.0",
42
42
  "angular-html-parser": "^6.0.2",
43
43
  "html-format": "^1.1.7",
44
44
  "prettier": "^3.3.3",
@@ -112,5 +112,5 @@
112
112
  "url": "https://github.com/oslokommune/punkt/issues"
113
113
  },
114
114
  "license": "MIT",
115
- "gitHead": "b17a65e093bc83b470feabc13eba6ae162b5b9cb"
115
+ "gitHead": "eec066758ede7f850bc9f4683957baee56e7abc5"
116
116
  }
@@ -13,6 +13,11 @@ export interface IPktCheckbox extends React.InputHTMLAttributes<HTMLInputElement
13
13
  isSwitch?: boolean
14
14
  hideLabel?: boolean
15
15
  labelPosition?: 'right' | 'left'
16
+ optionalTag?: boolean
17
+ optionalText?: string
18
+ requiredTag?: boolean
19
+ requiredText?: string
20
+ tagText?: string | null
16
21
  onChange?: ChangeEventHandler<HTMLInputElement>
17
22
  }
18
23
 
@@ -31,6 +36,11 @@ export const PktCheckbox = forwardRef(
31
36
  labelPosition = 'right',
32
37
  defaultChecked,
33
38
  checked,
39
+ optionalTag,
40
+ optionalText = 'Valgfritt',
41
+ requiredTag,
42
+ requiredText = 'Må fylles ut',
43
+ tagText,
34
44
  ...props
35
45
  }: IPktCheckbox,
36
46
  ref: ForwardedRef<HTMLInputElement>,
@@ -54,12 +64,24 @@ export const PktCheckbox = forwardRef(
54
64
  .filter(Boolean)
55
65
  .join(' ')
56
66
 
67
+ const tagClasses = ['pkt-tag', 'pkt-tag--small', 'pkt-tag--thin-text'].join(' ')
68
+
69
+ const renderTags = () => {
70
+ return (
71
+ <>
72
+ {tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
73
+ {optionalTag && <span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText}</span>}
74
+ {requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText}</span>}
75
+ </>
76
+ )
77
+ }
78
+
57
79
  return (
58
80
  <div className={classes}>
59
81
  <div className={inputTileClasses}>
60
82
  {labelPosition === 'left' && (
61
83
  <label className={labelClasses} htmlFor={id}>
62
- {label}
84
+ {label} {renderTags()}
63
85
  {checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
64
86
  </label>
65
87
  )}
@@ -75,7 +97,7 @@ export const PktCheckbox = forwardRef(
75
97
  />
76
98
  {labelPosition === 'right' && (
77
99
  <label className={labelClasses} htmlFor={id}>
78
- {label}
100
+ {label} {renderTags()}
79
101
  {checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
80
102
  </label>
81
103
  )}
@@ -17,6 +17,7 @@ export interface IPktInputWrapper extends RefAttributes<HTMLElement> {
17
17
  optionalText?: string
18
18
  requiredTag?: boolean
19
19
  requiredText?: string
20
+ tagText?: string | null
20
21
  hasError?: boolean
21
22
  errorMessage?: string | ReactNode
22
23
  disabled?: boolean
@@ -45,6 +46,7 @@ export const PktInputWrapper = forwardRef(
45
46
  optionalText = 'Valgfritt',
46
47
  requiredTag = false,
47
48
  requiredText = 'Må fylles ut',
49
+ tagText = null,
48
50
  hasError = false,
49
51
  errorMessage,
50
52
  disabled = false,
@@ -61,8 +63,6 @@ export const PktInputWrapper = forwardRef(
61
63
  ) => {
62
64
  const [isHelpTextOpen, setIsHelpTextOpen] = useState(false)
63
65
 
64
- const tagText = optionalTag ? optionalText : requiredTag ? requiredText : null
65
-
66
66
  const describedBy = ariaDescribedby || (helptext ? `${forId}-helptext` : undefined)
67
67
  const showCounter = !!counter
68
68
  const counterTop = showCounter && counterPosition === 'top'
@@ -80,15 +80,7 @@ export const PktInputWrapper = forwardRef(
80
80
  .filter(Boolean)
81
81
  .join(' ')
82
82
 
83
- const tagClasses = [
84
- 'pkt-tag',
85
- 'pkt-tag--small',
86
- 'pkt-tag--thin-text',
87
- optionalTag && 'pkt-tag--blue-light',
88
- !optionalTag && requiredTag && 'pkt-tag--beige',
89
- ]
90
- .filter(Boolean)
91
- .join(' ')
83
+ const tagClasses = ['pkt-tag', 'pkt-tag--small', 'pkt-tag--thin-text'].join(' ')
92
84
 
93
85
  const Counter = () =>
94
86
  showCounter ? (
@@ -98,10 +90,19 @@ export const PktInputWrapper = forwardRef(
98
90
  </div>
99
91
  ) : null
100
92
 
93
+ const renderTags = () => {
94
+ return (
95
+ <>
96
+ {tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
97
+ {optionalTag && <span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText}</span>}
98
+ {requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText}</span>}
99
+ </>
100
+ )
101
+ }
101
102
  const renderLabel = () => {
102
103
  const labelContent = (
103
104
  <>
104
- {label} {tagText && <span className={tagClasses}>{tagText}</span>}
105
+ {label} {renderTags()}
105
106
  </>
106
107
  )
107
108
 
@@ -11,6 +11,11 @@ export interface IPktRadioButton extends React.InputHTMLAttributes<HTMLInputElem
11
11
  checked?: boolean
12
12
  hasError?: boolean
13
13
  value?: string
14
+ optionalTag?: boolean
15
+ optionalText?: string
16
+ requiredTag?: boolean
17
+ requiredText?: string
18
+ tagText?: string | null
14
19
  onChange?: ChangeEventHandler<HTMLInputElement>
15
20
  }
16
21
 
@@ -27,6 +32,11 @@ export const PktRadioButton = forwardRef(
27
32
  hasError = false,
28
33
  defaultChecked,
29
34
  checked,
35
+ optionalTag,
36
+ optionalText,
37
+ requiredTag,
38
+ requiredText,
39
+ tagText,
30
40
  ...props
31
41
  }: IPktRadioButton,
32
42
  ref: ForwardedRef<HTMLInputElement>,
@@ -52,6 +62,18 @@ export const PktRadioButton = forwardRef(
52
62
  .filter(Boolean)
53
63
  .join(' ')
54
64
 
65
+ const tagClasses = ['pkt-tag', 'pkt-tag--small', 'pkt-tag--thin-text'].join(' ')
66
+
67
+ const renderTags = () => {
68
+ return (
69
+ <>
70
+ {tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
71
+ {optionalTag && <span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText}</span>}
72
+ {requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText}</span>}
73
+ </>
74
+ )
75
+ }
76
+
55
77
  return (
56
78
  <div className={classes}>
57
79
  <div className={inputTileClasses}>
@@ -66,7 +88,7 @@ export const PktRadioButton = forwardRef(
66
88
  {...props}
67
89
  />
68
90
  <label className={labelClasses} htmlFor={id}>
69
- {label}
91
+ {label} {renderTags()}
70
92
  {checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
71
93
  </label>
72
94
  </div>
@@ -30,6 +30,7 @@ export interface IPktSelectProps extends SelectHTMLAttributes<HTMLSelectElement>
30
30
  optionalText?: string
31
31
  requiredTag?: boolean
32
32
  requiredText?: string
33
+ tagText?: string | null
33
34
  options?: Array<{ value: string; label: string; disabled?: boolean }>
34
35
  }
35
36
 
@@ -55,6 +56,7 @@ export const PktSelect = forwardRef(
55
56
  optionalText,
56
57
  requiredTag = false,
57
58
  requiredText,
59
+ tagText,
58
60
  ...props
59
61
  }: IPktSelectProps,
60
62
  ref: ForwardedRef<HTMLSelectElement>,
@@ -72,6 +74,7 @@ export const PktSelect = forwardRef(
72
74
  optionalText={optionalText}
73
75
  requiredTag={requiredTag}
74
76
  requiredText={requiredText}
77
+ tagText={tagText}
75
78
  hasError={hasError}
76
79
  errorMessage={errorMessage}
77
80
  disabled={disabled}
@@ -33,6 +33,7 @@ export interface IPktTextarea extends TextareaHTMLAttributes<HTMLTextAreaElement
33
33
  optionalText?: string
34
34
  requiredTag?: boolean
35
35
  requiredText?: string
36
+ tagText?: string | null
36
37
  placeholder?: string
37
38
  rows?: number
38
39
  useWrapper?: boolean
@@ -69,6 +70,7 @@ export const PktTextarea = forwardRef(
69
70
  optionalText,
70
71
  requiredTag = false,
71
72
  requiredText,
73
+ tagText = null,
72
74
  placeholder,
73
75
  rows,
74
76
  useWrapper = true,
@@ -121,6 +123,7 @@ export const PktTextarea = forwardRef(
121
123
  optionalText={optionalText}
122
124
  requiredTag={requiredTag}
123
125
  requiredText={requiredText}
126
+ tagText={tagText}
124
127
  useWrapper={useWrapper}
125
128
  counter={counter}
126
129
  counterCurrent={counterCurrent}
@@ -36,6 +36,7 @@ export interface IPktTextinput extends InputHTMLAttributes<HTMLInputElement> {
36
36
  optionalText?: string
37
37
  requiredTag?: boolean
38
38
  requiredText?: string
39
+ tagText?: string | null
39
40
  placeholder?: string
40
41
  prefix?: string
41
42
  suffix?: string
@@ -81,6 +82,7 @@ export const PktTextinput = forwardRef(
81
82
  optionalText,
82
83
  requiredTag = false,
83
84
  requiredText,
85
+ tagText = null,
84
86
  placeholder,
85
87
  prefix,
86
88
  suffix,
@@ -144,6 +146,7 @@ export const PktTextinput = forwardRef(
144
146
  optionalText={optionalText}
145
147
  requiredTag={requiredTag}
146
148
  requiredText={requiredText}
149
+ tagText={tagText}
147
150
  useWrapper={useWrapper}
148
151
  counter={counter}
149
152
  counterCurrent={counterCurrent}