Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:TextField #374

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/playground/pages/web3-elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SheetTrigger,
SheetContent,
Avatar,
TextField,
} from '@web3-ui/components/src';

const Web3ComponentsPage: NextPage = () => {
Expand Down Expand Up @@ -150,6 +151,19 @@ const Web3ComponentsPage: NextPage = () => {
<SheetContent side="right"></SheetContent>
</Sheet>
</div>

{/* TextField Element */}
<div className={`item`}>
<Text
size={`lg`}
as={`p`}
weight={'semibold'}
css={{ padding: '$4' }}
>
TextField
</Text>
<TextField placeholder="placeholder" />
</div>
</div>
</main>
);
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/elements/Badge/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Badge } from './';
import { ComponentStory, ComponentMeta } from '@storybook/react';

Expand Down
1 change: 0 additions & 1 deletion packages/components/src/elements/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Button } from './';
import { ComponentStory, ComponentMeta } from '@storybook/react';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { Checkbox } from './Checkbox';
import { ComponentStory, ComponentMeta } from '@storybook/react';

Expand Down
17 changes: 17 additions & 0 deletions packages/components/src/elements/TextField/TextField.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TextField } from './TextField';
import { ComponentStory, ComponentMeta } from '@storybook/react';

export default {
title: 'Elements/TextField',
component: TextField,
argTypes: {},
} as ComponentMeta<typeof TextField>;

const Template: ComponentStory<typeof TextField> = (args) => (
<TextField {...args} />
);

export const Default = Template.bind({});
Default.args = {
placeholder: 'placeholder',
};
10 changes: 10 additions & 0 deletions packages/components/src/elements/TextField/TextField.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render } from '@testing-library/react';

import { TextField } from './TextField';

describe('TextField', () => {
it('renders without throwing', () => {
const { container } = render(<TextField />);
expect(container).toBeInTheDocument();
});
});
140 changes: 140 additions & 0 deletions packages/components/src/elements/TextField/TextField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { styled } from '../../theme/stitches.config';

export const TextField = styled('input', {
// Reset
appearance: 'none',
borderWidth: '0',
boxSizing: 'border-box',
fontFamily: 'inherit',
margin: '0',
outline: 'none',
padding: '0',
width: '100%',
WebkitTapHighlightColor: 'rgba(0,0,0,0)',
'&::before': {
boxSizing: 'border-box',
},
'&::after': {
boxSizing: 'border-box',
},

// Custom
backgroundColor: '$gray50',
boxShadow: 'inset 0 0 0 1px $colors$gray700',
color: '$hiContrast',
fontVariantNumeric: 'tabular-nums',

'&:-webkit-autofill': {
boxShadow:
'inset 0 0 0 1px $colors$blue6, inset 0 0 0 100px $colors$blue300',
},

'&:-webkit-autofill::first-line': {
fontFamily: '$untitled',
color: '$hiContrast',
},

'&:focus': {
boxShadow:
'inset 0px 0px 0px 1px $colors$blue800, 0px 0px 0px 1px $colors$blue700',
'&:-webkit-autofill': {
boxShadow:
'inset 0px 0px 0px 1px $colors$blue700, 0px 0px 0px 1px $colors$blue700, inset 0 0 0 100px $colors$blue300',
},
},
'&::placeholder': {
color: '$gray700',
},
'&:disabled': {
pointerEvents: 'none',
backgroundColor: '$gray100',
color: '$gray800',
cursor: 'not-allowed',
'&::placeholder': {
color: '$gray600',
},
},
'&:read-only': {
backgroundColor: '$gray100',
'&:focus': {
boxShadow: 'inset 0px 0px 0px 1px $colors$gray700',
},
},

variants: {
size: {
'1': {
borderRadius: '$md',
height: '$5',
fontSize: '$lg',
p: '$4',
lineHeight: '$sizes$5',
'&:-webkit-autofill::first-line': {
fontSize: '$1',
},
},
'2': {
borderRadius: '$md',
height: '$6',
fontSize: '$lg',
px: '$6',
lineHeight: '$sizes$6',
'&:-webkit-autofill::first-line': {
fontSize: '$3',
},
},
},
variant: {
ghost: {
boxShadow: 'none',
backgroundColor: 'transparent',
'@hover': {
'&:hover': {
boxShadow: 'inset 0 0 0 1px $colors$gray900',
},
},
'&:focus': {
backgroundColor: '$loContrast',
boxShadow:
'inset 0px 0px 0px 1px $colors$blue700, 0px 0px 0px 1px $colors$blue700',
},
'&:disabled': {
backgroundColor: 'transparent',
},
'&:read-only': {
backgroundColor: 'transparent',
},
},
},
state: {
invalid: {
boxShadow: 'inset 0 0 0 1px $colors$red7',
'&:focus': {
boxShadow:
'inset 0px 0px 0px 1px $colors$red700, 0px 0px 0px 1px $colors$red700',
},
},
valid: {
boxShadow: 'inset 0 0 0 1px $colors$green7',
'&:focus': {
boxShadow:
'inset 0px 0px 0px 1px $colors$green700, 0px 0px 0px 1px $colors$green700',
},
},
},
cursor: {
default: {
cursor: 'default',
'&:focus': {
cursor: 'text',
},
},
text: {
cursor: 'text',
},
},
},
defaultVariants: {
size: '1',
},
});
1 change: 1 addition & 0 deletions packages/components/src/elements/TextField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './TextField';
1 change: 1 addition & 0 deletions packages/components/src/elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './Checkbox';
export * from './DropdownMenu';
export * from './Sheet';
export * from './Avatar';
export * from './TextField';