@oslokommune/punkt-react 20.0.1 → 20.0.3

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.
@@ -46,8 +46,9 @@ export type { IPktTextareaBase, ITextareaSpecProps } from './textarea';
46
46
  export { TEXTINPUT_DEFAULTS, TEXTINPUT_TYPES } from './textinput';
47
47
  export type { TPktTextinputType, IPktTextinputBase, ITextinputSpecProps } from './textinput';
48
48
  export type { TPktCounterPosition, IPktInputWrapperBase, IInputWrapperSpecProps, } from './input-wrapper';
49
- export { TAG_SKINS, TAG_STATES } from './skin';
50
- export type { TMessageboxSkin, TTagSkin, TTagState } from './skin';
49
+ export type { TMessageboxSkin } from './skin';
50
+ export { TAG_SKINS, TAG_STATES, TAG_TEXT_STYLES, TAG_DEFAULTS } from './tag';
51
+ export type { TTagSkin, TTagState, TTagTextStyle, IPktTagBase, ITagSpecProps } from './tag';
51
52
  export { MESSAGEBOX_SKINS, MESSAGEBOX_LIGHT_ONLY_SKINS, MESSAGEBOX_DEFAULTS } from './messagebox';
52
53
  export type { IPktMessageboxBase, IMessageboxSpecProps } from './messagebox';
53
54
  export { CALENDAR_DEFAULTS } from './calendar';
@@ -13,10 +13,11 @@ import { LINKCARD_LIGHT_ONLY_SKINS as m } from "./linkcard.js";
13
13
  import { INPUT_WRAPPER_DEFAULTS as h } from "./input-wrapper.js";
14
14
  import { TEXTAREA_DEFAULTS as g } from "./textarea.js";
15
15
  import { TEXTINPUT_DEFAULTS as _ } from "./textinput.js";
16
- import { MESSAGEBOX_DEFAULTS as v, MESSAGEBOX_LIGHT_ONLY_SKINS as y } from "./messagebox.js";
16
+ import { TAG_DEFAULTS as v } from "./tag.js";
17
+ import { MESSAGEBOX_DEFAULTS as y, MESSAGEBOX_LIGHT_ONLY_SKINS as b } from "./messagebox.js";
17
18
  import "./calendar.js";
18
- import { PROGRESSBAR_DEFAULTS as b } from "./progressbar.js";
19
+ import { PROGRESSBAR_DEFAULTS as x } from "./progressbar.js";
19
20
  import "./combobox.js";
20
- import { SELECT_DEFAULTS as x } from "./select.js";
21
- import { TABLE_DEFAULTS as S } from "./table.js";
22
- export { p as ACCORDION_LIGHT_ONLY_SKINS, u as ANIMATION_DEFAULT_PATH, i as CARD_DEFAULTS, a as CARD_LIGHT_ONLY_SKINS, o as CHECKBOX_DEFAULTS, l as CONSENT_DEFAULTS, n as DEFAULT_FOOTER_PERSONVERN_URL, r as DEFAULT_FOOTER_TILGJENGELIGHET_URL, e as DEFAULT_HEADER_FOOTER_URL, t as DEFAULT_HEADER_LOGO_LINK, d as ICON_DEFAULTS, h as INPUT_WRAPPER_DEFAULTS, m as LINKCARD_LIGHT_ONLY_SKINS, f as LOADER_DEFAULTS, v as MESSAGEBOX_DEFAULTS, y as MESSAGEBOX_LIGHT_ONLY_SKINS, c as OPTION_GROUP_DEFAULTS, b as PROGRESSBAR_DEFAULTS, s as RADIOBUTTON_DEFAULTS, x as SELECT_DEFAULTS, S as TABLE_DEFAULTS, g as TEXTAREA_DEFAULTS, _ as TEXTINPUT_DEFAULTS };
21
+ import { SELECT_DEFAULTS as S } from "./select.js";
22
+ import { TABLE_DEFAULTS as C } from "./table.js";
23
+ export { p as ACCORDION_LIGHT_ONLY_SKINS, u as ANIMATION_DEFAULT_PATH, i as CARD_DEFAULTS, a as CARD_LIGHT_ONLY_SKINS, o as CHECKBOX_DEFAULTS, l as CONSENT_DEFAULTS, n as DEFAULT_FOOTER_PERSONVERN_URL, r as DEFAULT_FOOTER_TILGJENGELIGHET_URL, e as DEFAULT_HEADER_FOOTER_URL, t as DEFAULT_HEADER_LOGO_LINK, d as ICON_DEFAULTS, h as INPUT_WRAPPER_DEFAULTS, m as LINKCARD_LIGHT_ONLY_SKINS, f as LOADER_DEFAULTS, y as MESSAGEBOX_DEFAULTS, b as MESSAGEBOX_LIGHT_ONLY_SKINS, c as OPTION_GROUP_DEFAULTS, x as PROGRESSBAR_DEFAULTS, s as RADIOBUTTON_DEFAULTS, S as SELECT_DEFAULTS, C as TABLE_DEFAULTS, v as TAG_DEFAULTS, g as TEXTAREA_DEFAULTS, _ as TEXTINPUT_DEFAULTS };
@@ -9,13 +9,4 @@ export { ALERT_SKINS, type TAlertSkin } from './alert';
9
9
  export { ACCORDION_SKINS, type TAccordionSkin } from './accordion';
