Skip to content

Commit

Permalink
feat(select): implementing a responsive select (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
shipengqi authored Mar 7, 2024
1 parent 98accb5 commit bc33621
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
10 changes: 9 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ func (c *Config) createTemplatesSelect(label string) *ui.SelectModel {
for _, v := range all {
choices = append(choices, ui.Choice(v.Name))
}
m := ui.NewSelect(label, choices)
height := 8
if len(all) > 5 {
height = 12
} else if len(all) > 3 {
height = 10
} else if len(all) > 2 {
height = 9
}
m := ui.NewSelect(label, choices).WithHeight(height)
return m
}

Expand Down
4 changes: 2 additions & 2 deletions internal/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ items:
- name: WIP
desc: "Work in progress"
- name: chore
desc: "Changes to the build process or auxiliary tools\n and libraries such as documentation generation"
desc: "Changes to the build process or auxiliary tools and\n libraries such as documentation generation"
- name: style
desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
- name: refactor
desc: "A code change that neither fixes a bug nor adds a feature"
- name: perf
Expand Down
12 changes: 10 additions & 2 deletions internal/render/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Option struct {
func (o *Option) String() string {
var b strings.Builder
ml := len(o.Name)
pl := 10 - ml - 2
pl := 12 - ml - 2
padding := strings.Repeat(" ", pl)
b.WriteString(o.Name)
b.WriteString(": ")
Expand Down Expand Up @@ -143,7 +143,15 @@ func (t *Template) createSelectItem(label string, options []Option) *ui.SelectMo
for _, v := range options {
choices = append(choices, ui.Choice(v.String()))
}
m := ui.NewSelect(label, choices)
height := 8
if len(options) > 5 {
height = 12
} else if len(options) > 3 {
height = 10
} else if len(options) > 2 {
height = 9
}
m := ui.NewSelect(label, choices).WithHeight(height)
return m
}

Expand Down

0 comments on commit bc33621

Please sign in to comment.