Skip to main content

Crate topcoat_ant_design

Crate topcoat_ant_design 

Source
Expand description

§Topcoat Ant Design

English · 简体中文

topcoat-ant-design provides a reusable Rust library and a component Gallery binary behind the gallery feature. Components handle presentation, browser state, and interaction. They do not depend on a domain model, database, or external service.

Available components: Icons, Notification, Popconfirm, Dropdown Menu, Dialog, Tag, Tooltip, Collapse, Accordion, Tabs, Drawer, Table, Calendar, FormField, and DateTimeRange.

The AI component set includes messages, sending, conversation navigation, Markdown, process details, sources, actions, attachments, and prompts. The Gallery’s AI Components section shows individual examples and a composed Chat interface.

The current scope and next steps are recorded in AI component requirements. See the Chat component guide for the public API and host integration boundary.

See the complete integration guide or its Chinese version.

This library targets Topcoat 0.11.0. Interactive hosts must enable .runtime() on the router and include topcoat::runtime::script() in the document head.

See the 0.11 feature audit for component coverage and adoption decisions.

§Add the dependency

Starting with 0.11.0, this library uses the same version number as the supported Topcoat release. This release keeps the component APIs from 0.4.0.

Version 0.11.0 targets Topcoat 0.11.0 and requires Rust 1.99 or newer. When upgrading from 0.3.x, follow the Dropdown Menu guide for the updated target/id/close API.

Repository development uses Rust 1.99.1, pinned in rust-toolchain.toml, with rustfmt and clippy. Applications using this library must select a compatible toolchain in their own repository and build environment; dependency toolchain files are not inherited. See toolchain setup.

For the published version:

[dependencies]
topcoat-ant-design = "=0.11.0"

For local component development:

[dependencies]
topcoat-ant-design = { path = "../topcoat-ant-design" }

The default feature is sufficient to render components. Enable router only when the host uses selective route discovery and must explicitly register font routes:

topcoat-ant-design = { version = "=0.11.0", features = ["router"] }

§CSS, fonts, and assets

The library builds its own Tailwind component CSS and exposes it as a Topcoat Asset. The host does not need a build dependency on this crate or a path to its CSS. Call head_assets() in the root layout, then load and serve the Topcoat asset bundle from the host Router:

ⓘ
use topcoat_ant_design::head_assets;

Ok(view! {
    <head>
        head_assets()
    </head>
})

For selective route discovery, enable router and register the library’s Fontsource routes:

ⓘ
use topcoat_ant_design::RouterBuilderUiExt;
use topcoat::{
    asset::{AssetBundle, RouterBuilderAssetExt},
    runtime::RouterBuilderRuntimeExt,
};

let app_assets = AssetBundle::load().expect("load Topcoat asset bundle");
let router = topcoat::router::module_router!()
    .runtime()
    .topcoat_ant_design()
    .assets(app_assets)
    .build();

The host creates app_assets; it is not a global variable supplied by the library. Full .discover() already discovers the font routes, so use one registration strategy. JetBrains Mono is the default font at weights 400, 500, 600, and 700; Chinese glyphs fall back to the system font. Fontsource currently uses its default jsDelivr source. A fresh build may download the pinned Tailwind CLI through Topcoat. Component CSS does not include Tailwind Preflight.

§Icons and components

The build stages the Ant Design Iconify set from the committed icons/ant-design.json cache. Import a validated constant and render it with Topcoat’s native icon component:

ⓘ
use topcoat_ant_design::icons::PROJECT_OUTLINED;
use topcoat::icon::icon;

Ok(view! { icon(data: PROJECT_OUTLINED, label: "GitLab projects") })

The caller owns browser state through Topcoat signals. For example:

ⓘ
use topcoat_ant_design::{NotificationTone, notification};
use topcoat::runtime::signal;

let notice = signal(cx, String::new);

Ok(view! {
    <button @click=$(|_e| notice.set("Saved successfully.".to_owned()))>"Save"</button>
    notification(
        message: &notice,
        title: "Saved",
        tone: NotificationTone::Success,
    )
})

Popconfirm uses a trusted stable ID to associate its trigger and bubble; provide the business action in the child confirm button. The official Dropdown Menu groups actions in a native <details> control. For forms that require a modal with focus trapping and for menus inside scrollable tables, use the separate Native Dialog and Anchored Menu extensions. Collapse shares one signal between its trigger attributes and content. Official Tabs use real links and a host-provided active state. Drawer composes the official Sheet, accepts a Signal<bool>, and can navigate to a close URL through DrawerConfig::with_close_href. Each component has an English guide and a Chinese guide.

Built-in component labels default to English. Pass language: UiLanguage::ChineseSimplified to composed components that provide their own controls, such as Notification, Popconfirm, Drawer, and DateTimeRange, when the host page is in Chinese.

§Topcoat native UI

All 34 Topcoat 0.11.0 registry components are re-exported directly from topcoat_ant_design; their modules also remain available under topcoat_ant_design::ui. For example, use topcoat_ant_design::{button, ButtonVariant, dialog, dialog_content};. The upstream registry state is recorded in components.toml.

This root-level API is available in version 0.2.0 and later.

The official implementations replace the former local Accordion, Dialog, Dropdown Menu, Tabs, and Tooltip components. Use their official root-level names and composition APIs. Distinct composites such as data_table, drawer, popconfirm, and notification remain in the library; Drawer is built on the official Sheet.

The regular head_assets() includes all component styles and the project font. Official and local components share the Ant Design color tokens in the same stylesheet. No wrapper class or extra Cargo feature is needed. Put class="dark" on an ancestor to use dark colors.

The Gallery includes an interactive Topcoat native UI showcase with light and dark themes, sidebar, fields, dialogs, tables, and other controls.

The SearchMultiSelect component has its own Gallery page at http://127.0.0.1:3100/search-multi-select, with searchable options, removable selections, a disabled example, and expandable code.

The official sources are synchronized with Topcoat v0.11.0. The six existing local changes only adjust paragraph margins and transparent button backgrounds. See the upstream license. This project vendors the registry sources directly and does not require Topcoat’s ui Cargo feature.

cargo run -p topcoat-ant-design \
  --bin topcoat-ant-design-gallery \
  --features gallery

Open http://127.0.0.1:3100/ for the English Quick Start page, or http://127.0.0.1:3100/overview for the component overview. Use the 中文 switch for Chinese, or open http://127.0.0.1:3100/?lang=zh directly. HOST and PORT override the listening address. Component pages render interactive previews and examples. Most interactions use browser-side Topcoat signals; Chat also demonstrates validated Gallery-only procedures.

Gallery navigation uses Topcoat 0.11 runtime links. Internal page links navigate without a full document reload and prefetch on hover or focus; normal links still work when JavaScript is unavailable.

Open http://127.0.0.1:3100/chat for the Chat interface preview. /chat/new demonstrates multiple turns, request states, and a validated demo procedure; it does not contact a model.

Open http://127.0.0.1:3100/chat/live in two tabs to see Topcoat server push update the existing Chat components in both. This is a shared Gallery demo room with no model or persistence.

Open /bubble, /message-list, and /sender for individual Chat component examples and expandable source code.

Open http://127.0.0.1:3100/dropdown-menu for the interactive Dropdown Menu example.

§License

The project is MIT licensed. See LICENSE. The Ant Design icon data in icons/ant-design.json retains its MIT notice in LICENSES/ant-design-icons-MIT.txt.

§Additional components in 0.3.1

  • JSONViewer: collapsible JSON trees with node copying.
  • Table column settings: toggle column visibility, keep required columns visible, and restore defaults; the host configures columns hidden by default.

Re-exports§

pub use ui::accordion::*;
pub use ui::alert::*;
pub use ui::alert_dialog::*;
pub use ui::avatar::*;
pub use ui::badge::*;
pub use ui::breadcrumb::*;
pub use ui::button::*;
pub use ui::card::*;
pub use ui::checkbox::*;
pub use ui::dialog::*;
pub use ui::dropdown_menu::*;
pub use ui::field::*;
pub use ui::floating::*;
pub use ui::hover_card::*;
pub use ui::input::*;
pub use ui::kbd::*;
pub use ui::label::*;
pub use ui::navigation_menu::*;
pub use ui::pagination::*;
pub use ui::popover::*;
pub use ui::progress::*;
pub use ui::radio_group::*;
pub use ui::select::*;
pub use ui::separator::*;
pub use ui::sheet::*;
pub use ui::sidebar::*;
pub use ui::skeleton::*;
pub use ui::spinner::*;
pub use ui::switch::*;
pub use ui::table::*;
pub use ui::tabs::*;
pub use ui::textarea::*;
pub use ui::toggle::*;
pub use ui::tooltip::*;

Modules§

icons
Icons
ui
Official Topcoat UI components, vendored from its v0.11.0 registry.

