Skip to content

Commit 7a4a51e

Browse files
committed
Update readme and other docstrings
1 parent c9b064f commit 7a4a51e

File tree

7 files changed

+98
-93
lines changed

7 files changed

+98
-93
lines changed

README.md

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,39 @@
88

99
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.
1010

11-
## Local development
11+
## Docs and Examples
1212

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.
1414

15-
First, clone the mp-react-components repo: `git clone [email protected]:materialsproject/mp-react-components.git`
15+
## Getting Started with Local Development
1616

17-
From inside the top directory, install the dependencies using: `npm install`
17+
Clone the mp-react-components repo:
1818

19-
Deploy the app using: `npm start`
19+
```
20+
git clone [email protected]:materialsproject/mp-react-components.git
21+
```
22+
23+
From inside the top directory, install the dependencies:
24+
25+
```
26+
npm install
27+
```
28+
29+
Deploy the app to https://localhost:3000:
30+
31+
```
32+
npm start
33+
```
34+
35+
## Installing as a Node Module
36+
37+
Install the latest snapshot of mp-react-components:
2038

21-
### Developing components
39+
```
40+
npm install @materialsproject/mp-react-components@next
41+
```
42+
43+
## Developing Components
2244

2345
All the components are located in `src/components`
2446

@@ -32,13 +54,56 @@ The file structure for each component should look like the following:
3254
- `MyComponent.css`
3355
- `MyComponent.test.tsx`
3456

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`.
3676

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`.
3878

39-
### Developing with dash-mp-components
79+
### Exporting Components
4080

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
89+
90+
```
91+
npm install @materialsproject/mp-react-components@next
92+
```
93+
94+
### Manual Release
95+
96+
Use `npm build-publish` to build the project.
97+
Use `npm publish` to push to npm
98+
99+
### Automated Minor Release (un-tested)
100+
101+
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
42107
want to use the local version of `mp-react-components` for a better development workflow.
43108
Running those commands will tell `NPM` to use your local version of `mp-react-components`
44109

@@ -47,26 +112,26 @@ Running those commands will tell `NPM` to use your local version of `mp-react-co
47112
npm link <REACT_MP_HOME>
48113
```
49114

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:
51116

52-
### Manually
117+
```
118+
npm install @materialsproject/mp-react-components@next
119+
npm run build
120+
```
53121

54-
Use `npm build-publish` to build the project.
55-
Use `npm publish` to push to npm
122+
## Storybook
56123

57-
#### Pre-releases
124+
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`.
58125

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
126+
### Storybook Configuration
61127

62-
`npm install @materialsproject/mp-react-components@next`
128+
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.
63129

64-
### Automatically(TODO)
130+
### Story Order and Styles
65131

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.
68133

69-
## Deploy storybook to github pages
134+
### Deploy storybook to github pages
70135

71136
This will **build** and **deploy** the storybook.
72137
Stories are defined in `./src/stories`

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
"build-prod": "parcel build src/index.html",
1919
"build-publish": "rollup -c",
2020
"test": "jest --env=jsdom",
21-
"docz:dev": "docz dev",
22-
"docz:build": "docz build",
23-
"docz:serve": "docz build && docz serve",
2421
"lint:yaml": "yamllint ./.github/workflows/*.yml",
2522
"postversion": "git push && git push --tags",
2623
"storybook": "start-storybook -p 6006",

src/components/data-display/Modal/ModalContextProvider.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ export interface ModalContextProviderProps {
2626
* state using the ModalContext or a dash callback on the active prop.
2727
*/
2828
forceAction?: boolean;
29-
30-
/**
31-
* Set to true if the inner modal is a Drawer component instead of a Modal.
32-
* This will prevent the html container from being clipped as is done when a modal is activated.
33-
*/
34-
isDrawer?: boolean;
3529
}
3630

3731
const ModalContext = React.createContext<ModalState | undefined>(undefined);
@@ -51,9 +45,9 @@ export const ModalContextProvider: React.FC<ModalContextProviderProps> = (props)
5145
* Prevent document scrolling when active
5246
*/
5347
useEffect(() => {
54-
if (!props.isDrawer && active) {
48+
if (active) {
5549
document.documentElement.classList.add('is-clipped');
56-
} else if (!props.isDrawer) {
50+
} else {
5751
document.documentElement.classList.remove('is-clipped');
5852
}
5953
props.setProps!({ active: active });

src/components/data-display/SearchUI/SearchUIDataCards/SearchUIDataCards.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const SearchUIDataCards: React.FC = () => {
2828
return (
2929
<div data-testid="mpc-search-ui-data-cards" className="mpc-search-ui-data-cards">
3030
<CustomPaginator />
31-
{/* <div className="mpc-search-ui-data-cards-container">
32-
{state.results.map((d, i) => (
31+
<div className="mpc-search-ui-data-cards-container">
32+
{state.results!.map((d, i) => (
3333
<DataCard
3434
key={`mpc-data-card-${i}`}
3535
className="box mpc-search-ui-data-card"
@@ -46,7 +46,7 @@ export const SearchUIDataCards: React.FC = () => {
4646
}
4747
/>
4848
))}
49-
</div> */}
49+
</div>
5050
<CustomPaginator />
5151
</div>
5252
);

src/components/data-display/SearchUI/types.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
import { DecodedValueMap, QueryParamConfigMap } from 'use-query-params';
2-
import { MaterialsInputType } from '../../data-entry/MaterialsInput';
3-
import { InputHelpItem } from '../../data-entry/MaterialsInput/InputHelp/InputHelp';
4-
import { PeriodicTableMode } from '../../data-entry/MaterialsInput/MaterialsInput';
5-
import { MaterialsInputTypesMap } from '../../data-entry/MaterialsInput/utils';
6-
import { SearchUIDataCards } from './SearchUIDataCards';
72
import { SearchUIDataTable } from './SearchUIDataTable';
83
import { SearchUISynthesisRecipeCards } from './SearchUISynthesisRecipeCards';
94

10-
export enum FilterId {
11-
ELEMENTS = 'elements',
12-
VOLUME = 'volume',
13-
DENSITY = 'density',
14-
MP_ID = 'task_ids',
15-
FORMULA = 'formula',
16-
NELEMENTS = 'nelements'
17-
}
18-
195
/**
206
* See storybook for documentation
217
*/
@@ -388,13 +374,18 @@ export interface SearchUIContainerProps {
388374
*/
389375
disableRichColumnHeaders?: boolean;
390376
/**
391-
*
377+
* This prop is set automatically.
378+
* Array of results currently rendered in the UI.
392379
*/
393380
results?: any[];
394381
/**
395382
* Endpoint to use for fallback free text material searches against the Matscholar API.
396383
*/
397384
matscholarEndpoint?: string;
385+
/**
386+
* EXPERIMENTAL
387+
*/
388+
cardOptions?: any;
398389
}
399390

400391
export interface SearchState extends SearchUIContainerProps {

styleguide.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

webpack.config.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)