ar-design 0.3.67 → 0.3.68

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,20 @@
1
+ .ar-input-otp-wrapper {
2
+ display: flex;
3
+ flex-direction: row;
4
+ flex-wrap: nowrap;
5
+ justify-content: center;
6
+ align-items: center;
7
+ gap: 0.5rem;
8
+
9
+ > span {
10
+ > .ar-input-wrapper {
11
+ > .ar-input {
12
+ > .input {
13
+ > input {
14
+ text-align: center !important;
15
+ }
16
+ }
17
+ }
18
+ }
19
+ }
20
+ }
@@ -101,6 +101,9 @@
101
101
  }
102
102
  }
103
103
 
104
+ /* OTP */
105
+ @import url("./otp/styles.css");
106
+
104
107
  /* Core Css */
105
108
  @import url("./core/icon.css");
106
109
  @import url("./core/border.css");
@@ -3,7 +3,6 @@ import React, { useState } from "react";
3
3
  import Input from "../../form/input";
4
4
  import DatePicker from "../../form/date-picker";
5
5
  import Select from "../../form/select";
6
- import InputNumber from "../../form/input-number";
7
6
  const Editable = function ({ c, item, index, onEditable, validation }) {
8
7
  const key = c.key;
9
8
  const itemValue = item[c.key];
@@ -23,7 +22,7 @@ const Editable = function ({ c, item, index, onEditable, validation }) {
23
22
  onEditable({ ...item, [key]: c.editable?.type === "number" ? Number(value) : value }, index);
24
23
  }, validation: { text: _vText } }));
25
24
  case "input-number":
