Dropdown.styled.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import styled, { css, keyframes } from 'styled-components';
  2. import { ControlledMenu } from '@szhsin/react-menu';
  3. import { menuSelector, menuItemSelector } from '@szhsin/react-menu/style-utils';
  4. import '@szhsin/react-menu/dist/core.css';
  5. const menuShow = keyframes`
  6. from {
  7. opacity: 0;
  8. }
  9. `;
  10. const menuHide = keyframes`
  11. to {
  12. opacity: 0;
  13. }
  14. `;
  15. export const Dropdown = styled(ControlledMenu)(
  16. ({ theme: { dropdown } }) => css`
  17. // container for the menu items
  18. ${menuSelector.name} {
  19. border: 1px solid ${dropdown.borderColor};
  20. box-shadow: 0 4px 16px ${dropdown.shadow};
  21. padding: 8px 0;
  22. border-radius: 4px;
  23. font-size: 14px;
  24. background-color: ${dropdown.backgroundColor};
  25. text-align: left;
  26. }
  27. ${menuSelector.stateOpening} {
  28. animation: ${menuShow} 0.15s ease-out;
  29. }
  30. // NOTE: animation-fill-mode: forwards is required to
  31. // prevent flickering with React 18 createRoot()
  32. ${menuSelector.stateClosing} {
  33. animation: ${menuHide} 0.2s ease-out forwards;
  34. }
  35. ${menuItemSelector.name} {
  36. padding: 6px 16px;
  37. min-width: 150px;
  38. background-color: ${dropdown.item.backgroundColor.default};
  39. white-space: nowrap;
  40. }
  41. ${menuItemSelector.hover} {
  42. background-color: ${dropdown.item.backgroundColor.hover};
  43. }
  44. ${menuItemSelector.disabled} {
  45. cursor: not-allowed;
  46. opacity: 0.5;
  47. }
  48. `
  49. );
  50. export const DropdownButton = styled.button`
  51. background-color: transparent;
  52. border: none;
  53. display: flex;
  54. cursor: pointer;
  55. align-self: center;
  56. &:disabled {
  57. opacity: 0.5;
  58. cursor: not-allowed;
  59. }
  60. `;
  61. export const DangerItem = styled.div`
  62. color: ${({ theme: { dropdown } }) => dropdown.item.color.danger};
  63. `;
  64. export const DropdownItemHint = styled.div`
  65. color: ${({ theme }) => theme.topicMetaData.color.label};
  66. font-size: 12px;
  67. line-height: 1.4;
  68. margin-top: 5px;
  69. `;
  70. export const Wrapper = styled.div`
  71. display: inline-flex;
  72. align-items: center;
  73. justify-content: end;
  74. color: ${({ theme: { dropdown } }) => dropdown.item.color.normal};
  75. `;