|
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7 | 7 | <title>Vite + Lit + TS</title>
|
8 | 8 | <link rel="stylesheet" href="./src/index.css" />
|
9 |
| - <script type="module" src="/src/components/my-element/my-element.ts"></script> |
| 9 | + <script type="module" src="/src/components/button/button.ts"></script> |
| 10 | + |
| 11 | + <style> |
| 12 | + .special-button::part(root) { |
| 13 | + background-color: aquamarine; |
| 14 | + color: #000; |
| 15 | + } |
| 16 | + </style> |
10 | 17 | </head>
|
11 | 18 | <body>
|
12 |
| - <my-element> |
13 |
| - <h1>Vite + Lit</h1> |
14 |
| - </my-element> |
| 19 | + <div> |
| 20 | + <wds-button>Button default</wds-button> |
| 21 | + <wds-button disabled>Button default disabled</wds-button> |
| 22 | + <wds-button danger>Button danger</wds-button> |
| 23 | + <wds-button full-width>Button default full-width</wds-button> |
| 24 | + <wds-button disabled full-width>Button default disabled full-width</wds-button> |
| 25 | + |
| 26 | + <hr> |
| 27 | + |
| 28 | + <wds-button appearance="accent">Button accent</wds-button> |
| 29 | + <wds-button appearance="accent" disabled>Button accent disabled</wds-button> |
| 30 | + <wds-button appearance="accent" full-width>Button accent full-width</wds-button> |
| 31 | + <wds-button appearance="accent" disabled full-width>Button accent disabled full-width</wds-button> |
| 32 | + </div> |
| 33 | + |
| 34 | + <hr> |
| 35 | + |
| 36 | + <form> |
| 37 | + <input type="text" name="demo" /> |
| 38 | + |
| 39 | + <button>Native button</button> |
| 40 | + |
| 41 | + <wds-button type="button" class="special-button" id="js-special-button">Form Button special</wds-button> |
| 42 | + <wds-button type="reset">Form Reset</wds-button> |
| 43 | + <wds-button appearance="accent" type="submit">Form Submit</wds-button> |
| 44 | + </form> |
| 45 | + |
| 46 | + <wds-button class="button button-primary" data-modal-trigger="1">Open modal</wds-button> |
| 47 | + |
| 48 | + <dialog |
| 49 | + class="modal" data-modal="1" |
| 50 | + role="alertdialog" |
| 51 | + aria-modal="true" |
| 52 | + aria-labelledby="confirmation-dialog-title" |
| 53 | + aria-describedby="confirmation-dialog-description" |
| 54 | + > |
| 55 | + <h6 id="confirmation-dialog-title" class="modal-title">Modal title</h6> |
| 56 | + |
| 57 | + <div class="modal-content" id="confirmation-dialog-description"> |
| 58 | + <p>Modal body text goes here.</p> |
| 59 | + </div> |
| 60 | + |
| 61 | + <footer class="modal-footer"> |
| 62 | + <wds-button class="button button-secondary" data-modal-close="1">Close</wds-button> |
| 63 | + <wds-button class="button button-primary" data-modal-close="1">Save changes</wds-button> |
| 64 | + </footer> |
| 65 | + </dialog> |
| 66 | + |
| 67 | + <script> |
| 68 | + const dialogRootElementList = document.querySelectorAll('[data-modal]'); |
| 69 | + const dialogTriggerElementList = document.querySelectorAll('[data-modal-trigger]'); |
| 70 | + const dialogCloseElementList = document.querySelectorAll('[data-modal-close]'); |
| 71 | + |
| 72 | + if (dialogRootElementList?.length) { |
| 73 | + dialogTriggerElementList.forEach((dialogTriggerElementListItem) => { |
| 74 | + dialogTriggerElementListItem.addEventListener('click', () => { |
| 75 | + const selectedDialogRootElement = [...dialogRootElementList] |
| 76 | + .find(dialogRootElementListItem => |
| 77 | + dialogRootElementListItem.dataset?.modal === dialogTriggerElementListItem.dataset?.modalTrigger); |
| 78 | + |
| 79 | + if (selectedDialogRootElement) { |
| 80 | + selectedDialogRootElement.showModal(); |
| 81 | + } |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + dialogCloseElementList.forEach((dialogCloseElementListItem) => { |
| 86 | + dialogCloseElementListItem.addEventListener('click', () => { |
| 87 | + const selectedDialogRootElement = [...dialogRootElementList] |
| 88 | + .find(dialogRootElementListItem => |
| 89 | + dialogRootElementListItem.dataset?.modal === dialogCloseElementListItem.dataset?.modalClose); |
| 90 | + |
| 91 | + if (selectedDialogRootElement) { |
| 92 | + selectedDialogRootElement.close(); |
| 93 | + } |
| 94 | + }); |
| 95 | + }); |
| 96 | + } |
| 97 | + </script> |
| 98 | + |
| 99 | + <script> |
| 100 | + document.addEventListener("DOMContentLoaded", (event) => { |
| 101 | + const specialButtonElement = document.querySelector('#js-special-button'); |
| 102 | + |
| 103 | + specialButtonElement.addEventListener('click', (event) => { |
| 104 | + console.log('special button click', event); |
| 105 | + }) |
| 106 | + }); |
| 107 | + </script> |
15 | 108 | </body>
|
16 | 109 | </html>
|
0 commit comments