Sheet
Example sourceGo · Copyable
This is the complete source for the gallery example above.examples/components/sheet.go
Reuse the component construction and Render methods in a scaffolded project. The example’s registerSection and shared helpers are provided by the component gallery.
package main
import (
"github.com/dyike/keel/ui/core"
"github.com/dyike/keel/ui/el"
"github.com/dyike/keel/ui/kit"
"github.com/dyike/keel/ui/theme"
)
func init() {
registerSection("sheet", "overlays", func() core.Widget { return el.Root(newSheetGallery()) })
}
type sheetGallery struct{ right, bottom *kit.SheetView }
func newSheetGallery() *sheetGallery {
body := func() el.View {
menu := kit.Menu().Item(demoText("Copy order number", "复制订单号"), "", nil).Item(demoText("View action log", "查看操作记录"), "", nil)
menu.Trigger(kit.Button(demoText("Order actions", "订单操作"), menu.Toggle))
return el.ViewFunc(func(cx *el.Context) el.Element {
return el.Div().Gap(8).Child(el.Text(demoText("Order SO-1001", "订单 SO-1001")).Bold(), el.Text(demoText("East China Logistics · Awaiting payment · ¥300.00", "华东物流 · 待付款 · ¥300.00")).TextColor(theme.Muted),
kit.DescriptionList().Item(demoText("Owner", "负责人"), demoText("Alex Chen", "张三")).Item(demoText("Created at", "创建时间"), "2026-10-01 09:30").Render(cx), menu.Render(cx))
})
}
g := &sheetGallery{right: kit.Sheet(el.Right, demoText("Order details", "订单详情")).MarginTop(32).Body(body()), bottom: kit.Sheet(el.Bottom, demoText("Bulk actions", "批量操作")).Size(220).Body(body())}
g.right.PanelStyle(func(e *el.DivEl) { e.P(24).Gap(theme.SpaceLg).Border(1, theme.Border) })
g.right.Footer(kit.Button(demoText("Done", "完成"), func() { g.right.SetValue(false) }))
g.bottom.Footer(kit.Button(demoText("Close panel", "关闭面板"), func() { g.bottom.SetValue(false) }))
return g
}
func (g *sheetGallery) Render(cx *el.Context) el.Element {
return el.Div().P(24).Gap(12).Items(el.Start).Child(
el.Text(demoText("Sheet: drag the inner edge to resize. Esc or clicking the backdrop closes it.", "Sheet:拖动内侧边缘调整尺寸,Esc 或点遮罩关闭")).Bold(),
el.Div().Row().Wrap().Gap(8).Child(
kit.Button(demoText("Details on the right", "右侧详情"), func() { g.right.SetValue(true) }).Size(galleryTouchSize(cx)).Render(cx),
kit.Button(demoText("Bottom panel", "底部面板"), func() { g.bottom.SetValue(true) }).Size(galleryTouchSize(cx)).Variant(kit.ButtonSecondary).Render(cx),
),
g.right.Render(cx), g.bottom.Render(cx),
)
}
A modal panel attached to one side of the window, used for details, settings, and long forms.
details := kit.Sheet(el.Right, "Order details").Body(view).Size(400)
details.SetValue(true)
- Directions:
el.Right,el.Left,el.Top,el.Bottom. - Size:
Size(dp)is the width in the left and right directions and the height in the up and down directions. The default is 360; it will not exceed the window. - Open by sliding in from the edge with
kit.SheetSlide(200ms). Appears directly at the final position when reduced motion is turned on, which is the default in automation mode. - The closing method is the same as Dialog: Esc, click on the mask, close button on the title bar, and call
OnClose(fn)when closing. - The content area can be scrolled. The focus is limited to the panel and returns to its original position after closing.
Value()/SetValue(bool)reads or sets whether to open,SetTitlemodifies the title. You can also callsheet.Show(cx)in the callback. The drawer is hung directly to the root of the window without being placed in the view tree. It will be automatically removed after closing; the same instance should not be rendered at the same time.el.RootREQUIRED.
Agent: The role is dialog, the name is the title; the name of the close button is "Close".
Verification: go run ./examples/components -section sheet.
The body of Sheet can contain overlays such as Menu and Popover; the parent layer is registered first, Esc closes from the innermost layer, and finally the Sheet is closed. SetDisabled(true) closes and prevents reopening. Disabling or hiding ancestors will also close the modal layer. Restoring enablement will not automatically reopen. The user close callback is executed at most once.
The sliding distance uses the actual width and height constrained by the window. Ignored when the size is NaN or infinite; reopening immediately after closing will restart the animation, and does not require the closed state to be rendered once in the middle. The example "Order Action" validates the nested menu.
Footer(views...) sets an independent footer, copies incoming slices, supports multiple operation buttons and line breaks; the text continues to scroll independently, and the footer does not scroll with the text. When there is no text, the footer will be at the bottom of the panel, empty parameters will clear the footer, and nil sub-items will be ignored. The footer is suitable for small operations and requires sufficient panel height for the title and footer.
Keyboard(bool), Overlay(bool), OverlayClosable(bool), and CloseButton(bool) respectively control the Esc, mask color, external click close and title close buttons. They are all turned on by default. Hidden masks still maintain modal blocking and focus constraints; close buttons are not subject to Keyboard/OverlayClosable constraints. The configuration can be updated during opening, the procedure SetValue(false) is always available.
MarginTop(dp) reserves space at the top of the panel, e.g. MarginTop(32) avoids the title bar. All four directions are laid out within the remaining window area; the top panel slides in from the lower edge of the reserved area, the bottom panel remains attached to the bottom, and the left and right panels shorten their height. The drawing and clicking areas are cropped simultaneously, and the animation will not cover the reserved area. Default is 0, negative numbers and non-finite values are ignored; when the window height is exceeded, the panel is completely cropped and can still be closed by pressing Esc. Masks and modal blocking continue to cover the entire window, and click on the top reserved area to handle it as OverlayClosable.
PanelStyle(func(*el.DivEl)) Configure panel color, text color, border, rounded corners, shadow, padding and content spacing after default appearance; PanelStyle(nil) restore default. The callback receives new elements every frame and should not save references. The panel identity and Size/window constraints are set after the callback, and the body and actions continue to be provided through the Body/Footer. Subcomponents with explicitly set colors retain their own colors, and unset text inherits the panel color.
details.PanelStyle(func(panel *el.DivEl) {
panel.Bg(theme.Surface).Border(1, theme.Border).P(24).Gap(theme.SpaceLg)
})
Resizable(bool) Controls the 6dp adjustment knob on the inside edge, on by default. Drag the width of the left and right panels, drag the height of the upper and lower panels; the handle supports Tab focus, the arrow keys move 16dp along the corresponding axis, and Home/End is adjusted to the minimum/maximum size. The user adjustment range is from 80dp to the available window size; when the window is less than 80dp, it is limited to the actual space, and MarginTop is deducted vertically.
PanelSize() returns the requested size; OnResize(func(float32)) notifies the user of the adjustment result, and the program call Size is not triggered. Adjustments start from the actual size on the screen; canceling pointer dragging returns to the starting size (still constrained by the current window). Turning off, disabling resizing, or resizing the program ends the current drag. Apps can save dimensions in callbacks; dimensions are retained when reopened. By default, adding a new handle will add a keyboard dock. Resizable(false) can be used to restore the fixed size behavior.
Entry and exit share the root-owned presence lifecycle. Logical closing immediately disables the departing content and releases modality/focus; its visual exit continues briefly. Reopening in flight reverses from the current pose. Reduced motion skips transitions. Show mounts remain until exit completes. Removing the component cancels its lifecycle. This behavior is in the working branch, not v0.4.2.