Skip to content

Commit c9b064f

Browse files
committed
Add comments to MaterialsInput components
1 parent 7797aed commit c9b064f

File tree

9 files changed

+170
-11
lines changed

9 files changed

+170
-11
lines changed

.storybook/main.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ module.exports = {
1313
webpackFinal: async (config) => {
1414
config.module.rules.push({
1515
test: /\.less$/,
16-
use: ['style-loader', 'css-loader', 'less-loader']
16+
use: [
17+
'style-loader',
18+
{
19+
loader: 'css-loader',
20+
options: {
21+
modules: false
22+
}
23+
},
24+
{
25+
loader: 'less-loader',
26+
options: {
27+
lessOptions: {
28+
javascriptEnabled: true
29+
}
30+
}
31+
}
32+
]
1733
});
1834
return config;
1935
}

src/components/crystal-toolkit/CrystalToolkitScene/CrystalToolkitScene.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,30 @@ export interface CrystalToolkitSceneProps {
193193
* }
194194
*/
195195
customCameraState?: CameraState;
196+
/**
197+
* Determines if control bar is visible
198+
* @default true
199+
*/
196200
showControls?: boolean;
201+
/**
202+
* Determines if expand button in control bar is visible
203+
* @default true
204+
*/
197205
showExpandButton?: boolean;
206+
/**
207+
* Determines if image download button in control bar is visible
208+
* @default true
209+
*/
198210
showImageButton?: boolean;
211+
/**
212+
* Determines if file export button in control bar is visible
213+
* @default true
214+
*/
199215
showExportButton?: boolean;
216+
/**
217+
* Determines if return to original position button in control bar is visible
218+
* @default true
219+
*/
200220
showPositionButton?: boolean;
201221
}
202222

