2
0

_dropdown-button.scss 3.7 KB

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