@luscii-healthtech/web-ui 2.47.9 → 2.48.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.
@@ -13,6 +13,7 @@ export interface CheckboxProps {
13
13
  onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
14
14
  className?: string;
15
15
  error?: boolean;
16
+ innerRef?: React.Ref<HTMLInputElement>;
16
17
  }
17
- export declare const Checkbox: ({ id, text, explanation, type, isChecked, isIndeterminate, isDisabled, name, value, onChange, className, error, }: CheckboxProps) => JSX.Element;
18
+ export declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
18
19
  export default Checkbox;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormCheckboxProps } from "./form.types";
3
+ export declare const FormFieldCheckbox: React.ForwardRefExoticComponent<FormCheckboxProps & React.RefAttributes<HTMLInputElement>>;
@@ -5,6 +5,7 @@ import { RadioGroupProps } from "../RadioGroup/RadioGroupV2";
5
5
  import { SelectProps } from "../Select/Select";
6
6
  import { ImagePickerProps } from "../ImagePicker/ImagePicker";
7
7
  import { PartialProperties } from "../../types/general.types";
8
+ import { CheckboxProps } from "../Checkbox/Checkbox";
8
9
  export declare type AllowedTextInputTypes = Extract<HTMLInputTypeAttribute, "email" | "number" | "password" | "text">;
9
10
  export declare type FormFieldWidth = "sm" | "md" | "lg" | "xl" | "full";
