index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = exports.DotDuration = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. const DotDuration = exports.DotDuration = '--dot-duration';
  10. const genCarouselStyle = token => {
  11. const {
  12. componentCls,
  13. antCls
  14. } = token;
  15. return {
  16. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  17. '.slick-slider': {
  18. position: 'relative',
  19. display: 'block',
  20. boxSizing: 'border-box',
  21. touchAction: 'pan-y',
  22. WebkitTouchCallout: 'none',
  23. WebkitTapHighlightColor: 'transparent',
  24. '.slick-track, .slick-list': {
  25. transform: 'translate3d(0, 0, 0)',
  26. touchAction: 'pan-y'
  27. }
  28. },
  29. '.slick-list': {
  30. position: 'relative',
  31. display: 'block',
  32. margin: 0,
  33. padding: 0,
  34. overflow: 'hidden',
  35. '&:focus': {
  36. outline: 'none'
  37. },
  38. '&.dragging': {
  39. cursor: 'pointer'
  40. },
  41. '.slick-slide': {
  42. pointerEvents: 'none',
  43. // https://github.com/ant-design/ant-design/issues/23294
  44. [`input${antCls}-radio-input, input${antCls}-checkbox-input`]: {
  45. visibility: 'hidden'
  46. },
  47. '&.slick-active': {
  48. pointerEvents: 'auto',
  49. [`input${antCls}-radio-input, input${antCls}-checkbox-input`]: {
  50. visibility: 'visible'
  51. }
  52. },
  53. // fix Carousel content height not match parent node
  54. // when children is empty node
  55. // https://github.com/ant-design/ant-design/issues/25878
  56. '> div > div': {
  57. verticalAlign: 'bottom'
  58. }
  59. }
  60. },
  61. '.slick-track': {
  62. position: 'relative',
  63. top: 0,
  64. insetInlineStart: 0,
  65. display: 'block',
  66. '&::before, &::after': {
  67. display: 'table',
  68. content: '""'
  69. },
  70. '&::after': {
  71. clear: 'both'
  72. }
  73. },
  74. '.slick-slide': {
  75. display: 'none',
  76. float: 'left',
  77. height: '100%',
  78. minHeight: 1,
  79. img: {
  80. display: 'block'
  81. },
  82. '&.dragging img': {
  83. pointerEvents: 'none'
  84. }
  85. },
  86. '.slick-initialized .slick-slide': {
  87. display: 'block'
  88. },
  89. '.slick-vertical .slick-slide': {
  90. display: 'block',
  91. height: 'auto'
  92. }
  93. })
  94. };
  95. };
  96. const genArrowsStyle = token => {
  97. const {
  98. componentCls,
  99. motionDurationSlow,
  100. arrowSize,
  101. arrowOffset
  102. } = token;
  103. const arrowLength = token.calc(arrowSize).div(Math.SQRT2).equal();
  104. return {
  105. [componentCls]: {
  106. // Arrows
  107. '.slick-prev, .slick-next': {
  108. position: 'absolute',
  109. top: '50%',
  110. width: arrowSize,
  111. height: arrowSize,
  112. transform: 'translateY(-50%)',
  113. color: '#fff',
  114. opacity: 0.4,
  115. background: 'transparent',
  116. padding: 0,
  117. lineHeight: 0,
  118. border: 0,
  119. outline: 'none',
  120. cursor: 'pointer',
  121. zIndex: 1,
  122. transition: `opacity ${motionDurationSlow}`,
  123. '&:hover, &:focus': {
  124. opacity: 1
  125. },
  126. '&.slick-disabled': {
  127. pointerEvents: 'none',
  128. opacity: 0
  129. },
  130. '&::after': {
  131. boxSizing: 'border-box',
  132. position: 'absolute',
  133. top: token.calc(arrowSize).sub(arrowLength).div(2).equal(),
  134. insetInlineStart: token.calc(arrowSize).sub(arrowLength).div(2).equal(),
  135. display: 'inline-block',
  136. width: arrowLength,
  137. height: arrowLength,
  138. border: `0 solid currentcolor`,
  139. borderInlineStartWidth: 2,
  140. borderBlockStartWidth: 2,
  141. borderRadius: 1,
  142. content: '""'
  143. }
  144. },
  145. '.slick-prev': {
  146. insetInlineStart: arrowOffset,
  147. '&::after': {
  148. transform: 'rotate(-45deg)'
  149. }
  150. },
  151. '.slick-next': {
  152. insetInlineEnd: arrowOffset,
  153. '&::after': {
  154. transform: 'rotate(135deg)'
  155. }
  156. }
  157. }
  158. };
  159. };
  160. const genDotsStyle = token => {
  161. const {
  162. componentCls,
  163. dotOffset,
  164. dotWidth,
  165. dotHeight,
  166. dotGap,
  167. colorBgContainer,
  168. motionDurationSlow
  169. } = token;
  170. return {
  171. [componentCls]: {
  172. '.slick-dots': {
  173. position: 'absolute',
  174. insetInlineEnd: 0,
  175. bottom: 0,
  176. insetInlineStart: 0,
  177. zIndex: 15,
  178. display: 'flex !important',
  179. justifyContent: 'center',
  180. paddingInlineStart: 0,
  181. margin: 0,
  182. listStyle: 'none',
  183. '&-bottom': {
  184. bottom: dotOffset
  185. },
  186. '&-top': {
  187. top: dotOffset,
  188. bottom: 'auto'
  189. },
  190. li: {
  191. position: 'relative',
  192. display: 'inline-block',
  193. flex: '0 1 auto',
  194. boxSizing: 'content-box',
  195. width: dotWidth,
  196. height: dotHeight,
  197. marginInline: dotGap,
  198. padding: 0,
  199. textAlign: 'center',
  200. textIndent: -999,
  201. verticalAlign: 'top',
  202. transition: `all ${motionDurationSlow}`,
  203. borderRadius: dotHeight,
  204. overflow: 'hidden',
  205. '&::after': {
  206. display: 'block',
  207. position: 'absolute',
  208. top: 0,
  209. insetInlineStart: 0,
  210. width: '100%',
  211. height: dotHeight,
  212. content: '""',
  213. background: 'transparent',
  214. borderRadius: dotHeight,
  215. opacity: 1,
  216. outline: 'none',
  217. cursor: 'pointer',
  218. overflow: 'hidden',
  219. transform: 'translate3d(-100%, 0, 0)'
  220. },
  221. button: {
  222. position: 'relative',
  223. display: 'block',
  224. width: '100%',
  225. height: dotHeight,
  226. padding: 0,
  227. color: 'transparent',
  228. fontSize: 0,
  229. background: colorBgContainer,
  230. border: 0,
  231. borderRadius: dotHeight,
  232. outline: 'none',
  233. cursor: 'pointer',
  234. opacity: 0.2,
  235. transition: `all ${motionDurationSlow}`,
  236. overflow: 'hidden',
  237. '&:hover': {
  238. opacity: 0.75
  239. },
  240. '&::after': {
  241. position: 'absolute',
  242. inset: token.calc(dotGap).mul(-1).equal(),
  243. content: '""'
  244. }
  245. },
  246. '&.slick-active': {
  247. width: token.dotActiveWidth,
  248. position: 'relative',
  249. '&:hover': {
  250. opacity: 1
  251. },
  252. '&::after': {
  253. background: colorBgContainer,
  254. transform: 'translate3d(0, 0, 0)',
  255. transition: `transform var(${DotDuration}) ease-out`
  256. }
  257. }
  258. }
  259. }
  260. }
  261. };
  262. };
  263. const genCarouselVerticalStyle = token => {
  264. const {
  265. componentCls,
  266. dotOffset,
  267. arrowOffset,
  268. marginXXS
  269. } = token;
  270. const reverseSizeOfDot = {
  271. width: token.dotHeight,
  272. height: token.dotWidth
  273. };
  274. return {
  275. [`${componentCls}-vertical`]: {
  276. '.slick-prev, .slick-next': {
  277. insetInlineStart: '50%',
  278. marginBlockStart: 'unset',
  279. transform: 'translateX(-50%)'
  280. },
  281. '.slick-prev': {
  282. insetBlockStart: arrowOffset,
  283. insetInlineStart: '50%',
  284. '&::after': {
  285. transform: 'rotate(45deg)'
  286. }
  287. },
  288. '.slick-next': {
  289. insetBlockStart: 'auto',
  290. insetBlockEnd: arrowOffset,
  291. '&::after': {
  292. transform: 'rotate(-135deg)'
  293. }
  294. },
  295. '.slick-dots': {
  296. top: '50%',
  297. bottom: 'auto',
  298. flexDirection: 'column',
  299. width: token.dotHeight,
  300. height: 'auto',
  301. margin: 0,
  302. transform: 'translateY(-50%)',
  303. '&-left': {
  304. insetInlineEnd: 'auto',
  305. insetInlineStart: dotOffset
  306. },
  307. '&-right': {
  308. insetInlineEnd: dotOffset,
  309. insetInlineStart: 'auto'
  310. },
  311. li: Object.assign(Object.assign({}, reverseSizeOfDot), {
  312. margin: `${(0, _cssinjs.unit)(marginXXS)} 0`,
  313. verticalAlign: 'baseline',
  314. button: reverseSizeOfDot,
  315. '&::after': Object.assign(Object.assign({}, reverseSizeOfDot), {
  316. height: 0
  317. }),
  318. '&.slick-active': Object.assign(Object.assign({}, reverseSizeOfDot), {
  319. button: reverseSizeOfDot,
  320. '&::after': Object.assign(Object.assign({}, reverseSizeOfDot), {
  321. transition: `height var(${DotDuration}) ease-out`
  322. })
  323. })
  324. })
  325. }
  326. }
  327. };
  328. };
  329. const genCarouselRtlStyle = token => {
  330. const {
  331. componentCls
  332. } = token;
  333. return [{
  334. [`${componentCls}-rtl`]: {
  335. direction: 'rtl'
  336. }
  337. }, {
  338. [`${componentCls}-vertical`]: {
  339. '.slick-dots': {
  340. [`${componentCls}-rtl&`]: {
  341. flexDirection: 'column'
  342. }
  343. }
  344. }
  345. }];
  346. };
  347. const prepareComponentToken = token => {
  348. const dotActiveWidth = 24;
  349. return {
  350. arrowSize: 16,
  351. arrowOffset: token.marginXS,
  352. dotWidth: 16,
  353. dotHeight: 3,
  354. dotGap: token.marginXXS,
  355. dotOffset: 12,
  356. dotWidthActive: dotActiveWidth,
  357. dotActiveWidth
  358. };
  359. };
  360. // ============================== Export ==============================
  361. exports.prepareComponentToken = prepareComponentToken;
  362. var _default = exports.default = (0, _internal.genStyleHooks)('Carousel', token => [genCarouselStyle(token), genArrowsStyle(token), genDotsStyle(token), genCarouselVerticalStyle(token), genCarouselRtlStyle(token)], prepareComponentToken, {
  363. deprecatedTokens: [['dotWidthActive', 'dotActiveWidth']]
  364. });