<script setup>

defineOptions({
  name: 'xtx-checkbox'
})

const slots = defineSlots()

const props = defineProps({
  checked: {
    type: Boolean,
    default: false,
  },
})

const emit = defineEmits(['update:checked'])

const changeChecked = () => {
  emit('update:checked', !props.checked)
}
</script>

<template>
  <div class="xtx-checkbox" @click="changeChecked">
    <!-- 选择 -->
    <i v-if="checked" class="iconfont icon-checked"></i>
    <!-- 未选择 -->
    <i v-else class="iconfont icon-unchecked"></i>
    <span v-if="slots.default">
      <slot></slot>
    </span>
  </div>
</template>

<style scoped lang="less">
.xtx-checkbox {
  display: inline-block;
  margin-right: 2px;
  cursor: pointer;
  .icon-checked {
    color: var(--xtx-color);
    ~ span {
      color: var(--xtx-color);
    }
  }
  i {
    position: relative;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}
</style>
