lustre/ui/theme
Types
pub type ColourScaleVariables {
ColourScaleVariables(
bg: String,
bg_subtle: String,
tint: String,
tint_subtle: String,
tint_strong: String,
accent: String,
accent_subtle: String,
accent_strong: String,
solid: String,
solid_subtle: String,
solid_strong: String,
solid_text: String,
text: String,
text_subtle: String,
)
}
Constructors
-
ColourScaleVariables( bg: String, bg_subtle: String, tint: String, tint_subtle: String, tint_strong: String, accent: String, accent_subtle: String, accent_strong: String, solid: String, solid_subtle: String, solid_strong: String, solid_text: String, text: String, text_subtle: String, )
pub type FontVariables {
FontVariables(heading: String, body: String, code: String)
}
Constructors
-
FontVariables(heading: String, body: String, code: String)
Configuration for the different fonts that can be used in a themed application.
Each font String
should match the format you would write in a CSS font-family
rule.
If you are using custom fonts, remember to make sure the font is loaded in your
app, either through a <link>
tag, or a CSS @import
.
pub type Fonts {
Fonts(heading: String, body: String, code: String)
}
Constructors
-
Fonts(heading: String, body: String, code: String)
Configures the CSS selector used when applying a theme or a theme’s dark mode.
pub type Selector {
Global
Class(String)
DataAttribute(String, String)
}
Constructors
-
Global
-
Class(String)
-
DataAttribute(String, String)
Configuration for the different size values that can be used for different
parts of a themed application. Both a theme’s space
scale as well as the
different options for border radius
are configured by a SizeScale
.
Each field is a value in rem
units. So a value of 12.0
would be 12.0rem
in CSS, not 12.0px
. This means your space scale remains adaptive even
if the user configures their browser to render smaller or larger text (for
example when zooming or for accessibility reasons.)
pub type SizeScale {
SizeScale(
xs: Float,
sm: Float,
md: Float,
lg: Float,
xl: Float,
xl_2: Float,
xl_3: Float,
)
}
Constructors
-
SizeScale( xs: Float, sm: Float, md: Float, lg: Float, xl: Float, xl_2: Float, xl_3: Float, )
pub type SizeVariables {
SizeVariables(
xs: String,
sm: String,
md: String,
lg: String,
xl: String,
xl_2: String,
xl_3: String,
)
}
Constructors
-
SizeVariables( xs: String, sm: String, md: String, lg: String, xl: String, xl_2: String, xl_3: String, )
A Lustre UI theme dictates the visual style of an application. It defines a number of design tokens to set common styles such as fonts, colours, and spacing.
These design tokens can be used in your own components and styles to ensure a consistent look and feel in your application. For example you might want to colour a span of text with the primary colour of your theme by doing:
html.span([attribute.style([#("color", theme.primary.solid_text)])], [
html.text("Hello, world!")
])
You can construct a blank theme using the new
function, or start
with a sensible default using the Lustre UI’s default
theme.
A theme can be further customised using the various with_
functions, such
as with_primary_scale
, with_space
,
or with_dark_palette
.
pub opaque type Theme
Constants
pub const base: ColourScaleVariables
A record that lets you access theme tokens for the base colour scale of the theme. The base colour scale is typically a greyscale or neutral scale.
pub const colour: ColourScaleVariables
A record that lets you access theme tokens related to the current colour
scale. The current colour scale is context-dependent and depends on the
CSS cascade: if a parent element higher up the tree sets the data-scale
attribute or applies a class like .lustre-ui-primary
, these tokens will
match the colours from that scale.
pub const danger: ColourScaleVariables
A record that lets you access theme tokens for the danger colour scale of the theme. The danger colour scale is typically used in parts of your UI that indicate critical information or notify users that an action will have destructive consequences.
pub const font: FontVariables
A record that lets you access theme tokens related to fonts. You could use
these when styling elements yourself either with the style
attribute or
with sketch, a CSS-in-Gleam library.
pub const primary: ColourScaleVariables
A record that lets you access theme tokens for the primary colour scale of the theme. The primary colour scale is typically your brand colour.
pub const radius: SizeVariables
A record that lets you access theme tokens related to border radius. You
could use these when styling elements yourself either with the style
attribute or with sketch, a CSS-in-Gleam
library.
These border radius variables are typically used to round the corners of an element.
pub const secondary: ColourScaleVariables
A record that lets you access theme tokens for the secondary colour scale of the theme. The secondary colour scale is typically used as an accent or compliment to your primary colour.
pub const spacing: SizeVariables
A record that lets you access theme tokens related to spacing. You could use
these when styling elements yourself either with the style
attribute or
with sketch, a CSS-in-Gleam library.
These spacing variables are typically used to add margin or a gap between elements in a layout, or to add padding to an element.
pub const success: ColourScaleVariables
A record that lets you access theme tokens for the success colour scale of the theme. The success colour scale is typically used in parts of your UI that indicate an action was successful.
pub const warning: ColourScaleVariables
A record that lets you access theme tokens for the warning colour scale of the theme. The warning colour scale is typically used in parts of your UI to indicate non-critical information or notify users that an action may have non-destructive consequences.
Functions
pub fn augmented_forth(base: Float) -> SizeScale
pub fn default() -> Theme
Construct Lustre UI’s default theme. This theme defines some sensible defaults
for fonts, radius, and space, and provides both a light and dark mode palette.
The light mode palette applies globally, and the dark mode palette applies if
the user has enabled dark mode in their operating system or browser, or if you
manually set the "dark"
class on an element.
You can customise the theme further using the various with_
functions, such
as with_primary_scale
, with_space
,
with_dark_palette
, etc.
pub fn golden_ratio(base: Float) -> SizeScale
pub fn new(id: String, selector: Selector) -> Theme
Construct an empty theme with the given id and selector. The theme will have a sensible default configuration for fonts, radius, and space, but the colour palette will be empty.
You can customise the theme further using the various with_
functions, such
as with_primary_scale
, with_space
,
with_dark_palette
, etc.
pub fn perfect_fifth(base: Float) -> SizeScale
pub fn perfect_fourth(base: Float) -> SizeScale
pub fn use_danger() -> Attribute(a)
pub fn use_primary() -> Attribute(a)
pub fn use_secondary() -> Attribute(a)
pub fn use_success() -> Attribute(a)
pub fn use_warning() -> Attribute(a)
pub fn with_base_scale(theme: Theme, scale: ColourScale) -> Theme
Replace the base colour scale of a theme’s default colour palette with a new one.
pub fn with_body_font(theme: Theme, font: String) -> Theme
Replace the body font in a theme with a new value. The provided string
should match the kind of font stack you might write in a CSS font-family
rule.
The body font is typically used throughout an interface as the primary font in all copy.
pub fn with_code_font(theme: Theme, font: String) -> Theme
Replace the code font in a theme with a new value. The provided string
should match the kind of font stack you might write in a CSS font-family
rule.
The code font is typically a monospaced font used for code snippets in prose, but may also be used as an alternative heading font or otherwise used as an alternative to the body font.
pub fn with_danger_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the danger colour scale of a theme’s default colour palette with a new one.
pub fn with_dark_base_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the base colour scale of a theme’s dark mode colour palette with a new one. If the theme does not have a dark mode registered, calling this function will do nothing.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_dark_danger_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the danger colour scale of a theme’s dark mode colour palette with a new one. If the theme does not have a dark mode registered, calling this function will do nothing.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_dark_palette(
theme: Theme,
selector: Selector,
palette: ColourPalette,
) -> Theme
Add a new dark mode colour palette or replace a theme’s existing palette with a new one.
The Selector
used to apply a theme will switch over to the
dark mode colour palette if a user has indicated through their OS settings
that they prefer a dark colour scheme. Additionally, a selector other than
Global
can be used to enable dark mode for a specific part of the UI.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_dark_primary_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the primary colour scale of a theme’s dark mode colour palette with a new one. If the theme does not have a dark mode registered, calling this function will do nothing.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_dark_secondary_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the secondary colour scale of a theme’s dark mode colour palette with a new one. If the theme does not have a dark mode registered, calling this function will do nothing.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_dark_success_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the success colour scale of a theme’s dark mode colour palette with a new one. If the theme does not have a dark mode registered, calling this function will do nothing.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_dark_warning_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the warning colour scale of a theme’s dark mode colour palette with a new one. If the theme does not have a dark mode registered, calling this function will do nothing.
All of the colour scales in the colours module have corresponding dark mode variants
pub fn with_fonts(theme: Theme, fonts: Fonts) -> Theme
Set all of the fonts in a theme at once.
pub fn with_heading_font(theme: Theme, font: String) -> Theme
Replace the heading font in a theme with a new value. The provided string
should match the kind of font stack you might write in a CSS font-family
rule.
The heading font is typically used in the title and section headings in prose, but can also be used in heroes and other prominent sections.
pub fn with_light_palette(
theme: Theme,
light: ColourPalette,
) -> Theme
Set a theme’s default colour palette with a new one.
pub fn with_primary_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the primary colour scale of a theme’s default colour palette with a new one.
pub fn with_radius(theme: Theme, scale: SizeScale) -> Theme
Set the size scale used for border radius in a theme. The radius scale determines how rounded the elements in your application UI appear.
pub fn with_secondary_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the secondary colour scale of a theme’s default colour palette with a new one.
pub fn with_space(theme: Theme, scale: SizeScale) -> Theme
Set the space scale in a theme. The space scale determines how much visual space there is in your UI. It is used both within elements as padding and between elements to separate them in a collection.
pub fn with_success_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the success colour scale of a theme’s default colour palette with a new one.
pub fn with_warning_scale(
theme: Theme,
scale: ColourScale,
) -> Theme
Replace the warning colour scale of a theme’s default colour palette with a new one.