@luscii-healthtech/web-ui 2.64.1 → 2.66.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.
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import { Control, RegisterOptions } from "react-hook-form";
3
+ import { TextareaProps } from "../Textarea/Textarea";
4
+ import { FieldTextareaConfiguration, FormFieldLabelerWithFormProps } from "./form.types";
5
+ interface FormTextareaProps extends FieldTextareaConfiguration, Omit<TextareaProps, "name">, FormFieldLabelerWithFormProps {
6
+ control: Control;
7
+ rules?: Exclude<RegisterOptions, "valueAsNumber" | "valueAsDate" | "setValueAs">;
8
+ type: "textarea";
9
+ }
10
+ /**
11
+ * Input field that can be used in any react-hook-form context.
12
+ */
13
+ export declare const FormTextarea: React.ForwardRefExoticComponent<FormTextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
14
+ export {};
@@ -7,6 +7,7 @@ import { ImagePickerProps } from "../ImagePicker/ImagePicker";
7
7
  import { PartialProperties } from "../../types/general.types";
8
8
  import { CheckboxProps } from "../Checkbox/Checkbox";
9
9
  import { CheckboxListProps } from "../CheckboxList/CheckboxList.types";
10
+ import { TextareaProps } from "../Textarea/Textarea";
10
11
  export declare type AllowedTextInputTypes = Extract<HTMLInputTypeAttribute, "email" | "number" | "password" | "text">;
11
12
  export declare type FormFieldWidth = "sm" | "md" | "lg" | "xl" | "full";
12
13
  interface FormFieldBaseConfiguration<TFieldType> extends FormFieldLabelerProps {
@@ -31,7 +32,7 @@ export interface FormFieldLabelerProps {
31
32
  interface FieldVoidConfiguration extends Partial<FormFieldBaseConfiguration<never>> {
32
33
  type: "void";
33
34
  }
34
- export declare type FormFieldConfiguration<TFieldValues> = FieldInputConfiguration | FieldSelectConfiguration | FieldImagePickerConfiguration | FieldRadioGroupConfiguration | FieldRowConfiguration<TFieldValues> | FieldCheckboxConfiguration | FieldCheckboxListConfiguration | FieldVoidConfiguration;
35
+ export declare type FormFieldConfiguration<TFieldValues> = FieldInputConfiguration | FieldSelectConfiguration | FieldImagePickerConfiguration | FieldRadioGroupConfiguration | FieldRowConfiguration<TFieldValues> | FieldCheckboxConfiguration | FieldCheckboxListConfiguration | FieldTextareaConfiguration | FieldVoidConfiguration;
35
36
  /**
36
37
  * @backwardscompatibility
37
38
  * @deprecated - this is an alias for `FormFieldConfiguration`, for backwards compatibility the name can remain for now, but
@@ -46,6 +47,9 @@ export interface FieldRowConfiguration<TFieldValues> extends Record<keyof FormFi
46
47
  export interface FieldInputConfiguration extends FormFieldBaseConfiguration<Omit<InputProps, "name">> {
47
48
  type: AllowedTextInputTypes;
48
49
  }
50
+ export interface FieldTextareaConfiguration extends FormFieldBaseConfiguration<Omit<TextareaProps, "name">> {
51
+ type: "textarea";
52
+ }
49
53
  export interface FieldRadioGroupConfiguration extends FormFieldBaseConfiguration<Omit<RadioGroupProps, "name">> {
50
54
  type: "radioGroup";
51
55
  }
@@ -1,22 +1,29 @@
1
- export default Textarea;
2
- declare function Textarea(props: any): JSX.Element;
3
- declare namespace Textarea {
4
- namespace propTypes {
5
- const className: PropTypes.Requireable<string>;
6
- const value: PropTypes.Requireable<string>;
7
- const name: PropTypes.Validator<string>;
8
- const placeholder: PropTypes.Requireable<string>;
9
- const maxLength: PropTypes.Requireable<number>;
10
- const rows: PropTypes.Requireable<number>;
11
- const resizable: PropTypes.Requireable<string>;
12
- const isDisabled: PropTypes.Requireable<boolean>;
13
- const icon: PropTypes.Requireable<string>;
14
- const onChange: PropTypes.Validator<(...args: any[]) => any>;
15
- const onBlur: PropTypes.Requireable<(...args: any[]) => any>;
16
- const onFocus: PropTypes.Requireable<(...args: any[]) => any>;
17
- const onKeyPress: PropTypes.Requireable<(...args: any[]) => any>;
18
- const onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
19
- const onCtrlEnter: PropTypes.Requireable<(...args: any[]) => any>;
20
- }
1
+ import React, { ChangeEvent, FocusEvent, KeyboardEvent } from "react";
2
+ import "./Textarea.scss";
3
+ declare const resizeTypes: {
4
+ readonly NONE: "none";
5
+ readonly BOTH: "both";
6
+ readonly HORIZONTAL: "horizontal";
7
+ readonly VERTICAL: "vertical";
8
+ };
9
+ export declare type ResizeTypes = (typeof resizeTypes)[keyof typeof resizeTypes];
10
+ export interface TextareaProps {
11
+ className?: string;
12
+ value?: string;
13
+ name?: string;
14
+ placeholder?: string;
15
+ maxLength?: number;
16
+ rows?: number;
17
+ resizable?: ResizeTypes;
18
+ isDisabled?: boolean;
19
+ icon?: string;
20
+ onChange: (event: ChangeEvent) => void;
21
+ onBlur?: (event: FocusEvent<HTMLTextAreaElement>) => void;
22
+ onFocus?: (event: FocusEvent<HTMLTextAreaElement>) => void;
23
+ onKeyPress?: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
24
+ onKeyDown?: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
25
+ onCtrlEnter?: () => void;
26
+ isError?: boolean;
21
27
  }
22
- import PropTypes from "prop-types";
28
+ export declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
29
+ export {};
package/dist/index.d.ts CHANGED
@@ -61,7 +61,7 @@ export { PageHeader, PageHeaderProps } from "./components/PageHeader";
61
61
  export { default as TabLinks } from "./components/TabLinks/TabLinks";
62
62
  export { default as Tag } from "./components/Tag/Tag";
63
63
  export { default as TagGroup } from "./components/Tag/TagGroup";
64
- export { default as TextArea } from "./components/Textarea/Textarea";
64
+ export { Textarea, TextareaProps, ResizeTypes, } from "./components/Textarea/Textarea";
65
65
  export { default as TextEditor } from "./components/TextEditor/TextEditor";
66
66
  export { default as TextEditorV2 } from "./components/TextEditorV2/TextEditorV2";
67
67
  export { TextLink, TextLinkProps } from "./components/TextLink/TextLink";
@@ -7,7 +7,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
7
7
  var React = require('react');
8
8
  var React__default = _interopDefault(React);
9
9
  var classNames = _interopDefault(require('classnames'));
10
- var dragula = _interopDefault(require('react-dragula'));
11
10
  var lodash = require('lodash');
12
11
  var core = require('@dnd-kit/core');
13
12
  var sortable = require('@dnd-kit/sortable');
@@ -35,6 +34,7 @@ var htmlToDraft = _interopDefault(require('html-to-draftjs'));
35
34
  require('react-draft-wysiwyg/dist/react-draft-wysiwyg.css');
36
35
  var pick = _interopDefault(require('lodash/pick'));
37
36
  var index_ie11 = require('react-hook-form/dist/index.ie11');
37
+ var reactHookForm = require('react-hook-form');
38
38
 
39
39
  function _regeneratorRuntime() {
40
40
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -2804,71 +2804,79 @@ var _excluded$9 = ["items", "onDragEnd", "onAssetLoadError"];
2804
2804
 
2805
2805
  var DefaultList = function DefaultList(_ref) {
2806
2806
  var items = _ref.items,
2807
- onDragEnd = _ref.onDragEnd,
2807
+ _onDragEnd = _ref.onDragEnd,
2808
2808
  onAssetLoadError = _ref.onAssetLoadError,
2809
2809
  props = _objectWithoutPropertiesLoose(_ref, _excluded$9);
2810
2810
 
2811
- var listRef = React.useRef(null);
2812
- var dragulaRef = React.useRef(null);
2813
- React.useEffect(function () {
2814
- var _dragulaRef$current;
2815
-
2816
- (_dragulaRef$current = dragulaRef.current) == null ? void 0 : _dragulaRef$current.destroy == null ? void 0 : _dragulaRef$current.destroy();
2811
+ var sensor = core.useSensor(core.MouseSensor);
2817
2812
 
2818
- if (listRef.current && onDragEnd && items.length) {
2819
- dragulaRef.current = setupDragging();
2820
- }
2813
+ var _useState = React.useState(null),
2814
+ draggedListItem = _useState[0],
2815
+ setDraggedListItem = _useState[1];
2821
2816
 
2822
- return function () {
2823
- var _dragulaRef$current2;
2817
+ var _useState2 = React.useState(items),
2818
+ innerItems = _useState2[0],
2819
+ setInnerItems = _useState2[1];
2824
2820
 
2825
- (_dragulaRef$current2 = dragulaRef.current) == null ? void 0 : _dragulaRef$current2.destroy == null ? void 0 : _dragulaRef$current2.destroy();
2826
- };
2827
- }, [items, listRef]);
2821
+ React.useEffect(function () {
2822
+ setInnerItems(items);
2823
+ }, [items]);
2828
2824
 
2829
- var handleDragEnd = function handleDragEnd(element) {
2830
- var draggedItemId = element.dataset["id"];
2825
+ if (!_onDragEnd) {
2826
+ return /*#__PURE__*/React__default.createElement(BaseList, _extends({
2827
+ itemComponent: ListItem,
2828
+ items: items.map(function (item) {
2829
+ return _extends({}, item, {
2830
+ isDraggable: false,
2831
+ onAssetLoadError: onAssetLoadError
2832
+ });
2833
+ })
2834
+ }, props));
2835
+ }
2831
2836
 
2832
- if (listRef.current && draggedItemId) {
2833
- var itemIdsWithOldOrder = items.map(function (item) {
2834
- return item.itemId.toString();
2835
- });
2836
- var itemIdsWithNewOrder = Array.from(listRef.current.children).map(function (child) {
2837
- return child.dataset["id"];
2838
- }).filter(function (itemId) {
2839
- return !!itemId;
2840
- });
2841
- var oldIndexOfDraggedItemId = itemIdsWithOldOrder.indexOf(draggedItemId);
2842
- var newIndexOfDraggedItemId = itemIdsWithNewOrder.indexOf(draggedItemId);
2837
+ return /*#__PURE__*/React__default.createElement(core.DndContext, {
2838
+ sensors: [sensor],
2839
+ onDragStart: function onDragStart(event) {
2840
+ setDraggedListItem(getDndListItemProps(event.active));
2841
+ },
2842
+ onDragEnd: function onDragEnd(event) {
2843
+ var _event$active, _event$active$data, _event$active$data$cu, _event$active$data$cu2, _event$over, _event$over$data, _event$over$data$curr, _event$over$data$curr2;
2843
2844
 
2844
- if (oldIndexOfDraggedItemId !== newIndexOfDraggedItemId) {
2845
- onDragEnd == null ? void 0 : onDragEnd(draggedItemId, newIndexOfDraggedItemId);
2845
+ if (!draggedListItem) {
2846
+ return;
2846
2847
  }
2847
- }
2848
- };
2849
2848
 
2850
- var setupDragging = function setupDragging() {
2851
- if (!listRef.current) {
2852
- return null;
2853
- }
2849
+ var currentIndex = (_event$active = event.active) == null ? void 0 : (_event$active$data = _event$active.data) == null ? void 0 : (_event$active$data$cu = _event$active$data.current) == null ? void 0 : (_event$active$data$cu2 = _event$active$data$cu.sortable) == null ? void 0 : _event$active$data$cu2.index;
2850
+ var newIndex = (_event$over = event.over) == null ? void 0 : (_event$over$data = _event$over.data) == null ? void 0 : (_event$over$data$curr = _event$over$data.current) == null ? void 0 : (_event$over$data$curr2 = _event$over$data$curr.sortable) == null ? void 0 : _event$over$data$curr2.index;
2854
2851
 
2855
- var dragulaInstance = dragula([listRef.current], {
2856
- revertOnSpill: true
2857
- });
2858
- dragulaInstance.on("dragend", handleDragEnd);
2859
- return dragulaInstance;
2860
- };
2852
+ if (typeof currentIndex === "number" && typeof newIndex === "number") {
2853
+ setInnerItems(sortable.arrayMove(innerItems, currentIndex, newIndex));
2861
2854
 
2862
- return /*#__PURE__*/React__default.createElement(BaseList, _extends({
2863
- ref: listRef,
2864
- itemComponent: ListItem,
2865
- items: items.map(function (item) {
2855
+ _onDragEnd(draggedListItem.itemId, newIndex);
2856
+ }
2857
+
2858
+ setDraggedListItem(null);
2859
+ }
2860
+ }, /*#__PURE__*/React__default.createElement(SortableBaseList, _extends({
2861
+ draggableIdentifier: "sortable-list-identifier",
2862
+ items: innerItems.map(function (item) {
2866
2863
  return _extends({}, item, {
2867
- isDraggable: !!onDragEnd,
2864
+ draggableIdentifier: "" + item.itemId,
2865
+ isDraggable: true,
2868
2866
  onAssetLoadError: onAssetLoadError
2869
2867
  });
2870
2868
  })
2871
- }, props));
2869
+ }, props)), /*#__PURE__*/React__default.createElement(core.DragOverlay, {
2870
+ dropAnimation: null,
2871
+ wrapperElement: "ul",
2872
+ className: "shadow-lg"
2873
+ }, draggedListItem && /*#__PURE__*/React__default.createElement(ListItem, _extends({}, draggedListItem, {
2874
+ renderDragHandle: function renderDragHandle() {
2875
+ return /*#__PURE__*/React__default.createElement(DragHandle, {
2876
+ grabbing: true
2877
+ });
2878
+ }
2879
+ }))));
2872
2880
  }; // Rest operator isn't used here because TS seems to require the operation
2873
2881
  // happening in the branch of the code where the object is used in
2874
2882
 
@@ -7827,50 +7835,32 @@ var css_248z$p = ".cweb-textarea {\n border: 1px solid #cccccc;\n border-radiu
7827
7835
  styleInject(css_248z$p);
7828
7836
 
7829
7837
  var _excluded$s = ["className", "value", "name", "placeholder", "maxLength", "rows", "resizable", "isDisabled", "icon", "onChange", "onBlur", "onFocus", "onKeyPress", "onKeyDown", "onCtrlEnter"];
7830
- var RESIZE_TYPES = {
7838
+ var resizeTypes = {
7831
7839
  NONE: "none",
7832
7840
  BOTH: "both",
7833
7841
  HORIZONTAL: "horizontal",
7834
7842
  VERTICAL: "vertical"
7835
7843
  };
7836
- Textarea.propTypes = {
7837
- className: PropTypes.string,
7838
- value: PropTypes.string,
7839
- name: PropTypes.string.isRequired,
7840
- placeholder: PropTypes.string,
7841
- maxLength: PropTypes.number,
7842
- rows: PropTypes.number,
7843
- resizable: /*#__PURE__*/PropTypes.oneOf([RESIZE_TYPES.BOTH, RESIZE_TYPES.HORIZONTAL, RESIZE_TYPES.VERTICAL, RESIZE_TYPES.NONE]),
7844
- isDisabled: PropTypes.bool,
7845
- icon: PropTypes.string,
7846
- onChange: PropTypes.func.isRequired,
7847
- onBlur: PropTypes.func,
7848
- onFocus: PropTypes.func,
7849
- onKeyPress: PropTypes.func,
7850
- onKeyDown: PropTypes.func,
7851
- onCtrlEnter: PropTypes.func
7852
- };
7853
-
7854
- function Textarea(props) {
7855
- var className = props.className,
7856
- value = props.value,
7857
- name = props.name,
7858
- placeholder = props.placeholder,
7859
- maxLength = props.maxLength,
7860
- _props$rows = props.rows,
7861
- rows = _props$rows === void 0 ? 4 : _props$rows,
7862
- _props$resizable = props.resizable,
7863
- resizable = _props$resizable === void 0 ? RESIZE_TYPES.VERTICAL : _props$resizable,
7864
- _props$isDisabled = props.isDisabled,
7865
- isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
7866
- icon = props.icon,
7867
- onChange = props.onChange,
7868
- onBlur = props.onBlur,
7869
- onFocus = props.onFocus,
7870
- onKeyPress = props.onKeyPress,
7871
- _onKeyDown = props.onKeyDown,
7872
- onCtrlEnter = props.onCtrlEnter,
7873
- otherProps = _objectWithoutPropertiesLoose(props, _excluded$s);
7844
+ var Textarea = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
7845
+ var className = _ref.className,
7846
+ value = _ref.value,
7847
+ name = _ref.name,
7848
+ placeholder = _ref.placeholder,
7849
+ maxLength = _ref.maxLength,
7850
+ _ref$rows = _ref.rows,
7851
+ rows = _ref$rows === void 0 ? 4 : _ref$rows,
7852
+ _ref$resizable = _ref.resizable,
7853
+ resizable = _ref$resizable === void 0 ? resizeTypes.VERTICAL : _ref$resizable,
7854
+ _ref$isDisabled = _ref.isDisabled,
7855
+ isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
7856
+ icon = _ref.icon,
7857
+ onChange = _ref.onChange,
7858
+ onBlur = _ref.onBlur,
7859
+ onFocus = _ref.onFocus,
7860
+ onKeyPress = _ref.onKeyPress,
7861
+ _onKeyDown = _ref.onKeyDown,
7862
+ onCtrlEnter = _ref.onCtrlEnter,
7863
+ otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$s);
7874
7864
 
7875
7865
  var style;
7876
7866
 
@@ -7889,7 +7879,7 @@ function Textarea(props) {
7889
7879
  onFocus: onFocus,
7890
7880
  onKeyPress: onKeyPress,
7891
7881
  onKeyDown: function onKeyDown(event) {
7892
- _onKeyDown == null ? void 0 : _onKeyDown();
7882
+ _onKeyDown == null ? void 0 : _onKeyDown(event);
7893
7883
  var ctrlKey = event.ctrlKey,
7894
7884
  metaKey = event.metaKey,
7895
7885
  key = event.key;
@@ -7903,13 +7893,14 @@ function Textarea(props) {
7903
7893
  disabled: isDisabled,
7904
7894
  className: classNames("cweb-textarea", className, "p-2", "border", "placeholder-gray-500", "text-sm", "border-solid", "border-input-border", "hover:border-input-border-dark", "focus:outline-primary", "transition-colors", "duration-300", "w-full", "focus:border-primary", {
7905
7895
  "has-icon": !!icon,
7906
- resizable: resizable === RESIZE_TYPES.BOTH,
7907
- "resizable-x": resizable === RESIZE_TYPES.HORIZONTAL,
7908
- "resizable-y": resizable === RESIZE_TYPES.VERTICAL
7896
+ resizable: resizable === resizeTypes.BOTH,
7897
+ "resizable-x": resizable === resizeTypes.HORIZONTAL,
7898
+ "resizable-y": resizable === resizeTypes.VERTICAL
7909
7899
  }),
7910
- style: style
7900
+ style: style,
7901
+ ref: ref
7911
7902
  }));
7912
- }
7903
+ });
7913
7904
 
