🪨 @benev/slate
🚧 prerelease wip under constructon subject to change
- frontend ui framework
- lit compatible, uses lit-html for templating
GoldElement
is a replacement for LitElementSilverElement
is just like GoldElement but for the light domShaleView
is a sophisticated view classFlat
is a state management systemPipe
is cool syntax for.. pipingOp
is a system for showing loading spinnersprepare_frontend
connects your components and views with app-level context and state management
👷 recommended setup
- install slate into your project
npm i @benev/slate
- establish a "context" for your app
import {css} from "lit"
import {BaseContext} from "@benev/slate"
export class Context extends BaseContext {
flat = new Flat()
theme = css`
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
`
}
- prepare your frontend
export const {component, components, view, views} = prepare_frontend<Context>()
- register all your components to the dom
import {register_to_dom} from `@benev/slate`
register_to_dom(components(context, {
MyElement,
AnotherElement,
WhateverElement,
}))
🥇 GoldElement
import {html, css} from "lit"
import {GoldElement} from "@benev/slate"
export const MyComponent = component(context => class extends GoldElement {
static styles = css``
#state = context.flat.state({
count: 0,
})
#views = views(context, {
MyView,
})
#increment => () => {
this.#state.count++
}
render() {
return html`
<p>count: ${this.#state.count}</p>
<button @click=${this.#increment}>increment</button>
${this.#views.MyView({props: [this.#state.count]})}
`
}
})
🥈 SilverElement
it's just like GoldElement
, except it's light dom (no shadow dom), and thus it cannot have its own stylesheet (relies on styling from above).
🗿 ShaleView
export const MyView = view(context => class extends ShaleView {
name = "my-view"
styles = css``
render(count: number) {
return html`<p>${count}</p>`
}
})
- views are very similar to components
- but they are not custom elements
- they don't need to be registered to the dom
- views have their own shadow dom
- they do this thing called
auto_exportparts
- automatically exports shadow parts across many shadow layers
- it's on by default
- you just give the view a
part
, and it will use that part as a prefix to any sub-parts
more utilities with new docs coming soon