UNPKG

maille

Version:

Component library for MithrilJS

57 lines (56 loc) 1.92 kB
"use strict"; // THIS FILE WAS AUTO-GENERATED FOR PACKAGING, DO NOT MODIFY Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../../types"); class TextInput { constructor(vnode) { if (vnode) { if (vnode.attrs.value) { this.value = vnode.attrs.value; } } } view(vnode) { const classes = ["maille", "maille-text-input"]; const inputType = vnode.attrs.type || "text"; const onChange = vnode.attrs.onChange || types_1.NoOpFn; const onEnterPress = vnode.attrs.onEnterPress || types_1.NoOpFn; const size = vnode.attrs.size || types_1.Size.Medium; // If outlined, add the outline class if (vnode.attrs.rounded) { classes.push("rounded"); } if (vnode.attrs.disabled) { classes.push("disabled"); } classes.push(`size-${size}`); const className = classes.join(" "); return m("input", { id: vnode.attrs.id, className, type: inputType, name: vnode.attrs.name, disabled: vnode.attrs.disabled, placeholder: vnode.attrs.placeholder, onkeyup: (e) => { // Don't redraw, too many will cause dropped events e.redraw = false; // If it's disabled don't do anything if (vnode.attrs.disabled) { return; } if (e.keyCode === types_1.KeyboardKeyCode.Enter) { onEnterPress(this.value, e); return; } if (!e.target) { return; } this.value = e.target.value; onChange(this.value, e); }, value: this.value, }); } } exports.default = TextInput;