Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

Initial commit of component render classes. #8

Merged
merged 20 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0638019
Initial commit of component render classes.
chriscox Oct 20, 2016
e5d96a8
Merge branch 'develop' into feature/components
chriscox Oct 25, 2016
8500f7e
First pass of updates per feedback.
chriscox Oct 25, 2016
dad1c8b
Another pass of updates per feedback.
chriscox Oct 26, 2016
3c4c4fe
Refactors components to controls using Composition rather than Inheri…
chriscox Nov 7, 2016
2a0e894
Finalizes refactor of components to controls using Composition rather…
chriscox Nov 9, 2016
6bc9a3e
Updates constants formatting.
chriscox Nov 9, 2016
db0fa11
Fixes styles.less spacing/tabs.
chriscox Nov 9, 2016
939dbf7
Adds class commenting. Adds missing TextFieldControl. Removes SliderC…
chriscox Nov 9, 2016
f5d12f7
Merge branch 'develop' into feature/components
chriscox Nov 10, 2016
9ff18a0
Cleans up a few comment and strings.
chriscox Nov 10, 2016
2840c31
Updates control interfaces.
chriscox Nov 15, 2016
9bde50b
Refactors variable controls to call a prop callback method when updated.
chriscox Nov 17, 2016
be4a5d8
Work-in-progress.
chriscox Nov 18, 2016
bef5a8e
Now clones variables during update, allowing each control to handle i…
chriscox Nov 21, 2016
5d548ad
Resets package.json.
chriscox Nov 21, 2016
f791971
Merge branch 'develop' into feature/components
chriscox Nov 21, 2016
95e2423
Adds a render.tsx with logic that handles redrawing when variables up…
chriscox Nov 21, 2016
fffa746
Fixes adding callbacks to internal _callbacks
chriscox Nov 21, 2016
e1ea4fc
Minor code cleanup.
chriscox Nov 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/ui/controls/ColorSwatchControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import * as React from "react";
import { ColorControlInterface } from "./controlInterfaces";
import { ColorVariable } from "../../core/variables/ColorVariable";
import { ControlInterface } from "./ControlInterface";
import { CSS, VariableType } from "../../lib/Constants";

