@xanui/ui 1.2.6 → 1.2.8

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 (332) hide show
  1. package/Accordion/index.cjs +5 -5
  2. package/Accordion/index.cjs.map +1 -1
  3. package/Accordion/index.d.ts +3 -3
  4. package/Accordion/index.js +5 -5
  5. package/Accordion/index.js.map +1 -1
  6. package/Alert/index.cjs +19 -17
  7. package/Alert/index.cjs.map +1 -1
  8. package/Alert/index.d.ts +2 -2
  9. package/Alert/index.js +19 -17
  10. package/Alert/index.js.map +1 -1
  11. package/Autocomplete/index.cjs +2 -2
  12. package/Autocomplete/index.cjs.map +1 -1
  13. package/Autocomplete/index.d.ts +7 -7
  14. package/Autocomplete/index.js +2 -2
  15. package/Autocomplete/index.js.map +1 -1
  16. package/Avatar/index.cjs +2 -2
  17. package/Avatar/index.cjs.map +1 -1
  18. package/Avatar/index.d.ts +2 -2
  19. package/Avatar/index.js +2 -2
  20. package/Avatar/index.js.map +1 -1
  21. package/AvatarBox/index.cjs +19 -0
  22. package/AvatarBox/index.cjs.map +1 -0
  23. package/AvatarBox/index.d.ts +19 -0
  24. package/AvatarBox/index.js +17 -0
  25. package/AvatarBox/index.js.map +1 -0
  26. package/AvatarPicker/index.cjs +80 -0
  27. package/AvatarPicker/index.cjs.map +1 -0
  28. package/AvatarPicker/index.d.ts +27 -0
  29. package/AvatarPicker/index.js +78 -0
  30. package/AvatarPicker/index.js.map +1 -0
  31. package/Badge/index.cjs +1 -1
  32. package/Badge/index.cjs.map +1 -1
  33. package/Badge/index.d.ts +4 -4
  34. package/Badge/index.js +1 -1
  35. package/Badge/index.js.map +1 -1
  36. package/Box/index.d.ts +2 -2
  37. package/Button/index.cjs +5 -3
  38. package/Button/index.cjs.map +1 -1
  39. package/Button/index.d.ts +2 -2
  40. package/Button/index.js +5 -3
  41. package/Button/index.js.map +1 -1
  42. package/ButtonGroup/index.cjs +3 -2
  43. package/ButtonGroup/index.cjs.map +1 -1
  44. package/ButtonGroup/index.d.ts +2 -2
  45. package/ButtonGroup/index.js +3 -2
  46. package/ButtonGroup/index.js.map +1 -1
  47. package/Calendar/index.cjs +10 -10
  48. package/Calendar/index.cjs.map +1 -1
  49. package/Calendar/index.js +10 -10
  50. package/Calendar/index.js.map +1 -1
  51. package/CalendarInput/index.cjs +1 -1
  52. package/CalendarInput/index.cjs.map +1 -1
  53. package/CalendarInput/index.js +1 -1
  54. package/CalendarInput/index.js.map +1 -1
  55. package/Card/index.cjs +34 -0
  56. package/Card/index.cjs.map +1 -0
  57. package/Card/index.d.ts +10 -0
  58. package/Card/index.js +32 -0
  59. package/Card/index.js.map +1 -0
  60. package/Carousel/index.cjs +231 -0
  61. package/Carousel/index.cjs.map +1 -0
  62. package/Carousel/index.d.ts +28 -0
  63. package/Carousel/index.js +229 -0
  64. package/Carousel/index.js.map +1 -0
  65. package/Checkbox/index.cjs +2 -2
  66. package/Checkbox/index.cjs.map +1 -1
  67. package/Checkbox/index.d.ts +2 -2
  68. package/Checkbox/index.js +2 -2
  69. package/Checkbox/index.js.map +1 -1
  70. package/Chip/index.cjs +3 -3
  71. package/Chip/index.cjs.map +1 -1
  72. package/Chip/index.d.ts +2 -2
  73. package/Chip/index.js +3 -3
  74. package/Chip/index.js.map +1 -1
  75. package/CircleProgress/index.cjs +10 -10
  76. package/CircleProgress/index.cjs.map +1 -1
  77. package/CircleProgress/index.d.ts +2 -2
  78. package/CircleProgress/index.js +10 -10
  79. package/CircleProgress/index.js.map +1 -1
  80. package/ClickOutside/index.cjs +3 -12
  81. package/ClickOutside/index.cjs.map +1 -1
  82. package/ClickOutside/index.d.ts +3 -3
  83. package/ClickOutside/index.js +4 -13
  84. package/ClickOutside/index.js.map +1 -1
  85. package/Collaps/index.cjs +5 -5
  86. package/Collaps/index.cjs.map +1 -1
  87. package/Collaps/index.d.ts +2 -2
  88. package/Collaps/index.js +5 -5
  89. package/Collaps/index.js.map +1 -1
  90. package/Container/index.d.ts +2 -2
  91. package/DataFilter/index.d.ts +2 -2
  92. package/DataFilter/options/DateFilter.cjs +3 -3
  93. package/DataFilter/options/DateFilter.cjs.map +1 -1
  94. package/DataFilter/options/DateFilter.js +3 -3
  95. package/DataFilter/options/DateFilter.js.map +1 -1
  96. package/DataFilter/options/DateRangeFilter.cjs +2 -2
  97. package/DataFilter/options/DateRangeFilter.cjs.map +1 -1
  98. package/DataFilter/options/DateRangeFilter.js +2 -2
  99. package/DataFilter/options/DateRangeFilter.js.map +1 -1
  100. package/DataFilter/options/MultiSelectFilter.cjs +3 -3
  101. package/DataFilter/options/MultiSelectFilter.cjs.map +1 -1
  102. package/DataFilter/options/MultiSelectFilter.js +3 -3
  103. package/DataFilter/options/MultiSelectFilter.js.map +1 -1
  104. package/DataFilter/options/NumberFilter.cjs +2 -2
  105. package/DataFilter/options/NumberFilter.cjs.map +1 -1
  106. package/DataFilter/options/NumberFilter.js +2 -2
  107. package/DataFilter/options/NumberFilter.js.map +1 -1
  108. package/DataFilter/options/NumberRangeFilter.cjs +2 -2
  109. package/DataFilter/options/NumberRangeFilter.cjs.map +1 -1
  110. package/DataFilter/options/NumberRangeFilter.js +2 -2
  111. package/DataFilter/options/NumberRangeFilter.js.map +1 -1
  112. package/DataFilter/options/SelectFilter.cjs +3 -3
  113. package/DataFilter/options/SelectFilter.cjs.map +1 -1
  114. package/DataFilter/options/SelectFilter.js +3 -3
  115. package/DataFilter/options/SelectFilter.js.map +1 -1
  116. package/DataFilter/options/TextFilter.cjs +2 -2
  117. package/DataFilter/options/TextFilter.cjs.map +1 -1
  118. package/DataFilter/options/TextFilter.js +2 -2
  119. package/DataFilter/options/TextFilter.js.map +1 -1
  120. package/Datatable/FilterBox.cjs +2 -2
  121. package/Datatable/FilterBox.cjs.map +1 -1
  122. package/Datatable/FilterBox.js +2 -2
  123. package/Datatable/FilterBox.js.map +1 -1
  124. package/Datatable/Row.cjs +2 -2
  125. package/Datatable/Row.cjs.map +1 -1
  126. package/Datatable/Row.js +2 -2
  127. package/Datatable/Row.js.map +1 -1
  128. package/Datatable/SelectedBox.cjs +2 -2
  129. package/Datatable/SelectedBox.cjs.map +1 -1
  130. package/Datatable/SelectedBox.js +2 -2
  131. package/Datatable/SelectedBox.js.map +1 -1
  132. package/Datatable/Table.cjs +1 -1
  133. package/Datatable/Table.cjs.map +1 -1
  134. package/Datatable/Table.js +1 -1
  135. package/Datatable/Table.js.map +1 -1
  136. package/Datatable/TableHead.cjs +3 -3
  137. package/Datatable/TableHead.cjs.map +1 -1
  138. package/Datatable/TableHead.js +3 -3
  139. package/Datatable/TableHead.js.map +1 -1
  140. package/Datatable/index.cjs +1 -1
  141. package/Datatable/index.cjs.map +1 -1
  142. package/Datatable/index.d.ts +2 -2
  143. package/Datatable/index.js +1 -1
  144. package/Datatable/index.js.map +1 -1
  145. package/Divider/index.cjs +3 -3
  146. package/Divider/index.cjs.map +1 -1
  147. package/Divider/index.d.ts +2 -2
  148. package/Divider/index.js +3 -3
  149. package/Divider/index.js.map +1 -1
  150. package/Drawer/index.cjs +2 -2
  151. package/Drawer/index.cjs.map +1 -1
  152. package/Drawer/index.js +2 -2
  153. package/Drawer/index.js.map +1 -1
  154. package/FilePicker/index.cjs +115 -0
  155. package/FilePicker/index.cjs.map +1 -0
  156. package/FilePicker/index.d.ts +23 -0
  157. package/FilePicker/index.js +113 -0
  158. package/FilePicker/index.js.map +1 -0
  159. package/Form/index.cjs +1 -1
  160. package/Form/index.cjs.map +1 -1
  161. package/Form/index.d.ts +2 -2
  162. package/Form/index.js +1 -1
  163. package/Form/index.js.map +1 -1
  164. package/GalleryPicker/index.cjs +88 -0
  165. package/GalleryPicker/index.cjs.map +1 -0
  166. package/GalleryPicker/index.d.ts +26 -0
  167. package/GalleryPicker/index.js +86 -0
  168. package/GalleryPicker/index.js.map +1 -0
  169. package/GridContainer/index.d.ts +2 -2
  170. package/GridItem/index.d.ts +2 -2
  171. package/IconButton/index.cjs +6 -3
  172. package/IconButton/index.cjs.map +1 -1
  173. package/IconButton/index.d.ts +2 -2
  174. package/IconButton/index.js +6 -3
  175. package/IconButton/index.js.map +1 -1
  176. package/Image/index.cjs +2 -14
  177. package/Image/index.cjs.map +1 -1
  178. package/Image/index.d.ts +3 -5
  179. package/Image/index.js +3 -15
  180. package/Image/index.js.map +1 -1
  181. package/Input/index.cjs +10 -10
  182. package/Input/index.cjs.map +1 -1
  183. package/Input/index.d.ts +14 -14
  184. package/Input/index.js +10 -10
  185. package/Input/index.js.map +1 -1
  186. package/InputNumber/index.d.ts +2 -2
  187. package/Label/index.cjs +1 -1
  188. package/Label/index.cjs.map +1 -1
  189. package/Label/index.d.ts +2 -2
  190. package/Label/index.js +1 -1
  191. package/Label/index.js.map +1 -1
  192. package/Layer/index.cjs +12 -13
  193. package/Layer/index.cjs.map +1 -1
  194. package/Layer/index.d.ts +5 -5
  195. package/Layer/index.js +13 -14
  196. package/Layer/index.js.map +1 -1
  197. package/LineProgress/index.cjs +6 -6
  198. package/LineProgress/index.cjs.map +1 -1
  199. package/LineProgress/index.d.ts +2 -2
  200. package/LineProgress/index.js +6 -6
  201. package/LineProgress/index.js.map +1 -1
  202. package/Link/index.cjs +41 -0
  203. package/Link/index.cjs.map +1 -0
  204. package/Link/index.d.ts +17 -0
  205. package/Link/index.js +39 -0
  206. package/Link/index.js.map +1 -0
  207. package/List/index.cjs +1 -1
  208. package/List/index.cjs.map +1 -1
  209. package/List/index.d.ts +2 -2
  210. package/List/index.js +1 -1
  211. package/List/index.js.map +1 -1
  212. package/ListItem/index.cjs +8 -8
  213. package/ListItem/index.cjs.map +1 -1
  214. package/ListItem/index.d.ts +2 -2
  215. package/ListItem/index.js +8 -8
  216. package/ListItem/index.js.map +1 -1
  217. package/LoadingBox/index.cjs +2 -2
  218. package/LoadingBox/index.cjs.map +1 -1
  219. package/LoadingBox/index.d.ts +2 -2
  220. package/LoadingBox/index.js +2 -2
  221. package/LoadingBox/index.js.map +1 -1
  222. package/Menu/index.cjs +6 -21
  223. package/Menu/index.cjs.map +1 -1
  224. package/Menu/index.d.ts +6 -4
  225. package/Menu/index.js +6 -21
  226. package/Menu/index.js.map +1 -1
  227. package/Modal/index.cjs +5 -5
  228. package/Modal/index.cjs.map +1 -1
  229. package/Modal/index.js +5 -5
  230. package/Modal/index.js.map +1 -1
  231. package/Option/index.d.ts +2 -2
  232. package/PasswordInput/index.cjs +21 -0
  233. package/PasswordInput/index.cjs.map +1 -0
  234. package/PasswordInput/index.d.ts +11 -0
  235. package/PasswordInput/index.js +19 -0
  236. package/PasswordInput/index.js.map +1 -0
  237. package/Portal/index.d.ts +3 -3
  238. package/Radio/index.d.ts +2 -2
  239. package/RangeSlider/index.cjs +158 -0
  240. package/RangeSlider/index.cjs.map +1 -0
  241. package/RangeSlider/index.d.ts +24 -0
  242. package/RangeSlider/index.js +156 -0
  243. package/RangeSlider/index.js.map +1 -0
  244. package/Scrollbar/index.cjs +6 -6
  245. package/Scrollbar/index.cjs.map +1 -1
  246. package/Scrollbar/index.d.ts +3 -3
  247. package/Scrollbar/index.js +6 -6
  248. package/Scrollbar/index.js.map +1 -1
  249. package/Select/index.cjs +2 -2
  250. package/Select/index.cjs.map +1 -1
  251. package/Select/index.d.ts +5 -5
  252. package/Select/index.js +2 -2
  253. package/Select/index.js.map +1 -1
  254. package/Skeleton/index.cjs +7 -5
  255. package/Skeleton/index.cjs.map +1 -1
  256. package/Skeleton/index.js +7 -5
  257. package/Skeleton/index.js.map +1 -1
  258. package/Stack/index.d.ts +2 -2
  259. package/Switch/index.cjs +2 -2
  260. package/Switch/index.cjs.map +1 -1
  261. package/Switch/index.d.ts +3 -3
  262. package/Switch/index.js +2 -2
  263. package/Switch/index.js.map +1 -1
  264. package/Tab/index.cjs +23 -2
  265. package/Tab/index.cjs.map +1 -1
  266. package/Tab/index.d.ts +2 -2
  267. package/Tab/index.js +25 -4
  268. package/Tab/index.js.map +1 -1
  269. package/Table/index.cjs +9 -9
  270. package/Table/index.cjs.map +1 -1
  271. package/Table/index.d.ts +2 -2
  272. package/Table/index.js +9 -9
  273. package/Table/index.js.map +1 -1
  274. package/TableBody/index.d.ts +2 -2
  275. package/TableCell/index.cjs +1 -1
  276. package/TableCell/index.cjs.map +1 -1
  277. package/TableCell/index.d.ts +2 -2
  278. package/TableCell/index.js +1 -1
  279. package/TableCell/index.js.map +1 -1
  280. package/TableFooter/index.d.ts +2 -2
  281. package/TableHead/index.d.ts +2 -2
  282. package/TablePagination/index.cjs +2 -2
  283. package/TablePagination/index.cjs.map +1 -1
  284. package/TablePagination/index.d.ts +2 -2
  285. package/TablePagination/index.js +2 -2
  286. package/TablePagination/index.js.map +1 -1
  287. package/TableRow/index.d.ts +2 -2
  288. package/Tabs/context.cjs +11 -0
  289. package/Tabs/context.cjs.map +1 -0
  290. package/Tabs/context.js +8 -0
  291. package/Tabs/context.js.map +1 -0
  292. package/Tabs/index.cjs +83 -168
  293. package/Tabs/index.cjs.map +1 -1
  294. package/Tabs/index.d.ts +4 -22
  295. package/Tabs/index.js +86 -171
  296. package/Tabs/index.js.map +1 -1
  297. package/Tabs/types.d.ts +16 -0
  298. package/Text/index.cjs +1 -1
  299. package/Text/index.cjs.map +1 -1
  300. package/Text/index.d.ts +2 -2
  301. package/Text/index.js +1 -1
  302. package/Text/index.js.map +1 -1
  303. package/Toast/index.cjs +15 -16
  304. package/Toast/index.cjs.map +1 -1
  305. package/Toast/index.js +16 -17
  306. package/Toast/index.js.map +1 -1
  307. package/Tooltip/index.cjs +2 -2
  308. package/Tooltip/index.cjs.map +1 -1
  309. package/Tooltip/index.js +2 -2
  310. package/Tooltip/index.js.map +1 -1
  311. package/ViewBox/index.d.ts +2 -2
  312. package/index.cjs +126 -110
  313. package/index.cjs.map +1 -1
  314. package/index.d.ts +9 -1
  315. package/index.js +9 -1
  316. package/index.js.map +1 -1
  317. package/package.json +2 -2
  318. package/readme.md +1 -1
  319. package/useBlurCss/index.cjs +1 -2
  320. package/useBlurCss/index.cjs.map +1 -1
  321. package/useBlurCss/index.js +1 -2
  322. package/useBlurCss/index.js.map +1 -1
  323. package/useContextMenu/index.cjs +2 -2
  324. package/useContextMenu/index.cjs.map +1 -1
  325. package/useContextMenu/index.d.ts +1 -1
  326. package/useContextMenu/index.js +2 -2
  327. package/useContextMenu/index.js.map +1 -1
  328. package/Paper/index.cjs +0 -16
  329. package/Paper/index.cjs.map +0 -1
  330. package/Paper/index.d.ts +0 -8
  331. package/Paper/index.js +0 -14
  332. package/Paper/index.js.map +0 -1
package/Tabs/index.cjs CHANGED
@@ -5,196 +5,111 @@ var tslib = require('tslib');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
7
  var core = require('@xanui/core');
8
+ var context = require('./context.cjs');
8
9
 
9
- const getRect = (ele, parent) => {
10
- const _rect = {};
11
- const parentRect = parent.getBoundingClientRect();
12
- const childRect = ele.getBoundingClientRect();
13
- _rect.top = childRect.top - parentRect.top;
14
- _rect.right = childRect.right - parentRect.right;
15
- _rect.bottom = childRect.bottom - parentRect.bottom;
16
- _rect.left = childRect.left - parentRect.left;
17
- _rect.width = childRect.width;
18
- _rect.height = childRect.height;
19
- return _rect;
20
- };
21
10
  const Tabs = React.forwardRef((_a, ref) => {
22
11
  var _b, _c, _d;
23
12
  var { onChange, value, children } = _a, props = tslib.__rest(_a, ["onChange", "value", "children"]);
24
- let [_e] = core.useInterface("Tabs", props, {}), { verticle, color, variant, indicatorSize, disableTransition, slotProps } = _e, rest = tslib.__rest(_e, ["verticle", "color", "variant", "indicatorSize", "disableTransition", "slotProps"]);
13
+ let [_e] = core.useInterface("Tabs", props, {}), { color, variant, indicatorSize, disableTransition, slotProps } = _e, rest = tslib.__rest(_e, ["color", "variant", "indicatorSize", "disableTransition", "slotProps"]);
25
14
  const _p = {};
26
15
  if (variant)
27
16
  _p.variant = variant;
28
17
  if (color)
29
18
  _p.color = color;
30
- if (verticle)
31
- _p.verticle = verticle;
32
19
  if (disableTransition)
33
20
  _p.disableTransition = disableTransition;
34
21
  if (indicatorSize)
35
22
  _p.indicatorSize = indicatorSize;
36
23
  const p = core.useBreakpointProps(_p);
37
24
  variant = (_b = p.variant) !== null && _b !== void 0 ? _b : "end-line";
38
- color = (_c = p.color) !== null && _c !== void 0 ? _c : "brand";
39
- verticle = p.verticle;
25
+ color = (_c = p.color) !== null && _c !== void 0 ? _c : "primary";
40
26
  disableTransition = p.disableTransition;
41
27
  indicatorSize = (_d = p.indicatorSize) !== null && _d !== void 0 ? _d : 3;
42
- ref = ref || React.useRef(null);
43
- const containerRef = React.useRef(null);
44
- const [trans, setTrans] = React.useState();
45
- const { childs, selectedIndex } = React.useMemo(() => {
46
- let info = {
47
- childs: null,
48
- selectedIndex: 0
49
- };
50
- info.childs = React.Children.map(children, (child, idx) => {
51
- let selected = child.props.value === value;
52
- if (selected) {
53
- info.selectedIndex = idx;
54
- }
55
- let btnProps = {};
56
- if (variant === 'fill' && selected) {
57
- btnProps = {
58
- sx: {
59
- bgcolor: "transparent!importnat",
60
- color: "#FFFFFF!important"
61
- }
62
- };
63
- }
64
- else if (variant === 'soft' && selected) {
65
- btnProps = {
66
- sx: {
67
- bgcolor: "transparent!importnat",
68
- }
69
- };
70
- }
71
- // delete child.props.value
72
- return React.cloneElement(child, Object.assign(Object.assign(Object.assign({ corner: "square", value: undefined, onClick: () => {
73
- onChange && onChange(child.props.value);
74
- } }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.button), btnProps), { color: selected ? color : "default", variant: "text", classNames: [child.props.classNames, { "tab-selected": selected }] }));
75
- });
76
- return info;
77
- }, [children, onChange, value, variant, color, verticle]);
78
- React.useEffect(() => {
79
- let con = containerRef.current;
80
- const conChilds = con.children;
81
- if (conChilds && conChilds[selectedIndex]) {
82
- const selectedTab = con.querySelector(".tab-selected") || conChilds[0];
83
- const prevRect = getRect(selectedTab, con);
84
- const rect = getRect(conChilds[selectedIndex], con);
85
- let anim = () => ({});
86
- if (verticle) {
87
- let v = {
88
- from: {
89
- top: (prevRect === null || prevRect === void 0 ? void 0 : prevRect.top) || 0,
90
- height: (prevRect === null || prevRect === void 0 ? void 0 : prevRect.height) || 0,
91
- },
92
- to: {
93
- top: (rect === null || rect === void 0 ? void 0 : rect.top) || 0,
94
- height: (rect === null || rect === void 0 ? void 0 : rect.height) || 0,
95
- }
96
- };
97
- if (["fill", "soft", "outline"].includes(variant)) {
98
- v.from.width = prevRect === null || prevRect === void 0 ? void 0 : prevRect.width;
99
- v.to.width = rect === null || rect === void 0 ? void 0 : rect.width;
28
+ const indicatorRef = React.useRef(null);
29
+ const indicatorState = React.useRef({
30
+ left: 0,
31
+ width: 0
32
+ });
33
+ let indicatorProps = {};
34
+ switch (variant) {
35
+ case "outline":
36
+ indicatorProps = {
37
+ top: 0,
38
+ border: "1px solid",
39
+ borderColor: color,
40
+ bgcolor: "transparent"
41
+ };
42
+ break;
43
+ case "ghost":
44
+ indicatorProps = {
45
+ top: 0,
46
+ bgcolor: `${color}.ghost`
47
+ };
48
+ break;
49
+ case "text":
50
+ indicatorProps = {
51
+ display: "none"
52
+ };
53
+ break;
54
+ }
55
+ return (jsxRuntime.jsx(context.TabContext.Provider, { value: {
56
+ value,
57
+ variant,
58
+ color,
59
+ disableTransition,
60
+ indicatorSize,
61
+ onChange: (v, e) => {
62
+ var _a, _b;
63
+ onChange(v, e);
64
+ if (variant === 'text')
65
+ return;
66
+ const indicator = indicatorRef.current;
67
+ if (!indicator)
68
+ return;
69
+ const target = e.currentTarget;
70
+ switch (variant) {
71
+ case "start-line":
72
+ indicator.style.removeProperty("bottom");
73
+ indicator.style.top = `${target.offsetTop}px`;
74
+ indicator.style.height = `${indicatorSize}px`;
75
+ break;
76
+ case "end-line":
77
+ indicator.style.removeProperty("top");
78
+ indicator.style.bottom = `${target.offsetTop}px`;
79
+ indicator.style.height = `${indicatorSize}px`;
80
+ break;
81
+ case "fill":
82
+ case "outline":
83
+ case "ghost":
84
+ indicator.style.height = `${target.offsetHeight}px`;
85
+ indicator.style.top = `${target.offsetTop}px`;
86
+ break;
100
87
  }
101
- anim = () => v;
102
- }
103
- else {
104
- let v = {
88
+ core.animate({
105
89
  from: {
106
- left: (prevRect === null || prevRect === void 0 ? void 0 : prevRect.left) || 0,
107
- width: (prevRect === null || prevRect === void 0 ? void 0 : prevRect.width) || 0,
90
+ left: (_a = indicatorState.current.left) !== null && _a !== void 0 ? _a : 0,
91
+ width: (_b = indicatorState.current.width) !== null && _b !== void 0 ? _b : 0,
108
92
  },
109
93
  to: {
110
- left: (rect === null || rect === void 0 ? void 0 : rect.left) || 0,
111
- width: (rect === null || rect === void 0 ? void 0 : rect.width) || 0,
94
+ left: target.offsetLeft,
95
+ width: target.clientWidth,
112
96
  },
113
- };
114
- if (["fill", "soft", "outline"].includes(variant)) {
115
- v.from.height = (prevRect === null || prevRect === void 0 ? void 0 : prevRect.height) || 0;
116
- v.to.height = (rect === null || rect === void 0 ? void 0 : rect.height) || 0;
117
- }
118
- anim = () => v;
119
- }
120
- setTrans(() => anim);
121
- }
122
- // eslint-disable-next-line react-hooks/exhaustive-deps
123
- }, [selectedIndex, variant, color, verticle]);
124
- let indicatorProps = React.useMemo(() => {
125
- let _indicatorProps = {};
126
- switch (variant) {
127
- case "start-line":
128
- if (verticle) {
129
- _indicatorProps = {
130
- left: 0,
131
- width: indicatorSize
132
- };
133
- }
134
- else {
135
- _indicatorProps = {
136
- top: 0,
137
- height: indicatorSize
138
- };
139
- }
140
- break;
141
- case "end-line":
142
- if (verticle) {
143
- _indicatorProps = {
144
- right: 0,
145
- width: indicatorSize
146
- };
147
- }
148
- else {
149
- _indicatorProps = {
150
- bottom: 0,
151
- height: indicatorSize
152
- };
153
- }
154
- break;
155
- case "fill":
156
- _indicatorProps = {
157
- top: 0,
158
- bgcolor: color
159
- };
160
- break;
161
- case "outline":
162
- _indicatorProps = {
163
- top: 0,
164
- border: "1px solid",
165
- borderColor: color,
166
- bgcolor: "transparent"
167
- };
168
- break;
169
- case "soft":
170
- _indicatorProps = {
171
- top: 0,
172
- bgcolor: `${color}.soft.primary`
173
- };
174
- break;
175
- case "text":
176
- _indicatorProps = {
177
- display: "none"
178
- };
179
- break;
180
- }
181
- return _indicatorProps;
182
- }, [selectedIndex, variant, color, verticle]);
183
- return (jsxRuntime.jsxs(core.Tag, Object.assign({}, rest, { baseClass: 'tabs', ref: ref, sxr: {
184
- position: "relative",
185
- zIndex: 1,
186
- display: "inline-block"
187
- }, children: [jsxRuntime.jsx(core.Tag, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.content, { baseClass: 'tabs-content', sxr: {
188
- display: verticle ? "flex" : "inline-flex",
189
- flexDirection: verticle ? "column" : "row",
190
- }, ref: containerRef, children: childs })), jsxRuntime.jsx(core.Transition, { open: !!trans, variant: trans, duration: trans ? (disableTransition ? 0 : 250) : 0, easing: "smooth", children: jsxRuntime.jsx(core.Tag, Object.assign({ baseClass: 'tabs-indicator',
191
- // className={classname}
192
- sxr: {
193
- position: "absolute",
194
- zIndex: -1,
195
- cursor: "pointer",
196
- bgcolor: color
197
- } }, indicatorProps)) })] })));
97
+ duration: 180,
98
+ easing: (t) => 1 - Math.pow(1 - t, 3),
99
+ onUpdate: ({ left, width }) => {
100
+ indicatorState.current.left = left;
101
+ indicatorState.current.width = width;
102
+ indicator.style.left = `${left}px`;
103
+ indicator.style.width = `${width}px`;
104
+ },
105
+ });
106
+ },
107
+ }, children: jsxRuntime.jsxs(core.Tag, Object.assign({}, rest, { baseClass: 'tabs', sxr: {
108
+ position: "relative",
109
+ zIndex: 1,
110
+ display: "flex",
111
+ flexDirection: "row",
112
+ }, ref: ref, children: [children, jsxRuntime.jsx(core.Tag, { ref: indicatorRef, baseClass: 'tabs-indicator', sxr: Object.assign({ radius: 1, position: "absolute", zIndex: -1, bgcolor: color, height: 2 }, indicatorProps) })] })) }));
198
113
  });
