_dropdown-button.scss 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // stylelint-disable selector-attribute-name-disallowed-list
  2. $separator: 1px solid theme('colors.white-15');
  3. $radius: theme('borderRadius.sm');
  4. .w-dropdown-button {
  5. // Cosmetic details based on live tooltip placement,
  6. // implemented CSS-only by using Tippy.js `data-placement` and `:has`.
  7. --primary-button-radius-top: #{$radius};
  8. --primary-button-radius-bottom: #{$radius};
  9. --toggle-button-radius-top: #{$radius};
  10. --toggle-button-radius-bottom: #{$radius};
  11. --first-item-border-top: 0;
  12. --last-item-border-top: 0;
  13. // Set each separately so a button that’s both first and last is correct.
  14. --first-item-start-start-radius: 0;
  15. --first-item-start-end-radius: 0;
  16. --last-item-end-start-radius: 0;
  17. --last-item-end-end-radius: 0;
  18. display: flex;
  19. // Make sure the tooltip within will match this element’s width.
  20. position: relative;
  21. [data-tippy-root] {
  22. // Make sure the tooltip within will match this element’s width.
  23. width: 100%;
  24. }
  25. @supports not selector(:has(*)) {
  26. // Use no corner radius and always-on borders if `:has` is not supported.
  27. --primary-button-radius-top: 0;
  28. --primary-button-radius-bottom: 0;
  29. --toggle-button-radius-top: 0;
  30. --toggle-button-radius-bottom: 0;
  31. --first-item-border-top: #{$separator};
  32. --last-item-border-top: #{$separator};
  33. }
  34. &:has(:not([hidden]) > [data-placement^='bottom']) {
  35. --primary-button-radius-top: #{$radius};
  36. --primary-button-radius-bottom: 0;
  37. --toggle-button-radius-top: #{$radius};
  38. --toggle-button-radius-bottom: 0;
  39. --last-item-end-start-radius: #{$radius};
  40. --last-item-end-end-radius: #{$radius};
  41. --first-item-border-top: #{$separator};
  42. }
  43. &:has(:not([hidden]) > [data-placement^='top']) {
  44. --primary-button-radius-top: 0;
  45. --primary-button-radius-bottom: #{$radius};
  46. --toggle-button-radius-top: 0;
  47. --toggle-button-radius-bottom: #{$radius};
  48. --first-item-start-start-radius: #{$radius};
  49. --first-item-start-end-radius: #{$radius};
  50. --last-item-border-bottom: #{$separator};
  51. }
  52. }
  53. // Primary button next to the dropdown toggle.
  54. .w-dropdown-button > :is(a, button) {
  55. border-start-start-radius: var(--primary-button-radius-top);
  56. border-start-end-radius: 0;
  57. border-end-start-radius: var(--primary-button-radius-bottom);
  58. border-end-end-radius: 0;
  59. min-height: $text-input-height;
  60. }
  61. .w-dropdown-button .button.w-dropdown__toggle {
  62. width: theme('spacing.8');
  63. height: $text-input-height;
  64. padding: 0 theme('spacing.2');
  65. background-color: theme('colors.surface-button-default');
  66. color: theme('colors.text-button');
  67. border-inline-start: $separator;
  68. border-start-start-radius: 0;
  69. border-start-end-radius: var(--toggle-button-radius-top);
  70. border-end-start-radius: 0;
  71. border-end-end-radius: var(--toggle-button-radius-bottom);
  72. &:is(:hover, :focus-visible) {
  73. background-color: theme('colors.surface-button-hover');
  74. }
  75. }
  76. .w-dropdown-button .w-dropdown__content {
  77. padding: 0;
  78. }
  79. // Use a generic selector to support all types of links / buttons.
  80. .w-dropdown-button .w-dropdown__content :is(a, button) {
  81. @include show-focus-outline-inside();
  82. height: auto;
  83. min-height: $text-input-height;
  84. margin: 0;
  85. white-space: normal;
  86. border-radius: 0;
  87. &:nth-child(n + 2) {
  88. border-top: $separator;
  89. }
  90. &:first-child {
  91. border-top: var(--first-item-border-top);
  92. border-start-start-radius: var(--first-item-start-start-radius);
  93. border-start-end-radius: var(--first-item-start-end-radius);
  94. }
  95. &:last-child {
  96. border-bottom: var(--last-item-border-bottom);
  97. border-end-start-radius: var(--last-item-end-start-radius);
  98. border-end-end-radius: var(--last-item-end-end-radius);
  99. }
  100. }
  101. .w-dropdown-button > .warning {
  102. + .w-dropdown .button {
  103. background-color: theme('colors.warning.100');
  104. border-color: $separator;
  105. }
  106. + .w-dropdown .w-dropdown__toggle {
  107. border-inline-end-color: theme('colors.warning.100');
  108. border-top-color: theme('colors.warning.100');
  109. border-bottom-color: theme('colors.warning.100');
  110. }
  111. }