Structs§

CalendarEvent
A date-scoped entry. Multiple entries can be displayed on one date.
ChatMessage
Minimal message contract shared by the Gallery and host integrations.
DateTimeRangeConfig
DrawerConfig
Stable drawer ID, title, and optional close route.
FormFieldConfig
Stable field ID, label, and supporting information.
NativeDialogConfig
Stable dialog ID, title, and optional eyebrow.
SearchOption
A value and label offered by search_multi_select.
TableColumn
Stable identity and initial visibility of a table column.
anchored_menu
Anchored action menu
calendar
Presentational day, week, and month calendar. Use Topcoat signals, links, or procedures in the host for navigation, view switching, and loading entries; no browser script is needed.
chat_actions
Host-owned actions such as copy, retry, and cancel beneath a message.
chat_attachment_tray
Attachments selected for a draft. The host owns upload and removal.
chat_bubble
A message bubble with caller-provided content.
chat_conversation_item
One conversation link. Its active state comes from the current route.
chat_conversation_list
Navigation region for host-provided conversation routes.
chat_file
File metadata shown inside a message or attachment tray.
chat_markdown
Message content renderer for Markdown supplied by a user or model.
chat_message_list
Scrollable conversation region. The caller owns message data and stable IDs.
chat_prompt
One suggestion. The caller supplies the click handler through attrs.
chat_prompts
Suggested starting points for an empty conversation.
chat_sender
Chat input with a browser-owned draft and caller-owned submit behavior.
chat_source
Linked reference with an optional summary and activity label. Non-HTTP destinations are inert.
chat_sources
Expandable list of references used while preparing a response.
chat_think
Expandable reasoning or process details. Only pass content intended for users.
chat_thought_chain
Ordered steps in a user-visible process summary.
chat_thought_step
A single step inside chat_thought_chain.
collapse
Provide a reversible expand-and-collapse transition for content of unknown height.
data_table
Provide a data table with horizontal overflow, density options, and a composable pagination area.
date_time_range_filter
DateTimeRange filter
drawer
Show supplementary details from the right edge without leaving the current list, for example an event or audit record. Drawer composes the official Topcoat sheet and sheet_content primitives.
form_field
FormField
head_assets
Render the shared font and stylesheet assets for UI components.
json_viewer
JSONViewer
native_dialog
Native modal dialog
notification
Show an operation result in the upper-right corner of the viewport. The component enters the browser Top Layer. When a native modal Dialog is open, it temporarily mounts inside that dialog so it remains visible and interactive above the modal.
popconfirm
Show a lightweight confirmation bubble near a trigger button.
search_multi_select
Searchable multi-select backed by a JSON array in selected.
table_column_settings
Table column settings
table_page_size_select
Page-size selector for the pagination area.
table_pagination
Table pagination area. The caller supplies real links or Topcoat buttons as children.
table_toolbar
Table title on the left with host-supplied actions on the right.
tag
Tag for status or categories with caller attributes and text children.

Enums§

CalendarEventKind
A calendar event’s visual meaning. Its title remains visible as text.
CalendarView
The amount of time shown by calendar. Navigation state belongs to the caller.
ChatBubbleRole
Which side of a conversation a message belongs to.
ChatMessageStatus
Rendering state of a Chat message. The host owns transitions between states.
ChatThoughtStatus
Visual state of one process step.
DataTableDensity
Display density of a data table.
NotificationTone
Visual and accessibility tone of a notification.
TagTone
Semantic tag color. The label must also state the status without relying on color.
UiLanguage
Language for labels supplied by a component itself.

Constants§

DEFAULT_FONT
Default UI font; Chinese glyphs fall back to the host system font stack.
STYLESHEET
Component stylesheet built by this crate and bundled by the final application.

Functions§

anchored_menu_trigger_attributes
Connect a trigger to the official Popover positioning and native open/close behavior.
collapse_trigger_attributes
Create the Topcoat reactive attributes required by a Collapse trigger.
native_dialog_close_attributes
Create button attributes that close the specified dialog.
native_dialog_trigger_attributes
Create button attributes that open a native modal dialog.
popconfirm_trigger_attributes
Connect a Popconfirm trigger to its official Popover panel.
render_chat_markdown
Render untrusted chat Markdown with escaped raw HTML and safe link targets.
table_column_attributes
Apply the same attributes to a column’s th, each td, and optional col.
table_default_hidden_columns
Initial value for the host’s Signal<String> containing hidden column keys as JSON.