DictConfidence.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Dropdown, Progress, Space } from "antd";
  2. import { useState } from "react";
  3. import { LoadingOutlined } from "@ant-design/icons";
  4. import { _setValue } from "./DictPreference";
  5. interface IWidget {
  6. value?: number;
  7. onChange?: (value: number) => void;
  8. }
  9. const DictConfidence = ({ value, onChange }: IWidget) => {
  10. const [loading, setLoading] = useState(false);
  11. const confidence = [0, 40, 60, 80, 100];
  12. return (
  13. <Space>
  14. {loading ? <LoadingOutlined /> : <></>}
  15. <div style={{ width: 100 }}>
  16. <Dropdown
  17. menu={{
  18. items: confidence.map((item) => {
  19. return { key: item, label: item };
  20. }),
  21. onClick: async (info) => {
  22. setLoading(true);
  23. onChange && onChange(parseInt(info.key));
  24. setLoading(false);
  25. },
  26. }}
  27. >
  28. <Progress
  29. size="small"
  30. percent={Math.round(value ?? 0)}
  31. status={value !== undefined && value < 50 ? "exception" : undefined}
  32. />
  33. </Dropdown>
  34. </div>
  35. </Space>
  36. );
  37. };
  38. export default DictConfidence;