kui-vue 3.4.9 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/LICENSE +1 -1
  2. package/components/affix/affix.jsx +42 -42
  3. package/components/alert/alert.jsx +12 -7
  4. package/components/avatar/AvatarGroup.jsx +8 -5
  5. package/components/avatar/avatar.jsx +10 -7
  6. package/components/avatar/demo/base.md +1 -0
  7. package/components/avatar/demo/info.md +2 -5
  8. package/components/backtop/backtop.jsx +39 -32
  9. package/components/badge/badge.jsx +7 -7
  10. package/components/badge/demo/color.md +0 -1
  11. package/components/badge/styles/index.less +0 -4
  12. package/components/base/{collapse.js → collapse.jsx} +2 -7
  13. package/components/base/drop.jsx +181 -195
  14. package/components/base/input.jsx +27 -46
  15. package/components/base/pop.jsx +21 -17
  16. package/components/base/transition.js +1 -4
  17. package/components/breadcrumb/breadcrumb.jsx +6 -3
  18. package/components/breadcrumb/breadcrumbItem.jsx +4 -2
  19. package/components/breadcrumb/styles/index.less +1 -1
  20. package/components/button/button.jsx +95 -56
  21. package/components/button/buttonGroup.jsx +5 -3
  22. package/components/button/demo/base.md +3 -3
  23. package/components/button/demo/block.md +1 -1
  24. package/components/button/demo/color.md +30 -0
  25. package/components/button/demo/disabled.md +2 -2
  26. package/components/button/demo/index.vue +4 -4
  27. package/components/button/demo/light.md +8 -8
  28. package/components/button/demo/loading.md +10 -7
  29. package/components/button/demo/outline.md +22 -0
  30. package/components/button/demo/size.md +3 -4
  31. package/components/button/demo/with-icon.md +5 -5
  32. package/components/button/styles/index.less +269 -44
  33. package/components/card/card.jsx +4 -2
  34. package/components/carousel/carousel.jsx +143 -97
  35. package/components/carousel/carouselItem.jsx +13 -14
  36. package/components/carousel/styles/index.less +1 -1
  37. package/components/checkbox/checkbox.jsx +6 -4
  38. package/components/checkbox/demo/disabled.md +1 -3
  39. package/components/checkbox/group.jsx +6 -3
  40. package/components/collapse/collapse.jsx +14 -12
  41. package/components/collapse/demo/{accrodion.md → accordion.md} +2 -2
  42. package/components/collapse/demo/index.vue +2 -2
  43. package/components/collapse/panel.jsx +15 -16
  44. package/components/collapse/styles/index.less +3 -3
  45. package/components/colorPicker/alpha.jsx +107 -0
  46. package/components/colorPicker/colorpicker.jsx +177 -384
  47. package/components/colorPicker/demo/base.md +1 -3
  48. package/components/colorPicker/demo/customTriggle.md +34 -0
  49. package/components/colorPicker/demo/disabled.md +22 -0
  50. package/components/colorPicker/demo/disabledAlpha.md +20 -0
  51. package/components/colorPicker/demo/index.vue +11 -5
  52. package/components/colorPicker/demo/mode.md +16 -18
  53. package/components/colorPicker/demo/placement.md +25 -0
  54. package/components/colorPicker/demo/{colors.md → presets.md} +2 -2
  55. package/components/colorPicker/demo/size.md +14 -13
  56. package/components/colorPicker/hue.jsx +114 -0
  57. package/components/colorPicker/index.md +11 -11
  58. package/components/colorPicker/mode.jsx +176 -0
  59. package/components/colorPicker/paint.jsx +126 -0
  60. package/components/colorPicker/presets.jsx +69 -0
  61. package/components/colorPicker/styles/index.less +144 -46
  62. package/components/components.js +155 -0
  63. package/components/const/var.js +3 -0
  64. package/components/datePicker/datecalendar.jsx +34 -34
  65. package/components/datePicker/datepicker.jsx +24 -23
  66. package/components/datePicker/styles/calendar.less +3 -3
  67. package/components/descriptions/descriptions.jsx +12 -8
  68. package/components/descriptions/descriptionsItem.jsx +5 -2
  69. package/components/divider/divider.jsx +4 -2
  70. package/components/drawer/drawer.jsx +74 -69
  71. package/components/dropdown/dropdown.jsx +5 -2
  72. package/components/dropdown/styles/index.less +14 -3
  73. package/components/empty/empty.jsx +5 -5
  74. package/components/flex/demo/align.md +1 -1
  75. package/components/flex/demo/size.md +1 -1
  76. package/components/flex/flex.jsx +12 -4
  77. package/components/form/demo/length.md +1 -1
  78. package/components/form/demo/valid.md +1 -1
  79. package/components/form/form.jsx +9 -8
  80. package/components/form/formitem.jsx +14 -11
  81. package/components/grid/col.jsx +5 -2
  82. package/components/grid/row.jsx +11 -8
  83. package/components/icon/demo/base.md +8 -7
  84. package/components/icon/demo/index.vue +3 -1
  85. package/components/icon/demo/info.md +1 -38
  86. package/components/icon/demo/search.vue +16 -15
  87. package/components/icon/demo/use.md +30 -0
  88. package/components/icon/icon.jsx +5 -2
  89. package/components/image/group.jsx +4 -2
  90. package/components/image/image.jsx +16 -13
  91. package/components/image/index.js +6 -9
  92. package/components/image/{instance.js → instance.jsx} +6 -6
  93. package/components/image/preview.jsx +219 -195
  94. package/components/image/styles/index.less +1 -1
  95. package/components/index.js +36 -142
  96. package/components/input/input.jsx +6 -4
  97. package/components/input/inputGroup.jsx +16 -14
  98. package/components/input/textarea.jsx +16 -7
  99. package/components/inputNumber/demo/base.md +16 -8
  100. package/components/inputNumber/demo/format.md +7 -19
  101. package/components/inputNumber/demo/size.md +2 -6
  102. package/components/inputNumber/inputNumber.jsx +112 -104
  103. package/components/inputNumber/styles/index.less +47 -11
  104. package/components/layout/demo/base.md +11 -6
  105. package/components/layout/demo/layout1.md +82 -63
  106. package/components/layout/demo/layout2.md +93 -56
  107. package/components/layout/demo/layout3.md +95 -53
  108. package/components/layout/demo/layout4.md +97 -45
  109. package/components/layout/demo/layout5.md +81 -80
  110. package/components/layout/index.js +0 -4
  111. package/components/layout/layout.jsx +3 -2
  112. package/components/loading/demo/info.md +3 -3
  113. package/components/loading/{index.js → index.jsx} +29 -24
  114. package/components/locale/index.js +27 -69
  115. package/components/locale/lang/de.js +1 -1
  116. package/components/locale/lang/el.js +1 -1
  117. package/components/locale/lang/en.js +1 -1
  118. package/components/locale/lang/fr.js +2 -2
  119. package/components/locale/lang/it.js +1 -1
  120. package/components/locale/lang/ja.js +1 -1
  121. package/components/locale/lang/ko.js +1 -1
  122. package/components/locale/lang/ru.js +1 -1
  123. package/components/locale/lang/th.js +1 -1
  124. package/components/locale/lang/ua.js +1 -1
  125. package/components/locale/lang/vi.js +1 -1
  126. package/components/locale/lang/zh-CN.js +1 -1
  127. package/components/locale/lang/zh-TW.js +1 -1
  128. package/components/menu/demo/index.vue +2 -2
  129. package/components/menu/menu.jsx +6 -3
  130. package/components/menu/menudivider.jsx +5 -3
  131. package/components/menu/menugroup.jsx +4 -2
  132. package/components/menu/menuitem.jsx +6 -4
  133. package/components/menu/styles/index.less +88 -20
  134. package/components/menu/submenu.jsx +11 -28
  135. package/components/message/group.jsx +31 -28
  136. package/components/message/index.js +2 -2
  137. package/components/modal/demo/index.vue +2 -3
  138. package/components/modal/demo/info.md +5 -4
  139. package/components/modal/index.js +5 -7
  140. package/components/modal/modal.jsx +116 -121
  141. package/components/notice/index.js +2 -1
  142. package/components/page/page.jsx +15 -12
  143. package/components/page/styles/index.less +4 -4
  144. package/components/popconfirm/popconfirm.jsx +9 -8
  145. package/components/popconfirm/styles/index.less +15 -8
  146. package/components/poptip/poptip.jsx +7 -6
  147. package/components/poptip/styles/index.less +10 -4
  148. package/components/progress/progress.jsx +11 -8
  149. package/components/radio/button.jsx +4 -1
  150. package/components/radio/demo/button.md +1 -2
  151. package/components/radio/group.jsx +10 -19
  152. package/components/radio/radio.jsx +7 -9
  153. package/components/radio/styles/index.less +1 -1
  154. package/components/rate/rate.jsx +7 -10
  155. package/components/select/demo/base.md +5 -2
  156. package/components/select/demo/info.md +3 -1
  157. package/components/select/demo/multiple.md +1 -1
  158. package/components/select/demo/theme.md +0 -5
  159. package/components/select/index.md +4 -0
  160. package/components/select/option.jsx +8 -5
  161. package/components/select/select.jsx +70 -43
  162. package/components/select/styles/index.less +7 -13
  163. package/components/skeleton/demo/items.md +3 -3
  164. package/components/skeleton/skeleton.jsx +6 -2
  165. package/components/skeleton/skeletonAvatar.jsx +6 -2
  166. package/components/skeleton/skeletonButton.jsx +6 -2
  167. package/components/skeleton/skeletonImage.jsx +6 -2
  168. package/components/skeleton/skeletonText.jsx +6 -2
  169. package/components/slider/slider.jsx +15 -11
  170. package/components/slider/thumb.jsx +9 -8
  171. package/components/space/demo/align.md +5 -6
  172. package/components/space/demo/size.md +8 -8
  173. package/components/space/space.jsx +19 -17
  174. package/components/spin/demo/container.md +10 -10
  175. package/components/spin/spin.jsx +5 -2
  176. package/components/styles/color.less +57 -37
  177. package/components/styles/sys.less +31 -0
  178. package/components/styles/var.less +40 -11
  179. package/components/switch/styles/index.less +2 -2
  180. package/components/switch/switch.jsx +11 -8
  181. package/components/table/demo/edit.md +4 -4
  182. package/components/table/demo/expand.md +1 -2
  183. package/components/table/demo/filter.md +1 -1
  184. package/components/table/extend.jsx +172 -157
  185. package/components/table/styles/index.less +2 -1
  186. package/components/table/table.jsx +8 -6
  187. package/components/tabs/demo/base.md +6 -6
  188. package/components/tabs/demo/card.md +6 -6
  189. package/components/tabs/demo/centered.md +6 -6
  190. package/components/tabs/demo/closable.md +3 -3
  191. package/components/tabs/demo/disabled.md +6 -6
  192. package/components/tabs/demo/extra.md +6 -6
  193. package/components/tabs/demo/icon.md +4 -4
  194. package/components/tabs/demo/index.vue +3 -4
  195. package/components/tabs/demo/sample.md +6 -6
  196. package/components/tabs/index.js +2 -2
  197. package/components/tabs/index.md +1 -1
  198. package/components/tabs/styles/index.less +47 -9
  199. package/components/tabs/tabpanel.jsx +28 -0
  200. package/components/tabs/tabs.jsx +198 -151
  201. package/components/tag/demo/color.md +0 -1
  202. package/components/tag/styles/index.less +0 -6
  203. package/components/tag/tag.jsx +6 -3
  204. package/components/timeline/timeline.jsx +3 -1
  205. package/components/timeline/timelineitem.jsx +5 -2
  206. package/components/tooltip/demo/color.md +2 -3
  207. package/components/tooltip/styles/index.less +15 -26
  208. package/components/tooltip/tooltip.jsx +8 -6
  209. package/components/tree/demo/directory.md +3 -3
  210. package/components/tree/node.jsx +39 -50
  211. package/components/tree/styles/index.less +3 -3
  212. package/components/tree/tree.jsx +18 -28
  213. package/components/treeselect/styles/index.less +1 -1
  214. package/components/treeselect/treeselect.jsx +21 -22
  215. package/components/upload/demo/form.md +1 -1
  216. package/components/upload/upload.jsx +13 -27
  217. package/components/{_tool → utils}/animate.js +1 -1
  218. package/components/{_tool → utils}/clone.js +2 -2
  219. package/components/utils/color.js +5 -0
  220. package/components/{_tool/utils.js → utils/element.js} +8 -5
  221. package/components/utils/number.js +81 -0
  222. package/components/utils/theme.js +62 -0
  223. package/components/utils/vue.js +7 -0
  224. package/dist/k-ui.cjs.js +7 -0
  225. package/dist/k-ui.css +6 -7
  226. package/dist/k-ui.d.ts +162 -0
  227. package/dist/k-ui.esm.js +7 -0
  228. package/dist/k-ui.umd.js +7 -0
  229. package/dist/locale/de.js +5 -7
  230. package/dist/locale/el.js +5 -7
  231. package/dist/locale/en.js +5 -7
  232. package/dist/locale/fr.js +5 -7
  233. package/dist/locale/it.js +5 -7
  234. package/dist/locale/ja.js +5 -7
  235. package/dist/locale/ko.js +5 -7
  236. package/dist/locale/ru.js +5 -7
  237. package/dist/locale/th.js +5 -7
  238. package/dist/locale/ua.js +5 -7
  239. package/dist/locale/vi.js +5 -7
  240. package/dist/locale/zh-CN.js +7 -0
  241. package/dist/locale/zh-TW.js +7 -0
  242. package/package.json +54 -22
  243. package/readme.md +105 -0
  244. package/test/i18n@8.x.html +65 -0
  245. package/types/affix/Affix.d.ts +17 -0
  246. package/types/alert/Alert.d.ts +18 -0
  247. package/types/anchor/Anchor.d.ts +16 -0
  248. package/types/anchor/Link.d.ts +15 -0
  249. package/types/avatar/Avatar.d.ts +17 -0
  250. package/types/avatar/AvatarGroup.d.ts +15 -0
  251. package/types/backtop/BackTop.d.ts +16 -0
  252. package/types/badge/Badge.d.ts +20 -0
  253. package/types/base/BasePop.d.ts +24 -0
  254. package/types/base/Collapse.d.ts +15 -0
  255. package/types/base/Drop.d.ts +27 -0
  256. package/types/base/baseInput.d.ts +32 -0
  257. package/types/base/input.d.ts +32 -0
  258. package/types/base/pop.d.ts +36 -0
  259. package/types/breadcrumb/Breadcrumb.d.ts +11 -0
  260. package/types/breadcrumb/BreadcrumbItem.d.ts +17 -0
  261. package/types/button/Button.d.ts +27 -0
  262. package/types/button/ButtonGroup.d.ts +15 -0
  263. package/types/card/Card.d.ts +16 -0
  264. package/types/carousel/Carousel.d.ts +22 -0
  265. package/types/carousel/CarouselItem.d.ts +11 -0
  266. package/types/checkbox/Checkbox.d.ts +19 -0
  267. package/types/checkbox/CheckboxGroup.d.ts +20 -0
  268. package/types/collapse/Collapse.d.ts +15 -0
  269. package/types/collapse/Panel.d.ts +14 -0
  270. package/types/colorPicker/Alpha.d.ts +13 -0
  271. package/types/colorPicker/ColorPicker.d.ts +26 -0
  272. package/types/colorPicker/Hue.d.ts +13 -0
  273. package/types/colorPicker/Mode.d.ts +15 -0
  274. package/types/colorPicker/Paint.d.ts +14 -0
  275. package/types/colorPicker/Presets.d.ts +15 -0
  276. package/types/datePicker/DateCalendar.d.ts +27 -0
  277. package/types/datePicker/DatePicker.d.ts +36 -0
  278. package/types/descriptions/Descriptions.d.ts +21 -0
  279. package/types/descriptions/DescriptionsItem.d.ts +18 -0
  280. package/types/divider/Divider.d.ts +18 -0
  281. package/types/drawer/Drawer.d.ts +35 -0
  282. package/types/dropdown/Dropdown.d.ts +21 -0
  283. package/types/empty/Empty.d.ts +15 -0
  284. package/types/flex/Flex.d.ts +17 -0
  285. package/types/form/Form.d.ts +25 -0
  286. package/types/form/FormItem.d.ts +17 -0
  287. package/types/grid/Col.d.ts +15 -0
  288. package/types/grid/Row.d.ts +17 -0
  289. package/types/icon/Icon.d.ts +17 -0
  290. package/types/image/ImageGroup.d.ts +11 -0
  291. package/types/image/ImagePreview.d.ts +24 -0
  292. package/types/image/KImage.d.ts +21 -0
  293. package/types/image/imageProps.d.ts +19 -0
  294. package/types/image/instance.d.ts +19 -0
  295. package/types/index.d.ts +188 -0
  296. package/types/input/Input.d.ts +31 -0
  297. package/types/input/InputGroup.d.ts +17 -0
  298. package/types/input/TextArea.d.ts +16 -0
  299. package/types/inputNumber/InputNumber.d.ts +33 -0
  300. package/types/layout/layout.d.ts +13 -0
  301. package/types/layout/prop.d.ts +13 -0
  302. package/types/loading/Loading.d.ts +11 -0
  303. package/types/menu/Menu.d.ts +21 -0
  304. package/types/menu/MenuDivider.d.ts +11 -0
  305. package/types/menu/MenuGroup.d.ts +13 -0
  306. package/types/menu/MenuItem.d.ts +15 -0
  307. package/types/menu/SubMenu.d.ts +15 -0
  308. package/types/menu/show.d.ts +15 -0
  309. package/types/message/group.d.ts +13 -0
  310. package/types/message/inner.d.ts +24 -0
  311. package/types/modal/Modal.d.ts +31 -0
  312. package/types/page/Page.d.ts +26 -0
  313. package/types/popconfirm/Popconfirm.d.ts +21 -0
  314. package/types/poptip/Poptip.d.ts +22 -0
  315. package/types/progress/Progress.d.ts +33 -0
  316. package/types/radio/Radio.d.ts +19 -0
  317. package/types/radio/RadioButton.d.ts +18 -0
  318. package/types/radio/RadioGroup.d.ts +23 -0
  319. package/types/rate/Rate.d.ts +26 -0
  320. package/types/rate/Star.d.ts +22 -0
  321. package/types/select/Option.d.ts +15 -0
  322. package/types/select/Select.d.ts +38 -0
  323. package/types/skeleton/Skeleton.d.ts +21 -0
  324. package/types/skeleton/SkeletonAvatar.d.ts +19 -0
  325. package/types/skeleton/SkeletonButton.d.ts +20 -0
  326. package/types/skeleton/SkeletonImage.d.ts +18 -0
  327. package/types/skeleton/SkeletonText.d.ts +18 -0
  328. package/types/slider/Slider.d.ts +29 -0
  329. package/types/slider/thumb.d.ts +24 -0
  330. package/types/space/Space.d.ts +18 -0
  331. package/types/spin/Spin.d.ts +20 -0
  332. package/types/switch/KSwitch.d.ts +20 -0
  333. package/types/switch/Switch.d.ts +20 -0
  334. package/types/table/ExtendTable.d.ts +21 -0
  335. package/types/table/Table.d.ts +24 -0
  336. package/types/table/extend.d.ts +21 -0
  337. package/types/tabs/TabPanel.d.ts +17 -0
  338. package/types/tabs/Tabs.d.ts +18 -0
  339. package/types/tag/Tag.d.ts +18 -0
  340. package/types/timeline/TimeLine.d.ts +14 -0
  341. package/types/timeline/TimeLineItem.d.ts +16 -0
  342. package/types/tooltip/Tooltip.d.ts +23 -0
  343. package/types/tree/Tree.d.ts +28 -0
  344. package/types/tree/TreeNode.d.ts +17 -0
  345. package/types/treeselect/TreeSelect.d.ts +41 -0
  346. package/types/upload/Upload.d.ts +39 -0
  347. package/README.md +0 -106
  348. package/components/_tool/directives.js +0 -31
  349. package/components/_tool/number.js +0 -177
  350. package/components/bin/index.js +0 -3
  351. package/components/button/demo/normal.md +0 -41
  352. package/components/button/demo/solid.md +0 -16
  353. package/components/colorPicker/canvasHelper.js +0 -274
  354. package/components/colorPicker/demo/shape.md +0 -36
  355. package/components/tabs/tabpane.jsx +0 -25
  356. package/dist/k-ui.js +0 -9
  357. package/dist/locale/zhCN.js +0 -9
  358. package/dist/locale/zhTW.js +0 -9
  359. package/test/i18n@6.x.html +0 -52
  360. /package/components/{_tool → directives}/outsiteclick.js +0 -0
  361. /package/components/{_tool → directives}/resize.js +0 -0
  362. /package/components/{_tool → directives}/scroll.js +0 -0
  363. /package/components/{_tool → directives}/transfer.js +0 -0
  364. /package/components/menu/demo/{accrodion.md → accordion.md} +0 -0
  365. /package/components/modal/demo/{confrim.md → confirm.md} +0 -0
  366. /package/components/{_tool → utils}/docClick.js +0 -0
