Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion resources/views/collapse.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<details {{ $attributes }} @if ($open) open @endif>
<summary class="{{ $viewClasses['title'] }}">{{ $title }}</summary>
<summary class="{{ $viewClasses['title'] }}">
@isset($summary)
{{ $summary }}
@else
{{ $title }}
@endisset
</summary>
<div class="{{ $viewClasses['content'] }}">{{ $slot }}</div>
</details>
22 changes: 12 additions & 10 deletions resources/views/swap.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<label {{ $attributes }}>
<input
type="checkbox"
@if ($name) name="{{ $name }}" @endif
value="{{ $value }}"
@checked($checked)
@disabled($disabled)
{{ $inputAttributes }}
/>
<{{ $tag }} {{ $attributes }}>
@unless ($controlled)
<input
type="checkbox"
@if ($name) name="{{ $name }}" @endif
value="{{ $value }}"
@checked($checked)
@disabled($disabled)
{{ $inputAttributes }}
/>
@endunless

@if ($onLabel !== null)
<span class="{{ $viewClasses['on'] }}">{{ $onLabel }}</span>
Expand All @@ -27,4 +29,4 @@
@endif

{{ $slot }}
</label>
</{{ $tag }}>
12 changes: 10 additions & 2 deletions src/Components/Collapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Collapse extends DaisyComponent

public function __construct(
public string $title = '',
public string $summaryClass = '',
public string $contentClass = '',
public bool $open = false,
public bool $arrow = true,
public bool $plus = false,
Expand All @@ -18,8 +20,14 @@ public function __construct(
protected function viewClasses(): array
{
return [
'title' => 'collapse-title',
'content' => 'collapse-content',
'title' => $this->classes([
'collapse-title',
$this->summaryClass => $this->summaryClass !== '',
]),
'content' => $this->classes([
'collapse-content',
$this->contentClass => $this->contentClass !== '',
]),
];
}

Expand Down
7 changes: 6 additions & 1 deletion src/Components/Swap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ class Swap extends DaisyComponent
{
protected const VIEW = 'lazy::swap';

public string $tag;

public function __construct(
public bool $active = false,
public bool $rotate = false,
public bool $flip = false,
public bool $controlled = false,
public string $name = '',
public string $value = '1',
public bool $checked = false,
public bool $disabled = false,
public mixed $onLabel = null,
public mixed $offLabel = null,
public mixed $indeterminateLabel = null,
) {}
) {
$this->tag = $this->controlled ? 'div' : 'label';
}

protected function viewClasses(): array
{
Expand Down
23 changes: 23 additions & 0 deletions tests/Components/DaisyUiIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,26 @@
->assertSee('Users')
->assertSee('42');
});

it('supports externally controlled swap state for Alpine or other state owners', function () {
$this
->blade('<x-lazy-swap controlled rotate x-bind:class="{ \'swap-active\': open }"><x-slot:on>On</x-slot:on><x-slot:off>Off</x-slot:off></x-lazy-swap>')
->assertSee('<div', false)
->assertSee('swap-rotate')
->assertSee('x-bind:class', false)
->assertSee('swap-on')
->assertSee('swap-off')
->assertDontSee('type="checkbox"', false);
});

it('supports rich collapse summaries and content classes', function () {
$this
->blade('<x-lazy-collapse summary-class="text-lg font-semibold" content-class="space-y-5"><x-slot:summary><span>Permissions</span><small>12 total</small></x-slot:summary>Body</x-lazy-collapse>')
->assertSee('collapse-arrow')
->assertSee('text-lg')
->assertSee('font-semibold')
->assertSee('space-y-5')
->assertSee('Permissions')
->assertSee('12 total')
->assertSee('Body');
});