patricktalmadge / bootstrapper

Laravel Twitter Bootstrap Bundle
561 stars 129 forks source link

[Proposal] Add panel tables #273

Closed rmobis closed 9 years ago

rmobis commented 9 years ago

According to the Bootrstrap 3 documentation, it is possible to have tables inside panels simply by appending them after the body. There are even special styles for it. This PR adds a withTable method to allow for that along with a test that is pretty much like the other ones for the Panel class.

If there's anything to be improved, please let me know.

Example

The following PHP code:

Panel::normal()
    ->withHeader('Lorem Ipsum')
    ->withBody('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorum esse consequatur repellendus autem facere omnis sequi eaque error, cum tempora numquam. Quis totam suscipit nisi ut obcaecati! Veniam saepe, vel.')
    ->withTable(Table::withContents([
        [
            'Id' => 1,
            'First Name' => 'Patrick',
            'Last Name' => 'Talmadge'
        ],
        [
            'Id' => 2,
            'First Name' => 'Patrick',
            'Last Name' => 'Rose'
        ],
        [
            'Id' => 3,
            'First Name' => 'Maxime',
            'Last Name' => 'Fabre'
        ]
    ])->striped());

Produces the following HTML code:

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">Lorem Ipsum</h3>
    </div>
    <div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorum esse consequatur repellendus autem facere omnis sequi eaque error, cum tempora numquam. Quis totam suscipit nisi ut obcaecati! Veniam saepe, vel.</div>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Id</th>
                <th>First Name</th>
                <th>Last Name</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>1</td>
                <td>Patrick</td>
                <td>Talmadge</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Patrick</td>
                <td>Rose</td>
            </tr>
            <tr>
                <td>3</td>
                <td>Maxime</td>
                <td>Fabre</td>
            </tr>
        </tbody>
    </table>
</div>

Which renders to the following panel:

rmobis commented 9 years ago

Removed renderTable(). Is there anything you think should be different?

rmobis commented 9 years ago

Done. I left the $table->render() part on the withTable method. I'm unsure whether it'd be better to recreate the renderTable method for this and store the property without rendering...

rmobis commented 9 years ago

Thought so. Changed it.

PatrickRose commented 9 years ago

Sorry for the delay - thanks!