0.1.1-beta.0 • Published 4 years ago

@palfi-ltd/ui-components v0.1.1-beta.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

Palfi Ltd UI Components Library

TSDX React User Guide

This project was bootstrapped using TSDX, as that provides sensible build tooling for creating TypeScript-based components.

If you’re new to TypeScript and React, checkout this handy cheatsheet

Commands

The recommended workflow is to run TSDX in one terminal:

yarn start

This builds to /dist and runs the project in watch mode so any edits you save inside src causes a rebuild to /dist.

Then run the storybook:

Storybook

Run inside another terminal:

yarn storybook

This loads all stories named *.stories.mdx. (Other formats are possible, but we have chosen to adopt Storybook Docs using MDX format.)

Stories should provide examples for how the component should be used.

NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.

Build and tests

To do a one-off build, use yarn build.

To run tests, use yarn test.

Configuration

Code quality is set up for you with prettier, husky, and lint-staged. Adjust the respective fields in package.json accordingly.

Jest

Jest tests are set up to run with yarn test. This runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

React Testing Library

We are using react-testing-library for tests. Please do not feel tempted to add enzyme - tests written with enzyme often stray into testing implementation details, and the pain is not worth it. react-testing-library will do everything you want/need.

Rollup

TSDX uses Rollup v1.x as a bundler and generates multiple rollup configs for various module formats and build settings. See Optimizations for details.

TypeScript

tsconfig.json is set up to interpret dom and esnext types, as well as react for jsx. Adjust according to your needs.

Continuous Integration

GitHub Actions

CI has been set up using GitHub Actions. All pull requests will be built, linted, and tested.

Merged pull requests are automatically published to NPM as a preview release with a next tag. All merges into master will also result in a new storybook deployment to GitHub Pages.

To trigger a release build, make a PR with a single (empty) commit with a comment of chore: release. This can be done with the following command:

git commit --allow-empty -m "chore: release"

Optimizations

Please see the main tsdx optimizations docs. In particular, know that you can take advantage of development-only optimizations:

// ./types/index.d.ts
declare var __DEV__: boolean;

// inside your code...
if (__DEV__) {
  console.log('foo');
}

You can also choose to install and use invariant and warning functions.

Module Formats

CJS, ESModules, and UMD module formats are supported.

The appropriate paths are configured in package.json and dist/index.js accordingly. Please report if any issues are found.