@arkyn/components 3.0.1-beta.84 → 3.0.1-beta.86

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.
@@ -114,8 +114,8 @@ function Select(props) {
114
114
  const iconSize = iconSizes[size];
115
115
  const [search, setSearch] = useState("");
116
116
  const [isFocused, setIsFocused] = useState(false);
117
- const [selectedOptions, setSelectedOptions] = useState(defaultValue);
118
- const forceSelectedOptions = value || selectedOptions;
117
+ const [selectedOption, setSelectedOption] = useState(defaultValue);
118
+ const forceSelectedOptions = value || selectedOption;
119
119
  function optionHasSelected(value) {
120
120
  return forceSelectedOptions === value;
121
121
  }
@@ -142,12 +142,12 @@ function Select(props) {
142
142
  }
143
143
  function handleChangeValue(value) {
144
144
  if (optionHasSelected(value)) {
145
- setSelectedOptions("");
145
+ setSelectedOption("");
146
146
  if (onChange)
147
147
  onChange("");
148
148
  }
149
149
  else {
150
- setSelectedOptions(value);
150
+ setSelectedOption(value);
151
151
  if (onChange)
152
152
  onChange(value);
153
153
  }
@@ -163,6 +163,6 @@ function Select(props) {
163
163
  return true;
164
164
  return false;
165
165
  });
166
- return (_jsxs(FieldWrapper, { children: [label && _jsx(FieldLabel, { showAsterisk: showAsterisk, children: label }), _jsxs(SelectContainer, { handleContainerFocus: handleContainerFocus, disabled: disabled, isError: isError, isFocused: isFocused, isLoading: isLoading, readOnly: readOnly, size: size, variant: variant, className: className, prefixExists: !!prefix, id: selectId, children: [_jsx("input", { ref: selectRef, name: name, value: JSON.stringify(forceSelectedOptions), type: "hidden" }), _jsx(IconRenderer, { iconSize: iconSize, icon: prefix, className: "prefix" }), LeftIcon && _jsx(LeftIcon, { size: iconSize, strokeWidth: 2.5 }), _jsxs(SelectContent, { size: size, children: [forceSelectedOptions !== "" && (_jsx("p", { children: getOptionLabel(forceSelectedOptions) })), forceSelectedOptions === "" && _jsx("p", { children: placeholder })] }), _jsxs(SelectOptionsContainer, { isFocused: isFocused, isSearchable: isSearchable, search: search, onSearch: handleSearch, children: [mappedOptions.map(({ label, value }) => (_jsx(SelectOption, { label: label, value: value, size: size, handleChangeValue: handleChangeValue, optionHasSelected: optionHasSelected }, value))), mappedOptions.length <= 0 && _jsx("p", { children: notFoundText })] }), _jsx(SelectChevron, { disabled: disabled, isFocused: isFocused, readOnly: readOnly, iconSize: iconSize, isLoading: isLoading }), _jsx(SelectSpinner, { iconSize: iconSize, isLoading: isLoading }), _jsx(SelectOverlay, { handleBlur: handleBlur, isFocused: isFocused })] }), errorMessage && _jsx(FieldError, { children: errorMessage })] }));
166
+ return (_jsxs(FieldWrapper, { children: [label && _jsx(FieldLabel, { showAsterisk: showAsterisk, children: label }), _jsxs(SelectContainer, { handleContainerFocus: handleContainerFocus, disabled: disabled, isError: isError, isFocused: isFocused, isLoading: isLoading, readOnly: readOnly, size: size, variant: variant, className: className, prefixExists: !!prefix, id: selectId, children: [_jsx("input", { ref: selectRef, name: name, value: forceSelectedOptions, type: "hidden" }), _jsx(IconRenderer, { iconSize: iconSize, icon: prefix, className: "prefix" }), LeftIcon && _jsx(LeftIcon, { size: iconSize, strokeWidth: 2.5 }), _jsxs(SelectContent, { size: size, children: [forceSelectedOptions !== "" && (_jsx("p", { children: getOptionLabel(forceSelectedOptions) })), forceSelectedOptions === "" && _jsx("p", { children: placeholder })] }), _jsxs(SelectOptionsContainer, { isFocused: isFocused, isSearchable: isSearchable, search: search, onSearch: handleSearch, children: [mappedOptions.map(({ label, value }) => (_jsx(SelectOption, { label: label, value: value, size: size, handleChangeValue: handleChangeValue, optionHasSelected: optionHasSelected }, value))), mappedOptions.length <= 0 && _jsx("p", { children: notFoundText })] }), _jsx(SelectChevron, { disabled: disabled, isFocused: isFocused, readOnly: readOnly, iconSize: iconSize, isLoading: isLoading }), _jsx(SelectSpinner, { iconSize: iconSize, isLoading: isLoading }), _jsx(SelectOverlay, { handleBlur: handleBlur, isFocused: isFocused })] }), errorMessage && _jsx(FieldError, { children: errorMessage })] }));
167
167
  }
