@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.
- package/README.md +132 -0
- package/dist/index.cjs +181 -182
- package/dist/index.js +181 -182
- package/package.json +6 -5
- package/src/assets.ts +16 -0
- package/src/components/alert/Alert.tsx +4 -3
- package/src/components/alert/alert.django.html +2 -3
- package/src/components/alert/config.json +15 -4
- package/src/components/banner/Banner.tsx +8 -6
- package/src/components/banner/banner.django.html +4 -5
- package/src/components/banner/config.json +5 -1
- package/src/components/button/Button.tsx +1 -1
- package/src/components/button/button.django.html +2 -2
- package/src/components/button/config.json +14 -6
- package/src/components/code/Code.tsx +4 -27
- package/src/components/code/code.django.html +3 -9
- package/src/components/code/config.json +4 -0
- package/src/components/copy-to-clipboard/CopyToClipboard.tsx +35 -24
- package/src/components/copy-to-clipboard/config.json +14 -7
- package/src/components/copy-to-clipboard/copy-to-clipboard.django.html +14 -14
- package/src/components/footer/Footer.tsx +26 -6
- package/src/components/footer/config.json +4 -0
- package/src/components/footer/footer.django.html +10 -9
- package/src/components/header/Branding.tsx +9 -6
- package/src/components/header/Header.tsx +3 -1
- package/src/components/header/config.json +4 -0
- package/src/components/header/header.django.html +5 -26
- package/src/components/header/header.html +10 -10
- package/src/components/icon/Icon.tsx +6 -3
- package/src/components/icon/config.json +12 -6
- package/src/components/icon/icon.django.html +6 -4
- package/src/components/image/Image.tsx +8 -4
- package/src/components/image/config.json +10 -2
- package/src/components/image/image.django.html +8 -6
- package/src/components/layout/config.json +9 -9
- package/src/components/layout/layout.django.html +1 -1
- package/src/components/spinner/Spinner.tsx +18 -25
- package/src/components/spinner/config.json +4 -0
- package/src/components/spinner/spinner.django.html +4 -6
- package/src/components/tooltip/Tooltip.tsx +4 -2
- package/src/components/tooltip/config.json +7 -2
- package/src/components/tooltip/tooltip.django.html +1 -1
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>/`
|