Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USWDS-Next - Alpha: Create usa-details web component #29

Draft
wants to merge 25 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8cec43f
Set up initial details component
amyleadem Jun 26, 2024
c7c9700
Add open and name attributes
amyleadem Jun 28, 2024
671abca
Add accordion styles in JS; Add multiple details items
amyleadem Jul 1, 2024
7ee3737
Remove old code; format code
amyleadem Jul 1, 2024
57140c8
Move styles to separate js file
amyleadem Jul 1, 2024
7509fc1
Rename style classes; remove unnecessary styles
amyleadem Jul 1, 2024
a50916c
Add bordered variant; add css vars for settings
amyleadem Jul 2, 2024
27ef4e6
Remove console.log
amyleadem Jul 3, 2024
f628083
Add TODO comments; format code
amyleadem Jul 3, 2024
55f89c8
Merge branch 'develop' of https://github.com/uswds/uswds-next into al…
amyleadem Jul 3, 2024
83f51f1
Merge develop; move details component into src
amyleadem Jul 3, 2024
db372e3
Enable remark-gfm for doc formatting
amyleadem Jul 5, 2024
b4ebc5d
Add custom docs for details component
amyleadem Jul 5, 2024
21c2a02
Update `--theme-` -> `--usa-theme-`
amyleadem Jul 5, 2024
cd7b972
Move template content directly to render
amyleadem Jul 8, 2024
26e846c
Rename usa-details.mdx -> readme.mdx
amyleadem Jul 9, 2024
d833c45
Rename custom docs file; add css var controls
amyleadem Jul 9, 2024
4f8bad3
Rename readme and stories.js
amyleadem Jul 9, 2024
cef69c9
Move name attribute to usa-details
amyleadem Jul 9, 2024
0c38bf6
Replace name attribute with multiselect
amyleadem Jul 10, 2024
b7f5356
Add accordion component; add additional core vars
amyleadem Jul 10, 2024
c0f002e
Update details to diff from accordion
amyleadem Jul 10, 2024
4c8c0b4
Remove accordion component
amyleadem Jul 15, 2024
ab86a58
Fix typo in top margin var
amyleadem Jul 16, 2024
184fad1
Remove test class
amyleadem Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions src/components/usa-details/details.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import "./index";
import { html, nothing } from "lit";

export default {
title: "Components/Details",
component: "usa-details",
argTypes: {
groupName: { name: "Details group name" },
bordered: { name: "Add border to panels" },
item1Summary: {name: "Item 1 - Summary text"},
item1Content: { name: "Item 1 - Panel content"},
item1Open: { name: "Item 1 - Open panel on load"},
item2Show: { name: "Include item 2 in preview"},
item2Summary: {name: "Item 2 - Summary text", if: { arg: 'item2Show' } },
item2Content: { name: "Item 2 - Panel content", if: { arg: 'item2Show' } },
item2Open: { name: "Item 2 - Open panel on load", if: { arg: 'item2Show' } },
item3Show: { name: "Include item 3 in preview"},
item3Summary: {name: "Item 3 - Summary text", if: { arg: 'item3Show' } },
item3Content: { name: "Item 3 - Panel content", if: { arg: 'item3Show' } },
item3Open: { name: "Item 3 - Open panel on load", if: { arg: 'item3Show' } },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (if-minor): These are marked as defaults, but they're only used in two variants.

It'd be nice to cleanly separate this. Some suggestions:

  1. Separate default strings from default controls. For example, default args would be reserved for args that are seen on most/every variant.
  2. Adding ability to automatically add any number of accordions (depending on LOE).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: It'd be nice if we could do this in a more intuitive way that wasn't focused on a fixed number of elements.

Possible control ideas

  1. A button in controls that toggles fields for header/content.
  2. An array of objects for header/body content.
  3. A textarea to input any number of <details>.

},
args: {
groupName: "",
bordered: false,
item1Summary: "First Amendment",
item1Content: "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.",
item1Open: false,
item2Show: false,
item2Summary: "Second Amendment",
item2Content: "A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.",
item2Open: false,
item3Show: false,
item3Summary: "Third Amendment",
item3Content: "No Soldier shall, in time of peace be quartered in any house, without the consent of the Owner, nor in time of war, but in a manner to be prescribed by law.",
item3Open: false,
},
render: ({
groupName,
bordered,
item1Summary,
item1Content,
item1Open,
item2Show,
item2Summary,
item2Content,
item2Open,
item3Show,
item3Summary,
item3Content,
item3Open,
}) => html`
<usa-details bordered="${bordered || nothing}">
<details open=${item1Open || nothing} name=${groupName || nothing}>
<summary>${item1Summary}</summary>
<div slot="details-body">${item1Content}</div>
</details>
${item2Show ? html`
<details open=${item2Open || nothing} name=${groupName || nothing}>
<summary>${item2Summary}</summary>
<div slot="details-body">${item2Content}</div>
</details>
`: null}
${item3Show ? html`
<details open=${item3Open || nothing} name=${groupName || nothing}>
<summary>${item3Summary}</summary>
<div slot="details-body">${item3Content}</div>
</details>
`: null}
</usa-details>
`,
};

export const Default = {};

export const bordered = {
args: {
bordered: true
}
};

export const Open = {
args: {
item1Open: true,
},
}

export const GroupSingleSelect = {
args: {
groupName: "example-group-name",
item1Open: true,
item2Show: true,
item3Show: true,
},
}

export const GroupMultiSelect = {
args: {
item1Open: true,
item2Show: true,
item3Show: true,
},
}
63 changes: 63 additions & 0 deletions src/components/usa-details/index.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Are there any events we can trigger via JS on this component?

For example, <usa-banner> can be toggled via toggle() in console.

details-toggle-2024-07-05.at.13.17.58.webm

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { LitElement, html, css, unsafeCSS, nothing } from "lit";
import { classMap } from "lit/directives/class-map.js";
import styles from "./usa-details.css.js";
import uswdsCoreStyles from "@uswds/uswds/scss/uswds-core?inline";

/**
* @summary The usa-details component.
*
* @slot details-body - Content for the details panel
*
* @attribute {Boolean} open - Set the panel to be open on load
* @attribute {String} name - Add a group name if the element is part of a details group
*
* @cssprop --theme-details-font-family - Sets the font family for the details element
* @cssprop --theme-details-border-color - Sets the border width for the details element
* @cssprop --theme-details-border-width - Sets the border color for the details element
* @cssprop --theme-details-background-color - Sets the background color of the content panels
* @cssprop --theme-details-summary-background-color - Sets the background color of the summary element
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: I wonder if there's a way to show these component settings in storybook args.

*
* @tagname usa-details
*/
export class UsaDetails extends LitElement {
static styles = [unsafeCSS(uswdsCoreStyles), styles];

static properties = {
bordered: { type: Boolean }
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question (non-blocking): Should open be listed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was only listing the props that should be added to <usa-details> here. In the current iteration, the open attribute should be added to the the child <details> element, so I left it off the properties list for now. Let me know if that should change!


connectedCallback() {
super.connectedCallback();
this.details = [...this.querySelectorAll('details')];
}

template() {
const classes = {
"usa-details": true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: This should be on the element if it's not dynamic.

"usa-details__bordered": this.bordered
}
return html`
${this.details.map((detail) => {
this.summary = detail.querySelector('summary');
this.content = detail.querySelector('[slot="details-body"]');
this.open = detail.getAttribute('open');
this.name = detail.getAttribute('name');
this.summary.classList.add('usa-details__summary');
this.content.classList.add('usa-details__content');

return html`
<details class="${classMap(classes)}" open="${this.open || nothing}" name="${this.name || nothing}">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: In native disclosure, the open attribute doesn't have a value. For example something like open="false" will still keep the element open.

We should follow this pattern to keep things consistent.

The Details disclosure element - HTML: HyperText Markup Language | MDN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<details class="${classMap(classes)}" open="${this.open || nothing}" name="${this.name || nothing}">
<details class="usa-details ${classMap(classes)}" open="${this.open || nothing}" name="${this.name || nothing}">

${this.summary}
${this.content}
</details>
`;
})}
`;
}

render() {
return this.template();
amyleadem marked this conversation as resolved.
Show resolved Hide resolved
}
}

window.customElements.define("usa-details", UsaDetails);
12 changes: 12 additions & 0 deletions src/components/usa-details/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "usa-details",
"version": "0.0.1",
"description": "USWDS details component",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "SEE LICENSE IN LICENSE.md"
}
48 changes: 48 additions & 0 deletions src/components/usa-details/usa-details.css.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Curious why didn't we use usa-accordion SCSS here?

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { css } from "lit";

export default css`
:host {
.usa-details {
color: #1b1b1b;
/* TODO: use var to define this */
font-family: Source Sans Pro Web,Helvetica Neue,Helvetica,Roboto,Arial,sans-serif;
font-size: 1.06rem;
line-height: 1.5;
margin-top: .5rem;
}
.usa-details__summary {
/* TODO: use local files */
/* TODO: determine if background image is still the best way to add icons here */
background-image: url(https://designsystem.digital.gov/assets/img/usa-icons/add.svg);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question (non-blocking): Is it possible to override this? How would I set my own icon?

background-repeat: no-repeat;
background-size: 1.5rem;
background-color: var(--theme-details-summary-background-color, #f0f0f0);
background-repeat: no-repeat;
background-position: right 1.25rem center;
cursor: pointer;
font-size: 1.06rem;
font-weight: 700;
line-height: .9;
padding: 1rem 3.5rem 1rem 1.25rem;
}
.usa-details__content {
background-color: var(--theme-details-background-color, #fff);
padding: 1.5rem 1.25rem 1.5rem 1rem;
}
.usa-details__bordered {
border-color: var(--theme-details-border-color, #f0f0f0);
border-width: var(--theme-details-border-width, 0.25rem);
border-style: solid;
}
.usa-details[open] .usa-details__summary {
/* TODO: use local files */
background-image: url(https://designsystem.digital.gov/assets/img/usa-icons/remove.svg);
}
.usa-details > .usa-details__summary {
list-style: none;
}
.usa-details > .usa-details__summary ::-webkit-details-marker {
display: none;
}
}
`;
Loading