@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
package/README.md CHANGED
@@ -4,6 +4,138 @@ This package uses a self-contained component structure where each component owns
4
4
 
5
5
  USWDS is treated as an external foundation. This package does not bundle USWDS assets; consuming applications should load USWDS styles in their own application bundle.
6
6
 
7
+ ## Asset URLs And Subpath Deployment
8
+
9
+ `usxBaseUrl` means the **static asset root**, not the application's routing
10
+ base. USX does not own routing. An app at `/application-root/` can serve its
11
+ assets at `/application-root/`, `/static/usx/`, or a separate static host.
12
+ It does not affect your router/framework's application base.
13
+
14
+ ### Browser Configuration
15
+
16
+ No configuration is needed when assets use the default root paths, such as
17
+ `/img/sprite.svg`. For assets hosted elsewhere, `window.usxBaseUrl` is an
18
+ optional prefix override. For example, assets under `/application-root/`
19
+ could use:
20
+
21
+ ```html
22
+ <script>window.usxBaseUrl = '/application-root/';</script>
23
+ ```
24
+
25
+ Banner, Icon, and Spinner then load `/application-root/img/us_flag_small.png`,
26
+ `/application-root/img/sprite.svg#check`, and
27
+ `/application-root/img/usx-sprite.svg#spinner`. Alert and copy-button icons use
28
+ the same base, as do icons nested in other components. The example path is not
29
+ a required deployment layout: the value reflects wherever your assets are
30
+ already served, independently of the page URL.
31
+
32
+ ### Per-Component Overrides
33
+
34
+ Banner, Icon, Spinner, Alert, Code, CopyToClipboard, Image, Header, and Footer accept an optional
35
+ `staticBaseUrl` string. Their built-in asset URLs resolve automatically:
36
+
37
+ 1. A non-empty `staticBaseUrl` prop.
38
+ 2. A non-empty `window.usxBaseUrl`.
39
+ 3. `/`.
40
+
41
+ For example, these two props keep the filename separate from its base:
42
+
43
+ ```jsx
44
+ <Banner flagSrc="flags/agency.png" staticBaseUrl="/other-assets/" />
45
+ <Icon name="check" staticBaseUrl="/other-assets/" />
46
+ ```
47
+
48
+ The flag becomes `/other-assets/flags/agency.png`; the icon uses
49
+ `/other-assets/img/sprite.svg#check`. Banner's other images and nested lock icon
50
+ use its override too. No helper call or manual concatenation is needed.
51
+ Trailing slashes on the base and leading slashes on asset paths are normalized.
52
+ An empty override falls back to the global; `staticBaseUrl="/"` explicitly
53
+ selects root even when the global points elsewhere. Fully qualified asset
54
+ URLs pass through unchanged. Icon/Spinner's legacy `staticUrlPrefix` remains
55
+ a full sprite-URL escape hatch; it bypasses base resolution.
56
+
57
+ Internal asset resolution reads the global during rendering, with no subscriptions or automatic
58
+ rerendering. When using a global override, define it before rendering. USX does not
59
+ infer an asset root from the current route.
60
+
61
+ Without `window`, `staticBaseUrl` still works and the default remains `/`.
62
+ For SSR, the same component prop on the server and client keeps asset URLs
63
+ consistent during hydration. No process-global configuration is needed.
64
+
65
+ ### Image And Branding Assets
66
+
67
+ Image resolves its source, responsive fallback, and every source-set candidate
68
+ against the asset base. Header and Footer resolve branding logos, inverse artwork,
69
+ and symbols internally; Footer also resolves social-image paths. Supply filenames
70
+ without looking up or concatenating the base:
71
+
72
+ ```jsx
73
+ import { Image } from '@solexllc/usx-react';
74
+
75
+ function AgencyLogo() {
76
+ return <Image src="img/agency-logo.svg" alt="Agency" />;
77
+ }
78
+ ```
79
+
80
+ Asset resolution is internal to USX; no URL helper is exported from the package.
81
+ Image, Header, Footer, and direct Branding usage accept `staticBaseUrl` overrides.
82
+ Fully qualified and data URLs remain unchanged, as do navigation and image-link
83
+ destinations. Already-prefixed root-relative image paths should be replaced with
84
+ asset-relative paths to avoid adding the base twice.
85
+ Use root-relative or fully qualified bases for reliable deep-link behavior;
86
+ relative bases resolve against the document URL and are usually unsuitable.
87
+
88
+ ### Asset Publishing
89
+
90
+ How files reach those URLs is up to your application and deployment tools.
91
+ USX generates URLs but does not copy files or serve them. Its default component
92
+ paths expect USWDS images under `img/`, alongside the USX sprite supplied as
93
+ `@solexllc/usx/src/img/usx-sprite.svg`, relative to the asset base.
94
+
95
+ The asset base does **not** rewrite CSS `url(...)`, stylesheet/script imports,
96
+ router links, or supplied HTML. Precompiled USWDS CSS references sibling
97
+ `img/` and `fonts/` directories; bundlers may instead resolve and emit those
98
+ assets using their own public/base URL. This setting does not change either
99
+ approach or require vendor Sass recompilation.
100
+
101
+ A fully qualified asset base can point to a static host, but browsers generally
102
+ block cross-origin external SVG `<use>` sprites, even with CORS headers.
103
+ Serve `sprite.svg` and `usx-sprite.svg` through the application's origin (for
104
+ example, a reverse proxy). The safest shared base is same-origin; use explicit
105
+ image URLs for CDN images, or `staticUrlPrefix` to override individual Icon and
106
+ Spinner sprites. A CDN-only base cannot make every default icon work.
107
+
108
+ ### Django And Static HTML
109
+
110
+ Django uses `STATIC_URL` instead of the browser global. The same six components
111
+ accept `staticBaseUrl`; without an override their `asset_url` template tag
112
+ delegates to Django's static-file resolver. The tag lives in the included
113
+ `components` tag library. For example:
114
+
115
+ ```django
116
+ {% banner flagSrc="flags/agency.png" staticBaseUrl="/other-assets/" %}{% endbanner %}
117
+ ```
118
+
119
+ `STATIC_URL` is independent of `FORCE_SCRIPT_NAME` or URL routing. An example
120
+ static-file configuration is:
121
+
122
+ ```python
123
+ STATIC_URL = '/application-root/static/usx/'
124
+ STATICFILES_DIRS = [
125
+ BASE_DIR / 'node_modules/@uswds/uswds/dist',
126
+ ('img', BASE_DIR / 'node_modules/@solexllc/usx/src/img'),
127
+ ]
128
+ ```
129
+
130
+ Run `collectstatic` into your configured `STATIC_ROOT` and serve its output at
131
+ `STATIC_URL`. Preserve the `css/`, `img/`, and `fonts/` layout. The Storybook Django deployment exposes
132
+ this setting as `DJANGO_STATIC_URL`; its app mount is `DJANGO_FORCE_SCRIPT_NAME`.
133
+
134
+ Canonical `.html` files are reference markup, not a runtime URL resolver.
135
+ Replace their sample `/img/...` and `/assets/img/...` URLs with your deployed
136
+ asset paths when using that markup directly, or render the Django templates.
137
+ A browser global alone cannot rewrite literal URLs in static HTML.
138
+
7
139
  ## Structure
