Render buttons with the data needed to locate click handlers
This commit is contained in:
parent
8cba197ffd
commit
48c07e792d
2 changed files with 16 additions and 7 deletions
src/lib
|
@ -4,8 +4,17 @@ import { CardContext } from './card';
|
|||
import { getOptRaw } from './options';
|
||||
|
||||
export const Button: Proc<CardContext> = (vm, argv: TextPiece[]): ProcResult =>
|
||||
getOptRaw(argv, { $min: 1, $max: 1 }, (_opts, [label]) => {
|
||||
return {
|
||||
html: `<button>${AsHtml(label)}</button>`,
|
||||
};
|
||||
});
|
||||
getOptRaw(
|
||||
argv,
|
||||
{ $min: 1, $max: 1, onClick: 1 },
|
||||
({ onClick: [onClick = null] }, [label]) => {
|
||||
let buttonTrigger = "disabled";
|
||||
if (onClick && "pos" in onClick && onClick.pos != undefined) {
|
||||
buttonTrigger = `data-notcl-onClick="${onClick.pos}"`;
|
||||
}
|
||||
|
||||
return {
|
||||
html: `<button ${buttonTrigger}>${AsHtml(label)}</button>`,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue