mixin.less 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. // mixins for button
  2. // ------------------------
  3. .button-size(@height; @padding-horizontal; @font-size; @border-radius) {
  4. @padding-vertical: max(
  5. (round(((@height - @font-size * @line-height-base) / 2) * 10) / 10) - @border-width-base,
  6. 0
  7. );
  8. height: @height;
  9. padding: @padding-vertical @padding-horizontal;
  10. font-size: @font-size;
  11. border-radius: @border-radius;
  12. }
  13. .button-color(@color; @background; @border) {
  14. color: @color;
  15. border-color: @border; // a inside Button which only work in Chrome
  16. & when not(@background = null) {
  17. background: @background;
  18. }
  19. // http://stackoverflow.com/a/17253457
  20. > a:only-child {
  21. color: currentcolor;
  22. &::after {
  23. position: absolute;
  24. top: 0;
  25. right: 0;
  26. bottom: 0;
  27. left: 0;
  28. background: transparent;
  29. content: '';
  30. }
  31. }
  32. }
  33. .button-disabled(@color: @btn-disable-color; @background: @btn-disable-bg; @border: @btn-disable-border) {
  34. &[disabled] {
  35. &,
  36. &:hover,
  37. &:focus,
  38. &:active {
  39. .button-color(@color; @background; @border);
  40. text-shadow: none;
  41. box-shadow: none;
  42. }
  43. }
  44. }
  45. .button-variant-primary(@color; @background; @backgroundHover: yellow; @backgroundActive: yellow) {
  46. .button-color(@color; @background; @background);
  47. text-shadow: @btn-text-shadow;
  48. box-shadow: @btn-primary-shadow;
  49. &:hover,
  50. &:focus {
  51. & when (@theme = dark) {
  52. .button-color(
  53. @color; ~`colorPalette('@{background}', 7) `; ~`colorPalette('@{background}', 7) `
  54. );
  55. }
  56. & when (not (@theme = dark) and not (@theme = variable)) {
  57. .button-color(
  58. @color; ~`colorPalette('@{background}', 5) `; ~`colorPalette('@{background}', 5) `
  59. );
  60. }
  61. & when (@theme = variable) {
  62. .button-color(@color; @backgroundHover; @backgroundHover);
  63. }
  64. }
  65. &:active {
  66. & when (@theme = dark) {
  67. .button-color(
  68. @color; ~`colorPalette('@{background}', 5) `; ~`colorPalette('@{background}', 5) `
  69. );
  70. }
  71. & when (not (@theme = dark) and not (@theme = variable)) {
  72. .button-color(
  73. @color; ~`colorPalette('@{background}', 7) `; ~`colorPalette('@{background}', 7) `
  74. );
  75. }
  76. & when (@theme = variable) {
  77. .button-color(@color; @backgroundActive; @backgroundActive);
  78. }
  79. }
  80. .button-disabled();
  81. }
  82. .button-variant-other(@color; @background; @border) {
  83. .button-color(@color; @background; @border);
  84. &:hover,
  85. &:focus {
  86. & when (@theme = dark) {
  87. .button-color(@primary-5; @background; @primary-5);
  88. }
  89. & when (not (@theme = dark) and not (@theme = variable)) {
  90. .button-color(
  91. ~`colorPalette('@{btn-primary-bg}', 5) `; @background;
  92. ~`colorPalette('@{btn-primary-bg}', 5) `
  93. );
  94. }
  95. & when (@theme = variable) {
  96. .button-color(@primary-color-hover; @background; @primary-color-hover);
  97. }
  98. }
  99. &:active {
  100. & when (@theme = dark) {
  101. .button-color(@primary-7; @background; @primary-7);
  102. }
  103. & when (not (@theme = dark) and not (@theme = variable)) {
  104. .button-color(
  105. ~`colorPalette('@{btn-primary-bg}', 7) `; @background;
  106. ~`colorPalette('@{btn-primary-bg}', 7) `
  107. );
  108. }
  109. & when (@theme = variable) {
  110. .button-color(@primary-color-active; @background; @primary-color-active);
  111. }
  112. }
  113. .button-disabled();
  114. }
  115. .button-variant-ghost(@color; @border; @borderHover: yellow; @borderActive: yellow) {
  116. .button-color(@color; null; @border);
  117. text-shadow: none;
  118. &:hover,
  119. &:focus {
  120. & when (@border = transparent) {
  121. & when (@theme = dark) {
  122. .button-color(~`colorPalette('@{color}', 7) `; null; transparent);
  123. }
  124. & when (not (@theme = dark) and not (@theme = variable)) {
  125. .button-color(~`colorPalette('@{color}', 5) `; null; transparent);
  126. }
  127. & when (@theme = variable) {
  128. .button-color(@borderActive; transparent; transparent);
  129. }
  130. }
  131. & when not (@border = transparent) {
  132. & when (@theme = dark) {
  133. .button-color(
  134. ~`colorPalette('@{color}', 7) `; null; ~`colorPalette('@{color}', 7) `
  135. );
  136. }
  137. & when (not (@theme = dark) and not (@theme = variable)) {
  138. .button-color(
  139. ~`colorPalette('@{color}', 5) `; null; ~`colorPalette('@{color}', 5) `
  140. );
  141. }
  142. & when (@theme = variable) {
  143. .button-color(@borderHover; transparent; @borderHover);
  144. }
  145. }
  146. }
  147. &:active {
  148. & when (@border = transparent) {
  149. & when (@theme = dark) {
  150. .button-color(~`colorPalette('@{color}', 5) `; null; transparent);
  151. }
  152. & when (not (@theme = dark) and not (@theme = variable)) {
  153. .button-color(~`colorPalette('@{color}', 7) `; null; transparent);
  154. }
  155. & when (@theme = variable) {
  156. .button-color(@borderActive; transparent; transparent);
  157. }
  158. }
  159. & when not (@border = transparent) {
  160. & when (@theme = dark) {
  161. .button-color(
  162. ~`colorPalette('@{color}', 5) `; null; ~`colorPalette('@{color}', 5) `
  163. );
  164. }
  165. & when (not (@theme = dark) and not (@theme = variable)) {
  166. .button-color(
  167. ~`colorPalette('@{color}', 7) `; null; ~`colorPalette('@{color}', 7) `
  168. );
  169. }
  170. & when (@theme = variable) {
  171. .button-color(@borderActive; transparent; @borderActive);
  172. }
  173. }
  174. }
  175. .button-disabled();
  176. }
  177. .button-group-base(@btnClassName) {
  178. position: relative;
  179. display: inline-flex;
  180. > .@{btnClassName},
  181. > span > .@{btnClassName} {
  182. position: relative;
  183. &:hover,
  184. &:focus,
  185. &:active {
  186. z-index: 2;
  187. }
  188. &[disabled] {
  189. z-index: 0;
  190. }
  191. }
  192. .@{btnClassName}-icon-only {
  193. font-size: @font-size-base;
  194. }
  195. // size
  196. &-lg > .@{btnClassName},
  197. &-lg > span > .@{btnClassName} {
  198. .button-size(@btn-height-lg; @btn-padding-horizontal-lg; @btn-font-size-lg; 0);
  199. }
  200. &-lg .@{btnClassName}.@{btnClassName}-icon-only {
  201. .square(@btn-height-lg);
  202. padding-right: 0;
  203. padding-left: 0;
  204. }
  205. &-sm > .@{btnClassName},
  206. &-sm > span > .@{btnClassName} {
  207. .button-size(@btn-height-sm; @btn-padding-horizontal-sm; @font-size-base; 0);
  208. > .@{iconfont-css-prefix} {
  209. font-size: @font-size-base;
  210. }
  211. }
  212. &-sm .@{btnClassName}.@{btnClassName}-icon-only {
  213. .square(@btn-height-sm);
  214. padding-right: 0;
  215. padding-left: 0;
  216. }
  217. }
  218. // Base styles of buttons
  219. // --------------------------------------------------
  220. .btn() {
  221. position: relative;
  222. display: inline-block;
  223. font-weight: @btn-font-weight;
  224. white-space: nowrap;
  225. text-align: center;
  226. background-image: none;
  227. border: @btn-border-width @btn-border-style transparent;
  228. box-shadow: @btn-shadow;
  229. cursor: pointer;
  230. transition: all 0.3s @ease-in-out;
  231. user-select: none;
  232. touch-action: manipulation;
  233. .button-size(
  234. @btn-height-base; @btn-padding-horizontal-base; @font-size-base; @btn-border-radius-base
  235. );
  236. > .@{iconfont-css-prefix} {
  237. line-height: 1;
  238. }
  239. &,
  240. &:active,
  241. &:focus {
  242. outline: 0;
  243. }
  244. &:not([disabled]):hover {
  245. text-decoration: none;
  246. }
  247. &:not([disabled]):active {
  248. outline: 0;
  249. box-shadow: none;
  250. }
  251. &[disabled] {
  252. cursor: not-allowed;
  253. > * {
  254. pointer-events: none;
  255. }
  256. }
  257. &-lg {
  258. .button-size(
  259. @btn-height-lg; @btn-padding-horizontal-lg; @btn-font-size-lg; @btn-border-radius-base
  260. );
  261. }
  262. &-sm {
  263. .button-size(
  264. @btn-height-sm; @btn-padding-horizontal-sm; @btn-font-size-sm; @btn-border-radius-sm
  265. );
  266. }
  267. }
  268. // primary button style
  269. .btn-primary() {
  270. .button-variant-primary(@btn-primary-color; @btn-primary-bg; @primary-color-hover; @primary-color-active);
  271. }
  272. // default button style
  273. .btn-default() {
  274. .button-variant-other(@btn-default-color; @btn-default-bg; @btn-default-border; );
  275. &:hover,
  276. &:focus,
  277. &:active {
  278. text-decoration: none;
  279. background: @btn-default-bg;
  280. }
  281. }
  282. // ghost button style
  283. .btn-ghost() {
  284. .button-variant-other(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
  285. }
  286. // dashed button style
  287. .btn-dashed() {
  288. .button-variant-other(@btn-default-color, @btn-default-bg, @btn-default-border);
  289. border-style: dashed;
  290. }
  291. // danger button style
  292. .btn-danger() {
  293. .button-variant-primary(@btn-danger-color, @btn-danger-bg, @error-color-hover, @error-color-active);
  294. }
  295. // danger default button style
  296. .btn-danger-default() {
  297. .button-color(@error-color, @btn-default-bg, @error-color);
  298. &:hover,
  299. &:focus {
  300. & when (@theme = dark) {
  301. .button-color(
  302. ~`colorPalette('@{error-color}', 7) `; @btn-default-bg; ~`colorPalette('@{error-color}', 7)
  303. `
  304. );
  305. }
  306. & when (not (@theme = dark) and not (@theme = variable)) {
  307. .button-color(
  308. ~`colorPalette('@{error-color}', 5) `; @btn-default-bg; ~`colorPalette('@{error-color}', 5)
  309. `
  310. );
  311. }
  312. & when (@theme = variable) {
  313. .button-color(@error-color-hover, @btn-default-bg, @error-color-hover);
  314. }
  315. }
  316. &:active {
  317. & when (@theme = dark) {
  318. .button-color(
  319. ~`colorPalette('@{error-color}', 5) `; @btn-default-bg; ~`colorPalette('@{error-color}', 5)
  320. `
  321. );
  322. }
  323. & when (not (@theme = dark) and not (@theme = variable)) {
  324. .button-color(
  325. ~`colorPalette('@{error-color}', 7) `; @btn-default-bg; ~`colorPalette('@{error-color}', 7)
  326. `
  327. );
  328. }
  329. & when (@theme = variable) {
  330. .button-color(@error-color-active, @btn-default-bg, @error-color-active);
  331. }
  332. }
  333. .button-disabled();
  334. }
  335. // danger link button style
  336. .btn-danger-link() {
  337. .button-variant-other(@error-color, transparent, transparent);
  338. box-shadow: none;
  339. &:hover,
  340. &:focus {
  341. & when (@theme = dark) {
  342. .button-color(~`colorPalette('@{error-color}', 7) `; transparent; transparent);
  343. }
  344. & when (not (@theme = dark) and not (@theme = variable)) {
  345. .button-color(~`colorPalette('@{error-color}', 5) `; transparent; transparent);
  346. }
  347. & when (@theme = variable) {
  348. .button-color(@error-color-hover; transparent; transparent);
  349. }
  350. }
  351. &:active {
  352. & when (@theme = dark) {
  353. .button-color(~`colorPalette('@{error-color}', 5) `; transparent; transparent);
  354. }
  355. & when (not (@theme = dark) and not (@theme = variable)) {
  356. .button-color(~`colorPalette('@{error-color}', 7) `; transparent; transparent);
  357. }
  358. & when (@theme = variable) {
  359. .button-color(@error-color-active; transparent; transparent);
  360. }
  361. }
  362. .button-disabled(@disabled-color; transparent; transparent);
  363. }
  364. // link button style
  365. .btn-link() {
  366. .button-variant-other(@link-color, transparent, transparent);
  367. box-shadow: none;
  368. &:hover {
  369. background: @btn-link-hover-bg;
  370. }
  371. &:hover,
  372. &:focus,
  373. &:active {
  374. border-color: transparent;
  375. }
  376. .button-disabled(@disabled-color; transparent; transparent);
  377. }
  378. // text button style
  379. .btn-text() {
  380. .button-variant-other(@text-color, transparent, transparent);
  381. box-shadow: none;
  382. &:hover,
  383. &:focus {
  384. color: @text-color;
  385. background: @btn-text-hover-bg;
  386. border-color: transparent;
  387. }
  388. &:active {
  389. color: @text-color;
  390. background: fadein(@btn-text-hover-bg, 1%);
  391. border-color: transparent;
  392. }
  393. .button-disabled(@disabled-color; transparent; transparent);
  394. }
  395. .btn-danger-text() {
  396. .button-variant-other(@error-color, transparent, transparent);
  397. box-shadow: none;
  398. &:hover,
  399. &:focus {
  400. & when (@theme = dark) {
  401. .button-color(~`colorPalette('@{error-color}', 7) `; @btn-text-hover-bg; transparent);
  402. }
  403. & when (not (@theme = dark) and not (@theme = variable)) {
  404. .button-color(~`colorPalette('@{error-color}', 5) `; @btn-text-hover-bg; transparent);
  405. }
  406. & when (@theme = variable) {
  407. .button-color(@error-color-hover; @btn-text-hover-bg; transparent);
  408. }
  409. }
  410. &:active {
  411. & when (@theme = dark) {
  412. .button-color(~`colorPalette('@{error-color}', 5) `; fadein(@btn-text-hover-bg, 1%); transparent);
  413. }
  414. & when (not (@theme = dark) and not (@theme = variable)) {
  415. .button-color(~`colorPalette('@{error-color}', 7) `; fadein(@btn-text-hover-bg, 1%); transparent);
  416. }
  417. & when (@theme = variable) {
  418. .button-color(@error-color-active; fadein(@btn-text-hover-bg, 1%); transparent);
  419. }
  420. }
  421. .button-disabled(@disabled-color; transparent; transparent);
  422. }
  423. // round button
  424. .btn-round(@btnClassName: btn) {
  425. .button-size(@btn-circle-size; (@btn-circle-size / 2); @font-size-base; @btn-circle-size);
  426. &.@{btnClassName}-lg {
  427. .button-size(
  428. @btn-circle-size-lg; (@btn-circle-size-lg / 2); @btn-font-size-lg; @btn-circle-size-lg
  429. );
  430. }
  431. &.@{btnClassName}-sm {
  432. .button-size(
  433. @btn-circle-size-sm; (@btn-circle-size-sm / 2); @font-size-base; @btn-circle-size-sm
  434. );
  435. }
  436. }
  437. // square button: the content only contains icon
  438. .btn-square(@btnClassName: btn) {
  439. .square(@btn-square-size);
  440. .button-size(@btn-square-size; 0; @btn-square-only-icon-size; @btn-border-radius-base);
  441. & > * {
  442. font-size: @btn-square-only-icon-size;
  443. }
  444. &.@{btnClassName}-lg {
  445. .square(@btn-square-size-lg);
  446. .button-size(@btn-square-size-lg; 0; @btn-square-only-icon-size-lg; @btn-border-radius-base);
  447. & > * {
  448. font-size: @btn-square-only-icon-size-lg;
  449. }
  450. }
  451. &.@{btnClassName}-sm {
  452. .square(@btn-square-size-sm);
  453. .button-size(@btn-square-size-sm; 0; @btn-square-only-icon-size-sm; @btn-border-radius-base);
  454. & > * {
  455. font-size: @btn-square-only-icon-size-sm;
  456. }
  457. }
  458. }
  459. // circle button: the content only contains icon
  460. .btn-circle(@btnClassName: btn) {
  461. min-width: @btn-height-base;
  462. padding-right: 0;
  463. padding-left: 0;
  464. text-align: center;
  465. border-radius: 50%;
  466. &.@{btnClassName}-lg {
  467. min-width: @btn-height-lg;
  468. border-radius: 50%;
  469. }
  470. &.@{btnClassName}-sm {
  471. min-width: @btn-height-sm;
  472. border-radius: 50%;
  473. }
  474. }
  475. // Horizontal button groups style
  476. // --------------------------------------------------
  477. .btn-group(@btnClassName: btn) {
  478. .button-group-base(@btnClassName);
  479. .@{btnClassName} + .@{btnClassName},
  480. .@{btnClassName} + &,
  481. span + .@{btnClassName},
  482. .@{btnClassName} + span,
  483. > span + span,
  484. & + .@{btnClassName},
  485. & + & {
  486. margin-left: -1px;
  487. }
  488. .@{btnClassName}-primary + .@{btnClassName}:not(.@{btnClassName}-primary):not([disabled]) {
  489. border-left-color: transparent;
  490. }
  491. .@{btnClassName} {
  492. border-radius: 0;
  493. }
  494. > .@{btnClassName}:first-child,
  495. > span:first-child > .@{btnClassName} {
  496. margin-left: 0;
  497. }
  498. > .@{btnClassName}:only-child {
  499. border-radius: @btn-border-radius-base;
  500. }
  501. > span:only-child > .@{btnClassName} {
  502. border-radius: @btn-border-radius-base;
  503. }
  504. > .@{btnClassName}:first-child:not(:last-child),
  505. > span:first-child:not(:last-child) > .@{btnClassName} {
  506. border-top-left-radius: @btn-border-radius-base;
  507. border-bottom-left-radius: @btn-border-radius-base;
  508. }
  509. > .@{btnClassName}:last-child:not(:first-child),
  510. > span:last-child:not(:first-child) > .@{btnClassName} {
  511. border-top-right-radius: @btn-border-radius-base;
  512. border-bottom-right-radius: @btn-border-radius-base;
  513. }
  514. &-sm {
  515. > .@{btnClassName}:only-child {
  516. border-radius: @btn-border-radius-sm;
  517. }
  518. > span:only-child > .@{btnClassName} {
  519. border-radius: @btn-border-radius-sm;
  520. }
  521. > .@{btnClassName}:first-child:not(:last-child),
  522. > span:first-child:not(:last-child) > .@{btnClassName} {
  523. border-top-left-radius: @btn-border-radius-sm;
  524. border-bottom-left-radius: @btn-border-radius-sm;
  525. }
  526. > .@{btnClassName}:last-child:not(:first-child),
  527. > span:last-child:not(:first-child) > .@{btnClassName} {
  528. border-top-right-radius: @btn-border-radius-sm;
  529. border-bottom-right-radius: @btn-border-radius-sm;
  530. }
  531. }
  532. & > & {
  533. float: left;
  534. }
  535. & > &:not(:first-child):not(:last-child) > .@{btnClassName} {
  536. border-radius: 0;
  537. }
  538. & > &:first-child:not(:last-child) {
  539. > .@{btnClassName}:last-child {
  540. padding-right: 8px;
  541. border-top-right-radius: 0;
  542. border-bottom-right-radius: 0;
  543. }
  544. }
  545. & > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
  546. padding-left: 8px;
  547. border-top-left-radius: 0;
  548. border-bottom-left-radius: 0;
  549. }
  550. }