_button-group.scss 3.65 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;
Mark Otto's avatar
Mark Otto committed
12
    flex: 0 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

Mark Otto's avatar
Mark Otto committed
26
  // Prevent double borders when buttons are next to each other
Mark Otto's avatar
derp    
Mark Otto committed
27
28
29
30
  .btn + .btn,
  .btn + .btn-group,
  .btn-group + .btn,
  .btn-group + .btn-group {
31
    margin-left: -$btn-border-width;
Mark Otto's avatar
derp    
Mark Otto committed
32
  }
33
34
}

35
// Optional: Group multiple button groups together for a toolbar
36
.btn-toolbar {
Mark Otto's avatar
Mark Otto committed
37
  display: flex;
38
  flex-wrap: wrap;
Mark Otto's avatar
Mark Otto committed
39
  justify-content: flex-start;
40
41
42
43

  .input-group {
    width: auto;
  }
44
45
}

46
47
48
49
50
.btn-group {
  > .btn:first-child {
    margin-left: 0;
  }

ysds's avatar
ysds committed
51
52
53
54
  // Reset rounded corners
  > .btn:not(:last-child):not(.dropdown-toggle),
  > .btn-group:not(:last-child) > .btn {
    @include border-right-radius(0);
55
  }
56

ysds's avatar
ysds committed
57
58
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) > .btn {
59
60
61
    @include border-left-radius(0);
  }
}
62

63
64
65
66
// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

Mark Otto's avatar
Mark Otto committed
67
68
.btn-group-sm > .btn { @extend .btn-sm; }
.btn-group-lg > .btn { @extend .btn-lg; }
69

70

Mark Otto's avatar
Mark Otto committed
71
//
72
// Split button dropdowns
Mark Otto's avatar
Mark Otto committed
73
//
74

Mark Otto's avatar
Mark Otto committed
75
.dropdown-toggle-split {
76
77
  padding-right: $btn-padding-x * .75;
  padding-left: $btn-padding-x * .75;
78

ysds's avatar
ysds committed
79
80
81
  &::after,
  .dropup &::after,
  .dropright &::after {
82
    margin-left: 0;
83
  }
ysds's avatar
ysds committed
84
85
86
87

  .dropleft &::before {
    margin-right: 0;
  }
88
}
89

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

.btn-lg + .dropdown-toggle-split {
96
97
  padding-right: $btn-padding-x-lg * .75;
  padding-left: $btn-padding-x-lg * .75;
98
99
100
}


101
// The clickable button for toggling the menu
102
103
// Set the same inset shadow as the :active state
.btn-group.show .dropdown-toggle {
104
  @include box-shadow($btn-active-box-shadow);
105
106
107

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

Mark Otto's avatar
Mark Otto committed
112

Mark Otto's avatar
Mark Otto committed
113
//
114
// Vertical button groups
Mark Otto's avatar
Mark Otto committed
115
//
116

Mark Otto's avatar
derp    
Mark Otto committed
117
.btn-group-vertical {
Mark Otto's avatar
Mark Otto committed
118
119
  flex-direction: column;
  align-items: flex-start;
Mark Otto's avatar
linting    
Mark Otto committed
120
  justify-content: center;
Mark Otto's avatar
Mark Otto committed
121
122
123

  .btn,
  .btn-group {
124
    width: 100%;
125
126
127
128
129
130
  }

  > .btn + .btn,
  > .btn + .btn-group,
  > .btn-group + .btn,
  > .btn-group + .btn-group {
131
    margin-top: -$btn-border-width;
Mark Otto's avatar
derp    
Mark Otto committed
132
    margin-left: 0;
133
  }
Mark Otto's avatar
derp    
Mark Otto committed
134

ysds's avatar
ysds committed
135
136
137
138
  // 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
139
140
  }

ysds's avatar
ysds committed
141
142
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) > .btn {
Mark Otto's avatar
Mark Otto committed
143
    @include border-top-radius(0);
Mark Otto's avatar
derp    
Mark Otto committed
144
145
146
  }
}

147

148
// Checkbox and radio options
Mark Otto's avatar
Mark Otto committed
149
150
//
// In order to support the browser's form validation feedback, powered by the
151
152
153
154
// `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
155
156
// This way, we ensure a DOM element is visible to position the popover from.
//
157
158
// 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
159

Mark Otto's avatar
Mark Otto committed
160
.btn-group-toggle {
161
162
  > .btn,
  > .btn-group > .btn {
163
164
    margin-bottom: 0; // Override default `<label>` value

165
166
167
    input[type="radio"],
    input[type="checkbox"] {
      position: absolute;
168
      clip: rect(0, 0, 0, 0);
169
      pointer-events: none;
170
171
    }
  }
172
}