sketch/redraw
Types
Values
pub fn create_cache() -> Cache
Creates the Sketch Context and initialises the Sketch cache. Use it in
conjuction with provider to setup Sketch Redraw, otherwise
nothing will work.
import redraw
import redraw/dom/client
import sketch/redraw as sketch_redraw
pub fn main() {
let app = app()
let cache = sketch_redraw.create_cache()
let root = client.create_root("root")
client.render(root, {
redraw.strict_mode([
sketch_redraw.provider(cache, [
app(),
]),
])
})
}
pub fn initialise_cache(
prepare: fn(sketch.StyleSheet) -> sketch.StyleSheet,
) -> Cache
Creates the Sketch Context and initialises the Sketch cache. Use it in
conjuction with provider to setup Sketch Redraw, otherwise
nothing will work. initialise_cache acts like create_cache, but provides
a customisation function to modify the stylesheet at initialisation (to
inject custom styles, keyframes, etc.).
import redraw
import redraw/dom/client
import sketch/redraw as sketch_redraw
pub fn main() {
let app = app()
let cache = initialise_cache()
let root = client.create_root("root")
client.render(root, {
redraw.strict_mode([
sketch_redraw.provider(cache, [
app(),
]),
])
})
}
pub fn initialise_cache() {
use stylesheet <- sketch_redraw.initialise_cache()
stylesheet
|> sketch.at_rule(keyframes.wave(), _)
|> sketch.at_rule(keyframes.pulse(), _)
}
pub fn provider(
setup: Cache,
children: List(redraw.Component),
) -> redraw.Component
Create the Sketch provider used to manage the StyleSheet.
This makes sure identical styles will never be computed twice.
Use it at root of your render function.
import redraw
import redraw/dom/client
import sketch/redraw as sketch_redraw
pub fn main() {
let app = app()
let cache = sketch_redraw.create_cache()
let root = client.create_root("root")
client.render(root, {
redraw.strict_mode([
sketch_redraw.provider(cache, [
app(),
]),
])
})
}
pub fn use_class_name(styles: @internal Class) -> String
Generates the corresponding class name to styles.
import redraw
import redraw/dom/attribute
import redraw/dom/client
import redraw/dom/html
import sketch/redraw as sketch_redraw
pub fn my_component() {
use <- redraw.standalone("MyComponent")
let class_name = sketch_redraw.use_class_name(my_class())
html.div([attribute.class_name(class_name)], [
html.text("Styled!"),
])
}