gcg-website/static/admin/shortcodes/slider.js

77 lines
1.7 KiB
JavaScript
Raw Normal View History

import { Card, TextField } from "./components/index.js";
const SliderShortcode = {
2023-05-29 16:22:34 +02:00
label: "Bilderkarussell",
openTag: "{{< ",
closeTag: " >}}",
separator: " ",
toProps: (args) => {
if (args.length > 0) {
return {
dir:
args
.find((arg) => arg.startsWith("dir="))
?.split("=")[1]
.replaceAll('"', "") ?? "",
};
}
return { dir: "" };
},
toArgs: ({ dir }) => {
return [`dir=\"${dir}\"`];
},
control: ({ dir, onChange, controlProps }) => {
const { collection, field } = controlProps;
2023-05-29 16:22:34 +02:00
const handleChange = ({ path }) => {
onChange({ dir: path });
};
2023-05-29 16:22:34 +02:00
const handleOpenMediaLibrary = useMediaInsert(
dir,
{ collection, field, forFolder: true },
handleChange
);
2023-05-29 16:22:34 +02:00
return Card([
TextField({
label: "Bilderkarussell",
value: dir,
onChange: (event) => {
onChange({ dir: event.target.value });
},
}),
h(
"span",
2023-09-30 21:15:23 +02:00
{
key: "slider-button",
className: "CMS_WidgetDateTime_NowButton_root",
},
2023-05-29 16:22:34 +02:00
h(
"button",
{
type: "button",
onClick: handleOpenMediaLibrary,
2023-09-30 21:15:23 +02:00
className: "CMS_Button_root CMS_Button_outlined-primary",
2023-05-29 16:22:34 +02:00
},
"wählen"
)
),
]);
},
preview: ({ dir }) => {
return h(
"div",
{ className: "card mb-4" },
h(
"div",
{ className: "card-body mb-0" },
h("div", { className: "card-title h4" }, "Bilderkarussell"),
h("div", { className: "card-text" }, dir)
)
);
},
};
export default SliderShortcode;