SegmentedControlItem.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <Touchable
  3. :innerStyle="{
  4. ...itemStyle,
  5. ...disabled ? { opacity: 0.5 } : {},
  6. ...(index === 0 ? {
  7. borderTopLeftRadius: radius,
  8. borderBottomLeftRadius: radius,
  9. } : {}),
  10. ...(index !== maxLen ? {
  11. borderRightWidth: 0,
  12. } : {}),
  13. ...(index === maxLen ? {
  14. borderTopRightRadius: radius,
  15. borderBottomRightRadius: radius,
  16. } : {}),
  17. backgroundColor: active ? activeColor : normalColor,
  18. }"
  19. :pressedColor="pressedColor"
  20. :touchable="!active && !disabled"
  21. @click="emit('click')"
  22. >
  23. <text :style="{
  24. ...itemTextStyle,
  25. color: active ? activeTextColor : textColor,
  26. }">{{ label }}</Text>
  27. </Touchable>
  28. </template>
  29. <script setup lang="ts">
  30. import Touchable from '../feedback/Touchable.vue';
  31. import type { TextStyle, ViewStyle } from '../theme/ThemeDefine';
  32. export interface SegmentedControlItemProps {
  33. label: string,
  34. active: boolean,
  35. index: number,
  36. disabled: boolean,
  37. radius: string,
  38. maxLen: number,
  39. activeColor?: string,
  40. normalColor?: string,
  41. textColor?: string,
  42. activeTextColor?: string,
  43. pressedColor?: string,
  44. itemStyle: ViewStyle,
  45. itemTextStyle: TextStyle,
  46. }
  47. const emit = defineEmits([ 'click' ]);
  48. const props = defineProps<SegmentedControlItemProps>();
  49. defineOptions({
  50. options: {
  51. virtualHost: true,
  52. }
  53. })
  54. </script>