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

75 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-01-02 21:58:00 +01:00
import { Card, TextField, Label } from "./components.js";
const AudioShortcode = {
2023-05-29 16:22:34 +02:00
label: "Audiodatei",
openTag: "{{< ",
closeTag: " >}}",
separator: " ",
toProps: (args) => {
if (args.length > 0) {
const src =
args
.find((arg) => arg.startsWith("src="))
?.split("=")[1]
.replaceAll('"', "") ?? "";
return { src: src };
}
return { src: "" };
},
toArgs: ({ src }) => {
return [`src=\"${src}\"`];
},
control: ({ src, onChange, controlProps }) => {
const { collection, field } = controlProps;
2023-05-29 16:22:34 +02:00
const handleChange = ({ path }) => {
onChange({ src: path });
};
2023-05-29 16:22:34 +02:00
const handleOpenMediaLibrary = useMediaInsert(
src,
{ collection, field },
handleChange
);
2023-05-29 16:22:34 +02:00
return Card([
2024-01-02 21:58:00 +01:00
Label("Audiodatei"),
2023-05-29 16:22:34 +02:00
h(
"span",
2024-01-02 21:58:00 +01:00
{ className: "CMS_WidgetDateTime_inputs" },
TextField({
value: src,
onChange: (event) => {
onChange({ src: event.target.value });
},
}),
2023-05-29 16:22:34 +02:00
h(
2024-01-02 21:58:00 +01:00
"span",
2023-05-29 16:22:34 +02:00
{
2024-01-02 21:58:00 +01:00
key: "audio-button",
className: "CMS_WidgetDateTime_NowButton_root",
2023-05-29 16:22:34 +02:00
},
2024-01-02 21:58:00 +01:00
h(
"button",
{
type: "button",
onClick: handleOpenMediaLibrary,
className: "CMS_Button_root CMS_Button_outlined-primary",
},
"wählen"
)
2023-05-29 16:22:34 +02:00
)
),
]);
},
preview: ({ src }) => {
return h(
"div",
{ className: "card" },
h("audio", { src: src, controls: true })
);
},
};
export default AudioShortcode;