CheckBoxDefaultButton.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="nana-check-default-button" :style="{
  3. ...themeStyles.checkButtonOutView.value,
  4. ...selectStyleType(shape, 'round', {
  5. round: { borderRadius: themeContext.resolveThemeSize(size) },
  6. square: { borderRadius: themeContext.resolveSize(0) },
  7. }),
  8. width: themeContext.resolveSize(size),
  9. height: themeContext.resolveSize(size),
  10. borderStyle: 'solid',
  11. borderWidth: themeContext.resolveSize(borderWidth),
  12. borderColor: themeContext.resolveThemeColor(disabled ?
  13. (on ? disableCheckedBorderColor : disableBorderColor) :
  14. (on ? checkedBorderColor : borderColor)
  15. ),
  16. backgroundColor: themeContext.resolveThemeColor(disabled ?
  17. (on ? disableCheckedBackgroundColor : disableBackgroundColor) :
  18. (on ? checkedBackgroundColor : backgroundColor)
  19. ),
  20. ...style,
  21. }">
  22. <Icon
  23. v-if="on && type=='icon'"
  24. :icon="icon"
  25. :color="disabled ? disableCheckColor : checkColor"
  26. :size="iconSize"
  27. />
  28. <view v-else-if="on && type=='radio'" :style="{
  29. borderRadius: shape === 'round' ? themeContext.resolveThemeSize(iconSize) : undefined,
  30. width: themeContext.resolveThemeSize(iconSize),
  31. height: themeContext.resolveThemeSize(iconSize),
  32. backgroundColor: themeContext.resolveThemeColor(disabled ? disableCheckColor : checkColor),
  33. }" />
  34. </View>
  35. </template>
  36. <script setup lang="ts">
  37. import Icon from '../basic/Icon.vue';
  38. import { useTheme, type TextStyle, type ViewStyle } from '../theme/ThemeDefine';
  39. import { DynamicSize, selectStyleType } from '../theme/ThemeTools';
  40. export interface CheckBoxDefaultButtonProps {
  41. /**
  42. * 是否处于激活状态
  43. * @default false
  44. */
  45. on?: boolean;
  46. /**
  47. * 未选中状态下边框颜色。
  48. * @default border.input
  49. */
  50. borderColor?: string|undefined;
  51. /**
  52. * 选中状态下边框颜色。
  53. * @default primary
  54. */
  55. checkedBorderColor?: string|undefined;
  56. /**
  57. * 禁用并且未选中状态下边框颜色。
  58. * @default grey
  59. */
  60. disableBorderColor?: string|undefined;
  61. /**
  62. * 禁用并且选中状态下边框颜色。
  63. * @default grey
  64. */
  65. disableCheckedBorderColor?: string|undefined;
  66. /**
  67. * 图标颜色。
  68. * @default white
  69. */
  70. checkColor?: string|undefined;
  71. /**
  72. * 禁用状态下图标颜色。
  73. * @default grey
  74. */
  75. disableCheckColor?: string|undefined;
  76. /**
  77. * 未选中状态下按钮背景颜色。
  78. * @default white
  79. */
  80. backgroundColor?: string|undefined;
  81. /**
  82. * 且选中状态下按钮背景颜色。
  83. * @default primary
  84. */
  85. checkedBackgroundColor?: string|undefined;
  86. /**
  87. * 禁用并且未选中状态下按钮背景颜色。
  88. * @default background
  89. */
  90. disableBackgroundColor?: string|undefined;
  91. /**
  92. * 禁用并且选中状态下按钮背景颜色。
  93. * @default background
  94. */
  95. disableCheckedBackgroundColor?: string|undefined;
  96. /**
  97. * 按钮大小。
  98. * @default 36
  99. */
  100. size?: number|undefined;
  101. /**
  102. * 图标大小。
  103. * @default 30
  104. */
  105. iconSize?: number|undefined;
  106. /**
  107. * 边框粗细。
  108. * @default 2
  109. */
  110. borderWidth?: number|undefined;
  111. /**
  112. * 图标。
  113. * @default 'check-mark'
  114. */
  115. icon?: string;
  116. /**
  117. * 是否处于禁用状态。
  118. * @default false
  119. */
  120. disabled?: boolean;
  121. /**
  122. * 自定义样式
  123. */
  124. style?: ViewStyle,
  125. /**
  126. * 这个按钮的形状。
  127. * * square:正方形
  128. * * round:圆形
  129. * @default 'round'
  130. */
  131. shape?: "square"|"round";
  132. /**
  133. * 这个按钮的显示模式。
  134. * * icon:多选按钮显示的图标
  135. * * radio:单选按钮显示的圆形
  136. * @default 'icon'
  137. */
  138. type?: "icon"|"radio";
  139. }
  140. const themeContext = useTheme();
  141. withDefaults(defineProps<CheckBoxDefaultButtonProps>(), {
  142. on: false,
  143. borderColor: 'border.input',
  144. checkedBorderColor: 'primary',
  145. disableBorderColor: 'grey',
  146. disableCheckedBorderColor: 'grey',
  147. checkColor: 'white',
  148. disableCheckColor: 'grey',
  149. backgroundColor: 'white',
  150. checkedBackgroundColor: 'primary',
  151. disableBackgroundColor: 'background',
  152. disableCheckedBackgroundColor: 'background',
  153. size: 36,
  154. iconSize: 30,
  155. borderWidth: 2,
  156. icon: 'check-mark',
  157. disabled: false,
  158. shape: 'round',
  159. type: 'icon',
  160. });
  161. const themeStyles = themeContext.useThemeStyles({
  162. checkButtonOutView: {
  163. marginRight: DynamicSize('CheckBoxButtonMarginRight', 8),
  164. },
  165. })
  166. defineOptions({
  167. options: {
  168. styleIsolation: "shared",
  169. virtualHost: true,
  170. }
  171. })
  172. </script>
  173. <style>
  174. .nana-check-default-button {
  175. display: flex;
  176. overflow: hidden;
  177. flex-direction: row;
  178. align-items: center;
  179. justify-content: center;
  180. }
  181. </style>