You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+87-22Lines changed: 87 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,39 @@
8
8
9
9
This repo contains a set of components for displaying and interacting with material science data. These components provide the building blocks for the interactive components of the Materials Project website.
10
10
11
-
## Local development
11
+
## Docs and Examples
12
12
13
-
### Getting started
13
+
Check out the [mp-react-components storybook](https://materialsproject.github.io/mp-react-components/) to see examples and documentation for each component in this library.
14
14
15
-
First, clone the mp-react-components repo: `git clone [email protected]:materialsproject/mp-react-components.git`
15
+
## Getting Started with Local Development
16
16
17
-
From inside the top directory, install the dependencies using: `npm install`
All the components are located in `src/components`
24
46
@@ -32,13 +54,56 @@ The file structure for each component should look like the following:
32
54
-`MyComponent.css`
33
55
-`MyComponent.test.tsx`
34
56
35
-
### Exporting components
57
+
### Testing Components During Development
58
+
59
+
To see how your component looks and behaves while you are developing it, you have a few different options. When you start the app locally, the main entry point that determines what is rendered is in `src/app.tsx`. Because this is a component library and not a fully integrated app, the `app.tsx` file exists solely as a testing sandbox. A simple routing structure has been setup to test out different kinds of pages in a react-only environment. These test pages live in the `src/pages` directory. When testing a new component, you can use it inside of one of the existing pages or you can create a new page. There is also the `Sandbox` page within the `pages` directory that is intended to be cleared out any time and used to test new discrete components.
60
+
61
+
If you prefer, you can also test your component inside of storybook. To do this, create a new story within the `src/stories` directory. See the Storybook section below for more info about Storybook.
62
+
63
+
### Classes and Styles
64
+
65
+
By convention, almost all components are given a top-level class which is the name of the component converted into kabob-case and prefixed with "mpc-". For example, the `DataBlock` component has the class `mpc-data-block`. The `className` prop for any component should extend the default class rather than replace it.
66
+
67
+
The components in this library are intended to be used with the Bulma CSS Framework. For that reason, many bulma classes and component patterns are utilized within the components.
68
+
69
+
### Test ID's
70
+
71
+
Also by convention, almost all components are given a "test id" via the attribute `data-testid`. In some cases, a component may have multiple elements with test id's. These id's make it easier to select the components and their testable parts within the unit tests.
72
+
73
+
### Component Utils
74
+
75
+
For more complicated components like `MaterialsInput` and `SearchUI`, some of the re-usable or complex functions are housed in a `utils.tsx` file within the component folder. For example, all of the validation methods for the `MaterialsInput` can be found in `MaterialsInput/utils.tsx`.
36
76
37
-
To add a component to the list of components exported by this library, import and add the component to `src/index.ts`
77
+
Other utils that are used across multiple components can be found in the higher-level `src/utils` directory. For example, the functions for initializing table columns can be found in `src/utils/table.tsx`.
38
78
39
-
### Developing with dash-mp-components
79
+
### Exporting Components
40
80
41
-
If you have a local version of `dash-mp-components` and `mp-react-components`, you'll probably
81
+
Any component that you want to be usable when this library is imported as a third-party node module must be added to the exports list in `src/index.ts`.
82
+
83
+
## Deploying to npm
84
+
85
+
### Automated Pre-releases
86
+
87
+
Every push to the `main` branch triggers a build. If the build is succesfull, a snapshot is pushed
88
+
to npm, as a tagged package. To use the latest snapshot, type the following command
Run `npm version minor -m "Upgrade to %s"` to add a tag. Once the tag is pushed, an action will
102
+
build the components and push the package to build to npm
103
+
104
+
## Developing with dash-mp-components
105
+
106
+
If you have a local version of `dash-mp-components` and `mp-react-components`, you may
42
107
want to use the local version of `mp-react-components` for a better development workflow.
43
108
Running those commands will tell `NPM` to use your local version of `mp-react-components`
44
109
@@ -47,26 +112,26 @@ Running those commands will tell `NPM` to use your local version of `mp-react-co
47
112
npm link <REACT_MP_HOME>
48
113
```
49
114
50
-
## Deploy to npm
115
+
However, you can also push to the `main` branch to publish a new snapshot on npm whenever you are ready to start porting and testing your changes in dash-mp-components. Once the new snapshot is published, you will simply need to re-run these commands from your local dash-mp-components repo:
This library uses [Storybook](https://storybook.js.org/) to document the components and their usage. All of the exported components have a set of "stories" that showcase different examples of how to use the component and its props. The stories can be found inside of `src/stories`.
58
125
59
-
Every push triggers a build. If the build is succesfull, a snapshot is pushed
60
-
to npm, as a tagged package. To use the latest snapshot, type the following command
Storybook is configured using webpack and various plugins offered by Storybook. The config can be found in `.storybook/main.js`. Note that in general, all of the `@storybook/` dependencies should be using the same version as each other. This can occasionally cause issues with the storybook build.
63
129
64
-
### Automatically(TODO)
130
+
### Story Order and Styles
65
131
66
-
Run `npm version minor -m "Upgrade to %s"` to add a tag. Once the tag is pushed, an action will
67
-
build the components and push the package to build to npm
132
+
The order and hierarchy of the stories are set in `.storybook/preview.js`. This file is also where styles are imported into the storybook. Any styles that the storybook needs that aren't already imported into the components themselves should be included here.
0 commit comments