@oslokommune/punkt-react 19.5.2 → 19.6.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 +20 -0
- package/dist/components/inputwrapper/InputWrapper.d.ts +2 -0
- package/dist/components/radio/RadioButton.d.ts +2 -0
- package/dist/components/timepicker/useTimepickerState.d.ts +1 -2
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +196 -185
- package/dist/shared-types/checkbox.d.ts +3 -1
- package/dist/shared-types/size.d.ts +2 -1
- package/package.json +3 -3
- package/src/components/checkbox/Checkbox.test.tsx +24 -0
- package/src/components/checkbox/Checkbox.tsx +4 -1
- package/src/components/inputwrapper/InputWrapper.test.tsx +35 -0
- package/src/components/inputwrapper/InputWrapper.tsx +16 -1
- package/src/components/radio/RadioButton.test.tsx +26 -0
- package/src/components/radio/RadioButton.tsx +6 -1
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { IPktStringsProps } from '../shared-strings';
|
|
8
8
|
import type { IFormFieldErrorProps, IFormFieldLabelProps, ITagOptionalRequiredProps } from './form-field';
|
|
9
|
+
import type { TPktInputSize } from './size';
|
|
9
10
|
/** Checkbox label placement — shared runtime source for types, specs, and Preview. */
|
|
10
11
|
export declare const CHECKBOX_LABEL_POSITIONS: readonly ['right', 'left'];
|
|
11
12
|
export type TCheckboxLabelPosition = (typeof CHECKBOX_LABEL_POSITIONS)[number];
|
|
@@ -28,12 +29,13 @@ export interface IPktCheckboxBase extends IFormFieldLabelProps, Pick<IFormFieldE
|
|
|
28
29
|
isSwitch?: boolean;
|
|
29
30
|
hideLabel?: boolean;
|
|
30
31
|
labelPosition?: TCheckboxLabelPosition;
|
|
32
|
+
inputSize?: TPktInputSize;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Documented Checkbox props (subset of `IPktCheckboxBase`).
|
|
34
36
|
* Used for typed component specs in documentation.
|
|
35
37
|
*/
|
|
36
|
-
export type ICheckboxSpecProps = Pick<IPktCheckboxBase, 'label' | 'checkHelptext' | 'name' | 'form' | 'value' | 'id' | 'defaultChecked' | 'checked' | 'indeterminate' | 'hasTile' | 'disabled' | 'hasError' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText'>;
|
|
38
|
+
export type ICheckboxSpecProps = Pick<IPktCheckboxBase, 'label' | 'checkHelptext' | 'name' | 'form' | 'value' | 'id' | 'defaultChecked' | 'checked' | 'indeterminate' | 'hasTile' | 'inputSize' | 'disabled' | 'hasError' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText'>;
|
|
37
39
|
/**
|
|
38
40
|
* Default values for pkt-checkbox. Single source of truth for both frameworks.
|
|
39
41
|
* `checked` is intentionally absent — React must keep it `undefined` to stay uncontrolled.
|
|
@@ -19,4 +19,5 @@ export type TSize7 = 'xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlar
|
|
|
19
19
|
/**
|
|
20
20
|
* Sizes used in our input components
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export declare const InputSize: readonly ['xsmall', 'small', 'medium'];
|
|
23
|
+
export type TPktInputSize = (typeof InputSize)[number];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.6.0",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@eslint/eslintrc": "^3.3.5",
|
|
42
42
|
"@eslint/js": "^10.0.1",
|
|
43
43
|
"@oslokommune/punkt-assets": "^19.0.4",
|
|
44
|
-
"@oslokommune/punkt-css": "^19.
|
|
44
|
+
"@oslokommune/punkt-css": "^19.6.0",
|
|
45
45
|
"@testing-library/jest-dom": "^6.9.1",
|
|
46
46
|
"@testing-library/react": "^16.3.2",
|
|
47
47
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
102
102
|
},
|
|
103
103
|
"license": "MIT",
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "52793889285e2b8365c81315dce280062c38a543"
|
|
105
105
|
}
|
|
@@ -105,3 +105,27 @@ describe('PktCheckbox', () => {
|
|
|
105
105
|
})
|
|
106
106
|
})
|
|
107
107
|
})
|
|
108
|
+
|
|
109
|
+
describe('PktCheckbox inputSize', () => {
|
|
110
|
+
const root = (inputSize?: 'small' | 'medium' | 'xsmall') =>
|
|
111
|
+
render(<PktCheckbox id="s" label="Valg" inputSize={inputSize} />).container.querySelector('.pkt-input-check')
|
|
112
|
+
|
|
113
|
+
it('adds no size class without inputSize, so the size is inherited', () => {
|
|
114
|
+
expect(root()?.className).toBe('pkt-input-check')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('adds the size class for inputSize', () => {
|
|
118
|
+
expect(root('small')).toHaveClass('pkt-input-check--small')
|
|
119
|
+
expect(root('xsmall')).toHaveClass('pkt-input-check--xsmall')
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('adds the medium class when medium is set explicitly', () => {
|
|
123
|
+
expect(root('medium')).toHaveClass('pkt-input-check--medium')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('does not pass inputSize on to the native input', () => {
|
|
127
|
+
render(<PktCheckbox id="n" label="Valg" inputSize="small" />)
|
|
128
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputsize')
|
|
129
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputSize')
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -34,6 +34,7 @@ export const PktCheckbox = forwardRef(
|
|
|
34
34
|
isSwitch = CHECKBOX_DEFAULTS.isSwitch,
|
|
35
35
|
hideLabel = CHECKBOX_DEFAULTS.hideLabel,
|
|
36
36
|
labelPosition = CHECKBOX_DEFAULTS.labelPosition,
|
|
37
|
+
inputSize,
|
|
37
38
|
defaultChecked,
|
|
38
39
|
checked,
|
|
39
40
|
indeterminate,
|
|
@@ -66,7 +67,9 @@ export const PktCheckbox = forwardRef(
|
|
|
66
67
|
}
|
|
67
68
|
}, [ref])
|
|
68
69
|
|
|
69
|
-
const classes = [className, 'pkt-input-check'
|
|
70
|
+
const classes = [className, 'pkt-input-check', inputSize ? `pkt-input-check--${inputSize}` : '']
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join(' ')
|
|
70
73
|
|
|
71
74
|
const labelClasses = [
|
|
72
75
|
'pkt-input-check__input-label',
|
|
@@ -55,3 +55,38 @@ describe('PktInputWrapper', () => {
|
|
|
55
55
|
})
|
|
56
56
|
})
|
|
57
57
|
})
|
|
58
|
+
|
|
59
|
+
describe('PktInputWrapper options container', () => {
|
|
60
|
+
const renderWrapper = (props: Partial<Parameters<typeof PktInputWrapper>[0]> = {}) =>
|
|
61
|
+
render(
|
|
62
|
+
<PktInputWrapper forId="g" label="Gruppe" {...props}>
|
|
63
|
+
<span className="valg">Valg</span>
|
|
64
|
+
</PktInputWrapper>,
|
|
65
|
+
).container
|
|
66
|
+
|
|
67
|
+
test('wraps the options of a fieldset in a vertical options container', () => {
|
|
68
|
+
const options = renderWrapper({ hasFieldset: true }).querySelector('.pkt-inputwrapper__options')
|
|
69
|
+
|
|
70
|
+
expect(options).not.toHaveClass('pkt-inputwrapper__options--horizontal')
|
|
71
|
+
expect(options?.querySelector('.valg')).toBeInTheDocument()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('lays the options out horizontally with layout="horizontal"', () => {
|
|
75
|
+
const container = renderWrapper({ hasFieldset: true, layout: 'horizontal' })
|
|
76
|
+
|
|
77
|
+
expect(container.querySelector('.pkt-inputwrapper__options')).toHaveClass('pkt-inputwrapper__options--horizontal')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('uses the options container for horizontal layout without a fieldset', () => {
|
|
81
|
+
const container = renderWrapper({ layout: 'horizontal' })
|
|
82
|
+
|
|
83
|
+
expect(container.querySelector('.pkt-inputwrapper__options--horizontal .valg')).toBeInTheDocument()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('keeps the markup unchanged without a fieldset and horizontal layout', () => {
|
|
87
|
+
const container = renderWrapper()
|
|
88
|
+
|
|
89
|
+
expect(container.querySelector('.pkt-inputwrapper__options')).toBeNull()
|
|
90
|
+
expect(container.querySelector('.pkt-inputwrapper__fieldset > .valg')).toBeInTheDocument()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
@@ -7,6 +7,7 @@ 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
9
|
import { uuidish } from 'shared-utils/utils'
|
|
10
|
+
import type { TLayout } from 'shared-types'
|
|
10
11
|
import { PktAlert } from '../alert/Alert'
|
|
11
12
|
import { PktHelptext } from '../helptext/Helptext'
|
|
12
13
|
|
|
@@ -36,6 +37,7 @@ export interface IPktInputWrapper extends RefAttributes<HTMLElement>, IPktString
|
|
|
36
37
|
children?: ReactNode
|
|
37
38
|
className?: string
|
|
38
39
|
hasFieldset?: boolean
|
|
40
|
+
layout?: TLayout
|
|
39
41
|
role?: string
|
|
40
42
|
counterPosition?: 'top' | 'bottom'
|
|
41
43
|
size?: 'small' | 'medium' | 'xsmall'
|
|
@@ -66,6 +68,7 @@ export const PktInputWrapper = forwardRef(
|
|
|
66
68
|
children,
|
|
67
69
|
className = '',
|
|
68
70
|
hasFieldset = false,
|
|
71
|
+
layout = 'vertical',
|
|
69
72
|
role,
|
|
70
73
|
counterPosition = 'bottom',
|
|
71
74
|
size = 'medium',
|
|
@@ -193,7 +196,19 @@ export const PktInputWrapper = forwardRef(
|
|
|
193
196
|
{renderLabel()}
|
|
194
197
|
{renderHelptext()}
|
|
195
198
|
{counterTop && counterContent}
|
|
196
|
-
{
|
|
199
|
+
{hasFieldset || layout === 'horizontal' ? (
|
|
200
|
+
<div
|
|
201
|
+
className={
|
|
202
|
+
layout === 'horizontal'
|
|
203
|
+
? 'pkt-inputwrapper__options pkt-inputwrapper__options--horizontal'
|
|
204
|
+
: 'pkt-inputwrapper__options'
|
|
205
|
+
}
|
|
206
|
+
>
|
|
207
|
+
{children}
|
|
208
|
+
</div>
|
|
209
|
+
) : (
|
|
210
|
+
children
|
|
211
|
+
)}
|
|
197
212
|
{counterBottom && counterContent}
|
|
198
213
|
{hasError && errorMessage && (
|
|
199
214
|
<div className="pkt-inputwrapper__alert-wrapper">
|
|
@@ -66,3 +66,29 @@ describe('PktRadiobutton', () => {
|
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
})
|
|
69
|
+
|
|
70
|
+
describe('PktRadioButton inputSize', () => {
|
|
71
|
+
const root = (inputSize?: 'small' | 'medium' | 'xsmall') =>
|
|
72
|
+
render(<PktRadioButton id="s" name="g" label="Valg" inputSize={inputSize} />).container.querySelector(
|
|
73
|
+
'.pkt-input-check',
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
it('adds no size class without inputSize, so the size is inherited', () => {
|
|
77
|
+
expect(root()?.className).toBe('pkt-input-check')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('adds the size class for inputSize', () => {
|
|
81
|
+
expect(root('small')).toHaveClass('pkt-input-check--small')
|
|
82
|
+
expect(root('xsmall')).toHaveClass('pkt-input-check--xsmall')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('adds the medium class when medium is set explicitly', () => {
|
|
86
|
+
expect(root('medium')).toHaveClass('pkt-input-check--medium')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('does not pass inputSize on to the native input', () => {
|
|
90
|
+
render(<PktRadioButton id="n" name="g" label="Valg" inputSize="small" />)
|
|
91
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputsize')
|
|
92
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputSize')
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -2,12 +2,14 @@ import { ChangeEventHandler, ForwardedRef, forwardRef, type InputHTMLAttributes,
|
|
|
2
2
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
3
3
|
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
4
4
|
import type { IPktStringsProps } from 'shared-strings'
|
|
5
|
+
import type { TPktInputSize } from 'shared-types'
|
|
5
6
|
|
|
6
7
|
export interface IPktRadioButton extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
|
|
7
8
|
id: string
|
|
8
9
|
name: string
|
|
9
10
|
label: string
|
|
10
11
|
hasTile?: boolean
|
|
12
|
+
inputSize?: TPktInputSize
|
|
11
13
|
disabled?: boolean
|
|
12
14
|
checkHelptext?: ReactNode | ReactNode[] | string
|
|
13
15
|
defaultChecked?: boolean
|
|
@@ -32,6 +34,7 @@ export const PktRadioButton = forwardRef(
|
|
|
32
34
|
label,
|
|
33
35
|
className,
|
|
34
36
|
hasTile = false,
|
|
37
|
+
inputSize,
|
|
35
38
|
disabled = false,
|
|
36
39
|
checkHelptext,
|
|
37
40
|
hasError = false,
|
|
@@ -50,7 +53,9 @@ export const PktRadioButton = forwardRef(
|
|
|
50
53
|
): ReactElement => {
|
|
51
54
|
const s = usePktStrings(['forms'], strings)
|
|
52
55
|
const id = useGeneratedId(idProp)
|
|
53
|
-
const classes = [className, 'pkt-input-check'
|
|
56
|
+
const classes = [className, 'pkt-input-check', inputSize ? `pkt-input-check--${inputSize}` : '']
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(' ')
|
|
54
59
|
|
|
55
60
|
const inputTileClasses = [
|
|
56
61
|
'pkt-input-check__input',
|