Skip to content

Commit 0bd94cd

Browse files
authored
Merge pull request #374 from e-roy/feat-TextField
feat:TextField
2 parents 44c07e8 + 8fc15af commit 0bd94cd

File tree

9 files changed

+183
-3
lines changed

9 files changed

+183
-3
lines changed

apps/playground/pages/web3-elements/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SheetTrigger,
1919
SheetContent,
2020
Avatar,
21+
TextField,
2122
} from '@web3-ui/components/src';
2223

2324
const Web3ComponentsPage: NextPage = () => {
@@ -150,6 +151,19 @@ const Web3ComponentsPage: NextPage = () => {
150151
<SheetContent side="right"></SheetContent>
151152
</Sheet>
152153
</div>
154+
155+
{/* TextField Element */}
156+
<div className={`item`}>
157+
<Text
158+
size={`lg`}
159+
as={`p`}
160+
weight={'semibold'}
161+
css={{ padding: '$4' }}
162+
>
163+
TextField
164+
</Text>
165+
<TextField placeholder="placeholder" />
166+
</div>
153167
</div>
154168
</main>
155169
);

packages/components/src/elements/Badge/Badge.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { Badge } from './';
32
import { ComponentStory, ComponentMeta } from '@storybook/react';
43

packages/components/src/elements/Button/Button.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { Button } from './';
32
import { ComponentStory, ComponentMeta } from '@storybook/react';
43

packages/components/src/elements/Checkbox/Checkbox.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { Checkbox } from './Checkbox';
32
import { ComponentStory, ComponentMeta } from '@storybook/react';
43

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TextField } from './TextField';
2+
import { ComponentStory, ComponentMeta } from '@storybook/react';
3+
4+
export default {
5+
title: 'Elements/TextField',
6+
component: TextField,
7+
argTypes: {},
8+
} as ComponentMeta<typeof TextField>;
9+
10+
const Template: ComponentStory<typeof TextField> = (args) => (
11+
<TextField {...args} />
12+
);
13+
14+
export const Default = Template.bind({});
15+
Default.args = {
16+
placeholder: 'placeholder',
17+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { render } from '@testing-library/react';
2+
3+
import { TextField } from './TextField';
4+
5+
describe('TextField', () => {
6+
it('renders without throwing', () => {
7+
const { container } = render(<TextField />);
8+
expect(container).toBeInTheDocument();
9+
});
10+
});
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import { styled } from '../../theme/stitches.config';
2+
3+
export const TextField = styled('input', {
4+
// Reset
5+
appearance: 'none',
6+
borderWidth: '0',
7+
boxSizing: 'border-box',
8+
fontFamily: 'inherit',
9+
margin: '0',
10+
outline: 'none',
11+
padding: '0',
12+
width: '100%',
13+
WebkitTapHighlightColor: 'rgba(0,0,0,0)',
14+
'&::before': {
15+
boxSizing: 'border-box',
16+
},
17+
'&::after': {
18+
boxSizing: 'border-box',
19+
},
20+
21+
// Custom
22+
backgroundColor: '$gray50',
23+
boxShadow: 'inset 0 0 0 1px $colors$gray700',
24+
color: '$hiContrast',
25+
fontVariantNumeric: 'tabular-nums',
26+
27+
'&:-webkit-autofill': {
28+
boxShadow:
29+
'inset 0 0 0 1px $colors$blue6, inset 0 0 0 100px $colors$blue300',
30+
},
31+
32+
'&:-webkit-autofill::first-line': {
33+
fontFamily: '$untitled',
34+
color: '$hiContrast',
35+
},
36+
37+
'&:focus': {
38+
boxShadow:
39+
'inset 0px 0px 0px 1px $colors$blue800, 0px 0px 0px 1px $colors$blue700',
40+
'&:-webkit-autofill': {
41+
boxShadow:
42+
'inset 0px 0px 0px 1px $colors$blue700, 0px 0px 0px 1px $colors$blue700, inset 0 0 0 100px $colors$blue300',
43+
},
44+
},
45+
'&::placeholder': {
46+
color: '$gray700',
47+
},
48+
'&:disabled': {
49+
pointerEvents: 'none',
50+
backgroundColor: '$gray100',
51+
color: '$gray800',
52+
cursor: 'not-allowed',
53+
'&::placeholder': {
54+
color: '$gray600',
55+
},
56+
},
57+
'&:read-only': {
58+
backgroundColor: '$gray100',
59+
'&:focus': {
60+
boxShadow: 'inset 0px 0px 0px 1px $colors$gray700',
61+
},
62+
},
63+
64+
variants: {
65+
size: {
66+
'1': {
67+
borderRadius: '$md',
68+
height: '$5',
69+
fontSize: '$lg',
70+
p: '$4',
71+
lineHeight: '$sizes$5',
72+
'&:-webkit-autofill::first-line': {
73+
fontSize: '$1',
74+
},
75+
},
76+
'2': {
77+
borderRadius: '$md',
78+
height: '$6',
79+
fontSize: '$lg',
80+
px: '$6',
81+
lineHeight: '$sizes$6',
82+
'&:-webkit-autofill::first-line': {
83+
fontSize: '$3',
84+
},
85+
},
86+
},
87+
variant: {
88+
ghost: {
89+
boxShadow: 'none',
90+
backgroundColor: 'transparent',
91+
'@hover': {
92+
'&:hover': {
93+
boxShadow: 'inset 0 0 0 1px $colors$gray900',
94+
},
95+
},
96+
'&:focus': {
97+
backgroundColor: '$loContrast',
98+
boxShadow:
99+
'inset 0px 0px 0px 1px $colors$blue700, 0px 0px 0px 1px $colors$blue700',
100+
},
101+
'&:disabled': {
102+
backgroundColor: 'transparent',
103+
},
104+
'&:read-only': {
105+
backgroundColor: 'transparent',
106+
},
107+
},
108+
},
109+
state: {
110+
invalid: {
111+
boxShadow: 'inset 0 0 0 1px $colors$red7',
112+
'&:focus': {
113+
boxShadow:
114+
'inset 0px 0px 0px 1px $colors$red700, 0px 0px 0px 1px $colors$red700',
115+
},
116+
},
117+
valid: {
118+
boxShadow: 'inset 0 0 0 1px $colors$green7',
119+
'&:focus': {
120+
boxShadow:
121+
'inset 0px 0px 0px 1px $colors$green700, 0px 0px 0px 1px $colors$green700',
122+
},
123+
},
124+
},
125+
cursor: {
126+
default: {
127+
cursor: 'default',
128+
'&:focus': {
129+
cursor: 'text',
130+
},
131+
},
132+
text: {
133+
cursor: 'text',
134+
},
135+
},
136+
},
137+
defaultVariants: {
138+
size: '1',
139+
},
140+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TextField';

packages/components/src/elements/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './Checkbox';
44
export * from './DropdownMenu';
55
export * from './Sheet';
66
export * from './Avatar';
7+
export * from './TextField';

0 commit comments

Comments
 (0)