7914
7905
  var css_248z$q = ".ql-editor {\n resize: vertical;\n min-height: 10rem;\n}\n\n.ql-snow.ql-toolbar {\n display: block;\n background: #f1f5f9;\n border-top-left-radius: 0.5em;\n border-top-right-radius: 0.5em;\n margin-top: 0.5em;\n}";
7915
7906
  styleInject(css_248z$q);
@@ -8506,6 +8497,42 @@ var FormFieldCheckboxList = function FormFieldCheckboxList(_ref) {
8506
8497
  }));
8507
8498
  };
8508
8499
 
8500
+ var _excluded$z = ["control", "name", "rules", "fieldErrors", "fieldRequired", "label", "info", "decoratorClassname"];
8501
+ /**
8502
+ * Input field that can be used in any react-hook-form context.
8503
+ */
8504
+
8505
+ var FormTextarea = /*#__PURE__*/React__default.forwardRef(function (_ref, innerRef) {
8506
+ var control = _ref.control,
8507
+ name = _ref.name,
8508
+ rules = _ref.rules,
8509
+ fieldErrors = _ref.fieldErrors,
8510
+ fieldRequired = _ref.fieldRequired,
8511
+ label = _ref.label,
8512
+ info = _ref.info,
8513
+ decoratorClassname = _ref.decoratorClassname,
8514
+ fieldProps = _objectWithoutPropertiesLoose(_ref, _excluded$z);
8515
+
8516
+ return /*#__PURE__*/React__default.createElement(FormFieldLabeler, {
8517
+ name: name,
8518
+ fieldErrors: fieldErrors,
8519
+ fieldRequired: fieldRequired,
8520
+ label: label,
8521
+ info: info,
8522
+ decoratorClassname: decoratorClassname
8523
+ }, /*#__PURE__*/React__default.createElement(reactHookForm.Controller, {
8524
+ name: name,
8525
+ control: control,
8526
+ rules: rules,
8527
+ render: function render(field) {
8528
+ return /*#__PURE__*/React__default.createElement(Textarea, _extends({}, fieldProps, field, {
8529
+ isError: hasError(name, fieldErrors),
8530
+ ref: innerRef
8531
+ }));
8532
+ }
8533
+ }));
8534
+ });
8535
+
8509
8536
  /**
8510
8537
  * Create a straight forward Form, which takes away the 'overhead' of react-hook-form.
8511
8538
  *
@@ -8662,6 +8689,20 @@ function FormFieldMapper(formFieldProps, useFormReturn) {
8662
8689
  }));
8663
8690
  }
8664
8691
 
8692
+ case "textarea":
8693
+ {
8694
+ return /*#__PURE__*/React__default.createElement(FormTextarea, _extends({
8695
+ key: name
8696
+ }, decoratorProps, {
8697
+ fieldRequired: isRequired(options),
8698
+ fieldErrors: errors,
8699
+ type: "textarea",
8700
+ name: name,
8701
+ rules: options,
8702
+ control: control
8703
+ }, fieldProps));
8704
+ }
8705
+
8665
8706
  case "void":
8666
8707
  return null;
8667
8708
 
@@ -8841,10 +8882,10 @@ exports.Tag = Tag;
8841
8882
  exports.TagGroup = TagGroup;
8842
8883
  exports.TertiaryButton = TertiaryButton;
8843
8884
  exports.Text = Text;
8844
- exports.TextArea = Textarea;
8845
8885
  exports.TextEditor = TextEditor;
8846
8886
  exports.TextEditorV2 = TextEditorV2;
8847
8887
  exports.TextLink = TextLink;
8888
+ exports.Textarea = Textarea;
8848
8889
  exports.Timeline = Timeline;
8849
8890
  exports.Title = Title;
8850
8891
  exports.Toaster = Toaster;