generated from withstudiocms/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
2ffd4b1
commit be70bf5
Showing
8 changed files
with
116 additions
and
1 deletion.
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 @@ | ||
--- | ||
title: Accordion | ||
--- | ||
|
||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
import PreviewCard from '~/components/PreviewCard.astro'; | ||
import { Accordion, AccordionItem } from '@studiocms/ui/components'; | ||
|
||
A simple divider. Allows for showing a label in the center, which is helpful for seperating sidebars or other structured content. | ||
|
||
<Tabs> | ||
<TabItem label="Preview"> | ||
<PreviewCard> | ||
<Accordion> | ||
<AccordionItem> | ||
<div slot="summary">This is the summary</div> | ||
<div slot="details">These are the details</div> | ||
</AccordionItem> | ||
<AccordionItem> | ||
<div slot="summary">This is the 2nd summary</div> | ||
<div slot="details">These are the 2nd details</div> | ||
</AccordionItem> | ||
</Accordion> | ||
</PreviewCard> | ||
</TabItem> | ||
<TabItem label="Code"> | ||
```astro showLinenumbers title="DividerExample.astro" | ||
--- | ||
import { Divider } from '@studiocms/ui/components'; | ||
--- | ||
<Divider> | ||
Divider | ||
</Divider> | ||
``` | ||
</TabItem> | ||
</Tabs> |
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
14 changes: 14 additions & 0 deletions
14
packages/studiocms_ui/src/components/Accordion/Accordion.astro
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,14 @@ | ||
--- | ||
import './accordion.css'; | ||
interface Props { | ||
initialOpen?: string; | ||
} | ||
--- | ||
|
||
<div class="sui-accordion"> | ||
<slot /> | ||
</div> | ||
<script> | ||
import 'studiocms:ui/scripts/accordion'; | ||
</script> |
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,12 @@ | ||
--- | ||
--- | ||
|
||
<div class="sui-accordion-item"> | ||
<div class="sui-accordion-summary"> | ||
<slot name="summary" /> | ||
</div> | ||
<div class="sui-accordion-details initial"> | ||
<slot name="details" /> | ||
</div> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
packages/studiocms_ui/src/components/Accordion/accordion.css
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,23 @@ | ||
.sui-accordion { | ||
width: 100%; | ||
} | ||
|
||
.sui-accordion-details.initial { | ||
visibility: hidden; | ||
transition: none; | ||
max-height: none; | ||
position: absolute; | ||
top: -200vh; | ||
left: -200vh; | ||
} | ||
|
||
.sui-accordion-details.active { | ||
overflow: hidden; | ||
max-height: 0; | ||
transition: all .3s ease; | ||
position: relative; | ||
} | ||
|
||
.sui-accordion-item.active > .sui-accordion-details { | ||
max-height: 100px; | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/studiocms_ui/src/components/Accordion/accordion.ts
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,25 @@ | ||
const accordions = document.querySelectorAll<HTMLDivElement>('.sui-accordion'); | ||
|
||
for (const accordion of accordions) { | ||
const items = accordion.querySelectorAll<HTMLDivElement>('.sui-accordion-item'); | ||
|
||
for (const item of items) { | ||
const content = accordion.querySelector<HTMLDivElement>('.sui-accordion-details'); | ||
if (!content) continue; | ||
const contentBoundingBox = content.getBoundingClientRect(); | ||
|
||
if (content.classList.contains('initial')) { | ||
content.classList.remove('initial'); | ||
content.classList.add('active'); | ||
} | ||
|
||
item.addEventListener('click', () => { | ||
item.classList.toggle('active'); | ||
if (item.classList.contains('active')) { | ||
content.style.maxHeight = `${contentBoundingBox.height}px`; | ||
} else { | ||
content.style.maxHeight = `0`; | ||
} | ||
}); | ||
} | ||
} |
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