168
168
  export { Select };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Hook for automating actions based on form data.
3
+ *
4
+ * This hook automates the closing of modals and the display of giveaways
5
+ * based on the properties provided in the formResponseData object.
6
+ *
7
+ * @param {Object} formResponseData - Object containing form data for automation
8
+ * @param {boolean} [formResponseData.closeModal] - If true, closes all open modals
9
+ * @param {string} [formResponseData.message] - Message to be displayed in the giveaway
10
+ * @param {"success" | "danger"} [formResponseData.type] - Type of giveaway to be displayed
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * // Basic usage example
15
+ * const formResponseData = {
16
+ * closeModal: true,
17
+ * message: "Operation successfully completed!",
18
+ * type: "success"
19
+ * };
20
+ *
21
+ * useAutomation(formResponseData);
22
+ * ```
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * // Use with only modal closing
27
+ * const formResponseData = {
28
+ * closeModal: true
29
+ * };
30
+ *
31
+ * useAutomation(formResponseData);
32
+ * ```
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * // Use with only error message display
37
+ * const formResponseData = {
38
+ * message: "Error processing request",
39
+ * type: "danger" // "success" | "danger"
40
+ * };
41
+ *
42
+ * useAutomation(formResponseData);
43
+ * ```
44
+ */
45
+ declare function useAutomation(formResponseData: any): void;
46
+ export { useAutomation };
47
+ //# sourceMappingURL=useAutomation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,iBAAS,aAAa,CAAC,gBAAgB,EAAE,GAAG,QAa3C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { useEffect } from "react";
2
+ import { useModal } from "./useModal";
3
+ import { useToast } from "./useToast";
4
+ /**
5
+ * Hook for automating actions based on form data.
6
+ *
7
+ * This hook automates the closing of modals and the display of giveaways
8
+ * based on the properties provided in the formResponseData object.
9
+ *
10
+ * @param {Object} formResponseData - Object containing form data for automation
11
+ * @param {boolean} [formResponseData.closeModal] - If true, closes all open modals
12
+ * @param {string} [formResponseData.message] - Message to be displayed in the giveaway
13
+ * @param {"success" | "danger"} [formResponseData.type] - Type of giveaway to be displayed
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * // Basic usage example
18
+ * const formResponseData = {
19
+ * closeModal: true,
20
+ * message: "Operation successfully completed!",
21
+ * type: "success"
22
+ * };
23
+ *
24
+ * useAutomation(formResponseData);
25
+ * ```
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * // Use with only modal closing
30
+ * const formResponseData = {
31
+ * closeModal: true
32
+ * };
33
+ *
34
+ * useAutomation(formResponseData);
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * // Use with only error message display
40
+ * const formResponseData = {
41
+ * message: "Error processing request",
42
+ * type: "danger" // "success" | "danger"
43
+ * };
44
+ *
45
+ * useAutomation(formResponseData);
46
+ * ```
47
+ */
48
+ function useAutomation(formResponseData) {
49
+ const { closeAll } = useModal();
50
+ const { showToast } = useToast();
51
+ const closeModal = formResponseData?.closeModal;
52
+ const message = formResponseData?.message;
53
+ const type = formResponseData?.type;
54
+ useEffect(() => {
55
+ if (closeModal)
56
+ closeAll();
57
+ if (message && type === "success")
58
+ showToast({ message, type: "success" });
59
+ if (message && type === "danger")
60
+ showToast({ message, type: "danger" });
61
+ }, [formResponseData]);
62
+ }
63
+ export { useAutomation };
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export { TableFooter } from "./components/table/tableFooter";
44
44
  export { TableHeader } from "./components/table/tableHeader";
45
45
  export { Textarea } from "./components/textarea";
46
46
  export { Tooltip } from "./components/tooltip";
47
+ export { useAutomation } from "./hooks/useAutomation";
47
48
  export { useDrawer } from "./hooks/useDrawer";
48
49
  export { useForm } from "./hooks/useForm";
49
50
  export { useHydrated } from "./hooks/useHydrated";
@@ -1 +1 @@
1
- {"version":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AmB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ export { TableHeader } from "./components/table/tableHeader";
46
46
  export { Textarea } from "./components/textarea";
47
47
  export { Tooltip } from "./components/tooltip";
48
48
  // hooks
49
+ export { useAutomation } from "./hooks/useAutomation";
49
50
  export { useDrawer } from "./hooks/useDrawer";
50
51
  export { useForm } from "./hooks/useForm";
51
52
  export { useHydrated } from "./hooks/useHydrated";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "3.0.1-beta.84",
3
+ "version": "3.0.1-beta.86",
4
4
  "main": "./dist/bundle.js",
5
5
  "module": "./dist/bundle.js",
6
6
  "types": "./dist/index.d.ts",