Skip to content
Snippets Groups Projects
Commit 91f7e7c6 authored by Alexander Rose's avatar Alexander Rose
Browse files

color ui tweak to show option unnamed colors

parent 13fe0ea6
Branches
Tags
No related merge requests found
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import * as React from 'react' import * as React from 'react'
import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
import { camelCaseToWords } from 'mol-util/string'; import { camelCaseToWords } from 'mol-util/string';
import { ColorNames } from 'mol-util/color/tables'; import { ColorNames, ColorNamesValueMap } from 'mol-util/color/tables';
import { Color } from 'mol-util/color'; import { Color } from 'mol-util/color';
import { Slider, Slider2 } from './slider'; import { Slider, Slider2 } from './slider';
...@@ -172,6 +172,13 @@ function ColorOptions() { ...@@ -172,6 +172,13 @@ function ColorOptions() {
return _colors; return _colors;
} }
function ColorValueOption(color: Color) {
return !ColorNamesValueMap.has(color) ? <option key={Color.toHexString(color)} value={color} style={{ background: `${Color.toStyle(color)}` }} >
{Color.toHexString(color)}
</option> : null
}
export class ColorControl extends SimpleParam<PD.Color> { export class ColorControl extends SimpleParam<PD.Color> {
onChange = (e: React.ChangeEvent<HTMLSelectElement>) => { onChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
this.update(Color(parseInt(e.target.value))); this.update(Color(parseInt(e.target.value)));
...@@ -179,6 +186,7 @@ export class ColorControl extends SimpleParam<PD.Color> { ...@@ -179,6 +186,7 @@ export class ColorControl extends SimpleParam<PD.Color> {
renderControl() { renderControl() {
return <select value={this.props.value} onChange={this.onChange} style={{ borderLeft: `16px solid ${Color.toStyle(this.props.value)}` }}> return <select value={this.props.value} onChange={this.onChange} style={{ borderLeft: `16px solid ${Color.toStyle(this.props.value)}` }}>
{ColorValueOption(this.props.value)}
{ColorOptions()} {ColorOptions()}
</select>; </select>;
} }
......
...@@ -259,4 +259,13 @@ export const ColorNames = ColorMap({ ...@@ -259,4 +259,13 @@ export const ColorNames = ColorMap({
whitesmoke: 0xf5f5f5, whitesmoke: 0xf5f5f5,
yellow: 0xffff00, yellow: 0xffff00,
yellowgreen: 0x9acd32 yellowgreen: 0x9acd32
}) })
\ No newline at end of file export type ColorNames = typeof ColorNames
export type ColorName = keyof ColorNames
export const ColorNamesValueMap = (function(){
const map = new Map<Color, ColorName>()
Object.keys(ColorNames).forEach(name => {
map.set(ColorNames[name as ColorName], name as ColorName)
})
return map
})()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment