Scoop API

scoop:scoop.ui.component:0.1.0

src/sidebar/builder.scoop

Selected production source · src/sidebar/builder.scoop

1package scoop.ui.component
3import scoop.graphics.text.FontCollection
4import scoop.surface.AnimationSpec
5import scoop.ui.*
6import scoop.ui.style.*
7import scoop.window.ShortcutChord
9public class SidebarBuilder internal constructor() {
10 public var header: SidebarContent? = None
11 public var footer: SidebarContent? = None
12 public var inset: View? = None
13 public var variant: SidebarVariant = SidebarVariant.Sidebar
14 public var collapsible: SidebarCollapse = SidebarCollapse.Offcanvas
15 public var side: SidebarSide = SidebarSide.Start
16 public var layout: SidebarLayout = SidebarLayout.Auto
17 public var width: Double = 256.0
18 public var iconWidth: Double = 48.0
19 public var mobileWidth: Double = 288.0
20 public var breakpoint: Double = 768.0
21 public var rail: Boolean = false
22 public var railSemantics: ComponentSemantics = ComponentSemantics(name = Some("Toggle sidebar"))
23 public var enabled: Boolean = true
24 public var scrollState: ScrollState? = None
25 public var focus: OverlayFocusOptions = OverlayFocusOptions()
26 public var shortcut: ShortcutChord? = Some(sidebarShortcut())
27 public var transition: StyleValue<AnimationSpec?> = StyleValue.Inherit
28 public var onOpenChange: (Boolean) -> Unit = {}
29 public var onCloseRequest: (OverlayCloseReason) -> Boolean = { _ -> true }
30 public var onClosed: (OverlayCloseReason) -> Unit = {}
31 public var fonts: FontCollection? = None
32 public var theme: ThemeSource? = None
33 public var style: StyleOverride = styleOverride()
34 public var insetStyle: StyleOverride = styleOverride()
35 public var key: ViewKey = ViewKey.Position
36 public fun header(content: View) {
37 header = Some(SidebarContent.Custom(content))
38 }
39 public fun header(content: (SidebarPresentation) -> View) {
40 header = Some(SidebarContent.Resolved(content))
41 }
42 public fun footer(content: View) {
43 footer = Some(SidebarContent.Custom(content))
44 }
45 public fun footer(content: (SidebarPresentation) -> View) {
46 footer = Some(SidebarContent.Resolved(content))
47 }
48 public fun inset(content: View) {
49 inset = Some(content)
50 }
51 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
52 style = style.copy(configure)
53 }
54 public fun transition(value: AnimationSpec?) {
55 transition = StyleValue.Set(value)
56 }
57 internal fun snapshot(open: Binding<Boolean>, content: SidebarContent): SidebarProps =
58 SidebarProps(
59 open,
60 content,
61 header,
62 footer,
63 inset,
64 variant,
65 collapsible,
66 side,
67 layout,
68 width,
69 iconWidth,
70 mobileWidth,
71 breakpoint,
72 rail,
73 enabled,
74 scrollState,
75 focus,
76 shortcut,
77 transition,
78 onOpenChange,
79 onCloseRequest,
80 onClosed,
81 fonts,
82 theme,
83 style,
84 insetStyle,
85 railSemantics
86 )
89public fun sidebar(
90 open: Binding<Boolean>,
91 content: View,
92 configure: SidebarBuilder.() -> Unit = {}
93): View = makeSidebar(open, SidebarContent.Custom(content), configure)
95public fun sidebar(
96 open: Binding<Boolean>,
97 content: (SidebarPresentation) -> View,
98 configure: SidebarBuilder.() -> Unit = {}
99): View = makeSidebar(open, SidebarContent.Resolved(content), configure)
101private fun makeSidebar(
102 open: Binding<Boolean>,
103 content: SidebarContent,
104 configure: SidebarBuilder.() -> Unit
105): View {
106 val builder = SidebarBuilder();
107 builder.configure()
108 return component(
109 builder.snapshot(open, content),
110 { current, mount -> Sidebar(current, scope = mount) },
111 builder.key
112 )