@king-design/react 3.0.0-beta.0 → 3.0.0-beta.2

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 (223) hide show
  1. package/__tests__/__snapshots__/Dialog.md +1 -1
  2. package/__tests__/__snapshots__/React Demos.md +468 -309
  3. package/__tests__/components/cascader.spec.tsx +53 -0
  4. package/__tests__/components/drawer.spec.tsx +67 -5
  5. package/components/button/index.d.ts +1 -1
  6. package/components/button/index.js +1 -1
  7. package/components/button/styles.d.ts +1 -1
  8. package/components/button/styles.js +3 -5
  9. package/components/carousel/index.vdt.js +2 -2
  10. package/components/cascader/index.d.ts +22 -11
  11. package/components/cascader/index.js +9 -12
  12. package/components/cascader/index.spec.js +81 -0
  13. package/components/cascader/index.vdt.js +11 -9
  14. package/components/cascader/styles.js +1 -1
  15. package/components/cascader/useFields.d.ts +2 -0
  16. package/components/cascader/useFields.js +18 -0
  17. package/components/cascader/useFilterable.d.ts +2 -1
  18. package/components/cascader/useFilterable.js +17 -6
  19. package/components/cascader/useLabel.d.ts +2 -1
  20. package/components/cascader/useLabel.js +4 -4
  21. package/components/cascader/useLoad.d.ts +2 -1
  22. package/components/cascader/useLoad.js +9 -7
  23. package/components/collapse/item.vdt.js +1 -1
  24. package/components/colorpicker/index.d.ts +2 -0
  25. package/components/colorpicker/index.js +7 -2
  26. package/components/colorpicker/index.vdt.js +3 -6
  27. package/components/copy/index.d.ts +17 -0
  28. package/components/copy/index.js +43 -0
  29. package/components/copy/index.spec.d.ts +1 -0
  30. package/components/copy/index.spec.js +52 -0
  31. package/components/copy/index.vdt.js +45 -0
  32. package/components/copy/styles.d.ts +2 -0
  33. package/components/copy/styles.js +14 -0
  34. package/components/copy/useCopy.d.ts +4 -0
  35. package/components/copy/useCopy.js +90 -0
  36. package/components/datepicker/calendar.vdt.js +6 -6
  37. package/components/datepicker/index.spec.js +171 -153
  38. package/components/datepicker/index.vdt.js +1 -1
  39. package/components/datepicker/styles.js +1 -1
  40. package/components/datepicker/useValue.d.ts +3 -3
  41. package/components/datepicker/useValue.js +38 -9
  42. package/components/diagram/shapes/callout.d.ts +1 -1
  43. package/components/diagram/shapes/circle.d.ts +1 -1
  44. package/components/diagram/shapes/document.d.ts +1 -1
  45. package/components/diagram/shapes/ellipse.d.ts +1 -1
  46. package/components/diagram/shapes/hexagon.d.ts +1 -1
  47. package/components/diagram/shapes/image.d.ts +1 -1
  48. package/components/diagram/shapes/parallelogram.d.ts +1 -1
  49. package/components/diagram/shapes/rectangle.d.ts +1 -1
  50. package/components/diagram/shapes/square.d.ts +1 -1
  51. package/components/diagram/shapes/text.d.ts +1 -1
  52. package/components/dialog/alert.vdt.js +6 -5
  53. package/components/dialog/index.spec.js +6 -6
  54. package/components/dialog/styles.js +1 -1
  55. package/components/dropdown/dropdown.d.ts +6 -6
  56. package/components/dropdown/dropdown.js +58 -75
  57. package/components/dropdown/index.spec.js +96 -17
  58. package/components/dropdown/item.d.ts +1 -1
  59. package/components/dropdown/item.js +19 -7
  60. package/components/dropdown/menu.js +1 -1
  61. package/components/dropdown/usePosition.js +11 -2
  62. package/components/editable/index.d.ts +1 -0
  63. package/components/editable/index.js +20 -6
  64. package/components/editable/index.vdt.js +2 -1
  65. package/components/form/index.spec.js +4 -2
  66. package/components/form/item.vdt.js +2 -1
  67. package/components/form/styles.js +4 -4
  68. package/components/grid/useGutter.js +8 -8
  69. package/components/icon/styles.js +1 -1
  70. package/components/input/index.d.ts +13 -2
  71. package/components/input/index.js +16 -13
  72. package/components/input/index.spec.js +169 -1
  73. package/components/input/index.vdt.js +44 -12
  74. package/components/input/search.vdt.js +2 -4
  75. package/components/input/styles.js +30 -6
  76. package/components/input/useAutoRows.d.ts +2 -0
  77. package/components/input/useAutoRows.js +79 -0
  78. package/components/input/useAutoWidth.js +13 -3
  79. package/components/input/useFocus.d.ts +4 -0
  80. package/components/input/useFocus.js +21 -0
  81. package/components/input/useShowPassword.d.ts +7 -0
  82. package/components/input/useShowPassword.js +31 -0
  83. package/components/menu/index.spec.js +26 -15
  84. package/components/menu/item.d.ts +2 -0
  85. package/components/menu/item.js +5 -0
  86. package/components/menu/item.vdt.js +4 -1
  87. package/components/pagination/index.d.ts +1 -1
  88. package/components/pagination/index.js +3 -2
  89. package/components/pagination/index.spec.js +49 -0
  90. package/components/pagination/index.vdt.js +10 -12
  91. package/components/pagination/styles.js +1 -1
  92. package/components/popover/content.d.ts +19 -0
  93. package/components/popover/content.js +31 -0
  94. package/components/popover/content.vdt.js +68 -0
  95. package/components/popover/index.d.ts +16 -0
  96. package/components/popover/index.js +44 -0
  97. package/components/popover/index.spec.d.ts +1 -0
  98. package/components/popover/index.spec.js +195 -0
  99. package/components/popover/styles.d.ts +1 -0
  100. package/components/popover/styles.js +22 -0
  101. package/components/portal.d.ts +6 -2
  102. package/components/portal.js +4 -3
  103. package/components/position.js +2 -1
  104. package/components/progress/index.js +1 -1
  105. package/components/progress/index.vdt.js +46 -8
  106. package/components/progress/styles.js +19 -13
  107. package/components/rate/styles.js +1 -1
  108. package/components/select/base.d.ts +7 -3
  109. package/components/select/base.js +9 -3
  110. package/components/select/base.vdt.js +75 -47
  111. package/components/select/index.spec.js +25 -13
  112. package/components/select/menu.vdt.js +6 -6
  113. package/components/select/option.vdt.js +2 -1
  114. package/components/select/styles.js +11 -5
  115. package/components/select/useDraggble.d.ts +2 -0
  116. package/components/select/useDraggble.js +11 -0
  117. package/components/slider/index.spec.js +48 -9
  118. package/components/slider/index.vdt.js +23 -12
  119. package/components/slider/styles.js +23 -14
  120. package/components/slider/useValue.d.ts +3 -1
  121. package/components/slider/useValue.js +12 -0
  122. package/components/spinner/index.d.ts +0 -1
  123. package/components/spinner/index.js +1 -19
  124. package/components/spinner/index.vdt.js +13 -8
  125. package/components/spinner/styles.js +2 -2
  126. package/components/spinner/useChange.d.ts +1 -1
  127. package/components/spinner/useChange.js +2 -2
  128. package/components/spinner/useValue.d.ts +1 -0
  129. package/components/spinner/useValue.js +16 -1
  130. package/components/split/index.vdt.js +32 -20
  131. package/components/split/memo.d.ts +9 -0
  132. package/components/split/memo.js +26 -0
  133. package/components/steps/index.d.ts +1 -0
  134. package/components/steps/index.js +2 -1
  135. package/components/steps/index.spec.js +1 -1
  136. package/components/steps/index.vdt.js +7 -4
  137. package/components/steps/step.vdt.js +2 -3
  138. package/components/steps/styles.d.ts +1 -0
  139. package/components/steps/styles.js +50 -17
  140. package/components/switch/index.spec.js +82 -65
  141. package/components/table/cell.js +1 -6
  142. package/components/table/cell.vdt.js +1 -1
  143. package/components/table/column.vdt.js +40 -24
  144. package/components/table/index.spec.js +162 -20
  145. package/components/table/row.d.ts +1 -1
  146. package/components/table/row.js +2 -1
  147. package/components/table/styles.js +16 -9
  148. package/components/table/table.d.ts +15 -0
  149. package/components/table/table.js +16 -7
  150. package/components/table/table.vdt.js +20 -6
  151. package/components/table/useChecked.d.ts +3 -2
  152. package/components/table/useChecked.js +23 -12
  153. package/components/table/useDisableRow.d.ts +2 -1
  154. package/components/table/useDisableRow.js +4 -4
  155. package/components/table/useDraggable.d.ts +3 -2
  156. package/components/table/useDraggable.js +11 -15
  157. package/components/table/useGroup.d.ts +9 -3
  158. package/components/table/useGroup.js +48 -37
  159. package/components/table/useMerge.d.ts +2 -1
  160. package/components/table/useMerge.js +5 -4
  161. package/components/table/usePagination.d.ts +8 -0
  162. package/components/table/usePagination.js +81 -0
  163. package/components/table/useStickyScrollbar.js +2 -2
  164. package/components/table/useTree.d.ts +2 -1
  165. package/components/table/useTree.js +3 -4
  166. package/components/table/useWidth.js +2 -2
  167. package/components/tabs/index.d.ts +1 -1
  168. package/components/tabs/index.js +1 -1
  169. package/components/tabs/index.spec.js +67 -0
  170. package/components/tabs/index.vdt.js +9 -4
  171. package/components/tabs/styles.js +32 -34
  172. package/components/tabs/useScroll.d.ts +1 -1
  173. package/components/tabs/useScroll.js +75 -48
  174. package/components/tag/base.d.ts +1 -0
  175. package/components/tag/base.js +1 -1
  176. package/components/tag/index.d.ts +1 -0
  177. package/components/tag/index.js +2 -1
  178. package/components/tag/index.spec.js +147 -4
  179. package/components/tag/styles.d.ts +67 -0
  180. package/components/tag/styles.js +33 -8
  181. package/components/tag/tags.d.ts +27 -0
  182. package/components/tag/tags.js +51 -0
  183. package/components/tag/tags.vdt.js +91 -0
  184. package/components/tag/useChildren.d.ts +2 -0
  185. package/components/tag/useChildren.js +39 -0
  186. package/components/tag/useDraggable.d.ts +3 -0
  187. package/components/tag/useDraggable.js +89 -0
  188. package/components/tag/useNowrap.d.ts +7 -0
  189. package/components/tag/useNowrap.js +115 -0
  190. package/components/timepicker/index.spec.js +1 -1
  191. package/components/tooltip/content.d.ts +3 -2
  192. package/components/tooltip/content.js +18 -1
  193. package/components/tooltip/content.vdt.js +22 -10
  194. package/components/tooltip/index.spec.js +147 -92
  195. package/components/tooltip/styles.d.ts +23 -0
  196. package/components/tooltip/styles.js +2 -2
  197. package/components/tooltip/tooltip.d.ts +1 -1
  198. package/components/tooltip/tooltip.js +11 -11
  199. package/components/transfer/index.vdt.js +14 -3
  200. package/components/types.d.ts +1 -0
  201. package/components/upload/index.spec.js +5 -6
  202. package/components/upload/index.vdt.js +7 -5
  203. package/components/utils.d.ts +2 -0
  204. package/components/utils.js +24 -3
  205. package/components/virtual.d.ts +8 -0
  206. package/components/virtual.js +126 -0
  207. package/hooks/useResizeObserver.d.ts +1 -1
  208. package/hooks/useResizeObserver.js +19 -6
  209. package/i18n/en-US.d.ts +4 -1
  210. package/i18n/en-US.js +6 -2
  211. package/index.d.ts +5 -3
  212. package/index.js +5 -3
  213. package/package.json +2 -2
  214. package/styles/fonts/iconfont.eot +0 -0
  215. package/styles/fonts/iconfont.js +2 -2
  216. package/styles/fonts/iconfont.svg +35 -35
  217. package/styles/fonts/iconfont.ttf +0 -0
  218. package/styles/fonts/iconfont.woff +0 -0
  219. package/styles/fonts/ionicons.js +3 -3
  220. package/styles/global.js +1 -1
  221. package/yarn-error.log +41 -43
  222. package/components/table/useResizeObserver.d.ts +0 -2
  223. package/components/table/useResizeObserver.js +0 -20
