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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
44495b4
Add identifier component in storybook
amyleadem Jun 17, 2024
299b123
Comment out "an official" wrapper to prevent storybook error
amyleadem Jun 18, 2024
973de11
Use latest vite config to fix SCSS import errors
Jun 19, 2024
e25ca97
Add css preprocessor to vite config
amyleadem Jun 21, 2024
ec9bd87
Merge branch 'al/add-identifier-storybook' of https://github.com/uswd…
amyleadem Jun 21, 2024
26b0497
Create indiv link objects in storybook; rename stories
amyleadem Jun 21, 2024
dfdc3c9
Add starter tests to identifier.spec.js
amyleadem Jun 21, 2024
0603ca8
Update test for logos
amyleadem Jun 21, 2024
b2264c8
Add lang data and control; add default usagov
amyleadem Jun 25, 2024
5fd129e
Add custom content usagov; move lang data to json
amyleadem Jun 25, 2024
21c5c23
Create default link; add taxpayer attribute
amyleadem Jun 25, 2024
0ae101e
Consolidate aria-labels; rename controls
amyleadem Jun 26, 2024
5187659
Use map for required links
amyleadem Jun 28, 2024
3e35676
Use kebab case for slot names
amyleadem Jun 28, 2024
701aea8
Add default content in masthead
amyleadem Jun 28, 2024
5870445
Update taxpayer prop name
amyleadem Jun 28, 2024
36aebe9
Merge branch 'develop' of https://github.com/uswds/uswds-next into al…
amyleadem Jul 3, 2024
11146d5
Clean up code
amyleadem Jul 3, 2024
2300129
Add styles for second logo
amyleadem Jul 3, 2024
972e137
Replace aria-label prop with label
amyleadem Jul 5, 2024
3295148
Add custom docs
amyleadem Jul 16, 2024
20f6be0
Install remark-gfm
amyleadem Jul 16, 2024
a29a5fc
Add font-face for source sans
amyleadem Jul 17, 2024
311c8b4
Add system and theme css vars files
amyleadem Jul 17, 2024
aea6026
Add css custom props; format css
amyleadem Jul 17, 2024
a4be4bc
Merge branch 'develop' of https://github.com/uswds/uswds-next into al…
amyleadem Jul 31, 2024
ff13947
Add missing spacing units
amyleadem Jul 31, 2024
00cc022
Translate french data; remove unused json import
amyleadem Jul 31, 2024
1cb07c6
Remove masthead and nav wrappers
amyleadem Aug 1, 2024
8a3afcb
Include target attribute
amyleadem Aug 1, 2024
87287be
Run prettier
amyleadem Aug 1, 2024
95e034c
Add info to identifier README
amyleadem Aug 2, 2024
926b3ae
Move installation below implementation example
amyleadem Aug 2, 2024
c61b751
Add css parts to elements
amyleadem Aug 2, 2024
cfe4d5a
Change usagov element from div to p
amyleadem Aug 2, 2024
dec6453
Remove nav and disclaimer aria labels
amyleadem Aug 7, 2024
bcc13b1
Update identifier docs
amyleadem Aug 7, 2024
ccfc05f
Replace aria_labels -> aria_label
amyleadem Aug 7, 2024
4a731f9
Add slots table to readme
amyleadem Aug 7, 2024
83c1d62
More updates to implement single aria-label
amyleadem Aug 7, 2024
026ea11
Move slots table and update table headers
amyleadem Aug 8, 2024
8c4b5df
Rebuild required link list to use native element
amyleadem Aug 8, 2024
d820043
Alphabetize table data
amyleadem Aug 8, 2024
676561d
Update JSdocs
amyleadem Aug 8, 2024
6a94ffc
Replace req'd link slots with usa-link
amyleadem Aug 12, 2024
f20b3b8
Replace logo slots with usa-link
amyleadem Aug 12, 2024
bc8e74a
Merge branch 'develop' of https://github.com/uswds/uswds-next into al…
amyleadem Aug 13, 2024
622c0f9
Run prettier
amyleadem Aug 13, 2024
7e1f4a7
Remove identifier.spec.js
amyleadem Aug 13, 2024
a4c3508
Use props for req'd links urls; remove custom translation story (for …
amyleadem Aug 14, 2024
a72ef76
Add custom link text props; fix taxpayer_custom control
amyleadem Aug 14, 2024
7c43d59
Clean up storybook controls and jsdocs
amyleadem Aug 14, 2024
2096376
Remove usa-link import
amyleadem Aug 14, 2024
89d281e
Run prettier
amyleadem Aug 14, 2024
1d023af
Alphabetize props in docs
amyleadem Aug 14, 2024
c7a2ade
Add explicit color styles for disclaimer and usagov
amyleadem Aug 16, 2024
79f63e5
Merge branch 'develop' of https://github.com/uswds/uswds-next into al…
amyleadem Aug 16, 2024
61a01d9
Add --usa-theme-identifier-text-color & set to white
amyleadem Aug 20, 2024
f64f2ee
Run prettier
amyleadem Aug 20, 2024
0c5dc99
Run prettier
amyleadem Aug 20, 2024
37ba970
Merge branch 'develop' of https://github.com/uswds/uswds-next into al…
amyleadem Aug 20, 2024
089fe47
Add CSS var controls; rename text color vars
amyleadem Aug 20, 2024
5876e4b
Add basic unit tests
amyleadem Aug 20, 2024
8c67e36
Run prettier
amyleadem Aug 20, 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
164 changes: 164 additions & 0 deletions web-components/src/components/usa-identifier/identifier.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import "./index";
import { html } from "lit";

