index.js 11 KB

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