Improve color inspector
Summary: Before this change, color inspector used a color picker that showed: color, rgba, hex. The problem is that engineers have to click on it to see these values. This change leaves the picker as is, but presents both hex and rgba inlined within the inspector thus avoiding extra interactions. Reviewed By: antonk52 Differential Revision: D41495740 fbshipit-source-id: c8af01e3060d2e6725295418293b1e30679c1b1f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dbf3108c36
commit
ef64abb495
@@ -29,7 +29,7 @@ data class SpaceBox(val top: Int, val right: Int, val bottom: Int, val left: Int
|
|||||||
}
|
}
|
||||||
|
|
||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
data class Color(val r: Int, val g: Int, val b: Int, val alpha: Int) {
|
data class Color(val r: Int, val g: Int, val b: Int, val a: Int) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromColor(color: Int): Color {
|
fun fromColor(color: Int): Color {
|
||||||
val alpha: Int = (color shr 24) and 0xFF / 255
|
val alpha: Int = (color shr 24) and 0xFF / 255
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ const TextValue = styled.span(TextAttributeValueStyle);
|
|||||||
const EnumValue = styled.span(EnumAttributeValueStyle);
|
const EnumValue = styled.span(EnumAttributeValueStyle);
|
||||||
const ObjectContainer = styled.div(ObjectContainerStyle);
|
const ObjectContainer = styled.div(ObjectContainerStyle);
|
||||||
const CenteredContentContainer = styled.div(AutoMarginStyle);
|
const CenteredContentContainer = styled.div(AutoMarginStyle);
|
||||||
|
|
||||||
type NamedAttributeInspectorProps = {
|
type NamedAttributeInspectorProps = {
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NamedAttributeInspector: React.FC<NamedAttributeInspectorProps> = ({
|
const NamedAttributeInspector: React.FC<NamedAttributeInspectorProps> = ({
|
||||||
name,
|
name,
|
||||||
children,
|
children,
|
||||||
@@ -119,9 +121,10 @@ function create(
|
|||||||
);
|
);
|
||||||
case 'color':
|
case 'color':
|
||||||
return (
|
return (
|
||||||
<NamedAttributeInspector name={displayableName(name)}>
|
<ColorInspector
|
||||||
<ColorInspector color={inspectable.value} />
|
name={displayableName(name)}
|
||||||
</NamedAttributeInspector>
|
color={inspectable.value}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
case 'size':
|
case 'size':
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -8,46 +8,65 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Popover} from 'antd';
|
import {Col, Popover, Row} from 'antd';
|
||||||
import {Color} from '../../../types';
|
import {Color} from '../../../types';
|
||||||
import {SketchPicker, RGBColor, ColorResult} from 'react-color';
|
import {SketchPicker, ColorResult} from 'react-color';
|
||||||
import {styled} from 'flipper-plugin';
|
import {styled} from 'flipper-plugin';
|
||||||
import {ColorInnerButtonStyle, ColorOuterButtonStyle} from './Styles';
|
import {
|
||||||
|
AutoMarginStyle,
|
||||||
|
ColorInnerButtonStyle,
|
||||||
|
ColorOuterButtonStyle,
|
||||||
|
NumberAttributeValueStyle,
|
||||||
|
ObjectContainerStyle,
|
||||||
|
RowStyle,
|
||||||
|
} from './Styles';
|
||||||
|
import {theme} from 'flipper-plugin';
|
||||||
|
|
||||||
type State = {
|
type Props = {
|
||||||
color: RGBColor;
|
name: string;
|
||||||
|
color: Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
const OuterColorButton = styled.div(ColorOuterButtonStyle);
|
const DefaultColor: Color = {
|
||||||
const InnerColorButton = styled.div(ColorInnerButtonStyle);
|
|
||||||
|
|
||||||
class ColorInspector extends React.Component<{color: Color}> {
|
|
||||||
state: State = {
|
|
||||||
color: this.props.color ?? {
|
|
||||||
r: 255,
|
r: 255,
|
||||||
g: 255,
|
g: 255,
|
||||||
b: 255,
|
b: 255,
|
||||||
a: 1,
|
a: 1,
|
||||||
},
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
const CenteredContentContainer = styled.div(AutoMarginStyle);
|
||||||
|
const ObjectContainer = styled.div(ObjectContainerStyle);
|
||||||
|
const NumberValue = styled.span(NumberAttributeValueStyle);
|
||||||
|
const OuterColorButton = styled.div(ColorOuterButtonStyle);
|
||||||
|
const InnerColorButton = styled.div(ColorInnerButtonStyle);
|
||||||
|
|
||||||
|
const RGBA = styled.span({color: theme.semanticColors.numberValue});
|
||||||
|
|
||||||
|
const RGBAtoHEX = (color: Color) => {
|
||||||
|
const hex =
|
||||||
|
(color.r | (1 << 8)).toString(16).slice(1) +
|
||||||
|
(color.g | (1 << 8)).toString(16).slice(1) +
|
||||||
|
(color.b | (1 << 8)).toString(16).slice(1);
|
||||||
|
|
||||||
|
return '#' + hex.toUpperCase();
|
||||||
|
};
|
||||||
|
|
||||||
|
class ColorPicker extends React.Component<{color: Color}> {
|
||||||
handleChange = (_color: ColorResult) => {
|
handleChange = (_color: ColorResult) => {
|
||||||
// No color changes to be applied at this stage.
|
// No color changes to be applied at this stage.
|
||||||
// this.setState({color: color.rgb});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
placement="bottomRight"
|
placement="bottomRight"
|
||||||
content={
|
content={
|
||||||
<SketchPicker color={this.state.color} onChange={this.handleChange} />
|
<SketchPicker color={this.props.color} onChange={this.handleChange} />
|
||||||
}
|
}
|
||||||
trigger="click">
|
trigger="click">
|
||||||
<OuterColorButton role="button" tabIndex={0}>
|
<OuterColorButton role="button" tabIndex={0}>
|
||||||
<InnerColorButton
|
<InnerColorButton
|
||||||
style={{
|
style={{
|
||||||
background: `rgba(${this.state.color.r}, ${this.state.color.g}, ${this.state.color.b}, ${this.state.color.a})`,
|
background: `rgba(${this.props.color.r}, ${this.props.color.g}, ${this.props.color.b}, ${this.props.color.a})`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</OuterColorButton>
|
</OuterColorButton>
|
||||||
@@ -56,4 +75,64 @@ class ColorInspector extends React.Component<{color: Color}> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ColorHEX: React.FC<{color: Color}> = ({color}) => (
|
||||||
|
<NumberValue>{RGBAtoHEX(color)}</NumberValue>
|
||||||
|
);
|
||||||
|
|
||||||
|
const ColorRGBA: React.FC<{color: Color}> = ({color}) => (
|
||||||
|
<>
|
||||||
|
r: <RGBA>{color.r}</RGBA> g: <RGBA>{color.g}</RGBA> b:{' '}
|
||||||
|
<RGBA>{color.b}</RGBA> a: <RGBA>{color.a}</RGBA>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
class ColorInspector extends React.Component<Props> {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Row>
|
||||||
|
<Col span={8} style={AutoMarginStyle}>
|
||||||
|
{this.props.name}
|
||||||
|
</Col>
|
||||||
|
<Col span={16}>
|
||||||
|
<CenteredContentContainer>
|
||||||
|
<ColorPicker color={this.props.color} />
|
||||||
|
</CenteredContentContainer>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row style={RowStyle}>
|
||||||
|
<Col span={8} style={AutoMarginStyle}>
|
||||||
|
<ObjectContainer
|
||||||
|
style={{
|
||||||
|
paddingLeft: 2,
|
||||||
|
}}>
|
||||||
|
Hex
|
||||||
|
</ObjectContainer>
|
||||||
|
</Col>
|
||||||
|
<Col span={16}>
|
||||||
|
<CenteredContentContainer>
|
||||||
|
<ColorHEX color={this.props.color} />
|
||||||
|
</CenteredContentContainer>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row style={RowStyle}>
|
||||||
|
<Col span={8} style={AutoMarginStyle}>
|
||||||
|
<ObjectContainer
|
||||||
|
style={{
|
||||||
|
paddingLeft: 2,
|
||||||
|
}}>
|
||||||
|
RGBA
|
||||||
|
</ObjectContainer>
|
||||||
|
</Col>
|
||||||
|
<Col span={16}>
|
||||||
|
<CenteredContentContainer>
|
||||||
|
<ColorRGBA color={this.props.color} />
|
||||||
|
</CenteredContentContainer>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default ColorInspector;
|
export default ColorInspector;
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export type Color = {
|
|||||||
r: number;
|
r: number;
|
||||||
g: number;
|
g: number;
|
||||||
b: number;
|
b: number;
|
||||||
alpha: number;
|
a: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Snapshot = string;
|
export type Snapshot = string;
|
||||||
|
|||||||
Reference in New Issue
Block a user