SegmentedControlItem.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 : undefined,
  18. }"
  19. :pressedColor="pressedColor"
  20. :touchable="!active && !disabled"
  21. @click="emit('click')"
  22. >
  23. <text :style="{
  24. ...itemTextStyle,
  25. color: active ? activeTextColor : activeColor,
  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. activeTextColor: string,
  41. pressedColor: string,
  42. itemStyle: ViewStyle,
  43. itemTextStyle: TextStyle,
  44. }
  45. const emit = defineEmits([ 'click' ]);
  46. const props = defineProps<SegmentedControlItemProps>();
  47. defineOptions({
  48. options: {
  49. virtualHost: true,
  50. }
  51. })
  52. </script>