Last active
February 9, 2023 23:27
-
-
Save shumiyao/3b597864fd40bbcc7d2756f690281910 to your computer and use it in GitHub Desktop.
Shortcode Test for StaticCMS (warning: this is a work in progress and incomplete)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TestShortcodeProps { | |
src: string; | |
} | |
CMS.registerShortcode<TestShortcodeProps>('test', { | |
label: 'test', | |
openTag: '[', | |
closeTag: ']', | |
separator: '|', | |
toProps: (args) => { | |
if (args.length > 0) { | |
return { src: args[0] }; | |
} | |
return { src: '' }; | |
}, | |
toArgs: ({ src }) => { | |
return [src]; | |
}, | |
control: (test) => { | |
const { controlProps, onChange, src } = test; | |
function handleChange(event) { | |
const [file] = event.target.files; | |
onChange({ src: URL.createObjectURL(file) }); | |
} | |
return ( | |
<> | |
<span> | |
<input key='control-input' id='test' value='' type='file' onChange={handleChange} /> | |
</span> | |
<div key='control-preview'> | |
<img src={src} /> | |
</div> | |
</> | |
); | |
}, | |
preview: ({ src }) => { | |
return h( | |
'span', | |
{}, | |
h( | |
'iframe', | |
{ | |
width: '420', | |
height: '315', | |
src: `https://www.youtube.com/embed/${src}`, | |
}, | |
'' | |
) | |
); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment