Farmbot-Web-App/frontend/ui/color_picker.tsx

64 lines
1.9 KiB
TypeScript
Raw Normal View History

2017-07-25 16:24:25 -06:00
import * as React from "react";
import { Popover, Position } from "@blueprintjs/core";
import { Saucer } from "../ui/index";
2019-01-13 17:16:22 -07:00
import { ResourceColor } from "../interfaces";
2017-07-25 16:24:25 -06:00
import { colors } from "../util";
2020-02-28 09:34:28 -07:00
import { t } from "../i18next_wrapper";
2017-07-25 16:24:25 -06:00
2019-12-23 15:38:48 -07:00
export interface ColorPickerProps {
2019-12-11 12:22:48 -07:00
position?: Position;
2019-01-13 17:16:22 -07:00
current: ResourceColor;
2019-12-23 15:38:48 -07:00
onChange: (color: ResourceColor) => void;
2019-12-19 18:30:02 -07:00
saucerIcon?: string;
2017-07-25 16:24:25 -06:00
}
2019-12-23 15:38:48 -07:00
export interface ColorPickerClusterProps {
2019-12-18 15:46:38 -07:00
onChange: (color: ResourceColor) => void;
current: ResourceColor;
2019-12-19 18:30:02 -07:00
saucerIcon?: string;
2019-12-18 15:46:38 -07:00
}
2017-07-25 16:24:25 -06:00
2019-12-18 15:46:38 -07:00
interface ColorPickerItemProps extends ColorPickerClusterProps {
color: ResourceColor;
}
const ColorPickerItem = (props: ColorPickerItemProps) => {
2019-12-19 18:30:02 -07:00
return <div className="color-picker-item-wrapper"
2020-02-28 09:34:28 -07:00
title={t(props.color)}
2019-12-19 18:30:02 -07:00
onClick={() => props.onChange(props.color)}>
{props.saucerIcon
2019-12-21 12:47:19 -07:00
? <i className={`icon-saucer fa ${props.saucerIcon} ${props.color}`} />
: <Saucer color={props.color} active={false} />}
2019-12-18 15:46:38 -07:00
</div>;
};
export const ColorPickerCluster = (props: ColorPickerClusterProps) => {
2019-12-19 18:30:02 -07:00
return <div className="color-picker-cluster">
2019-12-18 15:46:38 -07:00
{colors.map((color) => {
return <ColorPickerItem
2019-12-19 09:26:40 -07:00
key={color}
2019-12-18 15:46:38 -07:00
onChange={props.onChange}
2019-12-19 18:30:02 -07:00
saucerIcon={props.saucerIcon}
2019-12-18 15:46:38 -07:00
current={props.current}
color={color} />;
})}
</div>;
};
2019-12-23 15:38:48 -07:00
export class ColorPicker extends React.Component<ColorPickerProps, {}> {
2017-07-25 16:24:25 -06:00
public render() {
2019-12-19 18:30:02 -07:00
return <Popover className="color-picker"
2019-12-11 12:22:48 -07:00
position={this.props.position || Position.BOTTOM}
2017-08-28 05:44:37 -06:00
popoverClassName="colorpicker-menu gray">
2019-12-19 18:30:02 -07:00
{this.props.saucerIcon
? <i className={`icon-saucer fa ${this.props.saucerIcon} ${
this.props.current}`} />
: <Saucer color={this.props.current} />}
<ColorPickerCluster
2019-12-23 15:38:48 -07:00
onChange={this.props.onChange}
2019-12-19 18:30:02 -07:00
current={this.props.current}
saucerIcon={this.props.saucerIcon} />
2017-08-28 05:44:37 -06:00
</Popover>;
2017-07-25 16:24:25 -06:00
}
}