export default {
title: "Components/Identifier",
component: "usa-identifier",
argTypes: {
primary_agency: { name: "Primary agency information" },
logo1: { control: "text", name: "Primary agency logo" },
secondary_agency: { name: "Secondary agency information" },
logo2: { control: "text", name: "Secondary agency logo" },
masthead: { name: "Masthead content" },
taxpayer: { name: "Taxpayer disclaimer" },
required_links: { name: "Required links" },
usagov: { name: "USA.gov information" },
main_aria_label: { name: "Component aria-label" },
},
args: {
main_aria_label: "Agency identifier",
primary_agency: {
name: "[Parent agency]",
shortname: "[Agency shortname]",
url: "javascipt:void(0)",
},
logo1: "https://designsystem.digital.gov/assets/img/circle-gray-20.svg",
secondary_agency: {
name: "[Other agency]",
url: "javascipt:void(0)",
},
logo2: "https://designsystem.digital.gov/assets/img/circle-gray-20.svg",
masthead: {
aria_label: "Agency description",
conjunction: "and",
domain: "[domain.gov]",
disclaimer: "An official website of the",
},
taxpayer: "Produced and published at taxpayer expense.",
required_links: {
aria_label: "Important links",
about: "About",
accessibility: "Accessibility statement",
foia: "FOIA requests",
no_FEAR: "No FEAR Act data",
oig: "Office of the Inspector General",
performance: "Performance reports",
privacy: "Privacy policy",
},
usagov: {
text: "Looking for U.S. government information and services?",
link_label: "Visit USA.gov",
link_url: "https://www.usa.gov/",
},
},
render: ({
primary_agency,
secondary_agency,
logo1,
logo2,
masthead,
taxpayer,
required_links,
usagov,
main_aria_label,
}) => html`
<usa-identifier aria-label="${main_aria_label}">
${logo1 ? html`
<a slot="logo" href="${primary_agency.url}">
<img src="${logo1}" alt="${primary_agency.name} logo" />
</a>`: null}
Copy link

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>

${logo2 ? html`
<a slot="logo" href="${secondary_agency.url}">
<img src="${logo2}" alt="${secondary_agency.name} logo" />
</a>`: null}
<p slot="disclaimer" aria-label="${masthead.aria_label}">
${masthead.disclaimer}
<a href="${primary_agency.url}">${primary_agency.name}</a>
${secondary_agency ? html`${masthead.conjunction} <a href="${secondary_agency.url}">${secondary_agency.name}</a>`: null}${taxpayer ? html`.
${taxpayer}` : null}
</p>
<nav slot="links" aria-label="${required_links.aria_label}">
<a href="">${required_links.about} ${primary_agency.shortname}</a>
<a href="">${required_links.accessibility}</a>
<a href="">${required_links.foia}</a>
<a href="">${required_links.no_FEAR}</a>
<a href="">${required_links.oig}</a>
<a href="">${required_links.performance}</a>
<a href="">${required_links.privacy}</a>
</nav>
<div slot="usagov">
${usagov.text} <a href="${usagov.link_url}">${usagov.link_label}</a>
</div>
</usa-identifier>
`,
};

export const Default = {};

export const DefaultSpanish = {
args: {
main_aria_label: "Identificador de la agencia",
masthead: {
aria_label: "Descripción de la agencia",
conjunction: "y",
domain: "[domain.gov]",
disclaimer: "Un sitio web oficial de",
},
taxpayer:
"Producido y publicado con dinero de los contribuyentes de impuestos.",
required_links: {
aria_label: "Enlaces importantes",
about: "Acerca de",
accessibility: "Declaración de accesibilidad",
foia: "Solicitud a través de FOIA",
no_FEAR: "Datos de la ley No FEAR",
oig: "Oficina del Inspector General",
performance: "Informes de desempeño",
privacy: "Política de privacidad",
},
usagov: {
text: "¿Necesita información y servicios del Gobierno?",
link_label: "Visite USA.gov en Español",
link_url: "https://www.usa.gov/espanol/",
},
},
};

