filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.4k stars 2.97k forks source link

Improve Repeater's `grid()` method to accept closure that can be evaluated later #14553

Closed tjodalv closed 1 month ago

tjodalv commented 1 month ago

Description

The grid() method of the Repeater component already accepts arrays, integers, or strings. This PR introduces support for using closures that can be evaluated later. If the value 'auto' is provided to the grid() method, a closure will be registered to automatically return the number of items in the Repeater. Additionally, users can provide their own custom closure to calculate the grid size based on specific logic.

Functional changes

niladam commented 1 month ago

I think this is a great addition.

I was already looking to this, in order to dynamically set the grid based on some other key.

This allows for doing stuff like this:

TextInput::make('products_number')
    ->label(__('Number of products'))
    ->reactive()
    ->numeric(),

Repeater::make('visible_products')
    ->reactive()
    ->schema([
        Select::make('product_id')
            ->label(__('Choose a product'))
            ->searchable()
            ->options(fn() => Product::active()->pluck('title', 'id')),
    ])
    ->usesPosition()
    ->hiddenLabel()
    ->grid(fn(Get $get) => $get('products_number') ?? 4)

Good job @tjodalv and thank you!

danharrin commented 1 month ago

Hi, apologies but we are no longer accepting new features for v3 as per #13744. Also, please check out our contributing guide which talks about proposing the feature before submitting the PR, to ensure you aren't spending time building something that we won't merge.

I would accept a PR for this feature when v4 is released, if you are still interested, with the following changes:

Thank you!