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

Web-components: Create usa-identifier web component #21

Open
wants to merge 64 commits into
base: develop
Choose a base branch
from

Conversation

amyleadem
Copy link
Contributor

@amyleadem amyleadem commented Jun 17, 2024

Summary

Create an alpha version of the usa-identifier web component.

Related issue

Closes #26

Preview link

Identifier component (Storybook)

Related PRs

This is a cleaned up version of the "identifier playground" in PR #11.

Note

PR #11 explores alternative methods for implementing the identifier component, including a couple of options for an attribute-based implementation. There are a lot of files and options in there, so I created this second PR to minimize confusion as I focus on the declarative markup version of the component. Please add any comments about the identifier web component to this PR, not PR #11.

Task list

  • Match visuals from USWDS 3
  • Passes accessibility tests
  • Offer ability to create content in multiple languages
  • Incorporate Lit internationalization (on hold)
  • Add CSS parts to customizable elements
  • Create CSS variables for existing identifier settings
  • Improve formatting on code preview in Storybook
  • Draft unit tests
  • Demo css variables in storybook controls

@amyleadem amyleadem marked this pull request as ready for review June 20, 2024 16:08
Copy link
Collaborator

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

Nice work so far! Added a few comments thinking about lessons learned in #12.

We don't have to follow that path, but we should consider what we can render by default in the component if users write <usa-identifier></usa-identifier>.

import uswdsCoreStyle from "@uswds/uswds/scss/uswds-core?inline";
import usaIdentifierStyle from "@uswds/uswds/scss/usa-identifier?inline";