export const oneAgency = {
args: {
logo2: false,
secondary_agency: false,
taxpayer: false,
},
argTypes: {
logo2: { table: { disable: true } },
secondary_agency: { table: { disable: true } },
taxpayer: { table: { disable: true } },
},
};

export const MultipleAgencies = {
args: {
taxpayer: false,
},
argTypes: {
taxpayer: { table: { disable: true } },
},
};

export const NoLogo = {
args: {
logo1: false,
logo2: false,
secondary_agency: false,
taxpayer: false,
},
argTypes: {
logo1: { table: { disable: true } },
logo2: { table: { disable: true } },
secondary_agency: { table: { disable: true } },
taxpayer: { table: { disable: true } },
},
};

export const TaxpayerDisclaimer = {};
156 changes: 156 additions & 0 deletions web-components/src/components/usa-identifier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { LitElement, html, css, unsafeCSS } from "lit";
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

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.

static styles = [
unsafeCSS(usaIdentifierStyle),
unsafeCSS(uswdsCoreStyle),
css`
.usa-identifier__usagov-description {
display: block;
}
`,
];

connectedCallback() {
super.connectedCallback();
this.domain = this.querySelector('[slot="domain"]');
this.logos = [...this.querySelectorAll('[slot="logo"]')];
this.links = [...this.querySelector('[slot="links"]').children];
this.domain = this.querySelector('[slot="domain"]');
this.disclaimer = this.querySelector('[slot="disclaimer"]');
this.usagov = this.querySelector('[slot="usagov"]');
}

// Render the logo(s) for the masthead
mastheadLogosTemplate() {
if (this.logos.length > 0) {
return html`
<div class="usa-identifier__logos">
${this.logos.map((logo) => {
const logoImage = logo.querySelector("img");
logo.classList.add("usa-identifier__logo");
logoImage.classList.add("usa-identifier__logo-img");
return html`${logo}`;
})}
</div>
`;
}
}

// Render the text for the masthead
mastheadTextTemplate() {
/**
* Scaffold domain text:
* Add necessary classes for styling
*/
if (this.domain) {
this.domain.classList.add("usa-identifier__identity-domain");
}
/**
* Scaffold disclaimer text:
* Add necessary classes for styling
* Wrap "An" in aria-hidden span
*/
if (this.disclaimer) {
this.disclaimer.classList.add("usa-identifier__identity-disclaimer");
}
/**
* For English implementations, wrap "An" in an aria-hidden span
* This prevents "An official" from sounding like "Unofficial" in audible readouts
*/
if (this.disclaimer.innerHTML.includes("An official")) {
this.disclaimer.innerHTML = this.disclaimer.innerHTML.replace(
"An official",
'<span aria-hidden="true">An</span> official'
);
}

if (this.disclaimer || this.domain) {
return html`
<section
class="usa-identifier__identity"
aria-label="Agency description"
>
${this.domain} ${this.disclaimer}
</section>
`;
}
}

// Render the logos and text in the masthead
mastheadTemplate() {
if (this.domain || this.disclaimer || this.logos.length > 0) {
return html`
<section
class="usa-identifier__section usa-identifier__section--masthead"
aria-label="Agency identifier"
>
<div class="usa-identifier__container">
${this.mastheadLogosTemplate()} ${this.mastheadTextTemplate()}
</div>
</section>
`;
}
}

// Render the list of links
linksTemplate() {
if (this.links && this.links.length > 0) {
return html`
<nav
class="usa-identifier__section usa-identifier__section--required-links"
aria-label="Important links"
>
<div class="usa-identifier__container">
<div class="usa-identifier__logos">
<ul class="usa-identifier__required-links-list">
${this.links.map((link) => {
link.classList.add("usa-identifier__required-link");
return html`<li class="usa-identifier__required-links-item">
${link}
</li>`;
})}
</ul>
</div>
</div>
</nav>
`;
}
}

// Render the footer USA.gov text
usagovTemplate() {
/**
* Scaffold usagov text:
* Add necessary classes for styling
*/
if (this.usagov) {
const usagovLink = this.usagov.querySelector("a");
this.usagov.classList.add("usa-identifier__usagov-description");
usagovLink.classList.add("usa-link");

return html`
<section
class="usa-identifier__section usa-identifier__section--usagov"
>
<div class="usa-identifier__container">
<div class="usa-identifier__usagov-description">${this.usagov}</div>
</div>
</section>
`;
}
}

render() {
return html`
<div class="usa-identifier">
${this.mastheadTemplate()} ${this.linksTemplate()}
${this.usagovTemplate()}
</div>
`;
}
}

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