26
- return (React.createElement(InputNumber, { variant: "borderless", name: c.key, value: value, onChange: (event) => {
25
+ return (React.createElement(Input.Number, { variant: "borderless", name: c.key, value: value, onChange: (event) => {
27
26
  const { value } = event.target;
28
27
  setValue(value);
29
28
  onEditable({ ...item, [key]: c.editable?.type === "number" ? Number(value) : value }, index);
@@ -1,7 +1,7 @@
1
- import { IBorder, IColors, ISize, IStatus, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
1
+ import { IBorder, IColors, IStatus, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
2
2
  type Props = {
3
3
  label?: string;
4
4
  isClock?: boolean;
5
5
  onChange: (value: string) => void;
6
- } & IVariant & IColors & IStatus & IBorder & ISize & IValidation & Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "onChange" | "size" | "color">;
6
+ } & IVariant & IColors & IStatus & IBorder & IValidation & Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "onChange" | "color">;
7
7
  export default Props;
@@ -1,7 +1,7 @@
1
1
  import IButtonProps from "../button/IProps";
2
2
  import { Variants } from "../../../libs/types";
3
- import { IBorder, IColors, IIcon, ISize, IUpperCase, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
4
- interface IProps extends IVariant, IColors, IBorder, IIcon, ISize, IUpperCase, IValidation, Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "size" | "color"> {
3
+ import { IBorder, IColors, IIcon, IUpperCase, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
4
+ interface IProps extends IVariant, IColors, IBorder, IIcon, IUpperCase, IValidation, Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "color"> {
5
5
  button?: Omit<IButtonProps, "size" | "shape" | "position" | "fullWidth">;
6
6
  addon?: {
7
7
  variant?: Variants;
@@ -1,5 +1,11 @@
1
1
  import React from "react";
2
- import "../../../assets/css/components/form/input/input.css";
2
+ import "../../../assets/css/components/form/input/styles.css";
3
3
  import IProps from "./IProps";
4
- declare const Input: React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLInputElement>>;
4
+ import Otp from "./otp/Otp";
5
+ import Num from "./num";
6
+ interface InputCompound extends React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLInputElement>> {
7
+ Number: typeof Num;
8
+ Otp: typeof Otp;
9
+ }
10
+ declare const Input: InputCompound;
5
11
  export default Input;
@@ -1,10 +1,12 @@
1
1
  "use client";
2
2
  import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
3
- import "../../../assets/css/components/form/input/input.css";
3
+ import "../../../assets/css/components/form/input/styles.css";
4
4
  import Button from "../button";
5
5
  import Utils from "../../../libs/infrastructure/shared/Utils";
6
6
  import { ARIcon } from "../../icons";
7
- const Input = forwardRef(({ variant = "outlined", color = "light", size = "normal", icon, border = { radius: "sm" }, button, addon, upperCase, validation, ...attributes }, ref) => {
7
+ import Otp from "./otp/Otp";
8
+ import Num from "./num";
9
+ const BaseInput = forwardRef(({ variant = "outlined", color = "light", icon, border = { radius: "sm" }, button, addon, upperCase, validation, ...attributes }, ref) => {
8
10
  // refs
9
11
  const _innerRef = useRef(null);
10
12
  const _label = useRef(null);
@@ -18,7 +20,7 @@ const Input = forwardRef(({ variant = "outlined", color = "light", size = "norma
18
20
  const _inputClassName = [];
19
21
  const _addonBeforeClassName = ["addon-before"];
20
22
  const _addonAfterClassName = ["addon-after"];
21
- _inputClassName.push(...Utils.GetClassName(variant, undefined, !Utils.IsNullOrEmpty(validation?.text) ? "red" : color, border, size, icon, attributes.className));
23
+ _inputClassName.push(...Utils.GetClassName(variant, undefined, !Utils.IsNullOrEmpty(validation?.text) ? "red" : color, border, undefined, icon, attributes.className));
22
24
  // addon className
23
25
  if (addon) {
24
26
  _wrapperClassName.push("addon");
@@ -75,7 +77,7 @@ const Input = forwardRef(({ variant = "outlined", color = "light", size = "norma
75
77
  validation && "* ",
76
78
  attributes.placeholder)),
77
79
  React.createElement("div", { className: "input" },
78
- React.createElement("input", { ref: _innerRef, ...attributes, type: attributes.type === "number" ? "text" : attributes.type, placeholder: `${validation ? "* " : ""}${attributes.placeholder ?? ""}`, value: value ?? attributes.value, size: 20, className: _inputClassName.map((c) => c).join(" "), ...(attributes.type === "number"
80
+ React.createElement("input", { ref: _innerRef, ...attributes, type: attributes.type === "number" ? "text" : attributes.type, placeholder: `${validation ? "* " : ""}${attributes.placeholder ?? ""}`, value: value ?? attributes.value, size: attributes.size || 20, className: _inputClassName.map((c) => c).join(" "), ...(attributes.type === "number"
79
81
  ? {
80
82
  onKeyDown: (event) => {
81
83
  const allowedKeys = ["Backspace", "Tab", "ArrowLeft", "ArrowRight", "Delete"];
@@ -138,5 +140,8 @@ const Input = forwardRef(({ variant = "outlined", color = "light", size = "norma
138
140
  addon?.after && React.createElement("span", { className: _addonAfterClassName.map((c) => c).join(" ") }, addon?.after),
139
141
  button && React.createElement(Button, { ...button, border: { radius: border.radius }, disabled: attributes.disabled })));
140
142
  });
141
- Input.displayName = "Input";
143
+ const Input = BaseInput;
144
+ Input.Otp = Otp;
145
+ Input.Number = Num;
146
+ BaseInput.displayName = "Input";
142
147
  export default Input;
@@ -1,4 +1,4 @@
1
- import { IBorder, IColors, IDisabled, IPlaceholder, IUpperCase, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
1
+ import { IBorder, IColors, IDisabled, IPlaceholder, IUpperCase, IValidation, IVariant } from "../../../../libs/types/IGlobalProps";
2
2
  interface IProps extends IVariant, IColors, IBorder, IUpperCase, IValidation, IPlaceholder, IDisabled {
3
3
  name: string;
4
4
  value: string | number | readonly string[] | undefined;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import IProps from "./IProps";
3
+ declare const Num: React.FC<IProps>;
4
+ export default Num;
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import React, { useEffect, useMemo, useRef, useState } from "react";
3
- import Input from "../input";
4
- import { NUMBER } from "../../../libs/infrastructure/shared";
5
- const InputNumber = ({ variant, color, name, value, onChange, locale = "tr-TR", digits, placeholder, validation, disabled, }) => {
3
+ import Input from "..";
4
+ import { NUMBER } from "../../../../libs/infrastructure/shared";
5
+ const Num = ({ variant, color, name, value, onChange, locale = "tr-TR", digits, placeholder, validation, disabled, }) => {
6
6
  // refs
7
7
  // const _firstLoad = useRef<boolean>(false);
8
8
  const _input = useRef(null);
@@ -71,7 +71,7 @@ const InputNumber = ({ variant, color, name, value, onChange, locale = "tr-TR",
71
71
  // setValue(getFormatter.format(Number(value)));
72
72
  // _firstLoad.current = true;
73
73
  // }
74
- setValue(getFormatter.format(Number(value)));
74
+ setValue(getFormatter.format(window.Number(value)));
75
75
  }, [value]);
76
76
  return (React.createElement(Input, { ref: _input, name: name, variant: variant, color: color, value: _value ?? "", type: "text", inputMode: "decimal", onChange: (event) => {
77
77
  // Disabled gelmesi durumunda işlem yapmasına izin verme...
@@ -80,4 +80,4 @@ const InputNumber = ({ variant, color, name, value, onChange, locale = "tr-TR",
80
80
  handleChange(event);
81
81
  }, onClick: handleClick, onKeyUp: handleKeyUp, placeholder: placeholder, validation: validation, disabled: disabled }));
82
82
  };
83
- export default InputNumber;
83
+ export default Num;
@@ -0,0 +1,6 @@
1
+ import { IColors, IVariant } from "../../../../libs/types/IGlobalProps";
2
+ interface IProps extends IVariant, IColors, Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "color"> {
3
+ character: number;
4
+ onChange?: React.ChangeEventHandler<HTMLInputElement>;
5
+ }
6
+ export default IProps;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import IProps from "./IProps";
3
+ declare const Otp: {
4
+ ({ character, onChange, ...attributes }: IProps): React.JSX.Element;
5
+ displayName: string;
6
+ };
7
+ export default Otp;
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import React, { useRef, useCallback } from "react";
3
+ import Input from "..";
4
+ const Otp = ({ character, onChange, ...attributes }) => {
5
+ // refs
6
+ const _inputs = useRef([]);
7
+ const _value = useRef({});
8
+ // methods
9
+ const handleChange = useCallback((index) => (event) => {
10
+ if (attributes.disabled)
11
+ return;
12
+ let { value } = event.target;
13
+ value = value.replace(/\D/g, "");
14
+ _value.current = { ..._value.current, [index]: value };
15
+ onChange?.({
16
+ ...event,
17
+ target: {
18
+ ...event.target,
19
+ name: attributes.name ?? "",
20
+ value: Object.keys(_value.current)
21
+ .sort((a, b) => Number(a) - Number(b))
22
+ .map((key) => _value.current[Number(key)])
23
+ .join(""),
24
+ },
25
+ });
26
+ }, [onChange, attributes.name, attributes.disabled]);
27
+ const handleKeyUp = useCallback((index) => (event) => {
28
+ const { value } = event.currentTarget;
29
+ if (value.length >= 1 && event.key >= "0" && event.key <= "9") {
30
+ _inputs.current[index + 1]?.focus();
31
+ _inputs.current[index + 1]?.select();
32
+ }
33
+ if (event.key === "ArrowLeft") {
34
+ _inputs.current[index - 1]?.focus();
35
+ _inputs.current[index - 1]?.select();
36
+ }
37
+ else if (event.key === "ArrowRight") {
38
+ _inputs.current[index + 1]?.focus();
39
+ _inputs.current[index + 1]?.select();
40
+ }
41
+ if (event.key === "Backspace" && value.length === 0) {
42
+ _inputs.current[index - 1]?.focus();
43
+ _inputs.current[index - 1]?.select();
44
+ }
45
+ }, []);
46
+ const handleClick = useCallback((event) => {
47
+ const input = event.currentTarget;
48
+ if (document.activeElement === input)
49
+ input.select();
50
+ }, []);
51
+ return (React.createElement("div", { className: "ar-input-otp-wrapper" }, Array.from({ length: character }, (_, index) => (React.createElement("span", { key: index },
52
+ React.createElement(Input, { ref: (el) => {
53
+ _inputs.current[index] = el;
54
+ }, ...attributes, value: _value.current[index] ?? "", onChange: handleChange(index), onKeyUp: handleKeyUp(index), onFocus: (event) => event.target.select(), onClick: handleClick, size: 1, placeholder: undefined, autoFocus: index === 0, autoComplete: "off" }))))));
55
+ };
56
+ Otp.displayName = "Input.Otp";
57
+ export default Otp;
@@ -1,4 +1,4 @@
1
- import { IBorder, IIcon, ISize, IStatus, IUpperCase, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
2
- interface IProps extends IVariant, IStatus, IBorder, IIcon, ISize, IUpperCase, IValidation, Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "size" | "color"> {
1
+ import { IBorder, IIcon, IStatus, IUpperCase, IValidation, IVariant } from "../../../libs/types/IGlobalProps";
2
+ interface IProps extends IVariant, IStatus, IBorder, IIcon, IUpperCase, IValidation, Omit<React.InputHTMLAttributes<HTMLInputElement>, "children" | "color"> {
3
3
  }
4
4
  export default IProps;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,6 @@ import ButtonGroup from "./components/form/button-group";
5
5
  import Checkbox from "./components/form/checkbox";
6
6
  import DatePicker from "./components/form/date-picker";
7
7
  import Input from "./components/form/input";
8
- import InputNumber from "./components/form/input-number";
9
8
  import InputTag from "./components/form/input-tag";
10
9
  import Radio from "./components/form/radio";
11
10
  import Select from "./components/form/select";
@@ -35,4 +34,4 @@ import Pagination from "./components/navigation/pagination";
35
34
  import Steps from "./components/navigation/steps";
36
35
  import Grid from "./components/data-display/grid-system";
37
36
  import Layout from "./components/layout";
38
- export { Button, ButtonAction, ButtonGroup, Checkbox, DatePicker, Input, InputNumber, InputTag, Radio, Select, Switch, TextEditor, Upload, Card, Chip, Diagram, Divider, DnD, KanbanBoard, Paper, SyntaxHighlighter, Table, Tabs, Typography, Alert, Drawer, Modal, Popover, Progress, Tooltip, Breadcrumb, Menu, Pagination, Steps, Grid, Layout, };
37
+ export { Button, ButtonAction, ButtonGroup, Checkbox, DatePicker, Input, InputTag, Radio, Select, Switch, TextEditor, Upload, Card, Chip, Diagram, Divider, DnD, KanbanBoard, Paper, SyntaxHighlighter, Table, Tabs, Typography, Alert, Drawer, Modal, Popover, Progress, Tooltip, Breadcrumb, Menu, Pagination, Steps, Grid, Layout, };
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ import ButtonGroup from "./components/form/button-group";
6
6
  import Checkbox from "./components/form/checkbox";
7
7
  import DatePicker from "./components/form/date-picker";
8
8
  import Input from "./components/form/input";
9
- import InputNumber from "./components/form/input-number";
10
9
  import InputTag from "./components/form/input-tag";
11
10
  import Radio from "./components/form/radio";
12
11
  import Select from "./components/form/select";
@@ -42,7 +41,7 @@ import Grid from "./components/data-display/grid-system";
42
41
  import Layout from "./components/layout";
43
42
  export {
44
43
  // Form Elements
45
- Button, ButtonAction, ButtonGroup, Checkbox, DatePicker, Input, InputNumber, InputTag, Radio, Select, Switch, TextEditor, Upload,
44
+ Button, ButtonAction, ButtonGroup, Checkbox, DatePicker, Input, InputTag, Radio, Select, Switch, TextEditor, Upload,
46
45
  // Data Display
47
46
  Card, Chip, Diagram, Divider, DnD, KanbanBoard, Paper, SyntaxHighlighter, Table, Tabs, Typography,
48
47
  // Feedback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.3.67",
3
+ "version": "0.3.68",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1,4 +0,0 @@
1
- import React from "react";
2
- import IProps from "./IProps";
3
- declare const InputNumber: React.FC<IProps>;
4
- export default InputNumber;