Blame view

src/styles/mixins/button.less 10 KB
e1596b7e   梁灏   add Button UI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  .button-size(@padding; @font-size; @border-radius) {
      padding: @padding;
      font-size: @font-size;
      border-radius: @border-radius;
  }
  
  .button-color(@color; @background; @border) {
      color: @color;
      background-color: @background;
      border-color: @border;
      // a inside Button which only work in Chrome
      // http://stackoverflow.com/a/17253457
      > a:only-child {
          color: currentColor;
          &:after {
              content: '';
              position: absolute;
              top: 0;
              left: 0;
              bottom: 0;
              right: 0;
              background: transparent;
          }
      }
  }
  
  .button-variant(@color; @background; @border) {
      .button-color(@color; @background; @border);
  
      &:hover
      //&:focus
      {
          .button-color(tint(@color, 20%); tint(@background, 20%); tint(@border, 20%));
      }
      &:active,
      &.active {
          .button-color(shade(@color, 5%); shade(@background, 5%); shade(@background, 5%));
      }
  
      &.disabled,
      &[disabled],
      fieldset[disabled] & {
          &,
          &:hover,
          &:focus,
          &:active,
          &.active {
              .button-color(@btn-disable-color; @btn-disable-bg; @btn-disable-border);
          }
      }
  }
  
  .button-group-base(@btnClassName) {
      position: relative;
      display: inline-block;
      vertical-align: middle;
      > .@{btnClassName} {
          position: relative;
          float: left;
          &:hover,
          //&:focus,
          &:active,
          &.active {
              z-index: 2;
          }
      }
  
0bc06000   梁灏   optimize ButtonGr...
68
      & .@{btnClassName}-icon-only .ivu-icon {
932c449d   梁灏   update Button style
69
          font-size: 13px;
0bc06000   梁灏   optimize ButtonGr...
70
          position: relative;
5fc37ce4   梁灏   update Button style
71
          //top: 1px;
0bc06000   梁灏   optimize ButtonGr...
72
73
74
      }
  
      &-large .@{btnClassName}-icon-only .ivu-icon{
932c449d   梁灏   update Button style
75
          font-size: 15px;
5fc37ce4   梁灏   update Button style
76
          //top: 2px;
0bc06000   梁灏   optimize ButtonGr...
77
78
79
80
      }
  
      &-small .@{btnClassName}-icon-only .ivu-icon{
          font-size: 12px;
5fc37ce4   梁灏   update Button style
81
          //top: 0;
0bc06000   梁灏   optimize ButtonGr...
82
83
      }
  
f1b3ed30   梁灏   Button add circle...
84
85
86
87
      &-circle .@{btnClassName} {
          border-radius: @btn-circle-size;
      }
  
e1596b7e   梁灏   add Button UI
88
      // size
f1b3ed30   梁灏   Button add circle...
89
90
91
92
93
94
95
      &-large&-circle .@{btnClassName} {
          border-radius: @btn-circle-size-large;
      }
      &-large {
          & > .@{btnClassName} {
              .button-size(@btn-padding-large; @btn-font-size-large; @btn-border-radius);
          }
e1596b7e   梁灏   add Button UI
96
97
      }
  
f1b3ed30   梁灏   Button add circle...
98
99
100
101
102
103
104
105
106
      &-small&-circle .@{btnClassName} {
          border-radius: @btn-circle-size-small;
      }
      &-small {
          & > .@{btnClassName}{
              .button-size(@btn-padding-small; @btn-font-size; @btn-border-radius-small);
              > .@{css-prefix-iconfont} {
                  font-size: @btn-font-size;
              }
e1596b7e   梁灏   add Button UI
107
108
          }
      }
5fc37ce4   梁灏   update Button style
109
  
932c449d   梁灏   update Button style
110
111
112
113
114
115
      //&-small .@{btnClassName}-icon-only{
      //    .button-size(@btn-padding-small-icon; @btn-font-size; @btn-border-radius-small);
      //}
      //&-large .@{btnClassName}-icon-only{
      //    .button-size(@btn-padding-large-icon; @btn-font-size-large; @btn-border-radius);
      //}
e1596b7e   梁灏   add Button UI
116
117
  }
  
