@trackunit/react-form-components 1.0.5 → 1.0.8

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/index.cjs.js CHANGED
@@ -1369,6 +1369,7 @@ const cvaRadioGroup = cssClassVarianceUtilities.cvaMerge(["flex", "gap-2", "flex
1369
1369
  },
1370
1370
  });
1371
1371
  const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
1372
+ "self-center",
1372
1373
  "w-4",
1373
1374
  "h-4",
1374
1375
  "appearance-none",
@@ -1384,7 +1385,6 @@ const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
1384
1385
  "hover:cursor-pointer",
1385
1386
  "hover:bg-slate-100",
1386
1387
  "focus-visible:outline-primary-700",
1387
- "mt-1",
1388
1388
  ], {
1389
1389
  variants: {
1390
1390
  checked: {
@@ -1432,22 +1432,14 @@ const cvaRadioItem = cssClassVarianceUtilities.cvaMerge([
1432
1432
  ],
1433
1433
  });
1434
1434
  const cvaRadioItemWrapper = cssClassVarianceUtilities.cvaMerge([
1435
- "gap-2",
1435
+ "grid-rows-subgrid", //* Children align to this parent grid
1436
+ "grid-cols-min-fr", //* explicit horizontal placement for input and label/description
1437
+ "auto-rows-auto", //* optional extra rows (suffix) will be auto-sized
1436
1438
  "group",
1437
1439
  "grid",
1438
- "grid-cols-min-fr",
1439
- "has-[:nth-child(3)]:grid-cols-min-fr-min", //if there's 3 children
1440
+ "gap-x-2",
1440
1441
  ]);
1441
- const cvaRadioItemDescription = cssClassVarianceUtilities.cvaMerge([
1442
- "-mt-1",
1443
- "text-sm",
1444
- "font-normal",
1445
- "text-slate-500",
1446
- "text-left",
1447
- "whitespace-nowrap",
1448
- "text-ellipsis",
1449
- "overflow-hidden",
1450
- ], {
1442
+ const cvaRadioItemDescription = cssClassVarianceUtilities.cvaMerge(["text-sm", "font-normal", "text-slate-500", "text-left", "whitespace-nowrap", "text-ellipsis", "overflow-hidden"], {
1451
1443
  variants: {
1452
1444
  disabled: {
1453
1445
  true: ["text-slate-400", "hover:text-slate-400", "group-hover:text-slate-400"],
@@ -1455,6 +1447,9 @@ const cvaRadioItemDescription = cssClassVarianceUtilities.cvaMerge([
1455
1447
  },
1456
1448
  },
1457
1449
  });
1450
+ const cvaLabelTooltip = cssClassVarianceUtilities.cvaMerge(["col-start-2", "w-full", "self-center"]);
1451
+ const cvaDescriptionTooltip = cssClassVarianceUtilities.cvaMerge(["col-span-2", "col-start-2", "row-start-2", "w-full"]);
1452
+ const cvaSuffixContainer = cssClassVarianceUtilities.cvaMerge(["flex", "col-start-3", "items-center"]);
1458
1453
 
1459
1454
  const RadioGroupContext = React__namespace.createContext(null);
1460
1455
 
@@ -1489,20 +1484,22 @@ RadioGroup.displayName = "RadioGroup";
1489
1484
  * @returns {JSX.Element} RadioItem component
1490
1485
  */
1491
1486
  const RadioItem = ({ label, value, dataTestId, className, description, suffix, ...rest }) => {
1492
- const groupCtx = React__namespace.useContext(RadioGroupContext);
1487
+ const groupCtx = React.useContext(RadioGroupContext);
1493
1488
  const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
1494
- const labelRef = React__namespace.useRef(null);
1495
- const descriptionRef = React__namespace.useRef(null);
1489
+ const labelRef = React.useRef(null);
1490
+ const descriptionRef = React.useRef(null);
1496
1491
  const labelTextIsCutOff = reactComponents.useIsTextCutOff(labelRef.current);
1497
1492
  const descriptionTextIsCutOff = reactComponents.useIsTextCutOff(descriptionRef.current);
1498
- return (jsxRuntime.jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : null, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, children: [jsxRuntime.jsx("input", { checked: isChecked, className: cvaRadioItem({
1493
+ const descriptionId = description ? `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}-description` : undefined;
1494
+ const inputId = `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`;
1495
+ return (jsxRuntime.jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : undefined, htmlFor: inputId, children: [jsxRuntime.jsx("input", { "aria-describedby": descriptionId, checked: isChecked, className: cvaRadioItem({
1499
1496
  checked: isChecked,
1500
1497
  disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1501
1498
  invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1502
- }), "data-testid": dataTestId, id: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value, ...rest }), jsxRuntime.jsxs("div", { className: "flex flex-col", children: [jsxRuntime.jsx(reactComponents.Tooltip, { className: "w-full", disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsxRuntime.jsx("label", { className: cvaLabel({
1503
- invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1504
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1505
- }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, ref: labelRef, children: label }) }, "tooltip-" + rest.name), description ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: "w-full", disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsxRuntime.jsx("label", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : null, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null, suffix] })] }));
1499
+ }), "data-testid": dataTestId, id: inputId, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value, ...rest }), jsxRuntime.jsx(reactComponents.Tooltip, { className: cvaLabelTooltip(), dataTestId: dataTestId ? `${dataTestId}-Label-Tooltip` : undefined, disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsxRuntime.jsx("span", { className: cvaLabel({
1500
+ invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1501
+ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1502
+ }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, ref: labelRef, children: label }) }, "tooltip-" + rest.name), suffix ? (jsxRuntime.jsx("div", { className: cvaSuffixContainer(), "data-testid": dataTestId ? `${dataTestId}-suffix-container` : undefined, children: suffix })) : null, description ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: cvaDescriptionTooltip(), dataTestId: dataTestId ? `${dataTestId}-Description-Tooltip` : undefined, disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsxRuntime.jsx("span", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : undefined, id: descriptionId, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null] }));
1506
1503
  };
1507
1504
 
1508
1505
  const cvaTimeRange = cssClassVarianceUtilities.cvaMerge([
package/index.esm.js CHANGED
@@ -4,7 +4,7 @@ import { IconButton, Icon, Tooltip, useIsTextCutOff, Heading, Text, Spinner, Men
4
4
  import { useCopyToClipboard } from 'usehooks-ts';
5
5
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
6
6
  import * as React from 'react';
7
- import React__default, { isValidElement, forwardRef, useMemo, useState, useCallback, useRef, cloneElement, useEffect, useImperativeHandle } from 'react';
7
+ import React__default, { isValidElement, forwardRef, useMemo, useState, useCallback, useRef, cloneElement, useEffect, useContext, useImperativeHandle } from 'react';
8
8
  import { uuidv4, nonNullable } from '@trackunit/shared-utils';
9
9
  import { Temporal } from '@js-temporal/polyfill';
10
10
  import parsePhoneNumberFromString, { isSupportedCountry, getCountries, getCountryCallingCode, AsYouType, parseIncompletePhoneNumber, isValidPhoneNumber } from 'libphonenumber-js';
@@ -1350,6 +1350,7 @@ const cvaRadioGroup = cvaMerge(["flex", "gap-2", "flex-col", "items-start"], {
1350
1350
  },
1351
1351
  });
1352
1352
  const cvaRadioItem = cvaMerge([
1353
+ "self-center",
1353
1354
  "w-4",
1354
1355
  "h-4",
1355
1356
  "appearance-none",
@@ -1365,7 +1366,6 @@ const cvaRadioItem = cvaMerge([
1365
1366
  "hover:cursor-pointer",
1366
1367
  "hover:bg-slate-100",
1367
1368
  "focus-visible:outline-primary-700",
1368
- "mt-1",
1369
1369
  ], {
1370
1370
  variants: {
1371
1371
  checked: {
@@ -1413,22 +1413,14 @@ const cvaRadioItem = cvaMerge([
1413
1413
  ],
1414
1414
  });
1415
1415
  const cvaRadioItemWrapper = cvaMerge([
1416
- "gap-2",
1416
+ "grid-rows-subgrid", //* Children align to this parent grid
1417
+ "grid-cols-min-fr", //* explicit horizontal placement for input and label/description
1418
+ "auto-rows-auto", //* optional extra rows (suffix) will be auto-sized
1417
1419
  "group",
1418
1420
  "grid",
1419
- "grid-cols-min-fr",
1420
- "has-[:nth-child(3)]:grid-cols-min-fr-min", //if there's 3 children
1421
+ "gap-x-2",
1421
1422
  ]);
1422
- const cvaRadioItemDescription = cvaMerge([
1423
- "-mt-1",
1424
- "text-sm",
1425
- "font-normal",
1426
- "text-slate-500",
1427
- "text-left",
1428
- "whitespace-nowrap",
1429
- "text-ellipsis",
1430
- "overflow-hidden",
1431
- ], {
1423
+ const cvaRadioItemDescription = cvaMerge(["text-sm", "font-normal", "text-slate-500", "text-left", "whitespace-nowrap", "text-ellipsis", "overflow-hidden"], {
1432
1424
  variants: {
1433
1425
  disabled: {
1434
1426
  true: ["text-slate-400", "hover:text-slate-400", "group-hover:text-slate-400"],
@@ -1436,6 +1428,9 @@ const cvaRadioItemDescription = cvaMerge([
1436
1428
  },
1437
1429
  },
1438
1430
  });
1431
+ const cvaLabelTooltip = cvaMerge(["col-start-2", "w-full", "self-center"]);
1432
+ const cvaDescriptionTooltip = cvaMerge(["col-span-2", "col-start-2", "row-start-2", "w-full"]);
1433
+ const cvaSuffixContainer = cvaMerge(["flex", "col-start-3", "items-center"]);
1439
1434
 
1440
1435
  const RadioGroupContext = React.createContext(null);
1441
1436
 
@@ -1470,20 +1465,22 @@ RadioGroup.displayName = "RadioGroup";
1470
1465
  * @returns {JSX.Element} RadioItem component
1471
1466
  */
1472
1467
  const RadioItem = ({ label, value, dataTestId, className, description, suffix, ...rest }) => {
1473
- const groupCtx = React.useContext(RadioGroupContext);
1468
+ const groupCtx = useContext(RadioGroupContext);
1474
1469
  const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
1475
- const labelRef = React.useRef(null);
1476
- const descriptionRef = React.useRef(null);
1470
+ const labelRef = useRef(null);
1471
+ const descriptionRef = useRef(null);
1477
1472
  const labelTextIsCutOff = useIsTextCutOff(labelRef.current);
1478
1473
  const descriptionTextIsCutOff = useIsTextCutOff(descriptionRef.current);
1479
- return (jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : null, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, children: [jsx("input", { checked: isChecked, className: cvaRadioItem({
1474
+ const descriptionId = description ? `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}-description` : undefined;
1475
+ const inputId = `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`;
1476
+ return (jsxs("label", { className: cvaRadioItemWrapper({ className }), "data-testid": dataTestId ? `${dataTestId}-Wrapper` : undefined, htmlFor: inputId, children: [jsx("input", { "aria-describedby": descriptionId, checked: isChecked, className: cvaRadioItem({
1480
1477
  checked: isChecked,
1481
1478
  disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1482
1479
  invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1483
- }), "data-testid": dataTestId, id: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value, ...rest }), jsxs("div", { className: "flex flex-col", children: [jsx(Tooltip, { className: "w-full", disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsx("label", { className: cvaLabel({
1484
- invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1485
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1486
- }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, ref: labelRef, children: label }) }, "tooltip-" + rest.name), description ? (jsx(Tooltip, { className: "w-full", disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsx("label", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : null, htmlFor: `${groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.id}-${value}`, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null, suffix] })] }));
1480
+ }), "data-testid": dataTestId, id: inputId, onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange, type: "radio", value: value, ...rest }), jsx(Tooltip, { className: cvaLabelTooltip(), dataTestId: dataTestId ? `${dataTestId}-Label-Tooltip` : undefined, disabled: !labelTextIsCutOff, label: label, placement: "top", children: jsx("span", { className: cvaLabel({
1481
+ invalid: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
1482
+ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
1483
+ }), "data-testid": dataTestId ? `${dataTestId}-Label` : undefined, ref: labelRef, children: label }) }, "tooltip-" + rest.name), suffix ? (jsx("div", { className: cvaSuffixContainer(), "data-testid": dataTestId ? `${dataTestId}-suffix-container` : undefined, children: suffix })) : null, description ? (jsx(Tooltip, { className: cvaDescriptionTooltip(), dataTestId: dataTestId ? `${dataTestId}-Description-Tooltip` : undefined, disabled: !descriptionTextIsCutOff, label: description, placement: "top", children: jsx("span", { className: cvaRadioItemDescription({ disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled }), "data-testid": dataTestId ? `${dataTestId}-Description` : undefined, id: descriptionId, ref: descriptionRef, children: description }) }, "description-tooltip-" + rest.name)) : null] }));
1487
1484
  };
1488
1485
 
1489
1486
  const cvaTimeRange = cvaMerge([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -18,7 +18,7 @@
18
18
  "react-hook-form": "7.53.1",
19
19
  "tailwind-merge": "^2.0.0",
20
20
  "@trackunit/css-class-variance-utilities": "^1.0.1",
21
- "@trackunit/react-components": "^1.0.5",
21
+ "@trackunit/react-components": "^1.0.8",
22
22
  "@trackunit/ui-icons": "^1.0.1",
23
23
  "@trackunit/shared-utils": "^1.0.2",
24
24
  "@trackunit/i18n-library-translation": "^1.0.3"
@@ -10,3 +10,6 @@ export declare const cvaRadioItemWrapper: (props?: import("class-variance-author
10
10
  export declare const cvaRadioItemDescription: (props?: ({
11
11
  disabled?: boolean | null | undefined;
12
12
  } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
13
+ export declare const cvaLabelTooltip: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
14
+ export declare const cvaDescriptionTooltip: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
15
+ export declare const cvaSuffixContainer: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
@@ -1,11 +1,11 @@
1
1
  import { CommonProps } from "@trackunit/react-components";
2
2
  import { MappedOmit } from "@trackunit/shared-utils";
3
- import * as React from "react";
4
- export interface RadioItemProps<V extends string | number = string> extends CommonProps, MappedOmit<React.InputHTMLAttributes<HTMLInputElement>, "prefix"> {
3
+ import { InputHTMLAttributes, ReactNode } from "react";
4
+ export interface RadioItemProps<V extends string | number = string> extends CommonProps, MappedOmit<InputHTMLAttributes<HTMLInputElement>, "prefix"> {
5
5
  /**
6
6
  * The label of the radio item.
7
7
  */
8
- label: React.ReactNode;
8
+ label: ReactNode;
9
9
  /**
10
10
  * The value of the radio item.
11
11
  */
@@ -17,7 +17,7 @@ export interface RadioItemProps<V extends string | number = string> extends Comm
17
17
  /**
18
18
  * An element to display after the label
19
19
  */
20
- suffix?: React.ReactNode;
20
+ suffix?: ReactNode;
21
21
  }
22
22
  /**
23
23
  * The RadioItem component.