@oslokommune/punkt-react 20.2.4 → 20.3.1
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 +58 -0
- package/dist/components/breadcrumbs/Breadcrumbs.js +22 -1
- package/dist/components/icon/Icon.js +34 -34
- package/dist/punkt-react.cjs +1 -1
- package/dist/shared-types/breadcrumbs.d.ts +1 -1
- package/dist/shared-types/icon.d.ts +6 -10
- package/dist/shared-types/icon.js +7 -2
- package/dist/shared-types/index.d.ts +2 -2
- package/dist/shared-types/index.js +16 -16
- package/package.json +3 -3
- package/src/components/breadcrumbs/Breadcrumbs.test.tsx +52 -4
- package/src/components/breadcrumbs/Breadcrumbs.tsx +24 -1
- package/src/components/icon/Icon.test.tsx +29 -0
- package/src/components/icon/Icon.tsx +3 -2
|
@@ -19,7 +19,7 @@ export type IBreadcrumbItem = IBreadcrumb;
|
|
|
19
19
|
/** @deprecated Use `IBreadcrumb` — former React export name (singular type, plural alias). */
|
|
20
20
|
export type IBreadcrumbs = IBreadcrumb;
|
|
21
21
|
/** Shared breadcrumbs props for React, Elements, and typed specs. */
|
|
22
|
-
export type IPktBreadcrumbsBase = IPktStringsProps<'breadcrumbs'> & {
|
|
22
|
+
export type IPktBreadcrumbsBase = IPktStringsProps<'breadcrumbs' | 'backlink'> & {
|
|
23
23
|
breadcrumbs: IBreadcrumb[];
|
|
24
24
|
};
|
|
25
25
|
/** Documented props for typed component specs. */
|
|
@@ -9,9 +9,9 @@ import type { Booleanish } from './booleanish';
|
|
|
9
9
|
export declare const ICON_DEFAULT_PATH = "https://cdn.ikoner.oslo.kommune.no/icons/";
|
|
10
10
|
/** Default CDN path for loading animations. Overridden globally by `window.pktAnimationPath`. */
|
|
11
11
|
export declare const ANIMATION_DEFAULT_PATH = "https://punkt-cdn.oslo.kommune.no/latest/animations/";
|
|
12
|
-
/** Icon
|
|
13
|
-
export declare const
|
|
14
|
-
export type
|
|
12
|
+
/** Icon sizes. Each adds the class `pkt-icon--{size}`; `inherit` makes the icon 1em, the size of the surrounding text. */
|
|
13
|
+
export declare const ICON_SIZES: readonly ['small', 'medium', 'large', 'inherit'];
|
|
14
|
+
export type TPktIconSize = (typeof ICON_SIZES)[number];
|
|
15
15
|
/**
|
|
16
16
|
* Icon props shared by React and Elements.
|
|
17
17
|
*
|
|
@@ -23,14 +23,10 @@ export interface IPktIconBase {
|
|
|
23
23
|
path?: string;
|
|
24
24
|
ariaHidden?: Booleanish;
|
|
25
25
|
ariaLabel?: string;
|
|
26
|
+
size?: TPktIconSize;
|
|
26
27
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
* (`className` in React, `class` in Elements), documented so Preview can offer it.
|
|
30
|
-
*/
|
|
31
|
-
export type IIconSpecProps = Pick<IPktIconBase, 'name' | 'path' | 'ariaHidden' | 'ariaLabel'> & {
|
|
32
|
-
className?: TIconSizeClass;
|
|
33
|
-
};
|
|
28
|
+
/** Documented Icon props. */
|
|
29
|
+
export type IIconSpecProps = Pick<IPktIconBase, 'name' | 'path' | 'ariaHidden' | 'ariaLabel' | 'size'>;
|
|
34
30
|
/**
|
|
35
31
|
* Default values for pkt-icon. Single source of truth for both frameworks.
|
|
36
32
|
* `path` is only the fallback — `window.pktIconPath` wins when set.
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
// ../../shared-types/icon.ts
|
|
2
|
-
var e = "https://cdn.ikoner.oslo.kommune.no/icons/", t = "https://punkt-cdn.oslo.kommune.no/latest/animations/", n =
|
|
2
|
+
var e = "https://cdn.ikoner.oslo.kommune.no/icons/", t = "https://punkt-cdn.oslo.kommune.no/latest/animations/", n = [
|
|
3
|
+
"small",
|
|
4
|
+
"medium",
|
|
5
|
+
"large",
|
|
6
|
+
"inherit"
|
|
7
|
+
], r = {
|
|
3
8
|
name: "",
|
|
4
9
|
path: e
|
|
5
10
|
};
|
|
6
|
-
export { t as ANIMATION_DEFAULT_PATH,
|
|
11
|
+
export { t as ANIMATION_DEFAULT_PATH, r as ICON_DEFAULTS, e as ICON_DEFAULT_PATH, n as ICON_SIZES };
|
|
@@ -21,8 +21,8 @@ export { OPTION_GROUP_DEFAULTS } from './option-group';
|
|
|
21
21
|
export type { IPktOptionGroupBase, IPktRadioGroupBase, IPktCheckboxGroupBase, IRadioGroupSpecProps, ICheckboxGroupSpecProps, } from './option-group';
|
|
22
22
|
export { CONSENT_TRIGGER_TYPES, CONSENT_TRIGGER_TYPE_OPTIONS, CONSENT_DEFAULTS } from './consent';
|
|
23
23
|
export type { TPktConsentTriggerType, IConsentItem, IConsentValue, ICookieConsentEvent, TConsentDetailsMap, TCookieEventHandler, ICookieEvents, ICookieBannerApi, IPktConsentBase, IConsentSpecProps, } from './consent';
|
|
24
|
-
export { ANIMATION_DEFAULT_PATH, ICON_DEFAULT_PATH,
|
|
25
|
-
export type {
|
|
24
|
+
export { ANIMATION_DEFAULT_PATH, ICON_DEFAULT_PATH, ICON_SIZES, ICON_DEFAULTS } from './icon';
|
|
25
|
+
export type { TPktIconSize, IPktIconBase, IIconSpecProps } from './icon';
|
|
26
26
|
export { LOADER_VARIANTS, LOADER_DEFAULTS } from './loader';
|
|
27
27
|
export type { TPktLoaderVariant, IPktLoaderBase, ILoaderSpecProps } from './loader';
|
|
28
28
|
export { LAYOUT_DIRECTIONS } from './layout';
|
|
@@ -7,21 +7,21 @@ import { CHECKBOX_DEFAULTS as s } from "./checkbox.js";
|
|
|
7
7
|
import { RADIOBUTTON_DEFAULTS as c } from "./radiobutton.js";
|
|
8
8
|
import { OPTION_GROUP_DEFAULTS as l } from "./option-group.js";
|
|
9
9
|
import { CONSENT_DEFAULTS as u } from "./consent.js";
|
|
10
|
-
import { ANIMATION_DEFAULT_PATH as d, ICON_DEFAULTS as f } from "./icon.js";
|
|
11
|
-
import { LOADER_DEFAULTS as
|
|
12
|
-
import { ACCORDION_LIGHT_ONLY_SKINS as
|
|
13
|
-
import { BUTTON_DEFAULTS as
|
|
14
|
-
import { LINKCARD_LIGHT_ONLY_SKINS as
|
|
15
|
-
import { INPUT_WRAPPER_DEFAULTS as
|
|
16
|
-
import { TEXTAREA_DEFAULTS as
|
|
17
|
-
import { TEXTINPUT_DEFAULTS as
|
|
18
|
-
import { TAG_DEFAULTS as
|
|
19
|
-
import { TABS_DEFAULTS as
|
|
20
|
-
import { MESSAGEBOX_DEFAULTS as
|
|
10
|
+
import { ANIMATION_DEFAULT_PATH as d, ICON_DEFAULTS as f, ICON_SIZES as p } from "./icon.js";
|
|
11
|
+
import { LOADER_DEFAULTS as m } from "./loader.js";
|
|
12
|
+
import { ACCORDION_LIGHT_ONLY_SKINS as h } from "./accordion.js";
|
|
13
|
+
import { BUTTON_DEFAULTS as g } from "./button.js";
|
|
14
|
+
import { LINKCARD_LIGHT_ONLY_SKINS as _ } from "./linkcard.js";
|
|
15
|
+
import { INPUT_WRAPPER_DEFAULTS as v } from "./input-wrapper.js";
|
|
16
|
+
import { TEXTAREA_DEFAULTS as y } from "./textarea.js";
|
|
17
|
+
import { TEXTINPUT_DEFAULTS as b } from "./textinput.js";
|
|
18
|
+
import { TAG_DEFAULTS as x } from "./tag.js";
|
|
19
|
+
import { TABS_DEFAULTS as S, TAB_ITEM_DEFAULTS as C } from "./tabs.js";
|
|
20
|
+
import { MESSAGEBOX_DEFAULTS as w, MESSAGEBOX_LIGHT_ONLY_SKINS as T } from "./messagebox.js";
|
|
21
21
|
import "./calendar.js";
|
|
22
|
-
import { DATEPICKER_DEFAULTS as
|
|
23
|
-
import { PROGRESSBAR_DEFAULTS as
|
|
22
|
+
import { DATEPICKER_DEFAULTS as E } from "./datepicker.js";
|
|
23
|
+
import { PROGRESSBAR_DEFAULTS as D } from "./progressbar.js";
|
|
24
24
|
import "./combobox.js";
|
|
25
|
-
import { SELECT_DEFAULTS as
|
|
26
|
-
import { TABLE_DEFAULTS as
|
|
27
|
-
export {
|
|
25
|
+
import { SELECT_DEFAULTS as O } from "./select.js";
|
|
26
|
+
import { TABLE_DEFAULTS as k } from "./table.js";
|
|
27
|
+
export { h as ACCORDION_LIGHT_ONLY_SKINS, d as ANIMATION_DEFAULT_PATH, g as BUTTON_DEFAULTS, a as CARD_DEFAULTS, o as CARD_LIGHT_ONLY_SKINS, s as CHECKBOX_DEFAULTS, u as CONSENT_DEFAULTS, E as DATEPICKER_DEFAULTS, r as DEFAULT_FOOTER_PERSONVERN_URL, i as DEFAULT_FOOTER_TILGJENGELIGHET_URL, e as DEFAULT_HEADER_FOOTER_URL, t as HEADER_GLOBAL_DEFAULTS, n as HEADER_SERVICE_DEFAULTS, f as ICON_DEFAULTS, p as ICON_SIZES, v as INPUT_WRAPPER_DEFAULTS, _ as LINKCARD_LIGHT_ONLY_SKINS, m as LOADER_DEFAULTS, w as MESSAGEBOX_DEFAULTS, T as MESSAGEBOX_LIGHT_ONLY_SKINS, l as OPTION_GROUP_DEFAULTS, D as PROGRESSBAR_DEFAULTS, c as RADIOBUTTON_DEFAULTS, O as SELECT_DEFAULTS, k as TABLE_DEFAULTS, S as TABS_DEFAULTS, C as TAB_ITEM_DEFAULTS, x as TAG_DEFAULTS, y as TEXTAREA_DEFAULTS, b as TEXTINPUT_DEFAULTS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.3.1",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@eslint/eslintrc": "^3.3.5",
|
|
43
43
|
"@eslint/js": "^10.0.1",
|
|
44
44
|
"@oslokommune/punkt-assets": "^20.0.5",
|
|
45
|
-
"@oslokommune/punkt-css": "^20.
|
|
45
|
+
"@oslokommune/punkt-css": "^20.3.1",
|
|
46
46
|
"@testing-library/jest-dom": "^7.0.1",
|
|
47
47
|
"@testing-library/react": "^16.3.3",
|
|
48
48
|
"@testing-library/user-event": "^14.6.8",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "b45927a24739ccb13c8285a863fceed389d070c0"
|
|
106
106
|
}
|
|
@@ -56,11 +56,59 @@ describe('PktBreadcrumbs Component', () => {
|
|
|
56
56
|
expect(getAllByText('Item')).toBeTruthy()
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
it('renders a single crumb
|
|
60
|
-
const { container,
|
|
59
|
+
it('renders a single crumb as a back link', () => {
|
|
60
|
+
const { container, getByRole } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs.slice(0, 1)} className="custom" />)
|
|
61
61
|
|
|
62
|
-
expect(
|
|
63
|
-
expect(container.querySelector('
|
|
62
|
+
expect(container.querySelector('.pkt-breadcrumbs__list')).not.toBeInTheDocument()
|
|
63
|
+
expect(container.querySelector('[aria-current]')).not.toBeInTheDocument()
|
|
64
|
+
|
|
65
|
+
const nav = getByRole('navigation')
|
|
66
|
+
expect(nav).toHaveClass('pkt-breadcrumbs', 'pkt-back-link', 'custom')
|
|
67
|
+
expect(nav).toHaveAttribute('aria-label', 'Gå tilbake til forrige side')
|
|
68
|
+
|
|
69
|
+
const link = getByRole('link')
|
|
70
|
+
expect(link).toHaveClass('pkt-link', 'pkt-link--icon-left')
|
|
71
|
+
expect(link).toHaveAttribute('href', '/')
|
|
72
|
+
expect(link).toHaveTextContent('Home')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('uses backlink strings override for a single crumb', () => {
|
|
76
|
+
const { getByRole } = render(
|
|
77
|
+
<PktBreadcrumbs breadcrumbs={breadcrumbs.slice(0, 1)} strings={{ backlink: { label: 'Back to overview' } }} />,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
expect(getByRole('navigation')).toHaveAttribute('aria-label', 'Back to overview')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('passes a single crumb through renderLink', () => {
|
|
84
|
+
const { getByRole } = render(
|
|
85
|
+
<PktBreadcrumbs
|
|
86
|
+
breadcrumbs={breadcrumbs.slice(0, 1)}
|
|
87
|
+
renderLink={({ href, className, children }) => (
|
|
88
|
+
<a href={href} className={className} data-custom="true">
|
|
89
|
+
{children}
|
|
90
|
+
</a>
|
|
91
|
+
)}
|
|
92
|
+
/>,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
expect(getByRole('link')).toHaveAttribute('data-custom', 'true')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('renders a single crumb with react-router navigation', () => {
|
|
99
|
+
const { getByRole } = render(
|
|
100
|
+
<TestRouter>
|
|
101
|
+
<PktBreadcrumbs breadcrumbs={breadcrumbs.slice(0, 1)} navigationType="router" />
|
|
102
|
+
</TestRouter>,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
expect(getByRole('link')).toHaveAttribute('href', '/')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('renders a single crumb with no wcag errors with axe', async () => {
|
|
109
|
+
const { container } = render(<PktBreadcrumbs breadcrumbs={breadcrumbs.slice(0, 1)} />)
|
|
110
|
+
|
|
111
|
+
expect(await axe(container)).toHaveNoViolations()
|
|
64
112
|
})
|
|
65
113
|
|
|
66
114
|
it('renders an empty trail without a back link', () => {
|
|
@@ -29,7 +29,7 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
29
29
|
const backLink = slicedBreadcrumbs[slicedBreadcrumbs.length - 2]
|
|
30
30
|
|
|
31
31
|
// Define the classes
|
|
32
|
-
const s = usePktStrings(['breadcrumbs'], strings)
|
|
32
|
+
const s = usePktStrings(['breadcrumbs', 'backlink'], strings)
|
|
33
33
|
const classes = [className, 'pkt-breadcrumbs'].filter(Boolean).join(' ')
|
|
34
34
|
|
|
35
35
|
// Create a default renderLink implementation based on navigationType
|
|
@@ -47,6 +47,29 @@ export const PktBreadcrumbs = forwardRef(
|
|
|
47
47
|
</a>
|
|
48
48
|
))
|
|
49
49
|
|
|
50
|
+
if (slicedBreadcrumbs.length === 1) {
|
|
51
|
+
const item = slicedBreadcrumbs[0]
|
|
52
|
+
return (
|
|
53
|
+
<nav ref={ref} aria-label={s.backlink.label} className={`${classes} pkt-back-link`}>
|
|
54
|
+
{linkRenderer({
|
|
55
|
+
href: item.href,
|
|
56
|
+
className: 'pkt-link pkt-link--icon-left',
|
|
57
|
+
children: (
|
|
58
|
+
<>
|
|
59
|
+
<PktIcon
|
|
60
|
+
className="pkt-back-link__icon pkt-icon pkt-link__icon"
|
|
61
|
+
name="chevron-thin-left"
|
|
62
|
+
aria-hidden="true"
|
|
63
|
+
/>
|
|
64
|
+
<span className="pkt-back-link__text">{item.text}</span>
|
|
65
|
+
</>
|
|
66
|
+
),
|
|
67
|
+
props,
|
|
68
|
+
})}
|
|
69
|
+
</nav>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
50
73
|
// Mobile and desktop have different markup
|
|
51
74
|
return (
|
|
52
75
|
<nav ref={ref} aria-label={s.breadcrumbs.ariaLabel} className={classes}>
|
|
@@ -111,6 +111,35 @@ describe('PktIcon', () => {
|
|
|
111
111
|
})
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
+
describe('size', () => {
|
|
115
|
+
test.each(['small', 'medium', 'large', 'inherit'] as const)('size="%s" adds pkt-icon--%s', async (size) => {
|
|
116
|
+
const { container } = await render(<PktIcon name="arrow" size={size} />)
|
|
117
|
+
const icon = container.querySelector('.pkt-icon')
|
|
118
|
+
|
|
119
|
+
expect(icon).toHaveClass(`pkt-icon--${size}`)
|
|
120
|
+
expect(icon).not.toHaveAttribute('size')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('keeps className next to the size class', async () => {
|
|
124
|
+
const { container } = await render(<PktIcon name="arrow" size="inherit" className="pkt-txt-24" />)
|
|
125
|
+
|
|
126
|
+
expect(container.querySelector('.pkt-icon')).toHaveClass('pkt-icon', 'pkt-icon--inherit', 'pkt-txt-24')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('adds no size class without size or with an unknown size', async () => {
|
|
130
|
+
const { container } = await render(
|
|
131
|
+
<>
|
|
132
|
+
<PktIcon name="arrow" />
|
|
133
|
+
<PktIcon name="arrow" size={'huge' as never} />
|
|
134
|
+
</>,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
for (const icon of container.querySelectorAll('.pkt-icon')) {
|
|
138
|
+
expect(icon.className).toBe('pkt-icon')
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
114
143
|
describe('Restricted storage', () => {
|
|
115
144
|
test('loads when reading sessionStorage throws', async () => {
|
|
116
145
|
const original = Object.getOwnPropertyDescriptor(globalThis, 'sessionStorage')
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { forwardRef, HTMLAttributes, MutableRefObject, useEffect, useLayoutEffect, useRef } from 'react'
|
|
5
5
|
import type { PktIconName } from '@oslokommune/punkt-assets/dist/icons/icon'
|
|
6
|
-
import { ICON_DEFAULTS, type Booleanish, type IPktIconBase } from 'shared-types'
|
|
6
|
+
import { ICON_DEFAULTS, ICON_SIZES, type Booleanish, type IPktIconBase } from 'shared-types'
|
|
7
7
|
|
|
8
8
|
declare global {
|
|
9
9
|
interface Window {
|
|
@@ -97,6 +97,7 @@ export const PktIcon = forwardRef<HTMLSpanElement, IPktIcon>(function PktIcon(
|
|
|
97
97
|
{
|
|
98
98
|
name = ICON_DEFAULTS.name,
|
|
99
99
|
path,
|
|
100
|
+
size,
|
|
100
101
|
className,
|
|
101
102
|
ariaHidden,
|
|
102
103
|
ariaLabel,
|
|
@@ -168,7 +169,7 @@ export const PktIcon = forwardRef<HTMLSpanElement, IPktIcon>(function PktIcon(
|
|
|
168
169
|
<span
|
|
169
170
|
{...rest}
|
|
170
171
|
ref={setRef}
|
|
171
|
-
className={classNames('pkt-icon', className)}
|
|
172
|
+
className={classNames('pkt-icon', size && ICON_SIZES.includes(size) && `pkt-icon--${size}`, className)}
|
|
172
173
|
{...(name ? { name } : {})}
|
|
173
174
|
data-path={resolvedPath}
|
|
174
175
|
/>
|