10
10
  export { CARD_SKINS, type TCardSkin } from './card';
11
11
  export { MESSAGEBOX_SKINS, type TMessageboxSkin } from './messagebox';
12
- /**
13
- * Tag component skin variants — shared runtime source for types, specs and demo pages.
14
- */
15
- export declare const TAG_SKINS: readonly ['gray', 'gray-light', 'blue-dark', 'blue', 'blue-light', 'blue-pale', 'green', 'green-light', 'red', 'red-light', 'yellow', 'yellow-light', 'beige', 'beige-light'];
16
- export type TTagSkin = (typeof TAG_SKINS)[number];
17
- /**
18
- * Forces a tag into a visual state without the user interacting with it.
19
- */
20
- export declare const TAG_STATES: readonly ['hover', 'focus', 'active'];
21
- export type TTagState = (typeof TAG_STATES)[number];
12
+ export { TAG_SKINS, TAG_STATES, type TTagSkin, type TTagState } from './tag';
@@ -0,0 +1,46 @@
1
+ /**
2
+ * tag.ts
3
+ *
4
+ * Shared types and defaults for Tag, used by both React and Elements.
5
+ */
6
+ import type { IPktStringsProps } from '../shared-strings';
7
+ import type { THTMLButtonType } from './form';
8
+ import type { TPktSizeBase } from './size';
9
+ /** Tag skins: shared runtime source for types, specs and demo pages. */
10
+ export declare const TAG_SKINS: readonly ['gray', 'gray-light', 'blue-dark', 'blue', 'blue-light', 'blue-pale', 'green', 'green-light', 'red', 'red-light', 'yellow', 'yellow-light', 'beige', 'beige-light'];
11
+ export type TTagSkin = (typeof TAG_SKINS)[number];
12
+ /** Forces a tag into a visual state without the user interacting with it. */
13
+ export declare const TAG_STATES: readonly ['hover', 'focus', 'active'];
14
+ export type TTagState = (typeof TAG_STATES)[number];
15
+ export declare const TAG_TEXT_STYLES: readonly ['normal-text', 'thin-text'];
16
+ export type TTagTextStyle = (typeof TAG_TEXT_STYLES)[number];
17
+ /**
18
+ * Framework-agnostic props for Tag.
19
+ *
20
+ * @remarks React adds `onClose` and `children`, and only accepts `type` when
21
+ * `closeTag` is `true`. Elements narrows `iconName` to `PktIconName` and
22
+ * dispatches a `close` event instead of `onClose`.
23
+ */
24
+ export interface IPktTagBase extends IPktStringsProps<'tag'> {
25
+ closeTag?: boolean;
26
+ size?: TPktSizeBase;
27
+ skin?: TTagSkin;
28
+ state?: TTagState | null;
29
+ textStyle?: TTagTextStyle | null;
30
+ iconName?: string;
31
+ type?: THTMLButtonType;
32
+ ariaLabel?: string | null;
33
+ }
34
+ /**
35
+ * Props documented in the component spec (docs and Preview).
36
+ * The spec file is type-checked against this.
37
+ */
38
+ export type ITagSpecProps = Pick<IPktTagBase, 'size' | 'iconName' | 'skin' | 'closeTag' | 'state' | 'textStyle' | 'type' | 'ariaLabel'>;
39
+ /** Default values, shared by React and Elements. */
40
+ export declare const TAG_DEFAULTS: {
41
+ readonly closeTag: false;
42
+ readonly size: 'medium';
43
+ readonly skin: 'gray';
44
+ readonly textStyle: 'normal-text';
45
+ readonly type: 'button';
46
+ };
@@ -0,0 +1,10 @@
1
+ //#region ../../shared-types/tag.ts
2
+ var e = {
3
+ closeTag: !1,
4
+ size: "medium",
5
+ skin: "gray",
6
+ textStyle: "normal-text",
7
+ type: "button"
8
+ };
9
+ //#endregion
10
+ export { e as TAG_DEFAULTS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "20.0.1",
3
+ "version": "20.0.3",
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",
@@ -43,7 +43,7 @@
43
43
  "@eslint/eslintrc": "^3.3.5",
44
44
  "@eslint/js": "^10.0.1",
45
45
  "@oslokommune/punkt-assets": "^20.0.0",
46
- "@oslokommune/punkt-css": "^20.0.1",
46
+ "@oslokommune/punkt-css": "^20.0.3",
47
47
  "@testing-library/jest-dom": "^7.0.1",
48
48
  "@testing-library/react": "^16.3.2",
49
49
  "@testing-library/user-event": "^14.6.1",
@@ -103,5 +103,5 @@
103
103
  "url": "https://github.com/oslokommune/punkt/issues"
104
104
  },