8
140
 
9
141
  - `src/components/<component>/`
@@ -98,7 +230,8 @@ loading component styles. Existing `$max-layout-width` and `$max-sidebar-width`
98
230
  remain the static defaults when the new width settings are unset. Runtime gutter
99
231
  hooks take precedence in the themed build. `$usx-layout-breakpoint` defaults to
100
232
  `$breakpoint-desktop` (1024px) and accepts a CSS length such as `880px`.
101
- It controls the outer gutters, not sidebar visibility. Configure it at
233
+ It controls outer gutters and USX-owned desktop transitions, including Hero,
234
+ MiscBanner, Pagination, and `at-media('desktop')`, not sidebar visibility. Configure it at
102
235
  compile time, since CSS custom properties cannot set media-query thresholds.
103
236
 
104
237
  CSS container queries show the expand/contract button only when the two widths
@@ -108,18 +241,36 @@ The expanded state is preserved when resizing temporarily removes the difference
108
241
  Django and static HTML use the same sizing and visibility rules.
109
242
 
110
243
  The `layout.sizing()` mixin accepts `$gutter-mobile` and `$gutter` lengths
111
- (defaults: 12px and 32px). It uses these for static padding and subtracts them
244
+ (defaults: `$usx-layout-gutter-mobile-default`, 12px, and
245
+ `$usx-layout-gutter-default`, 32px). It uses these for static padding and subtracts them
112
246
  from the expansion thresholds at the corresponding viewport breakpoint.
113
247
  For custom gutters, pass the same lengths used by your runtime gutter tokens
114
248
  or static Sass overrides. CSS size queries cannot read custom properties, so
115
249
  changing runtime gutters alone does not update the compiled button threshold.
116
250
  The compact comparison uses `$gutter-mobile: 1rem` and `$gutter: 2.5rem`.
117
251
 
118
- The custom grid does not require `grid-row`, `grid-col`, or `grid-gap`. USWDS's
119
- site-margin settings still control its own containers; align those settings
120
- with the USX gutter values when mixing both container types. Do not add a
252
+ The custom grid does not require `grid-row`, `grid-col`, or `grid-gap`. Shared
253
+ `grid-container`, Banner, Header, Hero, MiscBanner, and Identifier containers use
254
+ the same maximum and responsive gutters. Hero's horizontal tablet padding now
255
+ matches Layout rather than adding a separate intermediate gutter. Do not add a
121
256
  second padded `grid-container` around Layout unless nested gutters are intended.
122
257
 
258
+ Use `@include layout-container` for new page-shell containers, or
259
+ `@include layout-gutters` for padding alone. `at-media('desktop', 'max')` emits
260
+ an exclusive below-desktop query; `at-media('tablet')` reads
261
+ `$breakpoint-tablet`. The legacy `at-media('mobile')` means below tablet.
262
+ Legacy width and breakpoint variables remain default aliases, but new styles
263
+ should consume the `$usx-layout-*` settings and media helpers.
264
+
265
+ Load USWDS's precompiled CSS unchanged, then load USX as an overlay. No USWDS Sass
266
+ configuration or compilation is required. USX settings do not redefine upstream
267
+ `desktop:*` or `tablet:*` utilities. Header's mobile drawer and desktop structure
268
+ remain controlled by upstream CSS; use `at-media('uswds-header')` for appearance
269
+ overrides that must follow that transition. Its shared 64em compatibility value
270
+ is not a USWDS customization. Header container widths and gutters still use USX
271
+ layout settings. Use USX-owned selectors and media helpers when custom responsive
272
+ behavior is needed rather than changing the meaning of upstream utility classes.
273
+
123
274
  Layout stories use fullscreen previews. `ResponsiveComparison` and
124
275
  `ThemedComparison` cover no, left, right, and both sidebars. When checking
125
276
  expansion, expand at desktop width and resize without reloading the story.