2
0

_dropdown-button.scss 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. &:has(:not([hidden]) > [data-placement^='bottom']) {
  26. --primary-button-radius-top: #{$radius};
  27. --primary-button-radius-bottom: 0;
  28. --toggle-button-radius-top: #{$radius};
  29. --toggle-button-radius-bottom: 0;
  30. --last-item-end-start-radius: #{$radius};
  31. --last-item-end-end-radius: #{$radius};
  32. --first-item-border-top: #{$separator};
  33. }
  34. &:has(:not([hidden]) > [data-placement^='top']) {
  35. --primary-button-radius-top: 0;
  36. --primary-button-radius-bottom: #{$radius};
  37. --toggle-button-radius-top: 0;
  38. --toggle-button-radius-bottom: #{$radius};
  39. --first-item-start-start-radius: #{$radius};
  40. --first-item-start-end-radius: #{$radius};
  41. --last-item-border-bottom: #{$separator};
  42. }
  43. }
  44. // Primary button next to the dropdown toggle.
  45. .w-dropdown-button > :is(a, button) {
  46. border-start-start-radius: var(--primary-button-radius-top);
  47. border-start-end-radius: 0;
  48. border-end-start-radius: var(--primary-button-radius-bottom);
  49. border-end-end-radius: 0;
  50. min-height: $text-input-height;
  51. }
  52. .w-dropdown-button .button.w-dropdown__toggle {
  53. width: theme('spacing.8');
  54. height: $text-input-height;
  55. padding: 0 theme('spacing.2');
  56. background-color: theme('colors.surface-button-default');
  57. color: theme('colors.text-button');
  58. border-inline-start: $separator;
  59. border-start-start-radius: 0;
  60. border-start-end-radius: var(--toggle-button-radius-top);
  61. border-end-start-radius: 0;
  62. border-end-end-radius: var(--toggle-button-radius-bottom);
  63. &:is(:hover, :focus-visible) {
  64. background-color: theme('colors.surface-button-hover');
  65. }
  66. }
  67. .w-dropdown-button .w-dropdown__content {
  68. padding: 0;
  69. }
  70. // Use a generic selector to support all types of links / buttons.
  71. .w-dropdown-button .w-dropdown__content :is(a, button) {
  72. @include show-focus-outline-inside();
  73. height: auto;
  74. min-height: $text-input-height;
  75. margin: 0;
  76. white-space: normal;
  77. border-radius: 0;
  78. &:nth-child(n + 2) {
  79. border-top: $separator;
  80. }
  81. &:first-child {
  82. border-top: var(--first-item-border-top);
  83. border-start-start-radius: var(--first-item-start-start-radius);
  84. border-start-end-radius: var(--first-item-start-end-radius);
  85. }
  86. &:last-child {
  87. border-bottom: var(--last-item-border-bottom);
  88. border-end-start-radius: var(--last-item-end-start-radius);
  89. border-end-end-radius: var(--last-item-end-end-radius);
  90. }
  91. }
  92. .w-dropdown-button > .warning {
  93. + .w-dropdown .button {
  94. background-color: theme('colors.warning.100');
  95. border-color: $separator;
  96. }
  97. + .w-dropdown .w-dropdown__toggle {
  98. border-inline-end-color: theme('colors.warning.100');
  99. border-top-color: theme('colors.warning.100');
  100. border-bottom-color: theme('colors.warning.100');
  101. }
  102. }