index.js 9.4 KB

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