Documentation
¶
Index ¶
- type Advance
- type Anchor
- type Entry
- type Manager
- func (m *Manager[K, V]) Advance(now time.Time, paused bool) Advance[K, V]
- func (m *Manager[K, V]) Dismiss(id K, now time.Time) bool
- func (m *Manager[K, V]) DismissAll(now time.Time) []K
- func (m *Manager[K, V]) Entries() []Entry[K, V]
- func (m *Manager[K, V]) Get(id K) (v V, ok bool)
- func (m *Manager[K, V]) Len() int
- func (m *Manager[K, V]) Push(id K, value V, timeout time.Duration, now time.Time) (replaced V, ok bool)
- func (m *Manager[K, V]) Visible(limit int) []Entry[K, V]
- type Motion
- type Stack
- type Status
- type SwipeDirection
- type Toast
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advance ¶
type Advance[K comparable, V any] struct { Changed bool Presented []K Ending []K Removed []Entry[K, V] }
Advance is what an Advance changed: the toasts it presented, the ones whose timeout ran out, and the ones it removed.
type Anchor ¶
type Anchor uint8
Anchor is the edge of the viewport a Stack lays out from: the newest toast is nearest it.
type Entry ¶
type Entry[K comparable, V any] struct { ID K Value V Status Status }
Entry is a toast a Manager keeps.
type Manager ¶
type Manager[K comparable, V any] struct { Motion Motion // contains filtered or unexported fields }
Manager keeps toasts in order with their lifecycle, as gpui-base's: each one starts, is present once the motion's Duration has passed, counts its timeout down while present and not paused, and stays ending for the ExitDuration before it is removed. It renders nothing and runs no timer: the app pushes toasts, renders Visible with a Stack and calls Advance on a timer while any is shown, passing whether the stack is expanded. Times are the app's clock's, Scope.Now, so a test's manual clock moves them. The zero value has no toasts and Sonner's motion.
func (*Manager[K, V]) Advance ¶
Advance moves the lifecycle on to now; paused holds present toasts' timeouts, as while the stack is expanded.
func (*Manager[K, V]) Dismiss ¶
Dismiss begins a toast's exit and reports whether it was not leaving already.
func (*Manager[K, V]) DismissAll ¶
DismissAll begins every toast's exit and returns the ids of those that were not leaving already.
type Motion ¶
type Motion struct {
// Duration is how long a toast enters, and the stack's springs'
// response.
Duration time.Duration
// ExitDuration is how long a toast leaves.
ExitDuration time.Duration
// CollapsedPeek is how far apart collapsed toasts overlap, and
// ExpandedGap the space between expanded ones.
CollapsedPeek, ExpandedGap core.Points
// CollapsedScaleStep is how much narrower each collapsed toast behind
// the newest is, as a fraction of its width.
CollapsedScaleStep float32
// CollapsedVisible is how many collapsed toasts show.
CollapsedVisible int
}
Motion are the tokens of a Manager and a Stack; a zero field keeps Sonner's, which SonnerMotion returns.
type Stack ¶
type Stack[T any, K comparable] struct { Toasts func() []T Key func(T) K Toast func(cx *core.Scope, item func() T) core.Node Motion Motion Placement Anchor Reverse bool NoCloseOnEscape bool OnExpandedChange func(expanded bool) OnCancel func() Class string Style core.Style StyleFunc func() core.Style TestID string }
Stack lays toasts out, as gpui-base's: Toasts are its items, oldest first, each rendered by Toast and matched by Key as core.Each matches rows. From Placement's edge, collapsed toasts overlap CollapsedPeek apart, each further one narrower by CollapsedScaleStep, and only CollapsedVisible show; expanded, while the pointer or a finger is on it, they are a list ExpandedGap apart, so the app pauses its manager (OnExpandedChange). Reverse turns the stack around: the newest toast is the farthest from the edge and the oldest the nearest, as a list growing away from it. Arrivals, departures and expansion move them with critically damped springs of the motion's Duration; a Toast that is ending stays where it shows and takes no room, so the others close up as it leaves. While it holds toasts it hears Escape and back (OnCancel: dismiss the newest), unless NoCloseOnEscape. It has no look: its style gives its width, and the app places it, in an Overlay at that edge inside the safe area, centered at a center anchor.
type SwipeDirection ¶
type SwipeDirection uint8
SwipeDirection is the direction a toast is swiped away in.
const ( SwipeRight SwipeDirection = iota SwipeLeft SwipeUp SwipeDown // SwipeOff keeps the toast from being swiped. SwipeOff )
type Toast ¶
type Toast struct {
// Status is its phase, Starting when nil.
Status func() Status
SwipeDirection SwipeDirection
SwipeThreshold core.Points
StartingClass string
StartingStyle core.Style
EndingClass string
EndingStyle core.Style
SwipingClass string
SwipingStyle core.Style
Label string
// LabelFunc is a label that changes while the toast shows, as when a toast replaces it; it wins over Label, and the screen reader reads each new one.
LabelFunc func() string
// OnPress makes the toast itself a button. Child controls such as action buttons keep their own presses.
OnPress func()
// OnDismissRequest: the user swiped it away; dismiss it. It stays
// where the swipe took it.
OnDismissRequest func()
Class string
Style core.Style
StyleFunc func() core.Style
Children []core.Node
TestID string
// OnLayout and Tooltip are its view's, as a core.View's.
OnLayout func(core.Bounds)
Tooltip core.Node
}
Toast is an unstyled toast's root, as gpui-base's: the alert role around the app's content. Its look follows Status, a Manager's, through StartingStyle in its first frame while starting (so a Transition in its style animates its entry from it), EndingStyle while ending, and SwipingStyle while a pointer swipes it; they merge over Style and StyleFunc, and their classes are important, over both. A finger or the mouse dragged toward SwipeDirection moves it once it moved 10 points, so its buttons stay buttons; let go past SwipeThreshold (50 when 0) or flicked, it moves on out and asks to be dismissed with OnDismissRequest, and short of it goes back. While ending it takes no presses. The screen reader reads Label as it shows. A Stack lays toasts out.
The swipe moves a view around the root so its animated translation composes with StartingStyle, EndingStyle and the app's own Transform.