FtsSetting.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Popover, Typography } from "antd";
  2. import type { ISetting } from "../auth/setting/default"
  3. import SettingItem from "../auth/setting/SettingItem";
  4. const { Link } = Typography;
  5. interface IWidget {
  6. trigger?: React.ReactNode;
  7. orderBy?: string | null;
  8. match?: string | null;
  9. onChange?: Function;
  10. }
  11. const FtsSettingWidget = ({
  12. trigger,
  13. orderBy = "rank",
  14. match,
  15. onChange,
  16. }: IWidget) => {
  17. const searchSetting: ISetting[] = [
  18. {
  19. key: "match",
  20. label: "setting.search.match.label",
  21. defaultValue: match ? match : "case",
  22. widget: "select",
  23. options: [
  24. { label: "setting.search.match.complete.label", value: "complete" },
  25. { label: "setting.search.match.case.label", value: "case" },
  26. { label: "setting.search.match.similar.label", value: "similar" },
  27. ],
  28. },
  29. {
  30. key: "orderby",
  31. label: "setting.search.orderby.label",
  32. defaultValue: orderBy ? orderBy : "rank",
  33. widget: "select",
  34. options: [
  35. { label: "setting.search.orderby.rank.label", value: "rank" },
  36. { label: "setting.search.orderby.paragraph.label", value: "paragraph" },
  37. ],
  38. },
  39. ];
  40. return (
  41. <Popover
  42. overlayStyle={{ width: 300 }}
  43. placement="bottom"
  44. arrowPointAtCenter
  45. content={
  46. <>
  47. {searchSetting.map((item, index) => (
  48. <SettingItem
  49. key={index}
  50. data={item}
  51. onChange={(key: string, value: string | number | boolean) => {
  52. if (typeof onChange !== "undefined") {
  53. onChange(key, value);
  54. }
  55. }}
  56. />
  57. ))}
  58. </>
  59. }
  60. trigger="click"
  61. >
  62. <Link>{trigger}</Link>
  63. </Popover>
  64. );
  65. };
  66. export default FtsSettingWidget;