0.18.0 • Published 19 days ago

@beforesemicolon/markup v0.18.0

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
19 days ago

Markup

Reactive HTML Templating System

Static Badge npm npm Test

Markup is a plug-and-play template system for those who need the bare minimal yet powerful way to build user interface. Its small size and ready-to-go nature makes it perfect for quick prototypes, UI components library, browser extensions, and side projects. But make no mistake, it has all the templating features for a big project and serves as a perfect start to build any UI framework or library.

Motivation

Most UI libraries need too much setup and require build with a steep learning curve. If you find a good templating system its either not powerful enough or requires extra things to make it work by itself.

This templating system is standalone system. You don't need anything else to start rendering and reacting to changes.

It requires no build, its tiny, and the API is literally 2 main things to learn, and you are ready to go. It is pretty much HTML and Javascript so the learning curve is extremely small.

Example

Below is a simple todo app and as you can see, its pretty much HTML and Javascript.

import { html, state, repeat } from '@beforesemicolon/markup'

interface TodoItem {
    name: string
    description: string
    id: string
}

const [todos, updateTodos] = state<Array<TodoItem>>([])

const createTodo = () => {
    const name = window.prompt('Enter todo name')
    const description = window.prompt('Enter todo description') ?? ''

    if (name) {
        updateTodos((prev) => [
            ...prev,
            { name, description, id: crypto.randomUUID() },
        ])
    }
}

const deleteTodo = (id) => {
    updateTodos((prev) => prev.filter((todo) => todo.id !== id))
}

const TodoItem = ({ name, description, id }: TodoItem) => html`
    <div class="todo-item">
        <h3>${name}</h3>
        <p>${description}</p>
        <button type="button" onclick="${() => deleteTodo(id)}">delete</button>
    </div>
`

const TodoApp = html`
    <h2>Todo App</h2>
    <button type="button" onclick="${createTodo}">add new</button>
    <div class="todo-list">${repeat(todos, TodoItem)}</div>
`

TodoApp.render(document.body)

More examples

This is a simple example of a button, but you can check:

Install

npm install @beforesemicolon/markup

or

yarn add @beforesemicolon/markup

Use directly in the Browser

This library requires no build or parsing. The CDN package is one digit killobyte in size, tiny!

<!doctype html>
<html lang="en">
    <head>
        <!-- Grab the latest version -->
        <script src="https://unpkg.com/@beforesemicolon/markup/dist/client.js"></script>

        <!-- Or a specific version -->
        <script src="https://unpkg.com/@beforesemicolon/markup@0.3.0/dist/client.js"></script>
    </head>
</html>

Usage

<div id="app"></div>

<script>
    const { html } = BFS.MARKUP

    html`<h1>Hello World</h1>`.render(document.getElementById('app'))
</script>
0.18.6-next

19 days ago

0.18.7-next

19 days ago

0.18.0

19 days ago

0.18.8-next

19 days ago

0.18.5-next

19 days ago

0.18.3-next

1 month ago

0.18.4-next

1 month ago

0.18.1-next

1 month ago

0.18.2-next

1 month ago

0.18.0-next

2 months ago

0.17.0

2 months ago

0.16.6

2 months ago

0.16.5

3 months ago

0.16.4

4 months ago

0.16.3

4 months ago

0.16.2

4 months ago

0.16.0

4 months ago

0.16.1

4 months ago

0.15.1

4 months ago

0.15.0-next

4 months ago

0.15.1-next

4 months ago

0.15.0

4 months ago

0.14.2

4 months ago

0.14.3

4 months ago

0.14.2-next

5 months ago

0.14.1

5 months ago

0.14.1-next

5 months ago

0.13.2

5 months ago

0.14.0-next

5 months ago

0.12.0

5 months ago

0.13.0

5 months ago

0.13.1

5 months ago

0.11.0

5 months ago

0.10.0

5 months ago

0.9.0

5 months ago

0.8.0

6 months ago

0.7.0

6 months ago

0.6.0

6 months ago

0.5.0

6 months ago

0.4.0

6 months ago

0.3.0

6 months ago

0.0.0

6 months ago