Skip to content

Commit 7bcf907

Browse files
feat: add better website + ref based validation
1 parent bf14671 commit 7bcf907

28 files changed

+6643
-14318
lines changed

CODE_OF_CONDUCT.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Contributor Covenant Code of Conduct
32

43
## Our Pledge
@@ -18,23 +17,23 @@ diverse, inclusive, and healthy community.
1817
Examples of behavior that contributes to a positive environment for our
1918
community include:
2019

21-
* Demonstrating empathy and kindness toward other people
22-
* Being respectful of differing opinions, viewpoints, and experiences
23-
* Giving and gracefully accepting constructive feedback
24-
* Accepting responsibility and apologizing to those affected by our mistakes,
20+
- Demonstrating empathy and kindness toward other people
21+
- Being respectful of differing opinions, viewpoints, and experiences
22+
- Giving and gracefully accepting constructive feedback
23+
- Accepting responsibility and apologizing to those affected by our mistakes,
2524
and learning from the experience
26-
* Focusing on what is best not just for us as individuals, but for the overall
25+
- Focusing on what is best not just for us as individuals, but for the overall
2726
community
2827

2928
Examples of unacceptable behavior include:
3029

31-
* The use of sexualized language or imagery, and sexual attention or advances of
30+
- The use of sexualized language or imagery, and sexual attention or advances of
3231
any kind
33-
* Trolling, insulting or derogatory comments, and personal or political attacks
34-
* Public or private harassment
35-
* Publishing others' private information, such as a physical or email address,
32+
- Trolling, insulting or derogatory comments, and personal or political attacks
33+
- Public or private harassment
34+
- Publishing others' private information, such as a physical or email address,
3635
without their explicit permission
37-
* Other conduct which could reasonably be considered inappropriate in a
36+
- Other conduct which could reasonably be considered inappropriate in a
3837
professional setting
3938

4039
## Enforcement Responsibilities

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ Remember to add tests for your change if possible. Run the unit tests by:
5959
yarn test
6060
```
6161

62-
6362
### Commit message convention
6463

6564
We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:

README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<h1 align="center">
32
<img src="https://user-images.githubusercontent.com/6492229/120776507-9c7f1200-c524-11eb-905e-5ad46f2c2709.png" width="128">
43
<br>
@@ -20,7 +19,6 @@
2019

2120
Simple form library for React Native with great UX for developer and end-user api and some code inspired by [wsmd/react-native-use-form](https://github.com/wsmd/react-native-use-form)
2221

23-
2422
- Autoscroll to next fields with keyboard (iOS/Android)
2523
- Validation
2624
- Autoscroll to errors in form if submit validation fails
@@ -38,14 +36,15 @@ See an (older) demo: https://twitter.com/RichardLindhout/status/1344009881863516
3836
```sh
3937
yarn add react-native-use-form
4038
```
39+
4140
or
41+
4242
```sh
4343
npm install react-native-use-form
4444
```
4545

46-
47-
4846
## Import some localized strings
47+
4948
Ideally you do this somewhere in your `index.js` before `react-native-use-form` is used.
5049
Currently we have en/nl/de/pl/pt/ar/ko/frf translations but it's really easy to add one extra since it are only some labels and error messages.
5150

@@ -54,21 +53,21 @@ Currently we have en/nl/de/pl/pt/ar/ko/frf translations but it's really easy to
5453
import {
5554
en,
5655
registerTranslation,
57-
registerDefaultLocale
58-
} from 'react-native-use-form'
59-
registerTranslation('en', en)
56+
registerDefaultLocale,
57+
} from 'react-native-use-form';
58+
registerTranslation('en', en);
6059
// you can override the locale per form
61-
registerDefaultLocale('en') // optional (default = en)
60+
registerDefaultLocale('en'); // optional (default = en)
6261
// registerTranslation('nl', nl)
6362
```
6463

