checkbox.uvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <view class="flex flex-row flex-wrap">
  6. <cl-checkbox
  7. v-model="checked2"
  8. v-for="(item, index) in options"
  9. :key="index"
  10. :value="item.value"
  11. :pt="{
  12. className: 'mr-5'
  13. }"
  14. >
  15. {{ item.label }}
  16. </cl-checkbox>
  17. </view>
  18. </demo-item>
  19. <demo-item :label="t('单个 true / false')">
  20. <view class="flex flex-row justify-between">
  21. <cl-checkbox
  22. v-model="checked4"
  23. :pt="{
  24. className: 'mr-5'
  25. }"
  26. >同意并阅读《用户协议》</cl-checkbox
  27. >
  28. <cl-switch v-model="checked4"></cl-switch>
  29. </view>
  30. </demo-item>
  31. <demo-item :label="t('纵向排列')">
  32. <cl-checkbox
  33. v-model="checked"
  34. v-for="(item, index) in options"
  35. :key="index"
  36. :value="item.value"
  37. :pt="{
  38. className: parseClass([
  39. 'py-2',
  40. [
  41. isVerticalCustom,
  42. 'justify-between border border-solid border-surface-200 rounded-lg p-2 !my-1'
  43. ]
  44. ])
  45. }"
  46. >
  47. {{ item.label }}
  48. </cl-checkbox>
  49. <cl-list
  50. border
  51. :pt="{
  52. className: 'mt-2'
  53. }"
  54. >
  55. <cl-list-item :label="t('换个样式')">
  56. <cl-switch v-model="isVerticalCustom"></cl-switch>
  57. </cl-list-item>
  58. </cl-list>
  59. </demo-item>
  60. <demo-item :label="t('自定义')">
  61. <view class="mb-3 flex flex-row flex-wrap">
  62. <cl-checkbox
  63. v-model="checked3"
  64. v-for="(item, index) in options"
  65. :key="index"
  66. :value="item.value"
  67. :disabled="isDisabled"
  68. :show-icon="!isHideIcon"
  69. :active-icon="isIcon ? 'heart-fill' : 'checkbox-line'"
  70. :inactive-icon="isIcon ? 'heart-line' : 'checkbox-blank-line'"
  71. :pt="{
  72. className: parseClass([
  73. 'mr-5',
  74. [isCustom, 'bg-surface-100 py-2 px-3 rounded-lg !mr-2 !mb-2'],
  75. {
  76. '!bg-surface-700': isDark && isCustom
  77. }
  78. ])
  79. }"
  80. >
  81. {{ item.label }}
  82. </cl-checkbox>
  83. </view>
  84. <cl-list border>
  85. <cl-list-item :label="t('换个图标')">
  86. <cl-switch v-model="isIcon"></cl-switch>
  87. </cl-list-item>
  88. <cl-list-item :label="t('不显示图标')">
  89. <cl-switch v-model="isHideIcon"></cl-switch>
  90. </cl-list-item>
  91. <cl-list-item :label="t('禁用')">
  92. <cl-switch v-model="isDisabled"></cl-switch>
  93. </cl-list-item>
  94. <cl-list-item :label="t('其他样式')">
  95. <cl-switch v-model="isCustom"></cl-switch>
  96. </cl-list-item>
  97. </cl-list>
  98. </demo-item>
  99. </view>
  100. </cl-page>
  101. </template>
  102. <script lang="ts" setup>
  103. import { ref } from "vue";
  104. import DemoItem from "../components/item.uvue";
  105. import { useUi, type ClCheckboxOption } from "@/uni_modules/cool-ui";
  106. import { isDark, parseClass } from "@/cool";
  107. import { t } from "@/locale";
  108. const ui = useUi();
  109. const isIcon = ref(false);
  110. const isCustom = ref(false);
  111. const isDisabled = ref(false);
  112. const isHideIcon = ref(false);
  113. const isVerticalCustom = ref(false);
  114. const checked = ref<string[]>([]);
  115. const checked2 = ref<string[]>(["2"]);
  116. const checked3 = ref<string[]>(["2", "3"]);
  117. const checked4 = ref(false);
  118. const options = ref<ClCheckboxOption[]>([
  119. {
  120. label: "Vue",
  121. value: "1"
  122. },
  123. {
  124. label: "React",
  125. value: "2"
  126. },
  127. {
  128. label: "Angular",
  129. value: "3"
  130. },
  131. {
  132. label: "Svelte",
  133. value: "4"
  134. }
  135. ]);
  136. </script>