-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
187 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
|
||
export default class extends Controller { | ||
static targets = ["panel", "iconOpen", "iconClose"] | ||
|
||
connect(){ | ||
this.handleIconDisplay() | ||
} | ||
|
||
toggle(event) { | ||
|
||
const el = event.currentTarget.closest('[data-accordeon]'); | ||
const panelE = el.querySelector('[data-accordeon-target="panel"]'); | ||
|
||
this.panelTargets.forEach((panel) => { | ||
|
||
if (panel === panelE) { | ||
panel.classList.toggle("hidden"); | ||
} else { | ||
panel.classList.remove("open"); | ||
panel.classList.remove("hidden"); | ||
} | ||
}); | ||
|
||
this.handleIconDisplay() | ||
} | ||
|
||
handleIconDisplay(){ | ||
if( this.panelTarget.classList.contains("hidden")){ | ||
if(this.hasIconOpenTarget){ this.iconOpenTarget.classList.add("hidden") } | ||
if(this.hasIconCloseTarget){ this.iconCloseTarget.classList.remove("hidden") } | ||
} else { | ||
if(this.hasIconOpenTarget){ this.iconOpenTarget.classList.remove("hidden") } | ||
if(this.hasIconCloseTarget){ this.iconCloseTarget.classList.add("hidden") } | ||
} | ||
} | ||
} |
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
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,20 @@ | ||
<div role="none" data-action="click->accordeon#toggle" | ||
class="flex items-center justify-between py-5 px-5 border-b border-muted"> | ||
<span class="font-medium text-default"> | ||
<%= title%> | ||
</span> | ||
|
||
<svg stroke="currentColor" data-accordeon-target="iconOpen" fill="currentColor" stroke-width="0" viewBox="0 0 16 16" | ||
class="ml-auto text-default" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"> | ||
<path fill-rule="evenodd" d="M7.646 4.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 5.707l-5.646 5.647a.5.5 0 0 1-.708-.708l6-6z"> | ||
</path> | ||
</svg> | ||
|
||
<svg stroke="currentColor" data-accordeon-target="iconClose" fill="currentColor" stroke-width="0" t="1551322312294" viewBox="0 0 1024 1024" version="1.1" | ||
class="ml-auto text-default" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"> | ||
<defs></defs> | ||
<path d="M474 152m8 0l60 0q8 0 8 8l0 704q0 8-8 8l-60 0q-8 0-8-8l0-704q0-8 8-8Z"></path><path d="M168 474m8 0l672 0q8 0 8 8l0 60q0 8-8 8l-672 0q-8 0-8-8l0-60q0-8 8-8Z"> | ||
</path> | ||
</svg> | ||
|
||
</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