react-restyle-components 0.1.44 → 0.1.45

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.
Files changed (127) hide show
  1. package/lib/cjs/App.js +36 -12
  2. package/lib/cjs/App.test.js +10 -8
  3. package/lib/cjs/core-components/atoms/buttons/button.stories.js +26 -24
  4. package/lib/cjs/core-components/atoms/buttons/buttons.component.js +27 -9
  5. package/lib/cjs/core-components/atoms/buttons/buttons.test.js +15 -7
  6. package/lib/cjs/core-components/atoms/check-box/checkBox.component.js +102 -35
  7. package/lib/cjs/core-components/atoms/check-box/checkBox.stories.js +17 -17
  8. package/lib/cjs/core-components/atoms/check-box/checkBox.test.js +15 -7
  9. package/lib/cjs/core-components/atoms/date-picker/date-picker.component.js +98 -37
  10. package/lib/cjs/core-components/atoms/date-picker/date-picker.stories.js +17 -15
  11. package/lib/cjs/core-components/atoms/date-picker/date-picker.test.js +16 -7
  12. package/lib/cjs/core-components/atoms/form/form.component.js +571 -159
  13. package/lib/cjs/core-components/atoms/form/form.test.js +87 -59
  14. package/lib/cjs/core-components/atoms/icons/icons.component.js +40 -26
  15. package/lib/cjs/core-components/atoms/input/input-otp.component.js +118 -76
  16. package/lib/cjs/core-components/atoms/input/input-pin.component.js +180 -98
  17. package/lib/cjs/core-components/atoms/input/input-pin.stories.js +14 -14
  18. package/lib/cjs/core-components/atoms/input/input-pin.test.js +28 -10
  19. package/lib/cjs/core-components/atoms/input/input.component.js +104 -33
  20. package/lib/cjs/core-components/atoms/input/input.stories.js +15 -15
  21. package/lib/cjs/core-components/atoms/input/input.test.js +30 -10
  22. package/lib/cjs/core-components/atoms/input-dropdown/input-dropdown.component.js +127 -53
  23. package/lib/cjs/core-components/atoms/input-dropdown/input-dropdown.stories.js +12 -12
  24. package/lib/cjs/core-components/atoms/input-dropdown/input-dropdown.test.js +16 -7
  25. package/lib/cjs/core-components/atoms/loader/loader.component.js +83 -21
  26. package/lib/cjs/core-components/atoms/loader/loader.stories.js +8 -8
  27. package/lib/cjs/core-components/atoms/loader/loader.test.js +11 -7
  28. package/lib/cjs/core-components/atoms/radio/radio.component.js +102 -37
  29. package/lib/cjs/core-components/atoms/radio/radio.stories.js +16 -16
  30. package/lib/cjs/core-components/atoms/radio/radio.test.js +15 -7
  31. package/lib/cjs/core-components/atoms/stepper/stepper.component.js +77 -34
  32. package/lib/cjs/core-components/atoms/stepper/stepper.stories.js +13 -13
  33. package/lib/cjs/core-components/atoms/stepper/stepper.test.js +16 -7
  34. package/lib/cjs/core-components/atoms/stepper/stepper.test.js.map +1 -1
  35. package/lib/cjs/core-components/atoms/tabs/tabs.component.js +95 -0
  36. package/lib/cjs/core-components/atoms/tabs/tabs.component.js.map +1 -0
  37. package/lib/cjs/core-components/atoms/tabs/tabs.stories.js +26 -0
  38. package/lib/cjs/core-components/atoms/tabs/tabs.stories.js.map +1 -0
  39. package/lib/cjs/core-components/atoms/tabs/tabs.test.js +26 -0
  40. package/lib/cjs/core-components/atoms/tabs/tabs.test.js.map +1 -0
  41. package/lib/cjs/core-components/atoms/timer/timer.component.js +119 -92
  42. package/lib/cjs/core-components/atoms/timer/timer.test.js +20 -10
  43. package/lib/cjs/core-components/atoms/tooltip/tooltip.component.js +85 -45
  44. package/lib/cjs/core-components/atoms/tooltip/tooltip.component.test.js +13 -9
  45. package/lib/cjs/core-components/atoms/tooltip/tooltip.stories.js +8 -8
  46. package/lib/cjs/core-components/index.js +65 -27
  47. package/lib/cjs/core-components/index.js.map +1 -1
  48. package/lib/cjs/core-components/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.js +210 -106
  49. package/lib/cjs/core-components/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.test.js +23 -9
  50. package/lib/cjs/core-components/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.stories.js +38 -36
  51. package/lib/cjs/core-components/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.js +209 -104
  52. package/lib/cjs/core-components/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.test.js +28 -16
  53. package/lib/cjs/core-components/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.stories.js +24 -22
  54. package/lib/cjs/core-components/molecules/css-multiline-input/css-multiline-input.component.js +203 -106
  55. package/lib/cjs/core-components/molecules/css-multiline-input/css-multiline-input.stories.js +8 -8
  56. package/lib/cjs/core-components/molecules/css-multiline-input/css-multiline-input.test.js +14 -7
  57. package/lib/cjs/core-components/molecules/css-multiline-input/css-properties.js +159 -159
  58. package/lib/cjs/core-utils/index.js +31 -15
  59. package/lib/cjs/core-utils/unit-test.utils.js +8 -6
  60. package/lib/cjs/index.js +31 -15
  61. package/lib/cjs/library/assets/svg/index.js +39 -13
  62. package/lib/cjs/reportWebVitals.js +1 -1
  63. package/lib/cjs/setupTests.js +1 -1
  64. package/lib/esm/App.js +34 -12
  65. package/lib/esm/App.test.js +8 -8
  66. package/lib/esm/core-components/atoms/buttons/button.stories.js +24 -24
  67. package/lib/esm/core-components/atoms/buttons/buttons.component.js +23 -7
  68. package/lib/esm/core-components/atoms/buttons/buttons.test.js +13 -7
  69. package/lib/esm/core-components/atoms/check-box/checkBox.component.js +65 -19
  70. package/lib/esm/core-components/atoms/check-box/checkBox.stories.js +18 -18
  71. package/lib/esm/core-components/atoms/check-box/checkBox.test.js +13 -7
  72. package/lib/esm/core-components/atoms/date-picker/date-picker.component.js +54 -21
  73. package/lib/esm/core-components/atoms/date-picker/date-picker.stories.js +14 -14
  74. package/lib/esm/core-components/atoms/date-picker/date-picker.test.js +15 -8
  75. package/lib/esm/core-components/atoms/form/form.component.js +513 -138
  76. package/lib/esm/core-components/atoms/form/form.test.js +78 -60
  77. package/lib/esm/core-components/atoms/icons/icons.component.js +36 -24
  78. package/lib/esm/core-components/atoms/input/input-otp.component.js +80 -59
  79. package/lib/esm/core-components/atoms/input/input-pin.component.js +142 -81
  80. package/lib/esm/core-components/atoms/input/input-pin.stories.js +15 -15
  81. package/lib/esm/core-components/atoms/input/input-pin.test.js +26 -10
  82. package/lib/esm/core-components/atoms/input/input.component.js +66 -16
  83. package/lib/esm/core-components/atoms/input/input.stories.js +16 -16
  84. package/lib/esm/core-components/atoms/input/input.test.js +28 -10
  85. package/lib/esm/core-components/atoms/input-dropdown/input-dropdown.component.js +95 -36
  86. package/lib/esm/core-components/atoms/input-dropdown/input-dropdown.stories.js +13 -13
  87. package/lib/esm/core-components/atoms/input-dropdown/input-dropdown.test.js +14 -7
  88. package/lib/esm/core-components/atoms/loader/loader.component.js +80 -20
  89. package/lib/esm/core-components/atoms/loader/loader.stories.js +9 -9
  90. package/lib/esm/core-components/atoms/loader/loader.test.js +7 -7
  91. package/lib/esm/core-components/atoms/radio/radio.component.js +65 -21
  92. package/lib/esm/core-components/atoms/radio/radio.stories.js +17 -17
  93. package/lib/esm/core-components/atoms/radio/radio.test.js +13 -7
  94. package/lib/esm/core-components/atoms/stepper/stepper.component.js +74 -32
  95. package/lib/esm/core-components/atoms/stepper/stepper.stories.js +14 -14
  96. package/lib/esm/core-components/atoms/stepper/stepper.test.js +14 -7
  97. package/lib/esm/core-components/atoms/stepper/stepper.test.js.map +1 -1
  98. package/lib/esm/core-components/atoms/tabs/tabs.component.js +47 -0
  99. package/lib/esm/core-components/atoms/tabs/tabs.component.js.map +1 -0
  100. package/lib/esm/core-components/atoms/tabs/tabs.stories.js +23 -0
  101. package/lib/esm/core-components/atoms/tabs/tabs.stories.js.map +1 -0
  102. package/lib/esm/core-components/atoms/tabs/tabs.test.js +19 -0
  103. package/lib/esm/core-components/atoms/tabs/tabs.test.js.map +1 -0
  104. package/lib/esm/core-components/atoms/timer/timer.component.js +81 -75
  105. package/lib/esm/core-components/atoms/timer/timer.test.js +10 -10
  106. package/lib/esm/core-components/atoms/tooltip/tooltip.component.js +46 -25
  107. package/lib/esm/core-components/atoms/tooltip/tooltip.component.test.js +9 -9
  108. package/lib/esm/core-components/atoms/tooltip/tooltip.stories.js +9 -9
  109. package/lib/esm/core-components/index.js +19 -18
  110. package/lib/esm/core-components/index.js.map +1 -1
  111. package/lib/esm/core-components/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.js +170 -88
  112. package/lib/esm/core-components/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.test.js +17 -9
  113. package/lib/esm/core-components/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.stories.js +38 -37
  114. package/lib/esm/core-components/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.js +169 -86
  115. package/lib/esm/core-components/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.test.js +22 -16
  116. package/lib/esm/core-components/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.stories.js +24 -23
  117. package/lib/esm/core-components/molecules/css-multiline-input/css-multiline-input.component.js +166 -90
  118. package/lib/esm/core-components/molecules/css-multiline-input/css-multiline-input.stories.js +9 -9
  119. package/lib/esm/core-components/molecules/css-multiline-input/css-multiline-input.test.js +9 -7
  120. package/lib/esm/core-components/molecules/css-multiline-input/css-properties.js +159 -159
  121. package/lib/esm/core-utils/index.js +2 -2
  122. package/lib/esm/core-utils/unit-test.utils.js +5 -5
  123. package/lib/esm/index.js +2 -2
  124. package/lib/esm/library/assets/svg/index.js +19 -10
  125. package/lib/esm/reportWebVitals.js +1 -1
  126. package/lib/esm/setupTests.js +2 -2
  127. package/package.json +3 -1
