This file contains hidden or 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
| import { component, State, handle, JoistElement, get } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component<number>({ | |
| tagName: 'app-root', | |
| state: 0, | |
| render: template(({ state, run }) => { | |
| return html` | |
| <button @click=${run('dec')}>-</button> | |
| <span>${state}</span> |
This file contains hidden or 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
| import { component, JoistElement } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component({ | |
| tagName: 'app-root', | |
| shadowDom: 'open', | |
| state: { | |
| title: 'Hello World' | |
| }, | |
| styles: [` |
This file contains hidden or 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
| import { component, State, JoistElement, get } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component<number>({ | |
| tagName: 'my-counter', | |
| state: 'Hello', | |
| render: template(({ state }) => html`${state}`) | |
| }) | |
| class MyCounterElement extends JoistElement { | |
| @get(State) |
This file contains hidden or 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
| import { component, property, JoistElement } from '@joist/component'; | |
| function isString(val: unknown) { | |
| if (typeof val === 'string') { | |
| return null; | |
| } | |
| return { message: 'error' }; | |
| } |
This file contains hidden or 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
| import { component, State, handle, JoistElement, get } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component({ | |
| tagName: 'my-counter', | |
| state: 0, | |
| render: template(({ state, run }) => { | |
| return html` | |
| <button @click=${run('decrement')}>-</button> | |
| <span>${state}</span> |
This file contains hidden or 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
| import { component, State, handle, JoistElement, get } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component({ | |
| tagName: 'my-counter', | |
| state: 0, | |
| render: template(({ state, run }) => { | |
| return html` | |
| <button @click=${run('dec_btn_clicked', -1)}>-</button> | |
| <span>${state}</span> |
This file contains hidden or 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
| import { component, State, handle, JoistElement, get } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component({ | |
| tagName: 'my-counter', | |
| state: 0, | |
| render: template(({ state, run }) => { | |
| return html` | |
| <button @click=${run('dec_btn_clicked', -1)}>-</button> | |
| <span>${state}</span> |
This file contains hidden or 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
| import { component, State, handle, JoistElement, get, HandlerCtx } from '@joist/component'; | |
| import { template, html } from '@joist/component/lit-html'; | |
| @component({ | |
| tagName: 'my-counter', | |
| state: 0, | |
| render: template(({ state, run }) => { | |
| return html` | |
| <button @click=${run('dec_btn_clicked', -1)}>-</button> | |
| <span>${state}</span> |
This file contains hidden or 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
| export function getFocusableEls(element: HTMLElement) { | |
| return element.querySelectorAll<HTMLElement>( | |
| 'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])' | |
| ); | |
| } | |
| export class FocusTrap { | |
| private focusableEls!: NodeListOf<HTMLElement>; | |
| private firstFocusableEl?: HTMLElement; | |
| private lastFocusableEl?: HTMLElement; |
This file contains hidden or 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
| // Freezes document scrolling without remove scrollbar. | |
| // This gets rid of the annoying jump that happens when you set the body overflow to hidden | |
| // Maintains scroll position on the page | |
| export function freezeScroll() { | |
| document.body.style.top = -document.documentElement.scrollTop + 'px'; | |
| document.body.style.position = 'fixed'; | |
| document.body.style.left = '0'; | |
| document.body.style.right = '0'; | |
| document.body.style.overflowY = 'scroll'; | |
| } |