@oslokommune/punkt-react 12.40.9 → 12.41.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 +31 -0
- package/dist/index.d.ts +13 -14
- package/dist/punkt-react.es.js +3026 -3002
- package/dist/punkt-react.umd.js +244 -235
- package/package.json +4 -4
- package/src/components/button/Button.test.tsx +2 -9
- package/src/components/button/Button.tsx +84 -40
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.41.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": "^12.
|
|
41
|
+
"@oslokommune/punkt-elements": "^12.41.0",
|
|
42
42
|
"angular-html-parser": "^6.0.2",
|
|
43
43
|
"html-format": "^1.1.7",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/plugin-proposal-private-property-in-object": "^7.18.6",
|
|
51
51
|
"@oslokommune/punkt-assets": "^12.39.2",
|
|
52
|
-
"@oslokommune/punkt-css": "^12.
|
|
52
|
+
"@oslokommune/punkt-css": "^12.41.0",
|
|
53
53
|
"@testing-library/jest-dom": "^6.5.0",
|
|
54
54
|
"@testing-library/react": "^16.0.1",
|
|
55
55
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -112,5 +112,5 @@
|
|
|
112
112
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
113
113
|
},
|
|
114
114
|
"license": "MIT",
|
|
115
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "0fa02d9d211044739d7b86ec9f24f334df782a1d"
|
|
116
116
|
}
|
|
@@ -87,8 +87,6 @@ test('forwardRef works correctly', async () => {
|
|
|
87
87
|
const ref = createRef<HTMLButtonElement>()
|
|
88
88
|
render(<PktButton ref={ref}>Click me</PktButton>)
|
|
89
89
|
|
|
90
|
-
await window.customElements.whenDefined('pkt-button')
|
|
91
|
-
|
|
92
90
|
await userEvent.click(screen.getByText('Click me'))
|
|
93
91
|
|
|
94
92
|
expect(ref.current).toBe(screen.getByRole('button'))
|
|
@@ -96,17 +94,14 @@ test('forwardRef works correctly', async () => {
|
|
|
96
94
|
|
|
97
95
|
test('PktButton triggers click when focused and enter is pressed', async () => {
|
|
98
96
|
const handleClick = jest.fn()
|
|
99
|
-
render(<PktButton onClick={handleClick}>
|
|
100
|
-
|
|
101
|
-
await window.customElements.whenDefined('pkt-button')
|
|
97
|
+
render(<PktButton onClick={handleClick}>trøkk her</PktButton>)
|
|
102
98
|
|
|
103
|
-
const button = screen.getByRole('button')
|
|
99
|
+
const button = screen.getByRole('button', { name: /trøkk her/i })
|
|
104
100
|
|
|
105
101
|
button.focus()
|
|
106
102
|
expect(button).toHaveFocus()
|
|
107
103
|
|
|
108
104
|
await userEvent.keyboard('{Enter}')
|
|
109
|
-
|
|
110
105
|
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
111
106
|
})
|
|
112
107
|
|
|
@@ -114,8 +109,6 @@ test('PktButton triggers click when focused and space is pressed', async () => {
|
|
|
114
109
|
const handleClick = jest.fn()
|
|
115
110
|
render(<PktButton onClick={handleClick}>Trøkk igjen</PktButton>)
|
|
116
111
|
|
|
117
|
-
await window.customElements.whenDefined('pkt-button')
|
|
118
|
-
|
|
119
112
|
const button = screen.getByRole('button')
|
|
120
113
|
|
|
121
114
|
button.focus()
|
|
@@ -1,49 +1,93 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import React, { ForwardedRef, forwardRef } from 'react'
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
KeyboardEventHandler,
|
|
10
|
-
ChangeEventHandler,
|
|
11
|
-
FocusEventHandler,
|
|
12
|
-
MouseEventHandler,
|
|
13
|
-
ButtonHTMLAttributes,
|
|
14
|
-
} from 'react'
|
|
15
|
-
import { createComponent, EventName } from '@lit/react'
|
|
16
|
-
import { PktButton as PktElButton } from '@oslokommune/punkt-elements'
|
|
17
|
-
import type { IPktButton as IPktElButton } from '@oslokommune/punkt-elements'
|
|
4
|
+
import { PktIcon } from '../icon/Icon'
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
pktAnimationPath?: string
|
|
8
|
+
}
|
|
9
|
+
}
|
|
18
10
|
|
|
19
|
-
|
|
11
|
+
window.pktAnimationPath = window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
|
|
20
12
|
|
|
21
|
-
export interface IPktButton extends
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
export interface IPktButton extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
14
|
+
iconName?: string
|
|
15
|
+
secondIconName?: string
|
|
16
|
+
mode?: 'light' | 'dark'
|
|
17
|
+
size?: 'small' | 'medium' | 'large'
|
|
18
|
+
color?:
|
|
19
|
+
| 'blue'
|
|
20
|
+
| 'blue-outline'
|
|
21
|
+
| 'green'
|
|
22
|
+
| 'green-outline'
|
|
23
|
+
| 'green-dark'
|
|
24
|
+
| 'green-dark-outline'
|
|
25
|
+
| 'beige-light'
|
|
26
|
+
| 'beige-dark-outline'
|
|
27
|
+
| 'yellow'
|
|
28
|
+
| 'yellow-outline'
|
|
29
|
+
| 'red'
|
|
30
|
+
| 'red-outline'
|
|
31
|
+
skin?: 'primary' | 'secondary' | 'tertiary'
|
|
32
|
+
variant?: 'label-only' | 'icon-left' | 'icon-right' | 'icon-only' | 'icons-right-and-left'
|
|
33
|
+
state?: 'normal' | 'focus' | 'hover' | 'active'
|
|
34
|
+
type?: 'button' | 'submit' | 'reset'
|
|
35
|
+
isLoading?: boolean
|
|
36
|
+
loadingAnimationPath?: string
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
export const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
export const PktButton = forwardRef(
|
|
40
|
+
(
|
|
41
|
+
{
|
|
42
|
+
children,
|
|
43
|
+
className,
|
|
44
|
+
iconName = 'user',
|
|
45
|
+
secondIconName = 'user',
|
|
46
|
+
size = 'medium',
|
|
47
|
+
skin = 'primary',
|
|
48
|
+
type = 'button',
|
|
49
|
+
variant = 'label-only',
|
|
50
|
+
state,
|
|
51
|
+
color,
|
|
52
|
+
isLoading = undefined,
|
|
53
|
+
disabled = undefined,
|
|
54
|
+
loadingAnimationPath = window.pktAnimationPath,
|
|
55
|
+
...props
|
|
56
|
+
}: IPktButton,
|
|
57
|
+
ref: ForwardedRef<HTMLButtonElement>,
|
|
58
|
+
) => {
|
|
59
|
+
const classes = [
|
|
60
|
+
className,
|
|
61
|
+
'pkt-btn',
|
|
62
|
+
size && `pkt-btn--${size}`,
|
|
63
|
+
skin && `pkt-btn--${skin}`,
|
|
64
|
+
variant && `pkt-btn--${variant}`,
|
|
65
|
+
color && `pkt-btn--${color}`,
|
|
66
|
+
state && `pkt-btn--${state}`,
|
|
67
|
+
isLoading && `pkt-btn--isLoading`,
|
|
68
|
+
]
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join(' ')
|
|
40
71
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
72
|
+
return (
|
|
73
|
+
<button
|
|
74
|
+
{...props}
|
|
75
|
+
aria-busy={isLoading || undefined}
|
|
76
|
+
aria-disabled={disabled || undefined}
|
|
77
|
+
disabled={disabled}
|
|
78
|
+
className={classes}
|
|
79
|
+
type={type}
|
|
80
|
+
ref={ref}
|
|
81
|
+
>
|
|
82
|
+
{isLoading && (
|
|
83
|
+
<PktIcon className="pkt-btn__icon pkt-btn__spinner" name="spinner-blue" path={loadingAnimationPath} />
|
|
84
|
+
)}
|
|
85
|
+
{variant !== 'label-only' && <PktIcon className="pkt-btn__icon" name={iconName}></PktIcon>}
|
|
86
|
+
<span className="pkt-btn__text">{children}</span>
|
|
87
|
+
{variant === 'icons-right-and-left' && <PktIcon className="pkt-btn__icon" name={secondIconName}></PktIcon>}
|
|
88
|
+
</button>
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
)
|
|
48
92
|
|
|
49
93
|
PktButton.displayName = 'PktButton'
|