Skip to content

Commit

Permalink
[#148] Moving from php to twig
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-schmidt-viget committed Nov 8, 2024
1 parent 9eda4eb commit 3aeb353
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 40 deletions.
1 change: 0 additions & 1 deletion wp-content/themes/wp-starter/blocks/dialog/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
},
"viewStyle": "file:./view.css",
"editorStyle": "file:./editor.css",
"viewScript": "file:./view.js",
"acf": {
"mode": "preview"
}
Expand Down
67 changes: 67 additions & 0 deletions wp-content/themes/wp-starter/blocks/dialog/render.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{#
Block: Dialog
#}

{% set cbx_id = 'dialog-' ~ random() %}

{% if function('is_admin') == true %}
<input type="checkbox" id="{{ cbx_id }}" class="acfbt-dialog-checkbox">
<label for="{{ cbx_id }}" class="acfbt-dialog-label">Toggle Dialog</label>
{% endif %}

<div
{% if function('is_admin') == false %}
x-data="{
openDialog: false,
// Close the dialog when the user clicks backdrop
handleDialogClick(event) {
(event.target === $refs.dialogRef) && this.handleDialogClose()
},
// Delay close to allow for animation
handleDialogClose() {
if (!this.openDialog) return
this.openDialog = false
$refs.dialogRef.close()
}
}"
{% endif %}
>

<dialog
{{ block_attrs( block ) }}
{% if function('is_admin') == false %}
x-ref="dialogRef"
@keydown.escape.prevent="handleDialogClose()"
@click="handleDialogClick(event)"
{% endif %}
>
{% if function('is_admin') == false %}
<button
class="acf-dialog-close"
@click="handleDialogClose()"
>
<span class="sr-only">Close</span>
</button>
{% endif %}

<div class="inner">
{% if function('is_admin') == true %}
<label for="{{ cbx_id }}" class="acfbt-dialog-close">
<span class="sr-only">Close</span>
</label>
{% endif %}
{{ inner_blocks() }}
</div>
</dialog>

<button
class="btn-default"
{% if function('is_admin') == false %}
@click="$refs.dialogRef.showModal(), openDialog = true"
{% endif %}
>
Open
</button>
</div>
32 changes: 0 additions & 32 deletions wp-content/themes/wp-starter/blocks/dialog/view.js

This file was deleted.

7 changes: 0 additions & 7 deletions wp-content/themes/wp-starter/blocks/dialog/x-render.twig

This file was deleted.

0 comments on commit 3aeb353

Please sign in to comment.