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

Commit

Permalink
Fixes colorVariable bug when changed remotely. Closes #77 (#78)
Browse files Browse the repository at this point in the history
* Fixes colorVariable bug when changed remotely. Closes #77.

* Cleanup.
  • Loading branch information
chriscox authored Feb 27, 2017
1 parent a0de610 commit 3aa4462
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/core/variables/ColorVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ export class ColorVariable extends Variable implements IColorVariableParams {
ConstraintType.LIST : ConstraintType.NONE;
}

/**
* Updates the selected value.
* @override
* @param {any} value The selected value.
*/
updateValue(value: any): void {
let hexColorValue = TinyColor(value).toHexString();
super.updateValue(hexColorValue);
}

/**
* Clones the variable.
* @return {ColorVariable} Returns the cloned variable.
Expand Down
11 changes: 11 additions & 0 deletions src/core/variables/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ export class Variable implements IVariableParams {
}

set selectedValue(value: any) {
this.updateValue(value);
}

/**
* Updates the selected value, saves, and executes callbacks.
*
* Subclasses should override this method if any transformations are
* required on the selected value.
* @param {any} value The selected value.
*/
updateValue(value: any): void {
this._selectedValue = value;
this.save();
if (this._initialized) {
Expand Down
8 changes: 4 additions & 4 deletions src/ui/controls/ColorSwatchControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export class ColorSwatchControl extends React.Component<IColorControlProps, void

/** Handles the update event for this control. */
onClick = (event: React.FormEvent<HTMLElement>): void => {
this.props.updateVariable(
this.props.variable,
(event.target as HTMLElement).dataset["value"],
);
let value = (event.target as HTMLElement).dataset["value"];
if (value) {
this.props.updateVariable(this.props.variable, value);
}
}

/** @override */
Expand Down

0 comments on commit 3aa4462

Please sign in to comment.