switch.uvue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <cl-switch v-model="checked"></cl-switch>
  6. </demo-item>
  7. <demo-item :label="t('自定义颜色')">
  8. <view class="flex flex-row">
  9. <cl-switch
  10. v-model="checked"
  11. :pt="{
  12. className: 'mr-5',
  13. track: {
  14. className: '!bg-red-100'
  15. },
  16. thumb: {
  17. className: '!bg-red-500'
  18. }
  19. }"
  20. ></cl-switch>
  21. <cl-switch
  22. v-model="checked"
  23. :pt="{
  24. track: {
  25. className: '!bg-purple-100'
  26. },
  27. thumb: {
  28. className: '!bg-purple-500'
  29. }
  30. }"
  31. ></cl-switch>
  32. </view>
  33. </demo-item>
  34. <demo-item :label="t('自定义')">
  35. <cl-switch
  36. v-model="checked"
  37. :loading="isLoading"
  38. :disabled="isDisabled"
  39. :height="isSize ? 60 : 48"
  40. :width="isSize ? 100 : 80"
  41. :pt="{
  42. track: {
  43. className: parseClass([[isCustom, '!rounded-md']])
  44. },
  45. thumb: {
  46. className: parseClass([[isCustom, '!rounded-md']])
  47. }
  48. }"
  49. ></cl-switch>
  50. <cl-list
  51. border
  52. :pt="{
  53. className: 'mt-3'
  54. }"
  55. >
  56. <cl-list-item :label="t('禁用')">
  57. <cl-switch v-model="isDisabled"></cl-switch>
  58. </cl-list-item>
  59. <cl-list-item :label="t('加载中')">
  60. <cl-switch v-model="isLoading"></cl-switch>
  61. </cl-list-item>
  62. <cl-list-item :label="t('大一点')">
  63. <cl-switch v-model="isSize"></cl-switch>
  64. </cl-list-item>
  65. <cl-list-item :label="t('正方形')">
  66. <cl-switch v-model="isCustom"></cl-switch>
  67. </cl-list-item>
  68. </cl-list>
  69. </demo-item>
  70. </view>
  71. </cl-page>
  72. </template>
  73. <script lang="ts" setup>
  74. import { ref } from "vue";
  75. import DemoItem from "../components/item.uvue";
  76. import { parseClass } from "@/cool";
  77. import { t } from "@/locale";
  78. const checked = ref(false);
  79. const isDisabled = ref(false);
  80. const isLoading = ref(false);
  81. const isSize = ref(false);
  82. const isCustom = ref(false);
  83. </script>