ar-design 0.3.84 → 0.3.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.
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
2
  import "../../../assets/css/components/form/switch/styles.css";
3
3
  import IProps from "./IProps";
4
- declare const Switch: React.FC<IProps>;
4
+ declare const Switch: React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLInputElement>>;
5
5
  export default Switch;
@@ -1,9 +1,10 @@
1
1
  "use client";
2
- import React, { useEffect, useRef, useState } from "react";
2
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
3
3
  import "../../../assets/css/components/form/switch/styles.css";
4
4
  import Utils from "../../../libs/infrastructure/shared/Utils";
5
- const Switch = ({ label, color, border = { radius: "pill" }, ...attributes }) => {
5
+ const Switch = forwardRef(({ label, color, border = { radius: "pill" }, ...attributes }, ref) => {
6
6
  // refs
7
+ let _switchInput = useRef(null);
7
8
  let _switch = useRef(null);
8
9
  const _inputClassName = [];
9
10
  const _switchClassName = ["ar-switch"];
@@ -11,13 +12,16 @@ const Switch = ({ label, color, border = { radius: "pill" }, ...attributes }) =>
11
12
  const [checked, setChecked] = useState(attributes.checked ?? false);
12
13
  _inputClassName.push(attributes.checked ? "checked" : "unchecked");
13
14
  _switchClassName.push(...Utils.GetClassName(undefined, undefined, attributes.checked ? color : "light", border, undefined, undefined, attributes.className));
15
+ // hooks
16
+ // Dışarıdan gelen ref'i _innerRef'e bağla.
17
+ useImperativeHandle(ref, () => _switchInput.current);
14
18
  // useEffects
15
19
  useEffect(() => {
16
20
  setChecked(attributes.checked ?? false);
17
21
  }, [attributes.checked]);
18
22
  return (React.createElement("div", { className: "ar-switch-wrapper" },
19
23
  React.createElement("label", null,
20
- React.createElement("input", { type: "checkbox", ...attributes, className: _inputClassName.map((c) => c).join(" "), checked: checked, size: 0, onChange: (event) => {
24
+ React.createElement("input", { ref: _switchInput, type: "checkbox", ...attributes, className: _inputClassName.map((c) => c).join(" "), checked: checked, size: 0, onChange: (event) => {
21
25
  event.stopPropagation();
22
26
  (() => {
23
27
  setChecked(event.target.checked);
@@ -27,6 +31,6 @@ const Switch = ({ label, color, border = { radius: "pill" }, ...attributes }) =>
27
31
  React.createElement("span", { ref: _switch, className: _switchClassName.map((c) => c).join(" ") },
28
32
  React.createElement("span", { className: "handle border-radius-pill" })),
29
33
  label && React.createElement("span", { className: "label" }, label))));
30
- };
34
+ });
31
35
  Switch.displayName = "Switch";
32
36
  export default Switch;
@@ -158,7 +158,7 @@ export const useValidation = function (data, params, step) {
158
158
  const key = getKey(param.subkey);
159
159
  if (param.where) {
160
160
  if (s.type === "required" && param.where(data)) {
161
- Utils.IsNullOrEmpty(value) && setError(param.subkey ? key : param.key, s.message, param.step);
161
+ setError(param.subkey ? key : param.key, s.message, param.step);
162
162
  }
163
163
  }
164
164
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.3.84",
3
+ "version": "0.3.86",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",