Skip to content

feat: adds variants to TextArea for resize #271

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

Merged
merged 1 commit into from
May 16, 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
32 changes: 27 additions & 5 deletions src/components/TextArea/TextArea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
component: TextArea,
} as Meta

export const Default: Story = () => <TextArea id="default" />
export const Default: Story = (args) => <TextArea {...args} />

/**
* Supplying a `value` will make the component controlled. The changes can be handled by the standard `onChange`
Expand All @@ -19,13 +19,11 @@ export const Controlled: Story = () => {
return (
<Column>
<TextArea
id="description-event"
label="Description"
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
<TextArea
id="description-value"
label="Description"
value={description}
onValueChange={setDescription}
Expand All @@ -39,8 +37,8 @@ export const Controlled: Story = () => {
*/
export const WithLabel: React.FC = () => (
<Column>
<TextArea id="firstname" label="Description" />
<TextArea id="familyname" label="Family name" />
<TextArea name="firstname" label="First name" />
<TextArea name="familyname" label="Family name" />
</Column>
)

Expand All @@ -55,6 +53,30 @@ export const InlineLabel: Story = () => (
</Label>
)

/**
* A variant can be used to restrict the resize options or constrain it to the parent.
*/
export const Constrain: React.FC = () => (
<Column>
<TextArea
label="Horizontal"
placeholder="Can be resized horizontally"
resize="horizontal"
/>
<TextArea
label="Vertical"
placeholder="Can be resized vertically"
resize="vertical"
/>
<TextArea
label="Constrain"
placeholder="Can be resized but constrained by partent"
constrain
/>
<TextArea label="None" placeholder="Can't be resized" resize="none" />
</Column>
)

export const States: Story = () => (
<Grid
css={{
Expand Down
20 changes: 20 additions & 0 deletions src/components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ const StyledTextArea = styled(
{
padding: '$2',
height: '$8',

variants: {
resize: {
none: {
resize: 'none',
},
vertical: {
resize: 'vertical',
},
horizontal: {
resize: 'horizontal',
},
},
constrain: {
true: {
maxWidth: '100%',
maxHeight: '100%',
},
},
},
}
)

Expand Down