@oslokommune/punkt-react 13.10.1 → 13.12.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 +6 -4
- package/dist/punkt-react.es.js +1035 -1013
- package/dist/punkt-react.umd.js +52 -52
- package/package.json +5 -5
- package/src/components/messagebox/Messagebox.test.tsx +63 -0
- package/src/components/messagebox/Messagebox.tsx +58 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.12.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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@lit-labs/ssr-dom-shim": "^1.2.1",
|
|
41
41
|
"@lit/react": "^1.0.7",
|
|
42
|
-
"@oslokommune/punkt-elements": "^13.
|
|
42
|
+
"@oslokommune/punkt-elements": "^13.11.0",
|
|
43
43
|
"classnames": "^2.5.1",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
45
45
|
"react-element-to-jsx-string": "^15.0.0",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
|
|
51
|
-
"@oslokommune/punkt-assets": "^13.
|
|
52
|
-
"@oslokommune/punkt-css": "^13.
|
|
51
|
+
"@oslokommune/punkt-assets": "^13.11.0",
|
|
52
|
+
"@oslokommune/punkt-css": "^13.11.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",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
107
107
|
},
|
|
108
108
|
"license": "MIT",
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "d3cc0fca4886e3b69ab5cbe305765cef483eab32"
|
|
110
110
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { fireEvent, render as originalRender } from '@testing-library/react'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
import { PktMessagebox } from './Messagebox'
|
|
5
|
+
|
|
6
|
+
describe('Messagebox', () => {
|
|
7
|
+
const render = (jsx: ReactNode) => {
|
|
8
|
+
const renderResult = originalRender(jsx)
|
|
9
|
+
const messageBox = renderResult.container.children[0]
|
|
10
|
+
return { ...renderResult, messageBox }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
it('render with defaults', async () => {
|
|
14
|
+
const { messageBox } = render(<PktMessagebox />)
|
|
15
|
+
|
|
16
|
+
expect(messageBox.className).toEqual('pkt-messagebox')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('render with skin', async () => {
|
|
20
|
+
const { messageBox } = render(<PktMessagebox skin={'green'} />)
|
|
21
|
+
|
|
22
|
+
expect(messageBox.classList).toContain('pkt-messagebox--green')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('render compact', async () => {
|
|
26
|
+
const { messageBox } = render(<PktMessagebox compact />)
|
|
27
|
+
|
|
28
|
+
expect(messageBox.classList).toContain('pkt-messagebox--compact')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('render simple title', async () => {
|
|
32
|
+
const { getByText } = render(<PktMessagebox title={'Messagebox title'} />)
|
|
33
|
+
const titleElement = getByText('Messagebox title')
|
|
34
|
+
expect(titleElement.classList).toContain('pkt-messagebox__title')
|
|
35
|
+
})
|
|
36
|
+
it('render complex title', async () => {
|
|
37
|
+
const { messageBox } = render(
|
|
38
|
+
<PktMessagebox
|
|
39
|
+
title={
|
|
40
|
+
<>
|
|
41
|
+
Message<strong>box</strong> title
|
|
42
|
+
</>
|
|
43
|
+
}
|
|
44
|
+
/>,
|
|
45
|
+
)
|
|
46
|
+
const titleElement = messageBox.querySelector('.pkt-messagebox__title')!
|
|
47
|
+
expect(titleElement.innerHTML).toEqual('Message<strong>box</strong> title')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('should render empty title element when no title specified', async () => {
|
|
51
|
+
const { messageBox } = render(<PktMessagebox title={''} />)
|
|
52
|
+
expect(messageBox.querySelector('.pkt-messagebox__title')).toBeInTheDocument()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('closable', async () => {
|
|
56
|
+
const { getByRole, messageBox } = render(<PktMessagebox closable />)
|
|
57
|
+
const closeButton = getByRole('button', { name: 'Lukk' })
|
|
58
|
+
|
|
59
|
+
fireEvent.click(closeButton)
|
|
60
|
+
|
|
61
|
+
expect(messageBox.classList).toContain('pkt-hide')
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -1,36 +1,66 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import { createRef, FC, HTMLAttributes, ReactNode, useCallback, useState } from 'react'
|
|
5
|
+
|
|
6
|
+
import { PktIcon } from '..'
|
|
7
|
+
|
|
8
|
+
export type TMessageboxSkin = 'beige' | 'blue' | 'red' | 'green'
|
|
9
|
+
|
|
10
|
+
export interface IPktMessagebox extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
11
|
+
skin?: TMessageboxSkin
|
|
12
|
+
title?: ReactNode
|
|
11
13
|
compact?: boolean
|
|
12
14
|
closable?: boolean
|
|
13
|
-
onClose?: (
|
|
15
|
+
onClose?: () => void
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
export const PktMessagebox: FC<IPktMessagebox> = ({
|
|
19
|
+
children,
|
|
20
|
+
className,
|
|
21
|
+
skin,
|
|
22
|
+
title,
|
|
23
|
+
compact,
|
|
24
|
+
closable,
|
|
25
|
+
onClose,
|
|
26
|
+
...props
|
|
27
|
+
}: IPktMessagebox) => {
|
|
28
|
+
const [closed, setClosed] = useState(false)
|
|
29
|
+
|
|
30
|
+
const classes = {
|
|
31
|
+
'pkt-messagebox': true,
|
|
32
|
+
'pkt-messagebox--compact': compact,
|
|
33
|
+
[`pkt-messagebox--${skin}`]: skin,
|
|
34
|
+
'pkt-messagebox--closable': closable,
|
|
35
|
+
'pkt-hide': closed,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const componentRootRef = createRef<HTMLDivElement>()
|
|
39
|
+
|
|
40
|
+
const close = useCallback(() => {
|
|
41
|
+
setClosed(true)
|
|
42
|
+
if (onClose) {
|
|
43
|
+
onClose()
|
|
44
|
+
}
|
|
45
|
+
}, [setClosed, onClose])
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div {...props} className={classNames(classes, className)} ref={componentRootRef}>
|
|
49
|
+
{closable && (
|
|
50
|
+
<div className={'"pkt-messagebox__close"'}>
|
|
51
|
+
<button
|
|
52
|
+
onClick={close}
|
|
53
|
+
className={'pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only'}
|
|
54
|
+
aria-label={'Lukk'}
|
|
55
|
+
>
|
|
56
|
+
<PktIcon name="close" className="pkt-link__icon" />
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
)}
|
|
60
|
+
<div className="pkt-messagebox__title">{title}</div>
|
|
61
|
+
<div className={'pkt-messagebox__text'}>{children}</div>
|
|
62
|
+
</div>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
35
65
|
|
|
36
66
|
PktMessagebox.displayName = 'PktMessagebox'
|