@oslokommune/punkt-react 12.27.7 → 12.28.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 +18 -0
- package/dist/index.d.ts +16 -8
- package/dist/punkt-react.es.js +9953 -9889
- package/dist/punkt-react.umd.js +356 -329
- package/package.json +4 -4
- package/src/components/checkbox/Checkbox.test.tsx +18 -5
- package/src/components/checkbox/Checkbox.tsx +38 -62
- package/src/components/radio/RadioButton.test.tsx +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.28.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.5",
|
|
41
|
-
"@oslokommune/punkt-elements": "^12.
|
|
41
|
+
"@oslokommune/punkt-elements": "^12.28.0",
|
|
42
42
|
"angular-html-parser": "^6.0.2",
|
|
43
43
|
"html-format": "^1.1.7",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@oslokommune/punkt-assets": "^12.27.1",
|
|
51
|
-
"@oslokommune/punkt-css": "^12.
|
|
51
|
+
"@oslokommune/punkt-css": "^12.28.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.5.0",
|
|
53
53
|
"@testing-library/react": "^16.0.1",
|
|
54
54
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
112
112
|
},
|
|
113
113
|
"license": "MIT",
|
|
114
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "3dee4a0c63e59fe126be318bad620cfb9b9a6c6f"
|
|
115
115
|
}
|
|
@@ -9,42 +9,54 @@ expect.extend(toHaveNoViolations)
|
|
|
9
9
|
|
|
10
10
|
describe('PktCheckbox', () => {
|
|
11
11
|
// Test case for rendering a basic checkbox
|
|
12
|
-
it('renders a basic checkbox with label', () => {
|
|
12
|
+
it('renders a basic checkbox with label', async () => {
|
|
13
13
|
const { getByLabelText } = render(<PktCheckbox id="myCheckbox" label="My Checkbox" />)
|
|
14
14
|
|
|
15
|
+
await window.customElements.whenDefined('pkt-checkbox')
|
|
16
|
+
|
|
15
17
|
// Check if the label is present in the document
|
|
16
18
|
const checkboxLabel = getByLabelText('My Checkbox')
|
|
17
19
|
expect(checkboxLabel).toBeInTheDocument()
|
|
18
20
|
})
|
|
19
21
|
|
|
20
|
-
it('renders an error state checkbox', () => {
|
|
22
|
+
it('renders an error state checkbox', async () => {
|
|
21
23
|
render(<PktCheckbox id="myCheckbox" label="My Checkbox" hasError />)
|
|
24
|
+
|
|
25
|
+
await window.customElements.whenDefined('pkt-checkbox')
|
|
26
|
+
|
|
22
27
|
const checkbox = screen.getByRole('checkbox', { name: 'My Checkbox' })
|
|
23
28
|
|
|
24
29
|
// Verify that the error class is applied to the checkbox
|
|
25
30
|
expect(checkbox).toHaveClass('pkt-input-check__input-checkbox--error')
|
|
26
31
|
})
|
|
27
32
|
|
|
28
|
-
it('renders as Switch', () => {
|
|
33
|
+
it('renders as Switch', async () => {
|
|
29
34
|
render(<PktCheckbox id="myCheckbox" label="My Checkbox" isSwitch />)
|
|
35
|
+
|
|
36
|
+
await window.customElements.whenDefined('pkt-checkbox')
|
|
37
|
+
|
|
30
38
|
const checkbox = screen.getByRole('switch', { name: 'My Checkbox' })
|
|
31
39
|
|
|
32
40
|
// Verify that the error class is applied to the checkbox
|
|
33
41
|
expect(checkbox).toHaveAttribute('role', 'switch')
|
|
34
42
|
})
|
|
35
43
|
|
|
36
|
-
test('renders a default checked checkbox', () => {
|
|
44
|
+
test('renders a default checked checkbox', async () => {
|
|
37
45
|
const { getByRole } = render(<PktCheckbox id="myCheckbox" label="My Checkbox" defaultChecked={true} />)
|
|
46
|
+
|
|
47
|
+
await window.customElements.whenDefined('pkt-checkbox')
|
|
38
48
|
// Find the checkbox element by its "checkbox" role
|
|
39
49
|
const checkbox = getByRole('checkbox') as HTMLInputElement
|
|
40
50
|
// Verify that the checkbox is initially checked
|
|
41
51
|
expect(checkbox).toBeChecked()
|
|
42
52
|
})
|
|
43
53
|
|
|
44
|
-
test('handles onClick callback', () => {
|
|
54
|
+
test('handles onClick callback', async () => {
|
|
45
55
|
const onClickMock = jest.fn()
|
|
46
56
|
const { getByLabelText } = render(<PktCheckbox id="myCheckbox" label="My Checkbox" onClick={onClickMock} />)
|
|
47
57
|
|
|
58
|
+
await window.customElements.whenDefined('pkt-checkbox')
|
|
59
|
+
|
|
48
60
|
// Get the checkbox label element
|
|
49
61
|
const checkboxLabel = getByLabelText('My Checkbox')
|
|
50
62
|
|
|
@@ -58,6 +70,7 @@ describe('PktCheckbox', () => {
|
|
|
58
70
|
describe('accessibility', () => {
|
|
59
71
|
it('renders with no wcag errors with axe', async () => {
|
|
60
72
|
const { container } = render(<PktCheckbox id="accessibilityTest" label="My checkkbox"></PktCheckbox>)
|
|
73
|
+
await window.customElements.whenDefined('pkt-checkbox')
|
|
61
74
|
const results = await axe(container)
|
|
62
75
|
|
|
63
76
|
expect(results).toHaveNoViolations()
|
|
@@ -1,71 +1,47 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEventHandler,
|
|
3
|
+
FocusEventHandler,
|
|
4
|
+
ForwardedRef,
|
|
5
|
+
ForwardRefExoticComponent,
|
|
6
|
+
InputHTMLAttributes,
|
|
7
|
+
ReactNode,
|
|
8
|
+
} from 'react'
|
|
9
|
+
import { createComponent, EventName } from '@lit/react'
|
|
10
|
+
import { PktCheckbox as PktElCheckbox } from '@oslokommune/punkt-elements'
|
|
11
|
+
import { PktEventWithTarget } from '@/interfaces/IPktElements'
|
|
2
12
|
|
|
3
|
-
export interface IPktCheckbox extends
|
|
13
|
+
export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement> {
|
|
4
14
|
id: string
|
|
15
|
+
name?: string
|
|
16
|
+
label: string
|
|
5
17
|
hasTile?: boolean
|
|
6
|
-
disabled?: boolean
|
|
7
|
-
label?: string
|
|
8
|
-
labelPosition?: 'right' | 'left'
|
|
9
|
-
hideLabel?: boolean
|
|
10
|
-
checkHelptext?: string | React.ReactNode | React.ReactNode[]
|
|
11
18
|
hasError?: boolean
|
|
12
19
|
defaultChecked?: boolean
|
|
13
|
-
|
|
20
|
+
disabled?: boolean
|
|
14
21
|
value?: string
|
|
22
|
+
checkHelptext?: string | React.ReactNode | React.ReactNode[]
|
|
23
|
+
isSwitch?: boolean
|
|
24
|
+
hideLabel?: boolean
|
|
25
|
+
labelPosition?: 'right' | 'left'
|
|
26
|
+
checked?: boolean
|
|
27
|
+
ref?: ForwardedRef<HTMLInputElement>
|
|
28
|
+
onChange?: ChangeEventHandler<HTMLInputElement>
|
|
29
|
+
onInput?: ChangeEventHandler<HTMLInputElement>
|
|
30
|
+
onBlur?: FocusEventHandler<HTMLInputElement>
|
|
31
|
+
onFocus?: FocusEventHandler<HTMLInputElement>
|
|
32
|
+
onValueChange?: (e: CustomEvent) => void
|
|
15
33
|
}
|
|
16
34
|
|
|
17
|
-
export const PktCheckbox =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isSwitch = false,
|
|
29
|
-
className,
|
|
30
|
-
...props
|
|
31
|
-
}: IPktCheckbox,
|
|
32
|
-
ref: ForwardedRef<HTMLInputElement>,
|
|
33
|
-
): React.ReactElement => {
|
|
34
|
-
// Define the classes
|
|
35
|
-
const classes = [className, 'pkt-input-check'].filter(Boolean).join(' ')
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className={classes}>
|
|
39
|
-
<div
|
|
40
|
-
className={`pkt-input-check__input ${hasTile ? 'pkt-input-check__input--tile' : ''} ${
|
|
41
|
-
disabled && hasTile ? 'pkt-input-check__input--tile-disabled' : ''
|
|
42
|
-
}`}
|
|
43
|
-
>
|
|
44
|
-
{label && labelPosition === 'left' && (
|
|
45
|
-
<label className={`pkt-input-check__input-label ${hideLabel ? 'pkt-sr-only' : ''}`} htmlFor={id}>
|
|
46
|
-
{label}
|
|
47
|
-
{checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
|
|
48
|
-
</label>
|
|
49
|
-
)}
|
|
50
|
-
<input
|
|
51
|
-
ref={ref}
|
|
52
|
-
className={`pkt-input-check__input-checkbox ${hasError ? 'pkt-input-check__input-checkbox--error' : ''}`}
|
|
53
|
-
type="checkbox"
|
|
54
|
-
role={isSwitch ? 'switch' : 'checkbox'}
|
|
55
|
-
id={id}
|
|
56
|
-
disabled={disabled}
|
|
57
|
-
{...props}
|
|
58
|
-
/>
|
|
59
|
-
{label && labelPosition === 'right' && (
|
|
60
|
-
<label className={`pkt-input-check__input-label ${hideLabel ? 'pkt-sr-only' : ''}`} htmlFor={id}>
|
|
61
|
-
{label}
|
|
62
|
-
{checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
|
|
63
|
-
</label>
|
|
64
|
-
)}
|
|
65
|
-
</div>
|
|
66
|
-
</div>
|
|
67
|
-
)
|
|
35
|
+
export const PktCheckbox = createComponent({
|
|
36
|
+
tagName: 'pkt-checkbox',
|
|
37
|
+
elementClass: PktElCheckbox,
|
|
38
|
+
react: React,
|
|
39
|
+
displayName: 'PktCheckbox',
|
|
40
|
+
events: {
|
|
41
|
+
onChange: 'change' as EventName<PktEventWithTarget>,
|
|
42
|
+
onInput: 'input' as EventName<PktEventWithTarget>,
|
|
43
|
+
onBlur: 'blur' as EventName<FocusEvent>,
|
|
44
|
+
onFocus: 'focus' as EventName<FocusEvent>,
|
|
45
|
+
onValueChange: 'valueChange' as EventName<CustomEvent>,
|
|
68
46
|
},
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
PktCheckbox.displayName = 'PktCheckbox'
|
|
47
|
+
}) as ForwardRefExoticComponent<IPktCheckbox>
|
|
@@ -11,9 +11,7 @@ expect.extend(toHaveNoViolations)
|
|
|
11
11
|
describe('PktRadiobutton', () => {
|
|
12
12
|
// Test case for rendering a basic radiogroup
|
|
13
13
|
it('renders without errors', async () => {
|
|
14
|
-
const {
|
|
15
|
-
<PktRadioButton id="radio1" name="radioGroup" label="Option 1" value="option1" />,
|
|
16
|
-
)
|
|
14
|
+
const { container } = render(<PktRadioButton id="radio1" name="radioGroup" label="Option 1" value="option1" />)
|
|
17
15
|
await window.customElements.whenDefined('pkt-radiobutton')
|
|
18
16
|
|
|
19
17
|
const inputElement = container.querySelector('pkt-radiobutton')
|
|
@@ -64,6 +62,7 @@ describe('PktRadiobutton', () => {
|
|
|
64
62
|
const { container } = render(
|
|
65
63
|
<PktRadioButton name="accessibilitytest" id="accessibilityTest" label="My checkkbox" />,
|
|
66
64
|
)
|
|
65
|
+
await window.customElements.whenDefined('pkt-radiobutton')
|
|
67
66
|
const results = await axe(container)
|
|
68
67
|
|
|
69
68
|
expect(results).toHaveNoViolations()
|