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.
- package/lib/cjs/App.js +36 -12
- package/lib/cjs/App.test.js +10 -8
- package/lib/cjs/core-components/atoms/buttons/button.stories.js +26 -24
- package/lib/cjs/core-components/atoms/buttons/buttons.component.js +27 -9
- package/lib/cjs/core-components/atoms/buttons/buttons.test.js +15 -7
- package/lib/cjs/core-components/atoms/check-box/checkBox.component.js +102 -35
- package/lib/cjs/core-components/atoms/check-box/checkBox.stories.js +17 -17
- package/lib/cjs/core-components/atoms/check-box/checkBox.test.js +15 -7
- package/lib/cjs/core-components/atoms/date-picker/date-picker.component.js +98 -37
- package/lib/cjs/core-components/atoms/date-picker/date-picker.stories.js +17 -15
- package/lib/cjs/core-components/atoms/date-picker/date-picker.test.js +16 -7
- package/lib/cjs/core-components/atoms/form/form.component.js +571 -159
- package/lib/cjs/core-components/atoms/form/form.test.js +87 -59
- package/lib/cjs/core-components/atoms/icons/icons.component.js +40 -26
- package/lib/cjs/core-components/atoms/input/input-otp.component.js +118 -76
- package/lib/cjs/core-components/atoms/input/input-pin.component.js +180 -98
- package/lib/cjs/core-components/atoms/input/input-pin.stories.js +14 -14
- package/lib/cjs/core-components/atoms/input/input-pin.test.js +28 -10
- package/lib/cjs/core-components/atoms/input/input.component.js +104 -33
- package/lib/cjs/core-components/atoms/input/input.stories.js +15 -15
- package/lib/cjs/core-components/atoms/input/input.test.js +30 -10
- package/lib/cjs/core-components/atoms/input-dropdown/input-dropdown.component.js +127 -53
- package/lib/cjs/core-components/atoms/input-dropdown/input-dropdown.stories.js +12 -12
- package/lib/cjs/core-components/atoms/input-dropdown/input-dropdown.test.js +16 -7
- package/lib/cjs/core-components/atoms/loader/loader.component.js +83 -21
- package/lib/cjs/core-components/atoms/loader/loader.stories.js +8 -8
- package/lib/cjs/core-components/atoms/loader/loader.test.js +11 -7
- package/lib/cjs/core-components/atoms/radio/radio.component.js +102 -37
- package/lib/cjs/core-components/atoms/radio/radio.stories.js +16 -16
- package/lib/cjs/core-components/atoms/radio/radio.test.js +15 -7
- package/lib/cjs/core-components/atoms/stepper/stepper.component.js +77 -34
- package/lib/cjs/core-components/atoms/stepper/stepper.stories.js +13 -13
- package/lib/cjs/core-components/atoms/stepper/stepper.test.js +16 -7
- package/lib/cjs/core-components/atoms/stepper/stepper.test.js.map +1 -1
- package/lib/cjs/core-components/atoms/tabs/tabs.component.js +95 -0
- package/lib/cjs/core-components/atoms/tabs/tabs.component.js.map +1 -0
- package/lib/cjs/core-components/atoms/tabs/tabs.stories.js +26 -0
- package/lib/cjs/core-components/atoms/tabs/tabs.stories.js.map +1 -0
- package/lib/cjs/core-components/atoms/tabs/tabs.test.js +26 -0
- package/lib/cjs/core-components/atoms/tabs/tabs.test.js.map +1 -0
- package/lib/cjs/core-components/atoms/timer/timer.component.js +119 -92
- package/lib/cjs/core-components/atoms/timer/timer.test.js +20 -10
- package/lib/cjs/core-components/atoms/tooltip/tooltip.component.js +85 -45
- package/lib/cjs/core-components/atoms/tooltip/tooltip.component.test.js +13 -9
- package/lib/cjs/core-components/atoms/tooltip/tooltip.stories.js +8 -8
- package/lib/cjs/core-components/index.js +65 -27
- package/lib/cjs/core-components/index.js.map +1 -1
- 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
- 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
- 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
- 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
- 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
- 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
- package/lib/cjs/core-components/molecules/css-multiline-input/css-multiline-input.component.js +203 -106
- package/lib/cjs/core-components/molecules/css-multiline-input/css-multiline-input.stories.js +8 -8
- package/lib/cjs/core-components/molecules/css-multiline-input/css-multiline-input.test.js +14 -7
- package/lib/cjs/core-components/molecules/css-multiline-input/css-properties.js +159 -159
- package/lib/cjs/core-utils/index.js +31 -15
- package/lib/cjs/core-utils/unit-test.utils.js +8 -6
- package/lib/cjs/index.js +31 -15
- package/lib/cjs/library/assets/svg/index.js +39 -13
- package/lib/cjs/reportWebVitals.js +1 -1
- package/lib/cjs/setupTests.js +1 -1
- package/lib/esm/App.js +34 -12
- package/lib/esm/App.test.js +8 -8
- package/lib/esm/core-components/atoms/buttons/button.stories.js +24 -24
- package/lib/esm/core-components/atoms/buttons/buttons.component.js +23 -7
- package/lib/esm/core-components/atoms/buttons/buttons.test.js +13 -7
- package/lib/esm/core-components/atoms/check-box/checkBox.component.js +65 -19
- package/lib/esm/core-components/atoms/check-box/checkBox.stories.js +18 -18
- package/lib/esm/core-components/atoms/check-box/checkBox.test.js +13 -7
- package/lib/esm/core-components/atoms/date-picker/date-picker.component.js +54 -21
- package/lib/esm/core-components/atoms/date-picker/date-picker.stories.js +14 -14
- package/lib/esm/core-components/atoms/date-picker/date-picker.test.js +15 -8
- package/lib/esm/core-components/atoms/form/form.component.js +513 -138
- package/lib/esm/core-components/atoms/form/form.test.js +78 -60
- package/lib/esm/core-components/atoms/icons/icons.component.js +36 -24
- package/lib/esm/core-components/atoms/input/input-otp.component.js +80 -59
- package/lib/esm/core-components/atoms/input/input-pin.component.js +142 -81
- package/lib/esm/core-components/atoms/input/input-pin.stories.js +15 -15
- package/lib/esm/core-components/atoms/input/input-pin.test.js +26 -10
- package/lib/esm/core-components/atoms/input/input.component.js +66 -16
- package/lib/esm/core-components/atoms/input/input.stories.js +16 -16
- package/lib/esm/core-components/atoms/input/input.test.js +28 -10
- package/lib/esm/core-components/atoms/input-dropdown/input-dropdown.component.js +95 -36
- package/lib/esm/core-components/atoms/input-dropdown/input-dropdown.stories.js +13 -13
- package/lib/esm/core-components/atoms/input-dropdown/input-dropdown.test.js +14 -7
- package/lib/esm/core-components/atoms/loader/loader.component.js +80 -20
- package/lib/esm/core-components/atoms/loader/loader.stories.js +9 -9
- package/lib/esm/core-components/atoms/loader/loader.test.js +7 -7
- package/lib/esm/core-components/atoms/radio/radio.component.js +65 -21
- package/lib/esm/core-components/atoms/radio/radio.stories.js +17 -17
- package/lib/esm/core-components/atoms/radio/radio.test.js +13 -7
- package/lib/esm/core-components/atoms/stepper/stepper.component.js +74 -32
- package/lib/esm/core-components/atoms/stepper/stepper.stories.js +14 -14
- package/lib/esm/core-components/atoms/stepper/stepper.test.js +14 -7
- package/lib/esm/core-components/atoms/stepper/stepper.test.js.map +1 -1
- package/lib/esm/core-components/atoms/tabs/tabs.component.js +47 -0
- package/lib/esm/core-components/atoms/tabs/tabs.component.js.map +1 -0
- package/lib/esm/core-components/atoms/tabs/tabs.stories.js +23 -0
- package/lib/esm/core-components/atoms/tabs/tabs.stories.js.map +1 -0
- package/lib/esm/core-components/atoms/tabs/tabs.test.js +19 -0
- package/lib/esm/core-components/atoms/tabs/tabs.test.js.map +1 -0
- package/lib/esm/core-components/atoms/timer/timer.component.js +81 -75
- package/lib/esm/core-components/atoms/timer/timer.test.js +10 -10
- package/lib/esm/core-components/atoms/tooltip/tooltip.component.js +46 -25
- package/lib/esm/core-components/atoms/tooltip/tooltip.component.test.js +9 -9
- package/lib/esm/core-components/atoms/tooltip/tooltip.stories.js +9 -9
- package/lib/esm/core-components/index.js +19 -18
- package/lib/esm/core-components/index.js.map +1 -1
- 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
- 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
- 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
- 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
- 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
- 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
- package/lib/esm/core-components/molecules/css-multiline-input/css-multiline-input.component.js +166 -90
- package/lib/esm/core-components/molecules/css-multiline-input/css-multiline-input.stories.js +9 -9
- package/lib/esm/core-components/molecules/css-multiline-input/css-multiline-input.test.js +9 -7
- package/lib/esm/core-components/molecules/css-multiline-input/css-properties.js +159 -159
- package/lib/esm/core-utils/index.js +2 -2
- package/lib/esm/core-utils/unit-test.utils.js +5 -5
- package/lib/esm/index.js +2 -2
- package/lib/esm/library/assets/svg/index.js +19 -10
- package/lib/esm/reportWebVitals.js +1 -1
- package/lib/esm/setupTests.js +2 -2
- package/package.json +3 -1
|
@@ -1,35 +1,53 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { render, fireEvent } from
|
|
3
|
-
import userEvent from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
2
|
-
export const Icon = ({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
3
|
-
import
|
|
4
|
-
export const InputOtp = ({ className, pin, onPinChanged
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
3
|
-
import
|
|
4
|
-
export const InputPin = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
1
|
+
import { InputPin } from "./input-pin.component";
|
|
2
2
|
const meta = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|