_modal.scss 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // stylelint-disable function-disallowed-list
  2. // .modal-open - body class for killing the scroll
  3. // .modal - container to scroll within
  4. // .modal-dialog - positioning shell for the actual modal
  5. // .modal-content - actual modal w/ bg and corners and stuff
  6. // Container that the modal scrolls within
  7. .modal {
  8. // scss-docs-start modal-css-vars
  9. --#{$prefix}modal-zindex: #{$zindex-modal};
  10. --#{$prefix}modal-width: #{$modal-md};
  11. --#{$prefix}modal-padding: #{$modal-inner-padding};
  12. --#{$prefix}modal-margin: #{$modal-dialog-margin};
  13. --#{$prefix}modal-color: #{$modal-content-color};
  14. --#{$prefix}modal-bg: #{$modal-content-bg};
  15. --#{$prefix}modal-border-color: #{$modal-content-border-color};
  16. --#{$prefix}modal-border-width: #{$modal-content-border-width};
  17. --#{$prefix}modal-border-radius: #{$modal-content-border-radius};
  18. --#{$prefix}modal-box-shadow: #{$modal-content-box-shadow-xs};
  19. --#{$prefix}modal-inner-border-radius: #{$modal-content-inner-border-radius};
  20. --#{$prefix}modal-header-padding-x: #{$modal-header-padding-x};
  21. --#{$prefix}modal-header-padding-y: #{$modal-header-padding-y};
  22. --#{$prefix}modal-header-padding: #{$modal-header-padding}; // Todo in v6: Split this padding into x and y
  23. --#{$prefix}modal-header-border-color: #{$modal-header-border-color};
  24. --#{$prefix}modal-header-border-width: #{$modal-header-border-width};
  25. --#{$prefix}modal-title-line-height: #{$modal-title-line-height};
  26. --#{$prefix}modal-footer-gap: #{$modal-footer-margin-between};
  27. --#{$prefix}modal-footer-bg: #{$modal-footer-bg};
  28. --#{$prefix}modal-footer-border-color: #{$modal-footer-border-color};
  29. --#{$prefix}modal-footer-border-width: #{$modal-footer-border-width};
  30. // scss-docs-end modal-css-vars
  31. position: fixed;
  32. top: 0;
  33. left: 0;
  34. z-index: var(--#{$prefix}modal-zindex);
  35. display: none;
  36. width: 100%;
  37. height: 100%;
  38. overflow-x: hidden;
  39. overflow-y: auto;
  40. // Prevent Chrome on Windows from adding a focus outline. For details, see
  41. // https://github.com/twbs/bootstrap/pull/10951.
  42. outline: 0;
  43. // We deliberately don't use `-webkit-overflow-scrolling: touch;` due to a
  44. // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
  45. // See also https://github.com/twbs/bootstrap/issues/17695
  46. }
  47. // Shell div to position the modal with bottom padding
  48. .modal-dialog {
  49. position: relative;
  50. width: auto;
  51. margin: var(--#{$prefix}modal-margin);
  52. // allow clicks to pass through for custom click handling to close modal
  53. pointer-events: none;
  54. // When fading in the modal, animate it to slide down
  55. .modal.fade & {
  56. transform: $modal-fade-transform;
  57. @include transition($modal-transition);
  58. }
  59. .modal.show & {
  60. transform: $modal-show-transform;
  61. }
  62. // When trying to close, animate focus to scale
  63. .modal.modal-static & {
  64. transform: $modal-scale-transform;
  65. }
  66. }
  67. .modal-dialog-scrollable {
  68. height: calc(100% - var(--#{$prefix}modal-margin) * 2);
  69. .modal-content {
  70. max-height: 100%;
  71. overflow: hidden;
  72. }
  73. .modal-body {
  74. overflow-y: auto;
  75. }
  76. }
  77. .modal-dialog-centered {
  78. display: flex;
  79. align-items: center;
  80. min-height: calc(100% - var(--#{$prefix}modal-margin) * 2);
  81. }
  82. // Actual modal
  83. .modal-content {
  84. position: relative;
  85. display: flex;
  86. flex-direction: column;
  87. width: 100%; // Ensure `.modal-content` extends the full width of the parent `.modal-dialog`
  88. // counteract the pointer-events: none; in the .modal-dialog
  89. color: var(--#{$prefix}modal-color);
  90. pointer-events: auto;
  91. background-color: var(--#{$prefix}modal-bg);
  92. background-clip: padding-box;
  93. border: var(--#{$prefix}modal-border-width) solid var(--#{$prefix}modal-border-color);
  94. @include border-radius(var(--#{$prefix}modal-border-radius));
  95. @include box-shadow(var(--#{$prefix}modal-box-shadow));
  96. // Remove focus outline from opened modal
  97. outline: 0;
  98. }
  99. // Modal background
  100. .modal-backdrop {
  101. // scss-docs-start modal-backdrop-css-vars
  102. --#{$prefix}backdrop-zindex: #{$zindex-modal-backdrop};
  103. --#{$prefix}backdrop-bg: #{$modal-backdrop-bg};
  104. --#{$prefix}backdrop-opacity: #{$modal-backdrop-opacity};
  105. // scss-docs-end modal-backdrop-css-vars
  106. @include overlay-backdrop(var(--#{$prefix}backdrop-zindex), var(--#{$prefix}backdrop-bg), var(--#{$prefix}backdrop-opacity));
  107. }
  108. // Modal header
  109. // Top section of the modal w/ title and dismiss
  110. .modal-header {
  111. display: flex;
  112. flex-shrink: 0;
  113. align-items: center;
  114. padding: var(--#{$prefix}modal-header-padding);
  115. border-bottom: var(--#{$prefix}modal-header-border-width) solid var(--#{$prefix}modal-header-border-color);
  116. @include border-top-radius(var(--#{$prefix}modal-inner-border-radius));
  117. .btn-close {
  118. padding: calc(var(--#{$prefix}modal-header-padding-y) * .5) calc(var(--#{$prefix}modal-header-padding-x) * .5);
  119. // Split properties to avoid invalid calc() function if value is 0
  120. margin-top: calc(-.5 * var(--#{$prefix}modal-header-padding-y));
  121. margin-right: calc(-.5 * var(--#{$prefix}modal-header-padding-x));
  122. margin-bottom: calc(-.5 * var(--#{$prefix}modal-header-padding-y));
  123. margin-left: auto;
  124. }
  125. }
  126. // Title text within header
  127. .modal-title {
  128. margin-bottom: 0;
  129. line-height: var(--#{$prefix}modal-title-line-height);
  130. }
  131. // Modal body
  132. // Where all modal content resides (sibling of .modal-header and .modal-footer)
  133. .modal-body {
  134. position: relative;
  135. // Enable `flex-grow: 1` so that the body take up as much space as possible
  136. // when there should be a fixed height on `.modal-dialog`.
  137. flex: 1 1 auto;
  138. padding: var(--#{$prefix}modal-padding);
  139. }
  140. // Footer (for actions)
  141. .modal-footer {
  142. display: flex;
  143. flex-shrink: 0;
  144. flex-wrap: wrap;
  145. align-items: center; // vertically center
  146. justify-content: flex-end; // Right align buttons with flex property because text-align doesn't work on flex items
  147. padding: calc(var(--#{$prefix}modal-padding) - var(--#{$prefix}modal-footer-gap) * .5);
  148. background-color: var(--#{$prefix}modal-footer-bg);
  149. border-top: var(--#{$prefix}modal-footer-border-width) solid var(--#{$prefix}modal-footer-border-color);
  150. @include border-bottom-radius(var(--#{$prefix}modal-inner-border-radius));
  151. // Place margin between footer elements
  152. // This solution is far from ideal because of the universal selector usage,
  153. // but is needed to fix https://github.com/twbs/bootstrap/issues/24800
  154. > * {
  155. margin: calc(var(--#{$prefix}modal-footer-gap) * .5); // Todo in v6: replace with gap on parent class
  156. }
  157. }
  158. // Scale up the modal
  159. @include media-breakpoint-up(sm) {
  160. .modal {
  161. --#{$prefix}modal-margin: #{$modal-dialog-margin-y-sm-up};
  162. --#{$prefix}modal-box-shadow: #{$modal-content-box-shadow-sm-up};
  163. }
  164. // Automatically set modal's width for larger viewports
  165. .modal-dialog {
  166. max-width: var(--#{$prefix}modal-width);
  167. margin-right: auto;
  168. margin-left: auto;
  169. }
  170. .modal-sm {
  171. --#{$prefix}modal-width: #{$modal-sm};
  172. }
  173. }
  174. @include media-breakpoint-up(lg) {
  175. .modal-lg,
  176. .modal-xl {
  177. --#{$prefix}modal-width: #{$modal-lg};
  178. }
  179. }
  180. @include media-breakpoint-up(xl) {
  181. .modal-xl {
  182. --#{$prefix}modal-width: #{$modal-xl};
  183. }
  184. }
  185. // scss-docs-start modal-fullscreen-loop
  186. @each $breakpoint in map-keys($grid-breakpoints) {
  187. $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
  188. $postfix: if($infix != "", $infix + "-down", "");
  189. @include media-breakpoint-down($breakpoint) {
  190. .modal-fullscreen#{$postfix} {
  191. width: 100vw;
  192. max-width: none;
  193. height: 100%;
  194. margin: 0;
  195. .modal-content {
  196. height: 100%;
  197. border: 0;
  198. @include border-radius(0);
  199. }
  200. .modal-header,
  201. .modal-footer {
  202. @include border-radius(0);
  203. }
  204. .modal-body {
  205. overflow-y: auto;
  206. }
  207. }
  208. }
  209. }
  210. // scss-docs-end modal-fullscreen-loop