index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.prepareComponentToken = exports.default = void 0;
  7. var _cssinjs = require("@ant-design/cssinjs");
  8. var _style = require("../../style");
  9. var _fade = require("../../style/motion/fade");
  10. var _internal = require("../../theme/internal");
  11. var _util = _interopRequireDefault(require("../util"));
  12. var _keyframes = _interopRequireDefault(require("./keyframes"));
  13. // ============================== Group ==============================
  14. const floatButtonGroupStyle = token => {
  15. const {
  16. antCls,
  17. componentCls,
  18. floatButtonSize,
  19. margin,
  20. borderRadiusLG,
  21. borderRadiusSM,
  22. badgeOffset,
  23. floatButtonBodyPadding,
  24. zIndexPopupBase,
  25. calc
  26. } = token;
  27. const groupPrefixCls = `${componentCls}-group`;
  28. return {
  29. [groupPrefixCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  30. zIndex: zIndexPopupBase,
  31. display: 'flex',
  32. flexDirection: 'column',
  33. alignItems: 'center',
  34. justifyContent: 'center',
  35. border: 'none',
  36. position: 'fixed',
  37. height: 'auto',
  38. boxShadow: 'none',
  39. minWidth: floatButtonSize,
  40. minHeight: floatButtonSize,
  41. insetInlineEnd: token.floatButtonInsetInlineEnd,
  42. bottom: token.floatButtonInsetBlockEnd,
  43. borderRadius: borderRadiusLG,
  44. [`${groupPrefixCls}-wrap`]: {
  45. zIndex: -1,
  46. display: 'flex',
  47. justifyContent: 'center',
  48. alignItems: 'center',
  49. position: 'absolute'
  50. },
  51. [`&${groupPrefixCls}-rtl`]: {
  52. direction: 'rtl'
  53. },
  54. [componentCls]: {
  55. position: 'static'
  56. }
  57. }),
  58. [`${groupPrefixCls}-top > ${groupPrefixCls}-wrap`]: {
  59. flexDirection: 'column',
  60. top: 'auto',
  61. bottom: calc(floatButtonSize).add(margin).equal(),
  62. '&::after': {
  63. content: '""',
  64. position: 'absolute',
  65. width: '100%',
  66. height: margin,
  67. bottom: calc(margin).mul(-1).equal()
  68. }
  69. },
  70. [`${groupPrefixCls}-bottom > ${groupPrefixCls}-wrap`]: {
  71. flexDirection: 'column',
  72. top: calc(floatButtonSize).add(margin).equal(),
  73. bottom: 'auto',
  74. '&::after': {
  75. content: '""',
  76. position: 'absolute',
  77. width: '100%',
  78. height: margin,
  79. top: calc(margin).mul(-1).equal()
  80. }
  81. },
  82. [`${groupPrefixCls}-right > ${groupPrefixCls}-wrap`]: {
  83. flexDirection: 'row',
  84. left: {
  85. _skip_check_: true,
  86. value: calc(floatButtonSize).add(margin).equal()
  87. },
  88. right: {
  89. _skip_check_: true,
  90. value: 'auto'
  91. },
  92. '&::after': {
  93. content: '""',
  94. position: 'absolute',
  95. width: margin,
  96. height: '100%',
  97. left: {
  98. _skip_check_: true,
  99. value: calc(margin).mul(-1).equal()
  100. }
  101. }
  102. },
  103. [`${groupPrefixCls}-left > ${groupPrefixCls}-wrap`]: {
  104. flexDirection: 'row',
  105. left: {
  106. _skip_check_: true,
  107. value: 'auto'
  108. },
  109. right: {
  110. _skip_check_: true,
  111. value: calc(floatButtonSize).add(margin).equal()
  112. },
  113. '&::after': {
  114. content: '""',
  115. position: 'absolute',
  116. width: margin,
  117. height: '100%',
  118. right: {
  119. _skip_check_: true,
  120. value: calc(margin).mul(-1).equal()
  121. }
  122. }
  123. },
  124. [`${groupPrefixCls}-circle`]: {
  125. gap: margin,
  126. [`${groupPrefixCls}-wrap`]: {
  127. gap: margin
  128. }
  129. },
  130. [`${groupPrefixCls}-square`]: {
  131. [`${componentCls}-square`]: {
  132. padding: 0,
  133. borderRadius: 0,
  134. [`&${groupPrefixCls}-trigger`]: {
  135. borderRadius: borderRadiusLG
  136. },
  137. '&:first-child': {
  138. borderStartStartRadius: borderRadiusLG,
  139. borderStartEndRadius: borderRadiusLG
  140. },
  141. '&:last-child': {
  142. borderEndStartRadius: borderRadiusLG,
  143. borderEndEndRadius: borderRadiusLG
  144. },
  145. '&:not(:last-child)': {
  146. borderBottom: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorSplit}`
  147. },
  148. [`${antCls}-badge`]: {
  149. [`${antCls}-badge-count`]: {
  150. top: calc(calc(floatButtonBodyPadding).add(badgeOffset)).mul(-1).equal(),
  151. insetInlineEnd: calc(calc(floatButtonBodyPadding).add(badgeOffset)).mul(-1).equal()
  152. }
  153. }
  154. },
  155. [`${groupPrefixCls}-wrap`]: {
  156. borderRadius: borderRadiusLG,
  157. boxShadow: token.boxShadowSecondary,
  158. [`${componentCls}-square`]: {
  159. boxShadow: 'none',
  160. borderRadius: 0,
  161. padding: floatButtonBodyPadding,
  162. [`${componentCls}-body`]: {
  163. width: token.floatButtonBodySize,
  164. height: token.floatButtonBodySize,
  165. borderRadius: borderRadiusSM
  166. }
  167. }
  168. }
  169. },
  170. [`${groupPrefixCls}-top > ${groupPrefixCls}-wrap, ${groupPrefixCls}-bottom > ${groupPrefixCls}-wrap`]: {
  171. [`> ${componentCls}-square`]: {
  172. '&:first-child': {
  173. borderStartStartRadius: borderRadiusLG,
  174. borderStartEndRadius: borderRadiusLG
  175. },
  176. '&:last-child': {
  177. borderEndStartRadius: borderRadiusLG,
  178. borderEndEndRadius: borderRadiusLG
  179. },
  180. '&:not(:last-child)': {
  181. borderBottom: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorSplit}`
  182. }
  183. }
  184. },
  185. [`${groupPrefixCls}-left > ${groupPrefixCls}-wrap, ${groupPrefixCls}-right > ${groupPrefixCls}-wrap`]: {
  186. [`> ${componentCls}-square`]: {
  187. '&:first-child': {
  188. borderStartStartRadius: borderRadiusLG,
  189. borderEndStartRadius: borderRadiusLG
  190. },
  191. '&:last-child': {
  192. borderStartEndRadius: borderRadiusLG,
  193. borderEndEndRadius: borderRadiusLG
  194. },
  195. '&:not(:last-child)': {
  196. borderBottom: 'none',
  197. borderInlineEnd: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorSplit}`
  198. }
  199. }
  200. },
  201. [`${groupPrefixCls}-circle-shadow`]: {
  202. boxShadow: 'none'
  203. },
  204. [`${groupPrefixCls}-square-shadow`]: {
  205. boxShadow: token.boxShadowSecondary,
  206. [`${componentCls}-square`]: {
  207. boxShadow: 'none',
  208. padding: floatButtonBodyPadding,
  209. [`${componentCls}-body`]: {
  210. width: token.floatButtonBodySize,
  211. height: token.floatButtonBodySize,
  212. borderRadius: borderRadiusSM
  213. }
  214. }
  215. }
  216. };
  217. };
  218. // ============================== Shared ==============================
  219. const sharedFloatButtonStyle = token => {
  220. const {
  221. antCls,
  222. componentCls,
  223. floatButtonBodyPadding,
  224. floatButtonIconSize,
  225. floatButtonSize,
  226. borderRadiusLG,
  227. badgeOffset,
  228. dotOffsetInSquare,
  229. dotOffsetInCircle,
  230. zIndexPopupBase,
  231. calc
  232. } = token;
  233. return {
  234. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  235. border: 'none',
  236. position: 'fixed',
  237. cursor: 'pointer',
  238. zIndex: zIndexPopupBase,
  239. // Do not remove the 'display: block' here.
  240. // Deleting it will cause marginBottom to become ineffective.
  241. // Ref: https://github.com/ant-design/ant-design/issues/44700
  242. display: 'block',
  243. width: floatButtonSize,
  244. height: floatButtonSize,
  245. insetInlineEnd: token.floatButtonInsetInlineEnd,
  246. bottom: token.floatButtonInsetBlockEnd,
  247. boxShadow: token.boxShadowSecondary,
  248. // Pure Panel
  249. '&-pure': {
  250. position: 'relative',
  251. inset: 'auto'
  252. },
  253. '&:empty': {
  254. display: 'none'
  255. },
  256. [`${antCls}-badge`]: {
  257. width: '100%',
  258. height: '100%',
  259. [`${antCls}-badge-count`]: {
  260. transform: 'translate(0, 0)',
  261. transformOrigin: 'center',
  262. top: calc(badgeOffset).mul(-1).equal(),
  263. insetInlineEnd: calc(badgeOffset).mul(-1).equal()
  264. }
  265. },
  266. [`${componentCls}-body`]: {
  267. width: '100%',
  268. height: '100%',
  269. display: 'flex',
  270. justifyContent: 'center',
  271. alignItems: 'center',
  272. transition: `all ${token.motionDurationMid}`,
  273. [`${componentCls}-content`]: {
  274. overflow: 'hidden',
  275. textAlign: 'center',
  276. minHeight: floatButtonSize,
  277. display: 'flex',
  278. flexDirection: 'column',
  279. justifyContent: 'center',
  280. alignItems: 'center',
  281. padding: `${(0, _cssinjs.unit)(calc(floatButtonBodyPadding).div(2).equal())} ${(0, _cssinjs.unit)(floatButtonBodyPadding)}`,
  282. [`${componentCls}-icon`]: {
  283. textAlign: 'center',
  284. margin: 'auto',
  285. width: floatButtonIconSize,
  286. fontSize: floatButtonIconSize,
  287. lineHeight: 1
  288. }
  289. }
  290. }
  291. }),
  292. [`${componentCls}-rtl`]: {
  293. direction: 'rtl'
  294. },
  295. [`${componentCls}-circle`]: {
  296. height: floatButtonSize,
  297. borderRadius: '50%',
  298. [`${antCls}-badge`]: {
  299. [`${antCls}-badge-dot`]: {
  300. top: dotOffsetInCircle,
  301. insetInlineEnd: dotOffsetInCircle
  302. }
  303. },
  304. [`${componentCls}-body`]: {
  305. borderRadius: '50%'
  306. }
  307. },
  308. [`${componentCls}-square`]: {
  309. height: 'auto',
  310. minHeight: floatButtonSize,
  311. borderRadius: borderRadiusLG,
  312. [`${antCls}-badge`]: {
  313. [`${antCls}-badge-dot`]: {
  314. top: dotOffsetInSquare,
  315. insetInlineEnd: dotOffsetInSquare
  316. }
  317. },
  318. [`${componentCls}-body`]: {
  319. height: 'auto',
  320. borderRadius: borderRadiusLG
  321. }
  322. },
  323. [`${componentCls}-default`]: {
  324. backgroundColor: token.floatButtonBackgroundColor,
  325. transition: `background-color ${token.motionDurationMid}`,
  326. [`${componentCls}-body`]: {
  327. backgroundColor: token.floatButtonBackgroundColor,
  328. transition: `background-color ${token.motionDurationMid}`,
  329. '&:hover': {
  330. backgroundColor: token.colorFillContent
  331. },
  332. [`${componentCls}-content`]: {
  333. [`${componentCls}-icon`]: {
  334. color: token.colorText
  335. },
  336. [`${componentCls}-description`]: {
  337. display: 'flex',
  338. alignItems: 'center',
  339. lineHeight: (0, _cssinjs.unit)(token.fontSizeLG),
  340. color: token.colorText,
  341. fontSize: token.fontSizeSM
  342. }
  343. }
  344. }
  345. },
  346. [`${componentCls}-primary`]: {
  347. backgroundColor: token.colorPrimary,
  348. [`${componentCls}-body`]: {
  349. backgroundColor: token.colorPrimary,
  350. transition: `background-color ${token.motionDurationMid}`,
  351. '&:hover': {
  352. backgroundColor: token.colorPrimaryHover
  353. },
  354. [`${componentCls}-content`]: {
  355. [`${componentCls}-icon`]: {
  356. color: token.colorTextLightSolid
  357. },
  358. [`${componentCls}-description`]: {
  359. display: 'flex',
  360. alignItems: 'center',
  361. lineHeight: (0, _cssinjs.unit)(token.fontSizeLG),
  362. color: token.colorTextLightSolid,
  363. fontSize: token.fontSizeSM
  364. }
  365. }
  366. }
  367. }
  368. };
  369. };
  370. // ============================== Export ==============================
  371. const prepareComponentToken = token => ({
  372. dotOffsetInCircle: (0, _util.default)(token.controlHeightLG / 2),
  373. dotOffsetInSquare: (0, _util.default)(token.borderRadiusLG)
  374. });
  375. exports.prepareComponentToken = prepareComponentToken;
  376. var _default = exports.default = (0, _internal.genStyleHooks)('FloatButton', token => {
  377. const {
  378. colorTextLightSolid,
  379. colorBgElevated,
  380. controlHeightLG,
  381. marginXXL,
  382. marginLG,
  383. fontSize,
  384. fontSizeIcon,
  385. controlItemBgHover,
  386. paddingXXS,
  387. calc
  388. } = token;
  389. const floatButtonToken = (0, _internal.mergeToken)(token, {
  390. floatButtonBackgroundColor: colorBgElevated,
  391. floatButtonColor: colorTextLightSolid,
  392. floatButtonHoverBackgroundColor: controlItemBgHover,
  393. floatButtonFontSize: fontSize,
  394. floatButtonIconSize: calc(fontSizeIcon).mul(1.5).equal(),
  395. floatButtonSize: controlHeightLG,
  396. floatButtonInsetBlockEnd: marginXXL,
  397. floatButtonInsetInlineEnd: marginLG,
  398. floatButtonBodySize: calc(controlHeightLG).sub(calc(paddingXXS).mul(2)).equal(),
  399. // 这里的 paddingXXS 是简写,完整逻辑是 (controlHeightLG - (controlHeightLG - paddingXXS * 2)) / 2,
  400. floatButtonBodyPadding: paddingXXS,
  401. badgeOffset: calc(paddingXXS).mul(1.5).equal()
  402. });
  403. return [floatButtonGroupStyle(floatButtonToken), sharedFloatButtonStyle(floatButtonToken), (0, _fade.initFadeMotion)(token), (0, _keyframes.default)(floatButtonToken)];
  404. }, prepareComponentToken);