@oslokommune/punkt-react 13.13.1 → 13.14.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 +40 -0
- package/dist/index.d.ts +4 -2
- package/dist/punkt-react.es.js +878 -846
- package/dist/punkt-react.umd.js +106 -106
- package/package.json +4 -4
- package/src/components/button/Button.tsx +6 -0
- package/src/components/link/Link.test.tsx +112 -0
- package/src/components/link/Link.tsx +35 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.14.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.13.
|
|
42
|
+
"@oslokommune/punkt-elements": "^13.13.2",
|
|
43
43
|
"classnames": "^2.5.1",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
45
45
|
"react-element-to-jsx-string": "^15.0.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
|
|
51
51
|
"@oslokommune/punkt-assets": "^13.11.0",
|
|
52
|
-
"@oslokommune/punkt-css": "^13.13.
|
|
52
|
+
"@oslokommune/punkt-css": "^13.13.2",
|
|
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": "fe689e7956b40608a560d8c8cd6ee32b5f408f27"
|
|
110
110
|
}
|
|
@@ -16,6 +16,8 @@ export interface IPktButton extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
16
16
|
secondIconName?: string
|
|
17
17
|
mode?: 'light' | 'dark'
|
|
18
18
|
size?: 'small' | 'medium' | 'large'
|
|
19
|
+
fullWidth?: boolean
|
|
20
|
+
fullWidthOnMobile?: boolean
|
|
19
21
|
color?:
|
|
20
22
|
| 'blue'
|
|
21
23
|
| 'blue-outline'
|
|
@@ -45,6 +47,8 @@ export const PktButton = forwardRef(
|
|
|
45
47
|
iconName = 'user',
|
|
46
48
|
secondIconName = 'user',
|
|
47
49
|
size = 'medium',
|
|
50
|
+
fullWidth = false,
|
|
51
|
+
fullWidthOnMobile = false,
|
|
48
52
|
skin = 'primary',
|
|
49
53
|
type = 'button',
|
|
50
54
|
variant = 'label-only',
|
|
@@ -61,6 +65,8 @@ export const PktButton = forwardRef(
|
|
|
61
65
|
className,
|
|
62
66
|
'pkt-btn',
|
|
63
67
|
size && `pkt-btn--${size}`,
|
|
68
|
+
fullWidth && 'pkt-btn--full',
|
|
69
|
+
fullWidthOnMobile && 'pkt-btn--full-small',
|
|
64
70
|
skin && `pkt-btn--${skin}`,
|
|
65
71
|
variant && `pkt-btn--${variant}`,
|
|
66
72
|
color && `pkt-btn--${color}`,
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
|
|
3
|
+
import { PktLink } from './Link'
|
|
4
|
+
|
|
5
|
+
describe('PktLink', () => {
|
|
6
|
+
it('should render with children element', () => {
|
|
7
|
+
render(
|
|
8
|
+
<PktLink href="/test">
|
|
9
|
+
Test <strong>Link</strong>
|
|
10
|
+
</PktLink>,
|
|
11
|
+
)
|
|
12
|
+
const link = screen.getByRole('link')
|
|
13
|
+
expect(link.innerHTML).toEqual('Test <strong>Link</strong>')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('should apply href attribute', () => {
|
|
17
|
+
render(<PktLink href="/test-url">Test Link</PktLink>)
|
|
18
|
+
const link = screen.getByText('Test Link')
|
|
19
|
+
expect(link).toHaveAttribute('href', '/test-url')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should apply base pkt-link class', () => {
|
|
23
|
+
render(<PktLink href="/test">Test Link</PktLink>)
|
|
24
|
+
const link = screen.getByText('Test Link')
|
|
25
|
+
expect(link).toHaveClass('pkt-link')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('should apply custom className in addition to base class', () => {
|
|
29
|
+
render(
|
|
30
|
+
<PktLink href="/test" className="custom-class">
|
|
31
|
+
Test Link
|
|
32
|
+
</PktLink>,
|
|
33
|
+
)
|
|
34
|
+
const link = screen.getByText('Test Link')
|
|
35
|
+
expect(link).toHaveClass('pkt-link')
|
|
36
|
+
expect(link).toHaveClass('custom-class')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it.each`
|
|
40
|
+
description | iconName | iconPosition | expectedClasses | notExpectedClasses
|
|
41
|
+
${'icon-left class when iconName and no iconPosition'} | ${'arrow'} | ${undefined} | ${['pkt-link--icon-left']} | ${['pkt-link--icon-right']}
|
|
42
|
+
${'icon-left class when iconPosition is "left"'} | ${'arrow'} | ${'left'} | ${['pkt-link--icon-left']} | ${['pkt-link--icon-right']}
|
|
43
|
+
${'icon-right class when iconPosition is "right"'} | ${'arrow'} | ${'right'} | ${['pkt-link--icon-right']} | ${['pkt-link--icon-left']}
|
|
44
|
+
${'no icon classes when iconName is not provided'} | ${undefined} | ${undefined} | ${[]} | ${['pkt-link--icon-left', 'pkt-link--icon-right']}
|
|
45
|
+
${'no icon classes when iconName is not provided'} | ${undefined} | ${'left'} | ${[]} | ${['pkt-link--icon-left', 'pkt-link--icon-right']}
|
|
46
|
+
`('should apply $description', ({ iconName, iconPosition, expectedClasses, notExpectedClasses }) => {
|
|
47
|
+
render(
|
|
48
|
+
<PktLink href="/test" iconName={iconName} iconPosition={iconPosition}>
|
|
49
|
+
Test Link
|
|
50
|
+
</PktLink>,
|
|
51
|
+
)
|
|
52
|
+
const link = screen.getByText('Test Link')
|
|
53
|
+
expectedClasses.forEach((className: string) => {
|
|
54
|
+
expect(link).toHaveClass(className)
|
|
55
|
+
})
|
|
56
|
+
notExpectedClasses.forEach((className: string) => {
|
|
57
|
+
expect(link).not.toHaveClass(className)
|
|
58
|
+
})
|
|
59
|
+
const icon = document.querySelector('.pkt-link__icon')
|
|
60
|
+
if (iconName) {
|
|
61
|
+
expect(icon).toBeInTheDocument();
|
|
62
|
+
} else {
|
|
63
|
+
expect(icon).not.toBeInTheDocument();
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it.each`
|
|
68
|
+
description | external | hasExternalClass | relAttribute
|
|
69
|
+
${'external class and rel when external is true'} | ${true} | ${true} | ${'noopener noreferrer'}
|
|
70
|
+
${'no external class or rel when external is false'} | ${false} | ${false} | ${null}
|
|
71
|
+
${'no external class or rel when external is undefined'} | ${undefined} | ${false} | ${null}
|
|
72
|
+
`('should apply $description', ({ external, hasExternalClass, relAttribute }) => {
|
|
73
|
+
render(
|
|
74
|
+
<PktLink href="/test" external={external}>
|
|
75
|
+
Test Link
|
|
76
|
+
</PktLink>,
|
|
77
|
+
)
|
|
78
|
+
const link = screen.getByText('Test Link')
|
|
79
|
+
|
|
80
|
+
if (hasExternalClass) {
|
|
81
|
+
expect(link).toHaveClass('pkt-link--external')
|
|
82
|
+
} else {
|
|
83
|
+
expect(link).not.toHaveClass('pkt-link--external')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (relAttribute) {
|
|
87
|
+
expect(link).toHaveAttribute('rel', relAttribute)
|
|
88
|
+
} else {
|
|
89
|
+
expect(link).not.toHaveAttribute('rel')
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should apply target attribute', () => {
|
|
94
|
+
render(
|
|
95
|
+
<PktLink href="/test" target="_blank">
|
|
96
|
+
Test Link
|
|
97
|
+
</PktLink>,
|
|
98
|
+
)
|
|
99
|
+
const link = screen.getByText('Test Link')
|
|
100
|
+
expect(link).toHaveAttribute('target', '_blank')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should spread additional props to anchor element', () => {
|
|
104
|
+
render(
|
|
105
|
+
<PktLink href="/test" data-testid="custom-link" aria-label="Custom label">
|
|
106
|
+
Test Link
|
|
107
|
+
</PktLink>,
|
|
108
|
+
)
|
|
109
|
+
const link = screen.getByTestId('custom-link')
|
|
110
|
+
expect(link).toHaveAttribute('aria-label', 'Custom label')
|
|
111
|
+
})
|
|
112
|
+
})
|
|
@@ -1,41 +1,48 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ForwardRefExoticComponent,
|
|
8
|
-
LegacyRef,
|
|
9
|
-
LinkHTMLAttributes,
|
|
10
|
-
ReactElement,
|
|
11
|
-
} from 'react'
|
|
12
|
-
import { createComponent } from '@lit/react'
|
|
13
|
-
import { PktLink as PktElLink } from '@oslokommune/punkt-elements'
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import { FC, LinkHTMLAttributes } from 'react'
|
|
5
|
+
|
|
6
|
+
import { PktIcon } from '..'
|
|
14
7
|
|
|
15
8
|
interface IPktLink extends LinkHTMLAttributes<HTMLAnchorElement> {
|
|
16
9
|
href?: string
|
|
17
10
|
iconName?: string | undefined
|
|
11
|
+
className?: string | undefined
|
|
18
12
|
iconPosition?: string | undefined
|
|
19
13
|
external?: boolean
|
|
20
|
-
target?: string |
|
|
21
|
-
ref?: LegacyRef<HTMLAnchorElement>
|
|
14
|
+
target?: string | undefined
|
|
22
15
|
}
|
|
23
16
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
export const PktLink: FC<IPktLink> = ({
|
|
18
|
+
href,
|
|
19
|
+
iconName,
|
|
20
|
+
className,
|
|
21
|
+
iconPosition,
|
|
22
|
+
external,
|
|
23
|
+
target,
|
|
24
|
+
children,
|
|
25
|
+
...props
|
|
26
|
+
}: IPktLink) => {
|
|
27
|
+
const classes = {
|
|
28
|
+
'pkt-link': true,
|
|
29
|
+
'pkt-link--icon-left': (!!iconName && iconPosition === 'left') || !!(iconName && !iconPosition),
|
|
30
|
+
'pkt-link--icon-right': !!iconName && iconPosition === 'right',
|
|
31
|
+
'pkt-link--external': external,
|
|
32
|
+
}
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
return (
|
|
35
|
+
<a
|
|
36
|
+
{...props}
|
|
37
|
+
className={classNames(classes, className)}
|
|
38
|
+
href={href}
|
|
39
|
+
target={target}
|
|
40
|
+
rel={external ? 'noopener noreferrer' : undefined}
|
|
41
|
+
>
|
|
42
|
+
{iconName && <PktIcon name={iconName} className="pkt-link__icon" />}
|
|
43
|
+
{children}
|
|
44
|
+
</a>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
40
47
|
|
|
41
48
|
PktLink.displayName = 'PktLink'
|