fd6512a9   Rijn   implemented verti...
118
119
120
121
122
123
124
125
126
127
128
  .button-group-vertical-base(@btnClassName) {
      display: inline-block;
      vertical-align: middle;
      > .@{btnClassName} {
          display: block;
          width: 100%;
          max-width: 100%;
          float: none;
      }
  }
  
e1596b7e   梁灏   add Button UI
129
130
131
132
133
134
135
136
137
138
139
140
  .btn() {
      display: inline-block;
      margin-bottom: 0;
      font-weight: @btn-font-weight;
      text-align: center;
      vertical-align: middle;
      touch-action: manipulation;
      cursor: pointer;
      background-image: none;
      border: 1px solid transparent;
      white-space: nowrap;
      line-height: @line-height-base;
e2645048   jingsam   :fire: remove tra...
141
      user-select: none;
e1596b7e   梁灏   add Button UI
142
      .button-size(@btn-padding-base; @btn-font-size; @btn-border-radius);
de997724   Haven   Update button.less
143
      //transform: translate3d(0, 0, 0);
e2645048   jingsam   :fire: remove tra...
144
      //transition: all @transition-time linear;
9e5c7283   梁灏   Revert "Revert "u...
145
      transition: color @transition-time linear, background-color @transition-time linear, border @transition-time linear, box-shadow @transition-time linear;
e1596b7e   梁灏   add Button UI
146
147
  
      > .@{css-prefix-iconfont} {
932c449d   梁灏   update Button style
148
          line-height: @line-height-base;
bfeab68f   梁灏   update Button Ico...
149
150
151
          vertical-align: middle;
      }
  
5fc37ce4   梁灏   update Button style
152
      &-icon-only&-circle > .@{css-prefix-iconfont}{
bfeab68f   梁灏   update Button Ico...
153
154
155
156
157
          vertical-align: baseline;
      }
  
      > span{
          vertical-align: middle;
e1596b7e   梁灏   add Button UI
158
159
160
161
162
163
164
165
166
167
168
169
170
171
      }
  
      &,
      &:active,
      &:focus {
          outline: 0;
      }
  
      &:not([disabled]):hover {
          text-decoration: none;
      }
  
      &:not([disabled]):active {
          outline: 0;
5a3fe3ec   梁灏   update Button foc...
172
          // transition: none;  // 如果不注释此行,那么active会和focus同时触发,此时focus的开始动画transition会无效
e1596b7e   梁灏   add Button UI
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
      }
  
      &.disabled,
      &[disabled] {
          cursor: @cursor-disabled;
          > * {
              pointer-events: none;
          }
      }
  
      &-large {
          .button-size(@btn-padding-large; @btn-font-size-large; @btn-border-radius);
      }
  
      &-small {
          .button-size(@btn-padding-small; @btn-font-size; @btn-border-radius-small);
      }
5fc37ce4   梁灏   update Button style
190
191
192
193
194
195
196
197
198
199
  
      &-icon-only{
          .button-size(@btn-padding-base-icon; @btn-font-size; @btn-border-radius);
      }
      &-icon-only&-small{
          .button-size(@btn-padding-small-icon; @btn-font-size; @btn-border-radius-small);
      }
      &-icon-only&-large{
          .button-size(@btn-padding-large-icon; @btn-font-size-large; @btn-border-radius);
      }
e1596b7e   梁灏   add Button UI
200
201
202
203
204
205
206
207
208
  }
  
  // Default
  .btn-default() {
      .button-variant(@btn-default-color; @btn-default-bg; @btn-default-border);
  
      &:hover
      //&:focus
      {
0185d136   wynn   fix
209
          .button-color(tint(@search-color, 20%); white; tint(@search-color, 20%));
e1596b7e   梁灏   add Button UI
210
211
212
      }
      &:active,
      &.active {
0185d136   wynn   fix
213
          .button-color(shade(@search-color, 5%); white; shade(@search-color, 5%));
e1596b7e   梁灏   add Button UI
214
      }
0185d136   wynn   fix
215
      .active-btn-color(@search-color);
e1596b7e   梁灏   add Button UI
216
217
218
219
220
221
222
223
224
225
226
227
  }
  
  // Primary
  .btn-primary() {
      .button-variant(@btn-primary-color; @btn-primary-bg; @primary-color);
  
      &:hover,
      //&:focus,
      &:active,
      &.active {
          color: @btn-primary-color;
      }
b6af2c2a   梁灏   update Button styles
228
      .active-btn-color(@primary-color);
e1596b7e   梁灏   add Button UI
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
  }
  
  // Ghost
  .btn-ghost() {
      .button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
  
      &:hover
      //&:focus
      {
          .button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%));
      }
      &:active,
      &.active {
          .button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%));
      }
