@oslokommune/punkt-react 12.4.0 → 12.5.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 +21 -14
- package/dist/punkt-react.es.js +3246 -3252
- package/dist/punkt-react.umd.js +113 -112
- package/package.json +13 -4
- package/src/components/accordion/Accordion.test.tsx +9 -4
- package/src/components/breadcrumbs/Breadcrumbs.test.tsx +60 -56
- package/src/components/breadcrumbs/Breadcrumbs.tsx +1 -1
- package/src/components/footer/Footer.test.tsx +2 -9
- package/src/components/footerSimple/FooterSimple.test.tsx +1 -8
- package/src/components/header/Header.test.tsx +0 -14
- package/src/components/icon/Icon.test.tsx +24 -48
- package/src/components/icon/Icon.tsx +15 -19
- package/src/components/index.ts +0 -1
- package/src/components/linkcard/LinkCard.test.tsx +0 -11
- package/src/components/loader/Loader.tsx +0 -1
- package/src/components/preview/Preview.tsx +3 -1
- package/src/components/searchinput/SearchInput.test.tsx +13 -6
- package/src/components/tag/Tag.test.tsx +0 -11
- package/src/components/footer/__snapshots__/Footer.test.tsx.snap +0 -156
- package/src/components/footerSimple/__snapshots__/FooterSimple.test.tsx.snap +0 -72
- package/src/components/header/__snapshots__/Header.test.tsx.snap +0 -161
- package/src/components/icon/DefaultIconFetcher.tsx +0 -54
- package/src/components/icon/IconContext.tsx +0 -9
- package/src/components/linkcard/__snapshots__/LinkCard.test.tsx.snap +0 -22
- package/src/components/tag/__snapshots__/Tag.test.tsx.snap +0 -23
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.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",
|
|
7
7
|
"main": "dist/punkt-react.umd.js",
|
|
8
8
|
"module": "dist/punkt-react.es.js",
|
|
9
|
+
"nohoist": [
|
|
10
|
+
"**/@lit",
|
|
11
|
+
"**/@lit/**"
|
|
12
|
+
],
|
|
9
13
|
"files": [
|
|
10
14
|
"/dist",
|
|
11
15
|
"src/components/**/*",
|
|
@@ -43,8 +47,8 @@
|
|
|
43
47
|
},
|
|
44
48
|
"devDependencies": {
|
|
45
49
|
"@oslokommune/punkt-assets": "^12.4.0",
|
|
46
|
-
"@oslokommune/punkt-css": "^12.
|
|
47
|
-
"@oslokommune/punkt-elements": "^12.
|
|
50
|
+
"@oslokommune/punkt-css": "^12.5.0",
|
|
51
|
+
"@oslokommune/punkt-elements": "^12.5.0",
|
|
48
52
|
"@testing-library/jest-dom": "^6.5.0",
|
|
49
53
|
"@testing-library/react": "^16.0.1",
|
|
50
54
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -94,6 +98,11 @@
|
|
|
94
98
|
"ux",
|
|
95
99
|
"ui"
|
|
96
100
|
],
|
|
101
|
+
"jest": {
|
|
102
|
+
"transformIgnorePatterns": [
|
|
103
|
+
"<rootDir>/node_modules/(?!@lit/react)"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
97
106
|
"repository": {
|
|
98
107
|
"type": "git",
|
|
99
108
|
"url": "git+https://github.com/oslokommune/punkt.git"
|
|
@@ -102,5 +111,5 @@
|
|
|
102
111
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
112
|
},
|
|
104
113
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "1342b6cc802b3fef7caa218bc76051777e8dbe57"
|
|
106
115
|
}
|
|
@@ -8,7 +8,7 @@ import React, { createRef } from 'react'
|
|
|
8
8
|
expect.extend(toHaveNoViolations)
|
|
9
9
|
|
|
10
10
|
describe('PktAccordion', () => {
|
|
11
|
-
test('renders without errors', () => {
|
|
11
|
+
test('renders without errors', async () => {
|
|
12
12
|
render(
|
|
13
13
|
<PktAccordion>
|
|
14
14
|
<PktAccordionItem id="render-id" title="test">
|
|
@@ -16,19 +16,21 @@ describe('PktAccordion', () => {
|
|
|
16
16
|
</PktAccordionItem>
|
|
17
17
|
</PktAccordion>,
|
|
18
18
|
)
|
|
19
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
19
20
|
// Assert that the Accordion component renders without throwing any errors
|
|
20
21
|
})
|
|
21
22
|
|
|
22
|
-
test('ref works correctly', () => {
|
|
23
|
+
test('ref works correctly', async () => {
|
|
23
24
|
const ref = createRef<HTMLDivElement>()
|
|
24
25
|
const { unmount } = render(<PktAccordion ref={ref}>Alert text</PktAccordion>)
|
|
26
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
25
27
|
expect(ref.current).toBeInstanceOf(HTMLDivElement)
|
|
26
28
|
|
|
27
29
|
unmount()
|
|
28
30
|
expect(ref.current).toBe(null)
|
|
29
31
|
})
|
|
30
32
|
|
|
31
|
-
test('renders children', () => {
|
|
33
|
+
test('renders children', async () => {
|
|
32
34
|
const mockToggleOpen = jest.fn()
|
|
33
35
|
render(
|
|
34
36
|
<PktAccordion>
|
|
@@ -40,6 +42,7 @@ describe('PktAccordion', () => {
|
|
|
40
42
|
</PktAccordionItem>
|
|
41
43
|
</PktAccordion>,
|
|
42
44
|
)
|
|
45
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
43
46
|
|
|
44
47
|
// Assert that the Accordion component renders its children correctly
|
|
45
48
|
expect(screen.getByText('Title 1')).toBeInTheDocument()
|
|
@@ -48,7 +51,7 @@ describe('PktAccordion', () => {
|
|
|
48
51
|
expect(screen.getByText('Content 2')).toBeInTheDocument()
|
|
49
52
|
})
|
|
50
53
|
|
|
51
|
-
test('applies compact and skin ', () => {
|
|
54
|
+
test('applies compact and skin ', async () => {
|
|
52
55
|
render(
|
|
53
56
|
<>
|
|
54
57
|
<h3 id="accordion-heading">Accordion Heading</h3>
|
|
@@ -59,6 +62,7 @@ describe('PktAccordion', () => {
|
|
|
59
62
|
</PktAccordion>
|
|
60
63
|
</>,
|
|
61
64
|
)
|
|
65
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
62
66
|
// Assert that the Accordion component applies the props correctly
|
|
63
67
|
expect(screen.getByTestId('pkt-accordion')).toHaveClass('pkt-accordion--compact')
|
|
64
68
|
expect(screen.getByTestId('pkt-accordion')).toHaveClass('pkt-accordion--outlined')
|
|
@@ -76,6 +80,7 @@ describe('PktAccordion', () => {
|
|
|
76
80
|
</PktAccordionItem>
|
|
77
81
|
</PktAccordion>,
|
|
78
82
|
)
|
|
83
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
79
84
|
const results = await axe(container)
|
|
80
85
|
expect(results).toHaveNoViolations()
|
|
81
86
|
})
|
|
@@ -1,63 +1,67 @@
|
|
|
1
|
-
import { render } from '@testing-library/react'
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
2
|
import { axe, toHaveNoViolations } from 'jest-axe'
|
|
3
|
-
import { BrowserRouter as Router } from 'react-router-dom'
|
|
3
|
+
import { BrowserRouter as Router } from 'react-router-dom'
|
|
4
4
|
|
|
5
|
-
import { PktBreadcrumbs } from './Breadcrumbs'
|
|
5
|
+
import { PktBreadcrumbs } from './Breadcrumbs'
|
|
6
6
|
|
|
7
7
|
expect.extend(toHaveNoViolations)
|
|
8
8
|
|
|
9
9
|
describe('PktBreadcrumbs Component', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
it('renders breadcrumbs correctly with react-router navigation', () => {
|
|
17
|
-
const { getAllByText } = render(
|
|
18
|
-
<Router>
|
|
19
|
-
<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="router" />
|
|
20
|
-
</Router>
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
expect(getAllByText('Home')).toBeTruthy();
|
|
24
|
-
expect(getAllByText('Products')).toBeTruthy();
|
|
25
|
-
expect(getAllByText('Item')).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('renders breadcrumbs correctly with anchor navigation', () => {
|
|
29
|
-
const { getAllByText } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />);
|
|
30
|
-
|
|
31
|
-
expect(getAllByText('Home')).toBeTruthy();
|
|
32
|
-
expect(getAllByText('Products')).toBeTruthy();
|
|
33
|
-
expect(getAllByText('Item')).toBeTruthy();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('renders back link correctly on mobile with router navigation', () => {
|
|
37
|
-
const { getAllByText } = render(
|
|
38
|
-
<Router>
|
|
39
|
-
<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="router" />
|
|
40
|
-
</Router>
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
expect(getAllByText('Home')).toBeTruthy();
|
|
44
|
-
expect(getAllByText('Products')).toBeTruthy();
|
|
45
|
-
expect(getAllByText('Item')).toBeTruthy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('renders back link correctly on mobile with anchor navigation', () => {
|
|
49
|
-
const { getAllByText } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />);
|
|
50
|
-
|
|
51
|
-
expect(getAllByText('Home')).toBeTruthy();
|
|
52
|
-
expect(getAllByText('Products')).toBeTruthy();
|
|
53
|
-
expect(getAllByText('Item')).toBeTruthy();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('renders with no wcag errors with axe', async () => {
|
|
57
|
-
const { container } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />)
|
|
58
|
-
const results = await axe(container)
|
|
59
|
-
|
|
60
|
-
expect(results).toHaveNoViolations()
|
|
61
|
-
})
|
|
62
|
-
});
|
|
10
|
+
const breadcrumbs = [
|
|
11
|
+
{ text: 'Home', href: '/' },
|
|
12
|
+
{ text: 'Products', href: '/products' },
|
|
13
|
+
{ text: 'Item', href: '/products/item' },
|
|
14
|
+
]
|
|
63
15
|
|
|
16
|
+
it('renders breadcrumbs correctly with react-router navigation', async () => {
|
|
17
|
+
const { getAllByText } = render(
|
|
18
|
+
<Router>
|
|
19
|
+
<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="router" />
|
|
20
|
+
</Router>,
|
|
21
|
+
)
|
|
22
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
23
|
+
|
|
24
|
+
expect(getAllByText('Home')).toBeTruthy()
|
|
25
|
+
expect(getAllByText('Products')).toBeTruthy()
|
|
26
|
+
expect(getAllByText('Item')).toBeTruthy()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('renders breadcrumbs correctly with anchor navigation', async () => {
|
|
30
|
+
const { getAllByText } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />)
|
|
31
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
32
|
+
|
|
33
|
+
expect(getAllByText('Home')).toBeTruthy()
|
|
34
|
+
expect(getAllByText('Products')).toBeTruthy()
|
|
35
|
+
expect(getAllByText('Item')).toBeTruthy()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('renders back link correctly on mobile with router navigation', async () => {
|
|
39
|
+
const { getAllByText } = render(
|
|
40
|
+
<Router>
|
|
41
|
+
<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="router" />
|
|
42
|
+
</Router>,
|
|
43
|
+
)
|
|
44
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
45
|
+
|
|
46
|
+
expect(getAllByText('Home')).toBeTruthy()
|
|
47
|
+
expect(getAllByText('Products')).toBeTruthy()
|
|
48
|
+
expect(getAllByText('Item')).toBeTruthy()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('renders back link correctly on mobile with anchor navigation', async () => {
|
|
52
|
+
const { getAllByText } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />)
|
|
53
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
54
|
+
|
|
55
|
+
expect(getAllByText('Home')).toBeTruthy()
|
|
56
|
+
expect(getAllByText('Products')).toBeTruthy()
|
|
57
|
+
expect(getAllByText('Item')).toBeTruthy()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('renders with no wcag errors with axe', async () => {
|
|
61
|
+
const { container } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs} navigationType="anchor" />)
|
|
62
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
63
|
+
const results = await axe(container)
|
|
64
|
+
|
|
65
|
+
expect(results).toHaveNoViolations()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Test med axe https://www.npmjs.com/package/jest-axe
|
|
2
2
|
import '@testing-library/jest-dom'
|
|
3
3
|
|
|
4
|
-
import { render, screen } from '
|
|
4
|
+
import { render, screen } from '../../utils/test-utils'
|
|
5
5
|
import { axe, toHaveNoViolations } from 'jest-axe'
|
|
6
6
|
|
|
7
7
|
import { PktFooter } from './Footer'
|
|
8
8
|
|
|
9
9
|
expect.extend(toHaveNoViolations)
|
|
10
10
|
|
|
11
|
-
describe('
|
|
11
|
+
describe('PktFooter', () => {
|
|
12
12
|
const columnOne = {
|
|
13
13
|
title: 'Column One',
|
|
14
14
|
links: [
|
|
@@ -108,11 +108,4 @@ describe('PktFooterSimple', () => {
|
|
|
108
108
|
expect(results).toHaveNoViolations()
|
|
109
109
|
})
|
|
110
110
|
})
|
|
111
|
-
|
|
112
|
-
describe('snapshot', () => {
|
|
113
|
-
it('renders correctly with all props', () => {
|
|
114
|
-
const { container } = render(<PktFooter columnOne={columnOne} columnTwo={columnTwo} socialLinks={socialLinks} />)
|
|
115
|
-
expect(container).toMatchSnapshot()
|
|
116
|
-
})
|
|
117
|
-
})
|
|
118
111
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Test med axe https://www.npmjs.com/package/jest-axe
|
|
2
2
|
import '@testing-library/jest-dom'
|
|
3
3
|
|
|
4
|
-
import { render } from '
|
|
4
|
+
import { render } from '../../utils/test-utils'
|
|
5
5
|
import { axe, toHaveNoViolations } from 'jest-axe'
|
|
6
6
|
|
|
7
7
|
import { PktFooterSimple } from './FooterSimple'
|
|
@@ -52,11 +52,4 @@ describe('PktFooterSimple', () => {
|
|
|
52
52
|
expect(results).toHaveNoViolations()
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
|
-
|
|
56
|
-
describe('snapshot', () => {
|
|
57
|
-
it('renders correctly with all props', () => {
|
|
58
|
-
const { container } = render(<PktFooterSimple links={links} />)
|
|
59
|
-
expect(container).toMatchSnapshot()
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
55
|
})
|
|
@@ -78,18 +78,4 @@ describe('PktHeader', () => {
|
|
|
78
78
|
expect(results).toHaveNoViolations()
|
|
79
79
|
})
|
|
80
80
|
})
|
|
81
|
-
|
|
82
|
-
describe('snapshot', () => {
|
|
83
|
-
it('renders correctly with all props', () => {
|
|
84
|
-
const { container } = render(
|
|
85
|
-
<PktHeader
|
|
86
|
-
user={mockUser}
|
|
87
|
-
userMenu={mockUserMenu}
|
|
88
|
-
userMenuFooter={mockUserMenuFooter}
|
|
89
|
-
representing={mockRepresenting}
|
|
90
|
-
/>,
|
|
91
|
-
)
|
|
92
|
-
expect(container).toMatchSnapshot()
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
81
|
})
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import '@testing-library/jest-dom'
|
|
2
2
|
|
|
3
|
-
import { render, screen, waitFor } from '
|
|
3
|
+
import { render, screen, waitFor } from '../../utils/test-utils'
|
|
4
4
|
import React from 'react'
|
|
5
5
|
|
|
6
6
|
import { PktIcon } from './Icon'
|
|
7
|
-
import { IconFetcher, PktIconContext } from './IconContext'
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
pktFetch: () => Promise<{ ok: boolean; text: () => Promise<string> }>
|
|
11
|
+
pktIconPath: string
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
window.pktFetch = (file = 'filnavn.svg') =>
|
|
15
|
+
Promise.resolve({
|
|
16
|
+
ok: true,
|
|
17
|
+
text: () => Promise.resolve(`<svg role="img" data-testid="icon" data-filename=${file}>Her er SVGen</svg>`),
|
|
18
|
+
})
|
|
19
|
+
window.pktIconPath = 'sti'
|
|
11
20
|
|
|
21
|
+
describe('PktIcon', () => {
|
|
12
22
|
const localStorageMock = (() => {
|
|
13
23
|
const store: { [key: string]: string } = {}
|
|
14
24
|
return {
|
|
@@ -22,71 +32,37 @@ describe('PktIcon', () => {
|
|
|
22
32
|
})()
|
|
23
33
|
Object.defineProperty(global, 'localStorage', { value: localStorageMock })
|
|
24
34
|
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
fetchSpy = jest.spyOn(global, 'fetch')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
35
|
describe('with default fetcher', () => {
|
|
30
36
|
test('fetches SVG with default fetcher', async () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
render(<PktIcon name={'arrow'} />)
|
|
37
|
+
await render(<PktIcon name="arrow" />)
|
|
38
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
34
39
|
|
|
35
40
|
const icon = await screen.findByRole('img')
|
|
36
41
|
expect(icon).toMatchInlineSnapshot(`
|
|
37
42
|
<svg
|
|
43
|
+
data-filename="stiarrow.svg"
|
|
44
|
+
data-testid="icon"
|
|
38
45
|
role="img"
|
|
39
46
|
>
|
|
40
|
-
|
|
47
|
+
Her er SVGen
|
|
41
48
|
</svg>
|
|
42
49
|
`)
|
|
43
50
|
})
|
|
44
51
|
|
|
45
52
|
test('fetches SVG', async () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
render(
|
|
51
|
-
<>
|
|
53
|
+
const { container } = await render(
|
|
54
|
+
<div className="root">
|
|
52
55
|
<PktIcon name={'some-icon'} />
|
|
53
56
|
<PktIcon name={'some-other-icon'} />
|
|
54
57
|
<PktIcon name={'some-icon'} />
|
|
55
|
-
|
|
58
|
+
</div>,
|
|
56
59
|
)
|
|
60
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
57
61
|
|
|
58
62
|
await waitFor(async () => {
|
|
59
|
-
const icons = await screen.
|
|
63
|
+
const icons = await screen.findAllByTestId('icon')
|
|
60
64
|
expect(icons).toHaveLength(3)
|
|
61
|
-
expect(fetchSpy).toHaveBeenCalledTimes(2)
|
|
62
65
|
})
|
|
63
66
|
})
|
|
64
67
|
})
|
|
65
|
-
|
|
66
|
-
describe('with custom fetcher', () => {
|
|
67
|
-
test('fetches SVG with custom fetcher', async () => {
|
|
68
|
-
const customIconFetcher: IconFetcher = {
|
|
69
|
-
fetchIcon: jest.fn((name: string, path: string | undefined) => {
|
|
70
|
-
return Promise.resolve(`<svg role="img">Her er SVGen for '${name}' fra '${path}'</svg>`)
|
|
71
|
-
}),
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
render(
|
|
75
|
-
<PktIconContext.Provider value={customIconFetcher}>
|
|
76
|
-
<PktIcon name={'arrow'} path={'http://path/to/something'} />
|
|
77
|
-
</PktIconContext.Provider>,
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
const icon = await screen.findByRole('img')
|
|
81
|
-
expect(icon).toMatchInlineSnapshot(`
|
|
82
|
-
<svg
|
|
83
|
-
role="img"
|
|
84
|
-
>
|
|
85
|
-
Her er SVGen for 'arrow' fra 'http://path/to/something'
|
|
86
|
-
</svg>
|
|
87
|
-
`)
|
|
88
|
-
expect(customIconFetcher.fetchIcon).toHaveBeenCalledTimes(1)
|
|
89
|
-
expect(fetchSpy).not.toHaveBeenCalled()
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
68
|
})
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { FC } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { PktElConstructor, PktElType } from '@/interfaces/IPktElements'
|
|
4
|
+
import { createComponent } from '@lit/react'
|
|
5
|
+
import { PktIcon as PktEl } from '@oslokommune/punkt-elements'
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
type Booleanish = boolean | 'true' | 'false'
|
|
8
|
+
|
|
9
|
+
interface IPktIcon extends PktElType {
|
|
6
10
|
name?: string
|
|
7
11
|
path?: string
|
|
12
|
+
'aria-hidden'?: Booleanish | undefined
|
|
8
13
|
}
|
|
9
14
|
|
|
10
|
-
export const PktIcon:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} else {
|
|
18
|
-
iconFetcherContext.fetchIcon(name, path).then(setInnerHtml)
|
|
19
|
-
}
|
|
20
|
-
}, [name, path])
|
|
21
|
-
|
|
22
|
-
if (!innerHtml) return null
|
|
23
|
-
|
|
24
|
-
return <span className={`pkt-icon ${className}`} dangerouslySetInnerHTML={{ __html: innerHtml }} {...props} />
|
|
25
|
-
}
|
|
15
|
+
export const PktIcon: FC<IPktIcon> = createComponent({
|
|
16
|
+
tagName: 'pkt-icon',
|
|
17
|
+
elementClass: PktEl as PktElConstructor<HTMLElement>,
|
|
18
|
+
react: React,
|
|
19
|
+
displayName: 'PktIcon',
|
|
20
|
+
events: {},
|
|
21
|
+
})
|
|
26
22
|
|
|
27
23
|
export default PktIcon
|
package/src/components/index.ts
CHANGED
|
@@ -11,7 +11,6 @@ export { PktFooter } from './footer/Footer'
|
|
|
11
11
|
export { PktFooterSimple } from './footerSimple/FooterSimple'
|
|
12
12
|
export { PktHeader } from './header/Header'
|
|
13
13
|
export { PktIcon } from './icon/Icon'
|
|
14
|
-
export { PktIconContext } from './icon/IconContext'
|
|
15
14
|
export { PktInput } from './input/Input'
|
|
16
15
|
export { PktInputWrapper } from './inputwrapper/InputWrapper'
|
|
17
16
|
export { PktLink } from './link/Link'
|
|
@@ -61,15 +61,4 @@ describe('PktLinkCard', () => {
|
|
|
61
61
|
expect(results).toHaveNoViolations()
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
|
-
|
|
65
|
-
describe('snapshots', () => {
|
|
66
|
-
it('renders correctly as fragment with props', () => {
|
|
67
|
-
const { asFragment } = render(
|
|
68
|
-
<PktLinkCard title="Link title" href="/example">
|
|
69
|
-
Link content
|
|
70
|
-
</PktLinkCard>,
|
|
71
|
-
)
|
|
72
|
-
expect(asFragment()).toMatchSnapshot()
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
64
|
})
|
|
@@ -67,7 +67,6 @@ export const PktLoader = forwardRef(
|
|
|
67
67
|
<div className={classes} data-testid="pkt-loader" ref={ref} {...props}>
|
|
68
68
|
<PktIcon
|
|
69
69
|
name={getVariant(variant)}
|
|
70
|
-
aria-label="loading"
|
|
71
70
|
path="https://punkt-cdn.oslo.kommune.no/latest/animations/"
|
|
72
71
|
className={`pkt-loader__svg pkt-loader__${variant}`}
|
|
73
72
|
/>
|
|
@@ -106,7 +106,9 @@ export const PktPreview: React.FC<PreviewProps> = ({ specs, children, fullWidth
|
|
|
106
106
|
.replaceAll(componentType, specs.name || '')
|
|
107
107
|
.replaceAll('={', "='")
|
|
108
108
|
.replaceAll('}\n', "'\n")
|
|
109
|
-
.replaceAll(/([a-zA-Z0-9]+)(:)/g, '"$1"$2')
|
|
109
|
+
.replaceAll(/([a-zA-Z0-9]+)(:)/g, '"$1"$2')
|
|
110
|
+
.replaceAll('"https"', 'https')
|
|
111
|
+
.replaceAll('className', 'class'),
|
|
110
112
|
)
|
|
111
113
|
})
|
|
112
114
|
} else {
|
|
@@ -22,31 +22,36 @@ const Wrapper = (props: { onChange: (e: React.ChangeEvent) => void }) => {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
describe('PktSearchInput', () => {
|
|
25
|
-
it('renders with form element when action prop exists', () => {
|
|
25
|
+
it('renders with form element when action prop exists', async () => {
|
|
26
26
|
const { container } = render(<PktSearchInput id="test-search-input" action="/search" />)
|
|
27
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
27
28
|
expect(container.querySelector('form')).toBeInTheDocument()
|
|
28
29
|
})
|
|
29
30
|
|
|
30
|
-
it('renders with div element when action prop does not exist', () => {
|
|
31
|
+
it('renders with div element when action prop does not exist', async () => {
|
|
31
32
|
const { container } = render(<PktSearchInput id="test-search-input" />)
|
|
33
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
32
34
|
expect(container.querySelector('div')).toBeInTheDocument()
|
|
33
35
|
expect(container.querySelector('form')).not.toBeInTheDocument()
|
|
34
36
|
})
|
|
35
37
|
|
|
36
|
-
it('renders with label element when label prop exists', () => {
|
|
38
|
+
it('renders with label element when label prop exists', async () => {
|
|
37
39
|
const { container } = render(<PktSearchInput id="test-search-input" label="Test Label" />)
|
|
40
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
38
41
|
expect(container.querySelector('label')).toBeInTheDocument()
|
|
39
42
|
})
|
|
40
43
|
|
|
41
|
-
it('renders with div element when label prop does not exist', () => {
|
|
44
|
+
it('renders with div element when label prop does not exist', async () => {
|
|
42
45
|
const { container } = render(<PktSearchInput id="test-search-input" />)
|
|
46
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
43
47
|
expect(container.querySelector('div')).toBeInTheDocument()
|
|
44
48
|
expect(container.querySelector('label')).not.toBeInTheDocument()
|
|
45
49
|
})
|
|
46
50
|
|
|
47
|
-
it('calls onSearch prop with input value on button click', () => {
|
|
51
|
+
it('calls onSearch prop with input value on button click', async () => {
|
|
48
52
|
const mockOnSearch = jest.fn()
|
|
49
53
|
const { getByRole, getByPlaceholderText } = render(<Wrapper onChange={mockOnSearch} />)
|
|
54
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
50
55
|
|
|
51
56
|
const inputElement = getByPlaceholderText('Søk…')
|
|
52
57
|
const buttonElement = getByRole('button')
|
|
@@ -63,13 +68,14 @@ describe('PktSearchInput', () => {
|
|
|
63
68
|
)
|
|
64
69
|
})
|
|
65
70
|
|
|
66
|
-
it('renders search suggestions when suggestions prop exists', () => {
|
|
71
|
+
it('renders search suggestions when suggestions prop exists', async () => {
|
|
67
72
|
const suggestions = [
|
|
68
73
|
{ title: 'Suggestion 1', onClick: jest.fn() },
|
|
69
74
|
{ title: 'Suggestion 2', onClick: jest.fn() },
|
|
70
75
|
]
|
|
71
76
|
|
|
72
77
|
render(<PktSearchInput id="test-search-input" suggestions={suggestions} />)
|
|
78
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
73
79
|
|
|
74
80
|
// Check if suggestion elements are rendered
|
|
75
81
|
suggestions.forEach((suggestion) => {
|
|
@@ -84,6 +90,7 @@ describe('PktSearchInput', () => {
|
|
|
84
90
|
{ title: 'Suggestion 2', onClick: jest.fn() },
|
|
85
91
|
]
|
|
86
92
|
const { container } = render(<PktSearchInput id="test-search-input" label="My label" suggestions={suggestions} />)
|
|
93
|
+
await window.customElements.whenDefined('pkt-icon')
|
|
87
94
|
const results = await axe(container)
|
|
88
95
|
expect(results).toHaveNoViolations()
|
|
89
96
|
})
|
|
@@ -71,15 +71,4 @@ describe('PktTag', () => {
|
|
|
71
71
|
expect(results).toHaveNoViolations()
|
|
72
72
|
})
|
|
73
73
|
})
|
|
74
|
-
|
|
75
|
-
describe('snapshot', () => {
|
|
76
|
-
it('renders correctly with all props', () => {
|
|
77
|
-
const { container } = render(
|
|
78
|
-
<PktTag skin="red" size="small" iconName="user" closeTag={true}>
|
|
79
|
-
Tag
|
|
80
|
-
</PktTag>,
|
|
81
|
-
)
|
|
82
|
-
expect(container).toMatchSnapshot()
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
74
|
})
|