Skip to content

Commit

Permalink
feat(Input): add more size type
Browse files Browse the repository at this point in the history
  • Loading branch information
shervinchen committed Oct 26, 2024
1 parent 220be3a commit 2e41e0b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 2 additions & 0 deletions demo/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export function DemoInputTypes() {
export function DemoInputSizes() {
return (
<Unit layout="col">
<Input size="xs" placeholder="Extra Small" />
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />
<Input size="xl" placeholder="Extra Large" />
</Unit>
);
}
Expand Down
22 changes: 18 additions & 4 deletions packages/Input/Input.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,30 @@ export const useInputStyles = ({
const sizes: {
[key in InputSizes]: InputSizeStyles;
} = {
xs: {
fontSize: '12px',
height: '24px',
horizontalPadding: '8px',
},
sm: {
fontSize: '14px',
height: '32px',
height: '28px',
horizontalPadding: '12px',
},
md: {
fontSize: '14px',
height: '40px',
height: '32px',
horizontalPadding: '12px',
},
lg: {
fontSize: '14px',
height: '36px',
horizontalPadding: '12px',
},
xl: {
fontSize: '16px',
height: '48px',
height: '40px',
horizontalPadding: '16px',
},
};
const styles: {
Expand Down Expand Up @@ -103,6 +116,7 @@ export const useInputCSS = ({ type, size, width, disabled }: InputProps) => {
const {
fontSize,
height,
horizontalPadding,
color,
borderColor,
backgroundColor = 'transparent',
Expand All @@ -118,7 +132,7 @@ export const useInputCSS = ({ type, size, width, disabled }: InputProps) => {
box-sizing: border-box;
display: inline-flex;
height: ${height};
padding: 0 12px;
padding: 0 ${horizontalPadding};
line-height: normal;
box-shadow: none;
font-size: ${fontSize};
Expand Down
3 changes: 2 additions & 1 deletion packages/Input/Input.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';

export type InputTypes = 'default' | 'primary' | 'warning' | 'error';

export type InputSizes = 'sm' | 'md' | 'lg';
export type InputSizes = 'xs' | 'sm' | 'md' | 'lg' | 'xl';

export interface BaseInputProps {
value?: string;
Expand Down Expand Up @@ -31,6 +31,7 @@ export type InputProps = BaseInputProps & NativeInputProps;
export interface InputSizeStyles {
fontSize?: string;
height?: string;
horizontalPadding?: string;
}

export interface InputBasicStyles {
Expand Down
14 changes: 8 additions & 6 deletions packages/Input/__tests__/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const typeColorMap = {
};

const sizeHeightMap = {
sm: '32px',
md: '40px',
lg: '48px',
xs: '24px',
sm: '28px',
md: '32px',
lg: '36px',
xl: '40px',
};

const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
Expand Down Expand Up @@ -107,7 +109,7 @@ describe('Input', () => {
}
);

['sm', 'md', 'lg'].forEach((item: InputSizes) => {
['xs', 'sm', 'md', 'lg', 'xl'].forEach((item: InputSizes) => {
test(`should render ${item} size`, () => {
render(<Input size={item} />);
expect(screen.getByRole('textbox')).toHaveStyle(
Expand Down Expand Up @@ -231,8 +233,8 @@ describe('Input', () => {
disabled: false,
})
);
expect(result1.current.height).toBe('40px');
expect(result2.current.height).toBe('40px');
expect(result1.current.height).toBe('32px');
expect(result2.current.height).toBe('32px');
});

test('should get default focus style when type is unknown or falsy', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/Input/__tests__/__snapshots__/Input.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Input should match the snapshot 1`] = `
<DocumentFragment>
<input
autocomplete="off"
class="raw-input jsx-2920133267"
class="raw-input jsx-2241868620"
placeholder=""
type="text"
value=""
Expand Down
6 changes: 6 additions & 0 deletions src/app/(article)/components/input/input.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import { Input } from 'raw-ui';
scope={{ Grid, Input }}
code={`
<Grid gutter={[0, 32]}>
<Grid.Col span={24}>
<Input size="xs" placeholder="Extra Small" />
</Grid.Col>
<Grid.Col span={24}>
<Input size="sm" placeholder="Small" />
</Grid.Col>
Expand All @@ -49,6 +52,9 @@ import { Input } from 'raw-ui';
<Grid.Col span={24}>
<Input size="lg" placeholder="Large" />
</Grid.Col>
<Grid.Col span={24}>
<Input size="xl" placeholder="Extra Small" />
</Grid.Col>
</Grid>
`}
/>
Expand Down

0 comments on commit 2e41e0b

Please sign in to comment.