sketch
Want to know more about details? Go to the additional docs!
Table of Contents
-
Setup and usage
-
Lifecycle functions
-
Modifiers
-
Media Queries
-
Properties
width
width_
max_width
max_width_
min_width
min_width_
height
height_
max_height
max_height_
min_height
min_height_
color
font_family
font_style
font_size
font_size_
font_weight
letter_spacing
line_break
line_height
text_align
text_decoration
text_justify
text_overflow
text_transform
white_space
white_space_collapse
word_break
word_spacing
word_wrap
list_style
list_style_image
list_style_position
list_style_type
display
z_index
visibility
background
object_fit
object_position
opacity
pointer_events
user_select
position
outline
outline_color
outline_offset
outline_style
outline_width
offset
offset_anchor
offset_distance
offset_path
offset_position
offset_rotate
gap
gap_
column_gap
row_gap
grid_area
grid_column
grid_row
grid_template
grid_auto_columns
grid_auto_rows
grid_auto_flow
grid_template_areas
grid_template_columns
grid_template_rows
align_content
align_items
align_self
align_tracks
justify_content
justify_items
justify_self
justify_tracks
place_content
place_items
place_self
animation
animation_name
animation_duration
animation_timing_function
animation_delay
animation_iteration_count
animation_direction
animation_fill_mode
animation_play_state
transition
translate
transform
transform_box
transform_origin
transform_style
appearance
filter
aspect_ratio
top
bottom
right
left
top_
bottom_
right_
left_
box_shadow
box_sizing
overflow
overflow_x
overflow_y
direction
flex
flex_basis
flex_direction
flex_grow
border
border_top
border_bottom
border_right
border_left
border_radius
border_radius_
border_top_right_radius
border_top_right_radius_
border_top_left_radius
border_top_left_radius_
border_bottom_right_radius
border_bottom_right_radius_
border_bottom_left_radius
border_bottom_left_radius_
padding
padding_
padding_top
padding_bottom
padding_right
padding_left
margin
margin_
margin_top
margin_bottom
margin_right
margin_left
cursor
float
property
-
Pseudo-selectors
Types
Manages the styles. Can be instanciated with create_cache
.
pub type Cache =
cache.Cache
No direct usage, used for type-checking and to cancel impossible states.
pub type NoMedia
No direct usage, used for type-checking and to cancel impossible states.
pub type NoPseudoSelector
No direct usage, used for type-checking and to cancel impossible states.
pub type PseudoSelector
Represents a Style. It can be a class composition, a media query with its sub-properties, a pseudo-selector with its sub-properties or a property directly. It’s not possible to put a media query in a media query, and a pseudo-selector in a pseudo-selector.
pub opaque type Style(media, pseudo)
Functions
pub fn active(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn align_content(align: String) -> Style(a, b)
pub fn align_items(align: String) -> Style(a, b)
pub fn align_self(align: String) -> Style(a, b)
pub fn align_tracks(align: String) -> Style(a, b)
pub fn animation_delay(animation: String) -> Style(a, b)
pub fn animation_direction(animation: String) -> Style(a, b)
pub fn animation_duration(animation: String) -> Style(a, b)
pub fn animation_fill_mode(animation: String) -> Style(a, b)
pub fn animation_iteration_count(
animation: String,
) -> Style(a, b)
pub fn animation_name(animation: String) -> Style(a, b)
pub fn animation_play_state(animation: String) -> Style(a, b)
pub fn animation_timing_function(
animation: String,
) -> Style(a, b)
pub fn appearance(appearance: String) -> Style(a, b)
pub fn aspect_ratio(aspect_ratio: String) -> Style(a, b)
pub fn background(background: String) -> Style(a, b)
pub fn blank(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn border_bottom(border_bottom: String) -> Style(a, b)
pub fn border_bottom_left_radius(
border_bottom_left_radius: Size,
) -> Style(a, b)
pub fn border_bottom_left_radius_(
border_bottom_left_radius: String,
) -> Style(a, b)
pub fn border_bottom_right_radius(
border_bottom_right_radius: Size,
) -> Style(a, b)
pub fn border_bottom_right_radius_(
border_bottom_right_radius: String,
) -> Style(a, b)
pub fn border_left(border_left: String) -> Style(a, b)
pub fn border_radius(border_radius: Size) -> Style(a, b)
pub fn border_radius_(border_radius: String) -> Style(a, b)
pub fn border_right(border_right: String) -> Style(a, b)
pub fn border_top(border_top: String) -> Style(a, b)
pub fn border_top_left_radius(
border_top_left_radius: Size,
) -> Style(a, b)
pub fn border_top_left_radius_(
border_top_left_radius: String,
) -> Style(a, b)
pub fn border_top_right_radius(
border_top_right_radius: Size,
) -> Style(a, b)
pub fn border_top_right_radius_(
border_top_right_radius: String,
) -> Style(a, b)
pub fn box_shadow(box_shadow: String) -> Style(a, b)
pub fn box_sizing(box_sizing: String) -> Style(a, b)
pub fn checked(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn class(styles: List(Style(a, b))) -> Class
Compiles a static class, and reuses it across the same render flow.
Don’t use dynamic styles with it, use dynamic
instead.
pub fn column_gap(column_gap: Size) -> Style(a, b)
pub fn compose(class: Class) -> Style(a, b)
Compose styles by inheriting class, and later overrides them.
Works similarly to composes
property in CSS modules.
pub fn create_cache(
options: Options,
) -> Result(Cache, SketchError)
Create a cache manager, managing the styles for every repaint. You can instanciate as much cache manager that you want, if you want to use multiple render lifecycle. You can output the styles directly in a node style in the DOM, or by pushing them directly in a CSSStyleSheet, at the document level. The choice is up to you at the initialization of the Cache. On BEAM, this setting is ignored. If you’re using Lustre, you shouldn’t have to worry about it, and consider it as internal low-level.
pub fn disabled(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn dynamic(id: String, styles: List(Style(a, b))) -> Class
Compiles a dynamic class. It means during the render, when the class with the id
is re-computed, a new version will be pushed in the browser if needed.
It means you can reuse the function to output different classes with the same
function and basis. With a class
, once computed once during the render, it’s
not possible to change the content of the class.
Be careful to add a unique ID: right now, it’s not possible to push
a dynamic class in the browser without defining an ID. The ID should be unique
to the computed class, otherwise you could end up with some classes overlap.
pub fn enabled(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn first_child(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn first_of_type(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn flex_basis(flex_basis: String) -> Style(a, b)
pub fn flex_direction(flex_direction: String) -> Style(a, b)
pub fn focus(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn focus_visible(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn focus_within(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn font_family(font_family: String) -> Style(a, b)
pub fn font_size_(font_size: String) -> Style(a, b)
pub fn font_style(font_style: String) -> Style(a, b)
pub fn font_weight(font_weight: String) -> Style(a, b)
pub fn grid_auto_columns(
grid_auto_columns: String,
) -> Style(a, b)
pub fn grid_auto_flow(grid_auto_flow: String) -> Style(a, b)
pub fn grid_auto_rows(grid_auto_rows: String) -> Style(a, b)
pub fn grid_column(grid_column: String) -> Style(a, b)
pub fn grid_template(grid_template: String) -> Style(a, b)
pub fn grid_template_areas(
grid_template_areas: String,
) -> Style(a, b)
pub fn grid_template_columns(
grid_template_columns: String,
) -> Style(a, b)
pub fn grid_template_rows(
grid_template_rows: String,
) -> Style(a, b)
pub fn hover(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn important(style: Style(a, b)) -> Style(a, b)
Add an !important
flag to any CSS property.
It won’t have any effect on non-property style, like media, etc. It will
then act as the identity
function.
pub fn invalid(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn justify_content(justify: String) -> Style(a, b)
pub fn justify_items(justify: String) -> Style(a, b)
pub fn justify_self(justify: String) -> Style(a, b)
pub fn justify_tracks(justify: String) -> Style(a, b)
pub fn last_child(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn last_of_type(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn letter_spacing(letter_spacing: String) -> Style(a, b)
pub fn line_break(line_break: String) -> Style(a, b)
pub fn line_height(line_height: String) -> Style(a, b)
pub fn list_style(list_style: String) -> Style(a, b)
pub fn list_style_image(list_style_image: String) -> Style(a, b)
pub fn list_style_position(
list_style_position: String,
) -> Style(a, b)
pub fn list_style_type(list_style_type: String) -> Style(a, b)
pub fn lustre_setup(
options: Options,
) -> Result(fn(fn(a) -> b) -> fn(a) -> b, SketchError)
Deprecated: Use sketch/lustre.{setup, compose} instead.
pub fn margin_bottom(margin: Size) -> Style(a, b)
pub fn margin_left(margin: Size) -> Style(a, b)
pub fn margin_right(margin: Size) -> Style(a, b)
pub fn margin_top(margin: Size) -> Style(a, b)
pub fn max_height(height: Size) -> Style(a, b)
pub fn max_height_(height: String) -> Style(a, b)
pub fn max_width_(width: String) -> Style(a, b)
pub fn media(
query: Query,
styles: List(Style(NoMedia, PseudoSelector)),
) -> Style(Media, a)
pub fn memo(class: Class) -> Class
Memoizes a function across multiple renders. When encountered for the first time, the class will be put in long-live section of the stylesheet. Once in long-live section, the computed class will never be garbaged, and will be included in every render. This saves some time during render by skipping every memoized class. You can use it when you know that a class will be used during every render, or when you want a class to not be forgetted, because you’re using it often.
pub fn min_height(height: Size) -> Style(a, b)
pub fn min_height_(height: String) -> Style(a, b)
pub fn min_width_(width: String) -> Style(a, b)
pub fn nth_child(
selector: String,
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn nth_last_child(
selector: String,
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn nth_last_of_type(
selector: String,
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn nth_of_type(
selector: String,
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn object_fit(object_fit: String) -> Style(a, b)
pub fn object_position(object_position: String) -> Style(a, b)
pub fn offset_anchor(offset_anchor: String) -> Style(a, b)
pub fn offset_distance(offset_distance: String) -> Style(a, b)
pub fn offset_path(offset_path: String) -> Style(a, b)
pub fn offset_position(offset_position: String) -> Style(a, b)
pub fn offset_rotate(offset_rotate: String) -> Style(a, b)
pub fn only_child(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn only_of_type(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn optional(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn outline_color(outline_color: String) -> Style(a, b)
pub fn outline_offset(outline_offset: String) -> Style(a, b)
pub fn outline_style(outline_style: String) -> Style(a, b)
pub fn outline_width(outline_width: String) -> Style(a, b)
pub fn overflow_x(overflow_x: String) -> Style(a, b)
pub fn overflow_y(overflow_y: String) -> Style(a, b)
pub fn padding_bottom(padding: Size) -> Style(a, b)
pub fn padding_left(padding: Size) -> Style(a, b)
pub fn padding_right(padding: Size) -> Style(a, b)
pub fn padding_top(padding: Size) -> Style(a, b)
pub fn place_content(place: String) -> Style(a, b)
pub fn place_items(place: String) -> Style(a, b)
pub fn place_self(place: String) -> Style(a, b)
pub fn placeholder(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn pointer_events(pointer_events: String) -> Style(a, b)
pub fn prepare(cache: Cache) -> Nil
Lifecycle function — not side-effect free
prepare
should be called before your repaint, and before the different
calls to class
and dynamic
functions. This setups
the cache to prepare for a new paint, and will allow for diffing the styles.
As long as you don’t call prepare
, the stylesheet output by sketch will not
diff, and you’ll use the stylesheet as append-only. This could be done at
will.
Be careful, the styles computed by class
and dynamic
will be pushed in the last cache called by prepare
, due to the styles
handling (and some side-effects under-the-hood for performance purposes).
pub fn pseudo_selector(
value: String,
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn read_only(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn read_write(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn render(cache: Cache) -> Result(String, Nil)
Lifecycle function — not side-effect free
render
takes a Cache, and render its content to the stylesheet, according
to the choice of the Cache. render
is idempotent, and can be called as
much as you want.
You can expect render
to return Ok(String) representing the stylesheet on
BEAM, and Error(Nil) on JS. It means there’s not output String in JS, but the
modification happened in the DOM!
pub fn required(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn target(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn text_align(text_align: String) -> Style(a, b)
pub fn text_decoration(text_decoration: String) -> Style(a, b)
pub fn text_justify(text_justify: String) -> Style(a, b)
pub fn text_overflow(text_overflow: String) -> Style(a, b)
pub fn text_transform(text_transform: String) -> Style(a, b)
pub fn to_class_name(class: Class) -> String
Convert a Class
to its proper class name, to use it anywhere in your
application. It can have the form class1
or class1 class2
in case of
classes composition.
pub fn to_lustre(class: Class) -> Attribute(a)
Convert a Class
to its equivalent lustre attribute. Use it in your
view functions. I.e. html.div([sketch.to_lustre(class())], [])
.
pub fn transform_box(transform_box: String) -> Style(a, b)
pub fn transform_origin(transform_origin: String) -> Style(a, b)
pub fn transform_style(transform_style: String) -> Style(a, b)
pub fn transition(transition: String) -> Style(a, b)
pub fn user_select(user_select: String) -> Style(a, b)
pub fn valid(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn visibility(visibility: String) -> Style(a, b)
pub fn visited(
styles: List(Style(NoMedia, NoPseudoSelector)),
) -> Style(a, PseudoSelector)
pub fn white_space(white_space: String) -> Style(a, b)
pub fn white_space_collapse(
white_space_collapse: String,
) -> Style(a, b)
pub fn word_break(word_break: String) -> Style(a, b)
pub fn word_spacing(word_spacing: String) -> Style(a, b)