@oslokommune/punkt-react 12.40.10 → 12.41.1

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": "12.40.10",
3
+ "version": "12.41.1",
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.40.10",
41
+ "@oslokommune/punkt-elements": "^12.41.1",
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.40.10",
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": "cc642acc20fb7c667d25909bd6309fe613f66c6f"
115
+ "gitHead": "6af0ba1d43d2ba724a15b4d37c80ab62a68c8cae"
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}>Trøkk her</PktButton>)
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 React, {
4
- ForwardRefExoticComponent,
5
- LegacyRef,
6
- FC,
7
- forwardRef,
8
- ForwardedRef,
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
- type ExtendedButton = IPktElButton & ButtonHTMLAttributes<HTMLButtonElement>
11
+ window.pktAnimationPath = window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
20
12
 
21
- export interface IPktButton extends ExtendedButton {
22
- ref?: LegacyRef<HTMLButtonElement>
23
- onClick?: MouseEventHandler<HTMLButtonElement>
24
- onChange?: ChangeEventHandler<HTMLButtonElement>
25
- onBlur?: FocusEventHandler<HTMLButtonElement>
26
- onFocus?: FocusEventHandler<HTMLButtonElement>
27
- onKeydown?: KeyboardEventHandler<HTMLButtonElement>
28
- onKeyup?: KeyboardEventHandler<HTMLButtonElement>
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 LitComponent = createComponent({
32
- tagName: 'pkt-button',
33
- elementClass: PktElButton,
34
- react: React,
35
- displayName: 'PktButton',
36
- events: {
37
- onButtonClick: 'button-click' as EventName<CustomEvent>,
38
- },
39
- }) as ForwardRefExoticComponent<IPktButton>
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
- export const PktButton: FC<IPktButton> = forwardRef(({ children, ...props }, ref: ForwardedRef<HTMLButtonElement>) => {
42
- return (
43
- <LitComponent {...props} ref={ref}>
44
- <div className="pkt-contents">{children}</div>
45
- </LitComponent>
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'
@@ -9,9 +9,10 @@ import React, {
9
9
  FC,
10
10
  LegacyRef,
11
11
  forwardRef,
12
+ MouseEventHandler,
12
13
  } from 'react'
13
14
  import { PktCombobox as PktElCombobox } from '@oslokommune/punkt-elements'
14
- import type { IPktCombobox as IPktElCombobox, IPktComboboxOption } from '@oslokommune/punkt-elements'
15
+ import type { IPktCombobox as IPktElCombobox } from '@oslokommune/punkt-elements'
15
16
  import { createComponent, EventName } from '@lit/react'
16
17
  import { PktEventWithTarget } from '@/interfaces/IPktElements'
17
18
 
@@ -20,6 +21,7 @@ type ExtendedCombobox = Omit<IPktElCombobox, 'helptext'> & SelectHTMLAttributes<
20
21
  export interface IPktCombobox extends ExtendedCombobox {
21
22
  helptext?: string | ReactNode | ReactNode[]
22
23
  ref?: LegacyRef<HTMLSelectElement>
24
+ onClick?: MouseEventHandler<HTMLSelectElement>
23
25
  onChange?: ChangeEventHandler<HTMLSelectElement>
24
26
  onInput?: ChangeEventHandler<HTMLSelectElement>
25
27
  onBlur?: FocusEventHandler<HTMLSelectElement>
@@ -34,6 +36,7 @@ export const LitComponent = createComponent({
34
36
  react: React,
35
37
  displayName: 'PktCombobox',
36
38
  events: {
39
+ onClick: 'click' as EventName<PktEventWithTarget>,
37
40
  onChange: 'change' as EventName<PktEventWithTarget>,
38
41
  onInput: 'input' as EventName<PktEventWithTarget>,
39
42
  onBlur: 'blur' as EventName<FocusEvent>,