Skip to content

Commit f364987

Browse files
Lifelines page styling (#88)
* Add draggable dots * Style Lifelines Page * Fix build * Convert to styled component * fixed styled components bug * fixed styling for cards * fix styling for cards * fix imports * add input Co-authored-by: daniel-moon32 <[email protected]>
1 parent b426535 commit f364987

File tree

6 files changed

+494
-127
lines changed

6 files changed

+494
-127
lines changed

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"react-scripts": "5.0.0",
3838
"react-select": "^5.2.2",
3939
"styled-components": "^5.3.5",
40+
"styled-icons": "^10.45.0",
4041
"typescript": "^4.5.5",
4142
"web-vitals": "^2.1.4"
4243
},

client/src/components/draggable/DraggableLifelines.tsx

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TrashAlt } from '@styled-icons/boxicons-solid'
2+
import { ReOrderDotsVertical } from '@styled-icons/fluentui-system-filled/ReOrderDotsVertical'
23
import { CSSProperties, useEffect, useState } from 'react'
34
import {
45
DragDropContext,
@@ -8,6 +9,7 @@ import {
89
DropResult,
910
NotDraggingStyle,
1011
} from 'react-beautiful-dnd'
12+
import styled, { css } from 'styled-components'
1113

1214
import { ModuleResInterface } from '../../interfaces'
1315
import {
@@ -20,11 +22,38 @@ import LifelineCard from './LifelineCard'
2022
interface DraggableLifelinesInterface {
2123
lifelinesProp: ModuleResInterface[]
2224
}
25+
const StyledDiv = styled.div`
26+
display: flex;
27+
background: #f1f1f1;
28+
border-radius: 10px;
29+
width: 92.5%;
30+
padding: 0 2% 0 1%;
31+
grid-column: 2;
32+
border: 2px lightgrey solid;
33+
${(props) =>
34+
props.draggingOver
35+
? css`
36+
border-color: ${({ theme }) => theme.buttonBackground};
37+
`
38+
: css`
39+
border-color: ${({ theme }) => theme.secondaryText};
40+
`}
41+
`
42+
const Card = styled.div`
43+
display: flex;
44+
align-self: center;
45+
width: 5%;
46+
font-size: 1.29em;
47+
margin-left: 0%;
48+
`
2349

50+
const Alignment = styled.div`
51+
margin-left: 15%;
52+
align-self: center;
53+
`
2454
const DraggableLifelines = ({ lifelinesProp }: DraggableLifelinesInterface) => {
2555
const BASE_PADDING = 4
2656
const [lifelines, setLifelines] = useState<ModuleResInterface[]>([])
27-
2857
/* fill lifelines with passed in props for rendering */
2958
useEffect(() => {
3059
setLifelines(lifelinesProp)
@@ -41,19 +70,18 @@ const DraggableLifelines = ({ lifelinesProp }: DraggableLifelinesInterface) => {
4170

4271
const getDraggableItemStyle = (
4372
draggableStyle: DraggingStyle | NotDraggingStyle | undefined,
73+
isDraggingOver,
4474
): CSSProperties => ({
45-
padding: BASE_PADDING * 2,
46-
margin: `0 0 ${BASE_PADDING}px 0`,
75+
paddingBottom: BASE_PADDING * 2,
76+
margin: `0 0 15px 0`,
4777
alignItems: 'center',
4878
display: 'grid',
49-
gridTemplateColumns: '2.5fr 95fr 2.5fr',
50-
79+
gridTemplateColumns: '0fr 95fr 2.5fr',
5180
// styles we need to apply on draggables
5281
...draggableStyle,
5382
})
5483

5584
const getDroppableStyle = () => ({
56-
padding: `${BASE_PADDING}px`,
5785
margin: '0 auto',
5886
width: '95vw',
5987
})
@@ -84,41 +112,28 @@ const DraggableLifelines = ({ lifelinesProp }: DraggableLifelinesInterface) => {
84112
draggableId={index.toString()}
85113
index={index}
86114
>
87-
{(provided, _) => (
115+
{(provided, snapshot) => (
88116
<div
89117
ref={provided.innerRef}
90118
{...provided.draggableProps}
91119
{...provided.dragHandleProps}
92-
style={getDraggableItemStyle(provided.draggableProps.style)}
93-
>
94-
{index < NUM_LIFELINES_DISPLAYED && (
95-
<p
96-
style={{
97-
border: 'black 2px solid',
98-
borderRadius: '5px',
99-
gridColumn: 1,
100-
fontSize: '0.65em',
101-
justifySelf: 'center',
102-
padding: '10%',
103-
}}
104-
>
105-
{index + 1}
106-
</p>
120+
style={getDraggableItemStyle(
121+
provided.draggableProps.style,
122+
snapshot.draggingOver,
107123
)}
108-
<div
109-
style={{
110-
background: '#f1f1f1',
111-
borderRadius: '10px',
112-
width: '92.5%',
113-
padding: '0 2%',
114-
gridColumn: 2,
115-
}}
116-
>
124+
>
125+
<StyledDiv draggingOver={snapshot.draggingOver}>
126+
<Card>
127+
<ReOrderDotsVertical size="20px" />
128+
<Alignment>
129+
{index < NUM_LIFELINES_DISPLAYED && index + 1}
130+
</Alignment>
131+
</Card>
117132
<LifelineCard
118133
lifeline={lifeline}
119134
isDisplayed={index < NUM_LIFELINES_DISPLAYED}
120135
/>
121-
</div>
136+
</StyledDiv>
122137
{/* render delete button */}
123138
<TrashAlt
124139
size={'1.5em'}

client/src/components/draggable/LifelineCard.tsx

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PencilFill } from '@styled-icons/bootstrap'
1+
import styled from 'styled-components'
22

33
import { ModuleResInterface } from '../../interfaces'
44
import { returnFirstString } from '../../utils/utils'
@@ -7,45 +7,52 @@ interface LifelineCardInterface {
77
lifeline: ModuleResInterface
88
isDisplayed: boolean
99
}
10+
const Card = styled.div`
11+
display: flex;
12+
width: 100%;
13+
justify-content: space-between;
14+
padding: 10px;
15+
`
16+
const Text = styled.div`
17+
display: flex;
18+
flex-direction: column;
19+
margin-top: 0;
20+
justify-content: center;
21+
`
1022

23+
const Lifeline = styled.div`
24+
font-weight: 700;
25+
font-size: 18px;
26+
font-family: ${({ theme }) => theme.text};
27+
`
28+
29+
const Source = styled.div`
30+
margin-top: 8px;
31+
font-weight: 400;
32+
font-size: 18px;
33+
font-family: ${({ theme }) => theme.text};
34+
`
35+
const HideButton = styled.p`
36+
font-size: 0.8em;
37+
border: 1px black solid;
38+
padding: 5px 7.5px;
39+
border-radius: 5px;
40+
text-align: center;
41+
align-self: center;
42+
grid-column: 2;
43+
`
1144
const LifelineCard = ({
1245
lifeline: { labels, customizable },
1346
isDisplayed,
1447
}: LifelineCardInterface) => {
1548
return (
16-
<div
17-
style={{
18-
display: 'grid',
19-
gridTemplateColumns: '15fr 1fr 1fr',
20-
gridGap: '5px',
21-
}}
22-
>
23-
<h1 style={{ gridColumn: 1 }}>{returnFirstString(labels)}</h1>
24-
<p
25-
style={{
26-
fontSize: '0.8em',
27-
border: '1px black solid',
28-
padding: '5px 7.5px',
29-
borderRadius: '5px',
30-
textAlign: 'center',
31-
alignSelf: 'center',
32-
gridColumn: 2,
33-
}}
34-
>
35-
{isDisplayed ? 'Hide' : 'Show'}
36-
</p>
37-
{customizable && (
38-
<PencilFill
39-
size={'1.5em'}
40-
style={{
41-
justifySelf: 'center',
42-
cursor: 'pointer',
43-
alignSelf: 'center',
44-
gridColumn: 3,
45-
}}
46-
/>
47-
)}
48-
</div>
49+
<Card>
50+
<Text>
51+
<Lifeline>{returnFirstString(labels)}</Lifeline>
52+
<Source>{customizable ? '' : 'Climate Clock'}</Source>
53+
</Text>
54+
<HideButton>{isDisplayed ? 'Hide' : 'Show'}</HideButton>
55+
</Card>
4956
)
5057
}
5158

0 commit comments

Comments
 (0)