generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: form-field-textarea web component
- Loading branch information
Showing
7 changed files
with
242 additions
and
18 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,8 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
@import "../form-label/bem"; | ||
@import "../form-field/bem"; | ||
@import "../textarea/bem"; |
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,160 @@ | ||
<!-- | ||
@license EUPL-1.2 | ||
Copyright (c) 2021 Robbert Broersma | ||
--> | ||
|
||
import { Meta, Story, Canvas, ArgsTable } from "@storybook/addon-docs"; | ||
|
||
export const Template = ({ | ||
disabled = false, | ||
invalid = false, | ||
label = "", | ||
placeholder = "", | ||
readOnly = false, | ||
required = false, | ||
value = "", | ||
}) => | ||
`<utrecht-form-field-textarea${disabled ? ' disabled="true"' : ""}${invalid ? ' invalid="true"' : ""}${ | ||
placeholder ? ` placeholder="${placeholder}"` : "" | ||
}${readOnly ? ' readonly="true"' : ""}${required ? ' required="true"' : ""}${ | ||
value ? ` value="${value}"` : "" | ||
}>${label}</utrecht-form-field-textarea>`; | ||
|
||
<Meta | ||
title="Web Component/Form field with textarea" | ||
argTypes={{ | ||
disabled: { | ||
description: "Disabled", | ||
control: "boolean", | ||
}, | ||
invalid: { | ||
description: "Invalid", | ||
control: "boolean", | ||
}, | ||
label: { | ||
description: "Set the content of the label", | ||
control: "text", | ||
}, | ||
placeholder: { | ||
description: "Placeholder", | ||
control: "text", | ||
}, | ||
readOnly: { | ||
description: "Read-only", | ||
control: "boolean", | ||
}, | ||
required: { | ||
description: "Required", | ||
control: "boolean", | ||
}, | ||
value: { | ||
description: "Value", | ||
control: "text", | ||
}, | ||
}} | ||
parameters={{ | ||
docs: { | ||
transformSource: (_src, { args }) => Template(args), | ||
}, | ||
status: { | ||
type: "WORK IN PROGRESS", | ||
}, | ||
}} | ||
/> | ||
|
||
# Form field with textarea | ||
|
||
<Canvas> | ||
<Story | ||
name="Form field with textarea" | ||
args={{ | ||
disabled: false, | ||
invalid: false, | ||
label: "Message", | ||
placeholder: "", | ||
readOnly: false, | ||
required: false, | ||
value: "Lorem ipsum dolor sit amet", | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
<ArgsTable story="Form field with textarea" /> | ||
|
||
## States | ||
|
||
### Disabled | ||
|
||
<Canvas> | ||
<Story | ||
name="Disabled" | ||
args={{ | ||
disabled: true, | ||
label: "Message", | ||
value: "Lorem ipsum dolor sit amet", | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
### Invalid | ||
|
||
<Canvas> | ||
<Story | ||
name="Invalid" | ||
args={{ | ||
invalid: true, | ||
label: "Message", | ||
value: "Lorem ipsum dolor sit amet", | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
### Read-only | ||
|
||
<Canvas> | ||
<Story | ||
name="Read-only" | ||
args={{ | ||
required: true, | ||
label: "Message", | ||
value: "Lorem ipsum dolor sit amet", | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
### Required | ||
|
||
<Canvas> | ||
<Story | ||
name="Required" | ||
args={{ | ||
required: true, | ||
label: "Message", | ||
value: "Lorem ipsum dolor sit amet", | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
## Placeholder | ||
|
||
<Canvas> | ||
<Story | ||
name="Placeholder" | ||
args={{ | ||
label: "Message", | ||
placeholder: "Lorem ipsum dolor sit amet", | ||
}} | ||
> | ||
{Template.bind({})} | ||
</Story> | ||
</Canvas> |
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,59 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2021 Robbert Broersma | ||
*/ | ||
|
||
import { Component, Event, EventEmitter, Prop, h } from "@stencil/core"; | ||
import clsx from "clsx"; | ||
|
||
@Component({ | ||
tag: "utrecht-form-field-textarea", | ||
styleUrl: "stencil.scss", | ||
shadow: true, | ||
}) | ||
export class FormFieldTextarea { | ||
@Prop({ reflect: true }) disabled: boolean = false; | ||
@Prop({ reflect: true }) invalid: boolean = false; | ||
@Prop({ attribute: "readonly", reflect: true }) readOnly: boolean = false; | ||
@Prop() placeholder: string = ""; | ||
@Prop({ reflect: true }) required: boolean = false; | ||
@Prop() value: string = ""; | ||
@Event() utrechtBlur: EventEmitter; | ||
@Event() utrechtChange: EventEmitter; | ||
@Event() utrechtFocus: EventEmitter; | ||
@Event() utrechtInput: EventEmitter; | ||
|
||
render() { | ||
const { disabled, invalid, placeholder, readOnly, required, value } = this; | ||
|
||
return ( | ||
<div class="utrecht-form-field utrecht-form-field--textarea"> | ||
<textarea | ||
id="input" | ||
class={clsx( | ||
"utrecht-textarea", | ||
disabled && "utrecht-textarea--disabled", | ||
invalid && "utrecht-textarea--invalid", | ||
readOnly && "utrecht-textarea--readonly" | ||
)} | ||
disabled={disabled} | ||
placeholder={placeholder || null} | ||
readonly={readOnly} | ||
required={required} | ||
onBlur={(evt) => this.utrechtBlur.emit(evt)} | ||
onChange={(evt) => this.utrechtChange.emit(evt)} | ||
onFocus={(evt) => this.utrechtFocus.emit(evt)} | ||
onInput={(evt) => { | ||
this.value = (evt.target as HTMLTextAreaElement).value; | ||
this.utrechtInput.emit(evt); | ||
}} | ||
> | ||
{value} | ||
</textarea> | ||
<label class="utrecht-form-field-textarea__label utrecht-form-label" htmlFor="input"> | ||
<slot></slot> | ||
</label> | ||
</div> | ||
); | ||
} | ||
} |
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
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