Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multicolumn layout forms #214

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

adamdottv
Copy link
Contributor

@adamdottv adamdottv commented May 3, 2024

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 adamdottv requested a review from maaslalani as a code owner May 3, 2024 10:15
@maaslalani
Copy link
Member

maaslalani commented May 3, 2024

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!

@adamdottv
Copy link
Contributor Author

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

@adamdottv
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@maaslalani
Copy link
Member

maaslalani commented May 6, 2024

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)

@meowgorithm
Copy link
Member

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

@adamdottv
Copy link
Contributor Author

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

it's gt maru mono!

@meowgorithm
Copy link
Member

it's gt maru mono!

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

@adamdottv
Copy link
Contributor Author

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

@maaslalani
Copy link
Member

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

@adamdottv
Copy link
Contributor Author

no worries at all!

Copy link
Member

@maaslalani maaslalani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking awesome, thanks so much @adamdotdev!

@maaslalani maaslalani mentioned this pull request Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants