@solexllc/usx-react 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +156 -5
  2. package/dist/index.cjs +181 -182
  3. package/dist/index.js +181 -182
  4. package/package.json +6 -5
  5. package/src/assets.ts +16 -0
  6. package/src/components/alert/Alert.tsx +4 -3
  7. package/src/components/alert/alert.django.html +2 -3
  8. package/src/components/alert/config.json +15 -4
  9. package/src/components/banner/Banner.tsx +8 -6
  10. package/src/components/banner/banner.django.html +4 -5
  11. package/src/components/banner/config.json +5 -1
  12. package/src/components/button/Button.tsx +1 -1
  13. package/src/components/button/button.django.html +2 -2
  14. package/src/components/button/config.json +14 -6
  15. package/src/components/code/Code.tsx +4 -27
  16. package/src/components/code/code.django.html +3 -9
  17. package/src/components/code/config.json +4 -0
  18. package/src/components/copy-to-clipboard/CopyToClipboard.tsx +35 -24
  19. package/src/components/copy-to-clipboard/config.json +14 -7
  20. package/src/components/copy-to-clipboard/copy-to-clipboard.django.html +14 -14
  21. package/src/components/footer/Footer.tsx +26 -6
  22. package/src/components/footer/config.json +4 -0
  23. package/src/components/footer/footer.django.html +10 -9
  24. package/src/components/header/Branding.tsx +9 -6
  25. package/src/components/header/Header.tsx +3 -1
  26. package/src/components/header/config.json +4 -0
  27. package/src/components/header/header.django.html +5 -26
  28. package/src/components/header/header.html +10 -10
  29. package/src/components/icon/Icon.tsx +6 -3
  30. package/src/components/icon/config.json +12 -6
  31. package/src/components/icon/icon.django.html +6 -4
  32. package/src/components/image/Image.tsx +8 -4
  33. package/src/components/image/config.json +10 -2
  34. package/src/components/image/image.django.html +8 -6
  35. package/src/components/layout/config.json +9 -9
  36. package/src/components/layout/layout.django.html +1 -1
  37. package/src/components/spinner/Spinner.tsx +18 -25
  38. package/src/components/spinner/config.json +4 -0
  39. package/src/components/spinner/spinner.django.html +4 -6
  40. package/src/components/tooltip/Tooltip.tsx +4 -2
  41. package/src/components/tooltip/config.json +7 -2
  42. package/src/components/tooltip/tooltip.django.html +1 -1
  43. package/src/styles/core.scss +1 -2
@@ -145,6 +145,7 @@
145
145
  </div>{# /primary-section #}
146
146
 
147
147
  {# ── Secondary section ──────────────────────────────────────── #}
148
+ {% firstof branding.alt branding.title '' as brandingLabel %}
148
149
  {% if branding or socialLinks or contactHeading or contactPhone or contactEmail or contactLinks %}
149
150
  <div class="usa-footer__secondary-section">
150
151
  <div class="grid-container">
@@ -155,16 +156,16 @@
155
156
  <div class="usa-logo usx-logo usa-footer__logo grid-row grid-gap-2 usx-footer__logo">
156
157
  {% if branding.logo %}
157
158
  {% if brandingUrl %}<a href="{{ brandingUrl }}" class="usx-image usx-logo__image">{% else %}<div class="usx-image usx-logo__image">{% endif %}
158
- {% image src=branding.logo alt=branding.alt|default:branding.title|default:'' className='usx-logo__variant' %}{% endimage %}
159
- {% if branding.logoInverse %}{% image src=branding.logoInverse alt=branding.alt|default:branding.title|default:'' className='usx-logo__variant usx-logo__variant--inverse' %}{% endimage %}{% endif %}
159
+ {% image src=branding.logo alt=brandingLabel staticBaseUrl=staticBaseUrl className='usx-logo__variant' %}{% endimage %}
160
+ {% if branding.logoInverse %}{% image src=branding.logoInverse alt=brandingLabel staticBaseUrl=staticBaseUrl className='usx-logo__variant usx-logo__variant--inverse' %}{% endimage %}{% endif %}
160
161
  {% if brandingUrl %}</a>{% else %}</div>{% endif %}
161
162
  {% else %}
162
163
  <em class="usa-logo__text">
163
164
  {% if branding.symbol %}
164
- <img src="{{ branding.symbol }}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant" />
165
+ <img src="{% asset_url branding.symbol staticBaseUrl %}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant" />
165
166
  {% endif %}
166
167
  {% if branding.symbolInverse %}
167
- <img src="{{ branding.symbolInverse }}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse" />
168
+ <img src="{% asset_url branding.symbolInverse staticBaseUrl %}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse" />
168
169
  {% endif %}
169
170
  {% if branding.title %}
170
171
  {% if brandingUrl %}<a href="{{ brandingUrl }}" class="usx-logo__title">{{ branding.title }}</a>
@@ -182,16 +183,16 @@
182
183
  <div class="usa-logo usx-logo usa-footer__logo grid-row mobile-lg:grid-col-6 mobile-lg:grid-gap-2 usx-footer__logo">
183
184
  {% if branding.logo %}
184
185
  {% if brandingUrl %}<a href="{{ brandingUrl }}" class="usx-image usx-logo__image">{% else %}<div class="usx-image usx-logo__image">{% endif %}
185
- {% image src=branding.logo alt=branding.alt|default:branding.title|default:'' className='usx-logo__variant' %}{% endimage %}
186
- {% if branding.logoInverse %}{% image src=branding.logoInverse alt=branding.alt|default:branding.title|default:'' className='usx-logo__variant usx-logo__variant--inverse' %}{% endimage %}{% endif %}
186
+ {% image src=branding.logo alt=brandingLabel staticBaseUrl=staticBaseUrl className='usx-logo__variant' %}{% endimage %}
187
+ {% if branding.logoInverse %}{% image src=branding.logoInverse alt=brandingLabel staticBaseUrl=staticBaseUrl className='usx-logo__variant usx-logo__variant--inverse' %}{% endimage %}{% endif %}
187
188
  {% if brandingUrl %}</a>{% else %}</div>{% endif %}
188
189
  {% else %}
189
190
  <em class="usa-logo__text">
190
191
  {% if branding.symbol %}
191
- <img src="{{ branding.symbol }}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant" />
192
+ <img src="{% asset_url branding.symbol staticBaseUrl %}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant" />
192
193
  {% endif %}
193
194
  {% if branding.symbolInverse %}
194
- <img src="{{ branding.symbolInverse }}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse" />
195
+ <img src="{% asset_url branding.symbolInverse staticBaseUrl %}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse" />
195
196
  {% endif %}
196
197
  {% if branding.title %}
197
198
  {% if brandingUrl %}<a href="{{ brandingUrl }}" class="usx-logo__title">{{ branding.title }}</a>
@@ -209,7 +210,7 @@
209
210
  {% for social in socialLinks %}
210
211
  <div class="grid-col-auto">
211
212
  <a class="usa-social-link" href="{{ social.href }}"{% if social.alt %} aria-label="{{ social.alt }}"{% endif %}>
212
- <img class="usa-social-link__icon" src="{{ social.icon }}" alt="{{ social.alt|default:'' }}" />
213
+ <img class="usa-social-link__icon" src="{% asset_url social.icon staticBaseUrl %}" alt="{{ social.alt|default:'' }}" />
213
214
  </a>
214
215
  </div>
215
216
  {% endfor %}
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import Image from '../image/Image';
3
3
  import ClassNames from 'classnames';
4
+ import { getAssetUrl } from '../../assets';
4
5
 
5
6
  export interface BrandingLogoSource {
6
7
  srcSet: string;
@@ -26,10 +27,11 @@ export interface BrandingConfig {
26
27
  export interface BrandingProps extends React.HTMLAttributes<HTMLDivElement> {
27
28
  branding: BrandingConfig;
28
29
  projectUrl?: string;
30
+ staticBaseUrl?: string;
29
31
  className?: string;
30
32
  }
31
33
 
32
- function BrandingContent({ config, projectUrl }: { config: BrandingConfig; projectUrl?: string }) {
34
+ function BrandingContent({ config, projectUrl, staticBaseUrl }: { config: BrandingConfig; projectUrl?: string; staticBaseUrl?: string }) {
33
35
  const { title, symbol, symbolInverse, logo, logoInverse, alt } = config;
34
36
  const label = alt ?? title ?? '';
35
37
 
@@ -41,10 +43,11 @@ function BrandingContent({ config, projectUrl }: { config: BrandingConfig; proje
41
43
  {...(projectUrl ? { href: projectUrl } : {})}
42
44
  className="usx-image usx-logo__image"
43
45
  >
44
- <Image src={logo} alt={label} className="usx-logo__variant" />
46
+ <Image src={logo} alt={label} staticBaseUrl={staticBaseUrl} className="usx-logo__variant" />
45
47
  {logoInverse && (
46
48
  <Image
47
49
  src={logoInverse}
50
+ staticBaseUrl={staticBaseUrl}
48
51
  alt={label}
49
52
  className="usx-logo__variant usx-logo__variant--inverse"
50
53
  />
@@ -56,11 +59,11 @@ function BrandingContent({ config, projectUrl }: { config: BrandingConfig; proje
56
59
  return (
57
60
  <em className="usa-logo__text">
58
61
  {symbol && (
59
- <img src={symbol} alt="" aria-hidden="true" className="usx-logo__symbol usx-logo__variant" />
62
+ <img src={getAssetUrl(symbol, staticBaseUrl)} alt="" aria-hidden="true" className="usx-logo__symbol usx-logo__variant" />
60
63
  )}
61
64
  {symbolInverse && (
62
65
  <img
63
- src={symbolInverse}
66
+ src={getAssetUrl(symbolInverse, staticBaseUrl)}
64
67
  alt=""
65
68
  aria-hidden="true"
66
69
  className="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse"
@@ -75,7 +78,7 @@ function BrandingContent({ config, projectUrl }: { config: BrandingConfig; proje
75
78
  );
76
79
  }
77
80
 
78
- export default function Branding({ branding, projectUrl = '/', className = '', ...props }: BrandingProps) {
81
+ export default function Branding({ branding, projectUrl = '/', staticBaseUrl, className = '', ...props }: BrandingProps) {
79
82
  if (!branding) return null;
80
83
 
81
84
  const classes = ClassNames(
@@ -86,7 +89,7 @@ export default function Branding({ branding, projectUrl = '/', className = '', .
86
89
 
87
90
  return (
88
91
  <div className={classes} {...props}>
89
- <BrandingContent config={branding} projectUrl={projectUrl} />
92
+ <BrandingContent config={branding} projectUrl={projectUrl} staticBaseUrl={staticBaseUrl} />
90
93
  </div>
91
94
  );
92
95
  }
@@ -160,6 +160,7 @@ function PrimaryNav({
160
160
  export interface HeaderProps extends React.HTMLAttributes<HTMLElement> {
161
161
  id?: string;
162
162
  branding: BrandingProps;
163
+ staticBaseUrl?: string;
163
164
  projectUrl?: string;
164
165
  navSections?: HeaderNavSection[];
165
166
  secondaryLinks?: HeaderNavLink[];
@@ -178,6 +179,7 @@ export interface HeaderProps extends React.HTMLAttributes<HTMLElement> {
178
179
  export default function Header({
179
180
  id = 'header',
180
181
  branding,
182
+ staticBaseUrl,
181
183
  projectUrl = '/',
182
184
  navSections = [],
183
185
  secondaryLinks = [],
@@ -208,7 +210,7 @@ export default function Header({
208
210
 
209
211
  const navbar = (
210
212
  <div className="usa-navbar">
211
- <Branding branding={branding} projectUrl={projectUrl} />
213
+ <Branding branding={branding} projectUrl={projectUrl} staticBaseUrl={staticBaseUrl} />
212
214
  <button type="button" className="usa-menu-btn align-center">
213
215
  {useMenuIcon ? <Icon name="menu" size={3} /> : 'Menu'}
214
216
  </button>
@@ -3,6 +3,10 @@
3
3
  "template": "header/header.django.html",
4
4
  "version": 1,
5
5
  "props": {
6
+ "staticBaseUrl": {
7
+ "type": "string",
8
+ "description": "Optional branding image asset base, overriding window.usxBaseUrl in React or STATIC_URL in Django. Defaults to the global base or /."
9
+ },
6
10
  "id": {
7
11
  "type": "string",
8
12
  "default": "header",
@@ -14,41 +14,20 @@
14
14
  <div class="usa-navbar">
15
15
  <div class="usa-logo usx-logo">
16
16
  {% if branding.logo %}
17
+ {% firstof branding.alt branding.title '' as brandingLabel %}
17
18
  <a href="{{ projectUrl|default:'/' }}" class="usx-image usx-logo__image">
18
- <div class="usx-image usx-logo__variant">
19
- {% if branding.logo.fallback %}
20
- <picture>
21
- {% for source in branding.logo.sources %}
22
- <source srcset="{{ source.srcSet }}"{% if source.media %} media="{{ source.media }}"{% endif %}{% if source.type %} type="{{ source.type }}"{% endif %}{% if source.sizes %} sizes="{{ source.sizes }}"{% endif %} />
23
- {% endfor %}
24
- <img src="{{ branding.logo.fallback }}" alt="{{ branding.title }}" />
25
- </picture>
26
- {% else %}
27
- <img src="{{ branding.logo }}" alt="{{ branding.title }}" />
28
- {% endif %}
29
- </div>
19
+ {% image src=branding.logo alt=brandingLabel staticBaseUrl=staticBaseUrl className='usx-logo__variant' %}{% endimage %}
30
20
  {% if branding.logoInverse %}
31
- <div class="usx-image usx-logo__variant usx-logo__variant--inverse">
32
- {% if branding.logoInverse.fallback %}
33
- <picture>
34
- {% for source in branding.logoInverse.sources %}
35
- <source srcset="{{ source.srcSet }}"{% if source.media %} media="{{ source.media }}"{% endif %}{% if source.type %} type="{{ source.type }}"{% endif %}{% if source.sizes %} sizes="{{ source.sizes }}"{% endif %} />
36
- {% endfor %}
37
- <img src="{{ branding.logoInverse.fallback }}" alt="{{ branding.title }}" />
38
- </picture>
39
- {% else %}
40
- <img src="{{ branding.logoInverse }}" alt="{{ branding.title }}" />
41
- {% endif %}
42
- </div>
21
+ {% image src=branding.logoInverse alt=brandingLabel staticBaseUrl=staticBaseUrl className='usx-logo__variant usx-logo__variant--inverse' %}{% endimage %}
43
22
  {% endif %}
44
23
  </a>
45
24
  {% elif branding.symbol or branding.symbolInverse or branding.title %}
46
25
  <em class="usa-logo__text">
47
26
  {% if branding.symbol %}
48
- <img src="{{ branding.symbol }}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant" />
27
+ <img src="{% asset_url branding.symbol staticBaseUrl %}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant" />
49
28
  {% endif %}
50
29
  {% if branding.symbolInverse %}
51
- <img src="{{ branding.symbolInverse }}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse" />
30
+ <img src="{% asset_url branding.symbolInverse staticBaseUrl %}" alt="" aria-hidden="true" class="usx-logo__symbol usx-logo__variant usx-logo__variant--inverse" />
52
31
  {% endif %}
53
32
  {% if branding.title %}
54
33
  <a href="{{ projectUrl|default:'/' }}" class="usx-logo__title">{{ branding.title }}</a>
@@ -1,6 +1,6 @@
1
1
  <h3 class="site-preview-heading">Basic header</h3>
2
2
  <div class="usa-overlay"></div>
3
- <header class="usa-header usa-header--basic">
3
+ <header class="usa-header usx-header usa-header--basic">
4
4
  <div class="usa-nav-container">
5
5
  <div class="usa-navbar">
6
6
  <div class="usa-logo usx-logo">
@@ -10,7 +10,7 @@
10
10
  </div>
11
11
  <button type="button" class="usa-menu-btn">Menu</button>
12
12
  </div>
13
- <nav aria-label="Primary navigation" class="usa-nav">
13
+ <nav aria-label="Primary navigation" class="usa-nav usx-nav">
14
14
  <button type="button" class="usa-nav__close">
15
15
  <img src="/img/usa-icons/close.svg" role="img" alt="Close" />
16
16
  </button>
@@ -104,7 +104,7 @@
104
104
 
105
105
  <h3 class="site-preview-heading">Basic header with megamenu</h3>
106
106
  <div class="usa-overlay"></div>
107
- <header class="usa-header usa-header--basic usa-header--megamenu">
107
+ <header class="usa-header usx-header usa-header--basic usa-header--megamenu">
108
108
  <div class="usa-nav-container">
109
109
  <div class="usa-navbar">
110
110
  <div class="usa-logo usx-logo">
@@ -114,7 +114,7 @@
114
114
  </div>
115
115
  <button type="button" class="usa-menu-btn">Menu</button>
116
116
  </div>
117
- <nav aria-label="Primary navigation" class="usa-nav">
117
+ <nav aria-label="Primary navigation" class="usa-nav usx-nav">
118
118
  <button type="button" class="usa-nav__close">
119
119
  <img src="/img/usa-icons/close.svg" role="img" alt="Close" />
120
120
  </button>
@@ -295,7 +295,7 @@
295
295
 
296
296
  <h3 class="site-preview-heading">Extended header</h3>
297
297
  <div class="usa-overlay"></div>
298
- <header class="usa-header usa-header--extended">
298
+ <header class="usa-header usx-header usa-header--extended">
299
299
  <div class="usa-navbar">
300
300
  <div class="usa-logo usx-logo">
301
301
  <em class="usa-logo__text"
@@ -304,7 +304,7 @@
304
304
  </div>
305
305
  <button type="button" class="usa-menu-btn">Menu</button>
306
306
  </div>
307
- <nav aria-label="Primary navigation" class="usa-nav">
307
+ <nav aria-label="Primary navigation" class="usa-nav usx-nav">
308
308
  <div class="usa-nav__inner">
309
309
  <button type="button" class="usa-nav__close">
310
310
  <img src="/img/usa-icons/close.svg" role="img" alt="Close" />
@@ -413,7 +413,7 @@
413
413
 
414
414
  <h3 class="site-preview-heading">Basic header with megamenu</h3>
415
415
  <div class="usa-overlay"></div>
416
- <header class="usa-header usa-header--extended">
416
+ <header class="usa-header usx-header usa-header--extended">
417
417
  <div class="usa-navbar">
418
418
  <div class="usa-logo usx-logo">
419
419
  <em class="usa-logo__text"
@@ -422,7 +422,7 @@
422
422
  </div>
423
423
  <button type="button" class="usa-menu-btn">Menu</button>
424
424
  </div>
425
- <nav aria-label="Primary navigation" class="usa-nav">
425
+ <nav aria-label="Primary navigation" class="usa-nav usx-nav">
426
426
  <div class="usa-nav__inner">
427
427
  <button type="button" class="usa-nav__close">
428
428
  <img src="/img/usa-icons/close.svg" role="img" alt="Close" />
@@ -619,7 +619,7 @@
619
619
 
620
620
  <h3 class="site-preview-heading">Colored background w/ Logo</h3>
621
621
  <div class="usa-overlay"></div>
622
- <header class="usa-header usa-header--extended">
622
+ <header class="usa-header usx-header usa-header--extended">
623
623
  <div class="usa-navbar bg-primary-lighter">
624
624
  <div class="usa-logo usx-logo">
625
625
  <a href="/" class="usx-image usx-logo__image">
@@ -628,7 +628,7 @@
628
628
  </div>
629
629
  <button type="button" class="usa-menu-btn">Menu</button>
630
630
  </div>
631
- <nav aria-label="Primary navigation" class="usa-nav">
631
+ <nav aria-label="Primary navigation" class="usa-nav usx-nav">
632
632
  <div class="usa-nav__inner">
633
633
  <button type="button" class="usa-nav__close">
634
634
  <img src="/img/usa-icons/close.svg" role="img" alt="Close" />
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { getAssetUrl as assetUrl } from '../../assets';
2
3
 
3
4
  export interface IconProps extends React.SVGProps<SVGSVGElement> {
4
5
  name: string;
@@ -6,6 +7,7 @@ export interface IconProps extends React.SVGProps<SVGSVGElement> {
6
7
  size?: number;
7
8
  color?: string;
8
9
  alt?: string;
10
+ staticBaseUrl?: string;
9
11
  staticUrlPrefix?: string;
10
12
  className?: string;
11
13
  }
@@ -19,11 +21,12 @@ export default function Icon({
19
21
  size = 2,
20
22
  color,
21
23
  alt = name + ' icon',
22
- staticUrlPrefix = ((typeof window !== 'undefined' && (window as unknown as { usxBaseUrl?: string }).usxBaseUrl) || '/') +
23
- 'img/' + (source === 'usx' ? 'usx-sprite.svg' : 'sprite.svg') + '#',
24
+ staticBaseUrl,
25
+ staticUrlPrefix,
24
26
  className = '',
25
27
  ...props
26
28
  }: IconProps) {
29
+ const spritePrefix = staticUrlPrefix ?? assetUrl(`img/${source === 'usx' ? 'usx-sprite.svg' : 'sprite.svg'}#`, staticBaseUrl);
27
30
  return (
28
31
  <svg
29
32
  className={
@@ -40,7 +43,7 @@ export default function Icon({
40
43
  role="img"
41
44
  {...props}
42
45
  >
43
- <use href={staticUrlPrefix + name} />
46
+ <use href={spritePrefix + name} />
44
47
  </svg>
45
48
  );
46
49
  }
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "icon",
3
3
  "template": "icon/icon.django.html",
4
- "version": 1,
4
+ "version": 2,
5
5
  "props": {
6
+ "staticBaseUrl": {
7
+ "type": "string",
8
+ "description": "Optional asset base for this component. A non-empty value overrides window.usxBaseUrl in React or STATIC_URL in Django; otherwise the global base or / is used. Asset filenames remain separate."
9
+ },
6
10
  "name": {
7
11
  "type": "string",
8
12
  "default": "accessibility_new",
@@ -38,8 +42,7 @@
38
42
  },
39
43
  "staticUrlPrefix": {
40
44
  "type": "string",
41
- "default": "/img/sprite.svg#",
42
- "description": "The URL prefix for the static assets, which is used to construct the full URL for the icon sprite sheet or icon library being used."
45
+ "description": "Legacy full sprite URL prefix, including #, overriding automatic asset resolution. Use staticBaseUrl to change only the base directory."
43
46
  },
44
47
  "className": {
45
48
  "type": "string",
@@ -52,9 +55,12 @@
52
55
  "description": "Alternative text for the icon, used for accessibility purposes to provide a textual description of the icon's meaning or function."
53
56
  },
54
57
  "style": {
55
- "type": "string",
56
- "default": "",
57
- "description": "Inline styles to apply to the icon component."
58
+ "type": ["string", "object"],
59
+ "description": "Inline styles: a React CSSProperties object in React or a CSS declaration string in Django. Omit to leave inline styles unset.",
60
+ "renderers": {
61
+ "react": { "type": "object" },
62
+ "django": { "type": "string" }
63
+ }
58
64
  }
59
65
  }
60
66
  }
@@ -1,4 +1,4 @@
1
- {% load static %}
1
+ {% load components %}
2
2
 
3
3
  <svg
4
4
  class="
@@ -18,9 +18,11 @@
18
18
  focusable="false"
19
19
  role="img"
20
20
  >
21
- {% if source == 'usx' %}
22
- <use href="{% static 'img/usx-sprite.svg' %}#{{ name }}"></use>
21
+ {% if staticUrlPrefix %}
22
+ <use href="{{ staticUrlPrefix }}{{ name }}"></use>
23
+ {% elif source == 'usx' %}
24
+ <use href="{% asset_url 'img/usx-sprite.svg' staticBaseUrl %}#{{ name }}"></use>
23
25
  {% else %}
24
- <use href="{% static 'img/sprite.svg' %}#{{ name }}"></use>
26
+ <use href="{% asset_url 'img/sprite.svg' staticBaseUrl %}#{{ name }}"></use>
25
27
  {% endif %}
26
28
  </svg>
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import classNames from 'classnames';
3
+ import { getAssetUrl, getAssetSrcSet } from '../../assets';
3
4
 
4
5
  export interface ImageSource {
5
6
  srcSet: string;
@@ -13,7 +14,7 @@ export interface ResponsiveImage {
13
14
  sources: ImageSource[];
14
15
  }
15
16
 
16
- export interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
17
+ export interface ImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src'> {
17
18
  src: string | ResponsiveImage;
18
19
  alt?: string;
19
20
  href?: string;
@@ -24,6 +25,7 @@ export interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
24
25
  objectFit?: 'cover' | 'contain' | 'fill' | 'none' | 'scale-down' | '';
25
26
  maxWidth?: string | number;
26
27
  maxHeight?: string | number;
28
+ staticBaseUrl?: string;
27
29
  className?: string;
28
30
  }
29
31
 
@@ -38,6 +40,8 @@ export default function Image({
38
40
  objectFit = '',
39
41
  maxWidth,
40
42
  maxHeight,
43
+ staticBaseUrl,
44
+ srcSet,
41
45
  className = '',
42
46
  ...props
43
47
  }: ImageProps) {
@@ -72,15 +76,15 @@ export default function Image({
72
76
  <source
73
77
  key={i}
74
78
  {...(source.media ? { media: source.media } : {})}
75
- srcSet={source.srcSet}
79
+ srcSet={getAssetSrcSet(source.srcSet, staticBaseUrl)}
76
80
  {...(source.type ? { type: source.type } : {})}
77
81
  {...(source.sizes ? { sizes: source.sizes } : {})}
78
82
  />
79
83
  ))}
80
- <img src={(src as ResponsiveImage).fallback} alt={alt} style={style} {...props} />
84
+ <img src={getAssetUrl((src as ResponsiveImage).fallback, staticBaseUrl)} srcSet={srcSet ? getAssetSrcSet(srcSet, staticBaseUrl) : undefined} alt={alt} style={style} {...props} />
81
85
  </picture>
82
86
  ) : (
83
- <img src={src as string} alt={alt} style={style} {...props} />
87
+ <img src={getAssetUrl(src as string, staticBaseUrl)} srcSet={srcSet ? getAssetSrcSet(srcSet, staticBaseUrl) : undefined} alt={alt} style={style} {...props} />
84
88
  );
85
89
 
86
90
  if (caption) {
@@ -6,9 +6,17 @@
6
6
  "src"
7
7
  ],
8
8
  "props": {
9
- "src": {
9
+ "staticBaseUrl": {
10
+ "type": "string",
11
+ "description": "Optional image asset base, overriding window.usxBaseUrl in React or STATIC_URL in Django. Defaults to the global base or /."
12
+ },
13
+ "srcSet": {
10
14
  "type": "string",
11
- "description": "Image source URL"
15
+ "description": "Optional image source candidates and width/density descriptors. Each candidate path is resolved against the image asset base."
16
+ },
17
+ "src": {
18
+ "type": ["string", "object"],
19
+ "description": "Image asset path or responsive object { fallback, sources: [{ srcSet, media?, type?, sizes? }] }. Paths resolve against the asset base; fully qualified and data URLs are unchanged."
12
20
  },
13
21
  "alt": {
14
22
  "type": "string",
@@ -1,4 +1,6 @@
1
1
  {# Django template for Image #}
2
+ {% load components %}
3
+ {% if srcSet %}{% asset_srcset srcSet staticBaseUrl as imageSrcSet %}{% endif %}
2
4
  {# Props: src, alt, href, rounded, circular, objectFit, maxWidth, maxHeight, caption, hideCaption, className #}
3
5
  {# For responsive images, src may be an object: { fallback, sources: [{ srcSet, media?, type?, sizes? }] } #}
4
6
 
@@ -16,17 +18,17 @@
16
18
  {% if src.fallback %}
17
19
  <picture>
18
20
  {% for source in src.sources %}
19
- <source srcset="{{ source.srcSet }}"
21
+ <source srcset="{% asset_srcset source.srcSet staticBaseUrl %}"
20
22
  {% if source.media %}media="{{ source.media }}"{% endif %}
21
23
  {% if source.type %}type="{{ source.type }}"{% endif %}
22
24
  {% if source.sizes %}sizes="{{ source.sizes }}"{% endif %}
23
25
  />
24
26
  {% endfor %}
25
- <img src="{{ src.fallback }}"{% if alt %} alt="{{ alt }}"{% endif %}
27
+ <img src="{% asset_url src.fallback staticBaseUrl %}"{% if imageSrcSet %} srcset="{{ imageSrcSet }}"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}
26
28
  {% if maxWidth or maxHeight %}style="{% if maxWidth %}max-width: {{ maxWidth }};{% if not maxHeight %} height: auto;{% endif %}{% endif %}{% if maxHeight %} max-height: {{ maxHeight }};{% if not maxWidth %} width: auto;{% endif %}{% endif %}"{% endif %} />
27
29
  </picture>
28
30
  {% elif src %}
29
- <img src="{{ src }}"{% if alt %} alt="{{ alt }}"{% endif %}
31
+ <img src="{% asset_url src staticBaseUrl %}"{% if imageSrcSet %} srcset="{{ imageSrcSet }}"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}
30
32
  {% if maxWidth or maxHeight %}style="{% if maxWidth %}max-width: {{ maxWidth }};{% if not maxHeight %} height: auto;{% endif %}{% endif %}{% if maxHeight %} max-height: {{ maxHeight }};{% if not maxWidth %} width: auto;{% endif %}{% endif %}"{% endif %} />
31
33
  {% else %}
32
34
  Image
@@ -43,17 +45,17 @@
43
45
  {% if src.fallback %}
44
46
  <picture>
45
47
  {% for source in src.sources %}
46
- <source srcset="{{ source.srcSet }}"
48
+ <source srcset="{% asset_srcset source.srcSet staticBaseUrl %}"
47
49
  {% if source.media %}media="{{ source.media }}"{% endif %}
48
50
  {% if source.type %}type="{{ source.type }}"{% endif %}
49
51
  {% if source.sizes %}sizes="{{ source.sizes }}"{% endif %}
50
52
  />
51
53
  {% endfor %}
52
- <img src="{{ src.fallback }}"{% if alt %} alt="{{ alt }}"{% endif %}
54
+ <img src="{% asset_url src.fallback staticBaseUrl %}"{% if imageSrcSet %} srcset="{{ imageSrcSet }}"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}
53
55
  {% if maxWidth or maxHeight %}style="{% if maxWidth %}max-width: {{ maxWidth }};{% if not maxHeight %} height: auto;{% endif %}{% endif %}{% if maxHeight %} max-height: {{ maxHeight }};{% if not maxWidth %} width: auto;{% endif %}{% endif %}"{% endif %} />
54
56
  </picture>
55
57
  {% elif src %}
56
- <img src="{{ src }}"{% if alt %} alt="{{ alt }}"{% endif %}
58
+ <img src="{% asset_url src staticBaseUrl %}"{% if imageSrcSet %} srcset="{{ imageSrcSet }}"{% endif %}{% if alt %} alt="{{ alt }}"{% endif %}
57
59
  {% if maxWidth or maxHeight %}style="{% if maxWidth %}max-width: {{ maxWidth }};{% if not maxHeight %} height: auto;{% endif %}{% endif %}{% if maxHeight %} max-height: {{ maxHeight }};{% if not maxWidth %} width: auto;{% endif %}{% endif %}"{% endif %} />
58
60
  {% else %}
59
61
  Image
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "layout",
3
3
  "template": "layout/layout.django.html",
4
- "version": 1,
4
+ "version": 2,
5
5
  "props": {
6
6
  "variant": {
7
7
  "type": "select",
@@ -13,20 +13,20 @@
13
13
  "description": "Layout variant: single-column centers content, grid supports sidebars"
14
14
  },
15
15
  "children": {
16
- "type": "string",
17
- "description": "Inner HTML or text content (for single-column)"
16
+ "type": "slot",
17
+ "description": "Main content in either layout variant. Accepts text, React nodes, or a Django template fragment; takes precedence over content when truthy."
18
18
  },
19
19
  "content": {
20
- "type": "string",
21
- "description": "Main content for grid layout"
20
+ "type": "slot",
21
+ "description": "Fallback main content in either layout variant when children is falsy. Accepts text, React nodes, or a Django template fragment."
22
22
  },
23
23
  "leftSidebar": {
24
- "type": "string",
25
- "description": "Left sidebar content (grid variant only)"
24
+ "type": "slot",
25
+ "description": "Left sidebar content in the grid variant; accepts text, React nodes, or a Django template fragment."
26
26
  },
27
27
  "rightSidebar": {
28
- "type": "string",
29
- "description": "Right sidebar content (grid variant only)"
28
+ "type": "slot",
29
+ "description": "Right sidebar content in the grid variant; accepts text, React nodes, or a Django template fragment."
30
30
  },
31
31
  "expandLeftSidebar": {
32
32
  "type": "boolean",
@@ -4,7 +4,7 @@
4
4
  {# For grid: content, leftSidebar, rightSidebar #}
5
5
  {% fragment as expandButton %}
6
6
  {% if expandable %}
7
- {% html_attrs aria_expanded="false" aria_label="Expand" onclick="const layout = this.closest('.usx-layout'); const expanded = layout.classList.toggle('usx-expanded'); this.setAttribute('aria-expanded', expanded); this.setAttribute('aria-label', expanded ? 'Contract' : 'Expand');" as expandAttributes %}
7
+ {% dict aria_expanded="false" aria_label="Expand" onclick="const layout = this.closest('.usx-layout'); const expanded = layout.classList.toggle('usx-expanded'); this.setAttribute('aria-expanded', expanded); this.setAttribute('aria-label', expanded ? 'Contract' : 'Expand');" as expandAttributes %}
8
8
  {% button variant="primary" ghost=True type="button" className="usx-layout__expand-button" extraAttributes=expandAttributes %}
9
9
  {% icon source='usx' name='expand' size=3 className='usx-layout__expand-icon usx-layout__expand-icon--expand' %}{% endicon %}
10
10
  {% icon source='usx' name='contract' size=3 className='usx-layout__expand-icon usx-layout__expand-icon--contract' %}{% endicon %}
@@ -1,45 +1,38 @@
1
1
  import React from 'react';
2
+ import Icon from '../icon/Icon';
3
+ import Label from '../label/Label';
2
4
 
3
5
  export interface SpinnerProps extends React.HTMLAttributes<HTMLSpanElement> {
4
- size?: 1 | 2 | 3 | 4 | 5;
5
- color?: string | null;
6
+ size?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
7
+ color?: string;
6
8
  label?: string;
7
- omitLabel?: boolean;
9
+ screenReaderLabel?: string;
8
10
  staticUrlPrefix?: string;
11
+ staticBaseUrl?: string;
9
12
  className?: string;
10
13
  }
11
14
 
12
- const getDefaultStaticUrlPrefix = () => {
13
- if (typeof window !== 'undefined' && (window as unknown as { usxBaseUrl?: string }).usxBaseUrl) {
14
- return (window as unknown as { usxBaseUrl?: string }).usxBaseUrl + 'img/usx-sprite.svg#';
15
- }
16
- return '/img/usx-sprite.svg#';
17
- };
18
-
19
15
  const Spinner: React.FC<SpinnerProps> = ({
20
16
  size = 3,
21
- color = null,
17
+ color,
22
18
  label = null,
23
19
  screenReaderLabel = null,
24
- staticUrlPrefix = getDefaultStaticUrlPrefix(),
20
+ staticUrlPrefix,
21
+ staticBaseUrl,
25
22
  className = '',
26
23
  ...props
27
24
  }) => {
28
25
  return (
29
26
  <span role="status" aria-live="polite" className={`usx-spinner ${className}`} {...props}>
30
- <svg
31
- className={
32
- 'usa-icon ' +
33
- (size === 1 ? 'usx-spinner--size-1' : 'usa-icon--size-' + size) +
34
- (color ? ' text-' + color : '')
35
- }
36
- aria-hidden="true"
37
- focusable="false"
38
- >
39
- <use href={staticUrlPrefix + 'spinner'} />
40
- </svg>
41
- {screenReaderLabel && <span className="usa-sr-only">{screenReaderLabel}</span>}
42
- {label && <span className="usa-label usx-label">{label}</span>}
27
+ <Icon
28
+ name="spinner"
29
+ source="usx"
30
+ size={size}
31
+ color={color}
32
+ staticBaseUrl={staticBaseUrl}
33
+ />
34
+ {screenReaderLabel && <Label screenReaderOnly={true}>{screenReaderLabel}</Label>}
35
+ {label && <Label>{label}</Label>}
43
36
  </span>
44
37
  );
45
38
  };