|
| 1 | +import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react"; |
| 2 | +import PropTypes from "prop-types"; |
| 3 | +import Toggle from "./Toggle"; |
| 4 | +import SettingsGearButton from "./SettingsGearButton"; |
| 5 | + |
| 6 | +export default function SettingsMenu({ |
| 7 | + cacheEnabled, |
| 8 | + setCacheEnabled, |
| 9 | + sortAscending, |
| 10 | + setSortAscending, |
| 11 | + active, |
| 12 | +}) { |
| 13 | + return ( |
| 14 | + <Menu as="div" className="relative inline-block text-left"> |
| 15 | + <MenuButton as={SettingsGearButton} active={active} /> |
| 16 | + <MenuItems className="absolute right-0 z-10 mt-2 w-72 rounded-md border border-slate-200 bg-white p-4 shadow-lg focus:outline-none"> |
| 17 | + <MenuItem> |
| 18 | + <div className="flex items-start justify-between gap-4"> |
| 19 | + <div> |
| 20 | + <div className="text-sm font-semibold text-slate-900">Enable cache</div> |
| 21 | + <p className="text-xs text-slate-600"> |
| 22 | + Use browser cache for repeated requests. Disable to force fresh fetches. |
| 23 | + </p> |
| 24 | + </div> |
| 25 | + <Toggle |
| 26 | + checked={cacheEnabled} |
| 27 | + onChange={setCacheEnabled} |
| 28 | + className="ml-0" |
| 29 | + /> |
| 30 | + </div> |
| 31 | + </MenuItem> |
| 32 | + <MenuItem> |
| 33 | + <div className="mt-4 flex items-start justify-between gap-4"> |
| 34 | + <div> |
| 35 | + <div className="text-sm font-semibold text-slate-900"> |
| 36 | + Descending table order |
| 37 | + </div> |
| 38 | + <p className="text-xs text-slate-600"> |
| 39 | + Keep newest timestamps first. Disable to switch to oldest rows first. |
| 40 | + </p> |
| 41 | + </div> |
| 42 | + <Toggle |
| 43 | + checked={!sortAscending} |
| 44 | + onChange={(checked) => setSortAscending(!checked)} |
| 45 | + className="ml-0" |
| 46 | + /> |
| 47 | + </div> |
| 48 | + </MenuItem> |
| 49 | + </MenuItems> |
| 50 | + </Menu> |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +SettingsMenu.propTypes = { |
| 55 | + active: PropTypes.bool, |
| 56 | + cacheEnabled: PropTypes.bool.isRequired, |
| 57 | + setCacheEnabled: PropTypes.func.isRequired, |
| 58 | + setSortAscending: PropTypes.func.isRequired, |
| 59 | + sortAscending: PropTypes.bool.isRequired, |
| 60 | +}; |
0 commit comments