@oslokommune/punkt-react 19.4.0 → 19.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 +5 -0
- package/dist/components/icon/Icon.d.ts +4 -6
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1839 -1836
- package/dist/shared-types/icon.d.ts +39 -0
- package/dist/shared-types/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/components/icon/Icon.tsx +7 -11
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* icon.ts
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for pkt-icon.
|
|
5
|
+
* Used by React, Elements, and typed component specs.
|
|
6
|
+
*/
|
|
7
|
+
import type { Booleanish } from './booleanish';
|
|
8
|
+
/** Default CDN path for icons. Overridden globally by `window.pktIconPath`. */
|
|
9
|
+
export declare const ICON_DEFAULT_PATH = "https://punkt-cdn.oslo.kommune.no/latest/icons/";
|
|
10
|
+
/** Icon size modifier classes — shared runtime source for types, specs, and Preview. */
|
|
11
|
+
export declare const ICON_SIZE_CLASSES: readonly ['pkt-icon--small', 'pkt-icon--medium', 'pkt-icon--large'];
|
|
12
|
+
export type TIconSizeClass = (typeof ICON_SIZE_CLASSES)[number];
|
|
13
|
+
/**
|
|
14
|
+
* Icon props shared by React and Elements.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Elements narrows `name` to `PktIconName` and takes `aria-hidden`/`aria-label`
|
|
17
|
+
* as string attributes.
|
|
18
|
+
*/
|
|
19
|
+
export interface IPktIconBase {
|
|
20
|
+
name?: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
ariaHidden?: Booleanish;
|
|
23
|
+
ariaLabel?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Documented Icon props. `className` is not a component prop but the size class
|
|
27
|
+
* (`className` in React, `class` in Elements), documented so Preview can offer it.
|
|
28
|
+
*/
|
|
29
|
+
export type IIconSpecProps = Pick<IPktIconBase, 'name' | 'path' | 'ariaHidden' | 'ariaLabel'> & {
|
|
30
|
+
className?: TIconSizeClass;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Default values for pkt-icon. Single source of truth for both frameworks.
|
|
34
|
+
* `path` is only the fallback — `window.pktIconPath` wins when set.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ICON_DEFAULTS: {
|
|
37
|
+
readonly name: '';
|
|
38
|
+
readonly path: "https://punkt-cdn.oslo.kommune.no/latest/icons/";
|
|
39
|
+
};
|
|
@@ -15,6 +15,8 @@ export { CHECKBOX_LABEL_POSITIONS, CHECKBOX_DEFAULTS } from './checkbox';
|
|
|
15
15
|
export type { TCheckboxLabelPosition, IPktCheckboxBase, ICheckboxSpecProps } from './checkbox';
|
|
16
16
|
export { CONSENT_TRIGGER_TYPES, CONSENT_TRIGGER_TYPE_OPTIONS, CONSENT_DEFAULTS } from './consent';
|
|
17
17
|
export type { TPktConsentTriggerType, IConsentItem, IConsentValue, ICookieConsentEvent, TConsentDetailsMap, TCookieEventHandler, ICookieEvents, ICookieBannerApi, IPktConsentBase, IConsentSpecProps, } from './consent';
|
|
18
|
+
export { ICON_DEFAULT_PATH, ICON_SIZE_CLASSES, ICON_DEFAULTS } from './icon';
|
|
19
|
+
export type { TIconSizeClass, IPktIconBase, IIconSpecProps } from './icon';
|
|
18
20
|
export { LAYOUT_DIRECTIONS } from './layout';
|
|
19
21
|
export type { TLayout, TVerticalPosition, THorizontalPosition, TPosition, TPositionWithCenter, } from './layout';
|
|
20
22
|
export type { THTMLButtonType, TSelectionMode } from './form';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.5.0",
|
|
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",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
102
102
|
},
|
|
103
103
|
"license": "MIT",
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "b3cd6677098953e95888488fa523fcfed4dc714b"
|
|
105
105
|
}
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { forwardRef, HTMLAttributes, MutableRefObject, useEffect, useLayoutEffect, useRef } from 'react'
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
const defaultPath = 'https://punkt-cdn.oslo.kommune.no/latest/icons/'
|
|
5
|
+
import type { PktIconName } from '@oslokommune/punkt-assets/dist/icons/icon'
|
|
6
|
+
import { ICON_DEFAULTS, type Booleanish, type IPktIconBase } from 'shared-types'
|
|
8
7
|
|
|
9
8
|
if (typeof window !== 'undefined') {
|
|
10
9
|
window.pktFetch = window.pktFetch === undefined ? (fetch as unknown as typeof window.pktFetch) : window.pktFetch
|
|
11
|
-
window.pktIconPath = window.pktIconPath ||
|
|
10
|
+
window.pktIconPath = window.pktIconPath || ICON_DEFAULTS.path
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
const errorSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"></svg>'
|
|
@@ -72,11 +71,8 @@ const downloadIconOrGetFromCache = async (name: string, path: string | undefined
|
|
|
72
71
|
return errorSvg
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
interface IPktIcon extends HTMLAttributes<HTMLElement> {
|
|
76
|
-
name?:
|
|
77
|
-
path?: string
|
|
78
|
-
ariaHidden?: Booleanish
|
|
79
|
-
ariaLabel?: string
|
|
74
|
+
interface IPktIcon extends Omit<IPktIconBase, 'name'>, HTMLAttributes<HTMLElement> {
|
|
75
|
+
name?: PktIconName
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
const toBoolean = (v: Booleanish | undefined): boolean | undefined => {
|
|
@@ -86,7 +82,7 @@ const toBoolean = (v: Booleanish | undefined): boolean | undefined => {
|
|
|
86
82
|
|
|
87
83
|
export const PktIcon = forwardRef<HTMLSpanElement, IPktIcon>(function PktIcon(
|
|
88
84
|
{
|
|
89
|
-
name =
|
|
85
|
+
name = ICON_DEFAULTS.name,
|
|
90
86
|
path,
|
|
91
87
|
className,
|
|
92
88
|
ariaHidden,
|
|
@@ -97,7 +93,7 @@ export const PktIcon = forwardRef<HTMLSpanElement, IPktIcon>(function PktIcon(
|
|
|
97
93
|
},
|
|
98
94
|
forwardedRef,
|
|
99
95
|
) {
|
|
100
|
-
const resolvedPath = path ?? (typeof window !== 'undefined' ? window.pktIconPath :
|
|
96
|
+
const resolvedPath = path ?? (typeof window !== 'undefined' ? window.pktIconPath : ICON_DEFAULTS.path)
|
|
101
97
|
const elementRef = useRef<HTMLSpanElement | null>(null)
|
|
102
98
|
|
|
103
99
|
const explicitAriaHidden = toBoolean(ariaHidden) ?? toBoolean(ariaHiddenAttr)
|