Skip to content

module

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::*;.

Structs

  • AlertStyle

    Styling for Alert tones.

  • Bar

    One bar of a bar chart, in chart coordinates.

  • Bind

    Fluent scope builder for component setup functions.

  • FieldCtx

    What a Field shares with the control, label, description and error inside it (context "field"), so they link up with ARIA.

  • ShellCtx

    Shared by the AppShell parts: whether the sidebar is open on small screens.

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).

aria

pub fn aria(b: bool) -> Value

"true" / "false" for ARIA attributes.

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).

classes

pub fn classes(p: &Props, own: &str) -> String

own classes with the caller's class prop winning; with unstyled, only the caller's.

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).

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.

field

pub fn field(v: &Value, name: &str) -> Value

A record field, or Null.

field_text

pub fn field_text(v: &Value, name: &str) -> String

Field name of record v, as text.

flag

pub fn flag(p: &Props, name: &str, default: bool) -> bool

Prop name as a flag, or default: a bare attribute or true is true.

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).

list

pub fn list(p: &Props, name: &str) -> Vec<Value>

Prop name as a list (empty when it isn't one).

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ⁿ).

num

pub fn num(p: &Props, name: &str, default: f64) -> f64

Prop name as a number, or default.

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.

part

pub fn part(name: &str, tag: &str, own: &'static str) -> Component

A part: one element with default classes and a slot; the caller's class wins and other attributes and handlers are forwarded.

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: …).

prop

pub fn prop(p: &Props, name: &str) -> Option<Value>

Prop lookup that accepts both snake_case and kebab-case names. Only a missing (or null) prop is None: an empty string is a value ("nothing here"), so defaults never replace it.

rec

pub fn rec(pairs: &[(&str, Value)]) -> Value

A record from (key, value) pairs.

responsive

pub fn responsive(p: &Props, name: &str, default: &str, to_classes: impl Fn(&str) -> String) -> String

A styling prop's classes, with a value per breakpoint (see crate::styles::responsive_classes).

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.

stars

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

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

text

pub fn text(p: &Props, name: &str, default: &str) -> String

Prop name as text, or default.

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.

weekday

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

Day of the week, Monday = 0.

when

pub fn when(b: bool, v: impl Into<Value>) -> Value

Value::Null (attribute omitted) unless b.

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.