This PR makes project-wide changes to allow importing from files directly in addition to the index. Build and project configuration changes were made to ensure the package passes tests from https://arethetypeswrong.github.io/. All components were modified for one of the following reasons:
"use client" directive added for special components
library-specific source code moved to libSrc folder
src folder reserved for non-library code (ex: setupTests, custom rendering scenarios via vite preview or vite dev)
folder normalization (camelcase folder names for folders directly containing a component file only, otherwise lowercase)
missing exports added
component props types normalized (BaseXProps and XProps)
sibling components defined in the same file were moved to dedicated folder/file
utility functions moved to a utils module
constants moved to a constants module
fixtures moved to a fixtures module
base functional component and forwardRef outputs separated into their own files (X and XForwardRef)
_ref prop added to base component that the forwardRef version forwards its ref to (React 19 is standardizing ref being a prop on functional components and removing the need of forwardRef)
component modules only have default export
components with a clear parent element to spread props on that were not already spreading additional props now do
prop spreading on components happens after our predefined props instead of before, to ensure overridability
Some areas where we could use one of the react-uswds components instead of a jsx element (ex: Button, Grid) were updated to use those components instead.
A dedicated build script for handling the logic of building the library in various formats and related dependencies were added. Other build notes:
The DTS plugin is configured with an additional option to run a fixCjsDeclarations function for the cjs non-bundled export in order to move and rename the cjs d.ts extensions to proper d.cts
The project also now uses the USWDS' compile package via gulpfile to create the default settings css file (with all assets generated exposed).
In order to create compatible typescript declarations for both cjs and es modes, the module setting for typescript was changed to node16. This makes it required to include the extension on all relative imports (reflective of the fact this package is now esm by default and es modules have that import extension requirement. The isolatedModules option was also enabled, requiring type import/exports to be explicitly marked as type.
Add the jpandersen87/react-uswds#tree-shaking branch as your @trussworks/react-uswds dependency instead of from npm for your project
Verify your project continues to work (except for cases where you directly imported types from files that have had their paths changed from normalization)
Verify you can directly import from files instead of from index
Summary
This PR makes project-wide changes to allow importing from files directly in addition to the index. Build and project configuration changes were made to ensure the package passes tests from https://arethetypeswrong.github.io/. All components were modified for one of the following reasons:
libSrc
foldersrc
folder reserved for non-library code (ex: setupTests, custom rendering scenarios viavite preview
orvite dev
)utils
moduleconstants
modulefixtures
module_ref
prop added to base component that the forwardRef version forwards itsref
to (React 19 is standardizingref
being a prop on functional components and removing the need of forwardRef)Some areas where we could use one of the react-uswds components instead of a jsx element (ex: Button, Grid) were updated to use those components instead.
A dedicated build script for handling the logic of building the library in various formats and related dependencies were added. Other build notes:
DTS
plugin is configured with an additional option to run afixCjsDeclarations
function for the cjs non-bundled export in order to move and rename the cjsd.ts
extensions to properd.cts
The project also now uses the USWDS'
compile
package via gulpfile to create the default settings css file (with all assets generated exposed).In order to create compatible typescript declarations for both cjs and es modes, the
module
setting for typescript was changed tonode16
. This makes it required to include the extension on all relative imports (reflective of the fact this package is nowesm
by default andes
modules have that import extension requirement. TheisolatedModules
option was also enabled, requiring type import/exports to be explicitly marked astype
.The
.usa-tooltip__body
override was removed as its issue appears to have been resolved (https://github.com/uswds/uswds/issues/4458).Related Issues or PRs
N/A
How To Test
@trussworks/react-uswds
dependency instead of from npm for your project