Scoop API

scoop:scoop.ui.component:0.1.0

src/toast/builder.scoop

Selected production source · src/toast/builder.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.surface.AnimationSpec
5import scoop.time.Duration
6import scoop.ui.*
7import scoop.ui.style.*
8import scoop.window.accessibility.SemanticLive
10public class ToastActionBuilder internal constructor() {
11 public var dismiss: Boolean = true
12 public var enabled: Boolean = true
13 public var focus: FocusOptions = FocusOptions()
14 public var style: ButtonStyle = buttonStyle()
15 public var variant: ButtonVariant = ButtonVariant.Outline
16 public var size: ButtonSize = ButtonSize.Sm
17 public var semantics: ComponentSemantics = ComponentSemantics()
18 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
19 focus = focus.copy(configure)
20 }
21 public fun style(configure: ButtonStyleBuilder.() -> Unit) {
22 style = style.copy(configure)
23 }
24 internal fun snapshot(content: ButtonContent, onClick: () -> Unit): ToastAction =
25 ToastAction(content, onClick, dismiss, enabled, focus, style, variant, size, semantics)
28public class ToastBuilder internal constructor(private val title: PanelContent) {
29 public var description: PanelContent? = None
30 public var kind: ToastKind = ToastKind.Default
31 public var position: ToastPosition? = None
32 public var duration: Duration? = Some(Duration.seconds(5L))
33 public var dismiss: ToastDismiss = ToastDismiss()
34 public var icon: View? = None
35 public var action: ToastAction? = None
36 public var closeFocus: FocusOptions = FocusOptions()
37 public var style: StyleOverride = styleOverride()
38 public var onClosed: (ToastId, ToastCloseReason) -> Unit = { _, _ -> Unit }
39 public var semantics: ComponentSemantics = ComponentSemantics(live = SemanticLive.Polite)
40 public var closeSemantics: ComponentSemantics =
41 ComponentSemantics(name = Some("Dismiss notification"))
42 public fun description(text: String) {
43 description = Some(PanelContent.Label(LabelProps(LabelText.Plain(text, None))))
44 }
45 public fun description(text: StyledText) {
46 description = Some(PanelContent.Label(LabelProps(LabelText.Styled(text))))
47 }
48 public fun description(content: View) {
49 description = Some(PanelContent.Custom(content))
50 }
51 public fun action(
52 text: String,
53 onClick: () -> Unit,
54 configure: ToastActionBuilder.() -> Unit = {}
55 ) {
56 val b = ToastActionBuilder();
57 b.configure()
58 action =
59 Some(b.snapshot(ButtonContent.Label(LabelProps(LabelText.Plain(text, None))), onClick))
60 }
61 public fun action(
62 content: View,
63 onClick: () -> Unit,
64 configure: ToastActionBuilder.() -> Unit = {}
65 ) {
66 val b = ToastActionBuilder();
67 b.configure()
68 action = Some(b.snapshot(ButtonContent.Custom(content), onClick))
69 }
70 public fun action(
71 content: (ActionContentStyle) -> View,
72 onClick: () -> Unit,
73 configure: ToastActionBuilder.() -> Unit = {}
74 ) {
75 val b = ToastActionBuilder();
76 b.configure()
77 action = Some(b.snapshot(ButtonContent.Resolved(content), onClick))
78 }
79 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
80 style = style.copy(configure)
81 }
82 internal fun snapshot(): ToastProps =
83 ToastProps(
84 title,
85 description,
86 kind,
87 position,
88 duration,
89 dismiss,
90 icon,
91 action,
92 closeFocus,
93 style,
94 onClosed,
95 semantics,
96 closeSemantics
97 )
100public fun toastProps(title: String, configure: ToastBuilder.() -> Unit = {}): ToastProps =
101 makeToastProps(PanelContent.Label(LabelProps(LabelText.Plain(title, None))), configure)
103public fun toastProps(title: StyledText, configure: ToastBuilder.() -> Unit = {}): ToastProps =
104 makeToastProps(PanelContent.Label(LabelProps(LabelText.Styled(title))), configure)
106public fun toastProps(title: View, configure: ToastBuilder.() -> Unit = {}): ToastProps =
107 makeToastProps(PanelContent.Custom(title), configure)
109private fun makeToastProps(title: PanelContent, configure: ToastBuilder.() -> Unit): ToastProps {
110 val b = ToastBuilder(title);
111 b.configure();
112 return b.snapshot()
115public class ToasterBuilder internal constructor() {
116 public var position: ToastPosition = ToastPosition.BottomEnd
117 public var visibleCount: Long = 3L
118 public var order: ToastOrder = ToastOrder.OldestFirst
119 public var expanded: Boolean = false
120 public var width: Double = 384.0
121 public var offset: Double = 16.0
122 public var gap: Double = 12.0
123 public var enabled: Boolean = true
124 public var transition: StyleValue<AnimationSpec?> = StyleValue.Inherit
125 public var fonts: FontCollection? = None
126 public var theme: ThemeSource? = None
127 public var style: StyleOverride = styleOverride()
128 public var key: ViewKey = ViewKey.Position
129 public fun transition(value: AnimationSpec?) {
130 transition = StyleValue.Set(value)
131 }
132 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
133 style = style.copy(configure)
134 }
135 internal fun snapshot(state: ToastState): ToasterProps =
136 ToasterProps(
137 state,
138 position,
139 visibleCount,
140 order,
141 expanded,
142 width,
143 offset,
144 gap,
145 enabled,
146 transition,
147 fonts,
148 theme,
149 style
150 )
153public fun toaster(state: ToastState, configure: ToasterBuilder.() -> Unit = {}): View {
154 val b = ToasterBuilder();
155 b.configure()
156 return component(b.snapshot(state), { value, mount -> Toaster(value, mount) }, b.key)