|
| 1 | +{# |
| 2 | + Block: Dialog |
| 3 | +#} |
| 4 | + |
| 5 | +{% set cbx_id = 'dialog-' ~ random() %} |
| 6 | + |
| 7 | +{% if function('is_admin') == true %} |
| 8 | + <input type="checkbox" id="{{ cbx_id }}" class="acfbt-dialog-checkbox"> |
| 9 | + <label for="{{ cbx_id }}" class="acfbt-dialog-label">Toggle Dialog</label> |
| 10 | +{% endif %} |
| 11 | + |
| 12 | +<div |
| 13 | +{% if function('is_admin') == false %} |
| 14 | + x-data="{ |
| 15 | + openDialog: false, |
| 16 | +
|
| 17 | + // Close the dialog when the user clicks backdrop |
| 18 | + handleDialogClick(event) { |
| 19 | + (event.target === $refs.dialogRef) && this.handleDialogClose() |
| 20 | + }, |
| 21 | +
|
| 22 | + // Delay close to allow for animation |
| 23 | + handleDialogClose() { |
| 24 | + if (!this.openDialog) return |
| 25 | + this.openDialog = false |
| 26 | + $refs.dialogRef.close() |
| 27 | + } |
| 28 | + }" |
| 29 | +{% endif %} |
| 30 | +> |
| 31 | + |
| 32 | + <dialog |
| 33 | + {{ block_attrs( block ) }} |
| 34 | + {% if function('is_admin') == false %} |
| 35 | + x-ref="dialogRef" |
| 36 | + @keydown.escape.prevent="handleDialogClose()" |
| 37 | + @click="handleDialogClick(event)" |
| 38 | + {% endif %} |
| 39 | + > |
| 40 | + {% if function('is_admin') == false %} |
| 41 | + <button |
| 42 | + class="acf-dialog-close" |
| 43 | + @click="handleDialogClose()" |
| 44 | + > |
| 45 | + <span class="sr-only">Close</span> |
| 46 | + </button> |
| 47 | + {% endif %} |
| 48 | + |
| 49 | + <div class="inner"> |
| 50 | + {% if function('is_admin') == true %} |
| 51 | + <label for="{{ cbx_id }}" class="acfbt-dialog-close"> |
| 52 | + <span class="sr-only">Close</span> |
| 53 | + </label> |
| 54 | + {% endif %} |
| 55 | + {{ inner_blocks() }} |
| 56 | + </div> |
| 57 | + </dialog> |
| 58 | + |
| 59 | + <button |
| 60 | + class="btn-default" |
| 61 | + {% if function('is_admin') == false %} |
| 62 | + @click="$refs.dialogRef.showModal(), openDialog = true" |
| 63 | + {% endif %} |
| 64 | + > |
| 65 | + Open |
| 66 | + </button> |
| 67 | +</div> |
0 commit comments