@oslokommune/punkt-react 12.31.2 → 12.32.6
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 +108 -0
- package/dist/index.d.ts +17 -0
- package/dist/punkt-react.es.js +20285 -20032
- package/dist/punkt-react.umd.js +686 -472
- package/package.json +6 -5
- package/src/components/button/Button.test.tsx +32 -0
- package/src/components/combobox/Combobox.tsx +60 -0
- package/src/components/index.ts +1 -0
- package/src/components/interfaces.ts +1 -0
- package/src/components/preview/Preview.tsx +13 -0
- package/src/components/preview/PreviewPropEditor.tsx +1 -1
- package/src/components/preview/PreviewSpecs.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.32.6",
|
|
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.32.4",
|
|
42
42
|
"angular-html-parser": "^6.0.2",
|
|
43
43
|
"html-format": "^1.1.7",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
@@ -47,8 +47,9 @@
|
|
|
47
47
|
"react-syntax-highlighter": "^15.5.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@babel/plugin-proposal-private-property-in-object": "^7.18.6",
|
|
50
51
|
"@oslokommune/punkt-assets": "^12.30.1",
|
|
51
|
-
"@oslokommune/punkt-css": "^12.
|
|
52
|
+
"@oslokommune/punkt-css": "^12.32.1",
|
|
52
53
|
"@testing-library/jest-dom": "^6.5.0",
|
|
53
54
|
"@testing-library/react": "^16.0.1",
|
|
54
55
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"react-scripts": "^5.0.1",
|
|
72
73
|
"sass": "^1.78.0",
|
|
73
74
|
"typescript": "^5.6.2",
|
|
74
|
-
"vite": "^5.4.
|
|
75
|
+
"vite": "^5.4.18",
|
|
75
76
|
"vite-plugin-dts": "^4.2.1"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
|
@@ -111,5 +112,5 @@
|
|
|
111
112
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
112
113
|
},
|
|
113
114
|
"license": "MIT",
|
|
114
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "20594471ca6c6134e84a9de6b6e332d391566369"
|
|
115
116
|
}
|
|
@@ -94,6 +94,38 @@ test('forwardRef works correctly', async () => {
|
|
|
94
94
|
expect(ref.current).toBe(screen.getByRole('button'))
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
+
test('PktButton triggers click when focused and enter is pressed', async () => {
|
|
98
|
+
const handleClick = jest.fn()
|
|
99
|
+
render(<PktButton onClick={handleClick}>Trøkk her</PktButton>)
|
|
100
|
+
|
|
101
|
+
await window.customElements.whenDefined('pkt-button')
|
|
102
|
+
|
|
103
|
+
const button = screen.getByRole('button')
|
|
104
|
+
|
|
105
|
+
button.focus()
|
|
106
|
+
expect(button).toHaveFocus()
|
|
107
|
+
|
|
108
|
+
await userEvent.keyboard('{Enter}')
|
|
109
|
+
|
|
110
|
+
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('PktButton triggers click when focused and space is pressed', async () => {
|
|
114
|
+
const handleClick = jest.fn()
|
|
115
|
+
render(<PktButton onClick={handleClick}>Trøkk igjen</PktButton>)
|
|
116
|
+
|
|
117
|
+
await window.customElements.whenDefined('pkt-button')
|
|
118
|
+
|
|
119
|
+
const button = screen.getByRole('button')
|
|
120
|
+
|
|
121
|
+
button.focus()
|
|
122
|
+
expect(button).toHaveFocus()
|
|
123
|
+
|
|
124
|
+
await userEvent.keyboard(' ')
|
|
125
|
+
|
|
126
|
+
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
127
|
+
})
|
|
128
|
+
|
|
97
129
|
describe('accessibility', () => {
|
|
98
130
|
it('renders with no wcag errors with axe', async () => {
|
|
99
131
|
const { container } = render(<PktButton title="Normal" skin="primary"></PktButton>)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
ForwardRefExoticComponent,
|
|
3
|
+
ReactNode,
|
|
4
|
+
SelectHTMLAttributes,
|
|
5
|
+
ChangeEventHandler,
|
|
6
|
+
FocusEventHandler,
|
|
7
|
+
FC,
|
|
8
|
+
LegacyRef,
|
|
9
|
+
forwardRef,
|
|
10
|
+
} from 'react'
|
|
11
|
+
import { PktCombobox as PktElCombobox } from '@oslokommune/punkt-elements'
|
|
12
|
+
import type { IPktCombobox as IPktElCombobox, IPktComboboxOption } from '@oslokommune/punkt-elements'
|
|
13
|
+
import { createComponent, EventName } from '@lit/react'
|
|
14
|
+
import { PktEventWithTarget } from '@/interfaces/IPktElements'
|
|
15
|
+
|
|
16
|
+
type ExtendedCombobox = Omit<IPktElCombobox, 'helptext'> & SelectHTMLAttributes<HTMLSelectElement>
|
|
17
|
+
|
|
18
|
+
export interface IPktCombobox extends ExtendedCombobox {
|
|
19
|
+
helptext?: string | ReactNode | ReactNode[]
|
|
20
|
+
ref?: LegacyRef<HTMLSelectElement>
|
|
21
|
+
onChange?: ChangeEventHandler<HTMLSelectElement>
|
|
22
|
+
onInput?: ChangeEventHandler<HTMLSelectElement>
|
|
23
|
+
onBlur?: FocusEventHandler<HTMLSelectElement>
|
|
24
|
+
onFocus?: FocusEventHandler<HTMLSelectElement>
|
|
25
|
+
onValueChange?: (e: CustomEvent) => void
|
|
26
|
+
onToggleHelpText?: (e: CustomEvent) => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const LitComponent = createComponent({
|
|
30
|
+
tagName: 'pkt-combobox',
|
|
31
|
+
elementClass: PktElCombobox,
|
|
32
|
+
react: React,
|
|
33
|
+
displayName: 'PktCombobox',
|
|
34
|
+
events: {
|
|
35
|
+
onChange: 'change' as EventName<PktEventWithTarget>,
|
|
36
|
+
onInput: 'input' as EventName<PktEventWithTarget>,
|
|
37
|
+
onBlur: 'blur' as EventName<FocusEvent>,
|
|
38
|
+
onFocus: 'focus' as EventName<FocusEvent>,
|
|
39
|
+
onValueChange: 'valueChange' as EventName<CustomEvent>,
|
|
40
|
+
onToggleHelpText: 'toggleHelpText' as EventName<CustomEvent>,
|
|
41
|
+
},
|
|
42
|
+
}) as ForwardRefExoticComponent<IPktCombobox>
|
|
43
|
+
|
|
44
|
+
// Note:
|
|
45
|
+
// helptext slot needs to be before children because of how React reactivity works.
|
|
46
|
+
// Please do not change this.
|
|
47
|
+
export const PktCombobox: FC<IPktCombobox> = forwardRef(({ children, helptext, ...props }: IPktCombobox, ref) => {
|
|
48
|
+
return (
|
|
49
|
+
<LitComponent {...props} ref={ref}>
|
|
50
|
+
{helptext && (
|
|
51
|
+
<div slot="helptext" className="pkt-contents">
|
|
52
|
+
{helptext}
|
|
53
|
+
</div>
|
|
54
|
+
)}
|
|
55
|
+
{children}
|
|
56
|
+
</LitComponent>
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
PktCombobox.displayName = 'PktCombobox'
|
package/src/components/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { PktBreadcrumbs } from './breadcrumbs/Breadcrumbs'
|
|
|
6
6
|
export { PktButton } from './button/Button'
|
|
7
7
|
export { PktCard } from './card/Card'
|
|
8
8
|
export { PktCheckbox } from './checkbox/Checkbox'
|
|
9
|
+
export { PktCombobox } from './combobox/Combobox'
|
|
9
10
|
export { PktDatepicker } from './datepicker/Datepicker'
|
|
10
11
|
export { PktFooter } from './footer/Footer'
|
|
11
12
|
export { PktFooterSimple } from './footerSimple/FooterSimple'
|
|
@@ -5,6 +5,7 @@ export type { IPktBackLink } from './backlink/BackLink'
|
|
|
5
5
|
export type { IPktBreadcrumbs } from './breadcrumbs/Breadcrumbs'
|
|
6
6
|
export type { IPktButton } from './button/Button'
|
|
7
7
|
export type { IPktCheckbox } from './checkbox/Checkbox'
|
|
8
|
+
export type { IPktCombobox } from './combobox/Combobox'
|
|
8
9
|
export type { IPktDatepicker } from './datepicker/Datepicker'
|
|
9
10
|
export type { IPktFooter } from './footer/Footer'
|
|
10
11
|
export type { IPktFooterSimple } from './footerSimple/FooterSimple'
|
|
@@ -26,6 +26,19 @@ export const PktPreview: React.FC<PreviewProps> = ({ specs, children, fullWidth
|
|
|
26
26
|
specs.props && typeof specs.props === 'object' && !Array.isArray(specs.props)
|
|
27
27
|
? Object.entries(specs.props).reduce<Record<string, any>>((acc, [key, value]) => {
|
|
28
28
|
if (
|
|
29
|
+
typeof value === 'object' &&
|
|
30
|
+
!Array.isArray(value) &&
|
|
31
|
+
value.previewDefault !== undefined &&
|
|
32
|
+
value.previewDefault !== null
|
|
33
|
+
) {
|
|
34
|
+
if (value.previewDefault === 'false') {
|
|
35
|
+
value.previewDefault = false
|
|
36
|
+
}
|
|
37
|
+
if (value.previewDefault === 'true') {
|
|
38
|
+
value.previewDefault = true
|
|
39
|
+
}
|
|
40
|
+
acc[key] = value.previewDefault
|
|
41
|
+
} else if (
|
|
29
42
|
typeof value === 'object' &&
|
|
30
43
|
!Array.isArray(value) &&
|
|
31
44
|
value.default !== undefined &&
|
|
@@ -78,7 +78,7 @@ export const PktPreviewPropEditor: FC<PropEditorProps> = ({ propKey, spec, props
|
|
|
78
78
|
requiredTag={spec.required}
|
|
79
79
|
>
|
|
80
80
|
<option value=""></option>
|
|
81
|
-
{icons.map((icon) => (
|
|
81
|
+
{(icons as { id: string }[]).map((icon) => (
|
|
82
82
|
<option key={icon.id} value={icon.id}>
|
|
83
83
|
{icon.id}
|
|
84
84
|
</option>
|