Giter Site home page Giter Site logo

kingler / ui-components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 0xtheprodev/ui-components

0.0 1.0 0.0 100.24 MB

Reusable React components for SendGrid's applications

Home Page: http://styleguide.sendgrid.com/

License: MIT License

Shell 0.46% JavaScript 25.53% HTML 0.08% Dockerfile 0.31% CSS 32.90% TypeScript 40.69% Makefile 0.02%

ui-components's Introduction

SendGrid Logo

SendGrid UI Components

Twitter Follow GitHub contributors MIT licensed

Re-useable React components based on the SendGrid Style Guide. See them in action here.

Getting Started with UI Components in your project

Make sure your project has all required dependencies and development dependencies installed.

npm install

Using your local UI Components in your project

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.

Importing a Particular Component

You can import just the components that you need.

import Badge from '@sendgrid/ui-components/badge';

Importing UI Components into Your Project

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';

Getting Styles to Work

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';

Starting Storybook

After running npm install and ensuring that style-guide is pulled properly just run npm run storybook and you should be good to go!

Adding Test Hooks

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.

What are these Stateful Components?

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.

Contributing to UI Components

See CONTRIBUTING.md

Install project dependencies with:

npm ci

Semantic Versioning

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/

Available Commands

  • npm run start: This is an alias for npm 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 of npm run lint and npm 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}

Updating Icons

To update icons with the latest from StyleGuide follow these steps to change the font files and update necessary classes and variables.

  1. Download eot, ttf, woff, woff2 files from StyleGuide Icons
  2. Replace files in the icons directory with those that were downloaded
  3. Add new variable to the variables file with the unicode value found in the StyleGuide SVG file
  4. 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
  5. Run npm run update-icon-types to add the new icon as a type in icons.ts

Testing

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 command docker-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.

Deploying

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.

License

The MIT License (MIT)

ui-components's People

Contributors

stevekinney avatar chrischalstrom avatar mmissey avatar giantrobots avatar reedsa avatar ditofry avatar alexabreu avatar etjossem avatar alex-wicks avatar two24studios avatar rachelmulligan avatar krrishd avatar rossedfort avatar alfredlucero avatar hannahapuan avatar richbachman avatar martensonbj avatar cfree avatar anatolyyyyyy avatar productdana avatar duncanleung avatar inyee786 avatar jackreis avatar mauricetmeyer avatar vyaspranjal33 avatar rahulkumaran avatar s-hale avatar sanjaysingh avatar toddmoy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.