From 9489b3361383a46579bd8c276791bf19487598d3 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Thu, 3 Apr 2025 22:15:35 -0700 Subject: [PATCH] docs(table): more godoc updates --- table/table.go | 54 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/table/table.go b/table/table.go index 3f84d46..cd643ab 100644 --- a/table/table.go +++ b/table/table.go @@ -1,4 +1,4 @@ -// Package table provides a simple table component for Bubble Tea applications. +// Package table provides a table component for Bubble Tea applications. package table import ( @@ -92,8 +92,8 @@ func DefaultKeyMap() KeyMap { } } -// Styles contains style definitions for this table component. By default, these -// values are generated by DefaultStyles. +// Styles contains style definitions for this table component. Load default +// styles to your table with [DefaultStyles]. type Styles struct { border lipgloss.Border borderStyle lipgloss.Style @@ -119,7 +119,8 @@ func DefaultStyles() Styles { } } -// NewFromTemplate lets you create a table [Model] from Lip Gloss' [table.Table]. +// NewFromTemplate lets you create a table [Model] from Lip Gloss' +// [table.Table]. func NewFromTemplate(t *table.Table, headers []string, rows [][]string) *Model { m := &Model{ cursor: 0, @@ -158,7 +159,7 @@ func NewFromTemplate(t *table.Table, headers []string, rows [][]string) *Model { // top side, followed by the right side, then the bottom, and finally the left. // The final two values will set the row and column separators in that order. // -// With more than four arguments nothing will be set. +// With more than six arguments nothing will be set. func (m *Model) SetBorder(s ...bool) *Model { m.table.Border(m.styles.border) top, right, bottom, left, rowSeparator, columnSeparator := m.whichSides(s...) @@ -172,13 +173,20 @@ func (m *Model) SetBorder(s ...bool) *Model { return m } -// Border sets the top border. +// Border sets the kind of border to use for the table. See [lipgloss.Border]. func (m *Model) Border(border lipgloss.Border) *Model { m.styles.border = border m.table.Border(border) return m } +// BorderStyle sets the style for the table border. +func (m *Model) BorderStyle(style lipgloss.Style) *Model { + m.styles.borderStyle = style + m.table.BorderStyle(style) + return m +} + // BorderBottom sets the bottom border. func (m *Model) BorderBottom(v bool) *Model { m.styles.borderBottom = v @@ -214,7 +222,7 @@ func (m *Model) BorderColumn(v bool) *Model { return m } -// BorderHeader sets the header's border. +// BorderHeader sets the header border. func (m *Model) BorderHeader(v bool) *Model { m.styles.borderHeader = v m.table.BorderHeader(v) @@ -228,13 +236,6 @@ func (m *Model) BorderRow(v bool) *Model { return m } -// BorderStyle sets the style for the table border. -func (m *Model) BorderStyle(style lipgloss.Style) *Model { - m.styles.borderStyle = style - m.table.BorderStyle(style) - return m -} - // Options // Option is used to set options in [New]. For example: @@ -242,7 +243,8 @@ func (m *Model) BorderStyle(style lipgloss.Style) *Model { // table := New(WithHeaders([]string{"Rank", "City", "Country", "Population"})) type Option func(*Model) -// WithHeaders sets the table headers. +// WithHeaders sets the table headers. This function is used as an [Option] in +// when creating a table with [New]. func WithHeaders(headers ...string) Option { return func(m *Model) { m.SetHeaders(headers...) @@ -252,7 +254,8 @@ func WithHeaders(headers ...string) Option { // TODO andrey confirm this... I'm pretty sure that's how it's working now // // WithHeight sets the height of the table. The given height will be the total -// table height including borders, margins, and padding. +// table height including borders, margins, and padding. This function is used +// as an [Option] in when creating a table with [New]. func WithHeight(h int) Option { return func(m *Model) { m.table.Height(h) @@ -260,14 +263,16 @@ func WithHeight(h int) Option { } // WithWidth sets the width of the table. The given width will be the total -// table width including borders, margins, and padding. +// table width including borders, margins, and padding. This function is used as +// an [Option] in when creating a table with [New]. func WithWidth(w int) Option { return func(m *Model) { m.table.Width(w) } } -// WithRows sets the table rows. +// WithRows sets the table rows. This function is used as an [Option] in when +// creating a table with [New]. func WithRows(rows ...[]string) Option { return func(m *Model) { m.SetRows(rows...) @@ -282,14 +287,16 @@ func WithFocused(f bool) Option { } } -// WithStyles sets the table styles. +// WithStyles sets the table styles. This function is used as an [Option] in +// when creating a table with [New]. func WithStyles(s Styles) Option { return func(m *Model) { m.SetStyles(s) } } -// WithStyleFunc sets the table [table.StyleFunc] for conditional styling. +// WithStyleFunc sets the table [table.StyleFunc] for conditional styling. This +// function is used as an [Option] in when creating a table with [New]. func WithStyleFunc(s table.StyleFunc) Option { return func(m *Model) { m.useStyleFunc = true @@ -297,7 +304,8 @@ func WithStyleFunc(s table.StyleFunc) Option { } } -// WithKeyMap sets the [KeyMap]. +// WithKeyMap sets the [KeyMap]. This function is used as an [Option] in when +// creating a table with [New]. func WithKeyMap(km KeyMap) Option { return func(m *Model) { m.KeyMap = km @@ -375,11 +383,13 @@ func (m *Model) OverwriteStyles(s Styles) *Model { return m } -// TODO +// OverwriteStylesFromLipgloss sets the [Model]'s style attributes from an +// existing [lipgloss.Table]. func (m *Model) OverwriteStylesFromLipgloss(t *table.Table) { t.Rows(m.rows...) t.Headers(m.headers...) m.table = t + m.useStyleFunc = true } // SetStyleFunc sets the table's custom [table.StyleFunc]. Use this for conditional