/**
* GnInput - Text input field with label, icon, state, and help text.
*
* @typedef {Object} GnInputProps
* @property {string|number} [modelValue=''] - Bound value
* @property {string} [label=''] - Label text
* @property {string} [type='text'] - input type attribute
* @property {string} [icon=''] - Phosphor icon name with ph- prefix (e.g. "ph-pencil-simple")
* @property {string} [state=''] - error | warning | success
* @property {string} [help=''] - Help or validation message
* @property {boolean} [bare=false] - Render bare input without .form-group wrapper
*
* @emits update:modelValue
*/
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: "" },
bare: { type: Boolean, default: false }
},
emits: ["update:modelValue"],
setup(props, { attrs, emit }) {
return () => {
const input = h("input", {
...attrs,
type: props.type,
value: props.modelValue,
class: cx(props.bare ? "" : "input", attrs.class),
onInput: event => emit("update:modelValue", eventValue(event))
});
if(props.bare) {
return input;
}
return h("div", { class: "form-group" }, [
h("label", { class: cx("label", props.state) }, [
props.label,
iconNode(props.icon),
input
]),
props.help && h("div", { class: cx("input-info", props.state === "error" && "error") }, props.help)
]);
};
}
});