From fe99d1958bf806392200b4dae0277acf03eb044c Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Tue, 8 Aug 2017 17:05:04 -0400 Subject: [PATCH] feat(textarea): add textarea and interfaces for both inputs --- .../core/src/components/input/input-base.tsx | 58 +++ packages/core/src/components/input/input.tsx | 131 +++++-- .../core/src/components/input/test/basic.html | 130 +------ .../src/components/input/test/textarea.html | 89 +++++ .../core/src/components/input/textarea.tsx | 364 +++++++++++++++--- packages/core/stencil.config.js | 2 +- 6 files changed, 567 insertions(+), 207 deletions(-) create mode 100644 packages/core/src/components/input/input-base.tsx create mode 100644 packages/core/src/components/input/test/textarea.html diff --git a/packages/core/src/components/input/input-base.tsx b/packages/core/src/components/input/input-base.tsx new file mode 100644 index 0000000000..268426e744 --- /dev/null +++ b/packages/core/src/components/input/input-base.tsx @@ -0,0 +1,58 @@ +// Shared Interfaces + +import { EventEmitter } from '@stencil/core'; + +export interface InputBaseComponent { + ionStyle: EventEmitter; + ionBlur: EventEmitter; + ionFocus: EventEmitter; + + clearOnEdit: boolean; + didBlurAfterEdit: boolean; + styleTmr: number; + + // Shared Attributes + autocapitalize: string; + autocomplete: string; + autofocus: boolean; + disabled: boolean; + minlength: number; + maxlength: number; + name: string; + placeholder: string; + readonly: boolean; + required: boolean; + spellcheck: boolean; + value: string; + + // Shared Methods + inputBlurred: (ev: any) => void; + inputChanged: (ev: any) => void; + inputFocused: (ev: any) => void; + inputKeydown: (ev: any) => void; +} + +export interface InputComponent extends InputBaseComponent { + clearInput: boolean; + + // Input Attributes + accept: string; + autocorrect: string; + inputmode: string; + min: string; + max: string; + multiple: boolean; + pattern: string; + results: number; + step: string; + size: number; + type: string; +} + +export interface TextareaComponent extends InputBaseComponent { + + // Textarea Attributes + cols: number; + rows: number; + wrap: string; +} \ No newline at end of file diff --git a/packages/core/src/components/input/input.tsx b/packages/core/src/components/input/input.tsx index 4e159f2f5b..2fbc3a6b3b 100644 --- a/packages/core/src/components/input/input.tsx +++ b/packages/core/src/components/input/input.tsx @@ -2,6 +2,7 @@ import { Component, Element, Event, EventEmitter, Prop, PropDidChange } from '@s import { createThemedClasses } from '../../utils/theme'; +import { InputComponent } from './input-base'; @Component({ tag: 'ion-input', @@ -14,11 +15,12 @@ import { createThemedClasses } from '../../utils/theme'; theme: 'input' } }) -export class Input { - mode: any; - color: any; - styleTmr: any; +export class Input implements InputComponent { + mode: string; + color: string; + didBlurAfterEdit: boolean; + styleTmr: number; @Element() el: HTMLElement; @@ -37,6 +39,16 @@ export class Input { */ @Event() ionFocus: EventEmitter; + /** + * @input {string} If the value of the type attribute is `"file"`, then this attribute will indicate the types of files that the server accepts, otherwise it will be ignored. The value must be a comma-separated list of unique content type specifiers. + */ + @Prop() accept: string; + + /** + * @input {string} Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. Defaults to `"none"`. + */ + @Prop() autocapitalize: string = 'none'; + /** * @input {string} Indicates whether the value of the control can be automatically completed by the browser. Defaults to `"off"`. */ @@ -50,7 +62,7 @@ export class Input { /** * @input {string} This Boolean attribute lets you specify that a form control should have input focus when the page loads. Defaults to `false`. */ - @Prop() autofocus: boolean; + @Prop() autofocus: boolean = false; /** * @input {boolean} If true and the type is `checkbox` or `radio`, the control is selected by default. Defaults to `false`. @@ -72,9 +84,9 @@ export class Input { @Prop() clearInput: boolean = false; /** - * @input {boolean} If true, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types. Defaults to `false`. + * @input {boolean} If true, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types. */ - @Prop({state: true}) clearOnEdit: boolean; + @Prop({ state: true }) clearOnEdit: boolean; /** * @input {boolean} If true, the user cannot interact with this element. Defaults to `false`. @@ -90,14 +102,44 @@ export class Input { } /** - * @input {any} The minimum value, which must not be greater than its maximum (max attribute) value. + * @input {string} A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is `"text"`, `"password"`, `"email"`, or `"url"`. Possible values are: `"verbatim"`, `"latin"`, `"latin-name"`, `"latin-prose"`, `"full-width-latin"`, `"kana"`, `"katakana"`, `"numeric"`, `"tel"`, `"email"`, `"url"`. + */ + @Prop() inputmode: string; + + /** + * @input {string} The maximum value, which must not be less than its minimum (min attribute) value. + */ + @Prop() max: string; + + /** + * @input {number} If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the maximum number of characters that the user can enter. + */ + @Prop() maxlength: number; + + /** + * @input {string} The minimum value, which must not be greater than its maximum (max attribute) value. */ @Prop() min: string; /** - * @input {any} The maximum value, which must not be less than its minimum (min attribute) value. + * @input {number} If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the minimum number of characters that the user can enter. */ - @Prop() max: string; + @Prop() minlength: number; + + /** + * @input {boolean} If true, the user can enter more than one value. This attribute applies when the type attribute is set to `"email"` or `"file"`, otherwise it is ignored. + */ + @Prop() multiple: boolean; + + /** + * @input {string} The name of the control, which is submitted with the form data. + */ + @Prop() name: string; + + /** + * @input {string} A regular expression that the value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored. + */ + @Prop() pattern: string; /** * @input {string} Instructional text that shows before the input has a value. @@ -109,16 +151,31 @@ export class Input { */ @Prop() readonly: boolean = false; + /** + * @input {boolean} If true, the user must fill in a value before submitting a form. + */ + @Prop() required: boolean = false; + + /** + * @input {number} This is a nonstandard attribute supported by Safari that only applies when the type is `"search"`. Its value should be a nonnegative decimal integer. + */ + @Prop() results: number; + /** * @input {string} If true, the element will have its spelling and grammar checked. Defaults to `false`. */ @Prop() spellcheck: boolean = false; /** - * @input {any} Works with the min and max attributes to limit the increments at which a value can be set. + * @input {string} Works with the min and max attributes to limit the increments at which a value can be set. Possible values are: `"any"` or a positive floating point number. */ @Prop() step: string; + /** + * @input {number} The initial size of the control. This value is in pixels unless the value of the type attribute is `"text"` or `"password"`, in which case it is an integer number of characters. This attribute applies only when the `type` attribute is set to `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored. + */ + @Prop() size: number; + /** * @input {string} The type of control to display. The default type is text. Possible values are: `"text"`, `"password"`, `"email"`, `"number"`, `"search"`, `"tel"`, or `"url"`. */ @@ -129,7 +186,6 @@ export class Input { */ @Prop({ state: true }) value: string; - ionViewDidLoad() { this.emitStyle(); @@ -155,13 +211,6 @@ export class Input { }); } - /** - * @hidden - */ - hasValue(): boolean { - return (this.value !== null && this.value !== undefined && this.value !== ''); - } - /** * @hidden @@ -194,15 +243,6 @@ export class Input { } - /** - * @hidden - */ - hasFocus(): boolean { - // check if an input has focus or not - return this.el && (this.el.querySelector(':focus') === this.el.querySelector('input')); - } - - /** * @hidden */ @@ -241,7 +281,6 @@ export class Input { this.didBlurAfterEdit = false; } - /** * @hidden */ @@ -250,32 +289,52 @@ export class Input { this.value = ''; } + /** + * @hidden + */ + hasFocus(): boolean { + // check if an input has focus or not + return this.el && (this.el.querySelector(':focus') === this.el.querySelector('input')); + } + + + /** + * @hidden + */ + hasValue(): boolean { + return (this.value !== null && this.value !== undefined && this.value !== ''); + } + render() { const themedClasses = createThemedClasses(this.mode, this.color, 'text-input'); // TODO aria-labelledby={this.item.labelId} - // OLD RENDER - // '' + - // '' + - // '' + - // '' + - // '
', - return ( + + Slot + + + Toggle @@ -66,129 +71,6 @@ - diff --git a/packages/core/src/components/input/test/textarea.html b/packages/core/src/components/input/test/textarea.html new file mode 100644 index 0000000000..4ec28495c9 --- /dev/null +++ b/packages/core/src/components/input/test/textarea.html @@ -0,0 +1,89 @@ + + + + + Ionic Textareas + + + + + + + + Textareas + + + + + + + Inline Label + + + + + Fixed Label + + + + + + + + + Stacked Label + + + + + Floating Label + + + + + Disabled + + + + + Readonly + + + + + Clear on Edit + + + + + Clear on Edit + + + + +
+ + Toggle Disabled + + + + Toggle Readonly + +
+
+ + +
+ + + + + diff --git a/packages/core/src/components/input/textarea.tsx b/packages/core/src/components/input/textarea.tsx index 2698e86088..2ecaee0c4f 100644 --- a/packages/core/src/components/input/textarea.tsx +++ b/packages/core/src/components/input/textarea.tsx @@ -1,49 +1,321 @@ +import { Component, Element, Event, EventEmitter, Prop, PropDidChange } from '@stencil/core'; -// /** -// * @name TextArea -// * @description -// * -// * `ion-textarea` is used for multi-line text inputs. Ionic still -// * uses an actual ` + ) + } +} diff --git a/packages/core/stencil.config.js b/packages/core/stencil.config.js index 511e6a8859..790d65016e 100644 --- a/packages/core/stencil.config.js +++ b/packages/core/stencil.config.js @@ -14,7 +14,7 @@ exports.config = { { components: ['ion-gesture', 'ion-scroll'], priority: 'low' }, { components: ['ion-grid', 'ion-row', 'ion-col'] }, { components: ['ion-item', 'ion-item-divider', 'ion-item-sliding', 'ion-item-options', 'ion-item-option', 'ion-label', 'ion-list', 'ion-list-header', 'ion-skeleton-text'] }, - { components: ['ion-input'] }, + { components: ['ion-input', 'ion-textarea'] }, { components: ['ion-loading', 'ion-loading-controller'] }, { components: ['ion-menu'], priority: 'low' }, { components: ['ion-modal', 'ion-modal-controller'] },