@inera/ids-react 7.1.0 → 7.2.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.
@@ -5,6 +5,7 @@ interface IDSCheckboxGroupProps extends InputHTMLAttributes<HTMLInputElement> {
5
5
  compact?: boolean;
6
6
  tooltip?: ReactNode;
7
7
  block?: boolean;
8
+ noValidation?: boolean;
8
9
  children?: ReactNode;
9
10
  onValidityChange?: (isValid: boolean) => void;
10
11
  setCheckedBoxesCount?: Dispatch<SetStateAction<number>>;
@@ -6,42 +6,31 @@ import { useElementId } from '../../utils/hooks/useElementId.js';
6
6
  import { useGroupValidity } from '../form-hooks/useGroupValidity.js';
7
7
  import clsx from 'clsx';
8
8
 
9
- const IDSCheckboxGroup = ({ legend = "", errorMsg = "", compact = false, block = false, tooltip, children, className, onValidityChange, setCheckedBoxesCount }) => {
9
+ const IDSCheckboxGroup = ({ legend = "", errorMsg = "", compact = false, block = false, noValidation = false, tooltip, children, className, onValidityChange, setCheckedBoxesCount }) => {
10
10
  const groupRef = useRef(null);
11
- const isValid = useGroupValidity(groupRef, "checkbox");
11
+ const isValid = useGroupValidity(groupRef, "checkbox", () => {
12
+ onValidityChange?.(false);
13
+ });
12
14
  const errorMsgId = useElementId();
13
15
  useEffect(() => {
14
- if (onValidityChange) {
15
- onValidityChange(isValid);
16
- }
17
- }, [isValid, onValidityChange]);
18
- useEffect(() => {
19
- const checkboxes = groupRef.current?.querySelectorAll(`input[type="checkbox"]`);
20
- if (!checkboxes.length)
21
- return;
22
- const count = () => {
23
- const checkedCount = groupRef.current?.querySelectorAll('input[type="checkbox"]:checked')?.length ?? 0;
24
- if (setCheckedBoxesCount) {
25
- setCheckedBoxesCount(checkedCount);
26
- }
27
- };
28
- count();
29
- checkboxes.forEach(cb => {
30
- cb.addEventListener("change", count);
31
- });
32
- return () => {
33
- checkboxes.forEach(cb => {
34
- cb.removeEventListener("change", count);
35
- });
36
- };
16
+ const checkedCount = groupRef.current?.querySelectorAll('input[type="checkbox"]:checked')?.length ?? 0;
17
+ setCheckedBoxesCount?.(checkedCount);
37
18
  }, [groupRef]);
19
+ useEffect(() => {
20
+ onValidityChange?.(isValid);
21
+ }, [isValid, onValidityChange]);
38
22
  const clonedChildren = React__default.Children.map(children, child => {
39
- if (React__default.isValidElement(child) &&
40
- child.type.displayName === "IDSCheckbox") {
23
+ if (React__default.isValidElement(child) && child.type.displayName === "IDSCheckbox") {
41
24
  return React__default.cloneElement(child, {
42
25
  key: child.props.id,
43
26
  groupErrorMsgId: errorMsg && errorMsgId,
44
- block: block
27
+ block: block,
28
+ noValidation: noValidation,
29
+ onChange: (e) => {
30
+ child.props.onChange?.(e);
31
+ const checkedCount = groupRef.current?.querySelectorAll('input[type="checkbox"]:checked')?.length ?? 0;
32
+ setCheckedBoxesCount?.(checkedCount);
33
+ }
45
34
  });
46
35
  }
47
36
  return child;
@@ -44,7 +44,7 @@ const IDSCheckbox = forwardRef(({ invalid = false, disabled = false, required =
44
44
  "ids-checkbox--compact": compact
45
45
  }), children: [jsx("input", { id: fieldId, ref: checkboxRef, type: "checkbox", className: clsx("ids-checkbox__input", {
46
46
  "ids-focus-anchor": focusAnchor
47
- }), "aria-invalid": isInvalid, disabled: disabled, "aria-disabled": disabled, required: required, "aria-required": required, ...props }), jsxs("div", { className: clsx("ids-label-tooltip-wrapper", {
47
+ }), "aria-invalid": isInvalid, disabled: disabled, "aria-disabled": disabled, required: !noValidation && required, "aria-required": !noValidation && required, ...props }), jsxs("div", { className: clsx("ids-label-tooltip-wrapper", {
48
48
  "ids-label-tooltip-wrapper--block": block,
49
49
  "ids-label-tooltip-wrapper--inline": tooltip
50
50
  }), children: [jsx("label", { htmlFor: fieldId, className: clsx("ds-checkbox__label", {
@@ -1 +1 @@
1
- export declare function useGroupValidity(ref: React.RefObject<HTMLFieldSetElement>, type: "checkbox" | "radio"): boolean;
1
+ export declare function useGroupValidity(ref: React.RefObject<HTMLFieldSetElement>, type: "checkbox" | "radio", onInvalid?: () => void): boolean;
@@ -1,6 +1,6 @@
1
1
  import { useState, useRef, useEffect } from 'react';
2
2
 
3
- function useGroupValidity(ref, type) {
3
+ function useGroupValidity(ref, type, onInvalid) {
4
4
  const [isValid, setIsValid] = useState(true);
5
5
  const [hasInteracted, setHasInteracted] = useState(false);
6
6
  const initialized = useRef(false);
@@ -29,6 +29,7 @@ function useGroupValidity(ref, type) {
29
29
  initialized.current = true;
30
30
  }
31
31
  const handleInteraction = () => {
32
+ onInvalid?.();
32
33
  setHasInteracted(true);
33
34
  validate();
34
35
  };
@@ -38,7 +39,7 @@ function useGroupValidity(ref, type) {
38
39
  };
39
40
  inputs.forEach(cb => {
40
41
  cb.addEventListener("invalid", handleInteraction);
41
- cb.addEventListener("change", handleChange);
42
+ cb.addEventListener("input", handleChange);
42
43
  });
43
44
  const form = fieldset.closest("form");
44
45
  const handleSubmit = () => {
@@ -49,11 +50,11 @@ function useGroupValidity(ref, type) {
49
50
  return () => {
50
51
  inputs.forEach(cb => {
51
52
  cb.removeEventListener("invalid", handleInteraction);
52
- cb.removeEventListener("change", handleChange);
53
+ cb.removeEventListener("input", handleChange);
53
54
  });
54
55
  form?.removeEventListener("submit", handleSubmit);
55
56
  };
56
- }, [ref]);
57
+ }, [ref, onInvalid]);
57
58
  return isValid || !hasInteracted;
58
59
  }
59
60
 
@@ -56,7 +56,10 @@ const IDSSelectMultiple = ({ label = "", selectedLabel = "vald", selectedLabelPl
56
56
  "ids-focus-anchor": focusAnchor
57
57
  }), "aria-expanded": isExpanded, "aria-invalid": invalid || checkboxListInvalid, placeholder: placeholder, value: value, onClick: () => setIsExpanded(!isExpanded), ...props }) }), jsx("div", { className: "ids-select-multiple__dropdown__wrapper", children: jsx("div", { className: clsx("ids-select-multiple__dropdown", {
58
58
  "ids-select-multiple__dropdown--show": isExpanded
59
- }), children: jsx("div", { className: "ids-select-multiple__dropdown__inner", style: { maxHeight: maxHeight }, children: jsx(IDSCheckboxGroup, { block: true, errorMsg: errorMsg, setCheckedBoxesCount: setCheckedBoxesCount, onValidityChange: (isValid) => {
59
+ }), children: jsx("div", { className: "ids-select-multiple__dropdown__inner", style: { maxHeight: maxHeight }, children: jsx(IDSCheckboxGroup, { block: true, noValidation: noValidation, errorMsg: errorMsg, setCheckedBoxesCount: setCheckedBoxesCount, onValidityChange: (isValid) => {
60
+ if (!isValid) {
61
+ setIsExpanded(true);
62
+ }
60
63
  setCheckboxListInvalid(!isValid);
61
64
  }, children: children }) }) }) })] }));
62
65
  };
@@ -5,6 +5,7 @@ export interface IDSHeaderIneraAdminProps extends React.HTMLAttributes<HTMLDivEl
5
5
  serviceName?: string;
6
6
  fluid?: boolean;
7
7
  unresponsive?: boolean;
8
+ showLogo?: boolean;
8
9
  items?: ReactNode;
9
10
  avatar?: ReactNode;
10
11
  skipToContent?: ReactNode;
@@ -5,23 +5,19 @@ import '@inera/ids-design/components/header-inera-admin/header-inera-admin.css';
5
5
  import clsx from 'clsx';
6
6
  import { HeaderProvider } from '../utils/contexts/HeaderContext.js';
7
7
 
8
- const IDSHeaderIneraAdmin = ({ brandText = "", fluid = false, unresponsive = false, items, avatar, skipToContent, brandLink, serviceName = "EN TJÄNST FRÅN INERA", mobileMenu, className, children }) => {
8
+ const IDSHeaderIneraAdmin = ({ brandText = "", fluid = false, unresponsive = false, showLogo = false, items, avatar, skipToContent, brandLink, serviceName = "EN TJÄNST FRÅN INERA", mobileMenu, className, children }) => {
9
9
  const renderBrandText = () => {
10
10
  if (brandLink && isValidElement(brandLink)) {
11
- return (jsx("span", { className: "ids-header-inera-admin__brand-text-link", children: cloneElement(brandLink, {
12
- ...brandLink.props,
13
- children: brandText
11
+ return (jsx("span", { className: "ids-header-inera-admin__brand-link", children: cloneElement(brandLink, {
12
+ ...brandLink.props
14
13
  }) }));
15
14
  }
16
- if (brandText) {
17
- return jsx("h1", { className: "ids-header-inera-admin__brand-text", children: brandText });
18
- }
19
15
  return null;
20
16
  };
21
17
  return (jsx(HeaderProvider, { value: { unresponsive, fluid, hideRegionPicker: true, regionPickerText: "" }, children: jsxs("header", { className: clsx("ids-header-inera-admin", {
22
18
  "ids-header-inera-admin--unresponsive": unresponsive,
23
19
  "ids-header-inera-admin--fluid": fluid
24
- }, className), children: [skipToContent && (jsx("div", { className: "ids-header-inera-admin__skip-to-content", children: skipToContent })), jsxs("div", { className: "ids-header-inera-admin__inner", children: [jsxs("div", { className: "ids-header-inera-admin__service-wrapper", children: [renderBrandText(), jsx("h2", { className: "ids-header-inera-admin__service-name", children: serviceName })] }), jsxs("div", { className: "ids-header-inera-admin__items", children: [items, " ", avatar, " ", mobileMenu] })] }), children] }) }));
20
+ }, className), children: [skipToContent && jsx("div", { className: "ids-header-inera-admin__skip-to-content", children: skipToContent }), jsxs("div", { className: "ids-header-inera-admin__inner", children: [jsx("div", { className: "ids-header-inera-admin__service-wrapper", children: jsxs("div", { className: "ids-header-inera-admin__brand", children: [showLogo && jsx("div", { className: "ids-header-inera-admin__logo", "aria-label": "Logotyp inera" }), jsxs("div", { className: "ids-header-inera-admin__brand-inner", children: [renderBrandText(), jsx("h1", { className: "ids-header-inera-admin__brand-text", children: brandText }), jsx("h2", { className: "ids-header-inera-admin__service-name", children: serviceName })] })] }) }), jsxs("div", { className: "ids-header-inera-admin__items", children: [items, " ", avatar, " ", mobileMenu] })] }), children] }) }));
25
21
  };
26
22
 
27
23
  export { IDSHeaderIneraAdmin };
@@ -3,6 +3,7 @@ import "@inera/ids-design/components/tabs/tabs.css";
3
3
  import { IDSTabProps } from "./tab";
4
4
  interface IDSTabsProps extends React.HTMLAttributes<HTMLDivElement> {
5
5
  unresponsive?: boolean;
6
+ light?: boolean;
6
7
  compact?: boolean;
7
8
  breakpoint?: "m" | "s";
8
9
  selectLabel?: string;
@@ -6,7 +6,7 @@ import '@inera/ids-design/components/tabs/tabs.css';
6
6
  import { useElementId } from '../utils/hooks/useElementId.js';
7
7
  import clsx from 'clsx';
8
8
 
9
- const IDSTabs = ({ unresponsive = false, compact = false, breakpoint = "m", selectLabel = "", tabs = [], children, className, onTabChange }) => {
9
+ const IDSTabs = ({ unresponsive = false, light = false, compact = false, breakpoint = "m", selectLabel = "", tabs = [], children, className, onTabChange }) => {
10
10
  const tabsId = useElementId();
11
11
  const initialSelectedIndex = tabs.findIndex(tab => React__default.isValidElement(tab) && tab.props.selected === true);
12
12
  const [activeTab, setActiveTab] = useState(initialSelectedIndex !== -1 ? initialSelectedIndex : 0);
@@ -68,14 +68,28 @@ const IDSTabs = ({ unresponsive = false, compact = false, breakpoint = "m", sele
68
68
  handleSelect(index);
69
69
  };
70
70
  const renderTabOptions = () => tabs?.map((tab, i) => {
71
- const label = React__default.isValidElement(tab) ? tab.props.label || `Tab ${i + 1}` : `Tab ${i + 1}`;
72
- return (jsx("option", { value: i, children: label }, i));
71
+ if (!React__default.isValidElement(tab))
72
+ return null;
73
+ const { label, notification } = tab.props;
74
+ let notificationText = "";
75
+ if (typeof notification === "string" || typeof notification === "number") {
76
+ notificationText = String(notification);
77
+ }
78
+ else if (React__default.isValidElement(notification)) {
79
+ const badge = notification;
80
+ const childTexts = React__default.Children.toArray(badge.props.children)
81
+ .map(child => (typeof child === "string" || typeof child === "number" ? child : ""))
82
+ .join("");
83
+ notificationText = childTexts.trim();
84
+ }
85
+ const optionLabel = notificationText ? `${label} (${notificationText})` : label;
86
+ return (jsx("option", { value: i, children: optionLabel }, i));
73
87
  });
74
88
  return (jsxs("div", { className: clsx("ids-tabs", {
75
89
  "ids-tabs--unresponsive": unresponsive,
76
90
  "ids-tabs--responsive-on-m": responsiveOnM,
77
91
  "ids-tabs--responsive-on-s": responsiveOnS
78
- }, className), children: [jsx("div", { className: "ids-tabs__select", children: jsx(IDSSelect, { label: selectLabel, onChange: tabChangedFromSelect, value: activeTab, children: renderTabOptions() }) }), jsx("div", { className: "ids-tabs__tabs", role: "tablist", children: enhancedTabs }), jsx("div", { className: "ids-tabs__panels", children: enhancedTabPanels })] }));
92
+ }, className), children: [jsx("div", { className: "ids-tabs__select", children: jsx(IDSSelect, { label: selectLabel, onChange: tabChangedFromSelect, value: activeTab, light: light, children: renderTabOptions() }) }), jsx("div", { className: "ids-tabs__tabs", role: "tablist", children: enhancedTabs }), jsx("div", { className: "ids-tabs__panels", children: enhancedTabPanels })] }));
79
93
  };
80
94
 
81
95
  export { IDSTabs };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@inera/ids-react",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
6
  "react": "*"
7
7
  },
8
8
  "dependencies": {
9
- "@inera/ids-core": "7.1.x",
9
+ "@inera/ids-core": "7.2.x",
10
10
  "@lit-labs/react": "^1.1.0",
11
11
  "clsx": "*"
12
12
  },