Skip to content

crate

weft_ui

weft-ui

An accessible, Tailwind-styled component library for Weft — layout, actions, data display, feedback, overlays, navigation, forms, charts and 3D/shader graphics. Every component is a Component usable by name in templates once registered:

let registry = weft_ui::registry().with(my_page());
weft::web::start_themed("#app", app(), registry, weft_ui::theme());

Components style themselves with brand-* and accent-* color scales; theme_with rebrands the whole library.

Modules

  • catalogue

    Documentation for every component family: a summary, a live usage example, and each part's props and events. Drives the component catalogue page and the language server's hovers, completions and prop checks.

  • kit

    The helpers the components are built from: prop binding (kit::Bind, prop, text, flag), class merging (classes, cls, cx), the part builder and the shared styles. Components copied into a project with weft ui add use them through use weft::ui::kit::*;.

  • testing

    Helpers for testing apps built with weft-ui (used by the examples).

  • viz

    Charts: every one is a layout function (charts) in the same frame, which handles loading a src, errors, the legend, the tooltip, the source line and the table view.

Structs

  • AlertStyle

    Styling for Alert tones.

  • Bar

    One bar of a bar chart, in chart coordinates.

  • TreeRow

    One visible row of a Tree: its key and path, label and icon, depth, whether it has children and is expanded, and its parent row.

Functions

add_months

pub fn add_months(y: i32, m: u32, delta: i32) -> (i32, u32)

The month after/before (y, m) by delta months.

alert_style

pub fn alert_style(tone: &str) -> AlertStyle

The classes and icon for an alert of tone (info, success, warning, danger).

arc_midpoint

pub fn arc_midpoint(cx: f32, cy: f32, r: f32, start: f32, end: f32) -> (f32, f32)

The point at radius r halfway along an arc from start to end (degrees clockwise from 12 o'clock).

badge_classes

pub fn badge_classes(tone: &str) -> String

Classes for Badge tones.

bar_layout

pub fn bar_layout(values: &[(String, f64)], width: f32, height: f32, pad: f32) -> Vec<Bar>

Lay out bars inside a width × height box with pad margins.

button_classes

pub fn button_classes(variant: &str, size: &str, full: bool) -> String

Classes for Button variants and sizes.

chart_color

pub fn chart_color(i: usize) -> &'static str

The chart palette's colour for series i (it repeats after the last).

civil_from_days

pub fn civil_from_days(z: i64) -> (i32, u32, u32)

Days since 1970-01-01 → (year, month, day) (Howard Hinnant's algorithm).

cls

pub fn cls(own: &str, caller: &str) -> String

A part's own classes combined with the caller's class, the caller's winning — over the part's responsive and state variants too (see weft_tailwind::merge_override).

components

pub fn components() -> Vec<Component>

Every component in the library.

cx

pub fn cx(parts: &[&str]) -> String

Join non-empty class fragments with single spaces.

Conflicting classes are merged so later ones win (cx(&["px-5 py-2", "p-10"]) → "p-10"), which lets a component's class prop override its own styling.

days_in_month

pub fn days_in_month(y: i32, m: u32) -> u32

How many days month m (1–12) of year y has.

donut_segments

pub fn donut_segments(values: &[f64], gap_deg: f32) -> Vec<(f32, f32)>

Start/end angles (degrees, clockwise from 12 o'clock) for donut slices.

file_name

pub fn file_name(value: &str) -> String

The file name from a file input's value (C:\fakepath\cat.png → cat.png).

format_date

pub fn format_date(y: i32, m: u32, d: u32) -> String

A date as YYYY-MM-DD.

format_delta

pub fn format_delta(n: f64) -> String

"+12.5%" / "-3%".

format_number

pub fn format_number(n: f64) -> String

Thousands separators for large/whole numbers; up to two decimals for small fractional ones.

hover_columns

pub fn hover_columns(points: &[(f32, f32)], left: f32, right: f32) -> Vec<(f32, f32)>

Horizontal (start, end) bands, one per point, splitting the space left..right halfway between neighbours — so hovering anywhere picks the nearest point.

initials

pub fn initials(name: &str) -> String

"Ada Lovelace" → "AL".

is_leap

pub fn is_leap(y: i32) -> bool

Whether y is a leap year.

line_points

pub fn line_points(values: &[f64], width: f32, height: f32, pad: f32) -> Vec<(f32, f32)>

Points of a line chart (minimum at the bottom, including 0).

month_grid

pub fn month_grid(y: i32, m: u32) -> Vec<[Option<u32>; 7]>

Weeks of a month (Monday first); None pads days outside it.

nice_max

pub fn nice_max(v: f64) -> f64

A "nice" axis maximum ≥ v (1, 2, 2.5, 3, 4, 5, 6, 8 × 10ⁿ).

pagination_window

pub fn pagination_window(page: usize, pages: usize) -> Vec<Option<usize>>

Page numbers to show (1-based) with None for ellipses.

parse_date

pub fn parse_date(s: &str) -> Option<(i32, u32, u32)>

"YYYY-MM-DD" → (year, month, day) if valid.

percent

pub fn percent(value: f64, max: f64) -> f64

value / max as a percentage clamped to 0..=100.

points_attr

pub fn points_attr(points: &[(f32, f32)]) -> String

"x,y x,y …" for path(points: …).

register

pub fn register(registry: &mut Registry)

Add every component to registry.

registry

pub fn registry() -> Registry

A registry holding the whole library.

responsive_classes

pub fn responsive_classes(value: &str, default: &str, to_classes: impl Fn(&str) -> String) -> String

A styling prop's classes, with a value per breakpoint: "vertical md:horizontal" gives to_classes("vertical") plus to_classes("horizontal") under md:. Without a plain value, default applies below the first breakpoint. A prefix starts with a letter, so 16:9 stays one value.

roving_target

pub fn roving_target(key: &str, index: usize, count: usize) -> Option<usize>

Arrow/Home/End navigation within a group of count items.

smooth_samples

pub fn smooth_samples(points: &[(f32, f32)], per_segment: usize) -> Vec<(f32, f32)>

Sample a Catmull-Rom curve through points (per_segment samples per segment, passing through every point) — used for smooth chart areas.

sort_rows

pub fn sort_rows(rows: &[Value], sort: Option<(&str, bool)>) -> Vec<usize>

Row order for a sort: None keeps the given order.

stars

pub fn stars(value: f64, max: u32) -> String

"★★★★☆" for 4 out of 5.

theme

pub fn theme() -> Theme

The default theme: violet brand, cyan accent.

theme_with

pub fn theme_with(brand: &str, accent: &str) -> Theme

A theme with custom brand and accent scales (generated from their 500 shades).

tip_style

pub fn tip_style(x: f32, y: f32, w: f32, h: f32) -> String

left/top (in % of the drawing) for a tooltip anchored at (x, y).

today

pub fn today() -> (i32, u32, u32)

Today's date (UTC) from the system clock.

tree_rows

pub fn tree_rows(items: &[Value], expanded: &BTreeSet<String>) -> Vec<TreeRow>

Flatten the visible part of a tree (children of expanded nodes only).

weekday

pub fn weekday(y: i32, m: u32, d: u32) -> u32

Day of the week, Monday = 0.

Constants

CHART_COLORS

pub const CHART_COLORS: &[&str] = _;

Default categorical chart colors.

MONTHS

pub const MONTHS: [&str; 12] = _;

The months' names, January first.

WEEKDAYS

pub const WEEKDAYS: [&str; 7] = _;

The days' names, Monday first.