@@ -1,35 +1,53 @@
1
- import React from 'react';
2
- import { render, fireEvent } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { CheckBox, Input, Toggle, MultilineInput, Label, InputDate, InputFile, InputRadio, InputWrapper, } from './form.component';
5
- describe('Checkbox component', () => {
6
- it('render checkbox correctly', () => {
7
- const checkbox = render(React.createElement(CheckBox, null));
8
- expect(checkbox).toMatchSnapshot();
9
- });
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import {
5
+ CheckBox,
6
+ Input,
7
+ Toggle,
8
+ MultilineInput,
9
+ Label,
10
+ InputDate,
11
+ InputFile,
12
+ InputRadio,
13
+ InputWrapper,
14
+ } from "./form.component";
15
+ describe("Checkbox component", () => {
16
+ it("render checkbox correctly", () => {
17
+ const checkbox = render(React.createElement(CheckBox, null));
18
+ expect(checkbox).toMatchSnapshot();
19
+ });
10
20
  });
11
- describe('Input component', () => {
12
- it('render input correctly', () => {
13
- const inputComp = render(React.createElement(Input, { type: "text", value: "test", onChange: (val) => jest.fn(), onBlur: (value) => jest.fn(), onKeyDown: (val) => jest.fn() }));
14
- const input = inputComp.getByTestId('INPT');
15
- fireEvent.change(input, { target: { value: 'check' } });
16
- userEvent.type(input, 'value');
17
- fireEvent.blur(input);
18
- fireEvent.keyDown(input, {
19
- key: 'Escape',
20
- code: 'Escape',
21
- keyCode: 27,
22
- charCode: 27,
23
- });
24
- fireEvent.keyPress(input, { key: 'Enter', keyCode: 13 });
25
- expect(input).toMatchSnapshot();
21
+ describe("Input component", () => {
22
+ it("render input correctly", () => {
23
+ const inputComp = render(
24
+ React.createElement(Input, {
25
+ type: "text",
26
+ value: "test",
27
+ onChange: (val) => jest.fn(),
28
+ onBlur: (value) => jest.fn(),
29
+ onKeyDown: (val) => jest.fn(),
30
+ }),
31
+ );
32
+ const input = inputComp.getByTestId("INPT");
33
+ fireEvent.change(input, { target: { value: "check" } });
34
+ userEvent.type(input, "value");
35
+ fireEvent.blur(input);
36
+ fireEvent.keyDown(input, {
37
+ key: "Escape",
38
+ code: "Escape",
39
+ keyCode: 27,
40
+ charCode: 27,
26
41
  });
42
+ fireEvent.keyPress(input, { key: "Enter", keyCode: 13 });
43
+ expect(input).toMatchSnapshot();
44
+ });
27
45
  });
28
- describe('Toggle component', () => {
29
- it('render toggle correctly', () => {
30
- const toggle = render(React.createElement(Toggle, null));
31
- expect(toggle).toMatchSnapshot();
32
- });
46
+ describe("Toggle component", () => {
47
+ it("render toggle correctly", () => {
48
+ const toggle = render(React.createElement(Toggle, null));
49
+ expect(toggle).toMatchSnapshot();
50
+ });
33
51
  });
34
52
  // describe('SelectOption component', () => {
35
53
  // it('render selectOption correctly', () => {
@@ -42,11 +60,11 @@ describe('Toggle component', () => {
42
60
  // expect(select).toMatchSnapshot();
43
61
  // });
44
62
  // });
45
- describe('MultilineInput component', () => {
46
- it('render multilineInput correctly', () => {
47
- const multi = render(React.createElement(MultilineInput, null));
48
- expect(multi).toMatchSnapshot();
49
- });
63
+ describe("MultilineInput component", () => {
64
+ it("render multilineInput correctly", () => {
65
+ const multi = render(React.createElement(MultilineInput, null));
66
+ expect(multi).toMatchSnapshot();
67
+ });
50
68
  });
51
69
  // describe('Clock component', () => {
52
70
  // it('render clock correctly', () => {
@@ -56,17 +74,17 @@ describe('MultilineInput component', () => {
56
74
  // expect(clock).toMatchSnapshot();
57
75
  // });
58
76
  // });
59
- describe('Label component', () => {
60
- it('render label correctly', () => {
61
- const label = render(React.createElement(Label, { htmlFor: "vsdvrf" }));
62
- expect(label).toMatchSnapshot();
63
- });
77
+ describe("Label component", () => {
78
+ it("render label correctly", () => {
79
+ const label = render(React.createElement(Label, { htmlFor: "vsdvrf" }));
80
+ expect(label).toMatchSnapshot();
81
+ });
64
82
  });
65
- describe('InputDate component', () => {
66
- it('render inputDate correctly', () => {
67
- const inputDate = render(React.createElement(InputDate, null));
68
- expect(inputDate).toMatchSnapshot();
69
- });
83
+ describe("InputDate component", () => {
84
+ it("render inputDate correctly", () => {
85
+ const inputDate = render(React.createElement(InputDate, null));
86
+ expect(inputDate).toMatchSnapshot();
87
+ });
70
88
  });
71
89
  // describe('InputDateTime component', () => {
72
90
  // it('render inputDateTime correctly', () => {
@@ -74,22 +92,22 @@ describe('InputDate component', () => {
74
92
  // expect(inputDateTime).toMatchSnapshot();
75
93
  // });
76
94
  // });
77
- describe('InputFile component', () => {
78
- it('render inputFile correctly', () => {
79
- const inputFile = render(React.createElement(InputFile, null));
80
- expect(inputFile).toMatchSnapshot();
81
- });
95
+ describe("InputFile component", () => {
96
+ it("render inputFile correctly", () => {
97
+ const inputFile = render(React.createElement(InputFile, null));
98
+ expect(inputFile).toMatchSnapshot();
99
+ });
82
100
  });
83
- describe('InputRadio component', () => {
84
- it('render inputRadio correctly', () => {
85
- const inputRadio = render(React.createElement(InputRadio, null));
86
- expect(inputRadio).toMatchSnapshot();
87
- });
101
+ describe("InputRadio component", () => {
102
+ it("render inputRadio correctly", () => {
103
+ const inputRadio = render(React.createElement(InputRadio, null));
104
+ expect(inputRadio).toMatchSnapshot();
105
+ });
88
106
  });
89
- describe('InputWrapper component', () => {
90
- it('render inputWrapper correctly', () => {
91
- const inputWrapper = render(React.createElement(InputWrapper, null));
92
- expect(inputWrapper).toMatchSnapshot();
93
- });
107
+ describe("InputWrapper component", () => {
108
+ it("render inputWrapper correctly", () => {
109
+ const inputWrapper = render(React.createElement(InputWrapper, null));
110
+ expect(inputWrapper).toMatchSnapshot();
111
+ });
94
112
  });
95
- //# sourceMappingURL=form.test.js.map
113
+ //# sourceMappingURL=form.test.js.map
@@ -1,25 +1,37 @@
1
- import React from 'react';
2
- export const Icon = ({ nameIcon, propsIcon, tooltip = '', isDisable = false, onClick, }) => {
3
- try {
4
- const iconProps = Object.assign(Object.assign({}, propsIcon), { color: isDisable ? '#808080' : (propsIcon === null || propsIcon === void 0 ? void 0 : propsIcon.color) || '#ffffff' });
5
- const lib = nameIcon
6
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
7
- .split(' ')[0]
8
- .toLocaleLowerCase();
9
- // const ElementIcon: any = loadable(
10
- // () => import(`react-icons/${lib}/index.js`),
11
- // {
12
- // resolveComponent: (el) =>
13
- // el[nameIcon] != null ? el[nameIcon] : el[Object.keys(el.default)[0]],
14
- // }
15
- // );
16
- return (React.createElement("div", { onClick: () => {
17
- if (!isDisable)
18
- onClick && onClick();
19
- } }));
20
- }
21
- catch (error) {
22
- return React.createElement(React.Fragment, null);
23
- }
1
+ import React from "react";
2
+ export const Icon = ({
3
+ nameIcon,
4
+ propsIcon,
5
+ tooltip = "",
6
+ isDisable = false,
7
+ onClick,
8
+ }) => {
9
+ try {
10
+ const iconProps = Object.assign(Object.assign({}, propsIcon), {
11
+ color: isDisable
12
+ ? "#808080"
13
+ : (propsIcon === null || propsIcon === void 0
14
+ ? void 0
15
+ : propsIcon.color) || "#ffffff",
16
+ });
17
+ const lib = nameIcon
18
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
19
+ .split(" ")[0]
20
+ .toLocaleLowerCase();
21
+ // const ElementIcon: any = loadable(
22
+ // () => import(`react-icons/${lib}/index.js`),
23
+ // {
24
+ // resolveComponent: (el) =>
25
+ // el[nameIcon] != null ? el[nameIcon] : el[Object.keys(el.default)[0]],
26
+ // }
27
+ // );
28
+ return React.createElement("div", {
29
+ onClick: () => {
30
+ if (!isDisable) onClick && onClick();
31
+ },
32
+ });
33
+ } catch (error) {
34
+ return React.createElement(React.Fragment, null);
35
+ }
24
36
  };
25
- //# sourceMappingURL=icons.component.js.map
37
+ //# sourceMappingURL=icons.component.js.map
@@ -1,62 +1,83 @@
1
1
  /* eslint-disable no-console */
2
- import React, { useEffect, useRef } from 'react';
3
- import './input-otp.styles.css';
4
- export const InputOtp = ({ className, pin, onPinChanged, }) => {
5
- const pinLength = 6;
6
- const Pin_Min_Value = 0;
7
- const Pin_Max_Value = 9;
8
- const BACKSPACE_Key = 'Backspace';
9
- const inputRefs = useRef([]);
10
- useEffect(() => {
11
- const ref = inputRefs.current[0];
12
- if (ref) {
13
- ref.focus();
14
- }
15
- }, []);
16
- const changePinFocus = (pinIndex) => {
17
- const ref = inputRefs.current[pinIndex];
18
- if (ref) {
19
- ref.focus();
20
- }
21
- };
22
- const onChange = (event, index) => {
23
- const value = event.target.value;
24
- const pinNumber = Number(value.trim());
25
- if (isNaN(pinNumber) || value.length === 0) {
26
- return;
27
- }
28
- if (pinNumber >= Pin_Min_Value && pinNumber <= Pin_Max_Value) {
29
- onPinChanged(pinNumber, index);
30
- if (index < pinLength - 1) {
31
- changePinFocus(index + 1);
2
+ import React, { useEffect, useRef } from "react";
3
+ import "./input-otp.styles.css";
4
+ export const InputOtp = ({ className, pin, onPinChanged }) => {
5
+ const pinLength = 6;
6
+ const Pin_Min_Value = 0;
7
+ const Pin_Max_Value = 9;
8
+ const BACKSPACE_Key = "Backspace";
9
+ const inputRefs = useRef([]);
10
+ useEffect(() => {
11
+ const ref = inputRefs.current[0];
12
+ if (ref) {
13
+ ref.focus();
14
+ }
15
+ }, []);
16
+ const changePinFocus = (pinIndex) => {
17
+ const ref = inputRefs.current[pinIndex];
18
+ if (ref) {
19
+ ref.focus();
20
+ }
21
+ };
22
+ const onChange = (event, index) => {
23
+ const value = event.target.value;
24
+ const pinNumber = Number(value.trim());
25
+ if (isNaN(pinNumber) || value.length === 0) {
26
+ return;
27
+ }
28
+ if (pinNumber >= Pin_Min_Value && pinNumber <= Pin_Max_Value) {
29
+ onPinChanged(pinNumber, index);
30
+ if (index < pinLength - 1) {
31
+ changePinFocus(index + 1);
32
+ }
33
+ }
34
+ };
35
+ const onKeyDown = (event, index) => {
36
+ console.log({ event, index });
37
+ const keyboardKeyCode = event.nativeEvent.code;
38
+ if (keyboardKeyCode != BACKSPACE_Key) return;
39
+ if (pin[index] === undefined) {
40
+ changePinFocus(index - 1);
41
+ } else {
42
+ onPinChanged(undefined, index);
43
+ }
44
+ };
45
+ return React.createElement(
46
+ "div",
47
+ { className: `${className} relative` },
48
+ React.createElement(
49
+ "div",
50
+ {
51
+ className:
52
+ "flex space-x-1 bg-background-secondary rounded-lg outline-offset-8",
53
+ },
54
+ Array.from({ length: pinLength }, (_, index) =>
55
+ React.createElement("input", {
56
+ "data-testid": "onPinChanged",
57
+ className:
58
+ "pt-3 pb-2 block w-full px-0 text-5xl font-extrabold border-b-0 text-orange mt-0 bg-transparent text-center z-20 appearance-none focus:outline-none font-nunitoSansRegular",
59
+ onKeyDown: (event) => onKeyDown(event, index),
60
+ key: index,
61
+ onMouseUp: () => {
62
+ if (pin.join("").length <= 0) {
63
+ changePinFocus(0);
32
64
  }
33
- }
34
- };
35
- const onKeyDown = (event, index) => {
36
- console.log({ event, index });
37
- const keyboardKeyCode = event.nativeEvent.code;
38
- if (keyboardKeyCode != BACKSPACE_Key)
39
- return;
40
- if (pin[index] === undefined) {
41
- changePinFocus(index - 1);
42
- }
43
- else {
44
- onPinChanged(undefined, index);
45
- }
46
- };
47
- return (React.createElement("div", { className: `${className} relative` },
48
- React.createElement("div", { className: "flex space-x-1 bg-background-secondary rounded-lg outline-offset-8" }, Array.from({ length: pinLength }, (_, index) => (React.createElement("input", { "data-testid": "onPinChanged", className: "pt-3 pb-2 block w-full px-0 text-5xl font-extrabold border-b-0 text-orange mt-0 bg-transparent text-center z-20 appearance-none focus:outline-none font-nunitoSansRegular", onKeyDown: (event) => onKeyDown(event, index), key: index, onMouseUp: () => {
49
- if (pin.join('').length <= 0) {
50
- changePinFocus(0);
51
- }
52
- }, onClick: () => {
53
- if (pin.join('').length <= 0) {
54
- onPinChanged(undefined, 0);
55
- }
56
- }, ref: (el) => {
57
- if (el) {
58
- inputRefs.current[index] = el;
59
- }
60
- }, onChange: (event) => onChange(event, index), value: pin[index] || '' }))))));
65
+ },
66
+ onClick: () => {
67
+ if (pin.join("").length <= 0) {
68
+ onPinChanged(undefined, 0);
69
+ }
70
+ },
71
+ ref: (el) => {
72
+ if (el) {
73
+ inputRefs.current[index] = el;
74
+ }
75
+ },
76
+ onChange: (event) => onChange(event, index),
77
+ value: pin[index] || "",
78
+ }),
79
+ ),
80
+ ),
81
+ );
61
82
  };
62
- //# sourceMappingURL=input-otp.component.js.map
83
+ //# sourceMappingURL=input-otp.component.js.map
@@ -1,84 +1,145 @@
1
1
  /* eslint-disable */
2
- import React, { useRef, useState } from 'react';
3
- import './input.styles.css';
4
- export const InputPin = ({ title, className, defaultPin, errorMsg, defaultMsg, hasError, onPinChanged, }) => {
5
- const pin = useRef([]);
6
- const [reload, setReload] = useState(false);
7
- const pinLength = 12;
8
- const Pin_Min_Value = 0;
9
- const Pin_Max_Value = 9;
10
- const BACKSPACE_Key = 'Backspace';
11
- const inputRefs = useRef([]);
12
- const removeValuesFromArray = (valuesArray, value) => {
13
- const valueIndex = valuesArray.findIndex((entry) => entry === value);
14
- if (valueIndex === -1) {
15
- return;
16
- }
17
- valuesArray.splice(valueIndex, 1);
18
- };
19
- const changePinFocus = (pinIndex) => {
20
- const ref = inputRefs.current[pinIndex];
21
- if (ref) {
22
- ref.focus();
23
- }
24
- };
25
- const onChange = (event, index) => {
2
+ import React, { useRef, useState } from "react";
3
+ import "./input.styles.css";
4
+ export const InputPin = ({
5
+ title,
6
+ className,
7
+ defaultPin,
8
+ errorMsg,
9
+ defaultMsg,
10
+ hasError,
11
+ onPinChanged,
12
+ }) => {
13
+ const pin = useRef([]);
14
+ const [reload, setReload] = useState(false);
15
+ const pinLength = 12;
16
+ const Pin_Min_Value = 0;
17
+ const Pin_Max_Value = 9;
18
+ const BACKSPACE_Key = "Backspace";
19
+ const inputRefs = useRef([]);
20
+ const removeValuesFromArray = (valuesArray, value) => {
21
+ const valueIndex = valuesArray.findIndex((entry) => entry === value);
22
+ if (valueIndex === -1) {
23
+ return;
24
+ }
25
+ valuesArray.splice(valueIndex, 1);
26
+ };
27
+ const changePinFocus = (pinIndex) => {
28
+ const ref = inputRefs.current[pinIndex];
29
+ if (ref) {
30
+ ref.focus();
31
+ }
32
+ };
33
+ const onChange = (event, index) => {
34
+ var _a;
35
+ const previousValue = event.target.defaultValue;
36
+ const valueArray = event.target.value.split("");
37
+ const output = removeValuesFromArray(valueArray, previousValue);
38
+ const value = valueArray.pop();
39
+ if (!value) {
40
+ return;
41
+ }
42
+ const pinNumber = Number(value);
43
+ if (isNaN(pinNumber) || value.length === 0) {
44
+ return;
45
+ }
46
+ pin.current[
47
+ (_a = pin.current) === null || _a === void 0 ? void 0 : _a.length
48
+ ] = value;
49
+ setReload(!reload);
50
+ if (pinNumber >= Pin_Min_Value && pinNumber <= Pin_Max_Value) {
51
+ onPinChanged(pin.current, index);
52
+ if (index < pinLength - 1) {
53
+ changePinFocus(index + 1);
54
+ }
55
+ }
56
+ };
57
+ const onKeyDown = (event, index) => {
58
+ const keyboardKeyCode = event.nativeEvent.code;
59
+ if (keyboardKeyCode != BACKSPACE_Key) return;
60
+ if (pin.current[index] !== undefined && keyboardKeyCode === BACKSPACE_Key) {
61
+ changePinFocus(index - 1);
62
+ }
63
+ if (pin.current[index] === undefined) {
64
+ changePinFocus(index - 1);
65
+ } else {
66
+ onPinChanged(undefined, index);
67
+ }
68
+ };
69
+ return React.createElement(
70
+ "div",
71
+ { className: `${className} relative` },
72
+ React.createElement(
73
+ "label",
74
+ {
75
+ className:
76
+ "duration-300 -z-1 origin-0 text-gray-dark-secondary font-nunitoSansRegular text-md",
77
+ },
78
+ title,
79
+ ),
80
+ React.createElement(
81
+ "div",
82
+ { className: "flex space-x-1" },
83
+ Array.from({ length: pinLength }, (_, index) => {
26
84
  var _a;
27
- const previousValue = event.target.defaultValue;
28
- const valueArray = event.target.value.split('');
29
- const output = removeValuesFromArray(valueArray, previousValue);
30
- const value = valueArray.pop();
31
- if (!value) {
32
- return;
33
- }
34
- const pinNumber = Number(value);
35
- if (isNaN(pinNumber) || value.length === 0) {
36
- return;
37
- }
38
- pin.current[(_a = pin.current) === null || _a === void 0 ? void 0 : _a.length] = value;
39
- setReload(!reload);
40
- if (pinNumber >= Pin_Min_Value && pinNumber <= Pin_Max_Value) {
41
- onPinChanged(pin.current, index);
42
- if (index < pinLength - 1) {
43
- changePinFocus(index + 1);
44
- }
45
- }
46
- };
47
- const onKeyDown = (event, index) => {
48
- const keyboardKeyCode = event.nativeEvent.code;
49
- if (keyboardKeyCode != BACKSPACE_Key)
50
- return;
51
- if (pin.current[index] !== undefined && keyboardKeyCode === BACKSPACE_Key) {
52
- changePinFocus(index - 1);
53
- }
54
- if (pin.current[index] === undefined) {
55
- changePinFocus(index - 1);
56
- }
57
- else {
58
- onPinChanged(undefined, index);
59
- }
60
- };
61
- return (React.createElement("div", { className: `${className} relative` },
62
- React.createElement("label", { className: "duration-300 -z-1 origin-0 text-gray-dark-secondary font-nunitoSansRegular text-md" }, title),
63
- React.createElement("div", { className: "flex space-x-1" }, Array.from({ length: pinLength }, (_, index) => {
64
- var _a;
65
- return (React.createElement("div", { className: "flex space-x-1 max-w-full items-stretch", key: index },
66
- React.createElement("input", { "data-testid": "inputElementPin", type: "tel", className: "pb-2 block w-4 px-0 mt-0 bg-transparent text-center border-0 border-b z-20 appearance-none rounded-none focus:outline-none focus:ring-0 focus:border-gray-secondary border-gray-secondary font-nunitoSansRegular ", onKeyUp: (event) => onKeyDown(event, index), key: index, onMouseUp: () => {
67
- if (pin.current.join('').length <= 0) {
68
- changePinFocus(0);
69
- }
70
- }, onClick: () => {
71
- if (pin.current.join('').length <= 0) {
72
- onPinChanged(undefined, 0);
73
- }
74
- }, ref: (el) => {
75
- if (el) {
76
- inputRefs.current[index] = el;
77
- }
78
- }, onChange: (event) => onChange(event, index), value: ((_a = pin.current[index]) === null || _a === void 0 ? void 0 : _a.toString()) || '' }),
79
- React.createElement("div", { className: "invisible" }, (index + 1) % 4 === 0 ? 'ss' : null)));
80
- })),
81
- hasError && (hasError === null || hasError === void 0 ? void 0 : hasError.type) !== 'required' && (React.createElement("span", { className: "text-sm text-red text-4xs font-nunitoSansRegular", id: "error" }, `${errorMsg || ''}`)),
82
- (!hasError || (hasError === null || hasError === void 0 ? void 0 : hasError.type) === 'required') && (React.createElement("span", { className: "text-sm text-4xs font-nunitoSansRegular", id: "error" }, `${defaultMsg || ''}`))));
85
+ return React.createElement(
86
+ "div",
87
+ { className: "flex space-x-1 max-w-full items-stretch", key: index },
88
+ React.createElement("input", {
89
+ "data-testid": "inputElementPin",
90
+ type: "tel",
91
+ className:
92
+ "pb-2 block w-4 px-0 mt-0 bg-transparent text-center border-0 border-b z-20 appearance-none rounded-none focus:outline-none focus:ring-0 focus:border-gray-secondary border-gray-secondary font-nunitoSansRegular ",
93
+ onKeyUp: (event) => onKeyDown(event, index),
94
+ key: index,
95
+ onMouseUp: () => {
96
+ if (pin.current.join("").length <= 0) {
97
+ changePinFocus(0);
98
+ }
99
+ },
100
+ onClick: () => {
101
+ if (pin.current.join("").length <= 0) {
102
+ onPinChanged(undefined, 0);
103
+ }
104
+ },
105
+ ref: (el) => {
106
+ if (el) {
107
+ inputRefs.current[index] = el;
108
+ }
109
+ },
110
+ onChange: (event) => onChange(event, index),
111
+ value:
112
+ ((_a = pin.current[index]) === null || _a === void 0
113
+ ? void 0
114
+ : _a.toString()) || "",
115
+ }),
116
+ React.createElement(
117
+ "div",
118
+ { className: "invisible" },
119
+ (index + 1) % 4 === 0 ? "ss" : null,
120
+ ),
121
+ );
122
+ }),
123
+ ),
124
+ hasError &&
125
+ (hasError === null || hasError === void 0 ? void 0 : hasError.type) !==
126
+ "required" &&
127
+ React.createElement(
128
+ "span",
129
+ {
130
+ className: "text-sm text-red text-4xs font-nunitoSansRegular",
131
+ id: "error",
132
+ },
133
+ `${errorMsg || ""}`,
134
+ ),
135
+ (!hasError ||
136
+ (hasError === null || hasError === void 0 ? void 0 : hasError.type) ===
137
+ "required") &&
138
+ React.createElement(
139
+ "span",
140
+ { className: "text-sm text-4xs font-nunitoSansRegular", id: "error" },
141
+ `${defaultMsg || ""}`,
142
+ ),
143
+ );
83
144
  };
84
- //# sourceMappingURL=input-pin.component.js.map
145
+ //# sourceMappingURL=input-pin.component.js.map
@@ -1,21 +1,21 @@
1
- import { InputPin } from './input-pin.component';
1
+ import { InputPin } from "./input-pin.component";
2
2
  const meta = {
3
- title: 'Design System/Atoms/InputPin',
4
- component: InputPin,
5
- tags: ['autodocs'],
6
- parameters: {
7
- componentSubtitle: `import { InputPin } from 'react-restyle-components'`,
8
- },
3
+ title: "Design System/Atoms/InputPin",
4
+ component: InputPin,
5
+ tags: ["autodocs"],
6
+ parameters: {
7
+ componentSubtitle: `import { InputPin } from 'react-restyle-components'`,
8
+ },
9
9
  };
10
10
  export default meta;
11
11
  export const Primary = {
12
- args: {
13
- title: 'Enter your Aadhaar Number',
14
- hasError: true,
15
- defaultPin: [],
16
- onPinChanged: (item) => {
17
- console.log({ item });
18
- },
12
+ args: {
13
+ title: "Enter your Aadhaar Number",
14
+ hasError: true,
15
+ defaultPin: [],
16
+ onPinChanged: (item) => {
17
+ console.log({ item });
19
18
  },
19
+ },
20
20
  };
21
- //# sourceMappingURL=input-pin.stories.js.map
21
+ //# sourceMappingURL=input-pin.stories.js.map