mirror of https://github.com/halo-dev/halo
28 lines
750 B
TypeScript
28 lines
750 B
TypeScript
import { apiClient } from "@/utils/api-client";
|
|
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core";
|
|
import { checkbox, checkboxes, defaultIcon } from "@formkit/inputs";
|
|
|
|
function optionsHandler(node: FormKitNode) {
|
|
node.on("created", async () => {
|
|
const { data } = await apiClient.extension.menu.listv1alpha1Menu();
|
|
|
|
node.props.options = data.items.map((menu) => {
|
|
return {
|
|
value: menu.metadata.name,
|
|
label: menu.spec.displayName,
|
|
};
|
|
});
|
|
});
|
|
}
|
|
|
|
export const menuCheckbox: FormKitTypeDefinition = {
|
|
...checkbox,
|
|
props: ["onValue", "offValue"],
|
|
forceTypeProp: "checkbox",
|
|
features: [
|
|
optionsHandler,
|
|
checkboxes,
|
|
defaultIcon("decorator", "checkboxDecorator"),
|
|
],
|
|
};
|