export class UsaIdentifier extends LitElement {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lit recommends using component props as input. Source →

We should leverage reactive props if we're able to for defaults / configurable settings.

Comment on lines 67 to 69
<a slot="logo" href="${primary_agency.url}">
<img src="${logo1}" alt="${primary_agency.name} logo" />
</a>`: null}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seeing slot here, I'd expect to see <slot> elements in the component template.

Example

<!-- Our template - [`identifier/index.js`] -->
<slot name="logo"></slot>

<!-- User overrides in markup -->
<span slot="logo">
  <img src="logo-1.svg" />
  <img src="logo-2.svg" />
  <img src="logo-3.svg" />
</span>

web-components/src/components/usa-identifier/index.js Outdated Show resolved Hide resolved
@amyleadem amyleadem marked this pull request as draft June 26, 2024 23:48
@amyleadem amyleadem marked this pull request as ready for review August 14, 2024 20:27
@@ -45,6 +45,7 @@
"@storybook/addon-a11y": "^8.2.7",
"@storybook/addon-essentials": "^8.2.7",
"@storybook/addon-links": "^8.2.7",
"@storybook/addon-mdx-gfm": "^8.1.11",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note

Added this dependency to enable markdown tables in the readme.mdx file 1. If we move forward without the docs tables, we can remove this dependency.

Footnotes

  1. https://storybook.js.org/docs/writing-docs/mdx#markdown-tables-arent-rendering-correctly

Comment on lines +14 to +23
{
name: '@storybook/addon-docs',
options: {
mdxPluginOptions: {
mdxCompileOptions: {
remarkPlugins: [remarkGfm],
},
},
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note

Added this code to enable markdown tables in the readme.mdx file 1. If we move forward without the docs tables, we can remove this.

Footnotes

  1. https://storybook.js.org/docs/writing-docs/mdx#markdown-tables-arent-rendering-correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note

I manually added content to the tables on this page to demonstrate ideas for possible content in the storybook docs. In the future, we should explore ways to automatically generate this content from the JSDocs in index.js.

@amyleadem
Copy link
Contributor Author

@mahoneycm @mejiaj @heymatthenry @thisisdano

I just tagged you all for review on this PR. There is a lot here, so I'm proposing that before we dive into review of the structure of the .js and .css files, it would be good to first get feedback on the light DOM structure, the customization options, and the visuals and accessibility of the rendered component.

I just don't want us spending time diving too deep into the JS or CSS then decide we want to restructure it all in favor of a different light DOM setup, for example.

Let me know if you have any questions or comments!

@amyleadem amyleadem requested a review from mejiaj August 21, 2024 15:42
Copy link
Collaborator

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

Reviewing based on request for feedback on: structure, customization options, and visuals/accessibility of component.

I used our implementation of Identifier from USWDS-Site as a reference.

Structure

Listed a few ways I tried to create my own Identifier component.

Minimal markup

Note: Leaving out the required links intentionally to see what's generated.

Input

<usa-identifier>
  <div slot="logo">
    <a href="#">
      <img
        src="https://designsystem.digital.gov/img/gsa-logo.svg"
        alt="GSA logo"
      />
    </a>
  </div>
  <p slot="domain">designsystem.digital.gov</p>

  <div slot="agency-primary">
    <a href="#" agency-shortname="GSA">General Services Administration</a>
  </div>
</usa-identifier>

Ouput
The output is pretty good and it looks exactly how I'd expect.

image

Quibble: There's no indication that I'm missing required link URLs.

A working version

Input

<usa-identifier
  urlAbout="https://www.gsa.gov/about-us"
  urlAccessibility="https://www.gsa.gov/website-information/accessibility-statement"
  urlFOIA="https://www.gsa.gov/reference/freedom-of-information-act-foia"
  urlNoFEAR="https://www.gsa.gov/reference/civil-rights-programs/notification-and-federal-employee-antidiscrimination-and-retaliation-act-of-2002"
  urlOIG="https://www.gsaig.gov/"
  urlPerformance="https://www.gsa.gov/reference/reports/budget-performance"
  urlPrivacy="https://www.gsa.gov/website-information/website-policies"
>
  <div slot="logo">
    <a href="#">
      <img
        src="https://designsystem.digital.gov/img/gsa-logo.svg"
        alt="GSA logo"
      />
    </a>
  </div>
  <p slot="domain">designsystem.digital.gov</p>

  <div slot="agency-primary">
    <a href="#" agency-shortname="GSA">General Services Administration</a>
  </div>
</usa-identifier>

Output
Visually, nothing changed — which is good.

image

Customizing strings

Input

Not sure if I did it right, but the visual output looks similar to what I'd expect.

<usa-identifier
  urlAbout="https://www.gsa.gov/about-us"
  urlAccessibility="https://www.gsa.gov/website-information/accessibility-statement"
  urlFOIA="https://www.gsa.gov/reference/freedom-of-information-act-foia"
  urlNoFEAR="https://www.gsa.gov/reference/civil-rights-programs/notification-and-federal-employee-antidiscrimination-and-retaliation-act-of-2002"
  urlOIG="https://www.gsaig.gov/"
  urlPerformance="https://www.gsa.gov/reference/reports/budget-performance"
  urlPrivacy="https://www.gsa.gov/website-information/website-policies"
  textAbout="Sobre vote.gov"
  textAccessibility="Acessibilidade"
  textFOIA="Pedidos de FOIA (em inglês)"
  textPerformance="TK (em inglês)"
  textOIG="TK (em inglês)"
  textPrivacy="Política de privacidade (em inglês)"
>
  <div slot="logo">
    <a href="#">
      <img
        src="https://designsystem.digital.gov/img/gsa-logo.svg"
        alt="GSA logo"
      />
    </a>
  </div>
  <span slot="agency-intro">
    Uma página web oficial da Administração dos Serviços Gerais (em
    inglês)
  </span>
  <p slot="domain">designsystem.digital.gov</p>

  <div slot="agency-primary">
    <a href="#" agency-shortname="GSA">General Services Administration</a>
  </div>

  <!-- ! Docs say anchor, but demo uses div with an anchor. -->
  <!-- <a slot="usagov">Você procura informação e serviços do governo dos EUA? Visite USA.gov (em inglês)</a> -->

  <div slot="usagov">
    Você procura informação e serviços do governo dos EUA? Visite USA.gov
    (em inglês) <a href="https://www.usa.gov/">Visitez USA.gov</a>
  </div>
</usa-identifier>

Output

I had to reference the documentation a lot.

image

My version is missing translated strings for aria labels. I'm not sure how to set those (except for 1st item), but capturing findings below.

Aria label Description
usa-identifier This exists, but I forgot to change — maybe cue for us highlight in guidance.
Agency description In the stable implementation this is set on usa-identifier__identity.
Important links In stable this is set on usa-identifier__section--required-links.

Recommendations

  1. Reduce # of props. This would improve readability. It's also consistent with components from landscape analysis and with patterns in existing component. For example, a single prop to set urlAbout and textAbout or move that to markup.
  2. Allow aria labels to be set on description and important links. This could be on inner identifier markup.
  3. Prototype slots with the same name. This can help simplify the markup because they'll be placed one after the other. The user doesn't have to worry about grouping or setting containers.

Example

This is a rough example for discussion.

Before

      <usa-identifier
        urlAbout="https://www.gsa.gov/about-us"
        urlAccessibility="https://www.gsa.gov/website-information/accessibility-statement"
        urlFOIA="https://www.gsa.gov/reference/freedom-of-information-act-foia"
        urlNoFEAR="https://www.gsa.gov/reference/civil-rights-programs/notification-and-federal-employee-antidiscrimination-and-retaliation-act-of-2002"
        urlOIG="https://www.gsaig.gov/"
        urlPerformance="https://www.gsa.gov/reference/reports/budget-performance"
        urlPrivacy="https://www.gsa.gov/website-information/website-policies"
        textAbout="Sobre vote.gov"
        textAccessibility="Acessibilidade"
        textFOIA="Pedidos de FOIA (em inglês)"
        textPerformance="TK (em inglês)"
        textOIG="TK (em inglês)"
        textPrivacy="Política de privacidade (em inglês)"
      >
        <div slot="logo">
          <a href="#">
            <img
              src="https://designsystem.digital.gov/img/gsa-logo.svg"
              alt="GSA logo"
            />
          </a>
        </div>
        <span slot="agency-intro">
          Uma página web oficial da Administração dos Serviços Gerais (em
          inglês)
        </span>
        <p slot="domain">designsystem.digital.gov</p>

        <div slot="agency-primary">
          <a href="#" agency-shortname="GSA">General Services Administration</a>
        </div>

        <!-- ! Docs say anchor, but demo uses div with an anchor. -->
        <!-- <a slot="usagov">Você procura informação e serviços do governo dos EUA? Visite USA.gov (em inglês)</a> -->

        <div slot="usagov">
          Você procura informação e serviços do governo dos EUA? Visite USA.gov
          (em inglês) <a href="https://www.usa.gov/">Visitez USA.gov</a>
        </div>
      </usa-identifier>

After

<usa-identifier>
  <a href="#" slot="logo">
    <img
      src="https://designsystem.digital.gov/img/gsa-logo.svg"
      alt="GSA logo"
    />
  </a>
  <!-- User would add this markup to customize. -->
  <p slot="agency-disclaimer" aria-label="descrição">
    Uma página web oficial da Administração dos Serviços Gerais (em inglês)
    <a href="">&lt;Parent agency&gt;</a>
  </p>

  <nav class="usa-identifier__section--required-links" aria-label="Importante">
    <a href="#">Sobre GSA<a>
    <a href="#">Acessibilidade</a>
    <a href="#">Pedidos de FOIA (em inglês)</a>
    <a href="#">Performance (em inglês)</a>
    <a href="#">OIG (em inglês)</a>
    <a href="#">Política de privacidade (em inglês)</a>
  </nav>

  <div slot="usagov">
    Você procura informação e serviços do governo dos EUA? Visite USA.gov
    (em inglês) <a href="https://www.usa.gov/">Visitez USA.gov</a>
  </div>
</usa-identifier>

Customization

I was able to successfully override using CSS Custom Properties via usa-identifier selector in devtools.

@amyleadem amyleadem changed the title USWDS-Next: Create usa-identifier web component Web-components: Create usa-identifier web component Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web Component Identifier: Develop Beta 1
2 participants