10
11
  export interface GenericFormProps<TFieldValues extends FieldValues> {
@@ -27,7 +28,7 @@ export interface FormFieldDecoratorProps {
27
28
  info?: string;
28
29
  decoratorClassname?: string;
29
30
  }
30
- export declare type FormFieldProps<TFieldValues> = FormFieldInputProps | FormFieldSelectProps | FormFieldImagePickerProps | FormFieldRadioGroupProps | FormFieldRowProps<TFieldValues>;
31
+ export declare type FormFieldProps<TFieldValues> = FormFieldInputProps | FormFieldSelectProps | FormFieldImagePickerProps | FormFieldRadioGroupProps | FormFieldRowProps<TFieldValues> | FormFieldCheckboxBaseProps;
31
32
  export interface FormFieldRowProps<TFieldValues> extends Record<keyof FormFieldGenericProps<never>, never> {
32
33
  type: "row";
33
34
  key: string;
@@ -48,6 +49,10 @@ export interface FormFieldImagePickerProps extends FormFieldGenericProps<ImagePi
48
49
  type: "imagePicker";
49
50
  fieldProps: ImagePickerFieldProps;
50
51
  }
52
+ export interface FormFieldCheckboxBaseProps extends FormFieldGenericProps<Omit<CheckboxProps, "name" | "type">> {
53
+ type: "checkbox";
54
+ variant?: CheckboxProps["type"];
55
+ }
51
56
  export interface FormFieldDecoratorWithGeneratedProps extends FormFieldDecoratorProps {
52
57
  name: string;
53
58
  fieldErrors: FieldErrors;
@@ -71,4 +76,8 @@ export interface FormImagePickerProps extends ImagePickerFieldProps, FormFieldDe
71
76
  control: Control;
72
77
  rules?: Exclude<RegisterOptions, "valueAsNumber" | "valueAsDate" | "setValueAs">;
73
78
  }
79
+ export interface FormCheckboxProps extends FormFieldCheckboxBaseProps, FormFieldDecoratorWithGeneratedProps {
80
+ control: Control;
81
+ rules?: Exclude<RegisterOptions, "valueAsNumber" | "valueAsDate" | "setValueAs">;
82
+ }
74
83
  export {};
@@ -1,6 +1,7 @@
1
1
  import "./ListSkeleton.scss";
2
2
  declare type ListSkeletonProps = {
3
3
  items: number;
4
+ dataTestId?: string;
4
5
  };
5
- export declare const ListSkeleton: ({ items }: ListSkeletonProps) => JSX.Element;
6
+ export declare const ListSkeleton: ({ items, dataTestId, }: ListSkeletonProps) => JSX.Element;
6
7
  export {};
@@ -1213,7 +1213,9 @@ var ListItemSkeleton = function ListItemSkeleton() {
1213
1213
  };
1214
1214
 
1215
1215
  var ListSkeleton = function ListSkeleton(_ref) {
1216
- var items = _ref.items;
1216
+ var items = _ref.items,
1217
+ _ref$dataTestId = _ref.dataTestId,
1218
+ dataTestId = _ref$dataTestId === void 0 ? "list-skeleton" : _ref$dataTestId;
1217
1219
  var skeletonItems = Array.from({
1218
1220
  length: items || 5
1219
1221
  }, function (_, i) {
@@ -1222,6 +1224,7 @@ var ListSkeleton = function ListSkeleton(_ref) {
1222
1224
  });
1223
1225
  });
1224
1226
  return /*#__PURE__*/React__default.createElement("div", {
1227
+ "data-test-id": dataTestId,
1225
1228
  className: "flex flex-col divide-y divide-slate-200 bg-white border-slate-50 border rounded-lg shadow list-skeleton"
1226
1229
  }, /*#__PURE__*/React__default.createElement("div", {
1227
1230
  className: "flex flex-row items-center px-4 py-2"
@@ -2433,7 +2436,7 @@ var CenteredHero = function CenteredHero(_ref) {
2433
2436
  var css_248z$9 = ".cweb-checkbox {\n outline: none;\n}\n\n.cweb-checkbox .cweb-checkbox-input {\n position: absolute;\n -webkit-appearance: none;\n height: 1px;\n opacity: 0;\n width: 1px;\n}\n\n.cweb-checkbox.type-regular .cweb-checkbox-label {\n display: flex;\n align-items: center;\n margin-bottom: 0;\n}\n\n.cweb-checkbox.type-regular .cweb-checkbox-icon-container {\n width: 16px;\n height: 16px;\n display: flex;\n align-items: center;\n justify-content: center;\n flex: 0 0 auto;\n border: 1px solid #cccccc;\n border-radius: 4px;\n}\n\n.cweb-checkbox.type-regular.hasError .cweb-checkbox-icon-container {\n border: 1px solid #ff6266;\n}\n\n.cweb-checkbox.type-regular .cweb-checkbox-icon {\n display: block;\n}\n\n.cweb-checkbox.type-regular.is-focused .cweb-checkbox-icon-container {\n border-color: #0074dd;\n}\n\n.cweb-checkbox.type-regular.is-checked .cweb-checkbox-icon {\n width: 0.5rem;\n height: 0.5rem;\n padding: 4px;\n background: url(\"data:image/svg+xml,%3Csvg xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22 width%3D%2210%22 height%3D%228%22 viewBox%3D%220 0 10 8%22 fill%3D%22none%22%3E %3Cpath d%3D%22M9.207 0.792787C9.39447 0.980314 9.49979 1.23462 9.49979 1.49979C9.49979 1.76495 9.39447 2.01926 9.207 2.20679L4.207 7.20679C4.01947 7.39426 3.76516 7.49957 3.5 7.49957C3.23484 7.49957 2.98053 7.39426 2.793 7.20679L0.793 5.20679C0.610842 5.01818 0.510047 4.76558 0.512326 4.50339C0.514604 4.24119 0.619773 3.99038 0.805181 3.80497C0.990589 3.61956 1.2414 3.51439 1.5036 3.51211C1.7658 3.50983 2.0184 3.61063 2.207 3.79279L3.5 5.08579L7.793 0.792787C7.98053 0.605316 8.23484 0.5 8.5 0.5C8.76516 0.5 9.01947 0.605316 9.207 0.792787Z%22 fill%3D%22white%22%2F%3E%3C%2Fsvg%3E\") no-repeat center;\n background-size: contain;\n}\n\n.cweb-checkbox.type-regular.is-indeterminate .cweb-checkbox-icon {\n width: 0.5rem;\n height: 0.5rem;\n padding: 4px;\n background: url(\"data:image/svg+xml,%3Csvg width%3D%2210%22 height%3D%222%22 viewBox%3D%220 0 10 2%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath d%3D%22M9 -4.37114e-08C9.55228 -1.95703e-08 10 0.447715 10 1C10 1.55228 9.55228 2 9 2L1 2C0.447716 2 -6.78525e-08 1.55228 -4.37114e-08 1C-1.95703e-08 0.447715 0.447715 -4.17544e-07 1 -3.93402e-07L9 -4.37114e-08Z%22 fill%3D%22white%22%2F%3E%3C%2Fsvg%3E\") no-repeat center;\n background-size: contain;\n}\n\n.cweb-checkbox.type-regular.is-disabled.show-cross-when-disabled .cweb-checkbox-icon {\n width: 10px;\n height: 10px;\n background: url(\"data:image/svg+xml,%3Csvg width%3D%2211px%22 height%3D%2211px%22 viewBox%3D%220 0 11 11%22 version%3D%221.1%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E %3Cg stroke%3D%22none%22 stroke-width%3D%221%22 fill%3D%22none%22 fill-rule%3D%22evenodd%22 stroke-linecap%3D%22round%22%3E %3Cg transform%3D%22translate(-6.000000%2C -7.000000)%22 stroke%3D%22%232D2D2D%22 stroke-width%3D%222%22%3E %3Cpath d%3D%22M7%2C17 L16%2C8 M16%2C17 L7%2C8%22 %2F%3E %3C%2Fg%3E %3C%2Fg%3E%3C%2Fsvg%3E\") no-repeat center;\n background-size: contain;\n opacity: 0.6;\n}\n\n.cweb-checkbox.type-switch .cweb-checkbox-label {\n display: flex;\n align-items: center;\n margin-bottom: 0;\n width: 56px;\n height: 28px;\n position: relative;\n}\n\n.cweb-checkbox.type-switch .cweb-checkbox-icon-container {\n position: absolute;\n cursor: pointer;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: #d1d5db;\n border-radius: 16px;\n}\n\n.cweb-checkbox.type-switch .cweb-checkbox-icon-container:after {\n position: relative;\n display: block;\n content: \"\";\n height: 20px;\n width: 20px;\n top: 4px;\n left: 4px;\n background-color: white;\n border-radius: 50%;\n}\n\n.cweb-checkbox.type-switch.is-checked .cweb-checkbox-icon-container {\n background-color: #6abfa6;\n}\n\n.cweb-checkbox.type-switch.is-checked .cweb-checkbox-icon-container:after {\n left: 32px;\n}";
2434
2437
  styleInject(css_248z$9);
2435
2438
 
2436
- var Checkbox = function Checkbox(_ref) {
2439
+ var CheckboxInner = function CheckboxInner(_ref) {
2437
2440
  var id = _ref.id,
2438
2441
  text = _ref.text,
2439
2442
  explanation = _ref.explanation,
@@ -2448,13 +2451,14 @@ var Checkbox = function Checkbox(_ref) {
2448
2451
  value = _ref.value,
2449
2452
  onChange = _ref.onChange,
2450
2453
  className = _ref.className,
2451
- error = _ref.error;
2454
+ error = _ref.error,
2455
+ innerRef = _ref.innerRef;
2452
2456
 
2453
2457
  var _useState = React.useState(false),
2454
2458
  checked = _useState[0],
2455
2459
  setChecked = _useState[1];
2456
2460
 
2457
- var _useState2 = React.useState(false),
2461
+ var _useState2 = React.useState(isIndeterminate),
2458
2462
  indeterminate = _useState2[0],
2459
2463
  setIndeterminate = _useState2[1];
2460
2464
 
@@ -2462,7 +2466,6 @@ var Checkbox = function Checkbox(_ref) {
2462
2466
  isFocused = _useState3[0],
2463
2467
  setIsFocused = _useState3[1];
2464
2468
 
2465
- var checkboxRef = React__default.useRef(null);
2466
2469
  var containerClassName = classNames("cweb-checkbox", className, {
2467
2470
  "is-focused": isFocused,
2468
2471
  "is-checked": checked && !indeterminate,
@@ -2480,12 +2483,15 @@ var Checkbox = function Checkbox(_ref) {
2480
2483
  setIndeterminate(isIndeterminate);
2481
2484
  }, [isIndeterminate]);
2482
2485
  React.useEffect(function () {
2483
- if (checkboxRef != null && checkboxRef.current) {
2484
- checkboxRef.current.indeterminate = !indeterminate;
2486
+ if (innerRef) {
2487
+ if (typeof innerRef !== "function" && innerRef != null && innerRef.current) {
2488
+ innerRef.current.indeterminate = !indeterminate;
2489
+ }
2485
2490
  }
2486
2491
  }, [indeterminate]);
2487
2492
 
2488
2493
  var handleChange = function handleChange(event) {
2494
+ setChecked(event.currentTarget.checked);
2489
2495
  event.stopPropagation();
2490
2496
  setIndeterminate(false);
2491
2497
 
@@ -2513,7 +2519,7 @@ var Checkbox = function Checkbox(_ref) {
2513
2519
  }
2514
2520
  }, /*#__PURE__*/React__default.createElement("input", {
2515
2521
  id: id,
2516
- ref: checkboxRef,
2522
+ ref: innerRef,
2517
2523
  "data-test-id": "checkbox-" + name,
2518
2524
  className: "cweb-checkbox-input",
2519
2525
  name: name,
@@ -2550,6 +2556,12 @@ var Checkbox = function Checkbox(_ref) {
2550
2556
  }))));
2551
2557
  };
2552
2558
 
2559
+ var Checkbox = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
2560
+ return /*#__PURE__*/React__default.createElement(CheckboxInner, _extends({}, props, {
2561
+ innerRef: ref
2562
+ }));
2563
+ });
2564
+
2553
2565
  var ConfirmationDialogTitle = function ConfirmationDialogTitle(props) {
2554
2566
  var _props$title;
2555
2567
 
@@ -6807,6 +6819,52 @@ var FormImagePicker = /*#__PURE__*/React__default.forwardRef(function (_ref, inn
6807
6819
  }));
6808
6820
  });
6809
6821
 
6822
+ var _excluded$s = ["control", "name", "rules", "fieldErrors", "fieldRequired", "label", "info", "decoratorClassname"];
6823
+ var FormFieldCheckbox = /*#__PURE__*/React__default.forwardRef(function (_ref, innerRef) {
6824
+ var control = _ref.control,
6825
+ name = _ref.name,
6826
+ rules = _ref.rules,
6827
+ fieldErrors = _ref.fieldErrors,
6828
+ fieldRequired = _ref.fieldRequired,
6829
+ label = _ref.label,
6830
+ info = _ref.info,
6831
+ decoratorClassname = _ref.decoratorClassname,
6832
+ fieldProps = _objectWithoutPropertiesLoose(_ref, _excluded$s);
6833
+
6834
+ return /*#__PURE__*/React__default.createElement(FormFieldDecorator, {
6835
+ name: name,
6836
+ fieldErrors: fieldErrors,
6837
+ fieldRequired: fieldRequired,
6838
+ label: "",
6839
+ info: info,
6840
+ decoratorClassname: decoratorClassname
6841
+ }, /*#__PURE__*/React__default.createElement(index_ie11.Controller, {
6842
+ name: name,
6843
+ control: control,
6844
+ rules: rules,
6845
+ render: function render(_ref2) {
6846
+ var _onChange = _ref2.onChange,
6847
+ value = _ref2.value;
6848
+ return /*#__PURE__*/React__default.createElement(Checkbox, _extends({}, fieldProps, {
6849
+ // Might be a tech debt due to how we named this
6850
+ // but the field type is always a checkbox, its shape
6851
+ // or style is what changes. The name `variant` was added
6852
+ // to the props to avoid confusion.
6853
+ type: fieldProps.variant,
6854
+ isChecked: value,
6855
+ error: hasError(name, fieldErrors),
6856
+ ref: innerRef,
6857
+ name: name,
6858
+ onChange: function onChange(event) {
6859
+ _onChange(event.target.checked);
6860
+ },
6861
+ text: label,
6862
+ value: value
6863
+ }));
6864
+ }
6865
+ }));
6866
+ });
6867
+
6810
6868
  /**
6811
6869
  * Create a straight forward Form, which takes away the 'overhead' of react-hook-form.
6812
6870
  *
@@ -6933,6 +6991,21 @@ function FormFieldMapper(formFieldProps, useFormReturn) {
6933
6991
  }));
6934
6992
  }
6935
6993
 
6994
+ case "checkbox":
6995
+ {
6996
+ return /*#__PURE__*/React__default.createElement(FormFieldCheckbox, _extends({
6997
+ key: name
6998
+ }, decoratorProps, {
6999
+ fieldRequired: isRequired(options),
7000
+ fieldErrors: errors
7001
+ }, fieldProps, {
7002
+ type: "checkbox",
7003
+ name: name,
7004
+ rules: options,
7005
+ control: control
7006
+ }));
7007
+ }
7008
+
6936
7009
  default:
6937
7010
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
6938
7011
  }
@@ -7907,10 +7980,10 @@ var Icons = {
7907
7980
  StatusColoredIcon: StatusColoredIcon
7908
7981
  };
7909
7982
 
7910
- var _excluded$s = ["name"];
7983
+ var _excluded$t = ["name"];
7911
7984
  var Icon = function Icon(_ref) {
7912
7985
  var name = _ref.name,
7913
- iconProps = _objectWithoutPropertiesLoose(_ref, _excluded$s);
7986
+ iconProps = _objectWithoutPropertiesLoose(_ref, _excluded$t);
7914
7987
 
7915
7988
  return /*#__PURE__*/React__default.createElement(Icons[name], iconProps);
7916
7989
  };