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

Added template for grid columns on Group #2913

Merged
merged 3 commits into from
Oct 28, 2024
Merged

Added template for grid columns on Group #2913

merged 3 commits into from
Oct 28, 2024

Conversation

tabuna
Copy link
Member

@tabuna tabuna commented Oct 28, 2024

In the current version, the Group component is used to organize multiple fields in a single row divided into columns, and it supports two display modes:

  1. Default — each column has an equal width.
  2. AutoWidth — each column’s width is automatically determined based on its content size.

However, these modes can be limiting when building more customized interfaces, as they don't allow precise control over column widths (e.g., setting one field to take up 10% and another to take up 60% of the row).

To address this, I’ve added a new widthColumns() method, enabling CSS Grid support for columns. This method allows for flexible width configurations by passing values for the grid-template-columns CSS property. Example usage:

Group::make([
    Input::make('credit_card')
        ->mask('9999-9999-9999-9999')
        ->title('Credit card:')
        ->placeholder('Credit card number')
        ->help('Number is the long set of digits displayed across the front of your plastic card'),

    Input::make('currency')
        ->title('Currency dollar:')
        ->mask(['alias' => 'currency'])
        ->help('Examples: email, currency, decimal, integer, date, datetime, dd/mm/yyyy, etc.'),
])->widthColumns('2fr 1fr');

The widthColumns() method accepts a range of values:

  • Percentages, e.g., 30%
  • Pixels, e.g., 120px
  • Fractional units, e.g., 2fr
  • Other values such as max-content and auto

Warning

The number of specified values should not be less than the number of elements in the group.

These settings are applied only on desktop displays, while on mobile devices, each field will continue to display on a new row for better responsiveness.

This enhancement makes the Group component more versatile, allowing for customized column width distributions to create more tailored interfaces.

Conflict or Inconsistency

We already have a similar mechanism in the Split layout, where it’s possible to define a ratio:

Layout::split([
    Layout::view('first-view'),
    Layout::view('second-view'),
])->ratio('40/60');

I’m concerned that this new implementation may introduce inconsistency.

@agoalofalife agoalofalife self-requested a review October 28, 2024 12:24
@agoalofalife
Copy link
Contributor

I think we might rename method like gridWidthColumns or gridWidthColumns or widthColumns

@tabuna
Copy link
Member Author

tabuna commented Oct 28, 2024

@agoalofalife I like your suggestion; I would prefer a shorter name, such as widthColumns.

@tabuna tabuna merged commit b7d778d into master Oct 28, 2024
45 of 48 checks passed
@tabuna tabuna deleted the group-template branch October 28, 2024 21:36
@agoalofalife
Copy link
Contributor

@tabuna Do this feature need in public documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants