huh icon indicating copy to clipboard operation
huh copied to clipboard

feat: multicolumn layout forms

Open adamdottv opened this issue 9 months ago • 11 comments

over at @terminaldotshop we've got some huh forms used for payment and shipping info and they'd look a lot better in our app if they were spread over a couple of columns. this pr adds form.WithColumns(count) and splits the groups over the defined columns.

Screen Recording 2024-05-03 at 5 07 43 AM

adamdottv avatar May 03 '24 10:05 adamdottv

This is so awesome @adamdottv! We were thinking about adding different layouts and I think this is great. One thing we might want to do is make the API more "layout" based to allow swapping later on:

For example:

form.WithLayout(huh.LayoutColumns(2))
form.WithLayout(huh.LayoutGrid(2, 2))
form.WithLayout(huh.LayoutAuto) // would automatically layout the groups to fit the screen width
form.WithLayout(huh.LayoutStack) // vertically stack the groups (for tall and narrow terminals)

Obviously don't need to add the other layouts now but want to make sure the API supports future expansion, what do you think?

Also, the column layouts are so great, excited to get that in! Thank you for the awesome addition!

maaslalani avatar May 03 '24 15:05 maaslalani

ah, love it! will try to get these changes in over the weekend!

adamdottv avatar May 03 '24 22:05 adamdottv

alright @maaslalani, i reworked to use a Layout api and implemented LayoutDefault (one group at a time), LayoutColumns(columns int) and LayoutStack; lmk what you think!

adamdottv avatar May 04 '24 10:05 adamdottv

i tried to implement LayoutAuto and LayoutGrid but i'm not smart enough lol; also not a lot of go experience, so that doesn't help

adamdottv avatar May 04 '24 11:05 adamdottv

This is so great @adamdottv! I'll try to review this shortly, we can totally merge this without needing LayoutAuto and LayoutGrid, those can come later.

We'll have to think about what happens when someone specifies something like a Form width of 40 and group width of 30 and columns of 2. My general thinking is that the form width overrides everything and both the groups get adjusted to 20 columns.

We'll need to make sure all the columns are evenly divided to fit within that width, and respect the form width, group widths, and field width (I wonder if we can leverage lipgloss tables here. https://github.com/charmbracelet/lipgloss/releases/tag/v0.9.0, we did a lot of work on auto-resizing tables to fit a given height and to evenly distribute the columns)

maaslalani avatar May 06 '24 14:05 maaslalani

I have never seen a rounded font in a terminal before, @adamdottv. What typeface is this?

meowgorithm avatar May 06 '24 14:05 meowgorithm

I have never seen a rounded font in a terminal before, @adamdottv. What typeface is this?

it's gt maru mono!

adamdottv avatar May 06 '24 15:05 adamdottv

it's gt maru mono!

Fancy! I really never expected to see Grillitype and Open Source together (and yet it makes sense).

meowgorithm avatar May 06 '24 17:05 meowgorithm

fyi, i went ahead and added a LayoutGrid for funsies! tried taking a stab at LayoutAuto but struggled lol

adamdottv avatar May 08 '24 17:05 adamdottv

That's so fantastic! Thank you so much, sorry for taking a while to get to this one.

maaslalani avatar May 11 '24 08:05 maaslalani

no worries at all!

adamdottv avatar May 11 '24 10:05 adamdottv

Merged in https://github.com/charmbracelet/huh/pull/274

maaslalani avatar Jul 05 '24 20:07 maaslalani