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

72 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-01-02 21:58:00 +01:00
import { Card, TextField, Label } from "./components.js";
const CardShortcode = {
2023-05-29 16:22:34 +02:00
label: "Link-Karte",
openTag: "{{< ",
closeTag: " >}}",
separator: " ",
toProps: (args) => {
if (args.length > 0) {
var title = "";
var link = "";
const linkIndex = args.findIndex((arg) => arg.startsWith('link="'));
const titleIndex = args.findIndex((arg) => arg.startsWith('title="'));
for (let arg of args.slice(titleIndex, linkIndex)) {
title += " " + arg.replaceAll("title=", "").replaceAll('"', "");
}
for (let arg of args.slice(linkIndex)) {
link += " " + arg.replaceAll("link=", "").replaceAll('"', "");
}
2023-09-30 21:15:23 +02:00
return { title: title.trimStart(), link: link.trim() };
2023-05-29 16:22:34 +02:00
}
2023-05-29 16:22:34 +02:00
return { title: "", link: "" };
},
toArgs: ({ title, link }) => {
return [`title=\"${title}\"`, `link=\"${link}\"`];
},
control: ({ title, link, onChange }) => {
return Card([
2024-01-02 21:58:00 +01:00
Label("Titel"),
2023-05-29 16:22:34 +02:00
TextField({
value: title,
onChange: (event) => {
2023-09-30 21:15:23 +02:00
onChange({ title: event.target.value.trimStart(), link });
2023-05-29 16:22:34 +02:00
},
}),
2024-01-02 21:58:00 +01:00
Label("Link"),
2023-05-29 16:22:34 +02:00
TextField({
value: link,
onChange: (event) => {
onChange({ title, link: event.target.value });
},
}),
]);
},
preview: ({ title, link }) => {
return h(
"div",
{ className: "card border-primary rounded-0 hover-shadow mb-2" },
2023-05-29 16:22:34 +02:00
h(
"div",
{ className: "card-body mb-0" },
2023-05-29 16:22:34 +02:00
h(
"h4",
{ className: "card-title" },
h("a", { className: "text-decoration-none", href: link }, title)
),
h(
"a",
{
className: "mb-0 btn btn-primary btn-sm text-decoration-none",
href: link,
},
"Mehr anzeigen"
2023-05-29 16:22:34 +02:00
)
)
);
},
};
export default CardShortcode;