-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from chrisrhymes/feature/modals
Added modal and modal-card components
- Loading branch information
Showing
5 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@props(['trigger', 'type' => 'is-primary', 'title', 'cancel' => 'Cancel']) | ||
<div x-data="{ active: false }"> | ||
<button {{ $attributes->merge(['class' => 'button '.$type]) }} @click="active = true">{{ $trigger }}</button> | ||
<div class="modal" :class="{ 'is-active': active == true }"> | ||
<div class="modal-background" @click="active = false"></div> | ||
<div class="modal-card"> | ||
<header class="modal-card-head"> | ||
<p class="modal-card-title">{{ $title }}</p> | ||
<button class="delete" aria-label="close" @click="active = false"></button> | ||
</header> | ||
<section class="modal-card-body"> | ||
{{ $slot }} | ||
</section> | ||
@isset($footer) | ||
<footer class="modal-card-foot"> | ||
<button class="button" @click="active = false">{{ $cancel }}</button> | ||
{{ $footer }} | ||
</footer> | ||
@endisset | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@props(['trigger', 'type' => 'is-primary']) | ||
<div x-data="{ active: false }"> | ||
<button {{ $attributes->merge(['class' => 'button '.$type]) }} @click="active = true">{{ $trigger }}</button> | ||
<div class="modal" :class="{ 'is-active': active == true }"> | ||
<div class="modal-background" @click="active = false"></div> | ||
<div class="modal-content"> | ||
{{ $slot }} | ||
</div> | ||
<button class="modal-close is-large" aria-label="close" @click="active = false"></button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Tests\Components; | ||
|
||
use Tests\TestCase; | ||
|
||
class ModalCardTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_renders_the_message_component() | ||
{ | ||
$view = $this->blade( | ||
'<x-bbui::modal-card :title="$title"> | ||
<x-slot name="trigger">Open Modal</x-slot> | ||
The modal content | ||
</x-bbui::modal-card>', | ||
['title' => 'The modal title'] | ||
); | ||
|
||
$view->assertSee('The modal content'); | ||
$view->assertSee('button is-primary'); | ||
$view->assertSee('modal-background'); | ||
} | ||
|
||
/** @test */ | ||
public function it_overrides_the_type() | ||
{ | ||
$view = $this->blade( | ||
'<x-bbui::modal-card :title="$title" :type="$type"> | ||
<x-slot name="trigger">Open Modal</x-slot> | ||
The modal content | ||
</x-bbui::modal-card>', | ||
['title' => 'The modal title', 'type' => 'is-danger'] | ||
); | ||
|
||
$view->assertSee('button is-danger'); | ||
$view->assertDontSee('button is-primary'); | ||
} | ||
|
||
/** @test */ | ||
public function it_renders_the_footer() | ||
{ | ||
$view = $this->blade( | ||
'<x-bbui::modal-card :title="$title" :cancel="$cancel"> | ||
<x-slot name="trigger">Open Modal</x-slot> | ||
The modal content | ||
<x-slot name="footer"> | ||
<button class="button is-info" @click="active = false">Confirm</button> | ||
</x-slot> | ||
</x-bbui::modal-card>', | ||
['title' => 'The modal title', 'cancel' => 'Close Modal'] | ||
); | ||
|
||
$view->assertSee('modal-card-foot'); | ||
$view->assertSee('Close Modal'); | ||
$view->assertDontSee('Cancel'); | ||
$view->assertSee('Confirm'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Tests\Components; | ||
|
||
use Tests\TestCase; | ||
|
||
class ModalTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_renders_the_message_component() | ||
{ | ||
$view = $this->blade( | ||
'<x-bbui::modal> | ||
<x-slot name="trigger">Open Modal</x-slot> | ||
The modal content | ||
</x-bbui::modal>', | ||
[] | ||
); | ||
|
||
$view->assertSee('The modal content'); | ||
$view->assertSee('button is-primary'); | ||
$view->assertSee('modal-background'); | ||
} | ||
|
||
/** @test */ | ||
public function it_overrides_the_type() | ||
{ | ||
$view = $this->blade( | ||
'<x-bbui::modal :type="$type"> | ||
<x-slot name="trigger">Open Modal</x-slot> | ||
The modal content | ||
</x-bbui::modal>', | ||
['type' => 'is-danger'] | ||
); | ||
|
||
$view->assertSee('button is-danger'); | ||
$view->assertDontSee('button is-primary'); | ||
} | ||
} |