6564
### or register your own
65+
6666
Please send a PR with your language to make sure all locales are there next time
67+
6768
```tsx
68-
import {
69-
registerTranslation,
70-
} from 'react-native-use-form'
71-
registerTranslation("en", {
69+
import { registerTranslation } from 'react-native-use-form';
70+
registerTranslation('en', {
7271
required: (params) => `${params.label || params.fieldKey} is required`,
7372
lengtShouldBeLongerThan: (params) =>
7473
`${params.label || params.fieldKey} length should be longer than ${
@@ -81,23 +80,20 @@ registerTranslation("en", {
8180
shouldFollowRegex: (params) =>
8281
params.errorMessage ||
8382
`${params.label || params.fieldKey} is not in the right format`,
84-
})
83+
});
8584
```
8685

8786
## Advanced example
8887

8988
Also see /demo folder in this repository to see advanced usage!
90-
```tsx
9189

90+
```tsx
9291
import * as React from 'react';
9392

9493
import { View, ScrollView } from 'react-native';
9594
import { useFormState, Form } from 'react-native-use-form';
9695
import { Button, HelperText, TextInput } from 'react-native-paper';
9796

98-
99-
100-
10197
export default function App() {
10298
const scrollViewRef = useRef<ScrollView>(null);
10399
const [
@@ -133,11 +129,10 @@ export default function App() {
133129
<TextInputWithError
134130
mode="outlined"
135131
{...email('email', {
136-
137132
validate: (v) => {
138133
return looksLikeMail(v) ? true : 'Email-address is invalid';
139134
},
140-
label: "E-mail"
135+
label: 'E-mail',
141136
})}
142137
/>
143138
<TextInputWithError
@@ -147,7 +142,7 @@ export default function App() {
147142
minLength: 3,
148143
maxLength: 10,
149144
shouldFollowRegexes: [telephoneRegex],
150-
label: "Telefoon"
145+
label: 'Telefoon',
151146
})}
152147
/>
153148
<TextInputWithError
@@ -156,7 +151,7 @@ export default function App() {
156151
required: true,
157152
minLength: 3,
158153
maxLength: 10,
159-
label: "Wachtwoord"
154+
label: 'Wachtwoord',
160155
})}
161156
/>
162157
<Button mode="contained" onPress={submit}>
@@ -167,9 +162,10 @@ export default function App() {
167162
);
168163
}
169164

170-
171-
172-
function TextInputWithError({ errorMessage, ...rest }: React.ComponentProps<typeof TextInput> & { errorMessage?: string }) {
165+
function TextInputWithError({
166+
errorMessage,
167+
...rest
168+
}: React.ComponentProps<typeof TextInput> & { errorMessage?: string }) {
173169
return (
174170
<>
175171
<TextInput {...rest} />
@@ -180,7 +176,6 @@ function TextInputWithError({ errorMessage, ...rest }: React.ComponentProps<type
180176
);
181177
}
182178

183-
184179
const telephoneRegex = {
185180
regex: new RegExp(/^\d+$/),
186181
errorMessage: 'Telephone is invalid',
@@ -198,8 +193,6 @@ function looksLikeMail(str: string): boolean {
198193
str.length - lastDotPos > 2
199194
);
200195
}
201-
202-
203196
```
204197

205198
## Contributing
@@ -211,6 +204,7 @@ See the [contributing guide](../CONTRIBUTING.md) to learn how to contribute to t
211204
MIT
212205

213206
### Checkout our other libraries
207+
214208
- Simple cross platform navigation library for React Native: [react-native-ridge-navigation](https://github.com/web-ridge/react-native-ridge-navigation)
215209
- Smooth and fast cross platform Material Design date and time picker for React Native Paper: [react-native-paper-dates](https://github.com/web-ridge/react-native-paper-dates)
216210
- Smooth and fast cross platform Material Design Tabs for React Native Paper: [react-native-paper-tabs](https://github.com/web-ridge/react-native-paper-tabs)

0 commit comments

Comments
 (0)