@norges-domstoler/dds-components 0.0.0-dev-20260119083800 → 0.0.0-dev-20260120080949

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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { ComponentPropsWithRef, HTMLAttributes, Ref, CSSProperties, ElementType, ComponentPropsWithoutRef, ReactNode, SVGAttributes, JSX, ButtonHTMLAttributes, MouseEventHandler, DependencyList, RefCallback, Dispatch, SetStateAction, ChangeEvent, RefObject, KeyboardEvent as KeyboardEvent$1, ComponentProps, AnchorHTMLAttributes, LabelHTMLAttributes, AriaRole, InputHTMLAttributes, FocusEvent, ForwardedRef, ForwardRefExoticComponent, MouseEvent as MouseEvent$1, ReactElement } from 'react';
3
+ import { ComponentPropsWithRef, ElementType, CSSProperties, Ref, ComponentPropsWithoutRef, HTMLAttributes, ReactNode, SVGAttributes, JSX, ButtonHTMLAttributes, MouseEventHandler, DependencyList, RefCallback, Dispatch, SetStateAction, ChangeEvent, RefObject, KeyboardEvent as KeyboardEvent$1, ComponentProps, AnchorHTMLAttributes, LabelHTMLAttributes, AriaRole, InputHTMLAttributes, FocusEvent, ForwardedRef, ForwardRefExoticComponent, MouseEvent as MouseEvent$1, ReactElement } from 'react';
4
4
  import * as CSS from 'csstype';
5
5
  import { Property, StandardProperties } from 'csstype';
6
6
  import { Strategy, UseFloatingReturn, Placement as Placement$1 } from '@floating-ui/react-dom';
@@ -185,7 +185,7 @@ type ButtonSize = (typeof BUTTON_SIZES)[number];
185
185
  type ButtonPurpose = (typeof BUTTON_PURPOSES)[number];
186
186
  type IconPosition = 'left' | 'right';
187
187
  type PickedHTMLAttributes$4 = Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onFocus' | 'onBlur' | 'type' | 'aria-label'>;
188
- type ButtonProps<I extends SvgIcon = SvgIcon> = BaseComponentProps<HTMLButtonElement, {
188
+ type ButtonProps<I extends SvgIcon = SvgIcon, T extends ElementType = 'button'> = PolymorphicBaseComponentProps<T, {
189
189
  /** Størrelsen på knappen.
190
190
  * @default "medium"
191
191
  */
@@ -214,11 +214,7 @@ type ButtonProps<I extends SvgIcon = SvgIcon> = BaseComponentProps<HTMLButtonEle
214
214
  iconState?: IconStatesOf<I>;
215
215
  /**Knapp med full bredde. */
216
216
  fullWidth?: boolean;
217
- /**URL for knapper som skal brukes som lenke. Knappen blir til et `<a>`-element. */
218
- href?: string;
219
- /**Nativt `target`-attributt. Kan settes når knappen er et `<a>`-element. */
220
- target?: string;
221
- } & PickedHTMLAttributes$4, ButtonHTMLAttributes<HTMLButtonElement>>;
217
+ } & PickedHTMLAttributes$4>;
222
218
 
223
219
  declare const TEXT_COLORS: readonly ["text-on-action", "text-on-inverse", "text-on-status-default", "text-on-status-strong", "text-action-resting", "text-action-hover", "text-action-visited", "text-default", "text-requiredfield", "text-subtle", "text-medium", "text-on-notification", "text-on-primary-default", "text-on-primary-medium", "text-on-primary-subtle", "text-on-primary-strong", "text-on-secondary-default", "text-on-secondary-medium", "text-on-secondary-subtle", "text-on-secondary-strong", "text-on-tertiary-default", "text-on-tertiary-medium", "text-on-tertiary-subtle", "text-on-tertiary-strong", "text-on-data-default", "text-on-data-subtle", "icon-on-action", "icon-on-info-default", "icon-on-success-default", "icon-on-danger-default", "icon-on-warning-default", "icon-on-info-strong", "icon-on-success-strong", "icon-on-danger-strong", "icon-on-warning-strong", "icon-on-inverse", "icon-action-resting", "icon-action-hover", "icon-default", "icon-subtle", "icon-medium"];
224
220
  type DDSTextColor = (typeof TEXT_COLORS)[number];
@@ -254,7 +250,7 @@ declare namespace Icon {
254
250
  }
255
251
 
