UNPKG

@inkline/inkline

Version:

Inkline is the Vue.js UI/UX Library built for creating your next design system

148 lines 3.78 kB
import { defineComponent } from 'vue'; import { uid } from '../../helpers/index.mjs'; import { colorVariantClass, sizePropValidator, FormComponentMixin, defaultPropValue } from '../../mixins/index.mjs'; /** * Slot for default checkbox label * @name default * @kind slot */ const componentName = 'IToggle'; export default defineComponent({ name: componentName, mixins: [ FormComponentMixin ], props: { /** * The color variant of the checkbox * @type light | dark * @default light * @name color */ color: { type: String, default: defaultPropValue(componentName, 'color') }, /** * The disabled state of the checkbox * @type Boolean * @default false * @name disabled */ disabled: { type: Boolean, default: false }, /** * The indeterminate state of the checkbox * @type Boolean * @default false * @name indeterminate */ indeterminate: { type: Boolean, default: false }, /** * Used to set the checkbox value when used inside a checkbox group * @default false * @name value */ value: { default: false }, /** * Used to set the checkbox value when used by itself * @default false * @name modelValue */ modelValue: { default: false }, /** * The unique identifier of the checkbox * @type String * @default uid() * @name name */ name: { type: [String, Number], default() { return uid('toggle'); } }, /** * The readonly state of the checkbox * @type Boolean * @default false * @name readonly */ readonly: { type: Boolean, default: false }, /** * The size variant of the checkbox * @type sm | md | lg * @default md * @name size */ size: { type: String, default: defaultPropValue(componentName, 'size'), validator: sizePropValidator }, /** * The tabindex of the checkbox * @type Number | String * @default 0 * @name tabindex */ tabindex: { type: [Number, String], default: 0 } }, emits: [ /** * Event emitted for setting the modelValue * @event update:modelValue */ 'update:modelValue' ], computed: { classes() { return { ...colorVariantClass(this), [`-${this.size}`]: Boolean(this.size), '-disabled': this.isDisabled, '-readonly': this.isReadonly }; }, checked() { if (this.schema) { return this.schema.value; } return this.modelValue; }, tabIndex() { return this.isDisabled ? -1 : this.tabindex; } }, methods: { clickInputRef() { if (this.isReadonly) { return; } this.$refs.input.click(); }, onChange(event) { this.parent.onInput?.(this.name, event.target.checked); this.$emit('update:modelValue', event.target.checked); }, onBlur(event) { this.parent.onBlur?.(this.name, event); } } }); //# sourceMappingURL=script.mjs.map