This guide explains how to set up and customize styles for the application which uses the U.S. Web Design System (USWDS) as a foundation. The application can integrate with veda-ui
for core feature components styled with USWDS or use react-uswds
for standalone UI elements like grid, buttons, inputs, modals, etc.
Note: If you're using the provided template, this setup is already configured. You can skip the initial steps unless you're starting from scratch or modifying the default structure.
To use USWDS-based styles:
-
Install Required Dependencies
Make sure
@uswds/uswds
andsass
are installed:npm install @uswds/uswds@^3.8.1 sass # or yarn add @uswds/uswds@^3.8.1 sass
-
Configure SASS
Update your
sassOptions
in thenext.config.js
file to include the necessary USWDS paths. This allows SASS to resolve and process the USWDS styles correctly:module.exports = { sassOptions: { includePaths: [ 'node_modules/@uswds/uswds', 'node_modules/@uswds/uswds/dist', 'node_modules/@uswds/uswds/packages', ], }, };
-
Import and customize styles
Create a custom theme configuration file (e.g.,
app/styles/_uswds-theme.scss
) to define your application's tokens such as colors, typography, and asset paths. This file allows you to adapt USWDS to your application's branding and design needs.Example
_uswds-theme.scss
:@use 'uswds-core' with ( $theme-image-path: '/img', $theme-font-path: '/fonts', $theme-show-notifications: false, $utilities-use-important: true, $theme-font-weight-semibold: '600', $theme-type-scale-md: 8, $theme-color-primary: 'blue-50', $theme-color-secondary: 'gold-30' );
Import your theme and other USWDS styles into a main SCSS file (e.g.,
app/styles/index.scss
) to be used in your application.@forward 'uswds-theme'; @forward 'uswds'; @use 'uswds-core' as *;
-
Include styles in the application
Import the SCSS file into the root of your application to apply the styles globally:
import './styles/index.scss'; import '@developmentseed/veda-ui/lib/main.css';
In addition to customizing the theme, you can use USWDS utility classes directly in your components for quick and consistent styling. Below is an example of using USWDS utility classes:
<div className="usa-section margin-top-3 padding-2">
<h1 className="margin-bottom-2">Heading 1</h1>
<p className="padding-left-1">
This is an example of using USWDS utility classes for spacing.
</p>
</div>
If further customization is needed, you can also use custom stylesheets alongside USWDS utility classes. For example:
-
Create a custom stylesheet file (e.g.,
custom-styles.scss
). -
Add your custom styles:
.custom-heading { @include u-padding-x(2); max-width: units("desktop"); @include at-media("desktop") { @include u-padding-x(4); } }
-
Import the stylesheet into the
styles/index.scss
entry file:@forward 'uswds-theme'; @forward 'uswds'; @use 'uswds-core' as *; @import 'custom-styles';
-
Use the custom class in your component:
<h1 className="custom-heading">Custom styled heading</h1>
- Refer to the USWDS documentation for a complete list of available utility classes, mixins and design tokens.