Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,778 Bytes
5916048 741554a 5916048 1ce932e 5916048 6294700 5916048 1ce932e 5916048 6294700 5916048 1ce932e 5916048 1ce932e 6294700 5916048 91c3567 1ce932e ff1a29c 5916048 1ce932e 741554a 5916048 1ce932e ff1a29c 741554a 91c3567 1ce932e 03ce1cf 5916048 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import { useMemo } from "react";
import { Method } from "@/components/method";
import { splitStringBracket } from "@/utils";
import { ApiRoute } from "@/utils/type";
import { Parameter } from "./parameter";
export const Endpoint = ({
method,
path,
initialPath,
children,
onChange,
}: {
method: ApiRoute["method"];
path: string;
initialPath: ApiRoute["path"];
children: React.ReactElement;
onChange: (value: string) => void;
}) => {
const path_formatted = useMemo(
() => splitStringBracket(initialPath),
[initialPath]
);
const handleChange = (value: string, key: string) => {
onChange(path.replace(key, value));
};
return (
<div className="bg-white dark:bg-slate-950/40 w-full px-4 xl:px-6 pt-5">
<div className="bg-slate-200 border-slate-300 dark:border-0 dark:bg-slate-950 p-3 rounded-lg flex items-center justify-between">
<div className="text-gray-600 dark:text-white text-sm flex items-center justify-start gap-2 w-full">
<Method method={method} />
<div className="flex items-center justify-start gap-1 flex-wrap">
{path_formatted.map((p, i) => {
return p.editable ? (
<Parameter
key={i}
value={p.content}
onChange={(value, currentValue) =>
handleChange(
value,
currentValue === p.key ? p.key : currentValue
)
}
/>
) : (
<p key={i} className="text-gray-600 dark:text-slate-300">
{p.content}
</p>
);
})}
</div>
</div>
{children}
</div>
</div>
);
};
|