199
114
 
200
115
  module.exports = Tabs;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/Tabs/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useEffect, ReactElement, useMemo, cloneElement, useState, Children, useRef } from 'react'\nimport { TabProps } from '../Tab'\nimport { Tag, TagProps, useBreakpointProps, UseColorTemplateColor, useInterface, useBreakpointPropsType, Transition } from '@xanui/core'\nimport { ButtonProps } from '../Button'\n\n\ntype ValueType = string | number\nexport type TabsProps = Omit<TagProps, 'onChange'> & {\n children: ReactElement<TabProps> | ReactElement<TabProps>[];\n value?: ValueType;\n onChange?: (value: ValueType) => void;\n variant?: useBreakpointPropsType<\"start-line\" | \"end-line\" | \"fill\" | \"outline\" | \"text\" | \"soft\">;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n verticle?: useBreakpointPropsType<boolean>;\n disableTransition?: useBreakpointPropsType<boolean>;\n indicatorSize?: useBreakpointPropsType<number>;\n\n slotProps?: {\n content?: Omit<TagProps, \"children\">;\n button?: Omit<ButtonProps, \"children\" | \"color\" | \"variant\" | \"classNames\">;\n }\n}\n\nconst getRect = (ele: HTMLElement, parent: HTMLElement) => {\n const _rect: any = {};\n const parentRect = parent.getBoundingClientRect();\n const childRect = ele.getBoundingClientRect();\n _rect.top = childRect.top - parentRect.top;\n _rect.right = childRect.right - parentRect.right;\n _rect.bottom = childRect.bottom - parentRect.bottom;\n _rect.left = childRect.left - parentRect.left;\n _rect.width = childRect.width;\n _rect.height = childRect.height;\n return _rect\n}\n\nconst Tabs = React.forwardRef(({ onChange, value, children, ...props }: TabsProps, ref: any) => {\n let [{ verticle, color, variant, indicatorSize, disableTransition, slotProps, ...rest }] = useInterface<any>(\"Tabs\", props, {})\n const _p: any = {}\n if (variant) _p.variant = variant\n if (color) _p.color = color\n if (verticle) _p.verticle = verticle\n if (disableTransition) _p.disableTransition = disableTransition\n if (indicatorSize) _p.indicatorSize = indicatorSize\n const p: any = useBreakpointProps(_p)\n\n variant = p.variant ?? \"end-line\"\n color = p.color ?? \"brand\"\n verticle = p.verticle\n disableTransition = p.disableTransition\n indicatorSize = p.indicatorSize ?? 3\n\n ref = ref || useRef(null)\n const containerRef: any = useRef(null)\n const [trans, setTrans] = useState<any>()\n\n const { childs, selectedIndex } = useMemo(() => {\n let info: any = {\n childs: null,\n selectedIndex: 0\n }\n info.childs = Children.map(children, (child: any, idx: number) => {\n let selected = child.props.value === value\n if (selected) {\n info.selectedIndex = idx\n }\n\n let btnProps: any = {}\n if (variant === 'fill' && selected) {\n btnProps = {\n sx: {\n bgcolor: \"transparent!importnat\",\n color: \"#FFFFFF!important\"\n }\n }\n } else if (variant === 'soft' && selected) {\n btnProps = {\n sx: {\n bgcolor: \"transparent!importnat\",\n }\n }\n }\n\n // delete child.props.value\n return cloneElement(child, {\n corner: \"square\",\n value: undefined,\n onClick: () => {\n onChange && onChange(child.props.value)\n },\n ...slotProps?.button,\n ...btnProps,\n color: selected ? color : \"default\",\n variant: \"text\",\n classNames: [child.props.classNames, { \"tab-selected\": selected }],\n })\n })\n return info\n }, [children, onChange, value, variant, color, verticle])\n\n useEffect(() => {\n let con = containerRef.current\n const conChilds = con.children\n if (conChilds && conChilds[selectedIndex]) {\n const selectedTab = con.querySelector(\".tab-selected\") || conChilds[0]\n const prevRect = getRect(selectedTab, con)\n const rect = getRect(conChilds[selectedIndex], con)\n\n let anim: any = () => ({})\n if (verticle) {\n let v: any = {\n from: {\n top: prevRect?.top || 0,\n height: prevRect?.height || 0,\n },\n to: {\n top: rect?.top || 0,\n height: rect?.height || 0,\n }\n }\n\n if ([\"fill\", \"soft\", \"outline\"].includes(variant)) {\n v.from.width = prevRect?.width\n v.to.width = rect?.width\n }\n anim = () => v\n } else {\n let v: any = {\n from: {\n left: prevRect?.left || 0,\n width: prevRect?.width || 0,\n },\n to: {\n left: rect?.left || 0,\n width: rect?.width || 0,\n },\n }\n\n if ([\"fill\", \"soft\", \"outline\"].includes(variant)) {\n v.from.height = prevRect?.height || 0\n v.to.height = rect?.height || 0\n }\n anim = () => v\n }\n setTrans(() => anim)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selectedIndex, variant, color, verticle])\n\n let indicatorProps: any = useMemo(() => {\n let _indicatorProps: any = {}\n switch (variant) {\n case \"start-line\":\n if (verticle) {\n _indicatorProps = {\n left: 0,\n width: indicatorSize\n }\n } else {\n _indicatorProps = {\n top: 0,\n height: indicatorSize\n }\n }\n break;\n case \"end-line\":\n if (verticle) {\n _indicatorProps = {\n right: 0,\n width: indicatorSize\n }\n } else {\n _indicatorProps = {\n bottom: 0,\n height: indicatorSize\n }\n }\n break;\n case \"fill\":\n _indicatorProps = {\n top: 0,\n bgcolor: color\n }\n break;\n case \"outline\":\n _indicatorProps = {\n top: 0,\n border: \"1px solid\",\n borderColor: color,\n bgcolor: \"transparent\"\n }\n break;\n case \"soft\":\n _indicatorProps = {\n top: 0,\n bgcolor: `${color}.soft.primary`\n }\n break;\n case \"text\":\n _indicatorProps = {\n display: \"none\"\n }\n break;\n }\n return _indicatorProps\n }, [selectedIndex, variant, color, verticle])\n\n return (\n <Tag\n {...rest}\n baseClass='tabs'\n ref={ref}\n sxr={{\n position: \"relative\",\n zIndex: 1,\n display: \"inline-block\"\n }}\n >\n <Tag\n {...slotProps?.content}\n baseClass='tabs-content'\n sxr={{\n display: verticle ? \"flex\" : \"inline-flex\",\n flexDirection: verticle ? \"column\" : \"row\",\n }}\n ref={containerRef}\n >\n {childs}\n </Tag>\n <Transition\n open={!!trans}\n variant={trans}\n duration={trans ? (disableTransition ? 0 : 250) : 0}\n easing=\"smooth\"\n >\n <Tag\n baseClass='tabs-indicator'\n // className={classname}\n sxr={{\n position: \"absolute\",\n zIndex: -1,\n cursor: \"pointer\",\n bgcolor: color\n }}\n {...indicatorProps}\n >\n </Tag>\n </Transition>\n </Tag>\n )\n})\n\nexport default Tabs"],"names":[],"mappings":";;;;;;;;AAwBA;;AAEI;AACA;;;;;AAKA;AACA;AACA;AACJ;AAEA;;;AACI;;AAEA;AAAa;AACb;AAAW;AACX;AAAc;AACd;AAAuB;AACvB;AAAmB;AACnB;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;;;AAII;AACI;AACA;;AAEJ;;;AAGQ;;;AAIJ;AACI;AACI;AACI;AACA;AACH;;;AAEF;AACH;AACI;AACI;AACH;;;;AAKT;;AAKI;AAOR;AACA;AACJ;;AAGI;AACA;AACA;AACI;;;;;AAMI;AACI;;;AAGC;AACD;;;AAGC;;AAGL;AACI;AACA;;AAEJ;;;AAEA;AACI;;;AAGC;AACD;;;AAGC;;AAGL;AACI;AACA;;AAEJ;;AAEJ;;;;AAKR;;;AAGQ;;AAEQ;AACI;AACA;;;;AAGJ;AACI;AACA;;;;AAIZ;;AAEQ;AACI;AACA;;;;AAGJ;AACI;AACA;;;;AAIZ;AACI;AACI;AACA;;;AAGR;AACI;AACI;AACA;AACA;AACA;;;AAGR;AACI;AACI;;;;AAIR;AACI;AACI;;;;AAIZ;;AAGJ;AAMY;AACA;AACA;AACH;;;;;AAsBO;AACI;;AAEA;AACA;AACH;AAOrB;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/Tabs/index.tsx"],"sourcesContent":["\"use client\";\nimport React, { useRef } from 'react'\nimport { animate, Tag, useBreakpointProps, useInterface } from '@xanui/core'\nimport { TabContext } from './context';\nimport { TabsProps } from './types';\n\nexport type { TabsProps }\n\nconst Tabs = React.forwardRef(({ onChange, value, children, ...props }: TabsProps, ref: any) => {\n let [{ color, variant, indicatorSize, disableTransition, slotProps, ...rest }] = useInterface<any>(\"Tabs\", props, {})\n const _p: any = {}\n if (variant) _p.variant = variant\n if (color) _p.color = color\n if (disableTransition) _p.disableTransition = disableTransition\n if (indicatorSize) _p.indicatorSize = indicatorSize\n const p: any = useBreakpointProps(_p)\n\n variant = p.variant ?? \"end-line\"\n color = p.color ?? \"primary\"\n disableTransition = p.disableTransition\n indicatorSize = p.indicatorSize ?? 3\n\n const indicatorRef = useRef<HTMLElement>(null)\n const indicatorState = useRef({\n left: 0,\n width: 0\n })\n\n\n let indicatorProps: any = {}\n switch (variant) {\n case \"outline\":\n indicatorProps = {\n top: 0,\n border: \"1px solid\",\n borderColor: color,\n bgcolor: \"transparent\"\n }\n break;\n case \"ghost\":\n indicatorProps = {\n top: 0,\n bgcolor: `${color}.ghost`\n }\n break;\n case \"text\":\n indicatorProps = {\n display: \"none\"\n }\n break;\n }\n\n\n return (\n <TabContext.Provider\n value={{\n value,\n variant,\n color,\n disableTransition,\n indicatorSize,\n onChange: (v, e) => {\n onChange!(v, e)\n\n if (variant === 'text') return\n const indicator = indicatorRef.current;\n if (!indicator) return;\n\n const target = e.currentTarget as HTMLElement;\n\n switch (variant) {\n case \"start-line\":\n indicator.style.removeProperty(\"bottom\")\n indicator.style.top = `${target.offsetTop}px`\n indicator.style.height = `${indicatorSize}px`\n break;\n case \"end-line\":\n indicator.style.removeProperty(\"top\")\n indicator.style.bottom = `${target.offsetTop}px`\n indicator.style.height = `${indicatorSize}px`\n break;\n case \"fill\":\n case \"outline\":\n case \"ghost\":\n indicator.style.height = `${target.offsetHeight}px`\n indicator.style.top = `${target.offsetTop}px`\n break;\n }\n\n animate({\n from: {\n left: indicatorState.current.left ?? 0,\n width: indicatorState.current.width ?? 0,\n },\n to: {\n left: target.offsetLeft,\n width: target.clientWidth,\n },\n duration: 180,\n easing: (t) => 1 - Math.pow(1 - t, 3),\n onUpdate: ({ left, width }) => {\n indicatorState.current.left = left;\n indicatorState.current.width = width;\n\n indicator.style.left = `${left}px`;\n indicator.style.width = `${width}px`;\n },\n });\n },\n }}\n >\n <Tag\n {...rest}\n baseClass='tabs'\n sxr={{\n position: \"relative\",\n zIndex: 1,\n display: \"flex\",\n flexDirection: \"row\",\n }}\n ref={ref}\n >\n {children}\n <Tag\n ref={indicatorRef}\n baseClass='tabs-indicator'\n sxr={{\n radius: 1,\n position: \"absolute\",\n zIndex: -1,\n bgcolor: color,\n height: 2,\n ...indicatorProps\n }}\n />\n </Tag>\n </TabContext.Provider>\n )\n})\n\nexport default Tabs"],"names":[],"mappings":";;;;;;;;;AAQA;;;;;AAGI;AAAa;AACb;AAAW;AACX;AAAuB;AACvB;AAAmB;AACnB;AAEA;AACA;AACA;AACA;AAEA;;AAEI;AACA;AACH;;;AAKG;AACI;AACI;AACA;AACA;AACA;;;AAGR;AACI;AACI;;;;AAIR;AACI;AACI;;;;AAMZ;;;;;;AAQY;;AACI;;;AAGA;AACA;;AAEA;;AAGI;AACI;;;;AAIJ;AACI;;;;AAIJ;AACA;AACA;;;;;AAMJ;AACI;;;AAGC;AACD;;;AAGC;AACD;AACA;;AAEI;AACA;;;;AAKP;;;AAQD;AACA;AACA;AACA;;AAoBpB;;"}
