@oslokommune/punkt-react 12.12.3 → 12.13.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 +20 -0
- package/dist/index.d.ts +3 -3
- package/dist/punkt-react.es.js +3499 -3474
- package/dist/punkt-react.umd.js +200 -188
- package/package.json +4 -4
- package/src/components/linkcard/LinkCard.test.tsx +85 -22
- package/src/components/linkcard/LinkCard.tsx +19 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.13.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",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@oslokommune/punkt-assets": "^12.7.3",
|
|
50
|
-
"@oslokommune/punkt-css": "^12.
|
|
51
|
-
"@oslokommune/punkt-elements": "^12.
|
|
50
|
+
"@oslokommune/punkt-css": "^12.13.0",
|
|
51
|
+
"@oslokommune/punkt-elements": "^12.13.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.5.0",
|
|
53
53
|
"@testing-library/react": "^16.0.1",
|
|
54
54
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
112
112
|
},
|
|
113
113
|
"license": "MIT",
|
|
114
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "fafdb670e002cbf94fd34acc45dd066344695816"
|
|
115
115
|
}
|
|
@@ -10,49 +10,112 @@ import { PktLinkCard } from './LinkCard'
|
|
|
10
10
|
expect.extend(toHaveNoViolations)
|
|
11
11
|
|
|
12
12
|
describe('PktLinkCard', () => {
|
|
13
|
+
// BASIC RENDERING TESTS
|
|
13
14
|
describe('basic rendering', () => {
|
|
14
|
-
it('renders with
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
it('renders correctly with only default props', async () => {
|
|
16
|
+
const { getByText } = render(<PktLinkCard>LinkCard Content</PktLinkCard>)
|
|
17
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
18
|
+
expect(getByText('LinkCard Content')).toBeInTheDocument()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('renders with title', async () => {
|
|
22
|
+
render(<PktLinkCard title="Link title">Link content</PktLinkCard>)
|
|
23
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
24
|
+
const iconElement = document.querySelector('.pkt-linkcard__title')
|
|
25
|
+
expect(iconElement).toBeInTheDocument()
|
|
26
|
+
})
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
it('renders without title', async () => {
|
|
29
|
+
render(<PktLinkCard>Link content</PktLinkCard>)
|
|
30
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
31
|
+
const iconElement = document.querySelector('.pkt-linkcard__title')
|
|
32
|
+
expect(iconElement).not.toBeInTheDocument()
|
|
24
33
|
})
|
|
25
34
|
|
|
26
|
-
it('renders
|
|
35
|
+
it('renders with correct href', async () => {
|
|
27
36
|
const href = 'https://www.example.com'
|
|
28
|
-
const {
|
|
29
|
-
|
|
37
|
+
const { container } = render(
|
|
38
|
+
<PktLinkCard title="Link title" href={href}>
|
|
39
|
+
Link content
|
|
40
|
+
</PktLinkCard>,
|
|
41
|
+
)
|
|
42
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
43
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
30
44
|
expect(linkElement).toHaveAttribute('href', href)
|
|
31
45
|
})
|
|
32
46
|
})
|
|
33
47
|
|
|
48
|
+
// SKIN TESTS
|
|
49
|
+
|
|
34
50
|
describe('skins', () => {
|
|
35
|
-
it('renders with
|
|
51
|
+
it('renders with normal skin', async () => {
|
|
52
|
+
const { container } = render(
|
|
53
|
+
<div>
|
|
54
|
+
<PktLinkCard title="normal" skin="normal" />
|
|
55
|
+
</div>,
|
|
56
|
+
)
|
|
57
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
58
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
59
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--normal')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('renders with blue skin', async () => {
|
|
36
63
|
const { container } = render(
|
|
37
64
|
<div>
|
|
38
|
-
<PktLinkCard title="Normal" skin="normal" />
|
|
39
65
|
<PktLinkCard title="Blue" skin="blue" />
|
|
66
|
+
</div>,
|
|
67
|
+
)
|
|
68
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
69
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
70
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--blue')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('renders with beige skin', async () => {
|
|
74
|
+
const { container } = render(
|
|
75
|
+
<div>
|
|
40
76
|
<PktLinkCard title="Beige" skin="beige" />
|
|
77
|
+
</div>,
|
|
78
|
+
)
|
|
79
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
80
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
81
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--beige')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('renders with green skin', async () => {
|
|
85
|
+
const { container } = render(
|
|
86
|
+
<div>
|
|
87
|
+
<PktLinkCard title="Green" skin="green" />
|
|
88
|
+
</div>,
|
|
89
|
+
)
|
|
90
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
91
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
92
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--green')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('renders with beige-outline skin', async () => {
|
|
96
|
+
const { container } = render(
|
|
97
|
+
<div>
|
|
41
98
|
<PktLinkCard title="Beige outline" skin="beige-outline" />
|
|
42
|
-
|
|
99
|
+
</div>,
|
|
100
|
+
)
|
|
101
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
102
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
103
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--beige-outline')
|
|
104
|
+
})
|
|
105
|
+
it('renders with gray-outline skin', async () => {
|
|
106
|
+
const { container } = render(
|
|
107
|
+
<div>
|
|
43
108
|
<PktLinkCard title="Gray outline" skin="gray-outline" />
|
|
44
109
|
</div>,
|
|
45
110
|
)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(
|
|
49
|
-
expect(container.querySelectorAll('.pkt-linkcard--beige')).toHaveLength(1)
|
|
50
|
-
expect(container.querySelectorAll('.pkt-linkcard--beige-outline')).toHaveLength(1)
|
|
51
|
-
expect(container.querySelectorAll('.pkt-linkcard--grey-outline')).toHaveLength(1)
|
|
52
|
-
expect(container.querySelectorAll('.pkt-linkcard--gray-outline')).toHaveLength(1)
|
|
111
|
+
await window.customElements.whenDefined('pkt-linkcard')
|
|
112
|
+
const linkElement = container.querySelector('.pkt-linkcard')
|
|
113
|
+
expect(linkElement).toHaveClass('pkt-linkcard pkt-linkcard--gray-outline')
|
|
53
114
|
})
|
|
54
115
|
})
|
|
55
116
|
|
|
117
|
+
// ACCESSIBILITY TESTS
|
|
118
|
+
|
|
56
119
|
describe('accessibility', () => {
|
|
57
120
|
it('renders with no wcag errors with axe', async () => {
|
|
58
121
|
const { container } = render(<PktLinkCard title="Normal" skin="normal"></PktLinkCard>)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React, { ForwardedRef, forwardRef } from 'react'
|
|
1
|
+
import React, { FC, ForwardedRef, forwardRef, ReactElement } from 'react'
|
|
2
|
+
import { createComponent } from '@lit/react'
|
|
3
|
+
import { PktLinkCard as PktElLinkCard } from '@oslokommune/punkt-elements'
|
|
4
|
+
import type { PktElType, PktElConstructor } from '@/interfaces/IPktElements'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface IPktLinkCard extends React.HTMLAttributes<HTMLAnchorElement> {
|
|
6
|
-
skin?: 'normal' | 'blue' | 'beige' | 'beige-outline' | 'green' | 'grey' | 'gray' | 'grey-outline' | 'gray-outline'
|
|
6
|
+
export interface IPktLinkCard extends PktElType {
|
|
7
|
+
skin?: 'normal' | 'blue' | 'beige' | 'green' | 'gray' | 'beige-outline' | 'gray-outline'
|
|
7
8
|
title?: string
|
|
8
9
|
href?: string
|
|
9
10
|
iconName?: string
|
|
@@ -11,35 +12,20 @@ export interface IPktLinkCard extends React.HTMLAttributes<HTMLAnchorElement> {
|
|
|
11
12
|
external?: boolean
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
title,
|
|
25
|
-
...props
|
|
26
|
-
}: IPktLinkCard,
|
|
27
|
-
ref: ForwardedRef<HTMLAnchorElement>,
|
|
28
|
-
) => {
|
|
29
|
-
const classes = [className, 'pkt-linkcard', skin && `pkt-linkcard--${skin}`].filter(Boolean).join(' ')
|
|
15
|
+
const LitComponent: FC<IPktLinkCard> = createComponent({
|
|
16
|
+
tagName: 'pkt-linkcard',
|
|
17
|
+
elementClass: PktElLinkCard as PktElConstructor<HTMLElement>,
|
|
18
|
+
react: React,
|
|
19
|
+
displayName: 'PktLinkCard',
|
|
20
|
+
events: {},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const PktLinkCard: FC<IPktLinkCard> = forwardRef(
|
|
24
|
+
({ children, ...props }: IPktLinkCard, ref: ForwardedRef<HTMLElement>): ReactElement => {
|
|
30
25
|
return (
|
|
31
|
-
<
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
className={`pkt-linkcard pkt-link ${classes}`}
|
|
35
|
-
target={openInNewTab ? '_blank' : '_self'}
|
|
36
|
-
rel={openInNewTab ? 'noopener noreferrer' : undefined}
|
|
37
|
-
ref={ref}
|
|
38
|
-
>
|
|
39
|
-
{iconName && <PktIcon className="pkt-link__icon" name={iconName}></PktIcon>}
|
|
40
|
-
<div className={`pkt-linkcard__title ${external ? 'pkt-link pkt-link--external' : ''}`}>{title}</div>
|
|
41
|
-
<div className="pkt-linkcard__text">{children}</div>
|
|
42
|
-
</a>
|
|
26
|
+
<LitComponent ref={ref} {...props}>
|
|
27
|
+
<div className="pkt-contents">{children}</div>
|
|
28
|
+
</LitComponent>
|
|
43
29
|
)
|
|
44
30
|
},
|
|
45
31
|
)
|