@@ -371,6 +391,11 @@ export const CrystalToolkitScene: React.FC<CrystalToolkitSceneProps> = ({
371391
},
372392
mountNodeDebugRef.current!
373393
));
394+
/**
395+
* I believe this can be removed because image requesting is now handled by
396+
* the image dropdown.
397+
* Unclear what the role of the observable is here.
398+
*/
374399
const subscription = subscribe(({ filetype }) => requestImage(filetype, _s));
375400
return () => {
376401
// clean up code
@@ -644,11 +669,6 @@ export const CrystalToolkitScene: React.FC<CrystalToolkitSceneProps> = ({
644669
domain={[0, 100]}
645670
onChange={(values) => scene.current!.updateTime(values[0] / 100)}
646671
/>
647-
// <SimpleSlider
648-
// onUpdate={(a) => {
649-
// scene.current!.updateTime(a / 100);
650-
// }}
651-
// />
652672
)}
653673
</div>
654674
</div>

src/components/crystal-toolkit/DynamicCrystalToolkitScene/DynamicCrystalToolkitScene.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { CrystalToolkitScene } from '../CrystalToolkitScene';
33
import { boolean, number, object, select, withKnobs } from '@storybook/addon-knobs';
44
import { AnimationStyle, Renderer } from '../scene/constants';
55

6+
/**
7+
* Component for generating a CrystalToolkitScene dynamically from user-supplied JSON input
8+
*/
69
export const DynamicCrystalToolkitScene: React.FC = () => {
710
const [sceneData, setSceneData] = useState<Object | null>(null);
811
const [showScene, setShowScene] = useState(false);

src/components/crystal-toolkit/graph.component.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import PropTypes, { InferProps } from 'prop-types';
33
import Graph from 'react-graph-vis';
44
import './vis.less';
55

6+
/**
7+
* Render linked data in a force-directed graph.
8+
* This was an experimental component and is not being used anywhere at the moment.
9+
*/
610
export default function ReactGraphComponent(
711
props: InferProps<typeof ReactGraphComponent.propTypes>
812
) {
@@ -25,7 +29,7 @@ export default function ReactGraphComponent(
2529
<Graph
2630
graph={props.graph}
2731
options={props.options}
28-
getNetwork={network => (network.current = network)}
32+
getNetwork={(network) => (network.current = network)}
2933
/>
3034
);
3135
}

src/components/crystal-toolkit/scene/download-event.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
*
33
* A very simple and naive singleton event bus.
4+
* Unclear if this is still necessary. Can likely delete this whole file.
45
*
56
*/
67

src/components/data-entry/MaterialsInput/FormulaAutocomplete/FormulaAutocomplete.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface Props {
2323
let requestCount = 0;
2424

2525
/**
26-
*
26+
* Component for displaying dynamic formula suggestions based on a current input value.
2727
*/
2828
export const FormulaAutocomplete: React.FC<Props> = (props) => {
2929
const [show, setShow] = useState(props.show);

src/components/data-entry/MaterialsInput/InputHelp/InputHelp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface Props {
1313
}
1414

1515
/**
16-
* Interactive help menu to display below MaterialsInput
16+
* Interactive help menu to display below `MaterialsInput`
1717
*/
1818
export const InputHelp: React.FC<Props> = (props) => {
1919
return (

src/components/data-entry/MaterialsInput/MaterialsInput.tsx

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,143 @@ export enum PeriodicTableMode {
4848
NONE = 'none'
4949
}
5050

51+
/**
52+
* Props for `MaterialsInput` that get drilled into `MaterialsInputBox`
53+
*/
5154
export interface MaterialsInputSharedProps {
55+
/**
56+
* The current/initial value of the input.
57+
* This value will be dynamically updated so it can be accessed via dash callbacks.
58+
*/
5259
value?: string;
60+
/**
61+
* The current/initial type of the input.
62+
* The type value changes dynamically based on the input value.
63+
*/
5364
type?: MaterialsInputType;
65+
/**
66+
* List of input types that are allowed to be entered into the input.
67+
* This determines which types the component will dynamically detect.
68+
* Each item in the list must be a valid `MaterialsInputType`.
69+
* e.g. `['elements', 'checmical_system', 'formula']`
70+
*/
5471
allowedInputTypes?: MaterialsInputType[];
72+
/**
73+
* Text to display in the input when there is no value.
74+
*/
5575
placeholder?: string;
76+
/**
77+
* Text to display in the error tooltip when an invalid input value is detected.
78+
*/
5679
errorMessage?: string;
80+
/**
81+
* Class name(s) to apply to the input element in addition to the
82+
* 'input' class which is added automatically.
83+
*/
5784
inputClassName?: string;
85+
/**
86+
* API URL route to use to send autocomplete requests to when typing in a formula.
87+
*/
5888
autocompleteFormulaUrl?: string;
89+
/**
90+
* API key to send along with the autocomplete request.
91+
*/
5992
autocompleteApiKey?: string;
93+
/**
94+
* List of labels and examples to display under the input when it is focused and there is no value.
95+
* Each item must be an object with a `label` string and/or `examples` array.
96+
* Strings in `examples` arrays will be clickable and will fill the input value with the example.
97+
* e.g.
98+
* `[
99+
* {label: 'Search by formula', examples: ['NaCl', 'MnO2']},
100+
* {label: 'See more examples in the documentation'}
101+
* ]`
102+
*/
60103
helpItems?: InputHelpItem[];
104+
/**
105+
* The maximum number of elements that can be entered or selected in the periodic table.
106+
*/
61107
maxElementSelectable?: number;
108+
/**
109+
* This prop is used internally by `MaterialsInputBox` and will be ignored if set on `MaterialsInput`.
110+
*/
62111
showAutocomplete?: boolean;
112+
/**
113+
* This prop is used internally by `MaterialsInputBox` and will be ignored if set on `MaterialsInput`.
114+
*/
63115
setShowAutocomplete?: (value: boolean) => any;
116+
/**
117+
* Function to run when the value changes.
118+
*/
64119
onChange?: (value: string) => any;
120+
/**
121+
* Function to run when the input type changes.
122+
*/
65123
onInputTypeChange?: (type: MaterialsInputType) => any;
124+
/**
125+
* Function to run when the submit button is clicked.
126+
*/
66127
onSubmit?: (event: React.FormEvent | React.MouseEvent, value?: string, filterProps?: any) => any;
67128
}
68129

130+
/**
131+
* Props that are exclusively for `MaterialsInput` (not drilled into `MaterialsInputBox`)
132+
*/
69133
export interface MaterialsInputProps extends MaterialsInputSharedProps {
134+
/**
135+
* The ID used to identify this component in Dash callbacks
136+
*/
70137
id?: string;
138+
/**
139+
* Dash-assigned callback that should be called whenever any of the
140+
* properties change
141+
*/
71142
setProps?: (value: any) => any;
143+
/**
144+
* Class name(s) to append to the component's default class (`mpc-materials-input`)
145+
*/
72146
className?: string;
147+
/**
148+
* Number of milliseconds to wait before registering the value change.
149+
*/
73150
debounce?: number;
151+
/**
152+
* Control how or if the periodic table should display with the input.
153+
* Must be a valid `PeriodicTableMode` ('toggle', 'focus', or 'none').
154+
*/
74155
periodicTableMode?: PeriodicTableMode;
156+
/**
157+
* An alternative way to turn off the periodic table.
158+
* This could likely be removed in the future.
159+
*/
75160
hidePeriodicTable?: boolean;
161+
/**
162+
* Set to true to display a left-hand dropdown for displaying and changing
163+
* the input type.
164+
*/
76165
showTypeDropdown?: boolean;
166+
/**
167+
* Set to true to show a submit button on the right-hand side of the input.
168+
*/
77169
showSubmitButton?: boolean;
170+
/**
171+
* This prop can be used by dash callbacks to listen for user clicks on the submit button.
172+
*/
78173
submitButtonClicks?: number;
174+
/**
175+
* Text to display in the submit button.
176+
*/
79177
submitButtonText?: string;
178+
/**
179+
* Text to display in a label box on the left-hand side of the input.
180+
* If none is supplied, there will not be a label rendered.
181+
*/
80182
label?: string;
183+
/**
184+
* Hide the wildcard asterisk button with the periodic table.
185+
* Use this for situations where you want to support element or chemical system
186+
* selections, but you can't support wildcard searches.
187+
*/
81188
hideWildcardButton?: boolean;
82189
/**
83190
* Text to display in the periodic table help box when
@@ -91,12 +198,20 @@ export interface MaterialsInputProps extends MaterialsInputSharedProps {
91198
* Supports markdown.
92199
*/
93200
elementsSelectHelpText?: string;
201+
/**
202+
* This prop is controlled automatically.
203+
* It tells you whether the input is in the loading state or not.
204+
*/
94205
loading?: boolean;
206+
/**
207+
* Function to call when the input value changes that will pass the
208+
* updated props object to the function.
209+
*/
95210
onPropsChange?: (propsObject: any) => void;
96211
}
97212

98213
/**
99-
* An input field component for searching by mp-id, elements, or formula.
214+
* An input field component for searching by mp-id, elements, chemical system, formula, or plain text.
100215
* Renders a text input and a periodic table within a PeriodicContext to support
101216
* two-way binding between the input and periodic table.
102217
* i.e. when elements are typed into the field, they are selected in the table,

src/components/periodic-table/periodic-table-component/periodic-table.module.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@import '../table-variable.less';
22
@import '../../../assets/mixins.less';
33

4-
// 18 / 7 Periods
4+
// 18 / 7 Periods test
55
.table-legend-container {
66
justify-content: center;
77
.flex(row);

0 commit comments

Comments
 (0)