import { makeComponentProps } from '@/composables/component' import { makeTagProps } from '@/composables/tag' import { genericComponent, propsFactory } from '@/utils' import { ExtractPropTypes } from 'vue' import { computed, ref } from 'vue' export const makeUInnerTagCheckboxProps = propsFactory( { size: { type: String, default: 'sm', required: false, }, checkboxIsChecked: { type: Boolean, default: false, required: false, }, checkboxIsDisabled: { type: Boolean, default: false, required: false, }, ...makeComponentProps(), ...makeTagProps(), }, 'UInnerTagCheckbox' ) export type UInnerTagCheckboxProps = ExtractPropTypes< typeof makeUInnerTagCheckboxProps > export type UInnerTagCheckboxSlots = { // } export const UInnerTagCheckbox = genericComponent()({ name: 'UInnerTagCheckbox', props: makeUInnerTagCheckboxProps(), /* emits: { change: (e: MouseEvent) => true, }, */ emits: { change: (value: boolean) => true, }, setup(props, { emit }) { const backgroundColor = computed(() => { let backgroundColor = 'white' if (!props.checkboxIsChecked && !props.checkboxIsDisabled) { backgroundColor = `bg-white hover:bg-primary-100 active:bg-white active:shadow-xs-btn active:shadow-primary-100` } else if (props.checkboxIsChecked && !props.checkboxIsDisabled) { backgroundColor = `bg-primary-600 hover:bg-primary-700 active:bg-primary-600 active:shadow-xs-btn active:shadow-primary-100` } else if (!props.checkboxIsChecked && props.checkboxIsDisabled) { backgroundColor = 'bg-gray-100 border border-gray-200' } else if (props.checkboxIsChecked && props.checkboxIsDisabled) { backgroundColor = `bg-gray-200 border border-gray-200` } return backgroundColor }) const size = computed(() => { let sizes = '' if (props.size === 'sm') { sizes = 'h-3.5 w-3.5' } else if (props.size === 'md') { sizes = 'h-4.5 w-4' } else if (props.size === 'lg') { sizes = 'h-4.8 w-4.5' } return sizes }) const tagClasses = computed( () => `${backgroundColor.value} cursor-pointer rounded-3 ${size.value} flex justify-center items-center` ) const switchValue = ref(true) const switchCheckbox = () => { switchValue.value = !switchValue.value emit('change', switchValue.value) } return () => (
{props.size === 'lg' && props.checkboxIsChecked ? ( ) : null} {props.size === 'md' && props.checkboxIsChecked ? ( ) : null} {props.size === 'sm' && props.checkboxIsChecked ? ( ) : null}
) }, }) export type UInnerTagCheckbox = InstanceType