NCIOCPL / ncids

NCI Design System
10 stars 5 forks source link

Make NCIDS usa-site-alert to be USWDS html #1572

Closed bryanpizzillo closed 5 months ago

bryanpizzillo commented 8 months ago

Issue description

ESTIMATE TBD

Site Alert came before we were patching. We should update site alert to match USWDS HTML.

The main changes:

Tasks

Documentation site

ncids-css

[!WARNING]
All breaking changes above should be backwards compatible for now. Deprecate the old classes with a note they will be removed in 3.0. That means the patch should contain the "bad" classes extending the good classes.

ncids-twig

ncids-js

ncids-js documentation

Storybook

Example js site

Expand/Collapse Content Examples

Just text

<div class="usa-alert__body">
  <span class="usa-alert__heading">Emergency alert message</span>
  <p class="usa-alert__text">
    Additional context and followup information including
    <a class="usa-link" href="javascript:void(0);">a link</a>.
  </p>
</div>

becomes

<div class="usa-alert__body">
  <div class="usa-alert__nci-header">
    <span class="usa-alert__heading">Emergency alert message</span>
  </div>
  <div class="usa-alert__nci-content">
    <p class="usa-alert__text">
      Additional context and followup information including
      <a class="usa-link" href="javascript:void(0);">a link</a>.
    </p>
  </div>
</div>

Just a list

<div class="usa-alert__body">
    <span class="usa-alert__heading">Emergency alert message</span>
    <ul class="usa-list">
      <li>
        The primary emergency message and
        <a class="usa-link" href="javascript:void(0);">a link</a> for
        supporting context.
      </li>
      <li>
        Another message,
        <a class="usa-link" href="javascript:void(0);">and another link</a>.
      </li>
      <li>A final emergency message.</li>
    </ul>
</div>

becomes

<div class="usa-alert__body">
  <div class="usa-alert__nci-header">
    <span class="usa-alert__heading">Emergency alert message</span>
  </div>
  <div class="usa-alert__nci-content">  
    <ul class="usa-list">
      <li>
        The primary emergency message and
        <a class="usa-link" href="javascript:void(0);">a link</a> for
        supporting context.
      </li>
      <li>
        Another message,
        <a class="usa-link" href="javascript:void(0);">and another link</a>.
      </li>
      <li>A final emergency message.</li>
    </ul>
  </div>
</div>

Multi-things

<div class="usa-alert__body">
  <span class="usa-alert__heading">Emergency alert message</span>
  <p class="usa-alert__text">
    Additional context and followup information including
    <a class="usa-link" href="javascript:void(0);">a link</a>.
  </p>
  <ul class="usa-list">
    <li>
      The primary emergency message and
      <a class="usa-link" href="javascript:void(0);">a link</a> for
      supporting context.
    </li>
    <li>
      Another message,
      <a class="usa-link" href="javascript:void(0);">and another link</a>.
    </li>
    <li>A final emergency message.</li>
  </ul>
  <p class="usa-alert__text">
    Additional context and followup information including
    <a class="usa-link" href="javascript:void(0);">a link</a>.
  </p>
</div>

becomes

<div class="usa-alert__body">
  <div class="usa-alert__nci-header">
    <span class="usa-alert__heading">Emergency alert message</span>
  </div>
  <div class="usa-alert__nci-content">
    <p class="usa-alert__text">
      Additional context and followup information including
      <a class="usa-link" href="javascript:void(0);">a link</a>.
    </p>
    <ul class="usa-list">
      <li>
        The primary emergency message and
        <a class="usa-link" href="javascript:void(0);">a link</a> for
        supporting context.
      </li>
      <li>
        Another message,
        <a class="usa-link" href="javascript:void(0);">and another link</a>.
      </li>
      <li>A final emergency message.</li>
    </ul>
    <p class="usa-alert__text">
      Additional context and followup information including
      <a class="usa-link" href="javascript:void(0);">a link</a>.
    </p>
  </div>
</div>
olitharp-nci commented 8 months ago

slim

{
        "aria_label": "Slim site alert info example",
        "variant": "slim",
        "modifier": "info",
        "content": "<strong>Short alert message.</strong> Additional context and followup information including <a class=\"usa-link\" href=\"javascript:void(0);\">a link</a>."
}

default for a list

{
    "heading": "COVID-19 resources.",
    "aria_label": "Standard site alert example Code",
    "variant": "default",
    "modifier": "info",
    "content": [
        {
            "type": "text",
            "contents": "My text here (to go in a <p class=usa-site-alert__text>"
        },
        {
            "type": "list",
            "contents": [
                {
                    "type": "link",
                    "data": {
                        "href": "#",
                        "text": "What people with cancer should know"
                    },
                    "type": "text",
                    "data": "This is some text for the template"
                }
            ]
        }
    ]
}

twig template

{% macro defaultContent(content) %}
    <div class="usa-alert__nci-content">
        <ul class="usa-alert__nci-list">
            <li>
                <a class="usa-link" href="#!">
                    What people with cancer should know
                </a>
            </li>
            <li>
                <a class="usa-link" href="#!">
                    Get the latest public health information from CDC
                </a>
            </li>
            <li>
                <a class="usa-link" href="#!"> Guidance for cancer researchers </a>
            </li>
            <li>
                <a class="usa-link" href="#!">
                    Get the latest research information from NIH
                </a>
            </li>
        </ul>
    </div>
{% endmacro %}

{% macro slimContent(content) %}
    <div class="usa-alert__text">
        {{ content }}
    </div>
{% endmacro %}

{# Setup the class list. TwigJS does not have html_classes. #}
{% set classList = "usa-site-alert" %}

{% if variant == "slim" }
    {% set classList = classList + "usa-site-alert--nci-slim" %}
{% else %}
    {% set classList = classList + "usa-site-alert--nci-standard" %}
{% endif %}

{# The modifier should be 'info' or 'emergency' #}
{% if modifier }
    {% set classList = classList + "usa-site-alert--nci-" + modifier %}
{% endif %}

<section
  aria-label="{{aria_label}}"
  class="usa-site-alert usa-site-alert--nci-standard usa-site-alert--nci-info"
>
  <div class="usa-alert">
    <div class="usa-alert__body">
            {% if variant == "default" and heading %}
                <div class="usa-alert__nci-header">
                    <h3 class="usa-alert__heading">{{ heading }}</h3>
                </div>
            {% endif %}
            {% if variant == "default" %}
                {{ _self.defaultContent(content) }}
            {% elseif variant == "slim" %}
                {{ _self.slimContent(content) }}
            {% else %}
                <strong>UNKNOWN VARIANT</strong>
            {% endif %}

    </div>
  </div>
</section>