Skip to content

ProCard 高级卡片 ​

页面级卡片容器,支持标题区、分栏、栅格、折叠、标签页和加载状态。

何时使用 ​

  • 后台页面中组织多个信息区块或统计区域。
  • 需要卡片内分栏、多卡片栅格或卡片标签页时使用;简单容器可用 Card 卡片。
  • 需要指标卡时可配合 StatisticCard 使用。

在线体验 ​

ProCard 高级卡片 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

基本用法 ​

go
import "github.com/tangoui/tango/ui"

func page(c *ui.Context) {
    ui.ProCard(c, "项目概览").SubTitle("本周").Bordered().Body(func() {
        ui.Statistic(c, "完成率", 86, 0).Suffix("%")
    })
}

常见用法 ​

分栏卡片 ​

go
func split(c *ui.Context) {
    ui.ProCard(c, "").Split(ui.SplitVertical).Bordered().Body(func() {
        ui.ProCard(c, "左侧").ColSpan(8).Body(func() { ui.Text(c, "详情") })
        ui.ProCard(c, "右侧").Body(func() { ui.Text(c, "趋势") })
    })
}

栅格与间距 ​

go
func grid(c *ui.Context) {
    ui.ProCard(c, "").Ghost().Gutter(16).Wrap().Body(func() {
        ui.ProCard(c, "A").ColSpan(12).Body(nil)
        ui.ProCard(c, "B").ColSpan(12).Body(nil)
    })
}

折叠和标签页 ​

go
var folded bool
var activeTab = "base"

func interactive(c *ui.Context) {
    ui.ProCard(c, "可折叠").Collapsed(&folded).Body(func() { ui.Text(c, "内容") })
    ui.ProCard(c, "").Tabs(&activeTab, []ui.ProCardTab{
        {Key: "base", Label: "基础", Body: func() { ui.Text(c, "基础信息") }},
        {Key: "log", Label: "日志", Body: func() { ui.Text(c, "日志") }},
    }).Body(nil)
}

主题与样式 ​

ProCard 使用 Pro 卡片令牌控制边框、头部分隔线、间距、悬停和 shadcn 头部样式。默认键为 size、bordered、headerBordered、ghost、hoverable、collapsible、gutter。

注意事项 ​

折叠和标签状态应绑定到页面变量;子 ProCard 的栅格只在父卡片 Body 中直接生效。加载态用于等待数据,不应阻塞整个页面;可折叠头部和标签页支持键盘操作。

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

ProCard 高级卡片

gallery 演示 ProCard 的具名 Render 函数,源码 page_pro2_card.go#L22。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.ProCard ​

go
func ProCard(c *Context, title string) *ProCardW

ProCard starts a ProCard ("" title = no header unless Extra, Tooltip or Collapsible need one); chain options, then call Body.

ConfigProvider.Defaults("ProCard", ...) keys: "size" ("small" | "default" or a ControlSize), "bordered", "headerBordered", "ghost", "hoverable", "collapsible", "boxShadow" (bool), "gutter" (number).

Like Pro Components v3 (variant defaults to "outlined") a card is bordered unless Borderless is set; ghost cards and split children have no border.

返回 *ProCardW,可链式调用的方法见 ProCardW 方法。

ProCardW 方法 ​

ui.ProCardW:ProCardW builds a ProCard.

方法说明签名
ActionsActions adds the bottom action bar (Ant ProCard actions): each fn builds one equal-width slot, separated by dividers (CardAction makes an icon action).Actions(fns ...func()) *ProCardW
BodyBody builds the card with fn as its content.Body(fn func()) *ProCardW
BodyPaddingBodyPadding overrides the body padding.BodyPadding(in geom.Insets) *ProCardW
BorderedBordered draws a border around the card (the default; it overrides a "bordered": false ConfigProvider default).Bordered() *ProCardW
BorderlessBorderless removes the border (Pro v3 variant "borderless").Borderless() *ProCardW
BoxBox returns the card container (valid after Body).Box() *Box
BoxShadowBoxShadow gives the card the tertiary shadow and hides its border (Pro v3 boxShadow).BoxShadow(on bool) *ProCardW
CenteredCentered centres the body content on both axes.Centered() *ProCardW
ClickedClicked reports a click on a hoverable card.Clicked() bool
ColSpanColSpan sizes the card inside a parent ProCard row: span of 24 columns.ColSpan(span int) *ProCardW
ColWidthColWidth gives the card a fixed width inside a parent ProCard row.ColWidth(px float32) *ProCardW
CollapsedCollapsed binds the folded state (implies Collapsible).Collapsed(v *bool) *ProCardW
CollapsibleCollapsible lets a click on the header fold the body.Collapsible() *ProCardW
DefaultCollapsedDefaultCollapsed starts an uncontrolled collapsible card folded.DefaultCollapsed() *ProCardW
DirectionDirection sets how child ProCards are arranged: "row" (default) or "column".Direction(d string) *ProCardW
ExtraExtra builds the actions at the right of the header.Extra(fn func()) *ProCardW
GhostGhost removes the background and the body padding.Ghost() *ProCardW
GutterGutter sets the space between child ProCards.Gutter(px float32) *ProCardW
HeaderBorderedHeaderBordered draws a divider under the header.HeaderBordered() *ProCardW
HoverableHoverable lifts the card with a shadow on hover.Hoverable() *ProCardW
IDID returns the card's widget ID (valid after Body).ID() ID
IsCollapsedIsCollapsed reports whether the body is folded.IsCollapsed() bool
LayoutLayout applies layout options to the card.Layout(o ...layout.Option) *ProCardW
LoadingLoading shows the animated loading placeholder instead of the body.Loading(on bool) *ProCardW
SmallSmall uses the compact paddings.Small() *ProCardW
SplitSplit lays the child ProCards out on one surface separated by dividers (SplitVertical or SplitHorizontal).Split(dir string) *ProCardW
SubTitleSubTitle sets the secondary title shown after the title.SubTitle(s string) *ProCardW
TabChangedTabChanged reports a tab switch this frame.TabChanged() bool
TabExtraTabExtra builds content at the right of the tab bar.TabExtra(fn func()) *ProCardW
TabsTabs turns the card into a tab card bound to active; the active tab's Body is shown as the card body.Tabs(active *string, tabs []ProCardTab) *ProCardW
TabsCardTabsCard uses card-style tabs.TabsCard() *ProCardW
ToggledToggled reports a collapse / expand by the user this frame.Toggled() bool
TooltipTooltip adds a question icon after the title showing tip on hover.Tooltip(tip string) *ProCardW
WrapWrap lets child ProCards wrap onto new lines.Wrap() *ProCardW

相关链接 ​

以 MIT 许可发布