Skip to content

Feedback

github-actions[bot] edited this page Nov 26, 2026 · 7 revisions

Feedback Components

Alerts, badges, progress indicators and toasts report the status of the application. Install cn_bundle() as described in Getting Started. The examples use these imports and the ctx of the application builder:

use blinc::cn::prelude::*;
use blinc::layout::prelude::{div, text};

Alert

alert(message) shows a single message. alert_box() adds a title and a description:

alert("Your changes are ready to save.")
alert_box()
    .title("Heads up!")
    .description("Review the details before continuing.")

Variants

Both accept Default, Success, Warning or Destructive:

div().flex_col().gap(2.0)
    .child(alert("Saved").variant(AlertVariant::Success))
    .child(alert("Low disk space").variant(AlertVariant::Warning))
    .child(alert_box()
        .variant(AlertVariant::Destructive)
        .title("Upload failed")
        .description("Check your connection and try again."))

Messages, titles and descriptions can bind to Signals or Computeds. The root is .cn-alert or .cn-alert-box, with a variant class such as .cn-alert--success or .cn-alert--error. To change colors, restyle those rules. Do not pick colors in the component builder.

Badge

A badge has a variant for its meaning and a style for its appearance:

div().flex_row().gap(2.0)
    .child(badge("New"))
    .child(badge("3").variant(BadgeVariant::Secondary))
    .child(badge("Error").variant(BadgeVariant::Destructive))
    .child(badge("Beta").style(BadgeStyle::Outline))

Variants are Default, Secondary, Success, Warning and Destructive. Styles are Soft (the default), Solid and Outline:

badge("Done").variant(BadgeVariant::Success).style(BadgeStyle::Solid)

With an Icon

.icon(..) accepts an element builder:

badge("Verified")
    .variant(BadgeVariant::Success)
    .icon_position(IconPosition::Start)
    .icon(icon(icons::CHECK).size_px(12.0))

A Bound Label

To convert a Signal or Computed, use IntoReactive:

use blinc::core::reactive::computed;
use blinc::layout::binding::IntoReactive;

let count = ctx.use_signal(3usize);
let shown = computed(move |graph| format!("{} new", graph.get(count).unwrap_or(0)));

badge("").reactive_label(shown.into_reactive())

The root is .cn-badge. Its fill, border and text color come from .cn-badge--{style}-{variant}, such as .cn-badge--soft-success. For application overrides, you can add a custom class:

badge("Done").variant(BadgeVariant::Success).class("my-badge")
.my-badge { border-radius: 4px; }
.cn-badge--soft-success { background: #052e16; border-color: #16a34a; color: #4ade80; }

Progress

Values are in the 0..=100 range:

progress(75.0)

Bound to a Signal

An f32, Signal<f32> or Computed<f32> can drive the bar. Bound values change in place. The transition on .cn-progress-bar eases each change:

let pct = ctx.use_signal(0.0_f32);

div()
    .child(progress(pct).w(300.0))
    .child(button("Advance").on_click(move |_| {
        pct.update(|value| (value + 10.0).min(100.0));
    }))

Indeterminate

For work of unknown length, use this bar:

progress_indeterminate().w(300.0)

The track is .cn-progress, with data-size. If the progress is indeterminate, the track also has data-indeterminate. The bar is .cn-progress-bar. The track and the bar take their colors from --cn-progress-track and --cn-progress-bar. The transition and the cn-progress-pulse keyframes control the motion.

With a Label

use blinc::core::reactive::computed;

let pct = ctx.use_signal(0.0_f32);
let shown = computed(move |graph| format!("{}%", graph.get(pct).unwrap_or(0.0) as i32));

div().flex_col().gap(1.0)
    .child(div().flex_row().justify_between()
        .child(label("Uploading"))
        .child(label(shown)))
    .child(progress(pct))

Spinner

spinner().size(SpinnerSize::Medium)

Sizes are Small (16px), Medium (24px, the default) and Large (32px). The track is .cn-spinner__track. The cn-spinner-turn keyframes turn .cn-spinner__arc. To set the speed, use CSS:

.slow-spinner .cn-spinner__arc { animation-duration: 2000ms; }

Beside a Busy Button

A button binds its label and disabled prop. While the button is busy, add a spinner next to it:

use blinc::core::reactive::computed;

let busy = ctx.use_signal(false);
let caption = computed(move |graph| {
    if graph.get(busy).unwrap_or(false) { "Saving" } else { "Save" }.to_string()
});

div().flex_row().items_center().gap(2.0)
    .child(button(caption).disabled(busy).on_click(move |_| busy.set(true)))
    .show(busy, || div().child(spinner().size(SpinnerSize::Small)))
    .child(button("Finish").on_click(move |_| busy.set(false)))

In an application, the callback for the completed request clears busy. In this example, the Finish button makes that completion explicit. There is no button .loading(...) prop.

Skeleton

The cn-skeleton-pulse keyframes make a skeleton pulse:

div().flex_col().gap(2.0)
    .child(skeleton().w(200.0).h(20.0))
    .child(skeleton_circle(48.0))

The root is .cn-skeleton. A circle also has .cn-skeleton--circle. To override the animation, use a custom class:

.my-skeleton { animation-duration: 3000ms; }

Card Skeleton

card().child(card_content().child(
    div().flex_col().gap(2.0)
        .child(skeleton().w(150.0).h(24.0))
        .child(skeleton().w(200.0).h(16.0))
        .child(skeleton().w_full().h(100.0)),
))

Toast

Show notifications from an event or an application callback:

button("Notify").on_click(|_| {
    toast("Success")
        .description("Your changes have been saved.")
        .show();
})

toast_success, toast_warning and toast_error select variants directly. .duration_ms(..) sets the lifetime. With .persistent(), the toast waits for dismissal. .corner(..) sets the tray corner. .show() returns a handle, and the .dismiss() method of the handle removes that toast.

With an Action

let undone = ctx.use_signal(false);

button("Create event").on_click(move |_| {
    toast("Event created")
        .description("The event is on your calendar.")
        .action("Undo", move || undone.set(true))
        .duration_ms(5000)
        .show();
})

Styling and Motion

The root is .cn-toast with data-variant: default, success, warning or destructive. The parts include .cn-toast-icon, .cn-toast-title, .cn-toast-description and .cn-toast-close. To override the defaults, set --cn-toast-bg and --cn-toast-border.

Depending on the corner of the toast, its wrapper is .cn-toast-motion-right or .cn-toast-motion-left. The wrapper carries data-motion="enter" or "exit". It remains mounted until the exit completes:

.cn-toast-motion-right[data-motion="exit"] {
    animation: cn-slide-to-right 400ms var(--ease-in) forwards;
}

Examples

Loading State

To make content follow the Signal after construction, use a conditional region:

let loading = ctx.use_signal(true);

div().flex_col().gap(3.0)
    .child(button("Toggle loading").on_click(move |_| loading.update(|value| !value)))
    .show_or(loading,
        || div().flex_col().items_center().gap(2.0)
            .child(spinner().size(SpinnerSize::Large))
            .child(text("Loading")),
        || div().child(text("Content is ready")),
    )

Form Submission Feedback

The application owns the request state. Bind the button to that state, and mount the feedback through a computed condition. In this interactive example, the completion button takes the place of a request callback:

use blinc::core::reactive::computed;

let submitting = ctx.use_signal(false);
let message = ctx.use_signal(String::new());
let has_message = computed(move |graph| !graph.get(message).unwrap_or_default().is_empty());

div().flex_col().gap(3.0)
    .child(button("Submit").disabled(submitting).on_click(move |_| {
        message.set(String::new());
        submitting.set(true);
    }))
    .show(submitting, move || {
        div().flex_col().gap(2.0)
            .child(spinner())
            .child(button("Complete request").on_click(move |_| {
                submitting.set(false);
                message.set("Form submitted successfully.".to_string());
            }))
    })
    .show(has_message, move || {
        div().child(alert(message).variant(AlertVariant::Success))
    })

Signals update props or regions. Neither example branches on a value that it reads once at build time. For error feedback, you can use a separate error Signal and a Destructive alert, with the same binding pattern.

Notification Helpers

fn notify_success(message: &str) {
    blinc::cn::cn::toast_success("Success")
        .description(message)
        .duration_ms(5000)
        .show();
}

fn notify_error(message: &str) {
    blinc::cn::cn::toast_error("Error")
        .description(message)
        .duration_ms(10000)
        .show();
}

Navigation

Getting Started

Migrating

Mobile Development

Example Gallery

Web Development

Core Concepts

Animation

Components

Component Library (blinc_cn)

Widgets

Canvas Kit

Advanced

Architecture

Contributing

Clone this wiki locally