@@ -1,20 +1,30 @@
1
- import { canvasHelper, limit, hslToRgb, rgbToHsl, parseColor, rgbToHex, cssColorToRgba } from './canvasHelper'
2
- import { Input } from '../input'
3
- // import InputNumber from '../inputNumber'
4
- import { Button } from '../button'
5
- import Icon from '../icon'
6
1
  import Drop from '../base/drop'
7
- import { ChevronDown, CaretHor } from 'kui-icons'
8
- const modes = ['rgba', 'hex', 'hsla']
2
+ import { withInstall } from '../utils/vue'
3
+ import Mode from "./mode";
4
+ import Hue from "./hue";
5
+ import Alpha from "./alpha";
6
+ import Paint from "./paint";
7
+ import Color from "color";
8
+ import Presets from "./presets";
9
+ import { getChildren } from '../utils/element';
10
+ import cloneVNode from '../utils/clone';
11
+ const modes = ["rgb", "hex", "hsl"];
9
12
 
10
- export default {
13
+ const ColorPicker = {
11
14
  name: 'ColorPicker',
12
15
  props: {
13
16
  value: String,
14
- transfer: { type: Boolean, default: true },
15
17
  showMode: Boolean,
16
18
  disabled: Boolean,
17
- noAlpha: Boolean,
19
+ disabledAlpha: Boolean,
20
+ showText: Boolean,
21
+ trigger: {
22
+ type: String,
23
+ default: "click",
24
+ validator(value) {
25
+ return ["hover", "click"].indexOf(value) >= 0;
26
+ },
27
+ },
18
28
  size: {
19
29
  default: 'default',
20
30
  validator(value) {
@@ -22,46 +32,41 @@ export default {
22
32
  }
23
33
  },
24
34
  mode: {
25
- type: String, default: 'hex', validator: function (value) {
26
- return modes.indexOf(value) !== -1
35
+ type: String, default: 'hex',
36
+ validator: function (value) {
37
+ return modes.includes(value)
27
38
  }
28
39
  },
29
- shape: String,
30
- icon: [String, Array],
31
- showArrow: { type: Boolean, default: true },
32
- defalutColors: {
33
- type: Array, default: () => ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b', '#000'],
34
- validator: function (value) { return value.length <= 20 }
40
+ presets: {
41
+ type: Array,
42
+ },
43
+ placement: {
44
+ validator(value) {
45
+ return [
46
+ "top",
47
+ "top-left",
48
+ "top-right",
49
+ "bottom",
50
+ "bottom-left",
51
+ "bottom-right",
52
+ ].includes(value);
53
+ },
54
+ default: "bottom-left",
35
55
  }
36
56
  },
37
57
  watch: {
38
58
  value(v1) {
39
- // console.log(v1, v2, this.currentColor)
40
- if (v1 != this.currentColor) {
41
- this.valueChange('COLOR', v1)
42
- }
59
+ this.currentColor = v1
43
60
  }
44
61
  },
45
62
  data() {
46
63
  return {
47
64
  currentMode: this.mode,
48
65
  currentColor: this.value || '#000',
49
- paintHelper: null,
50
- hueHelper: null,
51
- H: 0, S: 0, L: 0, A: 1,
52
- R: 0, G: 0, B: 0,
53
- HEX: '',
54
- huePointer: {
55
- x: 0
56
- },
57
- alphaPointer: {
58
- x: 0,
59
- },
60
- paintPointer: {
61
- x: 0, y: 0
62
- },
63
66
  opened: false,
64
- isMouseDown: false
67
+ currentAlpha: 1,
68
+ currentHue: 0,
69
+ currentPlacement: this.placement,
65
70
  }
66
71
  },
67
72
  methods: {
@@ -71,393 +76,181 @@ export default {
71
76
  return false;
72
77
  }
73
78
  this.opened = !this.opened
74
- this.currentColor = this.value || '#000'
75
- },
76
- updatePostion() {
77
- //alpha
78
- {
79
- const x = 190 * this.A;
80
- this.alphaPointer.x = (x - 7);
81
- }
82
- //updaet hue pointer
83
- {
84
- const x = 190 * this.H / 360;
85
- this.huePointer.x = (x - 7);
86
- }
87
- //paint
88
- {
89
- const [r, g, b] = hslToRgb(this.H, this.S, this.L);
90
- const [x, y] = this.paintHelper.findColor(r, g, b);
91
- if (x >= 0) {
92
- this.paintPointer.x = (x - 7 + 10);
93
- this.paintPointer.y = (y - 7 + 10);
94
- }
95
- }
96
-
97
- },
98
- valueChange(prop, value) {
99
- switch (prop) {
100
- case 'COLOR':
101
- [this.R, this.G, this.B, this.A] = parseColor(value, 'rgba') || [0, 0, 0, 1];
102
- [this.H, this.S, this.L] = rgbToHsl(this.R, this.G, this.B);
103
- if (this.paintHelper) {
104
- this.paintHelper.setHue(this.H);
105
- this.updatePostion()
106
- this.alphaCanvsSetHue(this.$refs.alpha)
107
- }
108
- break;
109
- case 'HUE':
110
- this.H = value;
111
- // console.log(this.H);
112
- [this.R, this.G, this.B] = hslToRgb(this.H, this.S, this.L);
113
- if (this.paintHelper) {
114
- this.paintHelper.setHue(value);
115
- this.alphaCanvsSetHue(this.$refs.alpha);
116
- }
117
- break;
118
- case 'RGB':
119
- [this.R, this.G, this.B] = value;
120
- [this.H, this.S, this.L] = rgbToHsl(this.R, this.G, this.B);
121
- // let colors = rgbToHsl(this.R, this.G, this.B);
122
- // [this.H, this.S, this.L] = colors
123
- if (this.paintHelper) {
124
- this.alphaCanvsSetHue(this.$refs.alpha)
125
- }
126
- break;
127
- case 'ALPHA':
128
- this.A = value;
129
- break;
130
- }
131
- this.setHEX()
132
- },
133
- setHEX() {
134
- if (this.A != 1) {
135
- this.HEX = parseColor([this.R, this.G, this.B, this.A], 'hexcss4');
136
- } else {
137
- this.HEX = rgbToHex(this.R, this.G, this.B);
138
- }
139
-
140
- // this.currentColor = this.HEX
141
- // this.$emit('input', this.currentColor)
142
- // this.$emit('change', this.currentColor)
143
-
144
- this.updateValue()
145
- },
146
- updateValue() {
147
- let { currentMode, R, G, B, A, H, S, L, } = this, value = null;
148
- if (currentMode == 'hex') {
149
- value = this.HEX
150
- } else if (currentMode == 'rgba') {
151
- value = A < 1 ? `rgba(${R},${G},${B},${A})` : `rgba(${R},${G},${B})`
152
- } else {
153
- value = A < 1 ? `hsla(${H},${S}%,${L}%,${A})` : `hsl(${H},${S}%,${L}%)`
154
- }
155
- // console.log(value)
156
- this.currentColor = value
157
- this.$emit('input', value)
158
- this.$emit('change', value)
159
- // this.opened = false
160
79
  },
161
- setMode() {
162
- let i = modes.indexOf(this.currentMode) + 1
163
- i = i > 2 ? 0 : i
164
- this.currentMode = modes[i]
165
- this.updateValue()
166
- },
167
- initHueCanvas(canvas) {
168
- const ctx = canvas.getContext('2d', { willReadFrequently: true }),
169
- setp = 1 / 360,
170
- width = canvas.width,
171
- height = canvas.height,
172
- gradient = ctx.createLinearGradient(0, 0, width, 0);
173
-
174
- for (let i = 0; i <= 1; i += setp) {
175
- gradient.addColorStop(i, `hsl(${360 * i},100%,50%)`)
80
+ getColor() {
81
+ let text = "";
82
+ const color = Color(this.currentColor);
83
+ if (this.currentMode == "hex") {
84
+ text = color.alpha() < 1 ? color.hexa() : color.hex();
85
+ } else if (this.currentMode == "rgb") {
86
+ text = color.rgb().string(0);
87
+ } else if (this.currentMode == "hsl") {
88
+ text = color.hsl().string(0);
176
89
  }
177
- ctx.fillStyle = gradient
178
- ctx.fillRect(0, 0, width, height)
179
-
180
- const onMouseMove = e => {
181
- const x = limit(e.clientX - canvas.getBoundingClientRect().left, 0, width),
182
- hue = Math.round(x * 360 / width)
183
- this.huePointer.x = x - 7
184
- this.valueChange('HUE', hue)
185
- }
186
-
187
- const onMouseUp = () => {
188
- setTimeout(() => {
189
- this.isMouseDown = false
190
- }, 300);
191
- document.removeEventListener('mousemove', onMouseMove);
192
- document.removeEventListener('mouseup', onMouseUp)
193
- }
194
-
195
- canvas.addEventListener('mousedown', e => {
196
- this.isMouseDown = true
197
- onMouseMove(e)
198
- document.addEventListener('mousemove', onMouseMove)
199
- document.addEventListener('mouseup', onMouseUp)
200
- e.preventDefault()
201
- })
90
+ return text;
202
91
  },
203
- alphaCanvsSetHue(canvas) {
204
- if (this.noAlpha || !canvas) return;
205
- const ctx = canvas.getContext('2d', { willReadFrequently: true }),
206
- { width, height } = canvas,
207
- gradient = ctx.createLinearGradient(0, 0, width - 1, 0);
208
- let { H, S, L } = this
209
- ctx.clearRect(0, 0, width, height)
210
- gradient.addColorStop(0, `hsla(${H},${S}%,${L}%,0)`)
211
- gradient.addColorStop(1, `hsla(${H},${S}%,${L}%,1)`)
212
- ctx.fillStyle = gradient
213
- ctx.fillRect(0, 0, width, height)
92
+ renderTriggerText() {
93
+ let text = this.getColor();
94
+ return this.showText ? (
95
+ <div class="k-color-picker-trigger-text">{text}</div>
96
+ ) : null;
214
97
  },
215
- initAlphaCanvas(canvas) {
216
- this.alphaCanvsSetHue(canvas)
217
- const { width, height } = canvas;
218
- const onMouseMove = (e) => {
219
- const x = limit(e.clientX - canvas.getBoundingClientRect().left, 0, width),
220
- alpha = +(x / width).toFixed(2);
221
- this.alphaPointer.x = (x - 7)
222
- this.valueChange('ALPHA', alpha)
223
- }
224
-
225
- const onMouseUp = () => {
226
- setTimeout(() => {
227
- this.isMouseDown = false
228
- }, 300);
229
-
230
- document.removeEventListener('mousemove', onMouseMove);
231
- document.removeEventListener('mouseup', onMouseUp)
232
- }
233
-
234
- canvas.addEventListener('mousedown', e => {
235
- this.isMouseDown = true
236
-
237
- onMouseMove(e);
238
- document.addEventListener('mousemove', onMouseMove);
239
- document.addEventListener('mouseup', onMouseUp)
240
- e.preventDefault()
241
-
242
- })
243
-
98
+ updateColor(color) {
99
+ this.currentAlpha = color.alpha();
100
+ this.currentHue = color.hue();
101
+ this.updateColorValue(color.rgb());
244
102
  },
245
- initPaintCanvas(canvas) {
246
- const { width, height } = canvas;
247
- const onMouseMove = e => {
248
- const x = limit(e.clientX - canvas.getBoundingClientRect().left, 0, width - 1),
249
- y = limit(e.clientY - canvas.getBoundingClientRect().top, 0, height - 1),
250
- color = this.paintHelper.grabColor(x, y)
251
-
252
- this.paintPointer.x = x - 7 + 10
253
- this.paintPointer.y = y - 7 + 10
254
- this.valueChange('RGB', color)
255
-
256
- }
257
- const onMouseUp = () => {
258
- setTimeout(() => {
259
- this.isMouseDown = false
260
- }, 300);
261
-
262
- document.removeEventListener('mousemove', onMouseMove);
263
- document.removeEventListener('mouseup', onMouseUp)
264
- }
265
-
266
- canvas.addEventListener('mousedown', e => {
267
- this.isMouseDown = true
268
-
269
- onMouseMove(e)
270
- document.addEventListener('mousemove', onMouseMove)
271
- document.addEventListener('mouseup', onMouseUp)
272
- e.preventDefault()
273
- })
103
+ updateColorValue(color) {
104
+ this.currentAlpha = color.alpha();
105
+ this.currentColor = color;
106
+ this.currentHue = color.hue();
107
+ this.onUpdate(color);
274
108
  },
275
- renderPaint() {
276
- let prop = {
277
- class: 'k-color-picker-paint',
278
- attrs: { width: 234, height: 136 },
279
- ref: 'paint'
280
- }
281
- return <canvas {...prop} />
109
+ onUpdate(color) {
110
+ this.currentColor = color;
111
+ const value = this.getColor();
112
+ this.$emit("input", value);
113
+ this.$emit("change", value);
282
114
  },
283
- renderAlpha() {
284
- let prop = {
285
- class: 'k-color-picker-alpha',
286
- attrs: { width: 190, height: 8 },
287
- ref: 'alpha'
288
- }
289
- return !this.noAlpha ? <canvas {...prop} /> : null
115
+ onUpdateRGB({ r, g, b }) {
116
+ const color = Color({ r, g, b, alpha: this.currentAlpha });
117
+ this.onUpdate(color.rgb());
290
118
  },
291
- renderHue() {
292
- let prop = {
293
- class: 'k-color-picker-hue',
294
- attrs: { width: 190, height: 8 },
295
- ref: 'hue'
296
- }
297
- return <canvas {...prop} />
119
+ onUpdateHue(hue) {
120
+ // console.log("hue", hue);
121
+ this.currentHue = hue;
122
+ // currentColor.value = color;
123
+ // const value = getColor();
124
+ const value = Color(this.currentColor).hue(hue).rgb();
125
+ this.onUpdate(value);
298
126
  },
299
- renderValueInput(key) {
300
- let prop = {
301
- attrs: {
302
- maxlength: key == 'HEX' ? 9 : 4
303
- },
304
- props: {
305
- value: this[key] + ('SL'.indexOf(key) >= 0 ? '%' : ''),
306
- size: "small",
307
- },
308
- on: {
309
- "input": e => {
310
- let value = e.replace('%', '')
311
- if (!value) return;
312
- if (key == 'HEX') {
313
- value = value.toString().toLowerCase()
314
- if (/^#([0-9A-F]{6}|[0-9A-F]{3}|[0-9A-F]{8})$/i.test(value)) {
315
- [this.R, this.G, this.B, this.A] = cssColorToRgba(value) || [this.R, this.G, this.B, this.A];
316
- [this.H, this.S, this.L] = rgbToHsl(this.R, this.G, this.B);
317
- } else {
318
- return;
319
- }
320
- } else if (key == 'A') {
321
- if (!/^\d(.)\d*$/.test(value) || value > 1) return;
322
- } else {
323
- if (!/^\d*$/.test(value)) return;
324
- }
325
-
326
- this[key] = value
327
- // console.log(e,key)
328
- if ('RGB'.indexOf(key) >= 0) {
329
- [this.H, this.S, this.L] = rgbToHsl(this.R, this.G, this.B);
330
- }
331
- this.updatePostion()
332
- this.paintHelper.setHue(this.H)
333
- this.alphaCanvsSetHue(this.$refs.alpha)
334
- }
335
- }
336
- }
337
- return <Input {...prop} />
127
+ onUpdateAlpha(a) {
128
+ this.currentAlpha = a;
129
+ const value = Color(this.currentColor).alpha(a).rgb();
130
+ this.onUpdate(value);
338
131
  },
339
- renderValue() {
340
- if (this.showMode) {
341
- let { currentMode, renderValueInput } = this, node = []
342
- let mode = "RGB"
343
- let alpha = <Input v-model={this.A} size="small" class="k-color-picker-alpha-input" />
344
- if (currentMode == 'rgba') {
345
- let keys = ['R', 'G', 'B']
346
- let v = <div class="k-color-picker-val">{keys.map(k => renderValueInput(k))}{alpha}</div>
347
- // let k = <div class="k-color-picker-key">{keys.map(k => <span>{k}</span>)}</div>
348
- node.push(v)
349
- } else if (currentMode == 'hsla') {
350
- mode = 'HSB'
351
- let keys = ['H', 'S', 'L']
352
- let v = <div class="k-color-picker-val">{keys.map(k => renderValueInput(k))}{alpha}</div>
353
- // let k = <div class="k-color-picker-key">{keys.map(k => <span>{k}</span>)}</div>
354
- node.push(v)
355
- } else { //hex
356
- mode = 'HEX'
357
- let v = <div class="k-color-picker-val">{renderValueInput('HEX')}{alpha}</div>
358
- // let k = <div class="k-color-picker-key"><span>HEX</span></div>
359
- node.push(v)
360
- }
361
- node.unshift(<span class="k-color-picker-mode-label">{mode}:</span>)
362
- let btn = <Button size="small" theme="normal" icon={CaretHor} onClick={this.setMode} />
363
- node.push(btn)
364
- return <div class={`k-color-picker-mode k-color-picker-${currentMode}`}>{node}</div>
365
- }
132
+ onUpdateMode(mode) {
133
+ this.currentMode = mode;
134
+ this.onUpdate(this.currentColor);
135
+ this.$emit("update:mode", mode);
136
+ setTimeout(() => {
137
+ clearTimeout(this.hideTimer);
138
+ }, 0);
366
139
  },
367
- renderDefaultColor() {
368
- let color = this.defalutColors.map(c => <span style={"background-color:" + c} onClick={e => this.valueChange('COLOR', c)}></span>)
369
- // let okBtn = <Button circle onClick={this.updateValue}>OK</Button>
370
- return <div class="k-coclor-picker-defaults">{[color]}</div>
140
+ delayHide() {
141
+ this.hideTimer = setTimeout(() => {
142
+ this.opened = false;
143
+ }, 300);
371
144
  },
372
145
  renderDrop() {
373
- let paint = this.renderPaint()
374
- let alpha = this.renderAlpha()
375
- let hue = this.renderHue()
376
- // let colors = this.renderDefaultColor()
377
- let valueNode = this.renderValue()
378
-
379
146
  const props = {
380
- ref: 'overlay',
381
147
  props: {
382
- placement: 'bottom-left',
148
+ placement: this.placement,
383
149
  transfer: true,
384
150
  value: this.opened,
385
151
  selection: this.$el,
386
152
  className: 'k-color-picker-dropdown',
387
- transitionName: 'k-color-picker'
153
+ transitionName: 'k-color-picker',
154
+ extendWidth: false,
155
+ trigger: this.trigger
388
156
  },
389
157
  on: {
390
- input: e => {
391
- this.opened = e
392
- this.currentColor = this.value || '#000'
393
- },
394
- hide: () => {
395
- this.opened = false
396
- // this.currentColor = this.value || '#000'
397
- },
398
- render: () => {
399
- this.$nextTick(() => {
400
- let { paint, hue, alpha } = this.$refs
401
- this.paintHelper = canvasHelper(paint);
402
- this.initHueCanvas(hue);
403
- (!this.noAlpha && this.initAlphaCanvas(alpha));
404
- this.initPaintCanvas(paint)
405
- this.valueChange('COLOR', this.value)
406
- })
407
- },
158
+ hide: this.delayHide,
408
159
  }
409
160
  }
410
- let [r, g, b] = hslToRgb(this.H, this.S, this.L);
411
161
  return (<Drop {...props}>
412
- {paint}
413
- < span class="k-color-picker-paint-dot" style={'left:' + this.paintPointer.x + 'px;top:' + this.paintPointer.y + 'px'} ></span >
414
- <div class="k-color-picker-bar">
415
- <div class="k-color-picker-avatar">
416
- <div class="k-color-picker-avatar-inner" style={`background-color:rgba(${this.R}, ${this.G}, ${this.B}, ${this.A})`}></div>
162
+ <div class='k-color-picker-body' onMouseenter={()=>clearTimeout(this.hideTimer)}>
163
+ <Paint
164
+ hue={this.currentHue}
165
+ value={this.currentColor}
166
+ onUpdateRGB={this.onUpdateRGB}
167
+ />
168
+ <div class="k-color-picker-bar">
169
+ <div class="k-color-picker-avatar">
170
+ <div
171
+ class="k-color-picker-avatar-inner"
172
+ style={`background-color:${this.currentColor}`}></div>
173
+ </div>
174
+ <div class="k-color-picker-bar-box">
175
+ <Hue hue={this.currentHue} onUpdateHue={this.onUpdateHue} />
176
+ {!this.disabledAlpha ? (
177
+ <Alpha
178
+ value={this.currentColor}
179
+ onUpdateAlpha={this.onUpdateAlpha}
180
+ />
181
+ ) : null}
182
+ </div>
417
183
  </div>
418
- <div class="k-color-picker-bar-box">
419
- {[hue, alpha]}
420
- <span class="k-color-picker-hue-dot" style={{ 'left': this.huePointer.x + 'px', backgroundColor: `rgba(${r},${g},${b},1` }}></span>
421
- {!this.noAlpha ? <span class="k-color-picker-alpha-dot" style={{ 'left': this.alphaPointer.x + 'px', backgroundColor: `rgba(${r},${g},${b},${this.A}` }} ></span> : null}
184
+
185
+ <Mode
186
+ mode={this.currentMode}
187
+ value={this.currentColor}
188
+ disabledAlpha={this.disabledAlpha}
189
+ onUpdateMode={this.onUpdateMode}
190
+ onUpdateColorValue={this.updateColorValue}
191
+ />
192
+ <Presets
193
+ onUpdateColor={this.updateColor}
194
+ value={this.presets}
195
+ color={this.currentColor}
196
+ />
197
+ <div class={`k-color-picker-arrow`}>
198
+ <svg style={{ fill: "currentcolor" }} viewBox="0 0 24 8">
199
+ <path
200
+ id="ot"
201
+ d="m24,0.97087l0,1c-4,0 -5.5,1 -7.5,3c-2,2 -2.5,3 -4.5,3c-2,0 -2.5,-1 -4.5,-3c-2,-2 -3.5,-3 -7.5,-3l0,-1l24,0z"
202
+ />
203
+ <path
204
+ stroke="currentcolor"
205
+ id="in"
206
+ d="m24,0l0,1c-4,0 -5.5,1 -7.5,3c-2,2 -2.5,3 -4.5,3c-2,0 -2.5,-1 -4.5,-3c-2,-2 -3.5,-3 -7.5,-3l0,-1l24,0z"
207
+ />
208
+ </svg>
422
209
  </div>
423
210
  </div>
424
- {valueNode}
425
- {this.renderDefaultColor()}
426
- </Drop >
211
+ </Drop>
427
212
  )
428
213
  }
429
214
  },
430
-
215
+ mounted() {
216
+ if (this.value) {
217
+ this.currentAlpha = Color(this.value).alpha();
218
+ this.currentHue = Color(this.value).hue();
219
+ }
220
+ },
431
221
  render() {
432
222
  let drop = this.renderDrop()
433
- let { showArrow, icon, currentMode } = this
434
223
  let style = [
435
224
  'k-color-picker',
436
225
  {
437
226
  'k-color-picker-opened': this.opened,
438
227
  'k-color-picker-disabled': this.disabled,
439
228
  'k-color-picker-sm': this.size == 'small',
440
- 'k-color-picker-circle': this.shape == 'circle' && !showArrow,
441
229
  'k-color-picker-lg': this.size == 'large'
442
230
  },
443
231
  ]
444
- // let triggerText = ""
445
- // if (currentMode == 'hex') {
446
- // triggerText = this.currentColor
447
- // } else {
448
- // triggerText = this.currentColor.substr(0, 7)
449
- // }
450
-
451
-
452
- return (<div class={style} >
453
- <div class="k-color-picker-selection" onClick={this.toggleDrop}>
454
- <div class="k-color-picker-color">
455
- <div class="k-color-picker-color-inner" style={`background-color:${this.currentColor}`}></div>
232
+ const defaultNode = getChildren(this.$slots.default)
233
+ if (defaultNode.length > 0) {
234
+ const props = { on: {} }
235
+ if (this.trigger == 'click') {
236
+ props.on.click = this.toggleDrop
237
+ } else if (this.trigger == 'hover') {
238
+ props.on.mouseenter = this.toggleDrop
239
+ props.on.mouseleave = this.delayHide
240
+ }
241
+ return cloneVNode(defaultNode[0], props, drop)
242
+ } else {
243
+ return (<div class={style} onClick={this.toggleDrop}>
244
+ <div class="k-color-picker-selection">
245
+ <div class="k-color-picker-color">
246
+ <div class="k-color-picker-color-inner" style={`background-color:${this.currentColor}`}></div>
247
+ </div>
248
+ {this.renderTriggerText()}
456
249
  </div>
457
- {/* <div class="k-color-picker-trigger-text">{triggerText}</div> */}
458
- {showArrow && <Icon class="k-color-picker-arrow" type={icon || ChevronDown} />}
459
- </div>
460
- {drop}
461
- </div >)
250
+ {drop}
251
+ </div>)
252
+ }
462
253
  }
463
- }
254
+ }
255
+
256
+ export default withInstall(ColorPicker)
@@ -7,15 +7,13 @@
7
7
  <template>
8
8
  <div class="demo-color-picker">
9
9
  <ColorPicker v-model="color"/>
10
- <br/>
11
- <ColorPicker v-model="color" disabled/>
12
10
  </div>
13
11
  </template>
14
12
  <script>
15
13
  export default {
16
14
  data() {
17
15
  return {
18
- color: 'rgba(182,2,247,1)',
16
+ color: '#3a95ff',
19
17
  };
20
18
  }
21
19
  }