256
252
  declare const Button: {
257
- <I extends SvgIcon>({ children, purpose, size, iconPosition, href, target, loading, loadingTooltip, fullWidth, icon, iconState, onClick, onFocus, onBlur, id, ref, className, style, htmlProps, ...props }: ButtonProps<I>): react_jsx_runtime.JSX.Element | undefined;
253
+ <I extends SvgIcon, T extends ElementType = "button">({ as: propAs, children, purpose, size, iconPosition, loading, loadingTooltip, fullWidth, icon, iconState, onClick, onFocus, onBlur, id, ref, className, style, htmlProps, ...props }: ButtonProps<I, T>): react_jsx_runtime.JSX.Element;
258
254
  displayName: string;
259
255
  };
260
256
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { ComponentPropsWithRef, HTMLAttributes, Ref, CSSProperties, ElementType, ComponentPropsWithoutRef, ReactNode, SVGAttributes, JSX, ButtonHTMLAttributes, MouseEventHandler, DependencyList, RefCallback, Dispatch, SetStateAction, ChangeEvent, RefObject, KeyboardEvent as KeyboardEvent$1, ComponentProps, AnchorHTMLAttributes, LabelHTMLAttributes, AriaRole, InputHTMLAttributes, FocusEvent, ForwardedRef, ForwardRefExoticComponent, MouseEvent as MouseEvent$1, ReactElement } from 'react';
3
+ import { ComponentPropsWithRef, ElementType, CSSProperties, Ref, ComponentPropsWithoutRef, HTMLAttributes, ReactNode, SVGAttributes, JSX, ButtonHTMLAttributes, MouseEventHandler, DependencyList, RefCallback, Dispatch, SetStateAction, ChangeEvent, RefObject, KeyboardEvent as KeyboardEvent$1, ComponentProps, AnchorHTMLAttributes, LabelHTMLAttributes, AriaRole, InputHTMLAttributes, FocusEvent, ForwardedRef, ForwardRefExoticComponent, MouseEvent as MouseEvent$1, ReactElement } from 'react';
4
4
  import * as CSS from 'csstype';
5
5
  import { Property, StandardProperties } from 'csstype';
6
6
  import { Strategy, UseFloatingReturn, Placement as Placement$1 } from '@floating-ui/react-dom';
@@ -185,7 +185,7 @@ type ButtonSize = (typeof BUTTON_SIZES)[number];
185
185
  type ButtonPurpose = (typeof BUTTON_PURPOSES)[number];
186
186
  type IconPosition = 'left' | 'right';
187
187
  type PickedHTMLAttributes$4 = Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onFocus' | 'onBlur' | 'type' | 'aria-label'>;
188
- type ButtonProps<I extends SvgIcon = SvgIcon> = BaseComponentProps<HTMLButtonElement, {
188
+ type ButtonProps<I extends SvgIcon = SvgIcon, T extends ElementType = 'button'> = PolymorphicBaseComponentProps<T, {
189
189
  /** Størrelsen på knappen.
190
190
  * @default "medium"
191
191
  */
@@ -214,11 +214,7 @@ type ButtonProps<I extends SvgIcon = SvgIcon> = BaseComponentProps<HTMLButtonEle
214
214
  iconState?: IconStatesOf<I>;
215
215
  /**Knapp med full bredde. */
216
216
  fullWidth?: boolean;
217
- /**URL for knapper som skal brukes som lenke. Knappen blir til et `<a>`-element. */
218
- href?: string;
219
- /**Nativt `target`-attributt. Kan settes når knappen er et `<a>`-element. */
220
- target?: string;
221
- } & PickedHTMLAttributes$4, ButtonHTMLAttributes<HTMLButtonElement>>;
217
+ } & PickedHTMLAttributes$4>;
222
218
 
223
219
  declare const TEXT_COLORS: readonly ["text-on-action", "text-on-inverse", "text-on-status-default", "text-on-status-strong", "text-action-resting", "text-action-hover", "text-action-visited", "text-default", "text-requiredfield", "text-subtle", "text-medium", "text-on-notification", "text-on-primary-default", "text-on-primary-medium", "text-on-primary-subtle", "text-on-primary-strong", "text-on-secondary-default", "text-on-secondary-medium", "text-on-secondary-subtle", "text-on-secondary-strong", "text-on-tertiary-default", "text-on-tertiary-medium", "text-on-tertiary-subtle", "text-on-tertiary-strong", "text-on-data-default", "text-on-data-subtle", "icon-on-action", "icon-on-info-default", "icon-on-success-default", "icon-on-danger-default", "icon-on-warning-default", "icon-on-info-strong", "icon-on-success-strong", "icon-on-danger-strong", "icon-on-warning-strong", "icon-on-inverse", "icon-action-resting", "icon-action-hover", "icon-default", "icon-subtle", "icon-medium"];
