2019-07-24 16:25:20 +00:00
|
|
|
import { Button, Classes, H5, H6, MenuItem } from "@blueprintjs/core";
|
2019-07-24 15:51:44 +00:00
|
|
|
import { IconNames } from "@blueprintjs/icons";
|
|
|
|
import { ItemRenderer, Select } from "@blueprintjs/select";
|
|
|
|
import React from "react";
|
|
|
|
import styled from "styled-components";
|
2019-07-24 16:25:20 +00:00
|
|
|
import { FloatingCard, InstanceType } from ".";
|
2019-07-24 15:51:44 +00:00
|
|
|
import { IColorSchemeType } from "../../types";
|
|
|
|
|
|
|
|
const ColorSchemeSelect = Select.ofType<IColorSchemeType>();
|
|
|
|
|
|
|
|
const StyledLi = styled.li`
|
|
|
|
margin-top: 2px;
|
|
|
|
`;
|
|
|
|
const StyledKeyContainer = styled.div`
|
|
|
|
margin-top: 10px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
interface IGraphKeyProps {
|
|
|
|
current?: IColorSchemeType;
|
|
|
|
colorSchemes: IColorSchemeType[];
|
|
|
|
onItemSelect: (colorScheme?: IColorSchemeType) => void;
|
|
|
|
}
|
|
|
|
const GraphKey: React.FC<IGraphKeyProps> = ({ current, colorSchemes, onItemSelect }) => {
|
|
|
|
const unsetColorScheme = () => {
|
|
|
|
onItemSelect(undefined);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<FloatingCard>
|
|
|
|
<H5>Color coding</H5>
|
|
|
|
<ColorSchemeSelect
|
|
|
|
activeItem={current}
|
|
|
|
filterable={false}
|
|
|
|
items={colorSchemes}
|
|
|
|
itemRenderer={renderItem}
|
|
|
|
onItemSelect={onItemSelect}
|
|
|
|
popoverProps={{ minimal: true }}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
text={(current && current.name) || "Select..."}
|
|
|
|
icon={IconNames.TINT}
|
|
|
|
rightIcon={IconNames.CARET_DOWN}
|
|
|
|
/>
|
|
|
|
<Button icon={IconNames.SMALL_CROSS} minimal={true} onClick={unsetColorScheme} disabled={!current} />
|
|
|
|
</ColorSchemeSelect>
|
|
|
|
{current && (
|
|
|
|
<StyledKeyContainer>
|
|
|
|
<H6>Key</H6>
|
|
|
|
<ul className={Classes.LIST_UNSTYLED}>
|
2019-07-24 16:25:20 +00:00
|
|
|
{current.values.map(v => (
|
2019-07-24 15:51:44 +00:00
|
|
|
<StyledLi>
|
2019-07-24 16:25:20 +00:00
|
|
|
<InstanceType type={v} />
|
2019-07-24 15:51:44 +00:00
|
|
|
</StyledLi>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</StyledKeyContainer>
|
|
|
|
)}
|
|
|
|
</FloatingCard>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderItem: ItemRenderer<IColorSchemeType> = (colorScheme, { handleClick, modifiers }) => {
|
|
|
|
if (!modifiers.matchesPredicate) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return <MenuItem active={modifiers.active} key={colorScheme.name} onClick={handleClick} text={colorScheme.name} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default GraphKey;
|