-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat](@svelteui/core): add Textarea component (#407)
* [@svelteui/core]: add TextArea component * [@svelteui/core]: use camelCase for ids * [docs]: remove unused configurator prop
- Loading branch information
Showing
20 changed files
with
478 additions
and
4 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
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,65 @@ | ||
--- | ||
title: Textarea | ||
group: 'svelteuidev-core' | ||
packageGroup: '@svelteuidev/core' | ||
slug: /core/textarea/ | ||
category: 'inputs' | ||
description: 'Multiline text input' | ||
importCode: "import { Textarea } from '@svelteuidev/core';" | ||
source: 'svelteui-core/src/components/Textarea/Textarea.svelte' | ||
docs: 'core/textarea' | ||
--- | ||
|
||
<script> | ||
import { Demo, TextareaDemos } from '@svelteuidev/demos'; | ||
import { Heading } from "$lib/components"; | ||
</script> | ||
|
||
<svelte:head> | ||
|
||
<title>{title} - SvelteUI</title> | ||
</svelte:head> | ||
|
||
<Heading {title} {group} {packageGroup} {slug} {category} {description} {importCode} {source} {docs} /> | ||
|
||
## Usage | ||
|
||
<Demo demo={TextareaDemos.configurator} /> | ||
|
||
## Bindings | ||
|
||
```svelte | ||
<script> | ||
import { Textarea } from '@svelteuidev/core'; | ||
let value = ''; | ||
</script> | ||
<Textarea bind:value /> | ||
``` | ||
|
||
## Invalid state and error | ||
|
||
<Demo demo={TextareaDemos.invalid} /> | ||
|
||
## Disabled state | ||
|
||
<Demo demo={TextareaDemos.disabled} /> | ||
|
||
## With icon | ||
|
||
<Demo demo={TextareaDemos.icon} /> | ||
|
||
## With right section | ||
|
||
<Demo demo={TextareaDemos.rightsection} /> | ||
|
||
## Accessibility | ||
|
||
Provide `aria-label` in case you use component without label for screen reader support: | ||
|
||
```svelte | ||
<Textarea /> // -> not ok, input is not labeled | ||
<Textarea label="Comment" /> // -> ok, input and label are connected | ||
<Textarea aria-label="Comment" /> // -> ok, label is not visible but will be announced by screen reader | ||
``` |
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
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
38 changes: 38 additions & 0 deletions
38
packages/svelteui-core/src/components/TextInput/TextInput.stories.svelte
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,38 @@ | ||
<script lang="ts"> | ||
import { Meta, Story, Template } from '@storybook/addon-svelte-csf'; | ||
import { TextInput } from './index'; | ||
</script> | ||
|
||
<Meta title="Components/TextInput" component={TextInput} /> | ||
|
||
<Template let:args> | ||
<TextInput {...args} /> | ||
</Template> | ||
|
||
<Story | ||
name="Default" | ||
id="textInputStory" | ||
args={{ | ||
label: 'Full name' | ||
}} | ||
/> | ||
|
||
<Story | ||
name="Description" | ||
id="textInputDescriptionStory" | ||
args={{ | ||
label: 'Full name', | ||
description: 'Tell us your name', | ||
placeholder: 'Hanazono Yurine' | ||
}} | ||
/> | ||
|
||
<Story | ||
name="Error" | ||
id="textInputErrorStory" | ||
args={{ | ||
label: 'Full Name', | ||
placeholder: 'Hanazono Yurine', | ||
error: 'Something went wrong' | ||
}} | ||
/> |
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,7 @@ | ||
import type { DefaultProps } from '$lib/styles'; | ||
import { InputProps } from '../Input/Input'; | ||
import { InputWrapperProps } from '../InputWrapper/InputWrapper'; | ||
|
||
export type TextareaProps = Omit<InputProps, 'size' | 'type'> & | ||
Omit<InputWrapperProps, 'size'> & | ||
DefaultProps<HTMLTextAreaElement>; |
50 changes: 50 additions & 0 deletions
50
packages/svelteui-core/src/components/Textarea/Textarea.stories.svelte
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,50 @@ | ||
<script lang="ts"> | ||
import { Meta, Story, Template } from '@storybook/addon-svelte-csf'; | ||
import { Textarea } from './index'; | ||
</script> | ||
|
||
<Meta title="Components/Textarea" component={Textarea} /> | ||
|
||
<Template let:args> | ||
<Textarea {...args} /> | ||
</Template> | ||
|
||
<Story | ||
name="Default" | ||
id="textareaStory" | ||
args={{ | ||
label: 'Your story', | ||
placeholder: 'Once upon a time' | ||
}} | ||
/> | ||
|
||
<Story | ||
name="Description" | ||
id="textareaDescriptionStory" | ||
args={{ | ||
label: 'Your story', | ||
description: 'Tell us about yourself', | ||
placeholder: 'Once upon a time' | ||
}} | ||
/> | ||
|
||
<Story | ||
name="Resizeable" | ||
id="textareaResizeableStory" | ||
args={{ | ||
label: 'Your story', | ||
placeholder: 'Once upon a time', | ||
rows: 4, | ||
resize: 'vertical' | ||
}} | ||
/> | ||
|
||
<Story | ||
name="Error" | ||
id="textareaErrorStory" | ||
args={{ | ||
label: 'Your story', | ||
placeholder: 'Once upon a time', | ||
error: "That's boring" | ||
}} | ||
/> |
85 changes: 85 additions & 0 deletions
85
packages/svelteui-core/src/components/Textarea/Textarea.svelte
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,85 @@ | ||
<script lang="ts"> | ||
import { get_current_component } from 'svelte/internal'; | ||
import { createEventForwarder, useActions } from '$lib/internal'; | ||
import { randomID } from '$lib/styles'; | ||
import { Input } from '../Input'; | ||
import { InputWrapper } from '../InputWrapper'; | ||
import type { TextareaProps as $$TextareaProps } from './Textarea'; | ||
interface $$Props extends $$TextareaProps {} | ||
export let use: $$Props['use'] = [], | ||
element: $$Props['element'] = undefined, | ||
className: $$Props['className'] = '', | ||
override: $$Props['override'] = {}, | ||
label: $$Props['label'] = '', | ||
description: $$Props['description'] = null, | ||
error: $$Props['error'] = null, | ||
required: $$Props['required'] = false, | ||
labelProps: $$Props['labelProps'] = {}, | ||
descriptionProps: $$Props['descriptionProps'] = {}, | ||
errorProps: $$Props['errorProps'] = {}, | ||
invalid: $$Props['invalid'] = false, | ||
id: $$Props['id'] = 'input-id', | ||
labelElement: $$Props['labelElement'] = 'label', | ||
showRightSection: $$Props['showRightSection'] = undefined, | ||
value: $$Props['value'] = '', | ||
placeholder: $$Props['placeholder'] = ''; | ||
export { className as class }; | ||
/** An action that forwards inner dom node events from parent component */ | ||
const forwardEvents = createEventForwarder(get_current_component()); | ||
const baseId = randomID(id); | ||
// Flag that enables the override of the right section slot | ||
// of the Input component only if it was provided | ||
const _showRightSection = | ||
showRightSection === undefined ? !!$$slots.rightSection : showRightSection; | ||
$: _invalid = invalid || !!error; | ||
</script> | ||
|
||
<!-- | ||
@component | ||
Multiline text input. | ||
@see https://svelteui.org/core/textarea | ||
@example | ||
```tsx | ||
<Textarea | ||
label='Comment' | ||
description="Tell us what's on your mind" | ||
placeholder='Blah blah blah' | ||
required | ||
/> | ||
``` | ||
--> | ||
|
||
<InputWrapper | ||
bind:element | ||
class={className} | ||
{override} | ||
{label} | ||
{description} | ||
{error} | ||
{required} | ||
{labelProps} | ||
{descriptionProps} | ||
{errorProps} | ||
id={baseId} | ||
{labelElement} | ||
> | ||
<Input | ||
bind:value | ||
{required} | ||
id={baseId} | ||
{placeholder} | ||
{...$$restProps} | ||
use={[forwardEvents, [useActions, use]]} | ||
invalid={_invalid} | ||
showRightSection={_showRightSection} | ||
root="textarea" | ||
multiline | ||
> | ||
<slot slot="rightSection" name="rightSection" /> | ||
</Input> | ||
</InputWrapper> |
8 changes: 8 additions & 0 deletions
8
packages/svelteui-core/src/components/Textarea/Textarea.test.ts
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,8 @@ | ||
import { describe } from 'vitest'; | ||
import { itSupportsClassName } from '@svelteuidev/tests'; | ||
|
||
import { default as Textarea } from './Textarea.svelte'; | ||
|
||
describe('Textarea', () => { | ||
itSupportsClassName(Textarea); | ||
}); |
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,2 @@ | ||
export { default as Textarea } from './Textarea.svelte'; | ||
export type { TextareaProps } from './Textarea'; |
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
Oops, something went wrong.