marvinlabs / laravel-html-bootstrap-4

Bootstrap 4 fluent HTML builder
MIT License
42 stars 15 forks source link

Shortcut method to make a row out of a form group #15

Closed vpratfr closed 6 years ago

vpratfr commented 6 years ago

As an effort to simplify creation of horizontal forms (related to #12, #14)

For instance

    {{ bs()->formGroup(bs()->text('first_name', 'John'))
            ->wrapControlIn(bs()->div()->addClass('col-sm-10'))
            ->label('First name', false, ['col-sm-2'])
            ->addClass('row')}}

could be

    {{ bs()->formGroup(bs()->text('first_name', 'John'))
            ->label('First name', false)
            ->asRow(['sm' => [2, 10]]) }}

or with offsets in some cases :

    {{ bs()->formGroup(bs()->submit('Submit', 'secondary')->child(fa()->icon('send')->addClass('ml-2')))
            ->wrapControlIn(bs()->div()->addClass('col-sm-10 offset-sm-2'))
            ->addClass('row')}}

would be

    {{ bs()->formGroup(bs()->submit('Submit', 'secondary')->child(fa()->icon('send')->addClass('ml-2')))
            ->asRow(['sm' => [2, 10]]) }}

Maybe an API would be better to simplify building row classes:

->asRow(['sm' => [2, 10]])

Could be something like

->asRow(bs()->formRow()->sm(2, 10)->md(3, 10))
->asRow(bs()->formRow()
    ->sm(false, 10)) // false means that we should ignore column and offset the next one