@@ -1,7 +1,4 @@
1
1
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
2
-
3
- function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
4
-
5
2
  import { css } from '@emotion/css';
6
3
  import { theme, setDefault } from '../../styles/theme';
7
4
  import { deepDefaults, sizes } from '../../styles/utils';
@@ -12,13 +9,19 @@ var closeFontSizeMap = {
12
9
  small: '18px',
13
10
  mini: '16px'
14
11
  };
12
+ var navigatorWidthMap = {
13
+ large: theme.large.height,
14
+ default: theme.default.height,
15
+ small: theme.small.height,
16
+ mini: theme.mini.height
17
+ };
15
18
  var defaults = deepDefaults({
16
19
  get transition() {
17
20
  return theme.transition.middle;
18
21
  },
19
22
 
20
23
  get borderColor() {
21
- return theme.color.border;
24
+ return '#f0f2f4';
22
25
  },
23
26
 
24
27
  borderWidth: '1px',
@@ -32,8 +35,6 @@ var defaults = deepDefaults({
32
35
  },
33
36
 
34
37
  closeGap: "8px",
35
- // scroll
36
- navigatorWidth: "20px",
37
38
  //active
38
39
  active: {
39
40
  get color() {
@@ -49,20 +50,21 @@ var defaults = deepDefaults({
49
50
 
50
51
  }
51
52
  },
52
- // border-card
53
- borderCard: {
53
+ card: {
54
54
  get bgColor() {
55
55
  return theme.color.bg;
56
- }
56
+ },
57
57
 
58
- },
59
- // no-border-card
60
- noBorderCard: {
61
- get bgColor() {
62
- return theme.color.bg;
58
+ get borderRadius() {
59
+ return theme.borderRadius;
63
60
  }
64
61
 
65
62
  },
63
+ flatCard: {
64
+ // get bgColor() { return theme.color.bg },
65
+ // get borderRadius() { return theme.borderRadius },
66
+ padding: '2px'
67
+ },
66
68
  // define size
67
69
  size: {
68
70
  large: {
@@ -90,6 +92,11 @@ var defaults = deepDefaults({
90
92
 
91
93
  get closeFontSize() {
92
94
  return closeFontSizeMap[size];
95
+ },
96
+
97
+ // scroll
98
+ get navigatorWidth() {
99
+ return navigatorWidthMap[size];
93
100
  }
94
101
 
95
102
  };
@@ -102,45 +109,36 @@ setDefault(function () {
102
109
  }).tabs;
103
110
  });
104
111
  export function makeStyles() {
105
- return /*#__PURE__*/css(makeCommonStyles(), ";", makeScrollStyles(), ";&.k-type-default{", makeDefaultStyles(), ";}&.k-type-card{", makeDefaultStyles(), " ", makeCardStyles(), ";}&.k-type-border-card{", makeBorderCardStyles(), ";}&.k-type-no-border-card{", makeNoBorderCardStyles(), ";}");
112
+ return /*#__PURE__*/css(makeCommonStyles(), ";", makeScrollStyles(), ";&.k-type-default{", makeDefaultStyles(), ";}&.k-type-card{", makeCardStyles(), ";}&.k-type-flat-card{", makeFlatCardStyles(), ";}");
106
113
  }
107
114
 
108
115
  function makeCommonStyles() {
109
116
  var active = tabs.active;
110
117
  var bar = active.bar;
111
- return /*#__PURE__*/css("position:relative;.k-tab{cursor:pointer;display:inline-block;text-align:center;color:", tabs.color, ";position:relative;vertical-align:middle;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;&:hover,&.k-active{color:", active.color, ";}&.k-disabled{color:", theme.color.disabled, ";cursor:not-allowed;}}.k-tab-close{margin-right:-", tabs.closeGap, ";margin-left:", tabs.closeGap, ";position:relative;top:-1px;color:", theme.color.lightBlack, ";}.k-tabs-active-bar{transition:all ", tabs.transition, ";position:absolute;left:0;height:", bar.height, ";background:", bar.bgColor, ";bottom:calc(-", bar.height, " / 2);}&.k-vertical{display:inline-block;.k-tab{display:block;}.k-tabs-active-bar{left:auto;top:0;right:calc(-", bar.height, " / 2);width:", bar.height, ";height:auto;}}", _mapInstanceProperty(sizes).call(sizes, function (size) {
118
+ return /*#__PURE__*/css("position:relative;.k-tab{display:inline-flex;cursor:pointer;text-align:center;align-items:center;color:", tabs.color, ";white-space:nowrap;text-overflow:ellipsis;&:hover,&.k-active{color:", active.color, ";}&.k-disabled{color:", theme.color.disabled, ";cursor:not-allowed;}}.k-tab-close{margin-right:-", tabs.closeGap, ";margin-left:", tabs.closeGap, ";color:", theme.color.lightBlack, ";}.k-tabs-active-bar{transition:all ", tabs.transition, ";position:absolute;left:0;height:", bar.height, ";background:", bar.bgColor, ";bottom:0;}&.k-vertical{display:inline-block;.k-tab{display:block;}.k-tabs-active-bar{left:auto;top:0;right:0;width:", bar.height, ";height:auto;}}", _mapInstanceProperty(sizes).call(sizes, function (size) {
112
119
  var styles = tabs[size];
113
- return "\n &.k-size-" + size + " {\n .k-tab {\n font-size: " + styles.fontSize + ";\n height: " + styles.height + ";\n line-height: " + styles.height + ";\n padding: " + styles.padding + ";\n }\n .k-tab-close .k-icon {\n font-size: " + styles.closeFontSize + ";\n }\n }\n ";
120
+ return "\n &.k-size-" + size + " {\n .k-tab {\n font-size: " + styles.fontSize + ";\n height: " + styles.height + ";\n line-height: " + styles.height + ";\n padding: " + styles.padding + ";\n }\n .k-tab-close .k-icon {\n font-size: " + styles.closeFontSize + ";\n }\n &:not(.k-vertical).k-is-scroll {\n padding: 0 " + styles.navigatorWidth + ";\n }\n &.k-vertical.k-is-scroll {\n padding: " + styles.navigatorWidth + " 0;\n }\n }\n ";
114
121
  }), ";");
115
122
  }
116
123
 
117
124
  function makeScrollStyles() {
118
- return /*#__PURE__*/css("&:not(.k-vertical){.k-tabs-scroll{overflow:hidden;position:relative;padding-bottom:1px;margin-bottom:-1px;}&.k-tabs-border-card,&.k-tabs-no-border-card{.k-tabs-scroll{padding-bottom:0;margin-bottom:0;}}.k-tabs-wrapper{white-space:nowrap;float:left;transition:transform ", tabs.transition, ";}.k-tabs-prev,.k-tabs-next{position:absolute;top:0;width:", tabs.navigatorWidth, "!important;}.k-tabs-prev{left:0;}.k-tabs-next{right:0;}&.k-is-scroll{padding:0 ", tabs.navigatorWidth, ";}}");
125
+ return /*#__PURE__*/css("overflow:hidden;.k-tabs-scroll{overflow:hidden;position:relative;padding-bottom:1px;margin-bottom:-1px;}&.k-type-card,&.k-type-flat-card{.k-tabs-scroll{padding-bottom:0;margin-bottom:0;}}.k-tabs-wrapper{white-space:nowrap;transition:transform ", tabs.transition, ";}.k-tabs-prev,.k-tabs-next{position:absolute;&:not(.k-disabled){box-shadow:", theme.boxShadow, ";}}&:not(.k-vertical){.k-tabs-wrapper{float:left;}.k-tabs-prev,.k-tabs-next{top:0;}.k-tabs-prev{left:0;}.k-tabs-next{right:0;}}&.k-vertical{&,.k-tabs-scroll{height:100%;}.k-tabs-prev,.k-tabs-next{width:100%!important;left:0;}.k-tabs-prev{top:0;}.k-tabs-next{bottom:0;}}");
119
126
  }
120
127
 
121
128
  function makeDefaultStyles() {
122
129
  return /*#__PURE__*/css("border-bottom:", tabs.border, ";&.k-vertical{border-bottom:none;border-right:", tabs.border, ";}");
123
130
  }
124
131
 
125
- function makeCardActiveBarCommonStyles() {
126
- return /*#__PURE__*/css(process.env.NODE_ENV === "production" ? {
127
- name: "1c3pzdg",
128
- styles: "background:#fff;top:0;height:auto;z-index:-1"
129
- } : {
130
- name: "1c3pzdg",
131
- styles: "background:#fff;top:0;height:auto;z-index:-1",
132
- toString: _EMOTION_STRINGIFIED_CSS_ERROR__
133
- });
132
+ function makeCardCommonStyles() {
133
+ return /*#__PURE__*/css("border-radius:", tabs.card.borderRadius, ";background-color:", tabs.card.bgColor, ";.k-tabs-active-bar{background:#fff;top:0;height:auto;z-index:-1;}");
134
134
  }
135
135
 
136
136
  function makeCardStyles() {
137
- return /*#__PURE__*/css(".k-tab{margin:0;}.k-tabs-active-bar{", makeCardActiveBarCommonStyles(), ";border-left:", tabs.border, ";border-right:", tabs.border, ";&:before{content:'';display:block;position:absolute;height:", tabs.active.bar.height, ";background:", theme.color.primary, ";top:0;left:-", tabs.borderWidth, ";right:-", tabs.borderWidth, ";}}&.k-vertical{.k-tabs-active-bar{left:0;width:auto;border-left:none;border-right:none;border-top:", tabs.border, ";border-bottom:", tabs.border, ";&:before{width:", tabs.active.bar.height, ";left:0;right:auto;bottom:0;height:auto;}}}");
138
- }
139
-
140
- function makeBorderCardStyles() {
141
- return /*#__PURE__*/css("border:", tabs.border, ";border-bottom:none;background:", tabs.borderCard.bgColor, ";.k-tab{margin:0;}.k-tabs-active-bar{background:#fff;top:0;height:auto;z-index:-1;}&.k-vertical{border-right:none;border-bottom:", tabs.border, ";.k-tabs-active-bar{width:auto;height:0;left:0;bottom:0;right:0;}}");
137
+ var borderRadius = tabs.card.borderRadius;
138
+ return /*#__PURE__*/css(makeCardCommonStyles(), ";.k-tabs-active-bar{border-radius:", borderRadius, " ", borderRadius, " 0px 0px;box-shadow:", theme.boxShadow, ";}&.k-vertical{.k-tabs-active-bar{width:100%;left:0;border-radius:", borderRadius, " 0px 0px ", borderRadius, ";}}");
142
139
  }
143
140
 
144
- function makeNoBorderCardStyles() {
145
- return /*#__PURE__*/css("border-radius:", theme.borderRadius, ";.k-tab{&:before{content:'';display:block;position:absolute;background:", tabs.noBorderCard.bgColor, ";top:0;bottom:0;left:0;right:0;z-index:-1;}}.k-tabs-active-bar{background:#fff;top:0;height:auto;z-index:-1;box-shadow:0px 0px 5px rgba(0, 0, 0, 0.08);border-radius:4px 4px 0px 0px;}&.k-vertical{border-right:none;.k-tabs-active-bar{width:auto;height:0;left:0;bottom:0;right:0;}}");
141
+ function makeFlatCardStyles() {
142
+ var padding = tabs.flatCard.padding;
143
+ return /*#__PURE__*/css(makeCardCommonStyles(), ";padding:0 ", padding, ";.k-tabs-active-bar{top:", padding, ";height:calc(100% - ", padding, " * 2);border-radius:", tabs.card.borderRadius, ";}&.k-vertical{padding:", padding, " 0;.k-tabs-active-bar{left:", padding, ";width:calc(100% - ", padding, " * 2);}}");
146
144
  }
@@ -1,6 +1,6 @@
1
1
  export declare function useScroll(): {
2
2
  isScroll: import("../../hooks/useState").State<boolean>;
3
- left: import("../../hooks/useState").State<number>;
3
+ offset: import("../../hooks/useState").State<number>;
4
4
  enablePrev: import("../../hooks/useState").State<boolean>;
5
5
  enableNext: import("../../hooks/useState").State<boolean>;
6
6
  prev: () => void;
@@ -6,7 +6,7 @@ export function useScroll() {
6
6
  var scrollRef = createRef();
7
7
  var wrapperRef = createRef();
8
8
  var isScroll = useState(false);
9
- var left = useState(0);
9
+ var offset = useState(0);
10
10
  var enablePrev = useState(false);
11
11
  var enableNext = useState(false);
12
12
  onMounted(refresh);
@@ -16,94 +16,121 @@ export function useScroll() {
16
16
  presented: true
17
17
  });
18
18
 
19
- function refresh() {
19
+ function getLength() {
20
20
  var _instance$get = instance.get(),
21
21
  vertical = _instance$get.vertical;
22
22
 
23
- if (vertical) return;
24
- var scrollWidth = scrollRef.value.offsetWidth;
25
- var wrapperWidth = wrapperRef.value.offsetWidth;
26
- isScroll.set(scrollWidth < wrapperWidth);
27
- updateTransition(left.value, scrollWidth, wrapperWidth);
28
- }
29
-
30
- function updateTransition(_left, scrollWidth, wrapperWidth) {
31
- if (_left === void 0) {
32
- _left = left.value;
23
+ if (vertical) {
24
+ return {
25
+ scrollLength: scrollRef.value.offsetHeight,
26
+ wrapperLength: wrapperRef.value.offsetHeight
27
+ };
33
28
  }
34
29
 
35
- if (scrollWidth === void 0) {
36
- scrollWidth = scrollRef.value.offsetWidth;
37
- }
30
+ return {
31
+ scrollLength: scrollRef.value.offsetWidth,
32
+ wrapperLength: wrapperRef.value.offsetWidth
33
+ };
34
+ }
38
35
 
39
- if (wrapperWidth === void 0) {
40
- wrapperWidth = wrapperRef.value.offsetWidth;
41
- }
36
+ function refresh() {
37
+ var _getLength = getLength(),
38
+ scrollLength = _getLength.scrollLength,
39
+ wrapperLength = _getLength.wrapperLength;
42
40
 
41
+ isScroll.set(scrollLength < wrapperLength);
42
+ updateTransition(offset.value, scrollLength, wrapperLength);
43
+ }
44
+
45
+ function updateTransition(_offset, scrollLength, wrapperLength) {
43
46
  var prev = true;
44
47
  var next = true;
45
48
 
46
- if (_left >= 0) {
47
- _left = 0;
49
+ if (_offset >= 0) {
50
+ _offset = 0;
48
51
  prev = false;
49
- } else if (_left <= scrollWidth - wrapperWidth) {
50
- _left = scrollWidth - wrapperWidth;
52
+ } else if (_offset <= scrollLength - wrapperLength) {
53
+ _offset = scrollLength - wrapperLength;
51
54
  next = false;
52
55
  }
53
56
 
54
- left.set(_left);
57
+ offset.set(_offset);
55
58
  enablePrev.set(prev);
56
59
  enableNext.set(next);
57
60
  }
58
61
 
59
62
  function prev() {
60
- var scrollWidth = scrollRef.value.offsetWidth;
61
- updateTransition(left.value + scrollWidth);
63
+ var _getLength2 = getLength(),
64
+ scrollLength = _getLength2.scrollLength,
65
+ wrapperLength = _getLength2.wrapperLength;
66
+
67
+ updateTransition(offset.value + scrollLength, scrollLength, wrapperLength);
62
68
  }
63
69
 
64
70
  function next() {
65
- var scrollWidth = scrollRef.value.offsetWidth;
66
- updateTransition(left.value - scrollWidth);
71
+ var _getLength3 = getLength(),
72
+ scrollLength = _getLength3.scrollLength,
73
+ wrapperLength = _getLength3.wrapperLength;
74
+
75
+ updateTransition(offset.value - scrollLength, scrollLength, wrapperLength);
67
76
  }
68
77
 
69
78
  function scrollActiveToView() {
70
79
  var _instance$get2 = instance.get(),
71
80
  vertical = _instance$get2.vertical;
72
81
 
73
- if (vertical) return;
74
82
  var activeTab = scrollRef.value.querySelector('.k-tab.k-active');
75
83
 
76
84
  if (activeTab) {
77
- var _left = left.value; // don't use getBoundingClientRect, it has transform and will return digital number
85
+ var _offset = offset.value; // don't use getBoundingClientRect, it has transform and will return digital number
86
+
87
+ var activeRect;
88
+ var scrollRect;
89
+ var wrapperRect;
90
+
91
+ if (vertical) {
92
+ activeRect = {
93
+ offset: activeTab.offsetTop,
94
+ length: activeTab.offsetHeight
95
+ };
96
+ scrollRect = {
97
+ length: scrollRef.value.offsetHeight
98
+ };
99
+ wrapperRect = {
100
+ offset: wrapperRef.value.offsetTop,
101
+ length: wrapperRef.value.offsetHeight
102
+ };
103
+ } else {
104
+ activeRect = {
105
+ offset: activeTab.offsetLeft,
106
+ length: activeTab.offsetWidth
107
+ };
108
+ scrollRect = {
109
+ length: scrollRef.value.offsetWidth
110
+ };
111
+ wrapperRect = {
112
+ offset: wrapperRef.value.offsetLeft,
113
+ length: wrapperRef.value.offsetWidth
114
+ };
115
+ }
78
116
 
79
- var activeRect = {
80
- left: activeTab.offsetLeft,
81
- width: activeTab.offsetWidth
82
- };
83
- var scrollRect = {
84
- width: scrollRef.value.offsetWidth
85
- };
86
- var wrapperRect = {
87
- left: wrapperRef.value.offsetLeft,
88
- width: wrapperRef.value.offsetWidth
89
- };
90
- var x = activeRect.left - wrapperRect.left;
117
+ var offsetDelta = activeRect.offset - wrapperRect.offset;
91
118
 
92
- if (_left + x <= 0) {
93
- _left = -x;
94
- } else if (x + activeRect.width + _left > scrollRect.width) {
95
- _left = -x - activeRect.width + scrollRect.width;
119
+ if (_offset + offsetDelta <= 0) {
120
+ _offset = -offsetDelta;
121
+ } else if (offsetDelta + activeRect.length + _offset > scrollRect.length) {
122
+ _offset = -offsetDelta - activeRect.length + scrollRect.length;
96
123
  }
97
124
 
98
- left.set(_left);
125
+ offset.set(_offset);
99
126
  } else {
100
- left.set(0);
127
+ offset.set(0);
101
128
  }
102
129
  }
103
130
 
104
131
  return {
105
132
  isScroll: isScroll,
106
- left: left,
133
+ offset: offset,
107
134
  enablePrev: enablePrev,
108
135
  enableNext: enableNext,
109
136
  prev: prev,
@@ -14,6 +14,7 @@ export interface TagEvents {
14
14
  }
15
15
  export interface TagBlocks {
16
16
  }
17
+ export declare const typeDefs: Required<TypeDefs<TagProps>>;
17
18
  export declare class Tag<T extends TagProps = TagProps, E extends TagEvents = TagEvents, B extends TagBlocks = TagBlocks> extends Component<T, E, B> {
18
19
  static template: string | import("intact").Template<any>;
19
20
  static typeDefs: Required<TypeDefs<TagProps>>;
@@ -4,7 +4,7 @@ import { Component } from 'intact-react';
4
4
  import { bind } from '../utils';
5
5
  import template from './index.vdt';
6
6
  import { sizes } from '../../styles/utils';
7
- var typeDefs = {
7
+ export var typeDefs = {
8
8
  type: ['default', 'primary', 'danger', 'success', 'warning'],
9
9
  closable: Boolean,
10
10
  closed: Boolean,
@@ -1,4 +1,5 @@
1
1
  import { TagProps, TagEvents, TagBlocks, Tag as BaseTag } from './base';
2
+ export * from './tags';
2
3
  export type { TagProps, TagEvents, TagBlocks };
3
4
  export declare class Tag extends BaseTag<TagProps, TagEvents, TagBlocks> {
4
5
  }
@@ -1,5 +1,6 @@
1
1
  import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
2
- import { Tag as BaseTag } from './base'; // export declare class _Tag extends BaseTag<
2
+ import { Tag as BaseTag } from './base';
3
+ export * from './tags'; // export declare class _Tag extends BaseTag<
3
4
  // TagProps,
4
5
  // TagEvents,
5
6
  // TagBlocks
@@ -1,11 +1,11 @@
1
1
  import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
3
3
  import ClosableDemo from '~/components/tag/demos/closable';
4
- import { mount, unmount, wait } from '../../test/utils';
4
+ import { mount, wait, dispatchEvent, getElement } from '../../test/utils';
5
+ import TagsDemo from '~/components/tag/demos/tags';
6
+ import DraggableDemo from '~/components/tag/demos/draggable';
5
7
  describe('Tag', function () {
6
- afterEach(function () {
7
- return unmount();
8
- });
8
+ // afterEach(() => unmount());
9
9
  it('should not close tag if we has prevented default', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
10
10
  var _mount, instance, element, btns, preventDefaultBtn, commonBtn;
11
11
 
@@ -37,4 +37,147 @@ describe('Tag', function () {
37
37
  }
38
38
  }, _callee);
39
39
  })));
40
+ it('should hide tags that overflow', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
41
+ var _mount2, instance, element, lastPanel, more, tooltip, tags;
42
+
43
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
44
+ while (1) {
45
+ switch (_context2.prev = _context2.next) {
46
+ case 0:
47
+ _mount2 = mount(TagsDemo), instance = _mount2[0], element = _mount2[1];
48
+ lastPanel = element.querySelector('.k-split-last');
49
+ _context2.next = 4;
50
+ return wait(0);
51
+
52
+ case 4:
53
+ expect(lastPanel.innerHTML).to.matchSnapshot(); // show tooltip
54
+
55
+ more = lastPanel.querySelector('.k-tags-more');
56
+ dispatchEvent(more, 'mouseenter');
57
+ _context2.next = 9;
58
+ return wait();
59
+
60
+ case 9:
61
+ tooltip = getElement('.k-tags-tooltip');
62
+ expect(tooltip.querySelectorAll('.k-tag').length).to.eql(3); // remove one tag
63
+
64
+ dispatchEvent(lastPanel.querySelector('.k-tag-close'), 'click');
65
+ _context2.next = 14;
66
+ return wait(0);
67
+
68
+ case 14:
69
+ expect(lastPanel.innerHTML).to.matchSnapshot(); // resize
70
+
71
+ tags = lastPanel.querySelector('.k-tags');
72
+ tags.style.width = '200px';
73
+ _context2.next = 19;
74
+ return wait(200);
75
+
76
+ case 19:
77
+ expect(lastPanel.innerHTML).to.matchSnapshot(); // show tooltip again (the "more" element will be removed and created again)
78
+
79
+ more = lastPanel.querySelector('.k-tags-more');
80
+ dispatchEvent(more, 'mouseenter');
81
+ _context2.next = 24;
82
+ return wait();
83
+
84
+ case 24:
85
+ tooltip = getElement('.k-tags-tooltip');
86
+ expect(tooltip.querySelectorAll('.k-tag').length).to.eql(3);
87
+
88
+ case 26:
89
+ case "end":
90
+ return _context2.stop();
91
+ }
92
+ }
93
+ }, _callee2);
94
+ })));
95
+ it('should support drag tags', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
96
+ var _mount3, instance, element, test, _test, _element$querySelecto, tag1, tag2, tag6, _element$querySelecto2, tag11, tag22, more, dropdown, _dropdown$querySelect, tag55, tag66;
97
+
98
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
99
+ while (1) {
100
+ switch (_context4.prev = _context4.next) {
101
+ case 0:
102
+ _test = function _test3() {
103
+ _test = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(from, to) {
104
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
105
+ while (1) {
106
+ switch (_context3.prev = _context3.next) {
107
+ case 0:
108
+ dispatchEvent(from, 'dragstart');
109
+ _context3.next = 3;
110
+ return wait();
111
+
112
+ case 3:
113
+ dispatchEvent(to, 'dragover');
114
+ _context3.next = 6;
115
+ return wait(500);
116
+
117
+ case 6:
118
+ expect(element.innerHTML).to.matchSnapshot();
119
+ dispatchEvent(from, 'dragend');
120
+ _context3.next = 10;
121
+ return wait();
122
+
123
+ case 10:
124
+ expect(element.innerHTML).to.matchSnapshot();
125
+
126
+ case 11:
127
+ case "end":
128
+ return _context3.stop();
129
+ }
130
+ }
131
+ }, _callee3);
132
+ }));
133
+ return _test.apply(this, arguments);
134
+ };
135
+
136
+ test = function _test2(_x, _x2) {
137
+ return _test.apply(this, arguments);
138
+ };
139
+
140
+ _mount3 = mount(DraggableDemo), instance = _mount3[0], element = _mount3[1];
141
+ _element$querySelecto = element.querySelectorAll('.k-tag'), tag1 = _element$querySelecto[0], tag2 = _element$querySelecto[1], tag6 = _element$querySelecto[5];
142
+ _context4.next = 6;
143
+ return test(tag1, tag2);
144
+
145
+ case 6:
146
+ _context4.next = 8;
147
+ return test(tag1, tag6);
148
+
149
+ case 8:
150
+ // with more tooltip
151
+ _element$querySelecto2 = element.querySelectorAll('.k-tags:last-of-type .k-tag'), tag11 = _element$querySelecto2[0], tag22 = _element$querySelecto2[1], more = _element$querySelecto2[4];
152
+ _context4.next = 11;
153
+ return test(tag11, tag22);
154
+
155
+ case 11:
156
+ _context4.next = 13;
157
+ return wait(0);
158
+
159
+ case 13:
160
+ dispatchEvent(more, 'mouseenter');
161
+ _context4.next = 16;
162
+ return wait();
163
+
164
+ case 16:
165
+ dropdown = getElement('.k-tags-tooltip');
166
+ _dropdown$querySelect = dropdown.querySelectorAll('.k-tag'), tag55 = _dropdown$querySelect[0], tag66 = _dropdown$querySelect[1];
167
+ _context4.next = 20;
168
+ return test(tag55, tag11);
169
+
170
+ case 20:
171
+ expect(dropdown.innerText).to.eql('warning\nwith tooltip'); // should not drag to other tags
172
+
173
+ _context4.next = 23;
174
+ return test(tag11, tag2);
175
+
176
+ case 23:
177
+ case "end":
178
+ return _context4.stop();
179
+ }
180
+ }
181
+ }, _callee4);
182
+ })));
40
183
  });
@@ -1,2 +1,69 @@
1
1
  import '../../styles/global';
2
+ declare type TypeStyles = {
3
+ color: string;
4
+ bgColor: string;
5
+ };
6
+ declare const defaults: {
7
+ readonly border: string;
8
+ readonly borderRadius: string;
9
+ readonly fontSize: string;
10
+ padding: string;
11
+ height: string;
12
+ readonly bgColor: string;
13
+ close: {
14
+ fontSize: string;
15
+ gap: string;
16
+ /**
17
+ * fix the width to calculate the width for nowrap tags,
18
+ * otherwise the width will be decided by font font-icons loaded
19
+ */
20
+ width: string;
21
+ };
22
+ disabled: {
23
+ readonly color: string;
24
+ readonly borderColor: string;
25
+ readonly bgColor: string;
26
+ };
27
+ large: {
28
+ padding: string;
29
+ height: string;
30
+ readonly fontSize: string;
31
+ close: {
32
+ fontSize: string;
33
+ gap: string;
34
+ };
35
+ };
36
+ small: {
37
+ padding: string;
38
+ height: string;
39
+ readonly fontSize: string;
40
+ close: {
41
+ fontSize: string;
42
+ gap: string;
43
+ };
44
+ };
45
+ mini: {
46
+ padding: string;
47
+ height: string;
48
+ fontSize: string;
49
+ close: {
50
+ fontSize: string;
51
+ gap: string;
52
+ };
53
+ };
54
+ none: {
55
+ readonly bgColor: string;
56
+ };
57
+ tags: {
58
+ gap: string;
59
+ };
60
+ } & {
61
+ primary: TypeStyles;
62
+ warning: TypeStyles;
63
+ danger: TypeStyles;
64
+ success: TypeStyles;
65
+ };
66
+ declare let tag: typeof defaults;
67
+ export { tag };
2
68
  export declare function makeStyles(): string;
69
+ export declare function makeTagsStyles(): string;