These below snippets go into admin/main.js
Created
October 30, 2025 21:15
-
-
Save caseywatts/9ce8ad0da04e4230949621ad2ee80808 to your computer and use it in GitHub Desktop.
Decap Custom Widgets for USWDS Components
This file contains hidden or 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
| // DRAFT | |
| // This is for the USWDS Accordion component https://designsystem.digital.gov/components/accordion/ | |
| // This version is not accessible yet; I haven't set up the aria-controls and aria-expanded for this yet | |
| // | |
| // There are two approaches I'm considering | |
| // 1. having this in a web component, so it can create its own association | |
| // 2. having Decap generate a uuid to connect aria-controls | |
| function toBlock(data) { | |
| return `<div class="usa-accordion"><div class="usa-accordion__heading"><button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="a1">${data.summary}</button></div><div id="a1" class="usa-accordion__content usa-prose">\n\n${data.contents}\n\n</div></div>`; | |
| } | |
| const pattern = RegExp( | |
| `<div class="usa-accordion"><div class="usa-accordion__heading"><button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="a1">(.*?)</button></div><div id="a1" class="usa-accordion__content usa-prose">\n\n(.*?)\n\n</div></div>`, | |
| "ms", | |
| ); | |
| CMS.registerEditorComponent({ | |
| id: "uswds-accordion", | |
| label: "USWDS Accordion", | |
| fields: [ | |
| { | |
| name: "summary", | |
| label: "Summary", | |
| widget: "string", | |
| }, | |
| { | |
| name: "contents", | |
| label: "Contents", | |
| widget: "markdown", | |
| }, | |
| ], | |
| pattern: pattern, | |
| fromBlock: function (match) { | |
| return { | |
| summary: match[1], | |
| contents: match[2], | |
| }; | |
| }, | |
| toBlock: (data) => { | |
| return toBlock(data); | |
| }, | |
| toPreview: (data) => { | |
| return toBlock(data); | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment