Skip to content

Commit

Permalink
- Fix colors property passed down
Browse files Browse the repository at this point in the history
- Typescript error fixes
  • Loading branch information
wamra committed Sep 27, 2024
1 parent b09efd0 commit e5e1bbc
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 84 deletions.
23 changes: 4 additions & 19 deletions src/components/task-list/TaskListHeaderActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { UnfoldLess, UnfoldMore, UnfoldMoreDouble } from "@mui/icons-material";
import { createTheme, IconButton, ThemeProvider, Tooltip } from "@mui/material";
import { createTheme, IconButton, Theme, ThemeOptions, ThemeProvider, Tooltip } from "@mui/material";
import style from "./TaskListHeaderActions.module.css";
import { ColorStyles } from "../../types/public-types";

Expand All @@ -19,7 +19,7 @@ export const TaskListHeaderActions: React.FC<TaskListHeaderActionsProps> =
colors
}) => {

const materialLightTheme = createTheme({
let themeOptions: ThemeOptions = {
palette: {
primary: {
main: colors.barLabelColor // Maps to a primary color (e.g., task bar background)
Expand All @@ -35,22 +35,6 @@ export const TaskListHeaderActions: React.FC<TaskListHeaderActionsProps> =
primary: colors.barLabelColor, // Main text color (bar labels, etc.)
secondary: colors.barLabelColor // Context menu text color
},
error: {
main: colors.arrowCriticalColor // Critical task color
},
warning: {
main: colors.arrowWarningColor // Warning color (e.g., for dependencies)
},
success: {
main: colors.projectProgressColor // Progress color for successful project completion
},
info: {
main: colors.todayColor // Info color used for today's highlight
},
icon: {
primary: colors.barLabelColor, // Color for primary icons
secondary: colors.barLabelColor, // Color for secondary icons
},
},
components: {
MuiButton: {
Expand Down Expand Up @@ -79,7 +63,8 @@ export const TaskListHeaderActions: React.FC<TaskListHeaderActionsProps> =
},
},
}
});
};
const materialLightTheme: Theme = createTheme(themeOptions);

