locale.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use client'
  2. import { Menu, Transition } from '@headlessui/react'
  3. import { Fragment } from 'react'
  4. import { GlobeAltIcon } from '@heroicons/react/24/outline'
  5. type ISelectProps = {
  6. items: Array<{ value: string; name: string }>
  7. value?: string
  8. className?: string
  9. onChange?: (value: string) => void
  10. }
  11. export default function Select({
  12. items,
  13. value,
  14. onChange,
  15. }: ISelectProps) {
  16. const item = items.filter(item => item.value === value)[0]
  17. return (
  18. <div className="w-56 text-right">
  19. {/* <Menu as="div" className="relative inline-block text-left">
  20. <div>
  21. <Menu.Button className="inline-flex w-full h-[44px]justify-center items-center
  22. rounded-lg px-[10px] py-[6px]
  23. text-gray-900 text-[13px] font-medium
  24. border border-gray-200
  25. hover:bg-gray-100">
  26. <GlobeAltIcon className="w-5 h-5 mr-1" aria-hidden="true" />
  27. {item?.name}
  28. </Menu.Button>
  29. </div>
  30. <Transition
  31. as={Fragment}
  32. enter="transition ease-out duration-100"
  33. enterFrom="transform opacity-0 scale-95"
  34. enterTo="transform opacity-100 scale-100"
  35. leave="transition ease-in duration-75"
  36. leaveFrom="transform opacity-100 scale-100"
  37. leaveTo="transform opacity-0 scale-95"
  38. >
  39. <Menu.Items className="absolute right-0 mt-2 w-[200px] origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none z-10">
  40. <div className="px-1 py-1 ">
  41. {items.map((item) => {
  42. return <Menu.Item key={item.value}>
  43. {({ active }) => (
  44. <button
  45. className={`${active ? 'bg-gray-100' : ''
  46. } group flex w-full items-center rounded-lg px-3 py-2 text-sm text-gray-700`}
  47. onClick={(evt) => {
  48. evt.preventDefault()
  49. onChange && onChange(item.value)
  50. }}
  51. >
  52. {item.name}
  53. </button>
  54. )}
  55. </Menu.Item>
  56. })}
  57. </div>
  58. </Menu.Items>
  59. </Transition>
  60. </Menu> */}
  61. </div>
  62. )
  63. }
  64. export function InputSelect({
  65. items,
  66. value,
  67. onChange,
  68. }: ISelectProps) {
  69. const item = items.filter(item => item.value === value)[0]
  70. return (
  71. <div className="w-full">
  72. <Menu as="div" className="w-full">
  73. <div>
  74. <Menu.Button className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 sm:text-sm h-[38px] text-left">
  75. {item?.name}
  76. </Menu.Button>
  77. </div>
  78. <Transition
  79. as={Fragment}
  80. enter="transition ease-out duration-100"
  81. enterFrom="transform opacity-0 scale-95"
  82. enterTo="transform opacity-100 scale-100"
  83. leave="transition ease-in duration-75"
  84. leaveFrom="transform opacity-100 scale-100"
  85. leaveTo="transform opacity-0 scale-95"
  86. >
  87. <Menu.Items className="absolute right-0 mt-2 w-full origin-top-right divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none z-10">
  88. <div className="px-1 py-1 ">
  89. {items.map((item) => {
  90. return <Menu.Item key={item.value}>
  91. {({ active }) => (
  92. <button
  93. className={`${active ? 'bg-gray-100' : ''
  94. } group flex w-full items-center rounded-md px-2 py-2 text-sm`}
  95. onClick={() => {
  96. onChange && onChange(item.value)
  97. }}
  98. >
  99. {item.name}
  100. </button>
  101. )}
  102. </Menu.Item>
  103. })}
  104. </div>
  105. </Menu.Items>
  106. </Transition>
  107. </Menu>
  108. </div>
  109. )
  110. }