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

Create .gov banner component #279

Open
maxatdetroit opened this issue Jan 8, 2025 · 2 comments
Open

Create .gov banner component #279

maxatdetroit opened this issue Jan 8, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@maxatdetroit
Copy link
Member

.gov Banner Component

The goal of this task is to create a new .gov banner component in the stable build of the design system.

Mockups

The full mockups can be viewed in Figma: https://www.figma.com/design/1eNREu4goozzabiuUhXvpS/detroitmi.gov-redesign?node-id=35-2393&t=FgpYMyZiFD6ry3yt-1

Mobile

Image

Desktop

Image

Functionality

When someone clicks the down chevron, the banner should expand and show the following content:

Image

Requirements

@maxatdetroit maxatdetroit added the enhancement New feature or request label Jan 8, 2025
@sreidthomas
Copy link
Contributor

@maxatdetroit
Image

How am I supposed to add the stylesheets?

@maxatdetroit
Copy link
Member Author

maxatdetroit commented Jan 9, 2025

@sreidthomas , you can use the template literal approach in your screenshot or you can use the DOM manipulation approach like the existing experimental components:

import styles from '!!raw-loader!./AccordionBody.css';
import varStyles from '!!raw-loader!../../../../shared/variables.css';
import bootstrapStyles from '!!raw-loader!../../../../shared/themed-bootstrap.css';

const template = document.createElement('template');

template.innerHTML = `
<div></div>
`;

export default class AccordionBody extends HTMLElement {
  constructor() {
    // Always call super first in constructor
    super();
    // Create a shadow root
    const shadow = this.attachShadow({ mode: 'open' });
    shadow.appendChild(template.content.cloneNode(true));
    ...

    // Add styles
    const bootStyles = document.createElement('style');
    bootStyles.textContent = bootstrapStyles;
    const variableStyles = document.createElement('style');
    variableStyles.textContent = varStyles;
    const itemStyles = document.createElement('style');
    itemStyles.textContent = styles;
    shadow.appendChild(bootStyles);
    shadow.appendChild(variableStyles);
    shadow.appendChild(itemStyles);
  }

It's up to you. The outcome is the same and the performance difference is likely negligible. Whatever you decide, just be consistent with future components and I'll follow your lead. I like your template literal approach because it saves some lines of code and is more read-able in my opinion.

You can read #171 for an idea of what we'll want to do further down the road that may have a big impact on performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants