feat: custom color

This commit is contained in:
chenos 2023-04-12 00:03:44 +08:00
parent 63b1b49b0f
commit 620c8ceba9
7 changed files with 28 additions and 13 deletions

View File

@ -23,6 +23,7 @@ const formatData = (
progress: item[fieldNames.progress] * 100 || 0, progress: item[fieldNames.progress] * 100 || 0,
hideChildren: hideChildren, hideChildren: hideChildren,
project: projectId, project: projectId,
color: item.color,
}); });
formatData(item.children, fieldNames, tasks, item.id + '', hideChildren); formatData(item.children, fieldNames, tasks, item.id + '', hideChildren);
} else { } else {
@ -34,6 +35,7 @@ const formatData = (
type: fieldNames.end ? 'task' : 'milestone', type: fieldNames.end ? 'task' : 'milestone',
progress: item[fieldNames.progress] * 100 || 0, progress: item[fieldNames.progress] * 100 || 0,
project: projectId, project: projectId,
color: item.color,
}); });
} }
}); });

View File

@ -66,12 +66,12 @@ export const Gantt: any = (props: any) => {
barCornerRadius = 2, barCornerRadius = 2,
barProgressColor = '#1890ff', barProgressColor = '#1890ff',
barProgressSelectedColor = '#1890ff', barProgressSelectedColor = '#1890ff',
barBackgroundColor = '#82bdff', barBackgroundColor = '#1890ff',
barBackgroundSelectedColor = '#82bdff', barBackgroundSelectedColor = '#1890ff',
projectProgressColor = '#52c41a', projectProgressColor = '#52c41a',
projectProgressSelectedColor = '#52c41a', projectProgressSelectedColor = '#52c41a',
projectBackgroundColor = '#9cdc82', projectBackgroundColor = '#52c41a',
projectBackgroundSelectedColor = '#9cdc82', projectBackgroundSelectedColor = '#52c41a',
milestoneBackgroundColor = '#f1c453', milestoneBackgroundColor = '#f1c453',
milestoneBackgroundSelectedColor = '#f29e4c', milestoneBackgroundSelectedColor = '#f29e4c',
rtl = false, rtl = false,

View File

@ -1,10 +1,11 @@
import React from "react";
import { cx } from '@emotion/css'; import { cx } from '@emotion/css';
import React from "react";
import { barBackground } from './style'; import { barBackground } from './style';
type BarDisplayProps = { type BarDisplayProps = {
x: number; x: number;
y: number; y: number;
color?: string;
width: number; width: number;
height: number; height: number;
isSelected: boolean; isSelected: boolean;
@ -23,6 +24,7 @@ type BarDisplayProps = {
export const BarDisplay: React.FC<BarDisplayProps> = ({ export const BarDisplay: React.FC<BarDisplayProps> = ({
x, x,
y, y,
color,
width, width,
height, height,
isSelected, isSelected,
@ -33,10 +35,16 @@ export const BarDisplay: React.FC<BarDisplayProps> = ({
onMouseDown, onMouseDown,
}) => { }) => {
const getProcessColor = () => { const getProcessColor = () => {
if (color) {
return color;
}
return isSelected ? styles.progressSelectedColor : styles.progressColor; return isSelected ? styles.progressSelectedColor : styles.progressColor;
}; };
const getBarColor = () => { const getBarColor = () => {
if (color) {
return color;
}
return isSelected ? styles.backgroundSelectedColor : styles.backgroundColor; return isSelected ? styles.backgroundSelectedColor : styles.backgroundColor;
}; };

View File

@ -1,10 +1,10 @@
import React from "react";
import { cx } from '@emotion/css'; import { cx } from '@emotion/css';
import React from "react";
import { getProgressPoint } from "../../../helpers/bar-helper"; import { getProgressPoint } from "../../../helpers/bar-helper";
import { BarDisplay } from "./bar-display";
import { BarDateHandle } from "./bar-date-handle";
import { BarProgressHandle } from "./bar-progress-handle";
import { TaskItemProps } from "../task-item"; import { TaskItemProps } from "../task-item";
import { BarDateHandle } from "./bar-date-handle";
import { BarDisplay } from "./bar-display";
import { BarProgressHandle } from "./bar-progress-handle";
import { barWrapper } from './style'; import { barWrapper } from './style';
@ -27,6 +27,7 @@ export const Bar: React.FC<TaskItemProps> = ({
<BarDisplay <BarDisplay
x={task.x1} x={task.x1}
y={task.y} y={task.y}
color={task.color}
width={task.x2 - task.x1} width={task.x2 - task.x1}
height={task.height} height={task.height}
progressX={task.progressX} progressX={task.progressX}

View File

@ -19,4 +19,5 @@ export const barWrapper = css`
export const barBackground = css` export const barBackground = css`
user-select: none; user-select: none;
stroke-width: 0; stroke-width: 0;
opacity: .6;
`; `;

View File

@ -1,17 +1,19 @@
import React from 'react';
import { cx } from '@emotion/css'; import { cx } from '@emotion/css';
import React from 'react';
import { TaskItemProps } from '../task-item'; import { TaskItemProps } from '../task-item';
import { projectWrapper, projectBackground } from './style'; import { projectBackground, projectWrapper } from './style';
export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => { export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
const barColor = isSelected ? task.styles.backgroundSelectedColor : task.styles.backgroundColor; const barColor = isSelected ? task.styles.backgroundSelectedColor : task.styles.backgroundColor;
const processColor = isSelected ? task.styles.progressSelectedColor : task.styles.progressColor; const processColor = isSelected ? task.styles.progressSelectedColor : task.styles.progressColor;
const projectWith = task.x2 - task.x1; const projectWith = task.x2 - task.x1;
console.log('task', task);
return ( return (
<g tabIndex={0} className={cx(projectWrapper)}> <g tabIndex={0} className={cx(projectWrapper)}>
<rect <rect
fill={barColor} fill={task.color || barColor}
x={task.x1} x={task.x1}
width={projectWith} width={projectWith}
y={task.y} y={task.y}
@ -27,7 +29,7 @@ export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
height={task.height} height={task.height}
ry={task.barCornerRadius} ry={task.barCornerRadius}
rx={task.barCornerRadius} rx={task.barCornerRadius}
fill={processColor} fill={task.color || processColor}
/> />
</g> </g>
); );

View File

@ -12,6 +12,7 @@ export interface BarTask extends Task {
barCornerRadius: number; barCornerRadius: number;
handleWidth: number; handleWidth: number;
barChildren: BarTask[]; barChildren: BarTask[];
color?: string;
styles: { styles: {
backgroundColor: string; backgroundColor: string;
backgroundSelectedColor: string; backgroundSelectedColor: string;