Skip to content

Commit bb17417

Browse files
committed
feat: text input storie
1 parent 8471fc1 commit bb17417

File tree

8 files changed

+120
-2
lines changed

8 files changed

+120
-2
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
'no-spaced-func': 0,
1515
'react/react-in-jsx-scope': 2,
1616
'import/order': [
17-
2,
17+
0,
1818
{
1919
groups: [['builtin', 'external'], 'internal', ['sibling', 'parent', 'index'], 'object', 'type'],
2020
pathGroups: [

example/.storybook/preview.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const theme: DefaultTheme = {
66
colors: {
77
black: '#000000',
88
},
9+
textinputs: {
10+
background: '#5999fa',
11+
placeholder: {
12+
color: '#535AE4',
13+
},
14+
},
915
buttons: {
1016
primary: '#000000',
1117
secondary: '#E5E5E5',
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from 'react'
2+
import { View } from 'react-native'
3+
import { TextField } from '@berty/ui-components'
4+
import type { Meta } from '@storybook/react'
5+
6+
const meta = {
7+
title: 'Components/TextField',
8+
component: TextField,
9+
argTypes: {
10+
onPress: { action: 'pressed the button' },
11+
color: {
12+
control: {
13+
type: 'text',
14+
options: ['primary', 'secondary'],
15+
defaultValue: 'primary',
16+
},
17+
},
18+
},
19+
args: {
20+
color: 'primary',
21+
children: 'Primary Button',
22+
placeholder: 'Placeholder Text',
23+
},
24+
decorators: [
25+
Story => (
26+
<View
27+
style={{
28+
flex: 1,
29+
padding: 16,
30+
alignItems: 'flex-start',
31+
backgroundColor: '#4690FF',
32+
}}
33+
>
34+
<Story />
35+
</View>
36+
),
37+
],
38+
} satisfies Meta<typeof TextField>
39+
40+
export default meta
41+
42+
export const Basic = (args: any) => (
43+
<>
44+
<TextField {...args} />
45+
<View style={{ height: 16 }} />
46+
<TextField {...args} type='password' text='' />
47+
<View style={{ height: 16 }} />
48+
<TextField {...args} type='password' />
49+
</>
50+
)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"registry": "https://registry.npmjs.org/"
6666
},
6767
"dependencies": {
68+
"@expo/vector-icons": "^14.0.4",
6869
"styled-components": "^6.1.14"
6970
},
7071
"devDependencies": {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react'
2+
import { TextInputProps } from 'react-native'
3+
import styled, { DefaultTheme } from 'styled-components/native'
4+
import { FontAwesome } from '@expo/vector-icons'
5+
6+
export type Props = {
7+
type: 'password' | 'text'
8+
theme: DefaultTheme
9+
} & TextInputProps
10+
11+
export const TextField: React.FC<Props> = props => {
12+
const [isSecureText, setShowSecureText] = React.useState(props.type === 'password')
13+
14+
return (
15+
<Container>
16+
<TextFieldStyled {...props} secureTextEntry={isSecureText} />
17+
{props.type === 'password' ? (
18+
<ToggleIcon>
19+
<FontAwesome size={28} name={isSecureText ? 'eye-slash' : 'eye'} onPress={() => setShowSecureText(prev => !prev)} />
20+
</ToggleIcon>
21+
) : null}
22+
</Container>
23+
)
24+
}
25+
26+
const Container = styled.View<Props>`
27+
flex-direction: row;
28+
align-items: center;
29+
border-width: 1px;
30+
border-radius: 4px;
31+
padding: 2px;
32+
margin: 10px 0;
33+
border-color: ${({ theme }: { theme: DefaultTheme }) => theme.colors.black};
34+
color: ${({ theme }: { theme: DefaultTheme }) => theme.colors.black};
35+
background-color: ${({ theme }: { theme: DefaultTheme }) => theme.textinputs?.background};
36+
`
37+
38+
const TextFieldStyled = styled.TextInput.attrs((props: Props) => ({
39+
placeholderTextColor: props.theme.textinputs?.placeholder.color || props.theme.colors.black,
40+
}))`
41+
flex: 1;
42+
height: 40px;
43+
width: 100%;
44+
padding-horizontal: 16px;
45+
placeholder: ${({ theme }: { theme: DefaultTheme }) => theme.colors.black};
46+
border-style: solid;
47+
`
48+
49+
const ToggleIcon = styled.TouchableOpacity`
50+
color: ${({ theme }: { theme: DefaultTheme }) => theme.colors.black};
51+
padding: 2px;
52+
`

src/components/theme/styled.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ declare module 'styled-components/native' {
1111
}
1212
}
1313

14+
textinputs: {
15+
background: string
16+
placeholder: {
17+
color: string
18+
}
19+
}
20+
1421
colors: {
1522
black: string
1623
}

src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { DefaultTheme, ThemeProvider } from 'styled-components'
22
import { Button } from './components/buttons'
33
import { H1 } from './components/text'
4+
import { TextField } from './components/textFields/TextField'
45

56
export const Text = { H1 }
67

7-
export { ThemeProvider, DefaultTheme, Button }
8+
export { ThemeProvider, DefaultTheme, Button, TextField }

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ __metadata:
16551655
dependencies:
16561656
"@commitlint/config-conventional": "npm:^17.0.2"
16571657
"@evilmartians/lefthook": "npm:^1.5.0"
1658+
"@expo/vector-icons": "npm:^14.0.4"
16581659
"@react-native/eslint-config": "npm:^0.73.1"
16591660
"@release-it/conventional-changelog": "npm:^9.0.2"
16601661
"@trivago/prettier-plugin-sort-imports": "npm:^5.2.1"

0 commit comments

Comments
 (0)