Newer
Older
gnexus-ui-kit / src / vue / components / GnInput.js
@Eugene Sukhodolskiy Eugene Sukhodolskiy 15 hours ago 973 bytes Add Vue adapter foundation
import { defineComponent, h } from "vue";
import { cx, eventValue, iconNode } from "../utils.js";

export default defineComponent({
	name: "GnInput",
	inheritAttrs: false,
	props: {
		modelValue: { type: [String, Number], default: "" },
		label: { type: String, default: "" },
		type: { type: String, default: "text" },
		icon: { type: String, default: "" },
		state: { type: String, default: "" },
		help: { type: String, default: "" }
	},
	emits: ["update:modelValue"],
	setup(props, { attrs, emit }) {
		return () => h("div", { class: "form-group" }, [
			h("label", { class: cx("label", props.state) }, [
				props.label,
				iconNode(props.icon),
				h("input", {
					...attrs,
					type: props.type,
					value: props.modelValue,
					class: cx("input", attrs.class),
					onInput: event => emit("update:modelValue", eventValue(event))
				})
			]),
			props.help && h("div", { class: cx("input-info", props.state === "error" && "error") }, props.help)
		]);
	}
});