package/Tabs/index.d.ts CHANGED
@@ -1,24 +1,6 @@
1
- import React, { ReactElement } from 'react';
2
- import { TabProps } from '../Tab/index.js';
3
- import { TagProps, useBreakpointPropsType, UseColorTemplateColor } from '@xanui/core';
4
- import { ButtonProps } from '../Button/index.js';
1
+ import React__default from 'react';
2
+ import { TabsProps } from './types.js';
5
3
 
6
- type ValueType = string | number;
7
- type TabsProps = Omit<TagProps, 'onChange'> & {
8
- children: ReactElement<TabProps> | ReactElement<TabProps>[];
9
- value?: ValueType;
10
- onChange?: (value: ValueType) => void;
11
- variant?: useBreakpointPropsType<"start-line" | "end-line" | "fill" | "outline" | "text" | "soft">;
12
- color?: useBreakpointPropsType<UseColorTemplateColor>;
13
- verticle?: useBreakpointPropsType<boolean>;
14
- disableTransition?: useBreakpointPropsType<boolean>;
15
- indicatorSize?: useBreakpointPropsType<number>;
16
- slotProps?: {
17
- content?: Omit<TagProps, "children">;
18
- button?: Omit<ButtonProps, "children" | "color" | "variant" | "classNames">;
19
- };
20
- };
21
- declare const Tabs: React.ForwardRefExoticComponent<Omit<TabsProps, "ref"> & React.RefAttributes<unknown>>;
4
+ declare const Tabs: React__default.ForwardRefExoticComponent<Omit<TabsProps, "ref"> & React__default.RefAttributes<unknown>>;
22
5
 
23
- export { Tabs as default };
24
- export type { TabsProps };
6
+ export { TabsProps, Tabs as default };