Re-useable React components based on the SendGrid Style Guide. See them in action here.
Make sure your project has all required dependencies and development dependencies installed.
npm install
cd ~/ui-components/packages/ui-components
npm link
> info You can now run `npm link "@sendgrid/ui-components"` in the projects where you want to use this package and it will be used instead.
cd ~/ui-components/
npx tsc --newline lf --watch
cd ~/myCoolProject/
npm link "@sendgrid/ui-components"
List of available components in Available Components section.
You can import just the components that you need.
import Badge from '@sendgrid/ui-components/badge';
Importing all of UI Components is discouraged and will be deprecated in a a future version of UI Components.
import { Badge } from '@sendgrid/ui-components';
UI-Components uses a mix of module styles and global styles to insert style guide. To use module styles for each individual component, you'll need to update your webpack config to parse module styles from files with the naming convention .module.scss
.
config.module.rules.push({
test: /\.module.scss$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('css-loader'),
options: {
sourceMap: true,
importLoaders: 1,
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: true,
modules: true,
importLoaders: 1,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
],
});
To use the global application styles included with styleguide (such as typography, reset, tables, and more), you'll need to include the following in your root component:
import '../path_to_uicomponents/packages/styles/global/main.scss';
After running npm install
and ensuring that style-guide is pulled properly just run npm run storybook
and you should be good to go!
For many components, it's useful for testing to have attributes that make them easy to query for and select.
For this, use attributes={{'data-test':"some-test-id}}"
as an attribute that describes the component. If it's possible, you can and should include the data-test
attribute to create a unique identifier.
Nota bene: Stateful components are deprecated and should not be used in production projects.
State is hard and all of the UI components should be purely presentational. But, that makes them hard to test out in Storybook. The stateful components (e.g. StatefulTextInput
) are solely for working with Storybook and are not supported or endorsed in any way. Think of them as a private API. They can be removed at any time. You've been warned.
See CONTRIBUTING.md
Install project dependencies with:
npm ci
When making a pull request, make sure the title has a semantic version bump level defined (#major, #minor, or #patch).
Semantic versioning bumps are used to know when to update the @sendgrid/ui-components npm package. Patches and minor changes will be updated automatically, but major changes will update if you update your npm package version manually.
More information: https://semver.org/
npm run start
: This is an alias fornpm run storybook
npm run storybook
: Start Storybook on port 6006.npm run build
: Builds the assets for deployment.npm run lint
: Runs the linter.npm run lint-fix
: Runs the linter and auto-fixes the errors it can auto-fix.npm run test
: Run the unit tests.npm run snapshot
: Update snapshot tests. Make sure you run the tests first and you're not overwriting snapshots by accident.npm run lint-snapshot
: A combination ofnpm run lint
andnpm run snapshot
.npm run ci-test
: Test used for the CI build (doesn't use interactive mode).npm run build-storybook
: Build a deployable version of the Storybook.npm run prepare
: Used by npm to build the assets before publishing.npm run image-snapshots
: Builds a static index.html file and runs image snapshot tests.npm run update-icon-types
: Pull latest styleguide css and update the types of icon to match all found instances of sg-icon-${type}
To update icons with the latest from StyleGuide follow these steps to change the font files and update necessary classes and variables.
- Download
eot
,ttf
,woff
,woff2
files from StyleGuide Icons - Replace files in the icons directory with those that were downloaded
- Add new variable to the variables file with the unicode value found in the StyleGuide SVG file
- Add new style class for the icon in icon.module.scss prepended with
.sg-icon-
and use the variables that were created in step 3 - Run
npm run update-icon-types
to add the new icon as a type in icons.ts
To make sure your additions don't break UI Components, run npm run test
, which will test all of your changed *.test.*
files and show a coverage report. To check image snapshots run npm run image-snapshots
updating and other commands can be passed through to jest like npm run image-snapshots -- -u
.
Image Snapshots & Docker:
- Since we run image snapshots in Buildkite with docker we need to run them locally with docker as well because different OSs render fonts and other things differently. We don't publish our docker image so you'll have to build and re-build the image any time our dependencies change in
package.json
. To do so just run the commanddocker-compose build build
. This should build the container and be ready to run.
Image Snapshots & Animations:
- We add a css rule in storybook when we detect the
file://
pattern that disables all animations on the page so we can get consistent image snapshots with animations.
Visit the Buildkite Master Branch and select the semantic version appropriate to your deployment and you should be off and away. Make sure to post in eng-guild-frontend
that a new version is going out.