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), thepartbuilder and the shared styles. Components copied into a project withweft ui adduse them throughuse 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 asrc, errors, the legend, the tooltip, the source line and the table view.
Structs
- AlertStyle
Styling for
Alerttones. - 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) -> AlertStyleThe 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).
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) -> StringClasses for Button variants and sizes.
chart_color
pub fn chart_color(i: usize) -> &'static strThe 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) -> StringA 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).
cx
pub fn cx(parts: &[&str]) -> StringJoin 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.
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) -> StringThe file name from a file input's value (C:\fakepath\cat.png → cat.png).
format_number
pub fn format_number(n: f64) -> StringThousands 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.
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.
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.
responsive_classes
pub fn responsive_classes(value: &str, default: &str, to_classes: impl Fn(&str) -> String) -> StringA 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.
theme_with
pub fn theme_with(brand: &str, accent: &str) -> ThemeA 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) -> Stringleft/top (in % of the drawing) for a tooltip anchored at (x, y).
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).