224
220
  type DDSTextColor = (typeof TEXT_COLORS)[number];
@@ -254,7 +250,7 @@ declare namespace Icon {
254
250
  }
255
251
 
256
252
  declare const Button: {
257
- <I extends SvgIcon>({ children, purpose, size, iconPosition, href, target, loading, loadingTooltip, fullWidth, icon, iconState, onClick, onFocus, onBlur, id, ref, className, style, htmlProps, ...props }: ButtonProps<I>): react_jsx_runtime.JSX.Element | undefined;
253
+ <I extends SvgIcon, T extends ElementType = "button">({ as: propAs, children, purpose, size, iconPosition, loading, loadingTooltip, fullWidth, icon, iconState, onClick, onFocus, onBlur, id, ref, className, style, htmlProps, ...props }: ButtonProps<I, T>): react_jsx_runtime.JSX.Element;
258
254
  displayName: string;
259
255
  };
260
256
 
package/dist/index.js CHANGED
@@ -4357,12 +4357,11 @@ var useButtonGroupContext = () => (0, import_react19.useContext)(ButtonGroupCont
4357
4357
  // src/components/Button/Button.tsx
4358
4358
  var import_jsx_runtime198 = require("react/jsx-runtime");
4359
4359
  var Button = ({
4360
+ as: propAs,
4360
4361
  children,
4361
4362
  purpose = "primary",
4362
4363
  size: size2 = "medium",
4363
4364
  iconPosition = "left",
4364
- href,
4365
- target,
4366
4365
  loading,
4367
4366
  loadingTooltip,
4368
4367
  fullWidth = false,
@@ -4375,7 +4374,7 @@ var Button = ({
4375
4374
  ref,
4376
4375
  className,
4377
4376
  style,
4378
- htmlProps = {},
4377
+ htmlProps,
4379
4378
  ...props
4380
4379
  }) => {
4381
4380
  var _a;
@@ -4429,46 +4428,27 @@ var Button = ({
4429
4428
  ] });
4430
4429
  const rest = props;
4431
4430
  const { disabled: restDisabled, ...restFinal } = rest;
4432
- const htmlDisabled = htmlProps.disabled;
4431
+ const htmlDisabled = htmlProps == null ? void 0 : htmlProps.disabled;
4433
4432
  const isDisabled = ((_a = restDisabled != null ? restDisabled : htmlDisabled) != null ? _a : loading) === true;
4434
- if (!href)
4435
- return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(
4436
- "button",
4437
- {
4438
- ref,
4439
- ...getBaseHTMLProps(id, buttonCn, style, htmlProps, restFinal),
4440
- onClick,
4441
- onFocus,
4442
- onBlur,
4443
- disabled: isDisabled,
4444
- children: content
4445
- }
4446
- );
4447
- else if (href)
4448
- return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(
4449
- "a",
4450
- {
4451
- ref,
4452
- ...getBaseHTMLProps(
4453
- id,
4454
- buttonCn,
4455
- style,
4456
- //TODO: fikse types ordentlig
4457
- htmlProps,
4458
- props
4459
- ),
4460
- onClick: loading ? void 0 : (
4461
- //TODO: fikse types ordentlig
4462
- onClick
4463
- ),
4464
- onFocus,
4465
- onBlur,
4466
- href,
4467
- rel: "noreferrer noopener",
4468
- target,
4469
- children: content
4470
- }
4471
- );
4433
+ const as = propAs ? propAs : "button";
4434
+ const isAnchor = as === "a";
4435
+ const aProps = isAnchor ? {
4436
+ rel: "noopener noreferrer"
4437
+ } : {};
4438
+ return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(
4439
+ ElementAs,
4440
+ {
4441
+ as,
4442
+ ref,
4443
+ ...getBaseHTMLProps(id, buttonCn, style, htmlProps, restFinal),
4444
+ onClick,
4445
+ onFocus,
4446
+ onBlur,
4447
+ disabled: isDisabled,
4448
+ ...aProps,
4449
+ children: content
4450
+ }
4451
+ );
4472
4452
  };
4473
4453
  Button.displayName = "Button";
4474
4454
  var texts2 = createTexts({