You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

button.less 8.8KB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. .button-size(@padding; @font-size; @border-radius) {
  2. padding: @padding;
  3. font-size: @font-size;
  4. border-radius: @border-radius;
  5. }
  6. .button-color(@color; @background; @border) {
  7. color: @color;
  8. background-color: @background;
  9. border-color: @border;
  10. // a inside Button which only work in Chrome
  11. // http://stackoverflow.com/a/17253457
  12. > a:only-child {
  13. color: currentColor;
  14. &:after {
  15. content: '';
  16. position: absolute;
  17. top: 0;
  18. left: 0;
  19. bottom: 0;
  20. right: 0;
  21. background: transparent;
  22. }
  23. }
  24. }
  25. .button-variant(@color; @background; @border) {
  26. .button-color(@color; @background; @border);
  27. &:hover
  28. //&:focus
  29. {
  30. .button-color(tint(@color, 20%); tint(@background, 20%); tint(@border, 20%));
  31. }
  32. &:active,
  33. &.active {
  34. .button-color(shade(@color, 5%); shade(@background, 5%); shade(@background, 5%));
  35. }
  36. &.disabled,
  37. &[disabled],
  38. fieldset[disabled] & {
  39. &,
  40. &:hover,
  41. &:focus,
  42. &:active,
  43. &.active {
  44. .button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
  45. }
  46. }
  47. }
  48. .button-group-base(@btnClassName) {
  49. position: relative;
  50. display: inline-block;
  51. vertical-align: middle;
  52. > .@{btnClassName} {
  53. position: relative;
  54. float: left;
  55. &:hover,
  56. //&:focus,
  57. &:active,
  58. &.active {
  59. z-index: 2;
  60. }
  61. }
  62. & .@{btnClassName}-icon-only .ivu-icon {
  63. font-size: 14px;
  64. position: relative;
  65. top: 1px;
  66. }
  67. &-large .@{btnClassName}-icon-only .ivu-icon{
  68. font-size: 16px;
  69. top: 2px;
  70. }
  71. &-small .@{btnClassName}-icon-only .ivu-icon{
  72. font-size: 12px;
  73. top: 0;
  74. }
  75. &-circle .@{btnClassName} {
  76. border-radius: @btn-circle-size;
  77. }
  78. // size
  79. &-large&-circle .@{btnClassName} {
  80. border-radius: @btn-circle-size-large;
  81. }
  82. &-large {
  83. & > .@{btnClassName} {
  84. .button-size(@btn-padding-large; @btn-font-size-large; @btn-border-radius);
  85. }
  86. }
  87. &-small&-circle .@{btnClassName} {
  88. border-radius: @btn-circle-size-small;
  89. }
  90. &-small {
  91. & > .@{btnClassName}{
  92. .button-size(@btn-padding-small; @btn-font-size; @btn-border-radius-small);
  93. > .@{css-prefix-iconfont} {
  94. font-size: @btn-font-size;
  95. }
  96. }
  97. }
  98. }
  99. .button-group-vertical-base(@btnClassName) {
  100. display: inline-block;
  101. vertical-align: middle;
  102. > .@{btnClassName} {
  103. display: block;
  104. width: 100%;
  105. max-width: 100%;
  106. float: none;
  107. }
  108. }
  109. .btn() {
  110. display: inline-block;
  111. margin-bottom: 0;
  112. font-weight: @btn-font-weight;
  113. text-align: center;
  114. vertical-align: middle;
  115. touch-action: manipulation;
  116. cursor: pointer;
  117. background-image: none;
  118. border: 1px solid transparent;
  119. white-space: nowrap;
  120. line-height: @line-height-base;
  121. user-select: none;
  122. .button-size(@btn-padding-base; @btn-font-size; @btn-border-radius);
  123. transform: translate3d(0, 0, 0);
  124. //transition: all @transition-time linear;
  125. transition: color @transition-time linear, background-color @transition-time linear, border @transition-time linear;
  126. > .@{css-prefix-iconfont} {
  127. line-height: 1;
  128. }
  129. &,
  130. &:active,
  131. &:focus {
  132. outline: 0;
  133. }
  134. &:not([disabled]):hover {
  135. text-decoration: none;
  136. }
  137. &:not([disabled]):active {
  138. outline: 0;
  139. transition: none;
  140. }
  141. &.disabled,
  142. &[disabled] {
  143. cursor: @cursor-disabled;
  144. > * {
  145. pointer-events: none;
  146. }
  147. }
  148. &-large {
  149. .button-size(@btn-padding-large; @btn-font-size-large; @btn-border-radius);
  150. }
  151. &-small {
  152. .button-size(@btn-padding-small; @btn-font-size; @btn-border-radius-small);
  153. }
  154. }
  155. // Default
  156. .btn-default() {
  157. .button-variant(@btn-default-color; @btn-default-bg; @btn-default-border);
  158. &:hover
  159. //&:focus
  160. {
  161. .button-color(tint(@primary-color, 20%); white; tint(@primary-color, 20%));
  162. }
  163. &:active,
  164. &.active {
  165. .button-color(shade(@primary-color, 5%); white; shade(@primary-color, 5%));
  166. }
  167. }
  168. // Primary
  169. .btn-primary() {
  170. .button-variant(@btn-primary-color; @btn-primary-bg; @primary-color);
  171. &:hover,
  172. //&:focus,
  173. &:active,
  174. &.active {
  175. color: @btn-primary-color;
  176. }
  177. }
  178. // Ghost
  179. .btn-ghost() {
  180. .button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
  181. &:hover
  182. //&:focus
  183. {
  184. .button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%));
  185. }
  186. &:active,
  187. &.active {
  188. .button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%));
  189. }
  190. }
  191. // Dashed
  192. .btn-dashed() {
  193. .button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
  194. border-style: dashed;
  195. &:hover
  196. //&:focus
  197. {
  198. .button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%));
  199. }
  200. &:active,
  201. &.active {
  202. .button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%));
  203. }
  204. }
  205. // Text
  206. .btn-text() {
  207. .button-variant(@btn-ghost-color, @btn-ghost-bg, transparent);
  208. // for disabled
  209. &.disabled,
  210. &[disabled],
  211. fieldset[disabled] & {
  212. &,
  213. &:hover,
  214. &:focus,
  215. &:active,
  216. &.active {
  217. .button-color(@btn-disable-color; @btn-ghost-bg; transparent);
  218. }
  219. }
  220. &:hover
  221. //&:focus
  222. {
  223. .button-color(tint(@primary-color, 20%); @btn-ghost-bg; transparent);
  224. }
  225. &:active,
  226. &.active {
  227. .button-color(shade(@primary-color, 5%); @btn-ghost-bg; transparent);
  228. }
  229. }
  230. // Color
  231. .btn-color(@color) {
  232. .button-variant(@btn-primary-color; @color; @color);
  233. &:hover,
  234. //&:focus,
  235. &:active,
  236. &.active {
  237. color: @btn-primary-color;
  238. }
  239. }
  240. // Circle for Icon
  241. .btn-circle(@btnClassName: ivu-btn) {
  242. border-radius: @btn-circle-size;
  243. &.@{btnClassName}-large{
  244. border-radius: @btn-circle-size-large;
  245. }
  246. &.@{btnClassName}-size{
  247. border-radius: @btn-circle-size-small;
  248. }
  249. &.@{btnClassName}-icon-only{
  250. .square(@btn-circle-size);
  251. .button-size(0; @font-size-base + 2; 50%);
  252. &.@{btnClassName}-large{
  253. .square(@btn-circle-size-large);
  254. .button-size(0; @btn-font-size-large + 2; 50%);
  255. }
  256. &.@{btnClassName}-small{
  257. .square(@btn-circle-size-small);
  258. .button-size(0; @font-size-base; 50%);
  259. }
  260. }
  261. }
  262. // Group
  263. .btn-group(@btnClassName: ivu-btn) {
  264. .button-group-base(@btnClassName);
  265. .@{btnClassName} + .@{btnClassName},
  266. .@{btnClassName} + &,
  267. & + .@{btnClassName},
  268. & + & {
  269. margin-left: -1px;
  270. }
  271. .@{btnClassName}:not(:first-child):not(:last-child) {
  272. border-radius: 0;
  273. }
  274. &:not(&-vertical) > .@{btnClassName}:first-child {
  275. margin-left: 0;
  276. &:not(:last-child) {
  277. border-bottom-right-radius: 0;
  278. border-top-right-radius: 0;
  279. }
  280. }
  281. &:not(&-vertical) > .@{btnClassName}:last-child:not(:first-child) {
  282. border-bottom-left-radius: 0;
  283. border-top-left-radius: 0;
  284. }
  285. & > & {
  286. float: left;
  287. }
  288. & > &:not(:first-child):not(:last-child) > .@{btnClassName} {
  289. border-radius: 0;
  290. }
  291. &:not(&-vertical) > &:first-child:not(:last-child) {
  292. > .@{btnClassName}:last-child {
  293. border-bottom-right-radius: 0;
  294. border-top-right-radius: 0;
  295. padding-right: 8px;
  296. }
  297. }
  298. &:not(&-vertical) > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
  299. border-bottom-left-radius: 0;
  300. border-top-left-radius: 0;
  301. padding-left: 8px;
  302. }
  303. }
  304. .btn-group-vertical(@btnClassName: ivu-btn) {
  305. .button-group-vertical-base(@btnClassName);
  306. .@{btnClassName} + .@{btnClassName},
  307. .@{btnClassName} + &,
  308. & + .@{btnClassName},
  309. & + & {
  310. margin-top: -1px;
  311. margin-left: 0px;
  312. }
  313. > .@{btnClassName}:first-child {
  314. margin-top: 0;
  315. &:not(:last-child) {
  316. border-bottom-left-radius: 0;
  317. border-bottom-right-radius: 0;
  318. }
  319. }
  320. > .@{btnClassName}:last-child:not(:first-child) {
  321. border-top-left-radius: 0;
  322. border-top-right-radius: 0;
  323. }
  324. & > &:first-child:not(:last-child) {
  325. > .@{btnClassName}:last-child {
  326. border-bottom-left-radius: 0;
  327. border-bottom-right-radius: 0;
  328. padding-bottom: 8px;
  329. }
  330. }
  331. & > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
  332. border-bottom-right-radius: 0;
  333. border-bottom-left-radius: 0;
  334. padding-top: 8px;
  335. }
  336. }