diff --git a/resources/views/interactive/details.blade.php b/resources/views/interactive/details.blade.php new file mode 100644 index 00000000..1f812bac --- /dev/null +++ b/resources/views/interactive/details.blade.php @@ -0,0 +1,3 @@ +
+ {{ $slot }} +
diff --git a/src/Components/Interactive/Details.php b/src/Components/Interactive/Details.php new file mode 100644 index 00000000..714ee549 --- /dev/null +++ b/src/Components/Interactive/Details.php @@ -0,0 +1,73 @@ + elements to be connected, with only one open at a time. This allows + * developers to easily create UI features such as accordions without scripting. + * + * The name attribute specifies a group name — give multiple
elements the same name value to group them. + * Only one of the grouped
elements can be open at a time — opening one will cause another to close. If + * multiple grouped
elements are given the open attribute, only the first one in the source order will be + * rendered open. + */ + public string $name = ''; + + /** + * This Boolean attribute indicates whether the details — that is, the contents of the
element — are + * currently visible. The details are shown when this attribute exists, or hidden when this attribute is absent. + * By default this attribute is absent which means the details are not visible. + */ + public bool $open = false; + + /** + * The specific attributes for the details element. + */ + private AttributeCollection $specificAttributes; + + /** + * Standard mount function + */ + public function mount(): void + { + $this->setGlobalAttributes(); + $this->specificAttributes = new AttributeCollection(); + if ($this->open) { + $this->specificAttributes->add(['open']); + } + if (! empty($this->name)) { + $this->specificAttributes->add(['name' => $this->name]); + } + } + + /** + * Standard render function + */ + public function render(): Application|ContractedApplication|ContractedView|Factory|View + { + return view( + 'lw-bits::interactive.details', + [ + 'globalAttributes' => $this->getGlobalAttributes(), + 'specificAttributes' => $this->parseAttributes($this->specificAttributes), + 'slot' => '', + ] + ); + } +} diff --git a/tests/Feature/Interactive/DetailsTest.php b/tests/Feature/Interactive/DetailsTest.php new file mode 100644 index 00000000..1e55ccd9 --- /dev/null +++ b/tests/Feature/Interactive/DetailsTest.php @@ -0,0 +1,129 @@ +assertStatus(200); +}); + +it('can render with accesskey', function () { + Livewire::test(MyDetails::class, ['accessKey' => true]) + ->assertSee('accesskey'); +}); + +it('can render with autocapitalize', function () { + Livewire::test(MyDetails::class, ['autoCapitalize' => true]) + ->assertSee('autocapitalize'); +}); + +it('can render with autofocus', function () { + Livewire::test(MyDetails::class, ['autoFocus' => true]) + ->assertSee('autofocus'); +}); + +it('can render with contenteditable', function () { + Livewire::test(MyDetails::class, ['contentEditable' => true]) + ->assertSee('contenteditable'); +}); + +it('can render with css classes', function () { + Livewire::test(MyDetails::class, ['cssClasses' => ['class1', 'class2']]) + ->assertSee('class="class1 class2"', false); +}); + +it('can render with data-*', function () { + Livewire::test(MyDetails::class, ['data' => ['name' => 'main-details']]) + ->assertSee('data-name="main-details"', false); +}); + +it('can render with dir', function () { + Livewire::test(MyDetails::class, ['direction' => 'rtl']) + ->assertSee('dir="rtl"', false); +}); + +it('can render with draggable', function () { + Livewire::test(MyDetails::class, ['draggable' => true]) + ->assertSee('draggable'); +}); + +it('can render with enterkeyhint', function () { + Livewire::test(MyDetails::class, ['enterKeyHint' => 'enter']) + ->assertSee('enterkeyhint="enter"', false); +}); + +it('can render with hidden', function () { + Livewire::test(MyDetails::class, ['hidden' => true]) + ->assertSee('hidden'); +}); + +it('can render with id', function () { + Livewire::test(MyDetails::class, ['id' => 'main-details']) + ->assertSee('id="main-details"', false); +}); + +it('can render with language', function () { + Livewire::test(MyDetails::class, ['language' => 'en']) + ->assertSee('lang="en"', false); +}); + +it('can render with nonce', function () { + Livewire::test(MyDetails::class, ['nonce' => 'abc123']) + ->assertSee('nonce="abc123"', false); +}); + +it('can render with parts', function () { + Livewire::test(MyDetails::class, ['parts' => ['part1', 'part2']]) + ->assertSee('part="part1 part2"', false); +}); + +it('can render with popOver', function () { + Livewire::test(MyDetails::class, ['popOver' => true]) + ->assertSee('popover'); +}); + +it('can render with role', function () { + Livewire::test(MyDetails::class, ['role' => 'main']) + ->assertSee('role="main"', false); +}); + +it('can render with slot', function () { + Livewire::test(MyDetails::class, ['slotAttribute' => 'main-details']) + ->assertSee('slot="main-details"', false); +}); + +it('can render with spellcheck', function () { + Livewire::test(MyDetails::class, ['spellCheck' => true]) + ->assertSee('spellcheck'); +}); + +it('can render with styles', function () { + Livewire::test(MyDetails::class, ['styles' => ['color' => 'red', 'font-size' => '16px']]) + ->assertSee('style="color:red;font-size:16px"', false); +}); + +it('can render with tabindex', function () { + Livewire::test(MyDetails::class, ['tabIndex' => 1]) + ->assertSee('tabindex="1"', false); +}); + +it('can render with title', function () { + Livewire::test(MyDetails::class, ['title' => 'main-details']) + ->assertSee('title="main-details"', false); +}); + +it('can render with translate', function () { + Livewire::test(MyDetails::class, ['translate' => true]) + ->assertSee('translate'); +}); + +it('can render with open', function () { + Livewire::test(MyDetails::class, ['open' => true]) + ->assertSee('open'); +}); + +it('can render with name', function () { + Livewire::test(MyDetails::class, ['name' => 'main-details']) + ->assertSee('name="main-details"', false); +}); diff --git a/tests/TestSupport/Components/Interactive/MyDetails.php b/tests/TestSupport/Components/Interactive/MyDetails.php new file mode 100644 index 00000000..07a37a95 --- /dev/null +++ b/tests/TestSupport/Components/Interactive/MyDetails.php @@ -0,0 +1,7 @@ +