@norges-domstoler/dds-components 0.0.0-dev-20250306095813 → 0.0.0-dev-20250331092559

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
@@ -2757,6 +2757,7 @@ declare const Tabs: {
2757
2757
  displayName: string;
2758
2758
  };
2759
2759
 
2760
+ type PickedAttributes = Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onKeyDown'>;
2760
2761
  type TabProps = BaseComponentPropsWithChildren<HTMLButtonElement, {
2761
2762
  /**Spesifiserer om fanen er aktiv.
2762
2763
  * @default false
@@ -2774,7 +2775,7 @@ type TabProps = BaseComponentPropsWithChildren<HTMLButtonElement, {
2774
2775
  * @default "1fr"
2775
2776
  */
2776
2777
  width?: CSS.Properties['width'];
2777
- } & Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onKeyDown'>, Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onKeyDown'>>;
2778
+ } & PickedAttributes, Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof PickedAttributes>>;
2778
2779
  declare const Tab: {
2779
2780
  ({ active, icon, children, focus, setFocus, index, onClick, onKeyDown, id, className, htmlProps, width, ref, ...rest }: TabProps): react_jsx_runtime.JSX.Element;
2780
2781
  displayName: string;
package/dist/index.d.ts CHANGED
@@ -2757,6 +2757,7 @@ declare const Tabs: {
2757
2757
  displayName: string;
2758
2758
  };
2759
2759
 
2760
+ type PickedAttributes = Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onKeyDown'>;
2760
2761
  type TabProps = BaseComponentPropsWithChildren<HTMLButtonElement, {
2761
2762
  /**Spesifiserer om fanen er aktiv.
2762
2763
  * @default false
@@ -2774,7 +2775,7 @@ type TabProps = BaseComponentPropsWithChildren<HTMLButtonElement, {
2774
2775
  * @default "1fr"
2775
2776
  */
2776
2777
  width?: CSS.Properties['width'];
2777
- } & Pick<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onKeyDown'>, Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'onKeyDown'>>;
2778
+ } & PickedAttributes, Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof PickedAttributes>>;
2778
2779
  declare const Tab: {
2779
2780
  ({ active, icon, children, focus, setFocus, index, onClick, onKeyDown, id, className, htmlProps, width, ref, ...rest }: TabProps): react_jsx_runtime.JSX.Element;
2780
2781
  displayName: string;
package/dist/index.js CHANGED
@@ -587,6 +587,9 @@ var spaceSeparatedIdListGenerator = (values) => {
587
587
  return filtered.length > 0 ? filtered.join(" ") : void 0;
588
588
  };
589
589
 
590
+ // src/utils/object.tsx
591
+ var isEmpty = (obj) => Object.keys(obj).length === 0 && obj.constructor === Object;
592
+
590
593
  // src/utils/readonlyEventHandlers.tsx
591
594
  var readOnlyMouseDownHandler = (readOnly, onMouseDown) => {
592
595
  return (evt) => {
@@ -3177,7 +3180,7 @@ var AccordionContextProvider = ({
3177
3180
  };
3178
3181
  var useAccordionContext = () => {
3179
3182
  const context = (0, import_react13.useContext)(AccordionContext);
3180
- if (!context) {
3183
+ if (isEmpty(context)) {
3181
3184
  throw new Error(
3182
3185
  "useAccordionContext must be used within a AccordionContextProvider. Have you wrapped <AccordionHeader> and <AccordionBody> inside a <Accordion>, or <CardAccordionHeader> and <CardAccordionBody> inside a <CardAccordion>?"
3183
3186
  );
@@ -3240,7 +3243,7 @@ var AccordionHeader = ({
3240
3243
  ...rest
3241
3244
  }) => {
3242
3245
  const { isExpanded, headerProps } = useAccordionContext();
3243
- const { id, ...restHeaderProps } = headerProps;
3246
+ const { id, ...restHeaderProps } = headerProps != null ? headerProps : {};
3244
3247
  return /* @__PURE__ */ (0, import_jsx_runtime180.jsxs)(
3245
3248
  "button",
3246
3249
  {
@@ -3305,7 +3308,12 @@ var AccordionBody = ({
3305
3308
  ...rest
3306
3309
  }) => {
3307
3310
  const { bodyContentRef, bodyProps } = useAccordionContext();
3308
- const { className: bodyContextCn, id, height, ...restBodyProps } = bodyProps;
3311
+ const {
3312
+ className: bodyContextCn,
3313
+ id,
3314
+ height,
3315
+ ...restBodyProps
3316
+ } = bodyProps != null ? bodyProps : {};
3309
3317
  const styleVariables = {
3310
3318
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3311
3319
  ["--dds-card-accordion-body-height"]: height + "px"
@@ -3336,14 +3344,7 @@ var BackLink_default = {
3336
3344
  var import_jsx_runtime182 = require("react/jsx-runtime");
3337
3345
  var BackLink = ({ label, ref, ...rest }) => {
3338
3346
  return /* @__PURE__ */ (0, import_jsx_runtime182.jsx)("nav", { ref, "aria-label": "G\xE5 tilbake", children: /* @__PURE__ */ (0, import_jsx_runtime182.jsxs)(Link, { ...rest, children: [
3339
- /* @__PURE__ */ (0, import_jsx_runtime182.jsx)(
3340
- Icon,
3341
- {
3342
- icon: ArrowLeftIcon,
3343
- iconSize: "inherit",
3344
- className: BackLink_default.icon
3345
- }
3346
- ),
3347
+ /* @__PURE__ */ (0, import_jsx_runtime182.jsx)(Icon, { icon: ArrowLeftIcon, iconSize: "inherit", className: BackLink_default.icon }),
3347
3348
  label
3348
3349
  ] }) });
3349
3350
  };
@@ -3930,16 +3931,13 @@ var OverflowMenuGroup = ({
3930
3931
  handleClose();
3931
3932
  });
3932
3933
  const Children7 = import_react20.Children.map(children, (child, childIndex) => {
3933
- return (0, import_react20.isValidElement)(child) && (childIndex === 0 ? (0, import_react20.cloneElement)(
3934
- child,
3935
- {
3936
- "aria-haspopup": "menu",
3937
- "aria-controls": uniqueOverflowMenuId,
3938
- "aria-expanded": isOpen,
3939
- onClick: handleToggle,
3940
- ref: combinedAnchorRef
3941
- }
3942
- ) : child);
3934
+ return (0, import_react20.isValidElement)(child) && (childIndex === 0 ? (0, import_react20.cloneElement)(child, {
3935
+ "aria-haspopup": "menu",
3936
+ "aria-controls": uniqueOverflowMenuId,
3937
+ "aria-expanded": isOpen,
3938
+ onClick: handleToggle,
3939
+ ref: combinedAnchorRef
3940
+ }) : child);
3943
3941
  });
3944
3942
  return /* @__PURE__ */ (0, import_jsx_runtime195.jsx)(
3945
3943
  OverflowMenuContextProvider,
@@ -4203,7 +4201,7 @@ var CardExpandableHeader = ({
4203
4201
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4204
4202
  ["--dds-card-accordion-header-container-padding"]: padding != null ? padding : "var(--dds-spacing-x1) var(--dds-spacing-x0-75) var(--dds-spacing-x1) var(--dds-spacing-x1-5)"
4205
4203
  };
4206
- const { id, ...restHeaderProps } = headerProps;
4204
+ const { id, ...restHeaderProps } = headerProps != null ? headerProps : {};
4207
4205
  return /* @__PURE__ */ (0, import_jsx_runtime200.jsx)(
4208
4206
  "button",
4209
4207
  {
@@ -4269,7 +4267,12 @@ var CardExpandableBody = ({
4269
4267
  ...rest
4270
4268
  }) => {
4271
4269
  const { bodyContentRef, bodyProps } = useAccordionContext();
4272
- const { className: bodyContextCn, id, height, ...restBodyProps } = bodyProps;
4270
+ const {
4271
+ className: bodyContextCn,
4272
+ id,
4273
+ height,
4274
+ ...restBodyProps
4275
+ } = bodyProps != null ? bodyProps : {};
4273
4276
  const styleVariables = {
4274
4277
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4275
4278
  ["--dds-card-accordion-body-height"]: height + "px"
@@ -5535,9 +5538,7 @@ var Drawer = ({
5535
5538
  return () => handleElementWithBackdropUnmount(document.body);
5536
5539
  }
5537
5540
  }, [isOpen]);
5538
- const elements = [
5539
- drawerRef.current
5540
- ];
5541
+ const elements = [drawerRef.current];
5541
5542
  if (triggerEl) elements.push(triggerEl);
5542
5543
  useOnClickOutside(elements, () => {
5543
5544
  if (isOpen && !withBackdrop) {
@@ -5657,16 +5658,13 @@ var DrawerGroup = ({
5657
5658
  }
5658
5659
  });
5659
5660
  const Children7 = import_react38.Children.map(children, (child, childIndex) => {
5660
- return (0, import_react38.isValidElement)(child) && (childIndex === 0 ? (0, import_react38.cloneElement)(
5661
- child,
5662
- {
5663
- "aria-haspopup": "dialog",
5664
- "aria-controls": uniqueDrawerId,
5665
- "aria-expanded": isOpen,
5666
- ref: triggerRef,
5667
- onClick: handleOpen
5668
- }
5669
- ) : child);
5661
+ return (0, import_react38.isValidElement)(child) && (childIndex === 0 ? (0, import_react38.cloneElement)(child, {
5662
+ "aria-haspopup": "dialog",
5663
+ "aria-controls": uniqueDrawerId,
5664
+ "aria-expanded": isOpen,
5665
+ ref: triggerRef,
5666
+ onClick: handleOpen
5667
+ }) : child);
5670
5668
  });
5671
5669
  return /* @__PURE__ */ (0, import_jsx_runtime227.jsx)(
5672
5670
  DrawerContext,
@@ -8440,38 +8438,32 @@ var DDSInput = (props, ariaInvalid, ariaDescribedby) => /* @__PURE__ */ (0, impo
8440
8438
  );
8441
8439
  var DDSControl = (props, componentSize, readOnly, icon, dataTestId) => {
8442
8440
  const { className, ...rest } = props;
8443
- return /* @__PURE__ */ (0, import_jsx_runtime267.jsx)(
8444
- "div",
8441
+ return /* @__PURE__ */ (0, import_jsx_runtime267.jsx)("div", { "data-testid": dataTestId ? dataTestId + "-control" : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime267.jsxs)(
8442
+ Control,
8445
8443
  {
8446
- "data-testid": dataTestId ? dataTestId + "-control" : void 0,
8447
- children: /* @__PURE__ */ (0, import_jsx_runtime267.jsxs)(
8448
- Control,
8449
- {
8450
- ...rest,
8451
- className: cn(
8452
- className,
8453
- Select_default.control,
8454
- rest.isDisabled && Select_default["control--disabled"],
8455
- readOnly && Select_default["control--readonly"]
8456
- ),
8457
- children: [
8458
- icon && /* @__PURE__ */ (0, import_jsx_runtime267.jsx)(
8459
- Icon,
8460
- {
8461
- icon,
8462
- iconSize: getFormInputIconSize(componentSize),
8463
- className: cn(
8464
- Input_default["input-group__absolute-element"],
8465
- Select_default[`icon--${componentSize}`]
8466
- )
8467
- }
8468
- ),
8469
- props.children
8470
- ]
8471
- }
8472
- )
8444
+ ...rest,
8445
+ className: cn(
8446
+ className,
8447
+ Select_default.control,
8448
+ rest.isDisabled && Select_default["control--disabled"],
8449
+ readOnly && Select_default["control--readonly"]
8450
+ ),
8451
+ children: [
8452
+ icon && /* @__PURE__ */ (0, import_jsx_runtime267.jsx)(
8453
+ Icon,
8454
+ {
8455
+ icon,
8456
+ iconSize: getFormInputIconSize(componentSize),
8457
+ className: cn(
8458
+ Input_default["input-group__absolute-element"],
8459
+ Select_default[`icon--${componentSize}`]
8460
+ )
8461
+ }
8462
+ ),
8463
+ props.children
8464
+ ]
8473
8465
  }
8474
- );
8466
+ ) });
8475
8467
  };
8476
8468
 
8477
8469
  // src/components/Select/Select.tsx
@@ -8763,7 +8755,7 @@ var Pagination = ({
8763
8755
  };
8764
8756
  const listItems = items.length > 0 ? items.map((item, i) => {
8765
8757
  const isActive = item === activePage;
8766
- return /* @__PURE__ */ (0, import_jsx_runtime270.jsx)("li", { className: Pagination_default.list__item, children: item !== "truncator" ? /* @__PURE__ */ (0, import_jsx_runtime270.jsx)(
8758
+ return /* @__PURE__ */ (0, import_jsx_runtime270.jsx)("li", { className: Pagination_default.list__item, children: item !== "truncator" && typeof item === "number" ? /* @__PURE__ */ (0, import_jsx_runtime270.jsx)(
8767
8759
  Button,
8768
8760
  {
8769
8761
  purpose: isActive ? "primary" : "secondary",
@@ -9662,7 +9654,7 @@ var Popover = ({
9662
9654
  isOpen: contextIsOpen,
9663
9655
  anchorEl: contextAnchorEl
9664
9656
  } = context;
9665
- const hasContext = contextPopoverId !== void 0;
9657
+ const hasContext = !isEmpty(context);
9666
9658
  const generatedId = (0, import_react61.useId)();
9667
9659
  const uniquePopoverId = id != null ? id : `${generatedId}-popover`;
9668
9660
  const [
@@ -9817,16 +9809,13 @@ var PopoverGroup = ({
9817
9809
  });
9818
9810
  const isAnchorChild = (i) => i === 0;
9819
9811
  const Children7 = import_react62.Children.map(children, (child, childIndex) => {
9820
- return (0, import_react62.isValidElement)(child) && (isAnchorChild(childIndex) ? (0, import_react62.cloneElement)(
9821
- child,
9822
- {
9823
- "aria-haspopup": "dialog",
9824
- "aria-controls": uniquePopoverId,
9825
- "aria-expanded": open,
9826
- onClick: handleToggle,
9827
- ref: combinedAnchorRef
9828
- }
9829
- ) : child);
9812
+ return (0, import_react62.isValidElement)(child) && (isAnchorChild(childIndex) ? (0, import_react62.cloneElement)(child, {
9813
+ "aria-haspopup": "dialog",
9814
+ "aria-controls": uniquePopoverId,
9815
+ "aria-expanded": open,
9816
+ onClick: handleToggle,
9817
+ ref: combinedAnchorRef
9818
+ }) : child);
9830
9819
  });
9831
9820
  return /* @__PURE__ */ (0, import_jsx_runtime273.jsx)(
9832
9821
  PopoverContext,
@@ -11674,7 +11663,7 @@ var Tab = ({
11674
11663
  onKeyDown,
11675
11664
  id,
11676
11665
  className,
11677
- htmlProps,
11666
+ htmlProps = {},
11678
11667
  width = "1fr",
11679
11668
  ref,
11680
11669
  ...rest
@@ -11683,6 +11672,8 @@ var Tab = ({
11683
11672
  const itemRef = (0, import_react86.useRef)(null);
11684
11673
  const combinedRef = useCombinedRef(ref, itemRef);
11685
11674
  const { tabContentDirection, size: size2 } = useTabsContext();
11675
+ const { type = "button", ...restHtmlProps } = htmlProps;
11676
+ const fixedHtmlProps = { type, ...restHtmlProps };
11686
11677
  (0, import_react86.useEffect)(() => {
11687
11678
  var _a;
11688
11679
  if (focus) {
@@ -11696,11 +11687,11 @@ var Tab = ({
11696
11687
  }, [index, setFocus]);
11697
11688
  const handleOnClick = (e) => {
11698
11689
  handleSelect();
11699
- onClick && onClick(e);
11690
+ onClick == null ? void 0 : onClick(e);
11700
11691
  };
11701
11692
  const handleOnKeyDown = (e) => {
11702
11693
  handleSelect();
11703
- onKeyDown && onKeyDown(e);
11694
+ onKeyDown == null ? void 0 : onKeyDown(e);
11704
11695
  };
11705
11696
  return /* @__PURE__ */ (0, import_jsx_runtime302.jsxs)(
11706
11697
  "button",
@@ -11716,7 +11707,7 @@ var Tab = ({
11716
11707
  typographyStyles_default[`body-${size2}`],
11717
11708
  focus_default["focusable--inset"]
11718
11709
  ),
11719
- htmlProps,
11710
+ fixedHtmlProps,
11720
11711
  rest
11721
11712
  ),
11722
11713
  ref: combinedRef,
@@ -11766,6 +11757,7 @@ var TabList = ({
11766
11757
  return (0, import_react87.isValidElement)(child) && (0, import_react87.cloneElement)(child, {
11767
11758
  id: `${tabsId}-tab-${index}`,
11768
11759
  htmlProps: {
11760
+ ...child.props.htmlProps,
11769
11761
  "aria-controls": `${tabsId}-panel-${index}`
11770
11762
  },
11771
11763
  active: activeTab === index,