@idds/react 1.3.5 → 1.4.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.
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import React, { createContext, useRef, useState, useCallback, useMemo, useContext, useEffect, forwardRef, createElement, Fragment as Fragment$1, useId, useImperativeHandle } from "react";
2
+ import React, { createContext, useRef, useState, useCallback, useMemo, useContext, useId, useEffect, forwardRef, createElement, Fragment as Fragment$1, useImperativeHandle } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
  const iddsColorTokens = {
5
5
  // Neutral Colors
@@ -645,9 +645,8 @@ function Accordion(props) {
645
645
  } = props;
646
646
  const [internalOpen, setInternalOpen] = useState(defaultOpen);
647
647
  const accordionGroup = useAccordionGroup();
648
- const itemIdRef = useRef(
649
- `accordion-${Math.random().toString(36).substr(2, 9)}`
650
- );
648
+ const generatedId = useId().replace(/:/g, "-");
649
+ const itemIdRef = useRef(`accordion-${generatedId}`);
651
650
  const [itemIndex, setItemIndex] = useState(-1);
652
651
  const defaultOpenRef = useRef(defaultOpen);
653
652
  defaultOpenRef.current = defaultOpen;
@@ -2096,6 +2095,7 @@ function TextField({
2096
2095
  "input",
2097
2096
  {
2098
2097
  ...rest,
2098
+ id: (rest == null ? void 0 : rest.id) || (rest == null ? void 0 : rest.name) ? String((rest == null ? void 0 : rest.id) || (rest == null ? void 0 : rest.name)) : String(label).toLowerCase(),
2099
2099
  type: rest.type ?? "text",
2100
2100
  className: clsx("ina-text-field__input", className),
2101
2101
  value: inner,
@@ -3294,10 +3294,18 @@ function FieldInputTable({
3294
3294
  const containerClasses = clsx("ina-field-input-table", className);
3295
3295
  return /* @__PURE__ */ jsxs("div", { className: containerClasses, children: [
3296
3296
  /* @__PURE__ */ jsxs("div", { className: "ina-field-input-table__wrapper", children: [
3297
- /* @__PURE__ */ jsx("label", { className: "ina-field-input-table__label", children: placeholder }),
3297
+ /* @__PURE__ */ jsx(
3298
+ "label",
3299
+ {
3300
+ className: "ina-field-input-table__label",
3301
+ htmlFor: "field-input-table-input",
3302
+ children: placeholder
3303
+ }
3304
+ ),
3298
3305
  /* @__PURE__ */ jsx(
3299
3306
  "input",
3300
3307
  {
3308
+ id: "field-input-table-input",
3301
3309
  type: "text",
3302
3310
  className: "ina-field-input-table__input",
3303
3311
  value,
@@ -4520,7 +4528,8 @@ function Drawer({
4520
4528
  if (!isOpen || !mounted) return null;
4521
4529
  const containerClasses = clsx(
4522
4530
  "ina-drawer",
4523
- `ina-drawer--position-${position}`
4531
+ `ina-drawer--position-${position}`,
4532
+ className
4524
4533
  );
4525
4534
  const panelClasses = clsx(
4526
4535
  "ina-drawer__panel",
@@ -4579,7 +4588,7 @@ function Drawer({
4579
4588
  "div",
4580
4589
  {
4581
4590
  onClick: (e) => e.stopPropagation(),
4582
- className: clsx(panelClasses, className),
4591
+ className: panelClasses,
4583
4592
  style: panelStyle,
4584
4593
  children: [
4585
4594
  position !== "top" && /* @__PURE__ */ jsxs("div", { className: headerClasses, children: [
@@ -5168,13 +5177,21 @@ function TextArea({
5168
5177
  );
5169
5178
  const bottomText = status !== "neutral" && statusMessage != null ? statusMessage : helperText;
5170
5179
  return /* @__PURE__ */ jsxs("div", { className: containerClasses, children: [
5171
- label && /* @__PURE__ */ jsx("label", { className: "ina-text-area__label", children: label }),
5180
+ label && /* @__PURE__ */ jsx(
5181
+ "label",
5182
+ {
5183
+ className: "ina-text-area__label",
5184
+ htmlFor: (rest == null ? void 0 : rest.id) || (rest == null ? void 0 : rest.name) ? String((rest == null ? void 0 : rest.id) || (rest == null ? void 0 : rest.name)) : String(label).toLowerCase(),
5185
+ children: label
5186
+ }
5187
+ ),
5172
5188
  /* @__PURE__ */ jsxs("div", { className: wrapperClasses, children: [
5173
5189
  prefixIcon && /* @__PURE__ */ jsx("div", { className: "ina-text-area__prefix-icon", children: prefixIcon }),
5174
5190
  /* @__PURE__ */ jsx(
5175
5191
  "textarea",
5176
5192
  {
5177
5193
  ...rest,
5194
+ id: (rest == null ? void 0 : rest.id) || (rest == null ? void 0 : rest.name) ? String((rest == null ? void 0 : rest.id) || (rest == null ? void 0 : rest.name)) : String(label).toLowerCase(),
5178
5195
  ref: taRef,
5179
5196
  rows,
5180
5197
  className: "ina-text-area__input",
@@ -8128,52 +8145,42 @@ function YearPicker({
8128
8145
  useEffect(() => {
8129
8146
  if (isOpen && triggerRef.current) {
8130
8147
  const calculatePosition = () => {
8148
+ var _a;
8131
8149
  if (!triggerRef.current || !panelRef.current) return;
8132
8150
  const triggerRect = triggerRef.current.getBoundingClientRect();
8133
8151
  const panelRect = panelRef.current.getBoundingClientRect();
8134
8152
  const viewportWidth = window.innerWidth;
8135
8153
  const viewportHeight = window.innerHeight;
8136
- const defaultPanelWidth = 320;
8154
+ const isMobile = viewportWidth <= 640;
8155
+ const defaultPanelWidth = isMobile ? 200 : 320;
8137
8156
  const panelWidthValue = panelRect.width || defaultPanelWidth;
8138
8157
  const availableSpaceRight = viewportWidth - triggerRect.right;
8139
- const isMobile = viewportWidth <= 640;
8140
8158
  let left = void 0;
8141
8159
  let right = void 0;
8142
8160
  let shouldUseRight = false;
8143
8161
  if (isMobile) {
8144
- const threshold = 16;
8145
- const triggerCenter = triggerRect.left + triggerRect.width / 2;
8146
- const viewportCenter = viewportWidth / 2;
8147
- if (triggerRect.right > viewportWidth - threshold) {
8148
- shouldUseRight = true;
8149
- right = viewportWidth - triggerRect.right;
8150
- left = void 0;
8151
- } else if (triggerRect.left < threshold) {
8152
- shouldUseRight = false;
8153
- left = triggerRect.left;
8154
- right = void 0;
8155
- } else if (Math.abs(triggerCenter - viewportCenter) < panelWidthValue / 2) {
8156
- const panelLeft = triggerRect.left - (panelWidthValue - triggerRect.width) / 2;
8157
- if (panelLeft < 0) {
8158
- left = 0;
8159
- right = void 0;
8160
- } else if (panelLeft + panelWidthValue > viewportWidth) {
8161
- right = 0;
8162
- left = void 0;
8163
- } else {
8164
- left = panelLeft;
8165
- right = void 0;
8162
+ const panelCenterX = viewportWidth / 2;
8163
+ const panelLeftFromViewport = panelCenterX - panelWidthValue / 2;
8164
+ const containerRect = (_a = containerRef.current) == null ? void 0 : _a.getBoundingClientRect();
8165
+ if (containerRect) {
8166
+ let calculatedLeft = panelLeftFromViewport - containerRect.left;
8167
+ if (calculatedLeft < 0) {
8168
+ calculatedLeft = 0;
8169
+ }
8170
+ const panelRightInViewport = containerRect.left + calculatedLeft + panelWidthValue;
8171
+ if (panelRightInViewport > viewportWidth) {
8172
+ calculatedLeft = viewportWidth - panelWidthValue - containerRect.left;
8173
+ if (calculatedLeft < 0) {
8174
+ calculatedLeft = 0;
8175
+ }
8166
8176
  }
8177
+ left = calculatedLeft;
8178
+ right = void 0;
8167
8179
  shouldUseRight = false;
8168
8180
  } else {
8169
- shouldUseRight = panelWidthValue > availableSpaceRight;
8170
- if (shouldUseRight) {
8171
- right = viewportWidth - triggerRect.right;
8172
- left = void 0;
8173
- } else {
8174
- left = triggerRect.left;
8175
- right = void 0;
8176
- }
8181
+ left = Math.max(0, panelLeftFromViewport);
8182
+ right = void 0;
8183
+ shouldUseRight = false;
8177
8184
  }
8178
8185
  } else {
8179
8186
  shouldUseRight = panelWidthValue > availableSpaceRight;
@@ -8483,6 +8490,7 @@ function MonthPicker({
8483
8490
  useEffect(() => {
8484
8491
  if (isOpen && triggerRef.current) {
8485
8492
  const calculatePosition = () => {
8493
+ var _a;
8486
8494
  if (!triggerRef.current || !panelRef.current) return;
8487
8495
  const triggerRect = triggerRef.current.getBoundingClientRect();
8488
8496
  const panelRect = panelRef.current.getBoundingClientRect();
@@ -8496,39 +8504,28 @@ function MonthPicker({
8496
8504
  let right = void 0;
8497
8505
  let shouldUseRight = false;
8498
8506
  if (isMobile) {
8499
- const threshold = 16;
8500
- const triggerCenter = triggerRect.left + triggerRect.width / 2;
8501
- const viewportCenter = viewportWidth / 2;
8502
- if (triggerRect.right > viewportWidth - threshold) {
8503
- shouldUseRight = true;
8504
- right = viewportWidth - triggerRect.right;
8505
- left = void 0;
8506
- } else if (triggerRect.left < threshold) {
8507
- shouldUseRight = false;
8508
- left = triggerRect.left;
8509
- right = void 0;
8510
- } else if (Math.abs(triggerCenter - viewportCenter) < panelWidthValue / 2) {
8511
- const panelLeft = triggerRect.left - (panelWidthValue - triggerRect.width) / 2;
8512
- if (panelLeft < 0) {
8513
- left = 0;
8514
- right = void 0;
8515
- } else if (panelLeft + panelWidthValue > viewportWidth) {
8516
- right = 0;
8517
- left = void 0;
8518
- } else {
8519
- left = panelLeft;
8520
- right = void 0;
8507
+ const panelCenterX = viewportWidth / 2;
8508
+ const panelLeftFromViewport = panelCenterX - panelWidthValue / 2;
8509
+ const containerRect = (_a = containerRef.current) == null ? void 0 : _a.getBoundingClientRect();
8510
+ if (containerRect) {
8511
+ let calculatedLeft = panelLeftFromViewport - containerRect.left;
8512
+ if (calculatedLeft < 0) {
8513
+ calculatedLeft = 0;
8514
+ }
8515
+ const panelRightInViewport = containerRect.left + calculatedLeft + panelWidthValue;
8516
+ if (panelRightInViewport > viewportWidth) {
8517
+ calculatedLeft = viewportWidth - panelWidthValue - containerRect.left;
8518
+ if (calculatedLeft < 0) {
8519
+ calculatedLeft = 0;
8520
+ }
8521
8521
  }
8522
+ left = calculatedLeft;
8523
+ right = void 0;
8522
8524
  shouldUseRight = false;
8523
8525
  } else {
8524
- shouldUseRight = panelWidthValue > availableSpaceRight;
8525
- if (shouldUseRight) {
8526
- right = viewportWidth - triggerRect.right;
8527
- left = void 0;
8528
- } else {
8529
- left = triggerRect.left;
8530
- right = void 0;
8531
- }
8526
+ left = Math.max(0, panelLeftFromViewport);
8527
+ right = void 0;
8528
+ shouldUseRight = false;
8532
8529
  }
8533
8530
  } else {
8534
8531
  shouldUseRight = panelWidthValue > availableSpaceRight;
@@ -8793,7 +8790,7 @@ function DatePicker({
8793
8790
  popperPlacement = "bottom-start",
8794
8791
  dateFormat = "dd/MM/yyyy",
8795
8792
  className = "",
8796
- triggerWidth = "100%",
8793
+ triggerWidth = "",
8797
8794
  panelMaxHeight,
8798
8795
  panelClassName = "",
8799
8796
  triggerClassname = "",
@@ -9793,22 +9790,30 @@ function MultipleChoiceGrid({
9793
9790
  "div",
9794
9791
  {
9795
9792
  className: "ina-multiple-choice-grid__cell",
9796
- children: /* @__PURE__ */ jsxs("label", { className: "ina-multiple-choice-grid__radio-label", children: [
9797
- /* @__PURE__ */ jsx(
9798
- "input",
9799
- {
9800
- type: "radio",
9801
- name: `${name}-${row.id}`,
9802
- value: column.id,
9803
- checked: isSelected(row.id, column.id),
9804
- onChange: handleRadioChange,
9805
- disabled,
9806
- className: "ina-multiple-choice-grid__radio-input",
9807
- "aria-label": `${row.label} ${column.label}`
9808
- }
9809
- ),
9810
- /* @__PURE__ */ jsx("span", { className: "ina-multiple-choice-grid__radio-custom" })
9811
- ] })
9793
+ children: /* @__PURE__ */ jsxs(
9794
+ "label",
9795
+ {
9796
+ className: "ina-multiple-choice-grid__radio-label",
9797
+ htmlFor: `${name}-${row.id}-${column.id}`,
9798
+ children: [
9799
+ /* @__PURE__ */ jsx(
9800
+ "input",
9801
+ {
9802
+ id: `${name}-${row.id}-${column.id}`,
9803
+ type: "radio",
9804
+ name: `${name}-${row.id}`,
9805
+ value: column.id,
9806
+ checked: isSelected(row.id, column.id),
9807
+ onChange: handleRadioChange,
9808
+ disabled,
9809
+ className: "ina-multiple-choice-grid__radio-input",
9810
+ "aria-label": `${row.label} ${column.label}`
9811
+ }
9812
+ ),
9813
+ /* @__PURE__ */ jsx("span", { className: "ina-multiple-choice-grid__radio-custom" })
9814
+ ]
9815
+ }
9816
+ )
9812
9817
  },
9813
9818
  `${row.id}-${column.id}`
9814
9819
  ))