index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 _internal = require("../../theme/internal");
  9. var _group = _interopRequireDefault(require("./group"));
  10. var _style = require("../../style");
  11. var _compactItem = require("../../style/compact-item");
  12. var _compactItemVertical = require("../../style/compact-item-vertical");
  13. // ============================== Shared ==============================
  14. const genSharedButtonStyle = token => {
  15. const {
  16. componentCls,
  17. iconCls
  18. } = token;
  19. return {
  20. [componentCls]: {
  21. outline: 'none',
  22. position: 'relative',
  23. display: 'inline-block',
  24. fontWeight: 400,
  25. whiteSpace: 'nowrap',
  26. textAlign: 'center',
  27. backgroundImage: 'none',
  28. backgroundColor: 'transparent',
  29. border: `${token.lineWidth}px ${token.lineType} transparent`,
  30. cursor: 'pointer',
  31. transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
  32. userSelect: 'none',
  33. touchAction: 'manipulation',
  34. lineHeight: token.lineHeight,
  35. color: token.colorText,
  36. '> span': {
  37. display: 'inline-block'
  38. },
  39. // Leave a space between icon and text.
  40. [`> ${iconCls} + span, > span + ${iconCls}`]: {
  41. marginInlineStart: token.marginXS
  42. },
  43. '> a': {
  44. color: 'currentColor'
  45. },
  46. '&:not(:disabled)': (0, _extends2.default)({}, (0, _style.genFocusStyle)(token)),
  47. // make `btn-icon-only` not too narrow
  48. [`&-icon-only${componentCls}-compact-item`]: {
  49. flex: 'none'
  50. },
  51. // Special styles for Primary Button
  52. [`&-compact-item${componentCls}-primary`]: {
  53. [`&:not([disabled]) + ${componentCls}-compact-item${componentCls}-primary:not([disabled])`]: {
  54. position: 'relative',
  55. '&:before': {
  56. position: 'absolute',
  57. top: -token.lineWidth,
  58. insetInlineStart: -token.lineWidth,
  59. display: 'inline-block',
  60. width: token.lineWidth,
  61. height: `calc(100% + ${token.lineWidth * 2}px)`,
  62. backgroundColor: token.colorPrimaryHover,
  63. content: '""'
  64. }
  65. }
  66. },
  67. // Special styles for Primary Button
  68. '&-compact-vertical-item': {
  69. [`&${componentCls}-primary`]: {
  70. [`&:not([disabled]) + ${componentCls}-compact-vertical-item${componentCls}-primary:not([disabled])`]: {
  71. position: 'relative',
  72. '&:before': {
  73. position: 'absolute',
  74. top: -token.lineWidth,
  75. insetInlineStart: -token.lineWidth,
  76. display: 'inline-block',
  77. width: `calc(100% + ${token.lineWidth * 2}px)`,
  78. height: token.lineWidth,
  79. backgroundColor: token.colorPrimaryHover,
  80. content: '""'
  81. }
  82. }
  83. }
  84. }
  85. }
  86. };
  87. };
  88. const genHoverActiveButtonStyle = (hoverStyle, activeStyle) => ({
  89. '&:not(:disabled)': {
  90. '&:hover': hoverStyle,
  91. '&:active': activeStyle
  92. }
  93. });
  94. // ============================== Shape ===============================
  95. const genCircleButtonStyle = token => ({
  96. minWidth: token.controlHeight,
  97. paddingInlineStart: 0,
  98. paddingInlineEnd: 0,
  99. borderRadius: '50%'
  100. });
  101. const genRoundButtonStyle = token => ({
  102. borderRadius: token.controlHeight,
  103. paddingInlineStart: token.controlHeight / 2,
  104. paddingInlineEnd: token.controlHeight / 2
  105. });
  106. // =============================== Type ===============================
  107. const genDisabledStyle = token => ({
  108. cursor: 'not-allowed',
  109. borderColor: token.colorBorder,
  110. color: token.colorTextDisabled,
  111. backgroundColor: token.colorBgContainerDisabled,
  112. boxShadow: 'none'
  113. });
  114. const genGhostButtonStyle = (btnCls, textColor, borderColor, textColorDisabled, borderColorDisabled, hoverStyle, activeStyle) => ({
  115. [`&${btnCls}-background-ghost`]: (0, _extends2.default)((0, _extends2.default)({
  116. color: textColor || undefined,
  117. backgroundColor: 'transparent',
  118. borderColor: borderColor || undefined,
  119. boxShadow: 'none'
  120. }, genHoverActiveButtonStyle((0, _extends2.default)({
  121. backgroundColor: 'transparent'
  122. }, hoverStyle), (0, _extends2.default)({
  123. backgroundColor: 'transparent'
  124. }, activeStyle))), {
  125. '&:disabled': {
  126. cursor: 'not-allowed',
  127. color: textColorDisabled || undefined,
  128. borderColor: borderColorDisabled || undefined
  129. }
  130. })
  131. });
  132. const genSolidDisabledButtonStyle = token => ({
  133. '&:disabled': (0, _extends2.default)({}, genDisabledStyle(token))
  134. });
  135. const genSolidButtonStyle = token => (0, _extends2.default)({}, genSolidDisabledButtonStyle(token));
  136. const genPureDisabledButtonStyle = token => ({
  137. '&:disabled': {
  138. cursor: 'not-allowed',
  139. color: token.colorTextDisabled
  140. }
  141. });
  142. // Type: Default
  143. const genDefaultButtonStyle = token => (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, genSolidButtonStyle(token)), {
  144. backgroundColor: token.colorBgContainer,
  145. borderColor: token.colorBorder,
  146. boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlTmpOutline}`
  147. }), genHoverActiveButtonStyle({
  148. color: token.colorPrimaryHover,
  149. borderColor: token.colorPrimaryHover
  150. }, {
  151. color: token.colorPrimaryActive,
  152. borderColor: token.colorPrimaryActive
  153. })), genGhostButtonStyle(token.componentCls, token.colorBgContainer, token.colorBgContainer, token.colorTextDisabled, token.colorBorder)), {
  154. [`&${token.componentCls}-dangerous`]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({
  155. color: token.colorError,
  156. borderColor: token.colorError
  157. }, genHoverActiveButtonStyle({
  158. color: token.colorErrorHover,
  159. borderColor: token.colorErrorBorderHover
  160. }, {
  161. color: token.colorErrorActive,
  162. borderColor: token.colorErrorActive
  163. })), genGhostButtonStyle(token.componentCls, token.colorError, token.colorError, token.colorTextDisabled, token.colorBorder)), genSolidDisabledButtonStyle(token))
  164. });
  165. // Type: Primary
  166. const genPrimaryButtonStyle = token => (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, genSolidButtonStyle(token)), {
  167. color: token.colorTextLightSolid,
  168. backgroundColor: token.colorPrimary,
  169. boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlOutline}`
  170. }), genHoverActiveButtonStyle({
  171. color: token.colorTextLightSolid,
  172. backgroundColor: token.colorPrimaryHover
  173. }, {
  174. color: token.colorTextLightSolid,
  175. backgroundColor: token.colorPrimaryActive
  176. })), genGhostButtonStyle(token.componentCls, token.colorPrimary, token.colorPrimary, token.colorTextDisabled, token.colorBorder, {
  177. color: token.colorPrimaryHover,
  178. borderColor: token.colorPrimaryHover
  179. }, {
  180. color: token.colorPrimaryActive,
  181. borderColor: token.colorPrimaryActive
  182. })), {
  183. [`&${token.componentCls}-dangerous`]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({
  184. backgroundColor: token.colorError,
  185. boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.colorErrorOutline}`
  186. }, genHoverActiveButtonStyle({
  187. backgroundColor: token.colorErrorHover
  188. }, {
  189. backgroundColor: token.colorErrorActive
  190. })), genGhostButtonStyle(token.componentCls, token.colorError, token.colorError, token.colorTextDisabled, token.colorBorder, {
  191. color: token.colorErrorHover,
  192. borderColor: token.colorErrorHover
  193. }, {
  194. color: token.colorErrorActive,
  195. borderColor: token.colorErrorActive
  196. })), genSolidDisabledButtonStyle(token))
  197. });
  198. // Type: Dashed
  199. const genDashedButtonStyle = token => (0, _extends2.default)((0, _extends2.default)({}, genDefaultButtonStyle(token)), {
  200. borderStyle: 'dashed'
  201. });
  202. // Type: Link
  203. const genLinkButtonStyle = token => (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({
  204. color: token.colorLink
  205. }, genHoverActiveButtonStyle({
  206. color: token.colorLinkHover
  207. }, {
  208. color: token.colorLinkActive
  209. })), genPureDisabledButtonStyle(token)), {
  210. [`&${token.componentCls}-dangerous`]: (0, _extends2.default)((0, _extends2.default)({
  211. color: token.colorError
  212. }, genHoverActiveButtonStyle({
  213. color: token.colorErrorHover
  214. }, {
  215. color: token.colorErrorActive
  216. })), genPureDisabledButtonStyle(token))
  217. });
  218. // Type: Text
  219. const genTextButtonStyle = token => (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, genHoverActiveButtonStyle({
  220. color: token.colorText,
  221. backgroundColor: token.colorBgTextHover
  222. }, {
  223. color: token.colorText,
  224. backgroundColor: token.colorBgTextActive
  225. })), genPureDisabledButtonStyle(token)), {
  226. [`&${token.componentCls}-dangerous`]: (0, _extends2.default)((0, _extends2.default)({
  227. color: token.colorError
  228. }, genPureDisabledButtonStyle(token)), genHoverActiveButtonStyle({
  229. color: token.colorErrorHover,
  230. backgroundColor: token.colorErrorBg
  231. }, {
  232. color: token.colorErrorHover,
  233. backgroundColor: token.colorErrorBg
  234. }))
  235. });
  236. // Href and Disabled
  237. const genDisabledButtonStyle = token => (0, _extends2.default)((0, _extends2.default)({}, genDisabledStyle(token)), {
  238. [`&${token.componentCls}:hover`]: (0, _extends2.default)({}, genDisabledStyle(token))
  239. });
  240. const genTypeButtonStyle = token => {
  241. const {
  242. componentCls
  243. } = token;
  244. return {
  245. [`${componentCls}-default`]: genDefaultButtonStyle(token),
  246. [`${componentCls}-primary`]: genPrimaryButtonStyle(token),
  247. [`${componentCls}-dashed`]: genDashedButtonStyle(token),
  248. [`${componentCls}-link`]: genLinkButtonStyle(token),
  249. [`${componentCls}-text`]: genTextButtonStyle(token),
  250. [`${componentCls}-disabled`]: genDisabledButtonStyle(token)
  251. };
  252. };
  253. // =============================== Size ===============================
  254. const genSizeButtonStyle = function (token) {
  255. let sizePrefixCls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  256. const {
  257. componentCls,
  258. iconCls,
  259. controlHeight,
  260. fontSize,
  261. lineHeight,
  262. lineWidth,
  263. borderRadius,
  264. buttonPaddingHorizontal
  265. } = token;
  266. const paddingVertical = Math.max(0, (controlHeight - fontSize * lineHeight) / 2 - lineWidth);
  267. const paddingHorizontal = buttonPaddingHorizontal - lineWidth;
  268. const iconOnlyCls = `${componentCls}-icon-only`;
  269. return [
  270. // Size
  271. {
  272. [`${componentCls}${sizePrefixCls}`]: {
  273. fontSize,
  274. height: controlHeight,
  275. padding: `${paddingVertical}px ${paddingHorizontal}px`,
  276. borderRadius,
  277. [`&${iconOnlyCls}`]: {
  278. width: controlHeight,
  279. paddingInlineStart: 0,
  280. paddingInlineEnd: 0,
  281. [`&${componentCls}-round`]: {
  282. width: 'auto'
  283. },
  284. '> span': {
  285. transform: 'scale(1.143)' // 14px -> 16px
  286. }
  287. },
  288. // Loading
  289. [`&${componentCls}-loading`]: {
  290. opacity: token.opacityLoading,
  291. cursor: 'default'
  292. },
  293. [`${componentCls}-loading-icon`]: {
  294. transition: `width ${token.motionDurationSlow} ${token.motionEaseInOut}, opacity ${token.motionDurationSlow} ${token.motionEaseInOut}`
  295. },
  296. [`&:not(${iconOnlyCls}) ${componentCls}-loading-icon > ${iconCls}`]: {
  297. marginInlineEnd: token.marginXS
  298. }
  299. }
  300. },
  301. // Shape - patch prefixCls again to override solid border radius style
  302. {
  303. [`${componentCls}${componentCls}-circle${sizePrefixCls}`]: genCircleButtonStyle(token)
  304. }, {
  305. [`${componentCls}${componentCls}-round${sizePrefixCls}`]: genRoundButtonStyle(token)
  306. }];
  307. };
  308. const genSizeBaseButtonStyle = token => genSizeButtonStyle(token);
  309. const genSizeSmallButtonStyle = token => {
  310. const smallToken = (0, _internal.mergeToken)(token, {
  311. controlHeight: token.controlHeightSM,
  312. padding: token.paddingXS,
  313. buttonPaddingHorizontal: 8,
  314. borderRadius: token.borderRadiusSM
  315. });
  316. return genSizeButtonStyle(smallToken, `${token.componentCls}-sm`);
  317. };
  318. const genSizeLargeButtonStyle = token => {
  319. const largeToken = (0, _internal.mergeToken)(token, {
  320. controlHeight: token.controlHeightLG,
  321. fontSize: token.fontSizeLG,
  322. borderRadius: token.borderRadiusLG
  323. });
  324. return genSizeButtonStyle(largeToken, `${token.componentCls}-lg`);
  325. };
  326. const genBlockButtonStyle = token => {
  327. const {
  328. componentCls
  329. } = token;
  330. return {
  331. [componentCls]: {
  332. [`&${componentCls}-block`]: {
  333. width: '100%'
  334. }
  335. }
  336. };
  337. };
  338. // ============================== Export ==============================
  339. var _default = exports.default = (0, _internal.genComponentStyleHook)('Button', token => {
  340. const {
  341. controlTmpOutline,
  342. paddingContentHorizontal
  343. } = token;
  344. const buttonToken = (0, _internal.mergeToken)(token, {
  345. colorOutlineDefault: controlTmpOutline,
  346. buttonPaddingHorizontal: paddingContentHorizontal
  347. });
  348. return [
  349. // Shared
  350. genSharedButtonStyle(buttonToken),
  351. // Size
  352. genSizeSmallButtonStyle(buttonToken), genSizeBaseButtonStyle(buttonToken), genSizeLargeButtonStyle(buttonToken),
  353. // Block
  354. genBlockButtonStyle(buttonToken),
  355. // Group (type, ghost, danger, disabled, loading)
  356. genTypeButtonStyle(buttonToken),
  357. // Button Group
  358. (0, _group.default)(buttonToken),
  359. // Space Compact
  360. (0, _compactItem.genCompactItemStyle)(token, {
  361. focus: false
  362. }), (0, _compactItemVertical.genCompactItemVerticalStyle)(token)];
  363. });