Skip to main content

Crate next_rust_ui

Crate next_rust_ui 

Source
Expand description

Ready-made UI components for Next Rust.

use next_rust_ui::*;
use next_rust_view::*;

let form = form![
    Input![label = "Email", name = "email", kind = "email", placeholder = "you@example.com"],
    PasswordInput![label = "Password", name = "password"],
    Button![color = Color::Primary, submit = true, class("w-full"), "Sign in"],
];
let html = render_static(form);
assert!(html.contains(r#"class="nr-btn nr-btn-solid nr-c-primary nr-btn-md w-full""#));

Every component is a builder with a macro of the same name. Inside the macro, key = value sets a property and anything else is added like in an element macro: attributes (class(..), id(..), aria(..), data(..)) and children. Every property is optional.

Styling:

  • Each component has default classes (nr-btn, nr-input, …) whose rules live in the CSS components layer. Classes you add, Tailwind utilities or your own CSS, always win over them, without !important.
  • unstyled = true drops the default classes of the outer element.
  • Colors, radii and shadows are CSS variables (--nr-primary, --nr-radius-md, …): set them on :root to theme every component. Dark mode follows the system, or class="dark" / data-theme="dark" on an ancestor.
  • Pages receive only the CSS of the components they render.

Interactive components (select, date picker, password toggle, tabs with panels, modals, closable alerts, on_press) load a small script, /_next-rust/ui.js, on the pages that use them. Without it they fall back to the native control (a <select>, a <dialog>, <details>), so pages keep working.

Macros§

Accordion
Build a Accordion: key = value sets a property, anything else is added as an attribute or child.
AccordionItem
Build a AccordionItem: key = value sets a property, anything else is added as an attribute or child.
Alert
Build a Alert: key = value sets a property, anything else is added as an attribute or child.
AppShell
Build a AppShell: key = value sets a property, anything else is added as an attribute or child.
Avatar
Build a Avatar: key = value sets a property, anything else is added as an attribute or child.
AvatarGroup
Build a AvatarGroup: key = value sets a property, anything else is added as an attribute or child.
Badge
Build a Badge: key = value sets a property, anything else is added as an attribute or child.
BreadcrumbItem
Build a BreadcrumbItem: key = value sets a property, anything else is added as an attribute or child.
Breadcrumbs
Build a Breadcrumbs: key = value sets a property, anything else is added as an attribute or child.
Button
Build a Button: key = value sets a property, anything else is added as an attribute or child.
ButtonGroup
Build a ButtonGroup: key = value sets a property, anything else is added as an attribute or child.
Card
Build a Card: key = value sets a property, anything else is added as an attribute or child.
CardBody
Build a CardBody: key = value sets a property, anything else is added as an attribute or child.
CardFooter
Build a CardFooter: key = value sets a property, anything else is added as an attribute or child.
CardHeader
Build a CardHeader: key = value sets a property, anything else is added as an attribute or child.
Checkbox
Build a Checkbox: key = value sets a property, anything else is added as an attribute or child.
Chip
Build a Chip: key = value sets a property, anything else is added as an attribute or child.
CircularProgress
Build a CircularProgress: key = value sets a property, anything else is added as an attribute or child.
Container
Build a Container: key = value sets a property, anything else is added as an attribute or child.
DatePicker
Build a DatePicker: key = value sets a property, anything else is added as an attribute or child.
Divider
Build a Divider: key = value sets a property, anything else is added as an attribute or child.
EmptyState
Build a EmptyState: key = value sets a property, anything else is added as an attribute or child.
Grid
Build a Grid: key = value sets a property, anything else is added as an attribute or child.
Input
Build a Input: key = value sets a property, anything else is added as an attribute or child.
Kbd
Build a Kbd: key = value sets a property, anything else is added as an attribute or child.
Modal
Build a Modal: key = value sets a property, anything else is added as an attribute or child.
ModalBody
Build a ModalBody: key = value sets a property, anything else is added as an attribute or child.
ModalFooter
Build a ModalFooter: key = value sets a property, anything else is added as an attribute or child.
Navbar
Build a Navbar: key = value sets a property, anything else is added as an attribute or child.
NavbarItem
Build a NavbarItem: key = value sets a property, anything else is added as an attribute or child.
PasswordInput
Build a PasswordInput: key = value sets a property, anything else is added as an attribute or child.
Progress
Build a Progress: key = value sets a property, anything else is added as an attribute or child.
Radio
Build a Radio: key = value sets a property, anything else is added as an attribute or child.
RadioGroup
Build a RadioGroup: key = value sets a property, anything else is added as an attribute or child.
Select
Build a Select: key = value sets a property, anything else is added as an attribute or child.
SelectItem
Build a SelectItem: key = value sets a property, anything else is added as an attribute or child.
Sidebar
Build a Sidebar: key = value sets a property, anything else is added as an attribute or child.
SidebarItem
Build a SidebarItem: key = value sets a property, anything else is added as an attribute or child.
Skeleton
Build a Skeleton: key = value sets a property, anything else is added as an attribute or child.
Spinner
Build a Spinner: key = value sets a property, anything else is added as an attribute or child.
Stack
Build a Stack: key = value sets a property, anything else is added as an attribute or child.
Stat
Build a Stat: key = value sets a property, anything else is added as an attribute or child.
Step
Build a Step: key = value sets a property, anything else is added as an attribute or child.
Steps
Build a Steps: key = value sets a property, anything else is added as an attribute or child.
Switch
Build a Switch: key = value sets a property, anything else is added as an attribute or child.
Tab
Build a Tab: key = value sets a property, anything else is added as an attribute or child.
Table
Build a Table: key = value sets a property, anything else is added as an attribute or child.
Tabs
Build a Tabs: key = value sets a property, anything else is added as an attribute or child.
Textarea
Build a Textarea: key = value sets a property, anything else is added as an attribute or child.
Tooltip
Build a Tooltip: key = value sets a property, anything else is added as an attribute or child.

Structs§

Accordion
Sections that expand one at a time (or several, with multiple).
AccordionItem
One section of an Accordion: a <details> element, so it opens and closes without any script.
Alert
A message that stands out: information, a success, a warning, an error.
AppShell
A full page layout: navbar on top, sidebar on the left (a drawer on small screens, opened by the navbar’s menu_toggle), content in the middle.
Avatar
A user picture. Without src, or when the image fails to load, it shows the initials of name.
AvatarGroup
Overlapping avatars, with a +N count past max.
Badge
A count or a dot pinned to a corner of its child (an icon, an avatar).
BreadcrumbItem
One crumb; the last one is the current page.
Breadcrumbs
The path to the current page.
Button
A button, or a link styled as one (href).
ButtonGroup
Buttons joined into one control.
Card
A surface grouping related content, with optional header and footer.
CardBody
The main content of a Card.
CardFooter
The bottom of a Card, typically actions.
CardHeader
The top of a Card.
Checkbox
A checkbox with a label.
Chip
A small label: a tag, a status, a count.
CircularProgress
A ring that fills up.
Container
Centered content with a maximum width and side padding.
DatePicker
A date field with a calendar: month and year views, keyboard navigation, minimum and maximum dates. The value is an ISO date (2026-09-18); it is shown in the visitor’s locale.
Divider
A thin line between content.
EmptyState
What to show when there is nothing to show yet.
Grid
A responsive grid: cols columns on wide screens, fewer on narrow ones. With min_width, as many columns as fit.
Input
A text input.
Kbd
A keyboard key: Kbd!["⌘", "K"] renders two keys.
Modal
A dialog over the page: a <dialog> element.
ModalBody
The content of a Modal.
ModalFooter
The bottom of a Modal, typically its actions.
Navbar
A top bar: brand on the left, links in the middle, actions on the right.
NavbarItem
A navbar link, highlighted on its page.
PasswordInput
A password input with a button that shows and hides the password.
Press
Behavior for on_press: call a server action, navigate, dispatch an event, or run a script.
Progress
A horizontal progress bar.
Radio
One choice of a RadioGroup.
RadioGroup
Radio buttons sharing a name, with a label, description and error.
Select
A select with a styled listbox: keyboard navigation, type-ahead, single or multiple choice. Submits like a native <select> (it is one underneath).
SelectItem
One option of a Select. The text children are its label.
Sidebar
A vertical navigation list.
SidebarItem
A sidebar link with an optional icon, highlighted on its page.
Skeleton
A placeholder that shimmers while the real content loads.
Spinner
A loading indicator.
Stack
Children in a column (or a row) with even spacing.
Stat
A number with its label: “Students · 1,204 · ↑ 12%”.
Step
One step of a process. Children are extra content under the description.
Steps
Where someone is in a process.
Switch
An on/off switch.
Tab
One tab. With href it is a link (the page decides which is selected, by selected or by matching the current path with the client runtime); with children it is a panel the component script switches to.
Table
A data table. columns become the header; the children are the rows (tr![td![..], ..]), placed in the body. Wide tables scroll sideways inside their box instead of breaking the page.
Tabs
A strip of tabs: links between pages, or panels switched in place.
Textarea
A multi-line text input that grows with its content.
Tooltip
A short text shown on hover or focus. CSS only: the anchor is the child, which should be focusable (a button, a link) so keyboard users see it too.

Enums§

AccordionVariant
Look of an Accordion.
Align
Cross-axis alignment of a Stack.
Color
Color of a component.
FieldVariant
Visual style of text fields, selects and date pickers.
Justify
Main-axis distribution of a Stack.
LabelPlacement
Where a field’s label goes.
ModalPlacement
Where a Modal sits on the screen.
Placement
Where a Badge sits on its child.
Radius
Corner rounding. None in a builder keeps the component’s own default.
Shadow
Shadow depth.
Side
Side of the anchor a Tooltip shows on.
Size
Size of a component.
StepStatus
State of a Step.
TabsVariant
Look of a Tabs strip.
Trend
Direction of a Stat’s change.
Variant
Visual style of buttons and chips.
Width
Maximum width of a Container.

Constants§

UI_JS
Readable source of the component script.
UI_JS_MIN
UI_JS, minified.

Statics§

UI_CSS
The component stylesheet. Components add it to the page themselves; only the rules for the components a page renders are sent.

Traits§

MaybeText
Text that may be absent: &str, String or an Option of either, so error_message = form.error("email") works as is.

Functions§

rename_script_classes
script with every nr-* class name replaced through rename, for release builds that give the component classes short names. A class name is a whole nr-… token (so data-nr-ui is left alone).