@norges-domstoler/dds-components 0.0.0-dev-20260114122739 → 0.0.0-dev-20260119151916

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
 
@@ -3224,14 +3220,28 @@ type PropsOfWithRef<T extends ElementType> = ComponentPropsWithRef<T> & {
3224
3220
  type PolymorphicProps<T extends ElementType> = PropsOfWithRef<T>;
3225
3221
  declare const ElementAs: <T extends ElementType>({ as, ref, children, ...props }: PolymorphicProps<T>) => react_jsx_runtime.JSX.Element;
3226
3222
 
3227
- type AccordionProps = BaseComponentPropsWithChildren<HTMLDivElement, {
3228
- /**Spesifiserer om body skal være utvidet ved innlastning. */
3223
+ interface AccordionConfig {
3224
+ /**
3225
+ * Ukontrollerttilstand: om utvidbare delen skal være utvidet ved første render.
3226
+ */
3227
+ isInitiallyExpanded?: boolean;
3228
+ /**
3229
+ * Kontrollert tilstand: om utvidbare delen er utvidet.
3230
+ */
3229
3231
  isExpanded?: boolean;
3230
- /**For å lytte til endringer i expanded-state. */
3232
+ /**
3233
+ * Callback når tilstanden endres.
3234
+ */
3231
3235
  onChange?: (expanded: boolean) => void;
3232
- }>;
3236
+ /**
3237
+ * Custom id for accordion; delene får i tillegg suffix `'header'` og `'body'`.
3238
+ */
3239
+ id?: string;
3240
+ }
3241
+
3242
+ type AccordionProps = BaseComponentPropsWithChildren<HTMLDivElement, Pick<AccordionConfig, 'isExpanded' | 'isInitiallyExpanded' | 'onChange'>>;
3233
3243
  declare const Accordion: {
3234
- ({ isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: AccordionProps): react_jsx_runtime.JSX.Element;
3244
+ ({ isInitiallyExpanded, isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: AccordionProps): react_jsx_runtime.JSX.Element;
3235
3245
  displayName: string;
3236
3246
  };
3237
3247
 
@@ -3543,14 +3553,9 @@ declare const Card: {
3543
3553
  displayName: string;
3544
3554
  };
3545
3555
 
3546
- type CardExpandableProps = BaseComponentPropsWithChildren<HTMLDivElement, {
3547
- /**Spesifiserer om body skal være utvidet ved innlastning. */
3548
- isExpanded?: boolean;
3549
- /**For å lytte til endringer i expanded-state. */
3550
- onChange?: (expanded: boolean) => void;
3551
- }>;
3556
+ type CardExpandableProps = BaseComponentPropsWithChildren<HTMLDivElement, Pick<AccordionConfig, 'isExpanded' | 'isInitiallyExpanded' | 'onChange'>>;
3552
3557
  declare const CardExpandable: {
3553
- ({ isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: CardExpandableProps): react_jsx_runtime.JSX.Element;
3558
+ ({ isInitiallyExpanded, isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: CardExpandableProps): react_jsx_runtime.JSX.Element;
3554
3559
  displayName: string;
3555
3560
  };
3556
3561
 
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
 
@@ -3224,14 +3220,28 @@ type PropsOfWithRef<T extends ElementType> = ComponentPropsWithRef<T> & {
3224
3220
  type PolymorphicProps<T extends ElementType> = PropsOfWithRef<T>;
3225
3221
  declare const ElementAs: <T extends ElementType>({ as, ref, children, ...props }: PolymorphicProps<T>) => react_jsx_runtime.JSX.Element;
3226
3222
 
3227
- type AccordionProps = BaseComponentPropsWithChildren<HTMLDivElement, {
3228
- /**Spesifiserer om body skal være utvidet ved innlastning. */
3223
+ interface AccordionConfig {
3224
+ /**
3225
+ * Ukontrollerttilstand: om utvidbare delen skal være utvidet ved første render.
3226
+ */
3227
+ isInitiallyExpanded?: boolean;
3228
+ /**
3229
+ * Kontrollert tilstand: om utvidbare delen er utvidet.
3230
+ */
3229
3231
  isExpanded?: boolean;
3230
- /**For å lytte til endringer i expanded-state. */
3232
+ /**
3233
+ * Callback når tilstanden endres.
3234
+ */
3231
3235
  onChange?: (expanded: boolean) => void;
3232
- }>;
3236
+ /**
3237
+ * Custom id for accordion; delene får i tillegg suffix `'header'` og `'body'`.
3238
+ */
3239
+ id?: string;
3240
+ }
3241
+
3242
+ type AccordionProps = BaseComponentPropsWithChildren<HTMLDivElement, Pick<AccordionConfig, 'isExpanded' | 'isInitiallyExpanded' | 'onChange'>>;
3233
3243
  declare const Accordion: {
3234
- ({ isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: AccordionProps): react_jsx_runtime.JSX.Element;
3244
+ ({ isInitiallyExpanded, isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: AccordionProps): react_jsx_runtime.JSX.Element;
3235
3245
  displayName: string;
3236
3246
  };
3237
3247
 
@@ -3543,14 +3553,9 @@ declare const Card: {
3543
3553
  displayName: string;
3544
3554
  };
3545
3555
 
3546
- type CardExpandableProps = BaseComponentPropsWithChildren<HTMLDivElement, {
3547
- /**Spesifiserer om body skal være utvidet ved innlastning. */
3548
- isExpanded?: boolean;
3549
- /**For å lytte til endringer i expanded-state. */
3550
- onChange?: (expanded: boolean) => void;
3551
- }>;
3556
+ type CardExpandableProps = BaseComponentPropsWithChildren<HTMLDivElement, Pick<AccordionConfig, 'isExpanded' | 'isInitiallyExpanded' | 'onChange'>>;
3552
3557
  declare const CardExpandable: {
3553
- ({ isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: CardExpandableProps): react_jsx_runtime.JSX.Element;
3558
+ ({ isInitiallyExpanded, isExpanded, onChange, id, children, className, style, htmlProps, ...rest }: CardExpandableProps): react_jsx_runtime.JSX.Element;
3554
3559
  displayName: string;
3555
3560
  };
3556
3561
 
package/dist/index.js CHANGED
@@ -3581,32 +3581,27 @@ var AccordionBase_default = {
3581
3581
 
3582
3582
  // src/components/helpers/AccordionBase/useAccordion.tsx
3583
3583
  var useAccordion = ({
3584
- initiallyExpanded = false,
3584
+ isInitiallyExpanded = false,
3585
+ isExpanded: isExpandedProp,
3585
3586
  onChange,
3586
3587
  id
3587
3588
  }) => {
3588
3589
  var _a;
3589
- const [isExpanded, setIsExpanded] = (0, import_react17.useState)(initiallyExpanded);
3590
+ const [isExpanded, setIsExpanded] = useControllableState({
3591
+ onChange,
3592
+ defaultValue: isInitiallyExpanded,
3593
+ value: isExpandedProp
3594
+ });
3590
3595
  const generatedId = (0, import_react17.useId)();
3591
3596
  const accordionId = id != null ? id : `${generatedId}-accordion`;
3592
- const openAccordion = () => {
3593
- setIsExpanded(true);
3594
- };
3595
- const closeAccordion = () => {
3596
- setIsExpanded(false);
3597
- };
3598
- (0, import_react17.useEffect)(() => {
3599
- setIsExpanded(isExpanded);
3600
- }, [isExpanded]);
3597
+ const openAccordion = (0, import_react17.useCallback)(() => setIsExpanded(true), [setIsExpanded]);
3598
+ const closeAccordion = (0, import_react17.useCallback)(
3599
+ () => setIsExpanded(false),
3600
+ [setIsExpanded]
3601
+ );
3601
3602
  const toggleExpanded = (0, import_react17.useCallback)(() => {
3602
- setIsExpanded((prevExpanded) => {
3603
- const newExpanded = !prevExpanded;
3604
- if (onChange) {
3605
- onChange(newExpanded);
3606
- }
3607
- return newExpanded;
3608
- });
3609
- }, [onChange]);
3603
+ setIsExpanded((prev) => !prev);
3604
+ }, [setIsExpanded]);
3610
3605
  const bodyContentRef = (0, import_react17.useRef)(null);
3611
3606
  const [animate, setAnimate] = (0, import_react17.useState)(false);
3612
3607
  const isMounted = useIsMounted();
@@ -3676,7 +3671,8 @@ var useAccordionContext = () => {
3676
3671
  // src/components/Accordion/Accordion.tsx
3677
3672
  var import_jsx_runtime185 = require("react/jsx-runtime");
3678
3673
  var Accordion = ({
3679
- isExpanded = false,
3674
+ isInitiallyExpanded = false,
3675
+ isExpanded,
3680
3676
  onChange,
3681
3677
  id,
3682
3678
  children,
@@ -3692,7 +3688,7 @@ var Accordion = ({
3692
3688
  bodyContentRef,
3693
3689
  headerProps,
3694
3690
  bodyProps
3695
- } = useAccordion({ initiallyExpanded: isExpanded, onChange, id });
3691
+ } = useAccordion({ isInitiallyExpanded, isExpanded, onChange, id });
3696
3692
  return /* @__PURE__ */ (0, import_jsx_runtime185.jsx)(
3697
3693
  "div",
3698
3694
  {
@@ -4361,12 +4357,11 @@ var useButtonGroupContext = () => (0, import_react19.useContext)(ButtonGroupCont
4361
4357
  // src/components/Button/Button.tsx
4362
4358
  var import_jsx_runtime198 = require("react/jsx-runtime");
4363
4359
  var Button = ({
4360
+ as: propAs,
4364
4361
  children,
4365
4362
  purpose = "primary",
4366
4363
  size: size2 = "medium",
4367
4364
  iconPosition = "left",
4368
- href,
4369
- target,
4370
4365
  loading,
4371
4366
  loadingTooltip,
4372
4367
  fullWidth = false,
@@ -4379,7 +4374,7 @@ var Button = ({
4379
4374
  ref,
4380
4375
  className,
4381
4376
  style,
4382
- htmlProps = {},
4377
+ htmlProps,
4383
4378
  ...props
4384
4379
  }) => {
4385
4380
  var _a;
@@ -4433,46 +4428,27 @@ var Button = ({
4433
4428
  ] });
4434
4429
  const rest = props;
4435
4430
  const { disabled: restDisabled, ...restFinal } = rest;
4436
- const htmlDisabled = htmlProps.disabled;
4431
+ const htmlDisabled = htmlProps == null ? void 0 : htmlProps.disabled;
4437
4432
  const isDisabled = ((_a = restDisabled != null ? restDisabled : htmlDisabled) != null ? _a : loading) === true;
4438
- if (!href)
4439
- return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(
4440
- "button",
4441
- {
4442
- ref,
4443
- ...getBaseHTMLProps(id, buttonCn, style, htmlProps, restFinal),
4444
- onClick,
4445
- onFocus,
4446
- onBlur,
4447
- disabled: isDisabled,
4448
- children: content
4449
- }
4450
- );
4451
- else if (href)
4452
- return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(
4453
- "a",
4454
- {
4455
- ref,
4456
- ...getBaseHTMLProps(
4457
- id,
4458
- buttonCn,
4459
- style,
4460
- //TODO: fikse types ordentlig
4461
- htmlProps,
4462
- props
4463
- ),
4464
- onClick: loading ? void 0 : (
4465
- //TODO: fikse types ordentlig
4466
- onClick
4467
- ),
4468
- onFocus,
4469
- onBlur,
4470
- href,
4471
- rel: "noreferrer noopener",
4472
- target,
4473
- children: content
4474
- }
4475
- );
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
+ );
4476
4452
  };
4477
4453
  Button.displayName = "Button";
4478
4454
  var texts2 = createTexts({
@@ -5039,7 +5015,8 @@ var CardExpandable_default = {
5039
5015
  // src/components/Card/CardExpandable/CardExpandable.tsx
5040
5016
  var import_jsx_runtime212 = require("react/jsx-runtime");
5041
5017
  var CardExpandable = ({
5042
- isExpanded = false,
5018
+ isInitiallyExpanded = false,
5019
+ isExpanded,
5043
5020
  onChange,
5044
5021
  id,
5045
5022
  children,
@@ -5055,7 +5032,7 @@ var CardExpandable = ({
5055
5032
  bodyContentRef,
5056
5033
  headerProps,
5057
5034
  bodyProps
5058
- } = useAccordion({ initiallyExpanded: isExpanded, onChange, id });
5035
+ } = useAccordion({ isInitiallyExpanded, isExpanded, onChange, id });
5059
5036
  return /* @__PURE__ */ (0, import_jsx_runtime212.jsx)(
5060
5037
  "div",
5061
5038
  {