@oslokommune/punkt-react 12.29.2 → 12.29.3
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 +17 -0
- package/dist/index.d.ts +5 -24
- package/dist/punkt-react.es.js +8614 -8568
- package/dist/punkt-react.umd.js +286 -276
- package/package.json +3 -3
- package/src/components/index.ts +1 -1
- package/src/components/loader/Loader.test.tsx +21 -8
- package/src/components/loader/Loader.tsx +23 -80
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "12.29.
|
|
3
|
+
"version": "12.29.3",
|
|
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.29.
|
|
41
|
+
"@oslokommune/punkt-elements": "^12.29.3",
|
|
42
42
|
"angular-html-parser": "^6.0.2",
|
|
43
43
|
"html-format": "^1.1.7",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
112
112
|
},
|
|
113
113
|
"license": "MIT",
|
|
114
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "59a0d70f10e765285167342a739bbe6b126a9882"
|
|
115
115
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -9,18 +9,31 @@ expect.extend(toHaveNoViolations)
|
|
|
9
9
|
|
|
10
10
|
describe('PktLoader', () => {
|
|
11
11
|
describe('basic rendering', () => {
|
|
12
|
-
it('renders correctly without any props', () => {
|
|
13
|
-
const {
|
|
14
|
-
|
|
12
|
+
it('renders correctly without any props', async () => {
|
|
13
|
+
const { container } = render(<PktLoader id="loader1" />)
|
|
14
|
+
await window.customElements.whenDefined('pkt-loader')
|
|
15
|
+
|
|
16
|
+
const element = container.querySelector('pkt-loader')
|
|
17
|
+
expect(element).toBeInTheDocument()
|
|
15
18
|
})
|
|
16
19
|
|
|
17
|
-
it('renders', () => {
|
|
18
|
-
const { container } = render(<PktLoader size="
|
|
19
|
-
|
|
20
|
+
it('renders with size and variant', async () => {
|
|
21
|
+
const { container } = render(<PktLoader id="loader1" size="small" variant="rainbow" message="Loading.." />)
|
|
22
|
+
await window.customElements.whenDefined('pkt-loader')
|
|
23
|
+
|
|
24
|
+
const loaderBox = container.querySelector('pkt-loader')
|
|
25
|
+
const loaderSize = loaderBox?.querySelector('.pkt-loader--small')
|
|
26
|
+
|
|
27
|
+
expect(loaderSize).toBeInTheDocument()
|
|
28
|
+
expect(loaderBox).toHaveTextContent('Loading..')
|
|
20
29
|
})
|
|
21
|
-
|
|
30
|
+
|
|
31
|
+
it('renders inline', async () => {
|
|
22
32
|
const { container } = render(<PktLoader size="medium" message="Loading.." inline />)
|
|
23
|
-
|
|
33
|
+
await window.customElements.whenDefined('pkt-loader')
|
|
34
|
+
const elementInline = container.querySelector('.pkt-loader--inline')
|
|
35
|
+
|
|
36
|
+
expect(elementInline).toBeInTheDocument()
|
|
24
37
|
})
|
|
25
38
|
})
|
|
26
39
|
|
|
@@ -1,84 +1,27 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The `delay` prop controls how much time the loading should be given before the loader is displayed.
|
|
23
|
-
* This is handy for situations where the load time might be so short that loader is not necessary.
|
|
24
|
-
* Delay time is in milliseconds.
|
|
25
|
-
*/
|
|
26
|
-
delay?: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const PktLoader = forwardRef(
|
|
30
|
-
(
|
|
31
|
-
{
|
|
32
|
-
className,
|
|
33
|
-
message,
|
|
34
|
-
size = 'medium',
|
|
35
|
-
inline = false,
|
|
36
|
-
isLoading = true,
|
|
37
|
-
variant = 'rainbow',
|
|
38
|
-
delay = 0,
|
|
39
|
-
children,
|
|
40
|
-
...props
|
|
41
|
-
}: IPktLoader,
|
|
42
|
-
ref: ForwardedRef<HTMLDivElement>,
|
|
43
|
-
) => {
|
|
44
|
-
const classes = `pkt-loader pkt-loader--${size}`
|
|
45
|
-
|
|
46
|
-
const [shouldDisplayLoader, setShouldDisplayLoader] = useState(delay > 0 ? false : true)
|
|
47
|
-
|
|
48
|
-
delay > 0 &&
|
|
49
|
-
setTimeout(() => {
|
|
50
|
-
setShouldDisplayLoader(true)
|
|
51
|
-
}, delay)
|
|
52
|
-
|
|
53
|
-
const getVariant = (variant: 'blue' | 'rainbow' | 'shapes'): string => {
|
|
54
|
-
return variant === 'shapes' ? 'loader' : variant === 'blue' ? 'spinner-blue' : 'spinner'
|
|
55
|
-
}
|
|
56
|
-
|
|
1
|
+
import React, { forwardRef, ForwardedRef, FC, ReactElement } from 'react'
|
|
2
|
+
import { createComponent } from '@lit/react'
|
|
3
|
+
import { PktLoader as PktElLoader } from '@oslokommune/punkt-elements'
|
|
4
|
+
import type { IPktLoader as IPktElLoader } from '@oslokommune/punkt-elements'
|
|
5
|
+
import type { PktElType, PktElConstructor } from '@/interfaces/IPktElements'
|
|
6
|
+
|
|
7
|
+
type ExtendedLoader = IPktElLoader & PktElType
|
|
8
|
+
|
|
9
|
+
export interface IPktLoader extends ExtendedLoader {}
|
|
10
|
+
|
|
11
|
+
const LitComponent: FC<IPktLoader> = createComponent({
|
|
12
|
+
tagName: 'pkt-loader',
|
|
13
|
+
elementClass: PktElLoader as PktElConstructor<HTMLElement>,
|
|
14
|
+
react: React,
|
|
15
|
+
displayName: 'PktLoader',
|
|
16
|
+
events: {},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const PktLoader: FC<IPktLoader> = forwardRef(
|
|
20
|
+
({ children, ...props }: IPktLoader, ref: ForwardedRef<HTMLElement>): ReactElement => {
|
|
57
21
|
return (
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
aria-busy={isLoading}
|
|
62
|
-
className={`pkt-loader--${inline ? 'inline' : 'box'} ${className ? className : ''}`}
|
|
63
|
-
>
|
|
64
|
-
{isLoading ? (
|
|
65
|
-
<>
|
|
66
|
-
{shouldDisplayLoader ? (
|
|
67
|
-
<div className={classes} data-testid="pkt-loader" ref={ref} {...props}>
|
|
68
|
-
<PktIcon
|
|
69
|
-
name={getVariant(variant)}
|
|
70
|
-
path="https://punkt-cdn.oslo.kommune.no/latest/animations/"
|
|
71
|
-
className={`pkt-loader__svg pkt-loader__${variant}`}
|
|
72
|
-
/>
|
|
73
|
-
|
|
74
|
-
{message && <p>{message}</p>}
|
|
75
|
-
</div>
|
|
76
|
-
) : null}
|
|
77
|
-
</>
|
|
78
|
-
) : (
|
|
79
|
-
children
|
|
80
|
-
)}
|
|
81
|
-
</div>
|
|
22
|
+
<LitComponent {...props} ref={ref}>
|
|
23
|
+
<div className="pkt-contents">{children}</div>
|
|
24
|
+
</LitComponent>
|
|
82
25
|
)
|
|
83
26
|
},
|
|
84
27
|
)
|