scoop:scoop.ui.component:0.1.0
src/toast/builder.scoop
Selected production source · src/toast/builder.scoop
1
package scoop.ui.component3
import scoop.graphics.text.*4
import scoop.surface.AnimationSpec5
import scoop.time.Duration6
import scoop.ui.*7
import scoop.ui.style.*8
import scoop.window.accessibility.SemanticLive10
public class ToastActionBuilder internal constructor() {11
public var dismiss: Boolean = true12
public var enabled: Boolean = true13
public var focus: FocusOptions = FocusOptions()14
public var style: ButtonStyle = buttonStyle()15
public var variant: ButtonVariant = ButtonVariant.Outline16
public var size: ButtonSize = ButtonSize.Sm17
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)26
}28
public class ToastBuilder internal constructor(private val title: PanelContent) {29
public var description: PanelContent? = None30
public var kind: ToastKind = ToastKind.Default31
public var position: ToastPosition? = None32
public var duration: Duration? = Some(Duration.seconds(5L))33
public var dismiss: ToastDismiss = ToastDismiss()34
public var icon: View? = None35
public var action: ToastAction? = None36
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
closeSemantics97
)98
}100
public fun toastProps(title: String, configure: ToastBuilder.() -> Unit = {}): ToastProps =101
makeToastProps(PanelContent.Label(LabelProps(LabelText.Plain(title, None))), configure)103
public fun toastProps(title: StyledText, configure: ToastBuilder.() -> Unit = {}): ToastProps =104
makeToastProps(PanelContent.Label(LabelProps(LabelText.Styled(title))), configure)106
public fun toastProps(title: View, configure: ToastBuilder.() -> Unit = {}): ToastProps =107
makeToastProps(PanelContent.Custom(title), configure)109
private fun makeToastProps(title: PanelContent, configure: ToastBuilder.() -> Unit): ToastProps {110
val b = ToastBuilder(title);111
b.configure();112
return b.snapshot()113
}115
public class ToasterBuilder internal constructor() {116
public var position: ToastPosition = ToastPosition.BottomEnd117
public var visibleCount: Long = 3L118
public var order: ToastOrder = ToastOrder.OldestFirst119
public var expanded: Boolean = false120
public var width: Double = 384.0121
public var offset: Double = 16.0122
public var gap: Double = 12.0123
public var enabled: Boolean = true124
public var transition: StyleValue<AnimationSpec?> = StyleValue.Inherit125
public var fonts: FontCollection? = None126
public var theme: ThemeSource? = None127
public var style: StyleOverride = styleOverride()128
public var key: ViewKey = ViewKey.Position129
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
style150
)151
}153
public 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)157
}