Skip to content

Commit

Permalink
feat: support more properties for textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Aug 18, 2021
1 parent 2bcc6dc commit 9c38921
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 43 deletions.
59 changes: 47 additions & 12 deletions components/form-field-textbox/stencil.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export const Template = ({
disabled = false,
invalid = false,
label = "",
min = "",
max = "",
pattern = "",
placeholder = "",
readOnly = false,
required = false,
Expand All @@ -18,11 +21,11 @@ export const Template = ({
}) =>
`<utrecht-form-field-textbox${autoComplete ? ` autocomplete="${autoComplete}"` : ""}${
disabled ? ' disabled="true"' : ""
}${invalid ? ' invalid="true"' : ""}${placeholder ? ` placeholder="${placeholder}"` : ""}${
readOnly ? ' readonly="true"' : ""
}${required ? ' required="true"' : ""}${value ? ` value="${value}"` : ""}${
type ? ` type="${type}"` : ""
}>${label}</utrecht-form-field-textbox>`;
}${invalid ? ' invalid="true"' : ""}${min !== "" ? ` min="${min}"` : ""}${max !== "" ? ` max="${max}"` : ""}${
pattern ? ` pattern="${pattern}"` : ""
}${placeholder ? ` placeholder="${placeholder}"` : ""}${readOnly ? ' readonly="true"' : ""}${
required ? ' required="true"' : ""
}${value ? ` value="${value}"` : ""}${type ? ` type="${type}"` : ""}>${label}</utrecht-form-field-textbox>`;

<Meta
title="Web Component/Form field with textbox"
Expand Down Expand Up @@ -105,6 +108,18 @@ export const Template = ({
description: "Set the content of the label",
control: "text",
},
min: {
description: "Minimum",
control: "number",
},
max: {
description: "Maximum",
control: "number",
},
pattern: {
description: "Pattern",
control: "text",
},
placeholder: {
description: "Placeholder",
control: "text",
Expand All @@ -124,7 +139,7 @@ export const Template = ({
type: {
description: "Type",
control: { type: "select" },
options: ["email", "password", "search", "tel", "text", "url"],
options: ["", "email", "password", "search", "tel", "text", "url"],
},
}}
parameters={{
Expand All @@ -147,10 +162,13 @@ export const Template = ({
disabled: false,
invalid: false,
label: "Message",
min: "",
max: "",
pattern: "",
placeholder: "",
readOnly: false,
required: false,
value: "Lorem ipsum dolor sit amet",
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
type: "",
}}
>
Expand All @@ -170,7 +188,7 @@ export const Template = ({
args={{
disabled: true,
label: "Message",
value: "Lorem ipsum dolor sit amet",
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
Expand All @@ -185,7 +203,7 @@ export const Template = ({
args={{
invalid: true,
label: "Message",
value: "Lorem ipsum dolor sit amet",
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
Expand All @@ -200,7 +218,7 @@ export const Template = ({
args={{
required: true,
label: "Message",
value: "Lorem ipsum dolor sit amet",
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
Expand All @@ -216,7 +234,24 @@ export const Template = ({
autoComplete: "new-password",
label: "New password",
type: "password",
value: "Lorem ipsum dolor sit amet",
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>

## Number input

<Canvas>
<Story
name="Number input"
args={{
min: 0,
max: 100,
label: "Lucky number",
type: "number",
value: "42",
}}
>
{Template.bind({})}
Expand All @@ -230,7 +265,7 @@ export const Template = ({
name="Placeholder"
args={{
label: "Message",
placeholder: "Lorem ipsum dolor sit amet",
placeholder: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
Expand Down
10 changes: 8 additions & 2 deletions components/form-field-textbox/stencil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export class FormFieldTextbox {
@Prop({ attribute: "autocomplete", reflect: true }) autoComplete: string = "";
@Prop({ reflect: true }) disabled: boolean = false;
@Prop({ reflect: true }) invalid: boolean = false;
@Prop({ attribute: "readonly", reflect: true }) readOnly: boolean = false;
@Prop() min: string = "";
@Prop() max: string = "";
@Prop() pattern: string = "";
@Prop() placeholder: string = "";
@Prop({ attribute: "readonly", reflect: true }) readOnly: boolean = false;
@Prop({ reflect: true }) required: boolean = false;
@Prop({ reflect: true }) type: string = "";
@Prop() value: string = "";
Expand All @@ -26,7 +29,7 @@ export class FormFieldTextbox {
@Event() utrechtInput: EventEmitter;

render() {
const { autoComplete, disabled, invalid, placeholder, readOnly, required, type, value } = this;
const { autoComplete, disabled, invalid, min, max, pattern, placeholder, readOnly, required, type, value } = this;

return (
<div class="utrecht-form-field-textbox">
Expand All @@ -41,6 +44,9 @@ export class FormFieldTextbox {
type={type || "text"}
autoComplete={autoComplete}
disabled={disabled}
min={min}
max={max}
pattern={pattern}
placeholder={placeholder || null}
readonly={readOnly}
required={required}
Expand Down
159 changes: 159 additions & 0 deletions components/textbox/bem.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!--
@license EUPL-1.2
Copyright (c) 2021 Robbert Broersma
-->

import { Meta, Story, Canvas, ArgsTable } from "@storybook/addon-docs";
import "./bem.scss";
import clsx from "clsx";

export const Template = ({
disabled = false,
focus = false,
invalid = false,
readOnly = false,
required = false,
value = "",
}) =>
`<input class="${clsx(
"utrecht-textbox",
disabled && "utrecht-textbox--disabled",
focus && "utrecht-textbox--focus",
invalid && "utrecht-textbox--invalid",
readOnly && "utrecht-textbox--readonly",
required && "utrecht-textbox--required"
)}" value="${value}">`;

<Meta
title="CSS Component/Text Box"
argTypes={{
disabled: {
description: "Disabled",
control: "boolean",
},
focus: {
description: "Focus",
control: "boolean",
},
invalid: {
description: "Invalid",
control: "boolean",
},
readOnly: {
description: "Read-only",
control: "boolean",
},
required: {
description: "Required",
control: "boolean",
},
value: {
description: "Set the value of the text box",
control: "text",
},
}}
parameters={{
docs: {
transformSource: (_src, { args }) => Template(args),
},
status: {
type: "WORK IN PROGRESS",
},
}}
/>

# Text box component

Styling via the `<input>` element:

<Canvas>
<Story
name="Text box"
args={{
disabled: false,
focus: false,
invalid: false,
readOnly: false,
required: false,
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>

<ArgsTable story="Text box" />

## States

### Disabled

<Canvas>
<Story
name="Disabled text box"
args={{
disabled: true,
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Invalid

<Canvas>
<Story
name="Invalid text box"
args={{
invalid: true,
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Read-only

<Canvas>
<Story
name="Read-only text box"
args={{
readOnly: true,
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Required

<Canvas>
<Story
name="Required text box"
args={{
required: true,
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>

## Interactive States

### Focus

<Canvas>
<Story
name="Text box with focus"
args={{
focus: true,
value: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
>
{Template.bind({})}
</Story>
</Canvas>
2 changes: 2 additions & 0 deletions components/textbox/html.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
@import "./bem";

.utrecht-html {
input:not([type]),
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
Expand Down
Loading

0 comments on commit 9c38921

Please sign in to comment.