dropdown-menu.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { forwardRef } from 'react'
  2. import {
  3. Dropdown as BS5Dropdown,
  4. DropdownToggle as BS5DropdownToggle,
  5. DropdownMenu as BS5DropdownMenu,
  6. DropdownItem as BS5DropdownItem,
  7. DropdownDivider as BS5DropdownDivider,
  8. } from 'react-bootstrap-5'
  9. import type {
  10. DropdownProps,
  11. DropdownItemProps,
  12. DropdownToggleProps,
  13. DropdownMenuProps,
  14. } from '@/features/ui/components/types/dropdown-menu-props'
  15. import MaterialIcon from '@/shared/components/material-icon'
  16. export function Dropdown({ ...props }: DropdownProps) {
  17. return <BS5Dropdown {...props} />
  18. }
  19. export const DropdownItem = forwardRef<
  20. typeof BS5DropdownItem,
  21. DropdownItemProps
  22. >(
  23. (
  24. { active, children, description, leadingIcon, trailingIcon, ...props },
  25. ref
  26. ) => {
  27. const trailingIconType = active ? 'check' : trailingIcon
  28. return (
  29. <BS5DropdownItem
  30. active={active}
  31. className={description ? 'dropdown-item-description-container' : ''}
  32. role="menuitem"
  33. {...props}
  34. ref={ref}
  35. >
  36. {leadingIcon && (
  37. <MaterialIcon
  38. className="dropdown-item-leading-icon"
  39. type={leadingIcon}
  40. />
  41. )}
  42. {children}
  43. {trailingIconType && (
  44. <MaterialIcon
  45. className="dropdown-item-trailing-icon"
  46. type={trailingIconType}
  47. />
  48. )}
  49. {description && (
  50. <span className="dropdown-item-description">{description}</span>
  51. )}
  52. </BS5DropdownItem>
  53. )
  54. }
  55. )
  56. DropdownItem.displayName = 'DropdownItem'
  57. export function DropdownToggle({ ...props }: DropdownToggleProps) {
  58. return <BS5DropdownToggle {...props} />
  59. }
  60. export function DropdownMenu({ as = 'ul', ...props }: DropdownMenuProps) {
  61. return <BS5DropdownMenu as={as} role="menubar" {...props} />
  62. }
  63. export function DropdownDivider() {
  64. return <BS5DropdownDivider aria-hidden="true" />
  65. }