@trackunit/react-components 0.0.74-alpha-f1247b22d.0 → 0.0.74

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.
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { CommonProps } from "../../common/CommonProps";
3
- interface RadioGroupProps extends CommonProps {
3
+ export interface RadioGroupProps extends CommonProps, React.InputHTMLAttributes<HTMLInputElement> {
4
4
  /**
5
5
  */
6
6
  children: React.ReactNode;
@@ -32,12 +32,25 @@ interface RadioGroupProps extends CommonProps {
32
32
  * Whether the radio group is disabled or not.
33
33
  */
34
34
  disabled?: boolean;
35
+ /**
36
+ * An boolean flag to set invalid mode
37
+ * can be used for handling errors
38
+ */
39
+ isInvalid?: boolean;
35
40
  }
36
41
  /**
37
- * The RadioGroup component.
42
+ * Use radio buttons when you have a group of mutually exclusive choices and only one selection from the group is allowed.
43
+ *
44
+ * Radio buttons are used for mutually exclusive choices, not for multiple choices. Only one radio button can be selected at a time. When a user chooses a new item, the previous choice is automatically deselected.
45
+ *
46
+ * _**Do use** Radio buttons in forms, settings, or selections in a list._
47
+ *
48
+ * _**Do not use** Radio buttons if a user can select many option from a list, use checkboxes instead of radio buttons._
38
49
  *
39
50
  * @param {RadioGroupProps} props - The props for the RadioGroup component
40
51
  * @returns {JSX.Element} RadioGroup component
41
52
  */
42
- export declare const RadioGroup: ({ children, id, name, value, disabled, onChange, label, inline, className, dataTestId, }: RadioGroupProps) => JSX.Element;
43
- export {};
53
+ export declare const RadioGroup: {
54
+ ({ children, id, name, value, disabled, onChange, label, inline, className, dataTestId, isInvalid, }: RadioGroupProps): JSX.Element;
55
+ displayName: string;
56
+ };
@@ -4,6 +4,7 @@ interface RadioGroupContextProps {
4
4
  name: string;
5
5
  value: string | number;
6
6
  disabled?: boolean;
7
+ isInvalid?: boolean;
7
8
  onChange: (e: React.FormEvent<HTMLInputElement>) => void;
8
9
  }
9
10
  export declare const RadioGroupContext: React.Context<RadioGroupContextProps | null>;
@@ -9,6 +9,10 @@ interface RadioItemProps extends CommonProps {
9
9
  * The value of the radio item.
10
10
  */
11
11
  value: string | number;
12
+ /**
13
+ * The description of the radio item.
14
+ */
15
+ description?: string;
12
16
  }
13
17
  /**
14
18
  * The RadioItem component.
@@ -16,5 +20,5 @@ interface RadioItemProps extends CommonProps {
16
20
  * @param {RadioItemProps} props - The props for the RadioItem component
17
21
  * @returns {JSX.Element} RadioItem component
18
22
  */
19
- export declare const RadioItem: ({ label, value, dataTestId, className }: RadioItemProps) => JSX.Element;
23
+ export declare const RadioItem: ({ label, value, dataTestId, className, description }: RadioItemProps) => JSX.Element;
20
24
  export {};
package/index.js CHANGED
@@ -649,7 +649,7 @@ const Alert = ({
649
649
  weight: "bold"
650
650
  }, {
651
651
  children: title !== null && title !== void 0 ? title : children
652
- })), children && jsx(Description$1, Object.assign({
652
+ })), children && jsx(Description$2, Object.assign({
653
653
  weight: !title ? "bold" : "default",
654
654
  "$hasTitle": !!title
655
655
  }, {
@@ -660,7 +660,7 @@ const Alert = ({
660
660
  weight: "bold"
661
661
  }, {
662
662
  children: title !== null && title !== void 0 ? title : children
663
- })), children && jsx(Description$1, Object.assign({
663
+ })), children && jsx(Description$2, Object.assign({
664
664
  weight: !title ? "bold" : "default",
665
665
  "$hasTitle": !!title
666
666
  }, {
@@ -749,7 +749,7 @@ const Container$7 = tw.div`
749
749
  const Content$2 = tw.div`
750
750
  ${p => p.$inline ? tws`tu-alert__content--inline` : tws`tu-alert__content`}
751
751
  `;
752
- const Description$1 = tw(Text)`
752
+ const Description$2 = tw(Text)`
753
753
  ${p => p.$hasTitle ? tws`tu-alert__description` : null}
754
754
  `;
755
755
  const RightAligned = tw.div`
@@ -1502,7 +1502,7 @@ const Checkbox = React.forwardRef((_a, ref) => {
1502
1502
  onKeyPress: onKeyPress
1503
1503
  }, {
1504
1504
  children: icon
1505
- })), label && jsx(Label$4, Object.assign({
1505
+ })), label && jsx(Label$5, Object.assign({
1506
1506
  ref: internalRef,
1507
1507
  htmlFor: uuid,
1508
1508
  "$disabled": isReadonly,
@@ -1550,7 +1550,7 @@ const HiddenInput$1 = tw.input`
1550
1550
  const CheckboxContainer = tw.label`
1551
1551
  tu-checkbox--container group
1552
1552
  `;
1553
- const Label$4 = tw.label`
1553
+ const Label$5 = tw.label`
1554
1554
  tu-checkbox__label
1555
1555
  ${({
1556
1556
  $disabled
@@ -2491,7 +2491,7 @@ const Indicator$1 = _a => {
2491
2491
  "$withBackground": withBackground
2492
2492
  }, {
2493
2493
  children: icon
2494
- })), label !== undefined && jsx(Label$3, Object.assign({
2494
+ })), label !== undefined && jsx(Label$4, Object.assign({
2495
2495
  "data-testid": dataTestId ? `${dataTestId}-label` : "indicator-label"
2496
2496
  }, {
2497
2497
  children: label
@@ -2560,7 +2560,7 @@ const IconBackground = tw.div`
2560
2560
  return $withBackground ? "" : "tu-indicator__icon-background--none";
2561
2561
  }}
2562
2562
  `;
2563
- const Label$3 = tw.div`
2563
+ const Label$4 = tw.div`
2564
2564
  tu-indicator__label
2565
2565
  `;
2566
2566
 
@@ -2573,7 +2573,7 @@ const Label$3 = tw.div`
2573
2573
  * @returns {JSX.Element} Label component
2574
2574
  */
2575
2575
 
2576
- const Label$2 = ({
2576
+ const Label$3 = ({
2577
2577
  id,
2578
2578
  htmlFor,
2579
2579
  label,
@@ -2595,14 +2595,14 @@ const Label$2 = ({
2595
2595
  htmlFor: htmlFor
2596
2596
  }, {
2597
2597
  children: labelElement
2598
- })), jsx(Description, Object.assign({
2598
+ })), jsx(Description$1, Object.assign({
2599
2599
  subtle: true
2600
2600
  }, {
2601
2601
  children: description
2602
2602
  }))]
2603
2603
  });
2604
2604
  };
2605
- const Description = tw(Text)`
2605
+ const Description$1 = tw(Text)`
2606
2606
  tu-label
2607
2607
  `;
2608
2608
 
@@ -2634,7 +2634,7 @@ const LegendItem = ({
2634
2634
  style: {
2635
2635
  backgroundColor: color
2636
2636
  }
2637
- }), jsx(Label$1, {
2637
+ }), jsx(Label$2, {
2638
2638
  children: label
2639
2639
  })]
2640
2640
  }));
@@ -2657,7 +2657,7 @@ const Indicator = tw.span`
2657
2657
  rounded-[50%]
2658
2658
  mr-2
2659
2659
  `;
2660
- const Label$1 = tw.span`
2660
+ const Label$2 = tw.span`
2661
2661
  text-sm
2662
2662
  `;
2663
2663
 
@@ -2717,7 +2717,7 @@ const MenuItem = ({
2717
2717
  onClick: onClick
2718
2718
  }, {
2719
2719
  children: jsxs(Content, {
2720
- children: [jsx(Label, {
2720
+ children: [jsx(Label$1, {
2721
2721
  children: label
2722
2722
  }), icon && jsx(Icon, {
2723
2723
  children: icon
@@ -2734,7 +2734,7 @@ const Content = tw.div`
2734
2734
  const Icon = tw.div`
2735
2735
  tu-menuItem__icon
2736
2736
  `;
2737
- const Label = tw.div`
2737
+ const Label$1 = tw.div`
2738
2738
  tu-menuItem__label
2739
2739
  `;
2740
2740
 
@@ -3450,7 +3450,13 @@ const Prompt = ({
3450
3450
  const RadioGroupContext = React.createContext(null);
3451
3451
 
3452
3452
  /**
3453
- * The RadioGroup component.
3453
+ * Use radio buttons when you have a group of mutually exclusive choices and only one selection from the group is allowed.
3454
+ *
3455
+ * Radio buttons are used for mutually exclusive choices, not for multiple choices. Only one radio button can be selected at a time. When a user chooses a new item, the previous choice is automatically deselected.
3456
+ *
3457
+ * _**Do use** Radio buttons in forms, settings, or selections in a list._
3458
+ *
3459
+ * _**Do not use** Radio buttons if a user can select many option from a list, use checkboxes instead of radio buttons._
3454
3460
  *
3455
3461
  * @param {RadioGroupProps} props - The props for the RadioGroup component
3456
3462
  * @returns {JSX.Element} RadioGroup component
@@ -3466,37 +3472,38 @@ const RadioGroup = ({
3466
3472
  label,
3467
3473
  inline,
3468
3474
  className,
3469
- dataTestId
3475
+ dataTestId,
3476
+ isInvalid
3470
3477
  }) => {
3471
- return jsxs(Flex, Object.assign({
3472
- "$inline": inline,
3473
- className: className,
3474
- "data-testid": dataTestId
3478
+ return jsx(FormGroup, Object.assign({
3479
+ label: label,
3480
+ dataTestId: `${dataTestId}-FormGroup`
3475
3481
  }, {
3476
- children: [label && jsx(Text, Object.assign({
3477
- subtle: true,
3478
- size: "small"
3479
- }, {
3480
- children: label
3481
- })), jsx(RadioGroupContext.Provider, Object.assign({
3482
- value: {
3483
- id,
3484
- value,
3485
- name: name || id,
3486
- onChange,
3487
- disabled
3488
- }
3482
+ children: jsx(Flex, Object.assign({
3483
+ "$inline": inline,
3484
+ className: className,
3485
+ "data-testid": dataTestId
3489
3486
  }, {
3490
- children: children
3491
- }))]
3487
+ children: jsx(RadioGroupContext.Provider, Object.assign({
3488
+ value: {
3489
+ id,
3490
+ value,
3491
+ name: name || id,
3492
+ onChange,
3493
+ disabled,
3494
+ isInvalid
3495
+ }
3496
+ }, {
3497
+ children: children
3498
+ }))
3499
+ }))
3492
3500
  }));
3493
3501
  };
3502
+ RadioGroup.displayName = "RadioGroup";
3494
3503
  const Flex = tw.div`
3495
- flex
3496
- gap-2
3497
- ${({
3504
+ ${({
3498
3505
  $inline
3499
- }) => $inline ? tws`flex-row items-center` : tws`flex-col items-start`}
3506
+ }) => $inline ? tws`tu-radiogroup--inline` : tws`tu-radiogroup`}
3500
3507
  `;
3501
3508
 
3502
3509
  /**
@@ -3510,37 +3517,71 @@ const RadioItem = ({
3510
3517
  label,
3511
3518
  value,
3512
3519
  dataTestId,
3513
- className
3520
+ className,
3521
+ description
3514
3522
  }) => {
3515
3523
  const groupCtx = React.useContext(RadioGroupContext);
3516
3524
  const isChecked = (groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.value) === value;
3525
+ const uuid = v4();
3517
3526
  return jsxs(CustomFlex, Object.assign({
3518
3527
  className: className
3519
3528
  }, {
3520
- children: [jsx("input", {
3521
- id: `${label}_${value}`,
3522
- type: "radio",
3523
- className: "hover:cursor-pointer",
3524
- value: value,
3525
- checked: isChecked,
3526
- disabled: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
3527
- onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange,
3528
- "data-testid": dataTestId
3529
- }), jsx("label", Object.assign({
3530
- className: "w-full hover:cursor-pointer",
3531
- htmlFor: `${label}_${value}`
3532
- }, {
3533
- children: typeof label === "string" ? jsx(Text, {
3529
+ children: [jsxs(InputWrapper, {
3530
+ children: [jsx(Input, {
3531
+ id: uuid,
3532
+ type: "radio",
3533
+ value: value,
3534
+ checked: isChecked,
3535
+ "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
3536
+ "$isInvalid": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid,
3537
+ onChange: groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.onChange,
3538
+ "data-testid": dataTestId,
3539
+ "$checked": isChecked
3540
+ }), jsx(Label, Object.assign({
3541
+ htmlFor: uuid,
3542
+ "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
3543
+ "$isInvalid": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid
3544
+ }, {
3534
3545
  children: label
3535
- }) : label
3546
+ }))]
3547
+ }), description && jsx(Description, Object.assign({
3548
+ htmlFor: uuid,
3549
+ "$disabled": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.disabled,
3550
+ "$isInvalid": groupCtx === null || groupCtx === void 0 ? void 0 : groupCtx.isInvalid
3551
+ }, {
3552
+ children: description
3536
3553
  }))]
3537
3554
  }));
3538
3555
  };
3539
3556
  const CustomFlex = tw.div`
3540
- flex
3541
- items-center
3542
- gap-2
3543
- hover:cursor-pointer
3557
+ tu-radioitem_custom_flex
3558
+ `;
3559
+ const InputWrapper = tw.div`
3560
+ tu-radioitem_wrapper
3561
+ `;
3562
+ const Input = tw.input`
3563
+ tu-radioitem
3564
+ ${({
3565
+ $checked
3566
+ }) => $checked ? tws`tu-radioitem--checked` : tws``}
3567
+ ${({
3568
+ $disabled
3569
+ }) => $disabled ? tws`tu-radioitem--disabled` : tws``}
3570
+ ${({
3571
+ $isInvalid
3572
+ }) => $isInvalid ? tws`tu-radioitem--invalid` : tws``}
3573
+ `;
3574
+ const Label = tw.label`
3575
+ tu-radioitem__label
3576
+ ${({
3577
+ $isInvalid
3578
+ }) => $isInvalid ? tws`tu-radioitem__label--invalid` : tws``}
3579
+ ${({
3580
+ $disabled
3581
+ }) => $disabled ? tws`tu-radioitem__label--disabled` : tws``}
3582
+ `;
3583
+ const Description = tw.label`
3584
+ tu-radioitem__description
3544
3585
  `;
3545
3586
 
3546
3587
  /**
@@ -3564,7 +3605,7 @@ const SelectContainer = ({
3564
3605
  return jsxs(Container, Object.assign({
3565
3606
  "data-testid": dataTestId
3566
3607
  }, {
3567
- children: [label && !hideLabel && jsx(Label$2, {
3608
+ children: [label && !hideLabel && jsx(Label$3, {
3568
3609
  label: label,
3569
3610
  htmlFor: id !== null && id !== void 0 ? id : false,
3570
3611
  description: description
@@ -3969,7 +4010,7 @@ const TextArea = React.forwardRef(({
3969
4010
  className: className,
3970
4011
  "data-testid": dataTestId
3971
4012
  }, {
3972
- children: [jsx(Label$2, {
4013
+ children: [jsx(Label$3, {
3973
4014
  htmlFor: id !== null && id !== void 0 ? id : false,
3974
4015
  id: id,
3975
4016
  label: label,
@@ -4338,4 +4379,4 @@ const useTimeout = ({
4338
4379
  };
4339
4380
  };
4340
4381
 
4341
- export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$2 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MultiRowTableCell, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextField, TextInput, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, intentColors, useContainerProps, useCustomComponents, useCustomStyles, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
4382
+ export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$3 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MultiRowTableCell, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextField, TextInput, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, intentColors, useContainerProps, useCustomComponents, useCustomStyles, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "0.0.74-alpha-f1247b22d.0",
3
+ "version": "0.0.74",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "UNLICENSED",
6
6
  "dependencies": {
7
- "@trackunit/css-core": "0.0.46-alpha-f1247b22d.0",
8
- "@trackunit/tailwind-styled-components": "0.0.41-alpha-f1247b22d.0",
7
+ "@trackunit/css-core": "0.0.45",
8
+ "@trackunit/tailwind-styled-components": "0.0.40",
9
9
  "react": "17.0.1",
10
- "@trackunit/ui-design-tokens": "0.0.40-alpha-f1247b22d.0",
10
+ "@trackunit/ui-design-tokens": "0.0.39",
11
11
  "echarts-for-react": "^3.0.2",
12
12
  "uuid": "^8.3.2",
13
13
  "@react-spring/web": "^9.4.4",
14
14
  "react-use": "^17.3.2",
15
15
  "react-day-picker": "^8.0.3",
16
16
  "date-fns": "^2.28.0",
17
- "@trackunit/ui-icons": "0.0.42-alpha-f1247b22d.0",
17
+ "@trackunit/ui-icons": "0.0.41",
18
18
  "react-useportal": "^1.0.16",
19
19
  "react-helmet": "^6.1.0",
20
20
  "@popperjs/core": "^2.11.4",