b6af2c2a   梁灏   update Button styles
244
      .active-btn-color(@primary-color);
e1596b7e   梁灏   add Button UI
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
  }
  
  // Dashed
  .btn-dashed() {
      .button-variant(@btn-ghost-color, @btn-ghost-bg, @btn-ghost-border);
      border-style: dashed;
  
      &:hover
      //&:focus
      {
          .button-color(tint(@primary-color, 20%); @btn-ghost-bg; tint(@primary-color, 20%));
      }
      &:active,
      &.active {
          .button-color(shade(@primary-color, 5%); @btn-ghost-bg; shade(@primary-color, 5%));
      }
b6af2c2a   梁灏   update Button styles
261
      .active-btn-color(@primary-color);
e1596b7e   梁灏   add Button UI
262
263
  }
  
698e3b61   梁灏   iButton add some ...
264
265
  // Text
  .btn-text() {
b4fe39f7   梁灏   Button add ghost ...
266
      .button-variant(@btn-ghost-color, transparent, transparent);
698e3b61   梁灏   iButton add some ...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  
      // for disabled
      &.disabled,
      &[disabled],
      fieldset[disabled] & {
          &,
          &:hover,
          &:focus,
          &:active,
          &.active {
              .button-color(@btn-disable-color; @btn-ghost-bg; transparent);
          }
      }
  
      &:hover
          //&:focus
      {
          .button-color(tint(@primary-color, 20%); @btn-ghost-bg; transparent);
      }
      &:active,
      &.active {
          .button-color(shade(@primary-color, 5%); @btn-ghost-bg; transparent);
      }
b6af2c2a   梁灏   update Button styles
290
      .active-btn-color(@primary-color);
698e3b61   梁灏   iButton add some ...
291
292
  }
  
b88f42eb   梁灏   Button add 4 new ...
293
  // Color
b6af2c2a   梁灏   update Button styles
294
295
  // for tabindex
  .active-btn-color(@color) {
9e5c7283   梁灏   Revert "Revert "u...
296
      &:focus {
b6af2c2a   梁灏   update Button styles
297
          box-shadow: 0 0 0 2px fade(@color, 20%);
b6af2c2a   梁灏   update Button styles
298
299
      }
  }
b88f42eb   梁灏   Button add 4 new ...
300
301
302
303
304
305
306
307
308
  .btn-color(@color) {
      .button-variant(@btn-primary-color; @color; @color);
  
      &:hover,
          //&:focus,
      &:active,
      &.active {
          color: @btn-primary-color;
      }
b6af2c2a   梁灏   update Button styles
309
310
  
      .active-btn-color(@color);
b88f42eb   梁灏   Button add 4 new ...
311
312
  }
  
