-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: TextInput styling regression with icon and block prop usage (#1592)
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/components': patch | ||
--- | ||
|
||
Fixes a styling bug in TextInput components while using its `icon` and `block` props together |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React, {useState, ReactNode} from 'react' | ||
import {Meta} from '@storybook/react' | ||
|
||
import {BaseStyles, Box, ThemeProvider, Text} from '..' | ||
import TextInput, {TextInputProps} from '../TextInput' | ||
import {CheckIcon} from '@primer/octicons-react' | ||
|
||
export default { | ||
title: 'Forms/Text Input', | ||
component: TextInput, | ||
decorators: [ | ||
Story => { | ||
return ( | ||
<ThemeProvider> | ||
<BaseStyles> | ||
<Box paddingTop={5}>{Story()}</Box> | ||
</BaseStyles> | ||
</ThemeProvider> | ||
) | ||
} | ||
], | ||
argTypes: { | ||
sx: { | ||
table: { | ||
disable: true | ||
} | ||
}, | ||
block: { | ||
name: 'Block', | ||
defaultValue: false, | ||
control: { | ||
type: 'boolean' | ||
} | ||
}, | ||
disabled: { | ||
name: 'Disabled', | ||
defaultValue: false, | ||
control: { | ||
type: 'boolean' | ||
} | ||
}, | ||
variant: { | ||
name: 'Variants', | ||
options: ['small', 'medium', 'large'], | ||
control: {type: 'radio'} | ||
} | ||
} | ||
} as Meta | ||
|
||
const Label = ({htmlFor, children}: {htmlFor: string; children: ReactNode}) => ( | ||
<Text as="label" htmlFor={htmlFor} sx={{fontWeight: 600, fontSize: 14}}> | ||
{children} | ||
</Text> | ||
) | ||
|
||
export const Default = (args: TextInputProps) => { | ||
const [value, setValue] = useState('') | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(event.target.value) | ||
} | ||
|
||
const inputId = 'basic-text-input' | ||
|
||
return ( | ||
<form> | ||
<div className="form-group"> | ||
<div className="form-group-header"> | ||
<Label htmlFor={inputId}>Example label</Label> | ||
</div> | ||
<div className="form-group-body"> | ||
<TextInput id={inputId} value={value} onChange={handleChange} {...args} /> | ||
</div> | ||
</div> | ||
</form> | ||
) | ||
} | ||
|
||
export const WithLeadingIcon = (args: TextInputProps) => { | ||
const [value, setValue] = useState('') | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(event.target.value) | ||
} | ||
|
||
const inputId = 'basic-text-input-with-leading-icon' | ||
|
||
return ( | ||
<form> | ||
<Label htmlFor={inputId}>Example label</Label> | ||
<br /> | ||
<TextInput icon={CheckIcon} id={inputId} value={value} onChange={handleChange} type="password" {...args} /> | ||
</form> | ||
) | ||
} | ||
|
||
export const Password = (args: TextInputProps) => { | ||
const [value, setValue] = useState('') | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(event.target.value) | ||
} | ||
|
||
const inputId = 'basic-text-input-as-password' | ||
|
||
return ( | ||
<form> | ||
<Label htmlFor={inputId}>Password</Label> | ||
<br /> | ||
<TextInput type="password" id={inputId} value={value} onChange={handleChange} {...args} /> | ||
</form> | ||
) | ||
} |