/**
Expand All @@ -30,20 +30,17 @@ interface ColorSwatchProps {
}

/**
* A single color swatch displayed within the `ColorSwatchControl`.
* @class
* @extends React.Component
* Returns a single color swatch displayed within the `ColorSwatchControl`.
* @param {ColorSwatchProps} props The color swath properties.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"swatch"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*/
class ColorSwatch extends React.Component<ColorSwatchProps, void> {
render() {
const { color, isSelected, onClick } = this.props;
return (
<div className={CSS.RMX_COLOR_SWATCH_ITEM} style={{backgroundColor: color}}
value={color} onClick={onClick}>
{isSelected ? <i className="material-icons">check</i> : ""}
</div>
);
}
function ColorSwatch(props: ColorSwatchProps) {
const { color, isSelected, onClick } = props;
return (
<div className={CSS.RMX_COLOR_SWATCH_ITEM} style={{backgroundColor: color}}
value={color} onClick={onClick}>
{isSelected ? <i className="material-icons">check</i> : ""}
</div>
);
}

/**
Expand All @@ -52,7 +49,7 @@ class ColorSwatch extends React.Component<ColorSwatchProps, void> {
* @class
* @extends React.Component
*/
export class ColorSwatchControl extends React.Component<ControlInterface, ControlInterface> {
export class ColorSwatchControl extends React.Component<ColorControlInterface, ColorControlInterface> {
state = {
variable: this.props.variable,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you storing a prop as state?

Seems like you could get rid of all the state entirely and just move the possibleValues.includes(selectedValue) check into render.

};
Expand All @@ -63,7 +60,7 @@ export class ColorSwatchControl extends React.Component<ControlInterface, Contro
const {
possibleValues,
selectedValue
} = this.state.variable as ColorVariable;
} = this.state.variable;

if (possibleValues.indexOf(selectedValue) === -1) {
possibleValues.push(selectedValue);
Expand All @@ -87,7 +84,7 @@ export class ColorSwatchControl extends React.Component<ControlInterface, Contro
title,
possibleValues,
selectedValue
} = this.state.variable as ColorVariable;
} = this.state.variable;

return (
<div className={`${CSS.RMX_COLOR_SWATCH} ${CSS.MDL_LIST_ITEM} ${CSS.MDL_TWO_LINE}`}>
Expand Down
23 changes: 0 additions & 23 deletions src/ui/controls/ControlInterface.tsx

This file was deleted.

8 changes: 4 additions & 4 deletions src/ui/controls/DropdownControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

import * as React from "react";
import { ControlInterface } from "./ControlInterface";
import { CSS } from "../../lib/Constants";
import { StringControlInterface } from "./controlInterfaces";
import { StringVariable } from "../../core/variables/StringVariable";

/**
* A dropdown control.
* @class
* @extends React.Component
*/
export class DropdownControl extends React.Component<ControlInterface, ControlInterface> {
export class DropdownControl extends React.Component<StringControlInterface, StringControlInterface> {
state = {
variable: this.props.variable,
};
Expand All @@ -35,7 +35,7 @@ export class DropdownControl extends React.Component<ControlInterface, ControlIn
const {
possibleValues,
selectedValue
} = this.state.variable as StringVariable;
} = this.state.variable;

if (possibleValues.indexOf(selectedValue) === -1) {
possibleValues.push(selectedValue);
Expand All @@ -60,7 +60,7 @@ export class DropdownControl extends React.Component<ControlInterface, ControlIn
key,
possibleValues,
selectedValue
} = this.state.variable as StringVariable;
} = this.state.variable;
const id = `${CSS.RMX_DROPDOWN}-${key}`;

return (
Expand Down
8 changes: 4 additions & 4 deletions src/ui/controls/RadioListControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

import * as React from "react";
import { ControlInterface } from "./ControlInterface";
import { CSS, VariableType } from "../../lib/Constants";
import { StringControlInterface } from "./controlInterfaces";
import { StringVariable } from "../../core/variables/StringVariable";

/**
* A radio list control.
* @class
* @extends React.Component
*/
export class RadioListControl extends React.Component<ControlInterface, ControlInterface> {
export class RadioListControl extends React.Component<StringControlInterface, StringControlInterface> {
state = {
variable: this.props.variable,
};
Expand All @@ -35,7 +35,7 @@ export class RadioListControl extends React.Component<ControlInterface, ControlI
const {
possibleValues,
selectedValue
} = this.state.variable as StringVariable;
} = this.state.variable;

if (possibleValues.indexOf(selectedValue) === -1) {
possibleValues.push(selectedValue);
Expand All @@ -60,7 +60,7 @@ export class RadioListControl extends React.Component<ControlInterface, ControlI
key,
possibleValues,
selectedValue
} = this.state.variable as StringVariable;
} = this.state.variable;
const id = `${CSS.RMX_RADIO_LIST_ITEM}-${key}`;

return (
Expand Down
6 changes: 3 additions & 3 deletions src/ui/controls/SliderControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

import * as React from "react";
import { ControlInterface } from "./ControlInterface";
import { CSS, VariableType } from "../../lib/Constants";
import { RangeControlInterface } from "./controlInterfaces";
import { RangeVariable } from "../../core/variables/RangeVariable";

/**
* A slider control.
* @class
* @extends React.Component
*/
export class SliderControl extends React.Component<ControlInterface, ControlInterface> {
export class SliderControl extends React.Component<RangeControlInterface, RangeControlInterface> {
state = {
variable: this.props.variable,
};
Expand All @@ -48,7 +48,7 @@ export class SliderControl extends React.Component<ControlInterface, ControlInte
minValue,
maxValue,
increment,
} = this.state.variable as RangeVariable;
} = this.state.variable;
const id = `${CSS.RMX_SLIDER}-${key}`;

return (
Expand Down
4 changes: 2 additions & 2 deletions src/ui/controls/SwitchControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

import * as React from "react";
import { ControlInterface } from "./ControlInterface";
import { BooleanControlInterface } from "./controlInterfaces";
import { CSS } from "../../lib/Constants";

/**
* A switch control.
* @class
* @extends React.Component
*/
export class SwitchControl extends React.Component<ControlInterface, ControlInterface> {
export class SwitchControl extends React.Component<BooleanControlInterface, BooleanControlInterface> {
state = {
variable: this.props.variable,
};
Expand Down
6 changes: 3 additions & 3 deletions src/ui/controls/TextFieldControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

import * as React from "react";
import { ControlInterface } from "./ControlInterface";
import { CSS, VariableType } from "../../lib/Constants";
import { StringControlInterface } from "./controlInterfaces";
import { StringVariable } from "../../core/variables/StringVariable";

/**
* A textfield control.
* @class
* @extends React.Component
*/
export class TextFieldControl extends React.Component<ControlInterface, ControlInterface> {
export class TextFieldControl extends React.Component<StringControlInterface, StringControlInterface> {
state = {
variable: this.props.variable,
};
Expand All @@ -46,7 +46,7 @@ export class TextFieldControl extends React.Component<ControlInterface, ControlI
key,
dataType,
selectedValue
} = this.state.variable as StringVariable;
} = this.state.variable;
const id = `${CSS.RMX_TEXTFIELD}-${key}`;
const isNumber: boolean = dataType === VariableType.NUMBER;
const pattern = isNumber ? "-?[0-9]*(\.[0-9]+)?" : ".*";
Expand Down
80 changes: 80 additions & 0 deletions src/ui/controls/controlInterfaces.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/** @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

import { BooleanVariable } from "../../core/variables/BooleanVariable";
import { ColorVariable } from "../../core/variables/ColorVariable";
import { NumberVariable } from "../../core/variables/NumberVariable";
import { RangeVariable } from "../../core/variables/RangeVariable";
import { StringVariable } from "../../core/variables/StringVariable";
import { Variable } from "../../core/variables/Variable";

/**
* Interface for variable controls properties and state.
* @interface
*/
interface ControlInterface {
variable: Variable;
}

/**
* Interface for the properties and state of a control that implements a
* Boolean variable.
* @interface
* @extends ControlInterface
*/
export interface BooleanControlInterface extends ControlInterface {
variable: BooleanVariable;
}

/**
* Interface for the properties and state of a control that implements a
* Color variable.
* @interface
* @extends ControlInterface
*/
export interface ColorControlInterface extends ControlInterface {
variable: ColorVariable;
}

/**
* Interface for the properties and state of a control that implements a
* Number variable.
* @interface
* @extends ControlInterface
*/
export interface NumberControlInterface extends ControlInterface {
variable: NumberVariable;
}

/**
* Interface for the properties and state of a control that implements a
* Range variable.
* @interface
* @extends ControlInterface
*/
export interface RangeControlInterface extends ControlInterface {
variable: RangeVariable;
}

/**
* Interface for the properties and state of a control that implements a
* String variable.
* @interface
* @extends ControlInterface
*/
export interface StringControlInterface extends ControlInterface {
variable: StringVariable;
}
2 changes: 1 addition & 1 deletion src/ui/overlay/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Overlay extends React.Component<OverlayVariables, OverlayVariables>
case VariableType.STRING:
if (!variable["possibleValues"]) {
Control = TextFieldControl;
} else if (variable["possibleValues"].length <= 2) {
} else if (variable["possibleValues"].length === 2) {
Control = RadioListControl;
} else {
Control = DropdownControl;
Expand Down