_custom-forms.less 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. // Embedded icons from Open Iconic.
  2. // Released under MIT and copyright 2014 Waybury.
  3. // https://useiconic.com/open
  4. // Checkboxes and radios
  5. //
  6. // Base class takes care of all the key behavioral aspects.
  7. .custom-control {
  8. position: relative;
  9. z-index: 1;
  10. display: block;
  11. min-height: (@font-size-base * @line-height-base);
  12. padding-left: (@custom-control-gutter + @custom-control-indicator-size);
  13. color-adjust: exact; // Keep themed appearance for print
  14. }
  15. .custom-control-inline {
  16. display: inline-flex;
  17. margin-right: @custom-control-spacer-x;
  18. }
  19. .custom-control-input {
  20. position: absolute;
  21. left: 0;
  22. z-index: -1; // Put the input behind the label so it doesn't overlay text
  23. width: @custom-control-indicator-size;
  24. height: ((@font-size-base * @line-height-base + @custom-control-indicator-size) / 2);
  25. opacity: 0;
  26. &:checked ~ .custom-control-label::before {
  27. color: @custom-control-indicator-checked-color;
  28. border-color: @custom-control-indicator-checked-border-color;
  29. #gradient-bg(@custom-control-indicator-checked-bg);
  30. #box-shadow(@custom-control-indicator-checked-box-shadow);
  31. }
  32. &:focus ~ .custom-control-label::before {
  33. // the mixin is not used here to make sure there is feedback
  34. & when (@enable-shadows) {
  35. box-shadow: @input-box-shadow, @custom-control-indicator-focus-box-shadow;
  36. }
  37. & when not (@enable-shadows) {
  38. box-shadow: @custom-control-indicator-focus-box-shadow;
  39. }
  40. }
  41. &:focus:not(:checked) ~ .custom-control-label::before {
  42. border-color: @custom-control-indicator-focus-border-color;
  43. }
  44. &:not(:disabled):active ~ .custom-control-label::before {
  45. color: @custom-control-indicator-active-color;
  46. background-color: @custom-control-indicator-active-bg;
  47. border-color: @custom-control-indicator-active-border-color;
  48. #box-shadow(@custom-control-indicator-active-box-shadow);
  49. }
  50. // Use [disabled] and :disabled to work around https://github.com/twbs/bootstrap/issues/28247
  51. &[disabled],
  52. &:disabled {
  53. ~ .custom-control-label {
  54. color: @custom-control-label-disabled-color;
  55. &::before {
  56. background-color: @custom-control-indicator-disabled-bg;
  57. }
  58. }
  59. }
  60. }
  61. // Custom control indicators
  62. //
  63. // Build the custom controls out of pseudo-elements.
  64. .custom-control-label {
  65. position: relative;
  66. margin-bottom: 0;
  67. // LESS PORT: Less doesn’t strip “empty” property values so we have to check for a value first.
  68. & when not (@custom-control-label-color = ~"") { color: @custom-control-label-color; }
  69. vertical-align: top;
  70. // LESS PORT: Less doesn’t strip “empty” property values so we have to check for a value first.
  71. & when not (@custom-control-cursor = ~"") { cursor: @custom-control-cursor; }
  72. // Background-color and (when enabled) gradient
  73. &::before {
  74. position: absolute;
  75. top: ((@font-size-base * @line-height-base - @custom-control-indicator-size) / 2);
  76. left: -(@custom-control-gutter + @custom-control-indicator-size);
  77. display: block;
  78. width: @custom-control-indicator-size;
  79. height: @custom-control-indicator-size;
  80. pointer-events: none;
  81. content: "";
  82. background-color: @custom-control-indicator-bg;
  83. border: @custom-control-indicator-border-color solid @custom-control-indicator-border-width;
  84. #box-shadow(@custom-control-indicator-box-shadow);
  85. }
  86. // Foreground (icon)
  87. &::after {
  88. position: absolute;
  89. top: ((@font-size-base * @line-height-base - @custom-control-indicator-size) / 2);
  90. left: -(@custom-control-gutter + @custom-control-indicator-size);
  91. display: block;
  92. width: @custom-control-indicator-size;
  93. height: @custom-control-indicator-size;
  94. content: "";
  95. background: no-repeat 50% ~"/" @custom-control-indicator-bg-size;
  96. }
  97. }
  98. // Checkboxes
  99. //
  100. // Tweak just a few things for checkboxes.
  101. .custom-checkbox {
  102. .custom-control-label::before {
  103. #border-radius(@custom-checkbox-indicator-border-radius);
  104. }
  105. .custom-control-input:checked ~ .custom-control-label {
  106. &::after {
  107. background-image: escape-svg(@custom-checkbox-indicator-icon-checked);
  108. }
  109. }
  110. .custom-control-input:indeterminate ~ .custom-control-label {
  111. &::before {
  112. border-color: @custom-checkbox-indicator-indeterminate-border-color;
  113. #gradient-bg(@custom-checkbox-indicator-indeterminate-bg);
  114. #box-shadow(@custom-checkbox-indicator-indeterminate-box-shadow);
  115. }
  116. &::after {
  117. background-image: escape-svg(@custom-checkbox-indicator-icon-indeterminate);
  118. }
  119. }
  120. .custom-control-input:disabled {
  121. &:checked ~ .custom-control-label::before {
  122. #gradient-bg(@custom-control-indicator-checked-disabled-bg);
  123. }
  124. &:indeterminate ~ .custom-control-label::before {
  125. #gradient-bg(@custom-control-indicator-checked-disabled-bg);
  126. }
  127. }
  128. }
  129. // Radios
  130. //
  131. // Tweak just a few things for radios.
  132. .custom-radio {
  133. .custom-control-label::before {
  134. border-radius: @custom-radio-indicator-border-radius;
  135. }
  136. .custom-control-input:checked ~ .custom-control-label {
  137. &::after {
  138. background-image: escape-svg(@custom-radio-indicator-icon-checked);
  139. }
  140. }
  141. .custom-control-input:disabled {
  142. &:checked ~ .custom-control-label::before {
  143. #gradient-bg(@custom-control-indicator-checked-disabled-bg);
  144. }
  145. }
  146. }
  147. // switches
  148. //
  149. // Tweak a few things for switches
  150. .custom-switch {
  151. padding-left: (@custom-switch-width + @custom-control-gutter);
  152. .custom-control-label {
  153. &::before {
  154. left: -(@custom-switch-width + @custom-control-gutter);
  155. width: @custom-switch-width;
  156. pointer-events: all;
  157. border-radius: @custom-switch-indicator-border-radius;
  158. }
  159. &::after {
  160. // LESS PORT: Using format strings here so we can put computed values in the `calc()`.
  161. top: add(((@font-size-base * @line-height-base - @custom-control-indicator-size) / 2), (@custom-control-indicator-border-width * 2));
  162. left: add(-(@custom-switch-width + @custom-control-gutter), (@custom-control-indicator-border-width * 2));
  163. width: @custom-switch-indicator-size;
  164. height: @custom-switch-indicator-size;
  165. background-color: @custom-control-indicator-border-color;
  166. border-radius: @custom-switch-indicator-border-radius;
  167. #transition(transform 0.15s ease-in-out, @custom-forms-transition);
  168. }
  169. }
  170. .custom-control-input:checked ~ .custom-control-label {
  171. &::after {
  172. background-color: @custom-control-indicator-bg;
  173. transform: translateX((@custom-switch-width - @custom-control-indicator-size));
  174. }
  175. }
  176. .custom-control-input:disabled {
  177. &:checked ~ .custom-control-label::before {
  178. #gradient-bg(@custom-control-indicator-checked-disabled-bg);
  179. }
  180. }
  181. }
  182. // Select
  183. //
  184. // Replaces the browser default select with a custom one, mostly pulled from
  185. // https://primer.github.io/.
  186. //
  187. .custom-select {
  188. display: inline-block;
  189. width: 100%;
  190. height: @custom-select-height;
  191. padding: @custom-select-padding-y (@custom-select-padding-x + @custom-select-indicator-padding) @custom-select-padding-y @custom-select-padding-x;
  192. // LESS PORT: Less doesn’t strip “empty” property values so we have to check for a value first.
  193. & when not (@custom-select-font-family = ~"") { font-family: @custom-select-font-family; }
  194. #font-size(@custom-select-font-size);
  195. font-weight: @custom-select-font-weight;
  196. line-height: @custom-select-line-height;
  197. color: @custom-select-color;
  198. vertical-align: middle;
  199. background: @custom-select-bg @custom-select-background;
  200. border: @custom-select-border-width solid @custom-select-border-color;
  201. #border-radius(@custom-select-border-radius, 0);
  202. #box-shadow(@custom-select-box-shadow);
  203. appearance: none;
  204. &:focus {
  205. border-color: @custom-select-focus-border-color;
  206. outline: 0;
  207. & when (@enable-shadows) {
  208. #box-shadow(@custom-select-box-shadow, @custom-select-focus-box-shadow);
  209. }
  210. & when not (@enable-shadows) {
  211. // Avoid using mixin so we can pass custom focus shadow properly
  212. box-shadow: @custom-select-focus-box-shadow;
  213. }
  214. &::-ms-value {
  215. // For visual consistency with other platforms/browsers,
  216. // suppress the default white text on blue background highlight given to
  217. // the selected option text when the (still closed) <select> receives focus
  218. // in IE and (under certain conditions) Edge.
  219. // See https://github.com/twbs/bootstrap/issues/19398.
  220. color: @input-color;
  221. background-color: @input-bg;
  222. }
  223. }
  224. &[multiple],
  225. &[size]:not([size="1"]) {
  226. height: auto;
  227. padding-right: @custom-select-padding-x;
  228. background-image: none;
  229. }
  230. &:disabled {
  231. color: @custom-select-disabled-color;
  232. background-color: @custom-select-disabled-bg;
  233. }
  234. // Hides the default caret in IE11
  235. &::-ms-expand {
  236. display: none;
  237. }
  238. // Remove outline from select box in FF
  239. &:-moz-focusring {
  240. color: transparent;
  241. text-shadow: 0 0 0 @custom-select-color;
  242. }
  243. }
  244. .custom-select-sm {
  245. height: @custom-select-height-sm;
  246. padding-top: @custom-select-padding-y-sm;
  247. padding-bottom: @custom-select-padding-y-sm;
  248. padding-left: @custom-select-padding-x-sm;
  249. #font-size(@custom-select-font-size-sm);
  250. }
  251. .custom-select-lg {
  252. height: @custom-select-height-lg;
  253. padding-top: @custom-select-padding-y-lg;
  254. padding-bottom: @custom-select-padding-y-lg;
  255. padding-left: @custom-select-padding-x-lg;
  256. #font-size(@custom-select-font-size-lg);
  257. }
  258. // File
  259. //
  260. // Custom file input.
  261. .custom-file {
  262. position: relative;
  263. display: inline-block;
  264. width: 100%;
  265. height: @custom-file-height;
  266. margin-bottom: 0;
  267. }
  268. .custom-file-input {
  269. position: relative;
  270. z-index: 2;
  271. width: 100%;
  272. height: @custom-file-height;
  273. margin: 0;
  274. opacity: 0;
  275. &:focus ~ .custom-file-label {
  276. border-color: @custom-file-focus-border-color;
  277. box-shadow: @custom-file-focus-box-shadow;
  278. }
  279. // Use [disabled] and :disabled to work around https://github.com/twbs/bootstrap/issues/28247
  280. &[disabled] ~ .custom-file-label,
  281. &:disabled ~ .custom-file-label {
  282. background-color: @custom-file-disabled-bg;
  283. }
  284. each(@custom-file-text, #(@value, @lang) {
  285. &:lang(@{lang}) ~ .custom-file-label::after {
  286. content: @value;
  287. }
  288. });
  289. ~ .custom-file-label[data-browse]::after {
  290. content: attr(data-browse);
  291. }
  292. }
  293. .custom-file-label {
  294. position: absolute;
  295. top: 0;
  296. right: 0;
  297. left: 0;
  298. z-index: 1;
  299. height: @custom-file-height;
  300. padding: @custom-file-padding-y @custom-file-padding-x;
  301. // LESS PORT: Less doesn’t strip “empty” property values so we have to check for a value first.
  302. & when not (@custom-file-font-family = ~"") { font-family: @custom-file-font-family; }
  303. font-weight: @custom-file-font-weight;
  304. line-height: @custom-file-line-height;
  305. color: @custom-file-color;
  306. background-color: @custom-file-bg;
  307. border: @custom-file-border-width solid @custom-file-border-color;
  308. #border-radius(@custom-file-border-radius);
  309. #box-shadow(@custom-file-box-shadow);
  310. &::after {
  311. position: absolute;
  312. top: 0;
  313. right: 0;
  314. bottom: 0;
  315. z-index: 3;
  316. display: block;
  317. height: @custom-file-height-inner;
  318. padding: @custom-file-padding-y @custom-file-padding-x;
  319. line-height: @custom-file-line-height;
  320. color: @custom-file-button-color;
  321. content: "Browse";
  322. #gradient-bg(@custom-file-button-bg);
  323. border-left: inherit;
  324. #border-radius(0 @custom-file-border-radius @custom-file-border-radius 0);
  325. }
  326. }
  327. // Range
  328. //
  329. // Style range inputs the same across browsers. Vendor-specific rules for pseudo
  330. // elements cannot be mixed. As such, there are no shared styles for focus or
  331. // active states on prefixed selectors.
  332. .custom-range {
  333. width: 100%;
  334. height: add(@custom-range-thumb-height, (@custom-range-thumb-focus-box-shadow-width * 2));
  335. padding: 0; // Need to reset padding
  336. background-color: transparent;
  337. appearance: none;
  338. &:focus {
  339. outline: none;
  340. // Pseudo-elements must be split across multiple rulesets to have an effect.
  341. // No box-shadow() mixin for focus accessibility.
  342. &::-webkit-slider-thumb { box-shadow: @custom-range-thumb-focus-box-shadow; }
  343. &::-moz-range-thumb { box-shadow: @custom-range-thumb-focus-box-shadow; }
  344. &::-ms-thumb { box-shadow: @custom-range-thumb-focus-box-shadow; }
  345. }
  346. &::-moz-focus-outer {
  347. border: 0;
  348. }
  349. &::-webkit-slider-thumb {
  350. width: @custom-range-thumb-width;
  351. height: @custom-range-thumb-height;
  352. margin-top: ((@custom-range-track-height - @custom-range-thumb-height) / 2); // Webkit specific
  353. #gradient-bg(@custom-range-thumb-bg);
  354. border: @custom-range-thumb-border;
  355. #border-radius(@custom-range-thumb-border-radius);
  356. #box-shadow(@custom-range-thumb-box-shadow);
  357. #transition(@custom-forms-transition);
  358. appearance: none;
  359. &:active {
  360. #gradient-bg(@custom-range-thumb-active-bg);
  361. }
  362. }
  363. &::-webkit-slider-runnable-track {
  364. width: @custom-range-track-width;
  365. height: @custom-range-track-height;
  366. color: transparent; // Why?
  367. cursor: @custom-range-track-cursor;
  368. background-color: @custom-range-track-bg;
  369. border-color: transparent;
  370. #border-radius(@custom-range-track-border-radius);
  371. #box-shadow(@custom-range-track-box-shadow);
  372. }
  373. &::-moz-range-thumb {
  374. width: @custom-range-thumb-width;
  375. height: @custom-range-thumb-height;
  376. #gradient-bg(@custom-range-thumb-bg);
  377. border: @custom-range-thumb-border;
  378. #border-radius(@custom-range-thumb-border-radius);
  379. #box-shadow(@custom-range-thumb-box-shadow);
  380. #transition(@custom-forms-transition);
  381. appearance: none;
  382. &:active {
  383. #gradient-bg(@custom-range-thumb-active-bg);
  384. }
  385. }
  386. &::-moz-range-track {
  387. width: @custom-range-track-width;
  388. height: @custom-range-track-height;
  389. color: transparent;
  390. cursor: @custom-range-track-cursor;
  391. background-color: @custom-range-track-bg;
  392. border-color: transparent; // Firefox specific?
  393. #border-radius(@custom-range-track-border-radius);
  394. #box-shadow(@custom-range-track-box-shadow);
  395. }
  396. &::-ms-thumb {
  397. width: @custom-range-thumb-width;
  398. height: @custom-range-thumb-height;
  399. margin-top: 0; // Edge specific
  400. margin-right: @custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
  401. margin-left: @custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
  402. #gradient-bg(@custom-range-thumb-bg);
  403. border: @custom-range-thumb-border;
  404. #border-radius(@custom-range-thumb-border-radius);
  405. #box-shadow(@custom-range-thumb-box-shadow);
  406. #transition(@custom-forms-transition);
  407. appearance: none;
  408. &:active {
  409. #gradient-bg(@custom-range-thumb-active-bg);
  410. }
  411. }
  412. &::-ms-track {
  413. width: @custom-range-track-width;
  414. height: @custom-range-track-height;
  415. color: transparent;
  416. cursor: @custom-range-track-cursor;
  417. background-color: transparent;
  418. border-color: transparent;
  419. border-width: (@custom-range-thumb-height / 2);
  420. #box-shadow(@custom-range-track-box-shadow);
  421. }
  422. &::-ms-fill-lower {
  423. background-color: @custom-range-track-bg;
  424. #border-radius(@custom-range-track-border-radius);
  425. }
  426. &::-ms-fill-upper {
  427. margin-right: 15px; // arbitrary?
  428. background-color: @custom-range-track-bg;
  429. #border-radius(@custom-range-track-border-radius);
  430. }
  431. &:disabled {
  432. &::-webkit-slider-thumb {
  433. background-color: @custom-range-thumb-disabled-bg;
  434. }
  435. &::-webkit-slider-runnable-track {
  436. cursor: default;
  437. }
  438. &::-moz-range-thumb {
  439. background-color: @custom-range-thumb-disabled-bg;
  440. }
  441. &::-moz-range-track {
  442. cursor: default;
  443. }
  444. &::-ms-thumb {
  445. background-color: @custom-range-thumb-disabled-bg;
  446. }
  447. }
  448. }
  449. .custom-control-label::before,
  450. .custom-file-label,
  451. .custom-select {
  452. #transition(@custom-forms-transition);
  453. }