Skip to content

Commit bc33621

Browse files
authored
feat(select): implementing a responsive select (#17)
1 parent 98accb5 commit bc33621

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

internal/config/config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ func (c *Config) createTemplatesSelect(label string) *ui.SelectModel {
9898
for _, v := range all {
9999
choices = append(choices, ui.Choice(v.Name))
100100
}
101-
m := ui.NewSelect(label, choices)
101+
height := 8
102+
if len(all) > 5 {
103+
height = 12
104+
} else if len(all) > 3 {
105+
height = 10
106+
} else if len(all) > 2 {
107+
height = 9
108+
}
109+
m := ui.NewSelect(label, choices).WithHeight(height)
102110
return m
103111
}
104112

internal/config/default.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ items:
1919
- name: WIP
2020
desc: "Work in progress"
2121
- name: chore
22-
desc: "Changes to the build process or auxiliary tools\n and libraries such as documentation generation"
22+
desc: "Changes to the build process or auxiliary tools and\n libraries such as documentation generation"
2323
- name: style
24-
desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
24+
desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
2525
- name: refactor
2626
desc: "A code change that neither fixes a bug nor adds a feature"
2727
- name: perf

internal/render/template.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Option struct {
1818
func (o *Option) String() string {
1919
var b strings.Builder
2020
ml := len(o.Name)
21-
pl := 10 - ml - 2
21+
pl := 12 - ml - 2
2222
padding := strings.Repeat(" ", pl)
2323
b.WriteString(o.Name)
2424
b.WriteString(": ")
@@ -143,7 +143,15 @@ func (t *Template) createSelectItem(label string, options []Option) *ui.SelectMo
143143
for _, v := range options {
144144
choices = append(choices, ui.Choice(v.String()))
145145
}
146-
m := ui.NewSelect(label, choices)
146+
height := 8
147+
if len(options) > 5 {
148+
height = 12
149+
} else if len(options) > 3 {
150+
height = 10
151+
} else if len(options) > 2 {
152+
height = 9
153+
}
154+
m := ui.NewSelect(label, choices).WithHeight(height)
147155
return m
148156
}
149157

0 commit comments

Comments
 (0)