-
Notifications
You must be signed in to change notification settings - Fork 5
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 - Web components: Beta 2 banner additions #65
Conversation
Following pattern from uswds/uswds#5829.
Following plugin guidance[^1] to avoid ESLint errors in unit tests [^1]: https://github.com/vitest-dev/eslint-plugin-vitest
Improve defaults, disable unused controls, and improve content.
…a-banner-component
package.json
Outdated
@@ -57,8 +58,9 @@ | |||
"@storybook/theming": "^8.2.9", | |||
"@storybook/web-components": "^8.2.9", | |||
"@storybook/web-components-vite": "^8.2.9", | |||
"@vitest/eslint-plugin": "^1.1.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked into this while doing some POAM for this repo. Good addition 👍
@@ -4,58 +4,59 @@ import { html, nothing } from "lit"; | |||
|
|||
import { userEvent, expect, waitFor } from "@storybook/test"; | |||
import { within } from "shadow-dom-testing-library"; | |||
import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Helps render custom slotted content in HTTPS body because it includes HTML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: Ideally we'll be able to do something else here at some point 🤔
src/core/colors.css
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Will look into @property
now that it has baseline support.
<ColorPalette> | ||
<ColorItem | ||
title="Base" | ||
subtitle="Grayscale colors" | ||
colors={{ | ||
White: "#FFFFFF", | ||
"Longer custom text": "#F3F3F3", | ||
Black: "#000", | ||
"--usa-base-lightest": "#F0F0F0", | ||
}} | ||
/> | ||
</ColorPalette> | ||
|
||
## Global | ||
|
||
<ColorPalette> | ||
<ColorItem | ||
title="Link" | ||
subtitle="Link colors" | ||
colors={{ | ||
"--usa-theme-link-color": "#005EA2", | ||
"--usa-theme-link-hover-color": "#1A4480", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Starting to document the shared properties here.
|
||
- Variants | ||
- Properties | ||
- CSS Custom Properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
We'll need to remove this if we continue with custom elements manifest.
* @summary The usa-banner component. | ||
* | ||
* @attribute {string} lang - The element's language. | ||
* @attribute {string} label - The custom aria label users can override. | ||
* @attribute {string} tld - The top level domain for the site. | ||
* | ||
* @cssprop --theme-banner-background-color - Sets banner background color. | ||
* @cssprop --theme-banner-font-family - Sets banner font family. | ||
* @cssprop --theme-banner-link-color - Sets the default link color. | ||
* @cssprop --theme-banner-link-hover-color - Sets the default link color. | ||
* | ||
* @slot banner-text - The text for official government website text. | ||
* @slot banner-action - Action text label "Here's how you know." | ||
* @slot domain-heading - Heading text for the domain section. | ||
* @slot domain-text - Body text for domain section. | ||
* @slot https-heading - Heading for HTTPs section. | ||
* @slot https-text - Body text for HTTPs section. | ||
* | ||
* @tagname usa-banner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…a-banner-component
…a-banner-component
Unfortunately, we're still hitting that issue in dev mode and it seems to be a Lit problem. From a Lit dev in their discord:
This tracks with my own troubleshooting since, if you add the banner via a CDN like esm.sh, such that you're getting the production build, it works with a server in dev mode. SInce Vite 6's environments API now gives library authors finer-grained controls over environment settings, maybe there's something we can use there? |
Useful for testing in other environments without having to run build on every change.
"build": "npm run clean && vite build && npm run manifest:build", | ||
"clean": "node ./scripts/rmrf.js dist", | ||
"build": "vite build && npm run manifest:build", | ||
"build:watch": "vite build --watch", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Added for local development and testing. For example, when using npm link
to test in Sandbox environment. You can run this without having to manually build every update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Nice. Thanks. I'd been doing this by hand a lot when npm link
ing
@heymatthenry I've done the the following:
|
min-width: 320px; | ||
min-height: 100vh; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
font-weight: 700; | ||
src: url("@uswds/uswds/fonts/public-sans/PublicSans-BoldItalic.woff2") | ||
format("woff2"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: These will all need to be in their own package sooner rather than later (but not today)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this! Especially on de-Sass-ifying things!
Summary
Improvements to Banner. Added JSDocs and component is now configurable via CSS custom properties.
Related issue
Closes #39.
Preview link
Preview link:
Banner preview →
Problem statement
Banner was missing:
Additionally, the HTTPS lock icon was using unsafe SVG.
Solution
Added all the items above and swapped the SVG icon for a background image.
Major changes
Global CSS properties
Shared global properties created in a new
core
directory. They contain global token values and theme settings. They're meant to be attached at:root
level and leaves:host
for component-level settings.Core stylesheets also added as an export in
package.json
.Example
Component properties
Caution
Missing the theme setting
theme-banner-max-width
because media queries don't allow custom props as a value. Potential solutions: SASS, PostCSS custom media queries, or Lightning CSS each requires additional dependencies for everyone.--usa-base-lightest
#f0f0f0
--usa-font-ui
system-ui, sans-serif
--theme-link-color
#005ea2
--theme-link-hover-color
#1a4480
Link settings and names match those defined in USA Link component.
Lock icon replaced
The icon is added via CSS on a class. This allows users to not worry about pasting in a big block of SVG markup. Especially useful when adding custom content via slots.
Following pattern set by @aduth in uswds/uswds#5829.
Testing and review
Dependency updates
2.0.22.0.35.4.35.4.8