105
105
  "license": "MIT",
106
- "gitHead": "6a72933651c086b0ce41e31a78ce63c2d4bb8c47"
106
+ "gitHead": "719cdc9b7c8f19b488226316108b4d0fd5555c24"
107
107
  }
@@ -9,10 +9,7 @@ import { PktTag } from './Tag'
9
9
 
10
10
  expect.extend(toHaveNoViolations)
11
11
 
12
- const render = async (
13
- ui: ReactNode,
14
- options?: Omit<RenderOptions, 'queries'> | undefined,
15
- ): Promise<RenderResult> => {
12
+ const render = async (ui: ReactNode, options?: Omit<RenderOptions, 'queries'> | undefined): Promise<RenderResult> => {
16
13
  const renderResult = originalRender(ui, options)
17
14
  return Promise.resolve(renderResult)
18
15
  }
@@ -50,6 +47,13 @@ describe('PktTag', () => {
50
47
  expect(spanElement).toHaveClass('pkt-tag--gray')
51
48
  })
52
49
 
50
+ it('defaults to normal text', async () => {
51
+ const { container } = await render(<PktTag>Tag</PktTag>)
52
+ const spanElement = container.querySelector('span.pkt-tag')
53
+
54
+ expect(spanElement).toHaveClass('pkt-tag--normal-text')
55
+ })
56
+
53
57
  it('renders a forced state class when state is provided', async () => {
54
58
  const { container } = await render(<PktTag state="hover">Tag</PktTag>)
55
59
  const spanElement = container.querySelector('span.pkt-tag')
@@ -14,27 +14,19 @@ import {
14
14
  useState,
15
15
  } from 'react'
16
16
 
17
- import type { TPktSizeBase, TTagSkin, TTagState } from 'shared-types'
17
+ import { TAG_DEFAULTS, type IPktTagBase } from 'shared-types'
18
18
 
19
19
  import { PktIcon } from '../icon/Icon'
20
20
  import { usePktStrings } from '../../hooks/usePktStrings'
21
- import { formatString, type IPktStringsProps } from 'shared-strings'
22
-
23
- interface BasePktTagProps extends IPktStringsProps<'tag'> {
24
- skin?: TTagSkin
25
- state?: TTagState
26
- textStyle?: 'normal-text' | 'thin-text'
27
- size?: TPktSizeBase
28
- closeTag?: boolean
29
- iconName?: string
30
- ariaLabel?: string
21
+ import { formatString } from 'shared-strings'
22
+
23
+ interface BasePktTagProps extends IPktTagBase {
31
24
  onClose?: () => void
32
25
  children?: ReactNode
33
26
  }
34
27
 
35
28
  interface ButtonPktTagProps extends BasePktTagProps, HTMLAttributes<HTMLButtonElement> {
36
29
  closeTag: true
37
- type?: 'button' | 'submit' | 'reset'
38
30
  }
39
31
 
40
32
  interface SpanPktTagProps extends BasePktTagProps, HTMLAttributes<HTMLSpanElement> {
@@ -49,16 +41,16 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
49
41
  (
50
42
  {
51
43
  children,
52
- skin = 'gray',
44
+ skin = TAG_DEFAULTS.skin,
53
45
  state,
54
- textStyle,
55
- size = 'medium',
56
- closeTag,
46
+ textStyle = TAG_DEFAULTS.textStyle,
47
+ size = TAG_DEFAULTS.size,
48
+ closeTag = TAG_DEFAULTS.closeTag,
57
49
  className,
58
50
  iconName,
59
51
  ariaLabel,
60
52
  onClose,
61
- type = 'button',
53
+ type = TAG_DEFAULTS.type,
62
54
  'aria-description': ariaDescriptionPropValue,
63
55
  strings,
64
56
  ...props
@@ -115,7 +107,7 @@ export const PktTag = forwardRef<HTMLSpanElement | HTMLButtonElement, ButtonPktT
115
107
  className={classNames(btnClasses, className)}
116
108
  type={type}
117
109
  onClick={close}
118
- aria-label={ariaLabel}
110
+ aria-label={ariaLabel ?? undefined}
119
111
  aria-description={ariaDescription}
120
112
  ref={forwardedRef as ForwardedRef<HTMLButtonElement>}
121
113
  >