return (
<ThemeProvider theme={materialLightTheme}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/task-list/columns/add-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styles from "./add-column.module.css";

export const AddColumn: React.FC<ColumnProps> = (props) => {
const {
data: { handleAddTask, icons, style, task }
data: { handleAddTask, icons, colors, task }
} = props;
const onClick = useCallback(() => {
if (task.type === "empty") {
Expand All @@ -22,7 +22,7 @@ export const AddColumn: React.FC<ColumnProps> = (props) => {

return (
<button type="button" onClick={onClick} style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}} className={styles.button}>
{icons?.renderAddIcon ? icons.renderAddIcon(task) : "+"}
</button>
Expand Down
6 changes: 3 additions & 3 deletions src/components/task-list/columns/date-end-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const DateEndColumn: React.FC<ColumnProps> = ({
dateFormats,
dateLocale,
},
style,
colors,
task,
},
}) => {
Expand All @@ -21,7 +21,7 @@ export const DateEndColumn: React.FC<ColumnProps> = ({
try {
return (
<div style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}}>
{format(task.end, dateFormats.dateColumnFormat, {
locale: dateLocale,
Expand All @@ -31,7 +31,7 @@ export const DateEndColumn: React.FC<ColumnProps> = ({
} catch (e) {
return (
<div style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}}>
{task.end.toString()}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/task-list/columns/date-start-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const DateStartColumn: React.FC<ColumnProps> = ({
dateFormats,
dateLocale,
},
style,
colors,
task,
},
}) => {
Expand All @@ -21,7 +21,7 @@ export const DateStartColumn: React.FC<ColumnProps> = ({
try {
return (
<div style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}}>
{format(task.start, dateFormats.dateColumnFormat, {
locale: dateLocale,
Expand All @@ -31,7 +31,7 @@ export const DateStartColumn: React.FC<ColumnProps> = ({
} catch (e) {
return (
<div style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}}>
{task.start.toString()}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/task-list/columns/delete-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import styles from "./delete-column.module.css";

export const DeleteColumn: React.FC<ColumnProps> = (props) => {
const {
data: { handleDeleteTasks, icons, style, task }
data: { handleDeleteTasks, icons, colors, task }
} = props;
const onClick = useCallback(() => {
handleDeleteTasks([task]);
}, [task, handleDeleteTasks]);

return (
<button type="button" onClick={onClick} style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}} className={styles.button}>
{icons?.renderDeleteIcon ? icons.renderDeleteIcon(task) : "-"}
</button>
Expand Down
4 changes: 2 additions & 2 deletions src/components/task-list/columns/dependencies-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { ColumnProps } from "../../../types/public-types";
export const DependenciesColumn: React.FC<ColumnProps> = ({
data: {
dependencies,
style
colors
},
}) => {
return (
<div style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}}>
{dependencies.map(({ name }) => name).join(', ')}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/task-list/columns/edit-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import styles from "./edit-column.module.css";

export const EditColumn: React.FC<ColumnProps> = (props) => {
const {
data: { handleEditTask, icons, style, task }
data: { handleEditTask, icons, colors, task }
} = props;
const onClick = useCallback(() => {
handleEditTask(task);
}, [task, handleEditTask]);

return (
<button type="button" onClick={onClick} style={{
"color": style.barLabelColor
"color": colors.barLabelColor
}} className={styles.button}>
{icons?.renderEditIcon ? icons.renderEditIcon(task) : "✎"}
</button>
Expand Down
6 changes: 3 additions & 3 deletions src/components/task-list/columns/title-column.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { CSSProperties, useCallback } from "react";
import React, { useCallback } from "react";

import { ColumnProps, Icons, TaskOrEmpty } from "../../../types/public-types";

Expand All @@ -24,6 +24,7 @@ const getExpanderSymbol = (
export const TitleColumn: React.FC<ColumnProps> = (props) => {
const {
data: {
colors,
distances: { expandIconWidth, nestedTaskNameOffset },
icons,
isShowTaskNumbers,
Expand All @@ -33,7 +34,6 @@ export const TitleColumn: React.FC<ColumnProps> = (props) => {
indexStr,
task,
onExpanderClick,
style
}
} = props;
const { name } = task;
Expand Down Expand Up @@ -69,7 +69,7 @@ export const TitleColumn: React.FC<ColumnProps> = (props) => {
{expanderSymbol}
</div>
<div style={{
color: style.barLabelColor
color: colors.barLabelColor
}} className={styles.taskName}>
{isShowTaskNumbers && <b>{indexStr} </b>}

Expand Down
7 changes: 4 additions & 3 deletions src/components/task-list/task-list-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const TaskListTableRowInner: React.FC<TaskListTableRowProps> =
isShowTaskNumbers,
onExpanderClick,
task, //: task.type === "empty" ? task : getTaskCurrentState(task),
style
colors
}),
[
canMoveTasks,
Expand All @@ -181,7 +181,7 @@ const TaskListTableRowInner: React.FC<TaskListTableRowProps> =
isShowTaskNumbers,
onExpanderClick,
task,
style
colors
]
);
const dropPreviewOffset =
Expand Down Expand Up @@ -300,7 +300,7 @@ const TaskListTableRowInner: React.FC<TaskListTableRowProps> =

return (
<div
className={`${styles.taskListTableRow} ${isCut ? styles.isCut : ""}`}
className={`${styles.taskListTableRow} ${isCut ? styles.cut : ""}`}
onMouseDown={onRootMouseDown}
style={{
height: fullRowHeight,
Expand All @@ -315,6 +315,7 @@ const TaskListTableRowInner: React.FC<TaskListTableRowProps> =
>
{columns.map((column, index) => {
const { Cell, width }= column;
// noinspection TypeScriptValidateTypes
return (
<div
className={styles.taskListCell}
Expand Down
5 changes: 2 additions & 3 deletions src/components/task-list/task-list-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { memo, useMemo, useState } from "react";
import type { ReactNode } from "react";

import { checkHasChildren } from "../../helpers/check-has-children";
import { Task, TaskListTableProps } from "../../types/public-types";
import { Task, TaskListTableProps, TaskOrEmpty } from "../../types/public-types";
import { TaskListTableRow } from "./task-list-table-row";

import styles from "./task-list-table.module.css";
Expand Down Expand Up @@ -48,7 +48,7 @@ const TaskListTableDefaultInner: React.FC<TaskListTableProps> = ({
[tasks]
);

const [draggedTask, setDraggedTask] = useState(null);
const [draggedTask, setDraggedTask] = useState<TaskOrEmpty>(null);

const renderedListWithOffset = useMemo(() => {
if (!renderedIndexes) {
Expand Down Expand Up @@ -117,7 +117,6 @@ const TaskListTableDefaultInner: React.FC<TaskListTableProps> = ({
tasks={tasks}
draggedTask={draggedTask}
setDraggedTask={setDraggedTask}
style={colors}
/>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/types/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ export type OnArrowDoubleClick = (

export type OnRelationChange = (
/**
* Task, targer, index
* Task, target, index
*/
from: [Task, DateExtremity, number],
/**
* Task, targer, index
* Task, target, index
*/
to: [Task, DateExtremity, number],
/**
Expand Down Expand Up @@ -819,7 +819,7 @@ export type ColumnData = {
isShowTaskNumbers: boolean;
onExpanderClick: (task: Task) => void;
task: TaskOrEmpty;
style: Partial<ColorStyles>;
colors: Partial<ColorStyles>;
};

export type ColumnProps = {
Expand Down
9 changes: 5 additions & 4 deletions stories/Comparison.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const Comparison: React.FC = props => {
const [tasks, setTasks] = useState<readonly TaskOrEmpty[]>(() => {
const firstLevelTasks = initTasks();

const secondLevelTasks = firstLevelTasks.map<TaskOrEmpty>(task => ({
...task,
comparisonLevel: 2,
}));
const secondLevelTasks = firstLevelTasks.map(
(task) => ({
...task,
comparisonLevel: 2
} as TaskOrEmpty));

return [...firstLevelTasks, ...secondLevelTasks];
});
Expand Down
Loading

0 comments on commit e5e1bbc

Please sign in to comment.