e1596b7e   梁灏   add Button UI
313
314
  // Circle for Icon
  .btn-circle(@btnClassName: ivu-btn) {
f1b3ed30   梁灏   Button add circle...
315
      border-radius: @btn-circle-size;
e1596b7e   梁灏   add Button UI
316
  
698e3b61   梁灏   iButton add some ...
317
      &.@{btnClassName}-large{
f1b3ed30   梁灏   Button add circle...
318
          border-radius: @btn-circle-size-large;
e1596b7e   梁灏   add Button UI
319
320
      }
  
698e3b61   梁灏   iButton add some ...
321
      &.@{btnClassName}-size{
f1b3ed30   梁灏   Button add circle...
322
          border-radius: @btn-circle-size-small;
698e3b61   梁灏   iButton add some ...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
      }
  
      &.@{btnClassName}-icon-only{
          .square(@btn-circle-size);
          .button-size(0; @font-size-base + 2; 50%);
  
          &.@{btnClassName}-large{
              .square(@btn-circle-size-large);
              .button-size(0; @btn-font-size-large + 2; 50%);
          }
  
          &.@{btnClassName}-small{
              .square(@btn-circle-size-small);
              .button-size(0; @font-size-base; 50%);
          }
e1596b7e   梁灏   add Button UI
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
      }
  }
  
  // Group
  .btn-group(@btnClassName: ivu-btn) {
      .button-group-base(@btnClassName);
  
      .@{btnClassName} + .@{btnClassName},
      .@{btnClassName} + &,
      & + .@{btnClassName},
      & + & {
          margin-left: -1px;
      }
  
      .@{btnClassName}:not(:first-child):not(:last-child) {
          border-radius: 0;
e1596b7e   梁灏   add Button UI
354
355
      }
  
fd6512a9   Rijn   implemented verti...
356
      &:not(&-vertical) > .@{btnClassName}:first-child {
e1596b7e   梁灏   add Button UI
357
358
359
360
          margin-left: 0;
          &:not(:last-child) {
              border-bottom-right-radius: 0;
              border-top-right-radius: 0;
e1596b7e   梁灏   add Button UI
361
362
363
          }
      }
  
fd6512a9   Rijn   implemented verti...
364
      &:not(&-vertical) > .@{btnClassName}:last-child:not(:first-child) {
e1596b7e   梁灏   add Button UI
365
366
          border-bottom-left-radius: 0;
          border-top-left-radius: 0;
e1596b7e   梁灏   add Button UI
367
368
369
370
371
372
373
374
375
376
      }
  
      & > & {
          float: left;
      }
  
      & > &:not(:first-child):not(:last-child) > .@{btnClassName} {
          border-radius: 0;
      }
  
fd6512a9   Rijn   implemented verti...
377
      &:not(&-vertical) > &:first-child:not(:last-child) {
e1596b7e   梁灏   add Button UI
378
379
380
381
382
383
384
          > .@{btnClassName}:last-child {
              border-bottom-right-radius: 0;
              border-top-right-radius: 0;
              padding-right: 8px;
          }
      }
  
fd6512a9   Rijn   implemented verti...
385
      &:not(&-vertical) > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
e1596b7e   梁灏   add Button UI
386
387
388
389
390
          border-bottom-left-radius: 0;
          border-top-left-radius: 0;
          padding-left: 8px;
      }
  }
fd6512a9   Rijn   implemented verti...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
  
  .btn-group-vertical(@btnClassName: ivu-btn) {
      .button-group-vertical-base(@btnClassName);
  
      .@{btnClassName} + .@{btnClassName},
      .@{btnClassName} + &,
      & + .@{btnClassName},
      & + & {
          margin-top: -1px;
          margin-left: 0px;
      }
  
      > .@{btnClassName}:first-child {
          margin-top: 0;
          &:not(:last-child) {
              border-bottom-left-radius: 0;
              border-bottom-right-radius: 0;
          }
      }
  
      > .@{btnClassName}:last-child:not(:first-child) {
          border-top-left-radius: 0;
          border-top-right-radius: 0;
      }
  
      & > &:first-child:not(:last-child) {
          > .@{btnClassName}:last-child {
              border-bottom-left-radius: 0;
              border-bottom-right-radius: 0;
              padding-bottom: 8px;
          }
      }
  
      & > &:last-child:not(:first-child) > .@{btnClassName}:first-child {
          border-bottom-right-radius: 0;
          border-bottom-left-radius: 0;
          padding-top: 8px;
      }
  }