ModeSwitchButton.vue 935 Bytes
<script lang="ts" setup>
  import { RadioButton, RadioGroup, Tooltip } from 'ant-design-vue';
  import { TABLE_CARD_MODE_LIST } from './const';
  import { ModeList } from './types';
  import Icon from '../Icon';
  const props = withDefaults(
    defineProps<{
      value: string;
      mode?: ModeList[];
    }>(),
    {
      mode: () => TABLE_CARD_MODE_LIST,
    }
  );

  const emit = defineEmits(['change']);

  const handleChange = (event: Event) => {
    const value = (event.target as HTMLInputElement).value;
    emit('change', value);
  };
</script>

<template>
  <RadioGroup :value="props.value" button-style="solid" @change="handleChange">
    <template v-for="item in $props.mode" :key="item.value">
      <Tooltip :title="item.label">
        <RadioButton class="cursor-pointer" :value="item.value">
          <Icon :icon="item.icon" />
        </RadioButton>
      </Tooltip>
    </template>
  </RadioGroup>
</template>