1.16.2 • Published 6 months ago

@beforesemicolon/web-component v1.16.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
6 months ago

Web Component

Static Badge Test npm npm

Reactive Web Component API enhanced with Markup.

Motivation

  • Native Web Components APIs are too robust. This means you need to write so much code for the simplest components.
  • Even if you manage to handle all the APIs fine, you still need to deal with DOM manipulation and handle your own reactivity.
  • Markup offers the simplest and more powerful templating system that can be used on the client without setup.

With all these reasons, it only made sense to introduce a simple API to handle everything for you.

// import everything from Markup as if you are using it directly
import { WebComponent, html } from '@beforesemicolon/web-component'
import stylesheet from './counter-app.css' with { type: 'css' }

interface Props {
    label: string
}

interface State {
    count: number
}

class CounterApp extends WebComponent<Props, State> {
    static observedAttributes = ['label']
    label = '+' // defined props default value
    initialState = {
        // declare initial state
        count: 0,
    }
    stylesheet = stylesheet

    countUp = (e: Event) => {
        e.stopPropagation()
        e.preventDefault()

        this.setState(({ count }) => ({ count: count + 1 }))
        this.dispatch('click')
    }

    render() {
        return html`
            <p>${this.state.count}</p>
            <button type="button" onclick="${this.countUp}">
                ${this.props.label}
            </button>
        `
    }
}

customElements.define('counter-app', CounterApp)

In your HTML you can simply use the tag normally.

<counter-app label="count up"></counter-app>

Install

npm install @beforesemicolon/web-component

In the browser

<!-- use the latest version -->
<script src="https://unpkg.com/@beforesemicolon/web-component/dist/client.js"></script>

<!-- use a specific version -->
<script src="https://unpkg.com/@beforesemicolon/web-component@0.0.4/dist/client.js"></script>

<!-- link you app script after -->
<script>
    const { WebComponent } = BFS
    const { html, state, effect } = BFS.MARKUP
</script>
1.14.0

1 year ago

1.12.0

1 year ago

1.16.2

6 months ago

1.16.1

6 months ago

1.16.0

1 year ago

1.12.5-next

1 year ago

1.14.0-next

1 year ago

1.13.0-next

1 year ago

1.15.0-next

1 year ago

1.11.0

1 year ago

1.15.0

1 year ago

1.13.0

1 year ago

1.11.1

1 year ago

1.15.3

1 year ago

1.15.2

1 year ago

1.15.1

1 year ago

1.10.0

1 year ago

1.12.4-next

1 year ago

1.12.3-next

1 year ago

1.12.2-next

1 year ago

1.12.0-next

1 year ago

1.12.1-next

1 year ago

1.8.1

2 years ago

1.11.1-next

1 year ago

1.9.2

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.11.2-next

1 year ago

1.11.0-next

1 year ago

1.10.0-next

1 year ago

1.9.0-next

1 year ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.0

2 years ago

1.1.4

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.16.3

4 years ago

0.16.4

4 years ago

0.15.0

4 years ago

0.16.0

4 years ago

0.15.1

4 years ago

0.17.0

4 years ago

0.16.1

4 years ago

0.15.2

4 years ago

0.18.0

4 years ago

0.17.1

4 years ago

0.16.2

4 years ago

0.15.3

4 years ago

0.10.0

4 years ago

0.11.0

4 years ago

0.10.1

4 years ago

0.12.0

4 years ago

0.10.2

4 years ago

0.13.0

4 years ago

0.10.3

4 years ago

0.14.0

4 years ago

0.10.4

4 years ago

0.14.1

4 years ago

0.10.5

4 years ago

0.14.2

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago