_list-group.scss 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // Base class
  2. //
  3. // Easily usable on <ul>, <ol>, or <div>.
  4. .list-group {
  5. // scss-docs-start list-group-css-vars
  6. --#{$prefix}list-group-color: #{$list-group-color};
  7. --#{$prefix}list-group-bg: #{$list-group-bg};
  8. --#{$prefix}list-group-border-color: #{$list-group-border-color};
  9. --#{$prefix}list-group-border-width: #{$list-group-border-width};
  10. --#{$prefix}list-group-border-radius: #{$list-group-border-radius};
  11. --#{$prefix}list-group-item-padding-x: #{$list-group-item-padding-x};
  12. --#{$prefix}list-group-item-padding-y: #{$list-group-item-padding-y};
  13. --#{$prefix}list-group-action-color: #{$list-group-action-color};
  14. --#{$prefix}list-group-action-hover-color: #{$list-group-action-hover-color};
  15. --#{$prefix}list-group-action-hover-bg: #{$list-group-hover-bg};
  16. --#{$prefix}list-group-action-active-color: #{$list-group-action-active-color};
  17. --#{$prefix}list-group-action-active-bg: #{$list-group-action-active-bg};
  18. --#{$prefix}list-group-disabled-color: #{$list-group-disabled-color};
  19. --#{$prefix}list-group-disabled-bg: #{$list-group-disabled-bg};
  20. --#{$prefix}list-group-active-color: #{$list-group-active-color};
  21. --#{$prefix}list-group-active-bg: #{$list-group-active-bg};
  22. --#{$prefix}list-group-active-border-color: #{$list-group-active-border-color};
  23. // scss-docs-end list-group-css-vars
  24. display: flex;
  25. flex-direction: column;
  26. // No need to set list-style: none; since .list-group-item is block level
  27. padding-left: 0; // reset padding because ul and ol
  28. margin-bottom: 0;
  29. @include border-radius(var(--#{$prefix}list-group-border-radius));
  30. }
  31. .list-group-numbered {
  32. list-style-type: none;
  33. counter-reset: section;
  34. > .list-group-item::before {
  35. // Increments only this instance of the section counter
  36. content: counters(section, ".") ". ";
  37. counter-increment: section;
  38. }
  39. }
  40. // Individual list items
  41. //
  42. // Use on `li`s or `div`s within the `.list-group` parent.
  43. .list-group-item {
  44. position: relative;
  45. display: block;
  46. padding: var(--#{$prefix}list-group-item-padding-y) var(--#{$prefix}list-group-item-padding-x);
  47. color: var(--#{$prefix}list-group-color);
  48. text-decoration: if($link-decoration == none, null, none);
  49. background-color: var(--#{$prefix}list-group-bg);
  50. border: var(--#{$prefix}list-group-border-width) solid var(--#{$prefix}list-group-border-color);
  51. &:first-child {
  52. @include border-top-radius(inherit);
  53. }
  54. &:last-child {
  55. @include border-bottom-radius(inherit);
  56. }
  57. &.disabled,
  58. &:disabled {
  59. color: var(--#{$prefix}list-group-disabled-color);
  60. pointer-events: none;
  61. background-color: var(--#{$prefix}list-group-disabled-bg);
  62. }
  63. // Include both here for `<a>`s and `<button>`s
  64. &.active {
  65. z-index: 2; // Place active items above their siblings for proper border styling
  66. color: var(--#{$prefix}list-group-active-color);
  67. background-color: var(--#{$prefix}list-group-active-bg);
  68. border-color: var(--#{$prefix}list-group-active-border-color);
  69. }
  70. // stylelint-disable-next-line scss/selector-no-redundant-nesting-selector
  71. & + .list-group-item {
  72. border-top-width: 0;
  73. &.active {
  74. margin-top: calc(-1 * var(--#{$prefix}list-group-border-width)); // stylelint-disable-line function-disallowed-list
  75. border-top-width: var(--#{$prefix}list-group-border-width);
  76. }
  77. }
  78. }
  79. // Interactive list items
  80. //
  81. // Use anchor or button elements instead of `li`s or `div`s to create interactive
  82. // list items. Includes an extra `.active` modifier class for selected items.
  83. .list-group-item-action {
  84. width: 100%; // For `<button>`s (anchors become 100% by default though)
  85. color: var(--#{$prefix}list-group-action-color);
  86. text-align: inherit; // For `<button>`s (anchors inherit)
  87. &:not(.active) {
  88. // Hover state
  89. &:hover,
  90. &:focus {
  91. z-index: 1; // Place hover/focus items above their siblings for proper border styling
  92. color: var(--#{$prefix}list-group-action-hover-color);
  93. text-decoration: none;
  94. background-color: var(--#{$prefix}list-group-action-hover-bg);
  95. }
  96. &:active {
  97. color: var(--#{$prefix}list-group-action-active-color);
  98. background-color: var(--#{$prefix}list-group-action-active-bg);
  99. }
  100. }
  101. }
  102. // Horizontal
  103. //
  104. // Change the layout of list group items from vertical (default) to horizontal.
  105. @each $breakpoint in map-keys($grid-breakpoints) {
  106. @include media-breakpoint-up($breakpoint) {
  107. $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
  108. .list-group-horizontal#{$infix} {
  109. flex-direction: row;
  110. > .list-group-item {
  111. &:first-child:not(:last-child) {
  112. @include border-bottom-start-radius(var(--#{$prefix}list-group-border-radius));
  113. @include border-top-end-radius(0);
  114. }
  115. &:last-child:not(:first-child) {
  116. @include border-top-end-radius(var(--#{$prefix}list-group-border-radius));
  117. @include border-bottom-start-radius(0);
  118. }
  119. &.active {
  120. margin-top: 0;
  121. }
  122. + .list-group-item {
  123. border-top-width: var(--#{$prefix}list-group-border-width);
  124. border-left-width: 0;
  125. &.active {
  126. margin-left: calc(-1 * var(--#{$prefix}list-group-border-width)); // stylelint-disable-line function-disallowed-list
  127. border-left-width: var(--#{$prefix}list-group-border-width);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. // Flush list items
  135. //
  136. // Remove borders and border-radius to keep list group items edge-to-edge. Most
  137. // useful within other components (e.g., cards).
  138. .list-group-flush {
  139. @include border-radius(0);
  140. > .list-group-item {
  141. border-width: 0 0 var(--#{$prefix}list-group-border-width);
  142. &:last-child {
  143. border-bottom-width: 0;
  144. }
  145. }
  146. }
  147. // scss-docs-start list-group-modifiers
  148. // List group contextual variants
  149. //
  150. // Add modifier classes to change text and background color on individual items.
  151. // Organizationally, this must come after the `:hover` states.
  152. @each $state in map-keys($theme-colors) {
  153. .list-group-item-#{$state} {
  154. --#{$prefix}list-group-color: var(--#{$prefix}#{$state}-text-emphasis);
  155. --#{$prefix}list-group-bg: var(--#{$prefix}#{$state}-bg-subtle);
  156. --#{$prefix}list-group-border-color: var(--#{$prefix}#{$state}-border-subtle);
  157. --#{$prefix}list-group-action-hover-color: var(--#{$prefix}emphasis-color);
  158. --#{$prefix}list-group-action-hover-bg: var(--#{$prefix}#{$state}-border-subtle);
  159. --#{$prefix}list-group-action-active-color: var(--#{$prefix}emphasis-color);
  160. --#{$prefix}list-group-action-active-bg: var(--#{$prefix}#{$state}-border-subtle);
  161. --#{$prefix}list-group-active-color: var(--#{$prefix}#{$state}-bg-subtle);
  162. --#{$prefix}list-group-active-bg: var(--#{$prefix}#{$state}-text-emphasis);
  163. --#{$prefix}list-group-active-border-color: var(--#{$prefix}#{$state}-text-emphasis);
  164. }
  165. }
  166. // scss-docs-end list-group-modifiers