diff --git a/sam-styles/packages/components/accordion/accordion.stories.js b/sam-styles/packages/components/accordion/accordion.stories.js index 7b3f13e0..fe568795 100644 --- a/sam-styles/packages/components/accordion/accordion.stories.js +++ b/sam-styles/packages/components/accordion/accordion.stories.js @@ -1,93 +1,70 @@ +//import BorderedAccordion from "./templates/bordered.html"; import MultiSelectableAccordion from "./templates/multiselectable.html"; -import BorderedAccordion from "./templates/bordered.html" export default { title: "Components/Accordion", argTypes: { - class: { control: 'text' }, - expanded: { control: 'boolean' } + class: {type: "string"}, + expanded: {type: "boolean"}, }, -}; -export const Bordered = (args) => { - const container = document.createElement('div'); - container.className = `usa-accordion ${args.class || 'usa-accordion--bordered'}`; - container.innerHTML = BorderedAccordion; + }; - const accordionButtons = container.querySelectorAll('.usa-accordion__button'); - const accordionContents = container.querySelectorAll('.usa-accordion__content'); + const BorderedTemplate = (args) => { + return `
- if (accordionButtons.length > 0 && accordionContents.length > 0) { - accordionButtons[0].setAttribute('aria-expanded', 'true'); - accordionContents[0].style.display = 'block'; - } +

+ +

+ - for (let i = 1; i < accordionButtons.length; i++) { - accordionButtons[i].setAttribute('aria-expanded', 'false'); - accordionContents[i].style.display = 'none'; - } +

+ +

+
+

Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.

+
- const script = document.createElement('script'); - script.type = 'module'; - script.textContent = ` - const initAccordion = () => { - const accordionButtons = document.querySelectorAll('.usa-accordion__button'); - accordionButtons.forEach(button => { - button.addEventListener('click', function() { - const isExpanded = this.getAttribute('aria-expanded') === 'true'; - // Toggle the current section - this.setAttribute('aria-expanded', !isExpanded); - const contentPanelId = this.getAttribute('aria-controls'); - const contentPanel = document.getElementById(contentPanelId); - contentPanel.style.display = isExpanded ? 'none' : 'block'; +

+ +

+ - // Collapse other sections - accordionButtons.forEach(otherButton => { - if (otherButton !== this) { - otherButton.setAttribute('aria-expanded', 'false'); - const otherContentPanel = document.getElementById(otherButton.getAttribute('aria-controls')); - otherContentPanel.style.display = 'none'; - } - }); - }); - }); - }; - initAccordion(); - `; +

+ +

+ - container.appendChild(script); +

+ +

+ - return container; -}; +
`; + }; -export const Multiselectable = () => { - const container = document.createElement('div'); - container.innerHTML = MultiSelectableAccordion; - container.querySelectorAll('.usa-accordion__button').forEach((button, index) => { - button.setAttribute('aria-expanded', index === 1 ? 'true' : 'false'); - }); - container.querySelectorAll('.usa-accordion__content').forEach((content, index) => { - content.style.display = index === 1 ? 'block' : 'none'; - }); - - const script = document.createElement('script'); - script.type = 'module'; - script.textContent = ` - const initAccordion = () => { - const accordionButtons = document.querySelectorAll('.usa-accordion__button'); - accordionButtons.forEach(button => { - button.addEventListener('click', function() { - const isExpanded = this.getAttribute('aria-expanded') === 'true'; - this.setAttribute('aria-expanded', !isExpanded); - const contentPanelId = this.getAttribute('aria-controls'); - const contentPanel = document.getElementById(contentPanelId); - contentPanel.style.display = isExpanded ? 'none' : 'block'; - }); - }); - }; - initAccordion(); - `; - - container.appendChild(script); - - return container; -}; + export const Multiselectable = () => { + return MultiSelectableAccordion; + }; + + export const Bordered = BorderedTemplate.bind({}); + Bordered.args = { + class: "usa-accordion--bordered", + }; \ No newline at end of file diff --git a/sam-styles/packages/components/accordion/templates/bordered.html b/sam-styles/packages/components/accordion/templates/bordered.html index 67e4abb9..a41a1e42 100644 --- a/sam-styles/packages/components/accordion/templates/bordered.html +++ b/sam-styles/packages/components/accordion/templates/bordered.html @@ -5,9 +5,9 @@

Accordion Button

-
+

-
+

-
+

-
+
\ No newline at end of file diff --git a/sam-styles/packages/components/accordion/templates/multiselectable.html b/sam-styles/packages/components/accordion/templates/multiselectable.html index 31c94a52..ee198e64 100644 --- a/sam-styles/packages/components/accordion/templates/multiselectable.html +++ b/sam-styles/packages/components/accordion/templates/multiselectable.html @@ -5,9 +5,9 @@

Accordion Button

-
+