ProCard 高级卡片
页面级卡片容器,支持标题区、分栏、栅格、折叠、标签页和加载状态。
何时使用
- 后台页面中组织多个信息区块或统计区域。
- 需要卡片内分栏、多卡片栅格或卡片标签页时使用;简单容器可用 Card 卡片。
- 需要指标卡时可配合
StatisticCard使用。
在线体验
基本用法
import "github.com/tangoui/tango/ui"
func page(c *ui.Context) {
ui.ProCard(c, "项目概览").SubTitle("本周").Bordered().Body(func() {
ui.Statistic(c, "完成率", 86, 0).Suffix("%")
})
}常见用法
分栏卡片
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, "趋势") })
})
}栅格与间距
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)
})
}折叠和标签页
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 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.ProCard
func ProCard(c *Context, title string) *ProCardWProCard 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.
| 方法 | 说明 | 签名 |
|---|---|---|
Actions | Actions 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 |
Body | Body builds the card with fn as its content. | Body(fn func()) *ProCardW |
BodyPadding | BodyPadding overrides the body padding. | BodyPadding(in geom.Insets) *ProCardW |
Bordered | Bordered draws a border around the card (the default; it overrides a "bordered": false ConfigProvider default). | Bordered() *ProCardW |
Borderless | Borderless removes the border (Pro v3 variant "borderless"). | Borderless() *ProCardW |
Box | Box returns the card container (valid after Body). | Box() *Box |
BoxShadow | BoxShadow gives the card the tertiary shadow and hides its border (Pro v3 boxShadow). | BoxShadow(on bool) *ProCardW |
Centered | Centered centres the body content on both axes. | Centered() *ProCardW |
Clicked | Clicked reports a click on a hoverable card. | Clicked() bool |
ColSpan | ColSpan sizes the card inside a parent ProCard row: span of 24 columns. | ColSpan(span int) *ProCardW |
ColWidth | ColWidth gives the card a fixed width inside a parent ProCard row. | ColWidth(px float32) *ProCardW |
Collapsed | Collapsed binds the folded state (implies Collapsible). | Collapsed(v *bool) *ProCardW |
Collapsible | Collapsible lets a click on the header fold the body. | Collapsible() *ProCardW |
DefaultCollapsed | DefaultCollapsed starts an uncontrolled collapsible card folded. | DefaultCollapsed() *ProCardW |
Direction | Direction sets how child ProCards are arranged: "row" (default) or "column". | Direction(d string) *ProCardW |
Extra | Extra builds the actions at the right of the header. | Extra(fn func()) *ProCardW |
Ghost | Ghost removes the background and the body padding. | Ghost() *ProCardW |
Gutter | Gutter sets the space between child ProCards. | Gutter(px float32) *ProCardW |
HeaderBordered | HeaderBordered draws a divider under the header. | HeaderBordered() *ProCardW |
Hoverable | Hoverable lifts the card with a shadow on hover. | Hoverable() *ProCardW |
ID | ID returns the card's widget ID (valid after Body). | ID() ID |
IsCollapsed | IsCollapsed reports whether the body is folded. | IsCollapsed() bool |
Layout | Layout applies layout options to the card. | Layout(o ...layout.Option) *ProCardW |
Loading | Loading shows the animated loading placeholder instead of the body. | Loading(on bool) *ProCardW |
Small | Small uses the compact paddings. | Small() *ProCardW |
Split | Split lays the child ProCards out on one surface separated by dividers (SplitVertical or SplitHorizontal). | Split(dir string) *ProCardW |
SubTitle | SubTitle sets the secondary title shown after the title. | SubTitle(s string) *ProCardW |
TabChanged | TabChanged reports a tab switch this frame. | TabChanged() bool |
TabExtra | TabExtra builds content at the right of the tab bar. | TabExtra(fn func()) *ProCardW |
Tabs | Tabs 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 |
TabsCard | TabsCard uses card-style tabs. | TabsCard() *ProCardW |
Toggled | Toggled reports a collapse / expand by the user this frame. | Toggled() bool |
Tooltip | Tooltip adds a question icon after the title showing tip on hover. | Tooltip(tip string) *ProCardW |
Wrap | Wrap lets child ProCards wrap onto new lines. | Wrap() *ProCardW |