index.js 10 KB

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