Skip to content

Commit 6ebedca

Browse files
committed
migrate to yarn v2; expose testID props
1 parent 2c10451 commit 6ebedca

File tree

13 files changed

+9477
-7678
lines changed

13 files changed

+9477
-7678
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ coverage/
77
yarn.lock
88
LICENSE
99
.gitignore
10-
.npmignore
10+
.npmignore
11+
yarnrc.yml

.github/workflows/ci.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
name: CI
22

33
on:
4-
54
push:
6-
branches: [ $default-branch ]
5+
branches: [ main ]
76
pull_request:
8-
branches: [ $default-branch ]
9-
10-
workflow_dispatch:
7+
branches: [ main ]
118

129
jobs:
1310
test:
1411
runs-on: macos-latest
12+
1513
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
14+
- uses: actions/checkout@v4
15+
16+
- name: Use Node.js
17+
uses: actions/setup-node@v4
1818
with:
19-
node-version: 16
19+
node-version: '20.x'
20+
21+
- name: Enable corepack
22+
run: corepack enable
23+
2024
- name: Install dependencies
2125
run: yarn
22-
- name: yarn test
23-
run: yarn test
26+
27+
- name: Run tests
28+
run: yarn run test

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,12 @@ jsconfig.json
5959
example/jsconfig.json
6060
example/src
6161
coverage
62-
RELEASE_NOTES.md
62+
RELEASE_NOTES.md
63+
64+
# Yarn
65+
.yarn/*
66+
!.yarn/patches
67+
!.yarn/plugins
68+
!.yarn/releases
69+
!.yarn/sdks
70+
!.yarn/versions

.npmignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ npm-debug.log
1717
.eslintignore
1818
.eslintrc.js
1919
babel.config.js
20-
jest.config.ts
20+
jest.config.js
2121
tsconfig.json
22-
RELEASE_NOTES.md
22+
RELEASE_NOTES.md
23+
.yarnrc.yml

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ yarn.lock
88
LICENSE
99
.gitignore
1010
.npmignore
11-
.eslintignore
11+
.eslintignore
12+
tsconfig.json
13+
.yarnrc.yml

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ A parity version of the iOS [UIStepper](https://developer.apple.com/reference/ui
2828
## Usage
2929

3030
```javascript
31+
import React from 'react';
3132
import SimpleStepper from 'react-native-simple-stepper';
3233

33-
function Example() {
34+
export default function Example(): React.JSX.Element {
3435
return <SimpleStepper valueChanged={value => console.log(value)} />;
3536
}
36-
37-
export default Example;
3837
```
3938

4039
## Text Position
@@ -44,11 +43,10 @@ export default Example;
4443
| ![screenshot](./screenshots/left.png) | ![screenshot](./screenshots/center.png) | ![screenshot](./screenshots/right.png) |
4544

4645
```javascript
46+
import React from 'react';
4747
import SimpleStepper from 'react-native-simple-stepper';
4848

49-
function TextPositionExample() {
49+
export default function TextPositionExample(): React.JSX.Element {
5050
return <SimpleStepper showText={true} textPosition={'right'} />;
5151
}
52-
53-
export default TextPositionExample;
5452
```

SimpleStepper.tsx

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState} from 'react';
1+
import React from 'react';
22
import {
33
StyleSheet,
44
Text,
@@ -12,6 +12,11 @@ import {
1212
ColorValue,
1313
} from 'react-native';
1414

15+
type HasReachedMaxMin = {
16+
hasReachedMax: boolean;
17+
hasReachedMin: boolean;
18+
};
19+
1520
export type SimpleStepperProps = {
1621
initialValue?: number;
1722
minimumValue?: number;
@@ -47,9 +52,15 @@ export type SimpleStepperProps = {
4752
useColor?: boolean;
4853
color?: ColorValue;
4954
textDecimalPlaces?: number;
55+
containerTestID?: string;
56+
separatorTestID?: string;
57+
incrementImageTestID?: string;
58+
decrementImageTestID?: string;
59+
incrementButtonTestID?: string;
60+
decrementButtonTestID?: string;
5061
};
5162

52-
const SimpleStepper: React.FC<SimpleStepperProps> = ({
63+
const SimpleStepper: React.FunctionComponent<SimpleStepperProps> = ({
5364
initialValue = 0,
5465
minimumValue = 0,
5566
maximumValue = 10,
@@ -107,26 +118,32 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
107118
useColor = false,
108119
color = 'blue',
109120
textDecimalPlaces = 2,
121+
containerTestID = 'container',
122+
separatorTestID = 'separator',
123+
incrementImageTestID = 'incrementImage',
124+
decrementImageTestID = 'decrementImage',
125+
incrementButtonTestID = 'incrementButton',
126+
decrementButtonTestID = 'decrementButton',
110127
}) => {
111-
const [value, setValue] = useState(initialValue);
128+
const [value, setValue] = React.useState(initialValue);
112129

113-
const _decrementAction = () => {
130+
function _decrementAction(): void {
114131
const nextValue = value - stepValue;
115132
const actualValue = _processValue(nextValue);
116133
onDecrement(actualValue);
117134
setValue(actualValue);
118135
valueChanged(actualValue);
119-
};
136+
}
120137

121-
const _incrementAction = () => {
138+
function _incrementAction(): void {
122139
const nextValue = value + stepValue;
123140
const actualValue = _processValue(nextValue);
124141
onIncrement(actualValue);
125142
setValue(actualValue);
126143
valueChanged(actualValue);
127-
};
144+
}
128145

129-
const _processValue = (actualValue: number) => {
146+
function _processValue(actualValue: number): number {
130147
if (actualValue > maximumValue) {
131148
return wraps ? minimumValue : maximumValue;
132149
} else if (actualValue === maximumValue) {
@@ -137,9 +154,9 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
137154
return minimumValue;
138155
}
139156
return actualValue;
140-
};
157+
}
141158

142-
const _getHasMinMax = () => {
159+
function _getHasMinMax(): HasReachedMaxMin {
143160
let hasReachedMax = true;
144161
let hasReachedMin = true;
145162
switch (true) {
@@ -160,9 +177,9 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
160177
hasReachedMax,
161178
hasReachedMin,
162179
};
163-
};
180+
}
164181

165-
const _renderText = () => {
182+
function _renderText(): React.JSX.Element {
166183
if (renderText) {
167184
return renderText(value);
168185
}
@@ -175,9 +192,9 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
175192
displayValue = Number(value.toFixed(textDecimalPlaces));
176193
}
177194
return <Text style={textStyle}>{displayValue}</Text>;
178-
};
195+
}
179196

180-
const _renderIncrementImage = (opacity: number) => {
197+
function _renderIncrementImage(opacity: number): React.JSX.Element {
181198
if (renderIncrementImage) {
182199
return renderIncrementImage(opacity);
183200
}
@@ -190,14 +207,14 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
190207
}
191208
return (
192209
<Image
193-
testID={'incrementImage'}
210+
testID={incrementImageTestID}
194211
style={[_incrementImageStyle, {opacity}]}
195212
source={incrementImage}
196213
/>
197214
);
198-
};
215+
}
199216

200-
const _renderDecrementImage = (opacity: number) => {
217+
function _renderDecrementImage(opacity: number): React.JSX.Element {
201218
if (renderDecrementImage) {
202219
return renderDecrementImage(opacity);
203220
}
@@ -210,12 +227,12 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
210227
}
211228
return (
212229
<Image
213-
testID={'decrementImage'}
230+
testID={decrementImageTestID}
214231
style={[_decrementImageStyle, {opacity}]}
215232
source={decrementImage}
216233
/>
217234
);
218-
};
235+
}
219236

220237
const {hasReachedMin, hasReachedMax} = _getHasMinMax();
221238
const decrementOpacity = hasReachedMin || disabled ? disabledOpacity : 1;
@@ -240,37 +257,37 @@ const SimpleStepper: React.FC<SimpleStepperProps> = ({
240257

241258
return (
242259
<View>
243-
<View testID={'container'} style={_containerStyle}>
260+
<View testID={containerTestID} style={_containerStyle}>
244261
{isLeft && _renderText()}
245-
{isLeft && <View testID={'separator'} style={_separatorStyle} />}
262+
{isLeft && <View testID={separatorTestID} style={_separatorStyle} />}
246263
{renderDecrementStep ? (
247264
renderDecrementStep(value, _decrementAction)
248265
) : (
249266
<TouchableOpacity
250-
testID={'decrementButton'}
267+
testID={decrementButtonTestID}
251268
style={decrementStepStyle}
252269
activeOpacity={activeOpacity}
253270
onPress={_decrementAction}
254271
disabled={hasReachedMin || disabled}>
255272
{_renderDecrementImage(decrementOpacity)}
256273
</TouchableOpacity>
257274
)}
258-
{isCenter && <View testID={'separator'} style={_separatorStyle} />}
275+
{isCenter && <View testID={separatorTestID} style={_separatorStyle} />}
259276
{isCenter && _renderText()}
260277
<View style={_separatorStyle} />
261278
{renderIncrementStep ? (
262279
renderIncrementStep(value, _incrementAction)
263280
) : (
264281
<TouchableOpacity
265-
testID={'incrementButton'}
282+
testID={incrementButtonTestID}
266283
style={incrementStepStyle}
267284
activeOpacity={activeOpacity}
268285
onPress={_incrementAction}
269286
disabled={hasReachedMax || disabled}>
270287
{_renderIncrementImage(incrementOpacity)}
271288
</TouchableOpacity>
272289
)}
273-
{isRight && <View testID={'separator'} style={_separatorStyle} />}
290+
{isRight && <View testID={separatorTestID} style={_separatorStyle} />}
274291
{isRight && _renderText()}
275292
</View>
276293
</View>

__tests__/__snapshots__/SimpleStepper.test.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports[`it renders 1`] = `
3434
}
3535
accessible={true}
3636
collapsable={false}
37-
focusable={true}
37+
focusable={false}
3838
onClick={[Function]}
3939
onResponderGrant={[Function]}
4040
onResponderMove={[Function]}
@@ -173,7 +173,7 @@ exports[`render increment and decrement 1`] = `
173173
}
174174
accessible={true}
175175
collapsable={false}
176-
focusable={true}
176+
focusable={false}
177177
onClick={[Function]}
178178
onResponderGrant={[Function]}
179179
onResponderMove={[Function]}
@@ -403,7 +403,7 @@ exports[`render text 1`] = `
403403
}
404404
accessible={true}
405405
collapsable={false}
406-
focusable={true}
406+
focusable={false}
407407
onClick={[Function]}
408408
onResponderGrant={[Function]}
409409
onResponderMove={[Function]}
@@ -555,7 +555,7 @@ exports[`show center text 1`] = `
555555
}
556556
accessible={true}
557557
collapsable={false}
558-
focusable={true}
558+
focusable={false}
559559
onClick={[Function]}
560560
onResponderGrant={[Function]}
561561
onResponderMove={[Function]}
@@ -734,7 +734,7 @@ exports[`show left text 1`] = `
734734
}
735735
accessible={true}
736736
collapsable={false}
737-
focusable={true}
737+
focusable={false}
738738
onClick={[Function]}
739739
onResponderGrant={[Function]}
740740
onResponderMove={[Function]}
@@ -873,7 +873,7 @@ exports[`show right text 1`] = `
873873
}
874874
accessible={true}
875875
collapsable={false}
876-
focusable={true}
876+
focusable={false}
877877
onClick={[Function]}
878878
onResponderGrant={[Function]}
879879
onResponderMove={[Function]}

0 commit comments

Comments
 (0)