_button-group.scss 3.54 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
// stylelint-disable selector-no-qualifying-type
Mark Otto's avatar
Mark Otto committed
2

3
// Make the div behave like a button
4
5
.btn-group,
.btn-group-vertical {
6
  position: relative;
7
  display: inline-flex;
8
  vertical-align: middle; // match .btn alignment given font-size hack above
Mark Otto's avatar
Mark Otto committed
9

Mark Otto's avatar
Mark Otto committed
10
  > .btn {
11
    position: relative;
12
    flex: 1 1 auto;
Mark Otto's avatar
Mark Otto committed
13

14
    // Bring the hover, focused, and "active" buttons to the front to overlay
Mark Otto's avatar
Mark Otto committed
15
16
    // the borders properly
    @include hover {
17
      z-index: 1;
Mark Otto's avatar
Mark Otto committed
18
    }
19
    &:focus,
20
21
    &:active,
    &.active {
22
      z-index: 1;
23
    }
Mark Otto's avatar
Mark Otto committed
24
  }
25
26
}

27
// Optional: Group multiple button groups together for a toolbar
28
.btn-toolbar {
Mark Otto's avatar
Mark Otto committed
29
  display: flex;
30
  flex-wrap: wrap;
Mark Otto's avatar
Mark Otto committed
31
  justify-content: flex-start;
32
33
34
35

  .input-group {
    width: auto;
  }
36
37
}

38
.btn-group {
39
40
41
42
  // Prevent double borders when buttons are next to each other
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) {
    margin-left: -$btn-border-width;
43
44
  }

ysds's avatar
ysds committed
45
46
47
48
  // Reset rounded corners
  > .btn:not(:last-child):not(.dropdown-toggle),
  > .btn-group:not(:last-child) > .btn {
    @include border-right-radius(0);
49
  }
50

ysds's avatar
ysds committed
51
52
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) > .btn {
53
54
55
    @include border-left-radius(0);
  }
}
56

57
58
59
60
// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

Mark Otto's avatar
Mark Otto committed
61
62
.btn-group-sm > .btn { @extend .btn-sm; }
.btn-group-lg > .btn { @extend .btn-lg; }
63

64

Mark Otto's avatar
Mark Otto committed
65
//
66
// Split button dropdowns
Mark Otto's avatar
Mark Otto committed
67
//
68

Mark Otto's avatar
Mark Otto committed
69
.dropdown-toggle-split {
70
71
  padding-right: $btn-padding-x * .75;
  padding-left: $btn-padding-x * .75;
72

ysds's avatar
ysds committed
73
74
75
  &::after,
  .dropup &::after,
  .dropright &::after {
76
    margin-left: 0;
77
  }
ysds's avatar
ysds committed
78
79
80
81

  .dropleft &::before {
    margin-right: 0;
  }
82
}
83

84
.btn-sm + .dropdown-toggle-split {
85
86
  padding-right: $btn-padding-x-sm * .75;
  padding-left: $btn-padding-x-sm * .75;
87
88
89
}

.btn-lg + .dropdown-toggle-split {
90
91
  padding-right: $btn-padding-x-lg * .75;
  padding-left: $btn-padding-x-lg * .75;
92
93
94
}


95
// The clickable button for toggling the menu
96
97
// Set the same inset shadow as the :active state
.btn-group.show .dropdown-toggle {
98
  @include box-shadow($btn-active-box-shadow);
99
100
101

  // Show no shadow for `.btn-link` since it has no other button styles.
  &.btn-link {
Mark Otto's avatar
Mark Otto committed
102
    @include box-shadow(none);
103
  }
104
}
105

Mark Otto's avatar
Mark Otto committed
106

Mark Otto's avatar
Mark Otto committed
107
//
108
// Vertical button groups
Mark Otto's avatar
Mark Otto committed
109
//
110

Mark Otto's avatar
derp    
Mark Otto committed
111
.btn-group-vertical {
Mark Otto's avatar
Mark Otto committed
112
113
  flex-direction: column;
  align-items: flex-start;
Mark Otto's avatar
linting    
Mark Otto committed
114
  justify-content: center;
Mark Otto's avatar
Mark Otto committed
115

116
117
  > .btn,
  > .btn-group {
118
    width: 100%;
119
120
  }

121
122
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) {
123
    margin-top: -$btn-border-width;
124
  }
Mark Otto's avatar
derp    
Mark Otto committed
125

ysds's avatar
ysds committed
126
127
128
129
  // Reset rounded corners
  > .btn:not(:last-child):not(.dropdown-toggle),
  > .btn-group:not(:last-child) > .btn {
    @include border-bottom-radius(0);
Mark Otto's avatar
Mark Otto committed
130
131
  }

ysds's avatar
ysds committed
132
133
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) > .btn {
Mark Otto's avatar
Mark Otto committed
134
    @include border-top-radius(0);
Mark Otto's avatar
derp    
Mark Otto committed
135
136
137
  }
}

138

139
// Checkbox and radio options
Mark Otto's avatar
Mark Otto committed
140
141
//
// In order to support the browser's form validation feedback, powered by the
142
143
144
145
// `required` attribute, we have to "hide" the inputs via `clip`. We cannot use
// `display: none;` or `visibility: hidden;` as that also hides the popover.
// Simply visually hiding the inputs via `opacity` would leave them clickable in
// certain cases which is prevented by using `clip` and `pointer-events`.
Mark Otto's avatar
Mark Otto committed
146
147
// This way, we ensure a DOM element is visible to position the popover from.
//
148
149
// See https://github.com/twbs/bootstrap/pull/12794 and
// https://github.com/twbs/bootstrap/pull/14559 for more information.
Mark Otto's avatar
Mark Otto committed
150

Mark Otto's avatar
Mark Otto committed
151
.btn-group-toggle {
152
153
  > .btn,
  > .btn-group > .btn {
154
155
    margin-bottom: 0; // Override default `<label>` value

156
157
158
    input[type="radio"],
    input[type="checkbox"] {
      position: absolute;
159
      clip: rect(0, 0, 0, 0);
160
      pointer-events: none;
161
162
    }
  }
163
}