@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
92 lines (91 loc) • 2.6 kB
JavaScript
import { defineComponent as u, useAttrs as c, ref as s, watch as f, computed as p } from "vue";
import { NeonSize as g } from "../../../common/enums/NeonSize.es.js";
import { NeonFunctionalColor as h } from "../../../common/enums/NeonFunctionalColor.es.js";
import { NeonSwitchStyle as S } from "../../../common/enums/NeonSwitchStyle.es.js";
import { NeonHorizontalPosition as y } from "../../../common/enums/NeonHorizontalPosition.es.js";
import w from "../../presentation/icon/NeonIcon.vue.es.js";
const P = u({
name: "NeonSwitch",
components: {
NeonIcon: w
},
props: {
/**
* The switch model.
*/
modelValue: { type: Boolean, required: !0 },
/**
* The switch label, the label can be optional only in the case the switch is part of a more complex component.
*/
label: { type: String, default: null },
/**
* The indeterminate state of the checkbox.
*/
indeterminate: { type: Boolean, default: !1 },
/**
* The size of the switch.
*/
size: { type: String, default: () => g.Medium },
/**
* The switch color.
*/
color: { type: String, default: () => h.Primary },
/**
* Style the switch as a <em>Switch</em> or a <em>Checkbox</em>.
*/
switchStyle: { type: String, default: () => S.Switch },
/**
* The position of the switch label.
*/
labelPosition: { type: String, default: () => y.Right },
/**
* Disabled state of the switch.
*/
disabled: { type: Boolean, default: !1 }
},
emits: [
/**
* Emitted when an indeterminate checkbox is toggled to checked.
*
* @type {boolean} The indeterminate state of the checkbox.
*/
"indeterminate-change",
/**
* Emitted when the switch is toggled checked or unchecked.
*
* @type {boolean} The checked state of the switch.
*/
"update:modelValue"
],
setup(t, { emit: i }) {
const a = c(), n = s(null);
f(
() => t.indeterminate,
(e) => {
n.value && (n.value.indeterminate = e);
},
{ immediate: !0 }
);
const l = (e) => {
i("indeterminate-change", e);
}, o = (e) => {
i("update:modelValue", e);
}, r = (e) => {
t.disabled || (t.indeterminate ? (l(!1), o(!0)) : o(e));
}, m = p(() => {
const { onIndeterminateChange: e, onClick: N, ...d } = a;
return d;
});
return {
checkbox: n,
sanitizedAttributes: m,
toggleSwitch: () => {
r(!t.modelValue);
}
};
}
});
export {
P as default
};
//# sourceMappingURL=NeonSwitch.es.js.map