carousel

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 3 Imported by: 0

README ¶

Release Software License

A carousel component for bubbletea applications.

carousel gif

Check the example.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type KeyMap ¶

type KeyMap struct {
	SelectLeft  key.Binding
	SelectRight key.Binding
}

KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which is used to render the menu.

func DefaultKeyMap ¶

func DefaultKeyMap() KeyMap

DefaultKeyMap returns a default set of keybindings.

type Model ¶

type Model struct {
	KeyMap KeyMap
	// contains filtered or unexported fields
}

Model defines a state for the carousel widget.

func New ¶

func New(opts ...Option) Model

New creates a new model for the carousel widget.

func (*Model) Blur ¶

func (m *Model) Blur()

Blur blurs the carousel, preventing selection or movement.

func (Model) Cursor ¶

func (m Model) Cursor() int

Cursor returns the index of the selected row.

func (*Model) Focus ¶

func (m *Model) Focus()

Focus focuses the carousel, allowing the user to move around the items and interact.

func (Model) Focused ¶

func (m Model) Focused() bool

Focused returns the focus state of the carousel.

func (Model) Height ¶

func (m Model) Height() int

Height returns the height of the carousel.

func (Model) Items ¶

func (m Model) Items() []string

Items returns the current items.

func (*Model) MoveLeft ¶

func (m *Model) MoveLeft()

MoveLeft moves the selection left by one item.. It can not go before the first item.

func (*Model) MoveRight ¶

func (m *Model) MoveRight()

MoveDown moves the selection right by one item. It can not go after the last row.

func (Model) SelectedItem ¶

func (m Model) SelectedItem() string

SelectedItem returns the selected item. You can cast it to your own implementation.

func (*Model) SetCursor ¶

func (m *Model) SetCursor(n int)

SetCursor sets the cursor position in the carousel.

func (*Model) SetHeight ¶

func (m *Model) SetHeight(h int)

SetHeight sets the height of the carousel.

func (*Model) SetItems ¶

func (m *Model) SetItems(items []string)

SetItems sets a new items state.

func (*Model) SetStyles ¶

func (m *Model) SetStyles(s Styles)

SetStyles sets the table styles.

func (*Model) SetWidth ¶

func (m *Model) SetWidth(w int)

SetWidth sets the width of the carousel.

func (Model) Update ¶

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update is the Bubble Tea update loop.

func (*Model) UpdateSize ¶

func (m *Model) UpdateSize()

UpdateSize updates the carousel size based on the previously defined items and width.

func (Model) View ¶

func (m Model) View() string

View renders the component.

func (Model) Width ¶

func (m Model) Width() int

Width returns the width of the carousel.

type Option ¶

type Option func(*Model)

Option is used to set options in New. For example:

carousel := New(WithItems([]string{"Item 1", "Item 2", "Item 3"}))

func WithEvenlySpacedItems ¶

func WithEvenlySpacedItems() Option

WithEvenlySpacedItems sets all items with the same width.

func WithFocused ¶

func WithFocused(f bool) Option

WithFocused sets the focus state of the carousel.

func WithHeight ¶

func WithHeight(h int) Option

WithHeight sets the height of the carousel.

func WithItems ¶

func WithItems(items []string) Option

WithItems sets the carousel items (data).

func WithKeyMap ¶

func WithKeyMap(km KeyMap) Option

WithKeyMap sets the key map.

func WithStyles ¶

func WithStyles(s Styles) Option

WithStyles sets the carousel styles.

func WithWidth ¶

func WithWidth(w int) Option

WithWidth sets the width of the carousel.

type Styles ¶

type Styles struct {
	Item     lipgloss.Style
	Selected lipgloss.Style
}

Styles contains style definitions for this carousel component. By default, vthese alues are generated by DefaultStyles.

func DefaultStyles ¶

func DefaultStyles() Styles

DefaultStyles returns a set of default style definitions for this carousel.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL