@agility/plenum-ui 1.3.9 → 1.3.10

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,11 +1,11 @@
1
1
  import { FC } from 'react';
2
2
  export interface RadioProps {
3
3
  /** group name */
4
- name: string;
4
+ name?: string;
5
5
  /** Radio label */
6
6
  label: string;
7
7
  /** Radio ID */
8
- id: string;
8
+ id?: string;
9
9
  /** Disabled state */
10
10
  isDisabled?: boolean;
11
11
  /** Check state */
@@ -7,9 +7,9 @@ export interface SimpleSelectProps {
7
7
  /** Label */
8
8
  label?: string;
9
9
  /** Select ID prop */
10
- id: string;
10
+ id?: string;
11
11
  /** Select name prop */
12
- name: string;
12
+ name?: string;
13
13
  /** List of options to display in the select menu */
14
14
  options: SimpleSelectOptions[];
15
15
  /** Select name prop */
@@ -4,9 +4,9 @@ export interface TextInputProps {
4
4
  /** Input type*/
5
5
  type: Type;
6
6
  /** Input ID */
7
- id: string;
7
+ id?: string;
8
8
  /** Input Name */
9
- name: string;
9
+ name?: string;
10
10
  /** Label for the input */
11
11
  label: string;
12
12
  /** Force the focus state on the input */
@@ -1,13 +1,13 @@
1
- import React from 'react';
2
- import { IconName } from '../../../util/DynamicIcons';
3
- export declare type Type = 'text' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'url' | 'date' | 'datetime-local' | 'month' | 'time' | 'week' | 'currency';
1
+ import React from "react";
2
+ import { IconName } from "../../../util/DynamicIcons";
3
+ export declare type Type = "text" | "email" | "number" | "password" | "search" | "tel" | "url" | "date" | "datetime-local" | "month" | "time" | "week" | "currency";
4
4
  export interface TextInputAddonProps {
5
5
  /** Input type*/
6
6
  type: Type;
7
7
  /** Input ID */
8
- id: string;
8
+ id?: string;
9
9
  /** Input Name */
10
- name: string;
10
+ name?: string;
11
11
  /** Label for the input */
12
12
  label?: string;
13
13
  /** placeholder for the input */
@@ -41,7 +41,7 @@ export interface TextInputAddonProps {
41
41
  /** Leading label for input CTA */
42
42
  leadLabel?: string;
43
43
  /** Remove bg and border from CTA */
44
- clearCta?: 'left' | 'right' | 'both' | 'none';
44
+ clearCta?: "left" | "right" | "both" | "none";
45
45
  /** Callback on change */
46
46
  onChange?(value: string): void;
47
47
  /** Callback on Cta click */
@@ -8,9 +8,9 @@ export interface TextInputSelectProps {
8
8
  /** Input type*/
9
9
  type: Type;
10
10
  /** Input ID */
11
- id: string;
11
+ id?: string;
12
12
  /** Input Name */
13
- name: string;
13
+ name?: string;
14
14
  /** Label for the input */
15
15
  label?: string;
16
16
  /** placeholder for the input */
@@ -1,11 +1,11 @@
1
1
  import React from "react";
2
2
  export interface TextareaProps {
3
3
  /** Input ID */
4
- id: string;
4
+ id?: string;
5
5
  /** Input Name */
6
- name: string;
6
+ name?: string;
7
7
  /** Label for the input */
8
- label: string;
8
+ label?: string;
9
9
  /** Error state */
10
10
  isError?: boolean;
11
11
  /** If field is required */
@@ -14,6 +14,7 @@ export interface TextareaProps {
14
14
  isDisabled?: boolean;
15
15
  /** Set default value */
16
16
  defaultValue?: string;
17
+ value?: string;
17
18
  /** Message shown under the text field */
18
19
  message?: string;
19
20
  /** Input character counter */
package/lib/index.esm.js CHANGED
@@ -12422,15 +12422,26 @@ var BaseField = function (_a, ref) {
12422
12422
  };
12423
12423
  var _BaseField = forwardRef(BaseField);
12424
12424
 
12425
+ var id = 0;
12426
+ function generateId() {
12427
+ return ++id;
12428
+ }
12429
+ var useId = function () {
12430
+ var _a = useState(generateId), id = _a[0], setId = _a[1];
12431
+ useLayoutEffect(function () {
12432
+ if (id === null)
12433
+ setId(generateId());
12434
+ }, [id]);
12435
+ return id != null ? '' + id : undefined;
12436
+ };
12437
+
12425
12438
  var TextInput = function (_a, ref) {
12426
12439
  var label = _a.label, isFocused = _a.isFocused, isError = _a.isError, id = _a.id, name = _a.name, isRequired = _a.isRequired, type = _a.type, defaultValue = _a.defaultValue, isDisabled = _a.isDisabled, message = _a.message, isShowCounter = _a.isShowCounter, _b = _a.maxLength, maxLength = _b === void 0 ? 100 : _b, onChange = _a.onChange, externalValue = _a.value;
12440
+ var uniqueID = useId();
12427
12441
  var _c = useState(Boolean(isFocused)), isFocus = _c[0], setIsFocus = _c[1];
12428
12442
  var _d = useState(false); _d[0]; var setIsActive = _d[1];
12429
- var _e = useState(defaultValue || ""), value = _e[0], setValue = _e[1];
12443
+ var _e = useState(externalValue || defaultValue || ""), value = _e[0], setValue = _e[1];
12430
12444
  var inputRef = useRef(null);
12431
- useEffect(function () {
12432
- setValue(externalValue);
12433
- }, [externalValue]);
12434
12445
  // set force focus
12435
12446
  useEffect(function () {
12436
12447
  var input = inputRef.current;
@@ -12464,6 +12475,11 @@ var TextInput = function (_a, ref) {
12464
12475
  "focus:ring-purple-500 border-purple-500 outline-purple-500 shadow-none": isFocus && !isError
12465
12476
  }, { "focus:ring-red-500 !border-red-500 shadow-none": isError });
12466
12477
  var discriptionStyles = cn("text-sm mt-1 block", { "text-gray-500": !isError }, { "text-red-500": isError });
12478
+ if (!id)
12479
+ id = "input-".concat(uniqueID);
12480
+ if (!name)
12481
+ name = id;
12482
+ console.log();
12467
12483
  return (React__default.createElement("div", null,
12468
12484
  React__default.createElement(InputLabel, { isPlaceholder: true, label: label, isRequired: isRequired, id: id, isError: isError, isActive: true, isDisabled: isDisabled }),
12469
12485
  React__default.createElement("div", null,
@@ -12504,17 +12520,25 @@ var InputCta = function (_a) {
12504
12520
  };
12505
12521
 
12506
12522
  var TextInputAddon = function (_a, ref) {
12507
- var label = _a.label, isFocused = _a.isFocused, isError = _a.isError, id = _a.id, name = _a.name, isRequired = _a.isRequired, type = _a.type, defaultValue = _a.defaultValue, isDisabled = _a.isDisabled, message = _a.message, isShowCounter = _a.isShowCounter, _b = _a.maxLength, maxLength = _b === void 0 ? 100 : _b, placeholder = _a.placeholder, leadIcon = _a.leadIcon, trailIcon = _a.trailIcon, inlineIcon = _a.inlineIcon, trailLabel = _a.trailLabel, leadLabel = _a.leadLabel, _c = _a.clearCta, clearCta = _c === void 0 ? 'none' : _c, onChange = _a.onChange, onCtaClick = _a.onCtaClick, externalValue = _a.value;
12523
+ var label = _a.label, isFocused = _a.isFocused, isError = _a.isError, id = _a.id, name = _a.name, isRequired = _a.isRequired, type = _a.type, defaultValue = _a.defaultValue, isDisabled = _a.isDisabled, message = _a.message, isShowCounter = _a.isShowCounter, _b = _a.maxLength, maxLength = _b === void 0 ? 100 : _b, placeholder = _a.placeholder, leadIcon = _a.leadIcon, trailIcon = _a.trailIcon, inlineIcon = _a.inlineIcon, trailLabel = _a.trailLabel, leadLabel = _a.leadLabel, _c = _a.clearCta, clearCta = _c === void 0 ? "none" : _c, onChange = _a.onChange, onCtaClick = _a.onCtaClick, externalValue = _a.value;
12508
12524
  var _d = useState(Boolean(isFocused)), isFocus = _d[0], setIsFocus = _d[1];
12509
- var _e = useState(defaultValue || ''), value = _e[0], setValue = _e[1];
12525
+ var _e = useState(defaultValue || ""), value = _e[0], setValue = _e[1];
12510
12526
  var inputRef = useRef(null);
12527
+ var uniqueID = useId();
12528
+ if (!id)
12529
+ id = "input-".concat(uniqueID);
12530
+ if (!name)
12531
+ name = id;
12511
12532
  useEffect(function () {
12512
12533
  setValue(externalValue);
12513
12534
  }, [externalValue]);
12514
12535
  // set force focus
12515
12536
  useEffect(function () {
12516
12537
  var input = inputRef.current;
12517
- if (!input || isFocus === undefined || isFocused === undefined || isDisabled)
12538
+ if (!input ||
12539
+ isFocus === undefined ||
12540
+ isFocused === undefined ||
12541
+ isDisabled)
12518
12542
  return;
12519
12543
  if (isFocus || isFocused) {
12520
12544
  input.focus();
@@ -12526,7 +12550,7 @@ var TextInputAddon = function (_a, ref) {
12526
12550
  // set label as active if default value is set
12527
12551
  useEffect(function () {
12528
12552
  var input = inputRef.current;
12529
- if (!input || defaultValue === undefined || defaultValue === '')
12553
+ if (!input || defaultValue === undefined || defaultValue === "")
12530
12554
  return;
12531
12555
  }, [defaultValue]);
12532
12556
  var handleInputFocus = function () {
@@ -12537,19 +12561,25 @@ var TextInputAddon = function (_a, ref) {
12537
12561
  setIsFocus(false);
12538
12562
  // add other focus effects here
12539
12563
  };
12540
- var className = cn('border py-2 px-3 rounded text-sm leading-5 font-normal w-full border-gray-300 outline-purple-500 shadow-sm focus:outline-none focus:ring-1 focus:ring-purple-500 focus:border-purple-500 ', { 'focus:ring-red-500 !border-red-500 !outline-red-500 shadow-none': isError }, { 'pl-10': inlineIcon }, { '!rounded-r-none !rounded-l': (trailIcon || trailLabel) && !(leadIcon || leadLabel) }, { '!rounded-r-none !rounded-r': !(trailIcon || trailLabel) && (leadIcon || leadLabel) }, { 'rounded-none': (trailIcon || trailLabel) && (leadIcon || leadLabel) });
12541
- var discriptionStyles = cn('text-sm mt-1 block', { 'text-gray-500': !isError }, { 'text-red-500': isError });
12564
+ var className = cn("border py-2 px-3 rounded text-sm leading-5 font-normal w-full border-gray-300 outline-purple-500 shadow-sm focus:outline-none focus:ring-1 focus:ring-purple-500 focus:border-purple-500 ", {
12565
+ "focus:ring-red-500 !border-red-500 !outline-red-500 shadow-none": isError
12566
+ }, { "pl-10": inlineIcon }, {
12567
+ "!rounded-r-none !rounded-l": (trailIcon || trailLabel) && !(leadIcon || leadLabel)
12568
+ }, {
12569
+ "!rounded-r-none !rounded-r": !(trailIcon || trailLabel) && (leadIcon || leadLabel)
12570
+ }, { "rounded-none": (trailIcon || trailLabel) && (leadIcon || leadLabel) });
12571
+ var discriptionStyles = cn("text-sm mt-1 block", { "text-gray-500": !isError }, { "text-red-500": isError });
12542
12572
  return (React__default.createElement("div", null,
12543
12573
  label && (React__default.createElement(InputLabel, { label: label, isRequired: isRequired, id: id, isError: isError, isDisabled: isDisabled })),
12544
12574
  React__default.createElement("div", { className: "flex" },
12545
- (leadIcon || leadLabel) && (React__default.createElement(InputCta, { icon: leadIcon, ctaLabel: leadLabel, align: "left", isClear: clearCta === 'left' || clearCta === 'both' })),
12546
- React__default.createElement("div", { className: "flex-grow focus-within:z-20 relative" },
12547
- inlineIcon && (React__default.createElement("div", { className: "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none" },
12575
+ (leadIcon || leadLabel) && (React__default.createElement(InputCta, { icon: leadIcon, ctaLabel: leadLabel, align: "left", isClear: clearCta === "left" || clearCta === "both" })),
12576
+ React__default.createElement("div", { className: "relative flex-grow focus-within:z-20" },
12577
+ inlineIcon && (React__default.createElement("div", { className: "pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3" },
12548
12578
  React__default.createElement(DynamicIcons, { icon: inlineIcon, className: "h-5 w-5 text-gray-400", outline: false }))),
12549
12579
  React__default.createElement(_BaseField, { onFocus: handleInputFocus, onBlur: handleInputBlur, onChange: onChange, onValueChange: setValue, ref: ref, type: type, name: name, id: id, className: className, isDisabled: isDisabled, value: value, defaultValue: defaultValue, maxLength: maxLength, placeholder: placeholder })),
12550
- (trailIcon || trailLabel) && (React__default.createElement(InputCta, { icon: trailIcon, ctaLabel: trailLabel, align: "right", isClear: clearCta === 'right' || clearCta === 'both', onClickHandler: onCtaClick }))),
12580
+ (trailIcon || trailLabel) && (React__default.createElement(InputCta, { icon: trailIcon, ctaLabel: trailLabel, align: "right", isClear: clearCta === "right" || clearCta === "both", onClickHandler: onCtaClick }))),
12551
12581
  React__default.createElement("div", { className: "flex flex-row space-x-3" },
12552
- React__default.createElement("div", { className: "grow" }, message && React__default.createElement("span", { className: discriptionStyles }, message)),
12582
+ React__default.createElement("div", { className: "grow" }, message && (React__default.createElement("span", { className: discriptionStyles }, message))),
12553
12583
  isShowCounter && (React__default.createElement("div", { className: "shrink-0" },
12554
12584
  React__default.createElement(InputCounter, { current: Number(value === null || value === void 0 ? void 0 : value.length), limit: maxLength }))))));
12555
12585
  };
@@ -12578,6 +12608,11 @@ var TextInputSelect = function (_a) {
12578
12608
  var _d = useState(Boolean(isFocused)), isFocus = _d[0], setIsFocus = _d[1];
12579
12609
  var _e = useState(defaultValue || ""), value = _e[0], setValue = _e[1];
12580
12610
  var inputRef = useRef(null);
12611
+ var uniqueID = useId();
12612
+ if (!id)
12613
+ id = "select-".concat(uniqueID);
12614
+ if (!name)
12615
+ name = id;
12581
12616
  useEffect(function () {
12582
12617
  setValue(externalValue);
12583
12618
  }, [externalValue]);
@@ -12636,6 +12671,11 @@ var TextInputSelect = function (_a) {
12636
12671
  /** Comment */
12637
12672
  var Radio = function (_a) {
12638
12673
  var label = _a.label, id = _a.id, name = _a.name, _b = _a.isDisabled, isDisabled = _b === void 0 ? false : _b, _c = _a.isChecked, isChecked = _c === void 0 ? false : _c, _d = _a.isRequired, isRequired = _d === void 0 ? false : _d, _e = _a.isError, isError = _e === void 0 ? false : _e, message = _a.message, onChange = _a.onChange, onClick = _a.onClick, value = _a.value;
12674
+ var uniqueID = useId();
12675
+ if (!id)
12676
+ id = "input-".concat(uniqueID);
12677
+ if (!name)
12678
+ name = id;
12639
12679
  var checboxStyles = cn('focus:ring-purple-500 h-4 w-4 text-purple-600 border-gray-300', {
12640
12680
  'border-red-500 shadow-none': isError
12641
12681
  });
@@ -12663,8 +12703,9 @@ var Radio = function (_a) {
12663
12703
  };
12664
12704
 
12665
12705
  var Textarea = function (_a, ref) {
12666
- var id = _a.id, name = _a.name, label = _a.label, isError = _a.isError, isRequired = _a.isRequired, isDisabled = _a.isDisabled, defaultValue = _a.defaultValue, message = _a.message, isShowCounter = _a.isShowCounter, _b = _a.maxLength, maxLength = _b === void 0 ? 500 : _b, _c = _a.rows, rows = _c === void 0 ? 4 : _c, onChange = _a.onChange;
12667
- var _d = useState(defaultValue), value = _d[0], setValue = _d[1];
12706
+ var id = _a.id, name = _a.name, label = _a.label, isError = _a.isError, isRequired = _a.isRequired, isDisabled = _a.isDisabled, defaultValue = _a.defaultValue, message = _a.message, isShowCounter = _a.isShowCounter, _b = _a.maxLength, maxLength = _b === void 0 ? 500 : _b, _c = _a.rows, rows = _c === void 0 ? 4 : _c, onChange = _a.onChange, externalValue = _a.value;
12707
+ var uniqueID = useId();
12708
+ var _d = useState(externalValue || defaultValue || ""), value = _d[0], setValue = _d[1];
12668
12709
  var handleOnchange = function (e) {
12669
12710
  var targetValue = e.currentTarget.value;
12670
12711
  typeof onChange === "function" && onChange(targetValue);
@@ -12672,13 +12713,14 @@ var Textarea = function (_a, ref) {
12672
12713
  };
12673
12714
  var className = cn("shadow-sm focus:ring-purple-500 focus:border-purple-500 block w-full sm:text-sm rounded", { "border-gray-300 ": !isError }, { "focus:ring-red-500 border-red-500 outline-red-500 shadow-none": isError });
12674
12715
  var discriptionStyles = cn("text-sm mt-1 block", { "text-gray-500": !isError }, { "text-red-500": isError });
12675
- var wrapperStyles = cn({ "opacity-50": isDisabled });
12676
- return (React__default.createElement("div", { className: wrapperStyles },
12716
+ if (!id)
12717
+ id = "ta-".concat(uniqueID);
12718
+ return (React__default.createElement("div", { className: cn({ "opacity-50": isDisabled }) },
12677
12719
  label && (React__default.createElement(InputLabel, { isPlaceholder: true, isActive: true, label: label, isRequired: isRequired, id: id, isError: isError, isDisabled: isDisabled })),
12678
12720
  React__default.createElement("div", null,
12679
- React__default.createElement("textarea", { ref: ref, maxLength: maxLength, onChange: handleOnchange, rows: rows, name: name, id: id, className: className, defaultValue: defaultValue })),
12721
+ React__default.createElement("textarea", { ref: ref, maxLength: maxLength, onChange: handleOnchange, rows: rows, name: name, id: id, className: className, defaultValue: defaultValue, value: value })),
12680
12722
  React__default.createElement("div", { className: "flex flex-row space-x-3" },
12681
- React__default.createElement("div", { className: "grow" }, message && React__default.createElement("span", { className: discriptionStyles }, message)),
12723
+ React__default.createElement("div", { className: "grow" }, message && (React__default.createElement("span", { className: discriptionStyles }, message))),
12682
12724
  isShowCounter && (React__default.createElement("div", { className: "shrink-0" },
12683
12725
  React__default.createElement(InputCounter, { current: Number(value === null || value === void 0 ? void 0 : value.length), limit: maxLength }))))));
12684
12726
  };
@@ -12688,6 +12730,11 @@ var _Textarea = forwardRef(Textarea);
12688
12730
  var Select = function (_a) {
12689
12731
  var label = _a.label, id = _a.id, name = _a.name, options = _a.options, onChange = _a.onChange, isDisabled = _a.isDisabled, isError = _a.isError, isRequired = _a.isRequired;
12690
12732
  var _b = useState(options[0].value), selectedOption = _b[0], setSelectedOption = _b[1];
12733
+ var uniqueID = useId();
12734
+ if (!id)
12735
+ id = "select-".concat(uniqueID);
12736
+ if (!name)
12737
+ name = id;
12691
12738
  var handleChange = function (e) {
12692
12739
  var targetValue = e.target.value;
12693
12740
  typeof onChange == "function" && onChange(targetValue);