@solexllc/usx-react 0.3.1 → 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 (42) hide show
  1. package/README.md +132 -0
  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
package/dist/index.js CHANGED
@@ -150,6 +150,39 @@ function Accordion({
150
150
  }
151
151
  );
152
152
  }
153
+ function getAssetUrl(assetPath, staticBaseUrl) {
154
+ if (/^[a-z][a-z\d+.-]*:/i.test(assetPath)) return assetPath;
155
+ const base = staticBaseUrl || typeof window !== "undefined" && window.usxBaseUrl || "/";
156
+ return `${base.replace(/\/+$/, "")}/${assetPath.replace(/^\/+/, "")}`;
157
+ }
158
+ function getAssetSrcSet(srcSet, staticBaseUrl) {
159
+ return srcSet.replace(/(^\s*|,\s*)(\S*[^,\s])(?=,?(?:\s|$))/g, (_match, separator, url) => `${separator}${getAssetUrl(url, staticBaseUrl)}`);
160
+ }
161
+ function Icon({
162
+ name,
163
+ source = "uswds",
164
+ size = 2,
165
+ color,
166
+ alt = name + " icon",
167
+ staticBaseUrl,
168
+ staticUrlPrefix,
169
+ className = "",
170
+ ...props
171
+ }) {
172
+ const spritePrefix = staticUrlPrefix ?? getAssetUrl(`img/${source === "usx" ? "usx-sprite.svg" : "sprite.svg"}#`, staticBaseUrl);
173
+ return /* @__PURE__ */ jsx(
174
+ "svg",
175
+ {
176
+ className: "usa-icon " + (size ? size === 1 ? "usx-icon--size-1" : "usa-icon--size-" + size : "") + " " + (color ? "text-" + color : "") + " " + className,
177
+ "aria-hidden": "true",
178
+ "aria-label": alt,
179
+ focusable: "false",
180
+ role: "img",
181
+ ...props,
182
+ children: /* @__PURE__ */ jsx("use", { href: spritePrefix + name })
183
+ }
184
+ );
185
+ }
153
186
  function Alert({
154
187
  heading,
155
188
  text,
@@ -161,6 +194,7 @@ function Alert({
161
194
  ariaLabel,
162
195
  ariaLabelledby,
163
196
  onDismiss = void 0,
197
+ staticBaseUrl,
164
198
  children = null,
165
199
  ...props
166
200
  }) {
@@ -187,32 +221,9 @@ function Alert({
187
221
  return /* @__PURE__ */ jsx("div", { className: classes, ...accessibilityProps, ...props, children: /* @__PURE__ */ jsxs("div", { className: "usa-alert__body", children: [
188
222
  !slim && heading ? /* @__PURE__ */ jsx("h4", { className: "usa-alert__heading", children: heading }) : null,
189
223
  children ? /* @__PURE__ */ jsx("div", { className: "usa-alert__text", children }) : /* @__PURE__ */ jsx("p", { className: "usa-alert__text", children: text }),
190
- onDismiss && /* @__PURE__ */ jsx("button", { className: "usx-alert__dismiss", "aria-label": "Dismiss alert", onClick: onDismiss, children: /* @__PURE__ */ jsx("svg", { className: "usa-icon usa-icon--size-3", "aria-hidden": "true", focusable: "false", role: "img", children: /* @__PURE__ */ jsx("use", { href: "./img/sprite.svg#close" }) }) })
224
+ onDismiss && /* @__PURE__ */ jsx("button", { className: "usx-alert__dismiss", "aria-label": "Dismiss alert", onClick: onDismiss, children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 3, staticBaseUrl }) })
191
225
  ] }) });
192
226
  }
193
- function Icon({
194
- name,
195
- source = "uswds",
196
- size = 2,
197
- color,
198
- alt = name + " icon",
199
- staticUrlPrefix = (typeof window !== "undefined" && window.usxBaseUrl || "/") + "img/" + (source === "usx" ? "usx-sprite.svg" : "sprite.svg") + "#",
200
- className = "",
201
- ...props
202
- }) {
203
- return /* @__PURE__ */ jsx(
204
- "svg",
205
- {
206
- className: "usa-icon " + (size ? size === 1 ? "usx-icon--size-1" : "usa-icon--size-" + size : "") + " " + (color ? "text-" + color : "") + " " + className,
207
- "aria-hidden": "true",
208
- "aria-label": alt,
209
- focusable: "false",
210
- role: "img",
211
- ...props,
212
- children: /* @__PURE__ */ jsx("use", { href: staticUrlPrefix + name })
213
- }
214
- );
215
- }
216
227
  const shapeClassMap = {
217
228
  circle: "usx-circle",
218
229
  "rounded-sm": "usx-rounded-sm",
@@ -353,7 +364,8 @@ function BackToTop({
353
364
  function Banner({
354
365
  id = "gov-banner",
355
366
  ariaLabel = "Official government website",
356
- flagSrc = (typeof window !== "undefined" && window.usxBaseUrl || "/") + "img/us_flag_small.png",
367
+ flagSrc,
368
+ staticBaseUrl,
357
369
  tld = ".gov",
358
370
  bannerText = "An official website of the United States government",
359
371
  bannerActionText = "Here's how you know",
@@ -364,7 +376,7 @@ function Banner({
364
376
  "A ",
365
377
  /* @__PURE__ */ jsx("strong", { children: "lock" }),
366
378
  " (",
367
- /* @__PURE__ */ jsx(Icon, { name: "lock", size: 1 }),
379
+ /* @__PURE__ */ jsx(Icon, { name: "lock", size: 1, staticBaseUrl }),
368
380
  ") or ",
369
381
  /* @__PURE__ */ jsx("strong", { children: "https://" }),
370
382
  " means you’ve safely connected to the ",
@@ -374,7 +386,6 @@ function Banner({
374
386
  className = "",
375
387
  ...props
376
388
  }) {
377
- const assetBaseUrl = typeof window !== "undefined" && window.usxBaseUrl || "/";
378
389
  const classes = classNames(
379
390
  "usa-banner",
380
391
  "usx-banner",
@@ -387,7 +398,7 @@ function Banner({
387
398
  {
388
399
  "aria-hidden": "true",
389
400
  className: "usa-banner__header-flag",
390
- src: flagSrc,
401
+ src: getAssetUrl(flagSrc ?? "img/us_flag_small.png", staticBaseUrl),
391
402
  alt: ""
392
403
  }
393
404
  ) }),
@@ -425,7 +436,7 @@ function Banner({
425
436
  "img",
426
437
  {
427
438
  className: "usa-banner__icon usa-media-block__img",
428
- src: `${assetBaseUrl}img/icon-dot-gov.svg`,
439
+ src: getAssetUrl("img/icon-dot-gov.svg", staticBaseUrl),
429
440
  role: "img",
430
441
  alt: "",
431
442
  "aria-hidden": "true"
@@ -442,7 +453,7 @@ function Banner({
442
453
  "img",
443
454
  {
444
455
  className: "usa-banner__icon usa-media-block__img",
445
- src: `${assetBaseUrl}img/icon-https.svg`,
456
+ src: getAssetUrl("img/icon-https.svg", staticBaseUrl),
446
457
  role: "img",
447
458
  alt: "",
448
459
  "aria-hidden": "true"
@@ -557,33 +568,71 @@ function Breadcrumb({
557
568
  }
558
569
  ) });
559
570
  }
560
- const getDefaultStaticUrlPrefix = () => {
561
- if (typeof window !== "undefined" && window.usxBaseUrl) {
562
- return window.usxBaseUrl + "img/usx-sprite.svg#";
563
- }
564
- return "/img/usx-sprite.svg#";
571
+ const Required = ({
572
+ title = "Required",
573
+ children = null,
574
+ className = "",
575
+ ...props
576
+ }) => {
577
+ const classes = classNames("usx-required", className);
578
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
579
+ /* @__PURE__ */ jsx("abbr", { title, className: classes, ...props, children: "*" }),
580
+ " ",
581
+ children ? children : ""
582
+ ] });
565
583
  };
584
+ function Label({
585
+ htmlFor,
586
+ required = false,
587
+ error = false,
588
+ children = null,
589
+ screenReaderOnly = false,
590
+ className = "",
591
+ classOverride = false,
592
+ ...props
593
+ }) {
594
+ const classes = classNames(
595
+ "usa-label",
596
+ "usx-label",
597
+ { "usa-sr-only": screenReaderOnly, "usa-label--error": !!error },
598
+ className
599
+ );
600
+ return /* @__PURE__ */ jsxs(
601
+ "label",
602
+ {
603
+ className: classOverride ? className : classes,
604
+ ...htmlFor ? { htmlFor } : {},
605
+ ...props,
606
+ children: [
607
+ required && /* @__PURE__ */ jsx(Required, {}),
608
+ children
609
+ ]
610
+ }
611
+ );
612
+ }
566
613
  const Spinner = ({
567
614
  size = 3,
568
- color = null,
615
+ color,
569
616
  label = null,
570
617
  screenReaderLabel = null,
571
- staticUrlPrefix = getDefaultStaticUrlPrefix(),
618
+ staticUrlPrefix,
619
+ staticBaseUrl,
572
620
  className = "",
573
621
  ...props
574
622
  }) => {
575
623
  return /* @__PURE__ */ jsxs("span", { role: "status", "aria-live": "polite", className: `usx-spinner ${className}`, ...props, children: [
576
624
  /* @__PURE__ */ jsx(
577
- "svg",
625
+ Icon,
578
626
  {
579
- className: "usa-icon " + (size === 1 ? "usx-spinner--size-1" : "usa-icon--size-" + size) + (color ? " text-" + color : ""),
580
- "aria-hidden": "true",
581
- focusable: "false",
582
- children: /* @__PURE__ */ jsx("use", { href: staticUrlPrefix + "spinner" })
627
+ name: "spinner",
628
+ source: "usx",
629
+ size,
630
+ color,
631
+ staticBaseUrl
583
632
  }
584
633
  ),
585
- screenReaderLabel && /* @__PURE__ */ jsx("span", { className: "usa-sr-only", children: screenReaderLabel }),
586
- label && /* @__PURE__ */ jsx("span", { className: "usa-label usx-label", children: label })
634
+ screenReaderLabel && /* @__PURE__ */ jsx(Label, { screenReaderOnly: true, children: screenReaderLabel }),
635
+ label && /* @__PURE__ */ jsx(Label, { children: label })
587
636
  ] });
588
637
  };
589
638
  function Button({
@@ -623,7 +672,7 @@ function Button({
623
672
  const classes = classNames(
624
673
  "usa-button",
625
674
  "usx-button",
626
- variant ? variantClasses[variant] : variantClasses["primary"],
675
+ variant && variantClasses[variant],
627
676
  big && "usa-button--big",
628
677
  inverse && "usa-button--inverse",
629
678
  ghost && "usx-button--ghost",
@@ -772,6 +821,8 @@ function Image({
772
821
  objectFit = "",
773
822
  maxWidth,
774
823
  maxHeight,
824
+ staticBaseUrl,
825
+ srcSet,
775
826
  className = "",
776
827
  ...props
777
828
  }) {
@@ -799,14 +850,14 @@ function Image({
799
850
  "source",
800
851
  {
801
852
  ...source.media ? { media: source.media } : {},
802
- srcSet: source.srcSet,
853
+ srcSet: getAssetSrcSet(source.srcSet, staticBaseUrl),
803
854
  ...source.type ? { type: source.type } : {},
804
855
  ...source.sizes ? { sizes: source.sizes } : {}
805
856
  },
806
857
  i
807
858
  )),
808
- /* @__PURE__ */ jsx("img", { src: src.fallback, alt, style, ...props })
809
- ] }) : /* @__PURE__ */ jsx("img", { src, alt, style, ...props });
859
+ /* @__PURE__ */ jsx("img", { src: getAssetUrl(src.fallback, staticBaseUrl), srcSet: srcSet ? getAssetSrcSet(srcSet, staticBaseUrl) : void 0, alt, style, ...props })
860
+ ] }) : /* @__PURE__ */ jsx("img", { src: getAssetUrl(src, staticBaseUrl), srcSet: srcSet ? getAssetSrcSet(srcSet, staticBaseUrl) : void 0, alt, style, ...props });
810
861
  if (caption) {
811
862
  return /* @__PURE__ */ jsxs("figure", { className: classes, style, children: [
812
863
  imgElement,
@@ -946,48 +997,6 @@ function CardGroup({ cardProps = [], className = "", ...props }) {
946
997
  );
947
998
  return /* @__PURE__ */ jsx("ul", { className: classes, ...props, children: cardProps.map((card, index) => /* @__PURE__ */ jsx(Card, { ...card, tag: "li" }, index)) });
948
999
  }
949
- const Required = ({
950
- title = "Required",
951
- children = null,
952
- className = "",
953
- ...props
954
- }) => {
955
- const classes = classNames("usx-required", className);
956
- return /* @__PURE__ */ jsxs(Fragment, { children: [
957
- /* @__PURE__ */ jsx("abbr", { title, className: classes, ...props, children: "*" }),
958
- " ",
959
- children ? children : ""
960
- ] });
961
- };
962
- function Label({
963
- htmlFor,
964
- required = false,
965
- error = false,
966
- children = null,
967
- screenReaderOnly = false,
968
- className = "",
969
- classOverride = false,
970
- ...props
971
- }) {
972
- const classes = classNames(
973
- "usa-label",
974
- "usx-label",
975
- { "usa-sr-only": screenReaderOnly, "usa-label--error": !!error },
976
- className
977
- );
978
- return /* @__PURE__ */ jsxs(
979
- "label",
980
- {
981
- className: classOverride ? className : classes,
982
- ...htmlFor ? { htmlFor } : {},
983
- ...props,
984
- children: [
985
- required && /* @__PURE__ */ jsx(Required, {}),
986
- children
987
- ]
988
- }
989
- );
990
- }
991
1000
  function Hint({
992
1001
  id,
993
1002
  children = null,
@@ -1330,24 +1339,69 @@ function Clickable({ className, children, ...rest }) {
1330
1339
  Clickable.Link = ClickableLink;
1331
1340
  Clickable.ColorChange = ClickableColorChange;
1332
1341
  Clickable.BgColorChange = ClickableBgColorChange;
1333
- function usxCopy(text) {
1334
- if (navigator.clipboard) {
1335
- navigator.clipboard.writeText(text);
1336
- } else {
1337
- const ta = document.createElement("textarea");
1338
- ta.value = text;
1339
- ta.style.cssText = "position:fixed;opacity:0";
1340
- document.body.appendChild(ta);
1341
- ta.focus();
1342
- ta.select();
1343
- try {
1344
- document.execCommand("copy");
1345
- } catch {
1346
- }
1347
- document.body.removeChild(ta);
1342
+ const Tooltip = ({
1343
+ label,
1344
+ position = "top",
1345
+ children,
1346
+ className = "",
1347
+ bodyClassName = "",
1348
+ ...props
1349
+ }) => {
1350
+ const validPositions = ["top", "bottom", "left", "right"];
1351
+ const normalizedPosition = validPositions.includes(position) ? position : "top";
1352
+ return /* @__PURE__ */ jsxs("span", { className: classNames("usx-tooltip", className), ...props, children: [
1353
+ children,
1354
+ /* @__PURE__ */ jsx(
1355
+ "span",
1356
+ {
1357
+ className: classNames("usa-tooltip__body", `usa-tooltip__body--${normalizedPosition}`, bodyClassName),
1358
+ role: "tooltip",
1359
+ children: label
1360
+ }
1361
+ )
1362
+ ] });
1363
+ };
1364
+ function copyTextToClipboard(text) {
1365
+ if (window.navigator.clipboard) {
1366
+ return window.navigator.clipboard.writeText(text);
1348
1367
  }
1349
1368
  }
1350
- function Code({ lines = [], allowHtml = false, copyText = null, className = "" }) {
1369
+ function CopyToClipboard({
1370
+ copyText = "",
1371
+ label = null,
1372
+ tooltipProps,
1373
+ staticBaseUrl,
1374
+ className = ""
1375
+ }) {
1376
+ const button = /* @__PURE__ */ jsxs(
1377
+ Button,
1378
+ {
1379
+ ghost: true,
1380
+ className: classNames("usx-copy", className),
1381
+ onClick: () => copyTextToClipboard(copyText),
1382
+ type: "button",
1383
+ children: [
1384
+ /* @__PURE__ */ jsx(Icon, { name: "content_copy", size: 0, className: "usx-copy__copy", staticBaseUrl }),
1385
+ /* @__PURE__ */ jsx(Icon, { name: "check", size: 0, className: "usx-copy__check", staticBaseUrl }),
1386
+ label && /* @__PURE__ */ jsx("span", { className: "margin-left-1", children: label })
1387
+ ]
1388
+ }
1389
+ );
1390
+ if (!tooltipProps) return button;
1391
+ const { label: tooltipLabel, copiedTooltip = "Copied", ...tooltipOptions } = tooltipProps;
1392
+ return /* @__PURE__ */ jsx(
1393
+ Tooltip,
1394
+ {
1395
+ ...tooltipOptions,
1396
+ label: /* @__PURE__ */ jsxs(Fragment, { children: [
1397
+ /* @__PURE__ */ jsx("span", { className: "usx-copy__tooltip--copy", children: tooltipLabel }),
1398
+ /* @__PURE__ */ jsx("span", { className: "usx-copy__tooltip--copied", children: copiedTooltip })
1399
+ ] }),
1400
+ children: button
1401
+ }
1402
+ );
1403
+ }
1404
+ function Code({ lines = [], allowHtml = false, copyText = null, staticBaseUrl, className = "" }) {
1351
1405
  return /* @__PURE__ */ jsxs("div", { className: classNames("usx-mockup-code", className), children: [
1352
1406
  /* @__PURE__ */ jsx("div", { className: "usx-mockup-code__content", children: lines.map((line, i) => /* @__PURE__ */ jsx(
1353
1407
  "pre",
@@ -1358,17 +1412,7 @@ function Code({ lines = [], allowHtml = false, copyText = null, className = "" }
1358
1412
  },
1359
1413
  i
1360
1414
  )) }),
1361
- copyText && /* @__PURE__ */ jsxs(
1362
- "button",
1363
- {
1364
- className: "usa-button usx-button usx-button--ghost usx-copy",
1365
- onClick: () => usxCopy(copyText),
1366
- children: [
1367
- /* @__PURE__ */ jsx("svg", { className: "usa-icon usx-copy__copy", "aria-hidden": "true", focusable: "false", role: "img", children: /* @__PURE__ */ jsx("use", { href: "./img/sprite.svg#content_copy" }) }),
1368
- /* @__PURE__ */ jsx("svg", { className: "usa-icon usx-copy__check", "aria-hidden": "true", focusable: "false", role: "img", children: /* @__PURE__ */ jsx("use", { href: "./img/sprite.svg#check" }) })
1369
- ]
1370
- }
1371
- )
1415
+ copyText && /* @__PURE__ */ jsx(CopyToClipboard, { copyText, staticBaseUrl, tooltipProps: { label: "Copy", copiedTooltip: "Copied", position: "left" } })
1372
1416
  ] });
1373
1417
  }
1374
1418
  function CollectionItem({ href, heading, description, imgSrc, imgAlt = "", calendarDate, meta, tags }) {
@@ -1468,38 +1512,6 @@ function Combobox({
1468
1512
  ] });
1469
1513
  return formGroup ? /* @__PURE__ */ jsx(FormGroup, { error: !!error, children: content }) : content;
1470
1514
  }
1471
- function CopyToClipboard({
1472
- copyText = "",
1473
- label = null,
1474
- tooltip = null,
1475
- copiedTooltip = "Copied",
1476
- className = ""
1477
- }) {
1478
- const button = /* @__PURE__ */ jsxs(
1479
- "button",
1480
- {
1481
- className: classNames(
1482
- "usa-button",
1483
- "usx-button",
1484
- "usx-button--ghost",
1485
- "usx-copy",
1486
- className
1487
- ),
1488
- onClick: () => window.navigator.clipboard.writeText(copyText),
1489
- type: "button",
1490
- children: [
1491
- /* @__PURE__ */ jsx("svg", { className: "usa-icon usx-copy__copy", "aria-hidden": "true", focusable: "false", role: "img", children: /* @__PURE__ */ jsx("use", { href: "./img/sprite.svg#content_copy" }) }),
1492
- /* @__PURE__ */ jsx("svg", { className: "usa-icon usx-copy__check", "aria-hidden": "true", focusable: "false", role: "img", children: /* @__PURE__ */ jsx("use", { href: "./img/sprite.svg#check" }) }),
1493
- label && /* @__PURE__ */ jsx("span", { className: "margin-left-1", children: label })
1494
- ]
1495
- }
1496
- );
1497
- return /* @__PURE__ */ jsxs("span", { className: "usx-tooltip", children: [
1498
- button,
1499
- tooltip && /* @__PURE__ */ jsx("span", { className: "usa-tooltip__body usa-tooltip__body--right usx-copy__tooltip--copy", role: "tooltip", children: tooltip }),
1500
- /* @__PURE__ */ jsx("span", { className: "usa-tooltip__body usa-tooltip__body--right usx-copy__tooltip--copied", role: "tooltip", children: copiedTooltip })
1501
- ] });
1502
- }
1503
1515
  function DatePicker({
1504
1516
  id = "date-picker",
1505
1517
  name,
@@ -1825,7 +1837,7 @@ function FileInput({
1825
1837
  ] });
1826
1838
  return formGroup ? /* @__PURE__ */ jsx(FormGroup, { error: !!error, children: content }) : content;
1827
1839
  }
1828
- function BrandingContent({ config, projectUrl }) {
1840
+ function BrandingContent({ config, projectUrl, staticBaseUrl }) {
1829
1841
  const { title, symbol, symbolInverse, logo, logoInverse, alt } = config;
1830
1842
  const label = alt ?? title ?? "";
1831
1843
  if (logo) {
@@ -1836,11 +1848,12 @@ function BrandingContent({ config, projectUrl }) {
1836
1848
  ...projectUrl ? { href: projectUrl } : {},
1837
1849
  className: "usx-image usx-logo__image",
1838
1850
  children: [
1839
- /* @__PURE__ */ jsx(Image, { src: logo, alt: label, className: "usx-logo__variant" }),
1851
+ /* @__PURE__ */ jsx(Image, { src: logo, alt: label, staticBaseUrl, className: "usx-logo__variant" }),
1840
1852
  logoInverse && /* @__PURE__ */ jsx(
1841
1853
  Image,
1842
1854
  {
1843
1855
  src: logoInverse,
1856
+ staticBaseUrl,
1844
1857
  alt: label,
1845
1858
  className: "usx-logo__variant usx-logo__variant--inverse"
1846
1859
  }
@@ -1850,11 +1863,11 @@ function BrandingContent({ config, projectUrl }) {
1850
1863
  );
1851
1864
  }
1852
1865
  return /* @__PURE__ */ jsxs("em", { className: "usa-logo__text", children: [
1853
- symbol && /* @__PURE__ */ jsx("img", { src: symbol, alt: "", "aria-hidden": "true", className: "usx-logo__symbol usx-logo__variant" }),
1866
+ symbol && /* @__PURE__ */ jsx("img", { src: getAssetUrl(symbol, staticBaseUrl), alt: "", "aria-hidden": "true", className: "usx-logo__symbol usx-logo__variant" }),
1854
1867
  symbolInverse && /* @__PURE__ */ jsx(
1855
1868
  "img",
1856
1869
  {
1857
- src: symbolInverse,
1870
+ src: getAssetUrl(symbolInverse, staticBaseUrl),
1858
1871
  alt: "",
1859
1872
  "aria-hidden": "true",
1860
1873
  className: "usx-logo__symbol usx-logo__variant usx-logo__variant--inverse"
@@ -1863,14 +1876,14 @@ function BrandingContent({ config, projectUrl }) {
1863
1876
  title && (projectUrl ? /* @__PURE__ */ jsx("a", { href: projectUrl, className: "usx-logo__title", children: title }) : /* @__PURE__ */ jsx("span", { className: "usx-logo__title", children: title }))
1864
1877
  ] });
1865
1878
  }
1866
- function Branding({ branding, projectUrl = "/", className = "", ...props }) {
1879
+ function Branding({ branding, projectUrl = "/", staticBaseUrl, className = "", ...props }) {
1867
1880
  if (!branding) return null;
1868
1881
  const classes = classNames(
1869
1882
  "usa-logo",
1870
1883
  "usx-logo",
1871
1884
  className
1872
1885
  );
1873
- return /* @__PURE__ */ jsx("div", { className: classes, ...props, children: /* @__PURE__ */ jsx(BrandingContent, { config: branding, projectUrl }) });
1886
+ return /* @__PURE__ */ jsx("div", { className: classes, ...props, children: /* @__PURE__ */ jsx(BrandingContent, { config: branding, projectUrl, staticBaseUrl }) });
1874
1887
  }
1875
1888
  function FooterReturnToTop({ label = "Return to top", href = "#", className = "" }) {
1876
1889
  const classes = classNames(
@@ -1916,9 +1929,9 @@ function FooterSignUp({
1916
1929
  ] })
1917
1930
  ] });
1918
1931
  }
1919
- function FooterSocialLinks({ links = [], className = "" }) {
1932
+ function FooterSocialLinks({ links = [], staticBaseUrl, className = "" }) {
1920
1933
  if (!links.length) return null;
1921
- return /* @__PURE__ */ jsx("div", { className: ["usa-footer__social-links grid-row grid-gap-1 usx-footer__social-links", className].filter(Boolean).join(" "), children: links.map((link, i) => /* @__PURE__ */ jsx("div", { className: "grid-col-auto", children: /* @__PURE__ */ jsx("a", { className: "usa-social-link", href: link.href, "aria-label": link.alt, children: /* @__PURE__ */ jsx("img", { className: "usa-social-link__icon", src: link.icon, alt: link.alt }) }) }, i)) });
1934
+ return /* @__PURE__ */ jsx("div", { className: ["usa-footer__social-links grid-row grid-gap-1 usx-footer__social-links", className].filter(Boolean).join(" "), children: links.map((link, i) => /* @__PURE__ */ jsx("div", { className: "grid-col-auto", children: /* @__PURE__ */ jsx("a", { className: "usa-social-link", href: link.href, "aria-label": link.alt, children: /* @__PURE__ */ jsx("img", { className: "usa-social-link__icon", src: getAssetUrl(link.icon, staticBaseUrl), alt: link.alt }) }) }, i)) });
1922
1935
  }
1923
1936
  function normalizeContactLink(value, scheme) {
1924
1937
  var _a;
@@ -1956,6 +1969,7 @@ function Footer({
1956
1969
  signUp = null,
1957
1970
  branding = null,
1958
1971
  brandingUrl = "/",
1972
+ staticBaseUrl,
1959
1973
  socialLinks = [],
1960
1974
  contactHeading = null,
1961
1975
  contactPhone = null,
@@ -1985,9 +1999,9 @@ function Footer({
1985
1999
  links: contactLinks
1986
2000
  }
1987
2001
  ) : null;
1988
- const socialEl = socialLinks.length > 0 ? /* @__PURE__ */ jsx(FooterSocialLinks, { links: socialLinks }) : null;
2002
+ const socialEl = socialLinks.length > 0 ? /* @__PURE__ */ jsx(FooterSocialLinks, { links: socialLinks, staticBaseUrl }) : null;
1989
2003
  const logoClassName = variant === "slim" ? "usa-footer__logo grid-row grid-gap-2 usx-footer__logo" : "usa-footer__logo grid-row mobile-lg:grid-col-6 mobile-lg:grid-gap-2 usx-footer__logo";
1990
- const brandingEl = branding ? /* @__PURE__ */ jsx(Branding, { branding, projectUrl: brandingUrl, className: logoClassName }) : null;
2004
+ const brandingEl = branding ? /* @__PURE__ */ jsx(Branding, { branding, projectUrl: brandingUrl, staticBaseUrl, className: logoClassName }) : null;
1991
2005
  const secondaryContactBlock = socialEl || contactEl ? /* @__PURE__ */ jsxs("div", { className: "usa-footer__contact-links mobile-lg:grid-col-6", children: [
1992
2006
  socialEl,
1993
2007
  contactEl
@@ -2006,11 +2020,16 @@ function Footer({
2006
2020
  ] });
2007
2021
  }
2008
2022
  if (variant === "slim") {
2023
+ const slimContactLinks = [
2024
+ normalizeContactLink(contactPhone, "tel:"),
2025
+ normalizeContactLink(contactEmail, "mailto:"),
2026
+ ...contactLinks
2027
+ ].filter(Boolean);
2009
2028
  return /* @__PURE__ */ jsxs("footer", { className: classes, ...props, children: [
2010
2029
  returnToTopEl,
2011
2030
  /* @__PURE__ */ jsx("div", { className: "usa-footer__primary-section", children: primaryChildren ?? /* @__PURE__ */ jsxs("div", { className: "usa-footer__primary-container grid-row", children: [
2012
2031
  navLinks.length > 0 && /* @__PURE__ */ jsx("div", { className: "mobile-lg:grid-col-8", children: /* @__PURE__ */ jsx("nav", { className: "usa-footer__nav", "aria-label": navAriaLabel, children: /* @__PURE__ */ jsx("ul", { className: "grid-row grid-gap", children: navLinks.map((link, i) => /* @__PURE__ */ jsx("li", { className: "mobile-lg:grid-col-6 desktop:grid-col-auto usa-footer__primary-content", children: /* @__PURE__ */ jsx("a", { className: "usa-footer__primary-link", href: link.href, "aria-label": link.ariaLabel || void 0, children: link.text }) }, i)) }) }) }),
2013
- contactEl && /* @__PURE__ */ jsx("div", { className: "mobile-lg:grid-col-4", children: contactEl })
2032
+ slimContactLinks.length > 0 && /* @__PURE__ */ jsx("div", { className: "mobile-lg:grid-col-4", children: /* @__PURE__ */ jsx("address", { className: "usa-footer__address usx-footer__contact", children: /* @__PURE__ */ jsx("div", { className: "grid-row grid-gap", children: slimContactLinks.map((link, index) => /* @__PURE__ */ jsx("div", { className: "grid-col-auto mobile-lg:grid-col-12 desktop:grid-col-auto", children: /* @__PURE__ */ jsx("div", { className: "usa-footer__contact-info", children: /* @__PURE__ */ jsx("a", { href: link.href, children: link.text }) }) }, index)) }) }) })
2014
2033
  ] }) }),
2015
2034
  (brandingEl || secondaryChildren) && /* @__PURE__ */ jsx("div", { className: "usa-footer__secondary-section", children: secondaryChildren ?? /* @__PURE__ */ jsx("div", { className: "grid-container", children: brandingEl }) })
2016
2035
  ] });
@@ -2183,6 +2202,7 @@ function PrimaryNav({
2183
2202
  function Header({
2184
2203
  id = "header",
2185
2204
  branding,
2205
+ staticBaseUrl,
2186
2206
  projectUrl = "/",
2187
2207
  navSections = [],
2188
2208
  secondaryLinks = [],
@@ -2210,7 +2230,7 @@ function Header({
2210
2230
  { "usx-nav--sticky": stickyNav }
2211
2231
  );
2212
2232
  const navbar = /* @__PURE__ */ jsxs("div", { className: "usa-navbar", children: [
2213
- /* @__PURE__ */ jsx(Branding, { branding, projectUrl }),
2233
+ /* @__PURE__ */ jsx(Branding, { branding, projectUrl, staticBaseUrl }),
2214
2234
  /* @__PURE__ */ jsx("button", { type: "button", className: "usa-menu-btn align-center", children: useMenuIcon ? /* @__PURE__ */ jsx(Icon, { name: "menu", size: 3 }) : "Menu" })
2215
2235
  ] });
2216
2236
  if (extended) {
@@ -4829,27 +4849,6 @@ const Toggle = ({
4829
4849
  ] }, inputId);
4830
4850
  }) });
4831
4851
  };
4832
- const Tooltip = ({
4833
- label,
4834
- position = "top",
4835
- children,
4836
- className = "",
4837
- ...props
4838
- }) => {
4839
- const validPositions = ["top", "bottom", "left", "right"];
4840
- const normalizedPosition = validPositions.includes(position) ? position : "top";
4841
- return /* @__PURE__ */ jsxs("span", { className: classNames("usx-tooltip", className), ...props, children: [
4842
- children,
4843
- /* @__PURE__ */ jsx(
4844
- "span",
4845
- {
4846
- className: `usa-tooltip__body usa-tooltip__body--${normalizedPosition}`,
4847
- role: "tooltip",
4848
- children: label
4849
- }
4850
- )
4851
- ] });
4852
- };
4853
4852
  const Villain = ({
4854
4853
  title = "",
4855
4854
  callout = "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solexllc/usx-react",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "React component library for USX.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@solexllc/usx": "0.4.0",
29
- "@solexllc/usx-theme": "0.5.0",
30
- "@solexllc/usx-uswds-fixes": "0.1.9",
28
+ "@solexllc/usx": "0.5.0",
29
+ "@solexllc/usx-theme": "0.6.0",
30
+ "@solexllc/usx-uswds-fixes": "0.1.10",
31
31
  "classnames": "^2.5.1",
32
32
  "prop-types": "^15.8.1"
33
33
  },
@@ -43,6 +43,7 @@
43
43
  "react-dom": ">=17"
44
44
  },
45
45
  "scripts": {
46
- "build": "vite build"
46
+ "build": "vite build",
47
+ "test": "pnpm build && node test/asset-url-check.mjs"
47
48
  }
48
49
  }
package/src/assets.ts ADDED
@@ -0,0 +1,16 @@
1
+ declare global {
2
+ interface Window {
3
+ usxBaseUrl?: string;
4
+ }
5
+ }
6
+
7
+ export function getAssetUrl(assetPath: string, staticBaseUrl?: string): string {
8
+ if (/^[a-z][a-z\d+.-]*:/i.test(assetPath)) return assetPath;
9
+ const base = staticBaseUrl || (typeof window !== 'undefined' && window.usxBaseUrl) || '/';
10
+ return `${base.replace(/\/+$/, '')}/${assetPath.replace(/^\/+/, '')}`;
11
+ }
12
+
13
+ export function getAssetSrcSet(srcSet: string, staticBaseUrl?: string): string {
14
+ return srcSet.replace(/(^\s*|,\s*)(\S*[^,\s])(?=,?(?:\s|$))/g, (_match, separator, url) =>
15
+ `${separator}${getAssetUrl(url, staticBaseUrl)}`);
16
+ }
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import ClassNames from 'classnames';
3
+ import Icon from '../icon/Icon';
3
4
 
4
5
  export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
5
6
  heading?: string;
@@ -12,6 +13,7 @@ export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
12
13
  ariaLabel?: string;
13
14
  ariaLabelledby?: string;
14
15
  onDismiss?: () => void;
16
+ staticBaseUrl?: string;
15
17
  children?: React.ReactNode;
16
18
  }
17
19
 
@@ -26,6 +28,7 @@ export default function Alert({
26
28
  ariaLabel,
27
29
  ariaLabelledby,
28
30
  onDismiss = undefined,
31
+ staticBaseUrl,
29
32
  children = null,
30
33
  ...props
31
34
  }: AlertProps) {
@@ -77,9 +80,7 @@ export default function Alert({
77
80
  )}
78
81
  {onDismiss && (
79
82
  <button className="usx-alert__dismiss" aria-label="Dismiss alert" onClick={onDismiss}>
80
- <svg className="usa-icon usa-icon--size-3" aria-hidden="true" focusable="false" role="img">
81
- <use href="./img/sprite.svg#close" />
82
- </svg>
83
+ <Icon name="close" size={3} staticBaseUrl={staticBaseUrl} />
83
84
  </button>
84
85
  )}
85
86
  </div>