RadioButton.vue 569 B

1234567891011121314151617181920212223242526
  1. <template>
  2. <Button
  3. :checked="!disabled && _value === value"
  4. :disabled="disabled"
  5. type="radio"
  6. @click="!disabled && updateValue(value)"
  7. >
  8. <slot></slot>
  9. </Button>
  10. </template>
  11. <script lang="ts" setup>
  12. import { inject } from 'vue'
  13. import { injectKeyRadioGroupValue, type RadioGroupValue } from '@/types/injectKey'
  14. import Button from './Button.vue'
  15. const { value: _value, updateValue } = inject(injectKeyRadioGroupValue) as RadioGroupValue
  16. withDefaults(defineProps<{
  17. value: string
  18. disabled?: boolean
  19. }>(), {
  20. disabled: false,
  21. })
  22. </script>