forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timeline.tsx
140 lines (122 loc) · 3.25 KB
/
Timeline.tsx
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
import classnames from 'classnames'
import React from 'react'
import styled, {css} from 'styled-components'
import {Box} from '.'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'
const Timeline = styled.div<{clipSidebar?: boolean} & SxProp>`
display: flex;
flex-direction: column;
${props =>
props.clipSidebar &&
css`
.Timeline-Item:first-child {
padding-top: 0;
}
.Timeline-Item:last-child {
padding-bottom: 0;
}
`}
${sx};
`
type StyledTimelineItemProps = {condensed?: boolean} & SxProp
const TimelineItem = styled.div.attrs<StyledTimelineItemProps>(props => ({
className: classnames('Timeline-Item', props.className)
}))<StyledTimelineItemProps>`
display: flex;
position: relative;
padding: ${get('space.3')} 0;
margin-left: ${get('space.3')};
&::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
display: block;
width: 2px;
content: '';
background-color: ${get('colors.border.muted')};
}
${props =>
props.condensed &&
css`
padding-top: ${get('space.1')};
padding-bottom: 0;
&:last-child {
padding-bottom: ${get('space.3')};
}
.TimelineItem-Badge {
height: 16px;
margin-top: ${get('space.2')};
margin-bottom: ${get('space.2')};
color: ${get('colors.fg.muted')};
background-color: ${get('colors.canvas.default')};
border: 0;
}
`}
${sx};
`
export type TimelineBadgeProps = {children?: React.ReactNode} & SxProp
const TimelineBadge = (props: TimelineBadgeProps) => {
return (
<Box position="relative" zIndex={1}>
<Box
display="flex"
className="TimelineItem-Badge"
flexShrink={0}
borderRadius="50%"
borderWidth="2px"
borderStyle="solid"
borderColor="canvas.default"
overflow="hidden"
color="fg.muted"
bg="timeline.badgeBg"
width="32px"
height="32px"
mr={2}
ml="-15px"
alignItems="center"
justifyContent="center"
sx={props.sx}
>
{props.children}
</Box>
</Box>
)
}
const TimelineBody = styled.div<SxProp>`
min-width: 0;
max-width: 100%;
margin-top: ${get('space.1')};
color: ${get('colors.fg.muted')};
flex: auto;
font-size: ${get('fontSizes.1')};
${sx};
`
const TimelineBreak = styled.div<SxProp>`
position: relative
z-index: 1;
height: 24px;
margin: 0;
margin-bottom: -${get('space.3')};
margin-left: 0;
background-color: ${get('colors.canvas.default')};
border: 0;
border-top: ${get('space.1')} solid ${get('colors.border.default')};
${sx};
`
TimelineItem.displayName = 'Timeline.Item'
TimelineBadge.displayName = 'Timeline.Badge'
TimelineBody.displayName = 'Timeline.Body'
TimelineBreak.displayName = 'Timeline.Break'
export type TimelineProps = ComponentProps<typeof Timeline>
export type TimelineItemsProps = ComponentProps<typeof TimelineItem>
export type TimelineBodyProps = ComponentProps<typeof TimelineBody>
export type TimelineBreakProps = ComponentProps<typeof TimelineBreak>
export default Object.assign(Timeline, {
Item: TimelineItem,
Badge: TimelineBadge,
Body: TimelineBody,
Break: TimelineBreak
})