Skip to content

Commit e658334

Browse files
authored
Update CodeInput/PinInput components (#746)
* Rename from CodeInput to PinInput * Modified structure of components * Add styling props to pin input
1 parent d390cc3 commit e658334

File tree

14 files changed

+244
-209
lines changed

14 files changed

+244
-209
lines changed

example/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import SectionListExample from "./SectionListExample";
6363
import LinearProgressExample from "./LinearProgressExample";
6464
import CircularProgressExample from "./CircularProgressExample";
6565
import VideoPlayerExample from "./VideoPlayerExample";
66-
import CodeInputExample from "./CodeInputExample";
66+
import PinInputExample from "./PinInputExample";
6767

6868
const ROUTES = {
6969
AudioPlayer: AudioPlayerExample,
@@ -102,7 +102,7 @@ const ROUTES = {
102102
LinearProgress: LinearProgressExample,
103103
CircularProgress: CircularProgressExample,
104104
VideoPlayer: VideoPlayerExample,
105-
CodeInput: CodeInputExample,
105+
PinInput: PinInputExample,
106106
};
107107

108108
let customFonts = {
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
import React from "react";
22
import Section, { Container } from "./Section";
3-
import { CodeInput, CodeInputCell, CodeInputText } from "@draftbit/ui";
3+
import { PinInput, CustomPinInputCell, CustomPinInputText } from "@draftbit/ui";
44

5-
const CodeInputExample: React.FC = () => {
5+
const PinInputExample: React.FC = () => {
66
const [value1, setValue1] = React.useState("");
77
const [value2, setValue2] = React.useState("");
88

99
return (
1010
<Container style={{}}>
11-
<Section title="CodeInput (default cell)" style={{}}>
12-
<CodeInput value={value1} onChangeText={setValue1} />
11+
<Section title="PinInput (default cell)" style={{}}>
12+
<PinInput value={value1} onChangeText={setValue1} />
1313
</Section>
14-
<Section title="CodeInput (custom cell)" style={{}}>
15-
<CodeInput
14+
<Section title="PinInput (default cell, customized)" style={{}}>
15+
<PinInput
16+
value={value1}
17+
onChangeText={setValue1}
18+
focusedBorderColor="green"
19+
unFocusedBorderColor="gray"
20+
focusedBackgroundColor="rgba(0,1,0,0.2)"
21+
focusedBorderWidth={5}
22+
unFocusedBorderWidth={3}
23+
focusedTextColor="green"
24+
style={{ borderRadius: 35, fontWeight: 800 }}
25+
/>
26+
</Section>
27+
<Section title="PinInput (custom cell)" style={{}}>
28+
<PinInput
1629
value={value1}
1730
onChangeText={setValue1}
1831
onInputFull={(value) => console.log("Input full", value)}
1932
renderItem={({ cellValue, isFocused }) => {
2033
return (
21-
<CodeInputCell
34+
<CustomPinInputCell
2235
style={{
2336
width: 70,
2437
height: 70,
@@ -35,22 +48,22 @@ const CodeInputExample: React.FC = () => {
3548
justifyContent: "center",
3649
}}
3750
>
38-
<CodeInputText
51+
<CustomPinInputText
3952
style={{ color: isFocused ? "green" : "black", fontSize: 20 }}
4053
isFocused={isFocused}
4154
>
4255
{cellValue}
43-
</CodeInputText>
44-
</CodeInputCell>
56+
</CustomPinInputText>
57+
</CustomPinInputCell>
4558
);
4659
}}
4760
/>
4861
</Section>
49-
<Section title="CodeInput (more cells)" style={{}}>
50-
<CodeInput cellCount={7} value={value2} onChangeText={setValue2} />
62+
<Section title="PinInput (more cells)" style={{}}>
63+
<PinInput cellCount={7} value={value2} onChangeText={setValue2} />
5164
</Section>
5265
</Container>
5366
);
5467
};
5568

56-
export default CodeInputExample;
69+
export default PinInputExample;

packages/core/src/__tests__/Debouncing.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render, screen, fireEvent, act } from "@testing-library/react-native";
33
import TextInput from "../components/TextInput";
44
import TextField from "../components/TextField";
55
import NumberInput from "../components/NumberInput";
6-
import { CodeInput } from "../components/CodeInput";
6+
import { PinInput } from "../components/PinInput";
77
import DefaultTheme, { Theme } from "../styles/DefaultTheme";
88
import { IconI } from "../interfaces/Icon";
99

@@ -78,12 +78,12 @@ describe("Text Input debouncing test", () => {
7878
);
7979

8080
test.each([200, 500, 1000])(
81-
"should onChangeTextDelayed be called once with %s delay in CodeInput",
81+
"should onChangeTextDelayed be called once with %s delay in PinInput",
8282
(delay) => {
8383
const Wrapper: React.FC = () => {
8484
const [value, setValue] = React.useState("");
8585
return (
86-
<CodeInput
86+
<PinInput
8787
value={value}
8888
onChangeText={(text) => setValue(text)}
8989
changeTextDelay={delay}

packages/core/src/__tests__/components/CodeInput.test.tsx renamed to packages/core/src/__tests__/components/PinInput.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
22
import { render, screen, fireEvent, act } from "@testing-library/react-native";
33
import { View } from "react-native";
4-
import { CodeInput, CodeInputText } from "../../components/CodeInput";
4+
import { PinInput, PinInputText } from "../../components/PinInput";
55
import { Cursor } from "react-native-confirmation-code-field";
66

7-
describe("CodeInput tests", () => {
7+
describe("PinInput tests", () => {
88
test("should onInputFull be called when input is full", () => {
99
const cellCount = 6;
1010
const text = "0".repeat(cellCount);
@@ -13,7 +13,7 @@ describe("CodeInput tests", () => {
1313
const Wrapper: React.FC = () => {
1414
const [value, setValue] = React.useState("");
1515
return (
16-
<CodeInput
16+
<PinInput
1717
value={value}
1818
onChangeText={(text) => setValue(text)}
1919
cellCount={cellCount}
@@ -35,7 +35,7 @@ describe("CodeInput tests", () => {
3535
"should render %s custom input cells",
3636
(cellCount) => {
3737
render(
38-
<CodeInput
38+
<PinInput
3939
renderItem={() => <View testID="test-input-cell" />}
4040
cellCount={cellCount}
4141
/>
@@ -49,24 +49,24 @@ describe("CodeInput tests", () => {
4949
test.each([2, 4, 6, 7, 8])(
5050
"should render %s default input cells when renderItem not provided",
5151
(cellCount) => {
52-
render(<CodeInput cellCount={cellCount} />);
52+
render(<PinInput cellCount={cellCount} />);
5353

5454
const cells = screen.queryAllByTestId("default-code-input-cell");
5555
expect(cells).toHaveLength(cellCount);
5656
}
5757
);
5858

59-
describe("CodeInputText tests", () => {
59+
describe("PinInputText tests", () => {
6060
test("should render cursor when focused and does not have a value", () => {
61-
render(<CodeInputText isFocused />);
61+
render(<PinInputText isFocused />);
6262

6363
const cursor = screen.UNSAFE_queryByType(Cursor);
6464
expect(cursor).toBeTruthy();
6565
});
6666

6767
test("should render text value when focused and has a value", () => {
6868
const text = "sample text";
69-
render(<CodeInputText isFocused>{text}</CodeInputText>);
69+
render(<PinInputText isFocused>{text}</PinInputText>);
7070

7171
const cursor = screen.UNSAFE_queryByType(Cursor);
7272
const componentWithText = screen.queryByText(text);
@@ -76,7 +76,7 @@ describe("CodeInput tests", () => {
7676

7777
test("should render text value when not focused and has a value", () => {
7878
const text = "sample text";
79-
render(<CodeInputText isFocused={false}>{text}</CodeInputText>);
79+
render(<PinInputText isFocused={false}>{text}</PinInputText>);
8080

8181
const cursor = screen.UNSAFE_queryByType(Cursor);
8282
const componentWithText = screen.queryByText(text);

packages/core/src/components/CodeInput/CodeInput.tsx

Lines changed: 0 additions & 95 deletions
This file was deleted.

packages/core/src/components/CodeInput/CodeInputCell.tsx

Lines changed: 0 additions & 73 deletions
This file was deleted.

packages/core/src/components/CodeInput/index.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
import { StyleProp, ViewStyle, View } from "react-native";
3+
4+
interface CustomPinInputCellProps {
5+
style?: StyleProp<ViewStyle>;
6+
}
7+
8+
/**
9+
* Simple View wrapper component to create a custom pin input cell
10+
* Meant to be used in PinInput's renderItem
11+
*/
12+
const CustomPinInputCell: React.FC<
13+
React.PropsWithChildren<CustomPinInputCellProps>
14+
> = ({ style, children }) => {
15+
return <View style={style} children={children} />;
16+
};
17+
18+
export default CustomPinInputCell;

0 commit comments

Comments
 (0)