Skip to content

Commit

Permalink
refactor: make table ul list
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Aug 4, 2023
1 parent 3100436 commit a07b543
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 33 deletions.
9 changes: 9 additions & 0 deletions src/client/view/App.tsx
Expand Up @@ -64,5 +64,14 @@ const globalStyle = css`
p {
margin: 0;
}
ul {
list-style: none;
padding: 0;
margin: 0;
margin-block: 0;
margin-inline: 0;
padding-inline-start: 0;
}
}
`;
30 changes: 28 additions & 2 deletions src/client/view/share/components/Cell.tsx
Expand Up @@ -9,17 +9,21 @@ type CellProps = {
type: CellType;
title: string | null;
isCompleted: boolean;
position?: CellPosition;
};

export const Cell = ({ type, title, isCompleted }: CellProps) => {
export type CellPosition = 'lt' | 'rt' | 'lb' | 'rb' | 'center';

export const Cell = ({ type, title, isCompleted, position }: CellProps) => {
const className = cx(
baseCellBox,
type === 'sub' && subCellBox,
type === 'main' && mainCellBox,
type === 'task' && isCompleted && 'completed',
type !== 'task' && position && positionToStyle[position],
);
return (
<div className={className}>
<div role={'checkbox'} className={className} aria-checked={isCompleted}>
{title}
{isCompleted && (
<div className={completedDim}>
Expand Down Expand Up @@ -57,9 +61,11 @@ const baseCellBox = css`
`;

const subCellBox = css`
position: absolute;
background-color: var(--sub-color);
color: var(--main-color);
font-weight: 700;
z-index: 1;
`;

const mainCellBox = css`
Expand All @@ -68,9 +74,29 @@ const mainCellBox = css`
font-weight: 700;
position: absolute;
`;

const center = css`
top: calc((${TABLE_SIZE} - ${CELL_SIZE}) / 2 * 1px);
left: calc((${TABLE_SIZE} - ${CELL_SIZE}) / 2 * 1px);
`;
const lt = css`
top: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
left: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
`;
const rt = css`
top: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
right: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
`;
const lb = css`
bottom: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
left: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
`;
const rb = css`
bottom: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
right: calc((${TABLE_SIZE} / 2 - ${CELL_SIZE} * 0.5) / 2 * 1px);
`;
const positionToStyle = { center, lt, rt, lb, rb } as const;

const completedDim = css`
position: absolute;
Expand Down
12 changes: 10 additions & 2 deletions src/client/view/share/components/HeaderSection.tsx
Expand Up @@ -23,7 +23,9 @@ export const HeaderSection = ({
)}
<h1 className={title}>{detail.title}</h1>
<div className={progressInfoContainer}>
<span className={subtext}>달성률 ({completionRatio}%)</span>
<span id={'progressLabel'} className={subtext}>
달성률 ({completionRatio}%)
</span>
{detail.dueDate && (
<span className={cx(subtext, dueDate)}>~{formattedDueDate}</span>
)}
Expand All @@ -32,7 +34,13 @@ export const HeaderSection = ({
className={progressContainer}
style={{ '--progress-ratio': completionRatio } as CSSProperties}
>
<progress value={completionRatio} aria-label="반다라트 달성률" />
<progress
value={completionRatio}
max={100}
aria-labelledby="progressLabel"
aria-valuenow={completionRatio}
aria-valuemax={100}
/>
</div>
</section>
);
Expand Down
66 changes: 38 additions & 28 deletions src/client/view/share/components/Table.tsx
@@ -1,7 +1,7 @@
import { BandalartCell } from '../../../../types/BandalartCell';
import React from 'react';
import { css, cx } from '@linaria/core';
import { Cell } from './Cell';
import { Cell, CellPosition } from './Cell';
import {
GAP_BETWEEN_CELLS,
PADDING_IN_SECTION,
Expand All @@ -13,38 +13,48 @@ type TableProps = {
};

const subTaskPosition = [4, 2, 3, 1];
const subSectionPosition = ['lt', 'rt', 'lb', 'rb'];
const subSectionPosition = ['lt', 'rt', 'lb', 'rb'] as CellPosition[];

export const Table = ({ root }: TableProps) => {
return (
<div className={container}>
<Cell type={'main'} title={root.title} isCompleted={root.isCompleted} />
{root.children.map((subCell, subIdx) => (
<div
key={subSectionPosition[subIdx]}
className={cx(subSection, subSectionPosition[subIdx])}
>
{subCell.children.map((task, taskIdx) => (
<>
{taskIdx === subTaskPosition[subIdx] && (
<Cell
key={subCell.key}
type={'sub'}
title={subCell.title}
isCompleted={subCell.isCompleted}
/>
)}
<ul className={container}>
<li>
<Cell
type={'main'}
title={root.title}
isCompleted={root.isCompleted}
position={'center'}
/>
{root.children.map((subCell, subIdx) => (
<ul key={subSectionPosition[subIdx]}>
<li key={subCell.key}>
<Cell
key={task.key}
type={'task'}
title={task.title}
isCompleted={task.isCompleted}
type={'sub'}
title={subCell.title}
isCompleted={subCell.isCompleted}
position={subSectionPosition[subIdx]}
/>
</>
))}
</div>
))}
</div>
<ul className={cx(subSection, subSectionPosition[subIdx])}>
{subCell.children.map((task, taskIdx) => (
<>
{taskIdx === subTaskPosition[subIdx] && (
<li aria-hidden="true" />
)}
<li key={task.key}>
<Cell
type={'task'}
title={task.title}
isCompleted={task.isCompleted}
/>
</li>
</>
))}
</ul>
</li>
</ul>
))}
</li>
</ul>
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/client/view/share/index.tsx
Expand Up @@ -23,7 +23,9 @@ export const BandalartSharePage = () => {
}
>
<HeaderSection detail={detail} completionRatio={completionRatio} />
<Table root={treeRoot} />
<main>
<Table root={treeRoot} />
</main>
</div>
);
};
Expand Down

0 comments on commit a07b543

Please sign in to comment.