PaginationItem.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script setup lang="ts">
  2. import { computed, ref } from 'vue';
  3. import { useTheme, type TextStyle, type ViewStyle } from '../theme/ThemeDefine';
  4. import { DynamicSize } from '../theme/ThemeTools';
  5. import Touchable from '../feedback/Touchable.vue';
  6. const themeContext = useTheme();
  7. const themeStyles = themeContext.useThemeStyles({
  8. itemButton: {
  9. display: 'flex',
  10. flexGrow: 1,
  11. alignSelf: 'auto',
  12. justifyContent: 'center',
  13. alignContent: 'center',
  14. textAlign: 'center',
  15. },
  16. itemText: {
  17. fontSize: DynamicSize('PaginationItemTextFontSize', 26),
  18. textAlign: DynamicSize('PaginationItemTextAlign', 'center'),
  19. },
  20. });
  21. interface PaginationItemProps {
  22. text?: string;
  23. touchable?: boolean;
  24. active?: boolean;
  25. pressedColor?: string;
  26. pressedTextColor?: string;
  27. activeColor?: string;
  28. deactiveColor?: string;
  29. activeTextColor?: string;
  30. deactiveTextColor?: string;
  31. buttonStyle?: ViewStyle;
  32. textStyle?: TextStyle;
  33. }
  34. const emit = defineEmits([ 'click' ]);
  35. const props = defineProps<PaginationItemProps>();
  36. const state = ref('');
  37. const pressed = computed(() => state.value === 'active');
  38. </script>
  39. <template>
  40. <Touchable
  41. :pressedColor="themeContext.resolveThemeColor(pressedColor)"
  42. :innerStyle="{
  43. backgroundColor: themeContext.resolveThemeColor(active ? activeColor : (touchable ? deactiveColor : pressedColor)),
  44. ...themeStyles.itemButton.value,
  45. ...buttonStyle,
  46. }"
  47. :padding="[
  48. themeContext.getVar('PaginationItemPaddingHorizontal', 8),
  49. themeContext.getVar('PaginationItemPaddingVertical', 16),
  50. ]"
  51. :touchable="touchable"
  52. @state="(s) => state = s"
  53. @click="touchable && !active ? emit('click') : undefined"
  54. >
  55. <text :style="{
  56. ...themeStyles.itemText.value,
  57. ...textStyle,
  58. color: themeContext.resolveThemeColor(touchable ? (pressed ? pressedTextColor : (active ? activeTextColor : deactiveTextColor)) : pressedTextColor),
  59. }">{{ text}}</text>
  60. </Touchable>
  61. </template>