Skip to content

Commit f10e7fe

Browse files
WesSouzaarturbien
authored andcommitted
refactor(textinput): categorize under Controls, rename TextField to TextInput
1 parent b2b2230 commit f10e7fe

File tree

8 files changed

+105
-205
lines changed

8 files changed

+105
-205
lines changed

src/AppBar/AppBar.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
MenuList,
77
MenuListItem,
88
Separator,
9-
TextField,
9+
TextInput,
1010
Toolbar
1111
} from 'react95';
1212
import styled from 'styled-components';
@@ -74,7 +74,7 @@ export function Default() {
7474
)}
7575
</div>
7676

77-
<TextField placeholder='Search...' width={150} />
77+
<TextInput placeholder='Search...' width={150} />
7878
</Toolbar>
7979
</AppBar>
8080
);

src/NumberInput/NumberInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Button } from '../Button/Button';
55
import useControlledOrUncontrolled from '../common/hooks/useControlledOrUncontrolled';
66
import { blockSizes } from '../common/system';
77
import { clamp, getSize } from '../common/utils';
8-
import { TextField } from '../TextField/TextField';
8+
import { TextInput } from '../TextInput/TextInput';
99
import { CommonStyledProps } from '../types';
1010

1111
type NumberInputProps = {
@@ -163,7 +163,7 @@ const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
163163
width: width !== undefined ? getSize(width) : 'auto'
164164
}}
165165
>
166-
<TextField
166+
<TextInput
167167
value={valueDerived}
168168
variant={variant}
169169
onChange={handleInputChange}

src/TextField/TextField.mdx

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/TextField/TextField.stories.tsx renamed to src/TextInput/TextInout.stories.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentMeta } from '@storybook/react';
22
import React, { useState } from 'react';
3-
import { Button, ScrollView, TextField } from 'react95';
3+
import { Button, ScrollView, TextInput } from 'react95';
44
import styled from 'styled-components';
55

