Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | 7x 36x 36x 7x 36x 36x 7x 7x 36x 28x 4x 4x 7x 36x 36x 36x | import { PropsWithChildren } from 'react'
import { TimelineEntryStatus, TimelinePosition } from '../lib/types'
import TimelineEntryContent from './TimelineEntryContent'
export interface TimelineEntryProps extends PropsWithChildren {
type: TimelineEntryStatus
step: string
date?: string
subtext?: string
position: TimelinePosition
className?: string
background?: boolean
}
const topBorderStyle = (
type: TimelineEntryStatus,
position: TimelinePosition,
) => {
const style =
type === 'future' ? 'border-dashed border-black' : 'border-accent-success'
return position === 'first' ? 'border-transparent' : style
}
const bottomBorderStyle = (
type: TimelineEntryStatus,
position: TimelinePosition,
) => {
const style =
type === 'done' ? 'border-accent-success' : 'border-dashed border-black'
return position === 'last' ? 'border-transparent' : style
}
const svgStyles = {
done: '-translate-x-8',
current: '-translate-x-8',
future: '-translate-x-8',
}
const SVG = (type: TimelineEntryStatus, background: boolean | undefined) => {
switch (type) {
case 'done': {
return (
<svg
className={`${background ? 'bg-slate-100' : 'bg-white'} h-8 w-8 fill-accent-success`}
viewBox="1 4 64 64"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
>
<circle
cx="36"
cy="36"
r="24"
fill="green"
stroke="green"
strokeWidth="8"
/>
<line
x1="31"
y1="47"
x2="49"
y2="27"
stroke="white"
strokeWidth="6"
/>
<line
x1="34"
y1="48"
x2="21"
y2="37"
stroke="white"
strokeWidth="6"
/>
</svg>
)
}
case 'current': {
return (
<svg
className={`${background ? 'bg-slate-100' : 'bg-white'} h-8 w-8`}
viewBox="1 4 64 64"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
>
<circle
cx="36"
cy="36"
r="24"
fill="black"
stroke="black"
strokeWidth="8"
/>
</svg>
)
}
case 'future': {
return (
<svg
className={`${background ? 'bg-slate-100' : 'bg-white'} h-8 w-8`}
xmlns="http://www.w3.org/2000/svg"
viewBox="1 4 64 64"
aria-hidden="true"
>
<circle
cx="36"
cy="36"
r="24"
fill="none"
stroke="black"
strokeWidth="8"
/>
</svg>
)
}
}
}
const TimelineEntry = ({
type,
position,
step,
date,
subtext,
className,
background,
}: TimelineEntryProps) => {
const topBorderComputedStyle = topBorderStyle(type, position)
const bottomBorderComputedStyle = bottomBorderStyle(type, position)
return (
<div className={className}>
<div className="flex flex-row">
<div className="relative h-auto w-8">
<div
className={`absolute left-1/2 top-0 h-1/2 w-4 transform border-l-4 ${topBorderComputedStyle}`}
/>
<div
className={`absolute left-1/2 top-1/2 h-1/2 w-4 transform border-l-4 ${bottomBorderComputedStyle}`}
/>
</div>
<div className={`${svgStyles[type]} w-8 content-center`}>
{SVG(type, background)}
</div>
<div
className={`${type === 'done' ? '-translate-y-0' : 'translate-y-1'} my-6 -translate-x-4`}
>
<TimelineEntryContent
type={type}
position={position}
topText={step}
bottomDate={date}
bottomText={subtext}
/>
</div>
</div>
</div>
)
}
export default TimelineEntry
|