66
const loremIpsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sollicitudin, ante vel porttitor posuere, tellus nisi interdum ipsum, non bibendum ante risus ut purus. Curabitur vel posuere odio. Vivamus rutrum, nunc et ullamcorper sagittis, tellus ligula maximus quam, id dapibus sapien metus lobortis diam. Proin luctus, dolor in finibus feugiat, lacus enim gravida sem, quis aliquet tellus leo nec enim. Morbi varius bibendum augue quis venenatis. Curabitur ut elit augue. Pellentesque posuere enim a mattis interdum. Donec sodales convallis turpis, a vulputate elit. Suspendisse potenti.`;
@@ -19,10 +19,10 @@ const Wrapper = styled.div`
1919
`;
2020

2121
export default {
22-
title: 'TextField',
23-
component: TextField,
22+
title: 'Controls/TextInput',
23+
component: TextInput,
2424
decorators: [story => <Wrapper>{story()}</Wrapper>]
25-
} as ComponentMeta<typeof TextField>;
25+
} as ComponentMeta<typeof TextInput>;
2626

2727
export function Default() {
2828
const [state, setState] = useState({
@@ -36,7 +36,7 @@ export function Default() {
3636
return (
3737
<div style={{ width: 400 }}>
3838
<div style={{ display: 'flex' }}>
39-
<TextField
39+
<TextInput
4040
value={state.value}
4141
placeholder='Type here...'
4242
onChange={handleChange}
@@ -47,11 +47,11 @@ export function Default() {
4747
</Button>
4848
</div>
4949
<br />
50-
<TextField defaultValue='Disabled' disabled fullWidth />
50+
<TextInput defaultValue='Disabled' disabled fullWidth />
5151
<br />
52-
<TextField multiline rows={4} defaultValue={loremIpsum} fullWidth />
52+
<TextInput multiline rows={4} defaultValue={loremIpsum} fullWidth />
5353
<br />
54-
<TextField
54+
<TextInput
5555
multiline
5656
disabled
5757
rows={4}
@@ -74,15 +74,15 @@ export function Flat() {
7474
content), just use the flat variant:
7575
</p>
7676
<br />
77-
<TextField
77+
<TextInput
7878
variant='flat'
7979
placeholder='type here...'
8080
width={150}
8181
onChange={onChange}
8282
fullWidth
8383
/>
8484
<br />
85-
<TextField
85+
<TextInput
8686
id='disabled'
8787
variant='flat'
8888
placeholder='Disabled'
@@ -92,7 +92,7 @@ export function Flat() {
9292
fullWidth
9393
/>
9494
<br />
95-
<TextField
95+
<TextInput
9696
multiline
9797
variant='flat'
9898
rows={4}
@@ -101,7 +101,7 @@ export function Flat() {
101101
fullWidth
102102
/>
103103
<br />
104-
<TextField
104+
<TextInput
105105
multiline
106106
variant='flat'
107107
disabled

src/TextField/TextField.spec.tsx renamed to src/TextInput/TextInput.spec.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import React from 'react';
44
import { fireEvent } from '@testing-library/react';
55

66
import { renderWithTheme } from '../../test/utils';
7-
import { TextField } from './TextField';
7+
import { TextInput } from './TextInput';
88

9-
describe('<TextField />', () => {
9+
describe('<TextInput />', () => {
1010
it('should render an <input /> inside the div', () => {
11-
const { container } = renderWithTheme(<TextField />);
11+
const { container } = renderWithTheme(<TextInput />);
1212
const input = container.querySelector('input');
1313
expect(input).toHaveAttribute('type', 'text');
1414
expect(input).not.toHaveAttribute('required');
@@ -21,7 +21,7 @@ describe('<TextField />', () => {
2121
const handleKeyUp = jest.fn();
2222
const handleKeyDown = jest.fn();
2323
const { getByRole } = renderWithTheme(
24-
<TextField
24+
<TextInput
2525
onChange={handleChange}
2626
onFocus={handleFocus}
2727
onBlur={handleBlur}
@@ -50,7 +50,7 @@ describe('<TextField />', () => {
5050
});
5151

5252
it('should considered [] as controlled', () => {
53-
const { getByRole } = renderWithTheme(<TextField value={[]} />);
53+
const { getByRole } = renderWithTheme(<TextInput value={[]} />);
5454
const input = getByRole('textbox');
5555

5656
expect(input).toHaveProperty('value', '');
@@ -60,53 +60,53 @@ describe('<TextField />', () => {
6060

6161
it('should forwardRef to native input', () => {
6262
const inputRef = React.createRef<HTMLInputElement>();
63-
const { getByRole } = renderWithTheme(<TextField ref={inputRef} />);
63+
const { getByRole } = renderWithTheme(<TextInput ref={inputRef} />);
6464
const input = getByRole('textbox');
6565
expect(inputRef.current).toBe(input);
6666
});
6767

6868
describe('multiline', () => {
6969
it('should render textarea when passed the multiline prop', () => {
70-
const { container } = renderWithTheme(<TextField multiline />);
70+
const { container } = renderWithTheme(<TextInput multiline />);
7171
const textarea = container.querySelector('textarea');
7272
expect(textarea).not.toBe(null);
7373
});
7474

7575
it('should forward rows prop', () => {
76-
const { container } = renderWithTheme(<TextField multiline rows={3} />);
76+
const { container } = renderWithTheme(<TextInput multiline rows={3} />);
7777
const textarea = container.querySelector('textarea');
7878
expect(textarea).toHaveAttribute('rows', '3');
7979
});
8080
});
8181

8282
describe('prop: disabled', () => {
8383
it('should render a disabled <input />', () => {
84-
const { container } = renderWithTheme(<TextField disabled />);
84+
const { container } = renderWithTheme(<TextInput disabled />);
8585
const input = container.querySelector('input');
8686
expect(input).toHaveAttribute('disabled');
8787
});
8888
it('should be overridden by props', () => {
89-
const { getByRole, rerender } = renderWithTheme(<TextField disabled />);
90-
rerender(<TextField disabled={false} />);
89+
const { getByRole, rerender } = renderWithTheme(<TextInput disabled />);
90+
rerender(<TextInput disabled={false} />);
9191
const input = getByRole('textbox');
9292
expect(input).not.toHaveAttribute('disabled');
9393
});
9494
});
9595

9696
describe('prop: variant', () => {
9797
it('should be "default" by default', () => {
98-
const { getByTestId } = renderWithTheme(<TextField />);
98+
const { getByTestId } = renderWithTheme(<TextInput />);
9999
expect(getByTestId('variant-default')).toBeInTheDocument();
100100
});
101101
it('should handle "flat" variant', () => {
102-
const { getByTestId } = renderWithTheme(<TextField variant='flat' />);
102+
const { getByTestId } = renderWithTheme(<TextInput variant='flat' />);
103103
expect(getByTestId('variant-flat')).toBeInTheDocument();
104104
});
105105
});
106106

107107
describe('prop: fullWidth', () => {
108108
it('should make component take 100% width', () => {
109-
const { container } = renderWithTheme(<TextField fullWidth />);
109+
const { container } = renderWithTheme(<TextInput fullWidth />);
110110
expect(
111111
window.getComputedStyle(container.firstChild as HTMLInputElement).width
112112
).toBe('100%');

0 commit comments

Comments
 (0)