-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create an Agenda component to list sessions
- Loading branch information
1 parent
1b4d48d
commit 0d1cf9e
Showing
8 changed files
with
285 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { Children, Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/core'; | ||
import Heading from './Heading'; | ||
import Session from './Session'; | ||
import Time from './Time'; | ||
|
||
const Agenda = ({ children, className, tracks }) => { | ||
const childrenArray = Children.toArray(children); | ||
|
||
const sessionsByTime = childrenArray | ||
.filter((child) => child.type === Session) | ||
.reduce((memo, child) => { | ||
const { time } = child.props; | ||
|
||
return memo.set( | ||
time, | ||
memo.has(time) ? [...memo.get(time), child] : [child] | ||
); | ||
}, new Map()); | ||
|
||
return ( | ||
<div | ||
className={className} | ||
css={css` | ||
display: grid; | ||
grid-template-columns: 0.75fr repeat(${tracks.length}, 1fr); | ||
`} | ||
> | ||
<Heading | ||
css={css` | ||
grid-column-start: 2; | ||
`} | ||
> | ||
{tracks[0]} | ||
</Heading> | ||
|
||
{tracks.slice(1).map((track) => ( | ||
<Heading key={track}>{track}</Heading> | ||
))} | ||
|
||
{Array.from(sessionsByTime).map(([time, sessions]) => ( | ||
<Fragment key={time}> | ||
<Time>{time}</Time> | ||
{sessions} | ||
</Fragment> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
Agenda.propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
tracks: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
}; | ||
|
||
Agenda.Session = Session; | ||
|
||
export default Agenda; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import PropTypes from 'prop-types'; | ||
import styled from '@emotion/styled'; | ||
|
||
const Cell = styled.div` | ||
padding: 1rem; | ||
box-shadow: 0 0 0 1px var(--color-neutrals-400); | ||
background-color: ${({ inactive }) => | ||
inactive ? 'var(--color-neutrals-100)' : '#fff'}; | ||
.dark-mode & { | ||
background-color: ${({ inactive }) => | ||
inactive ? '#284049' : 'var(--color-dark-100)'}; | ||
box-shadow: 0 0 0 1px var(--color-dark-400); | ||
} | ||
`; | ||
|
||
Cell.propTypes = { | ||
inactive: PropTypes.bool, | ||
}; | ||
|
||
export default Cell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/core'; | ||
import Cell from './Cell'; | ||
|
||
const Heading = ({ children, className }) => ( | ||
<Cell | ||
inactive | ||
as="h5" | ||
className={className} | ||
css={css` | ||
color: var(--color-teal-600); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin: 0; | ||
padding: 0.75rem; | ||
text-align: center; | ||
text-transform: uppercase; | ||
font-size: 0.75rem; | ||
font-weight: 700; | ||
letter-spacing: 0.5px; | ||
.dark-mode & { | ||
color: #ade7ec; | ||
} | ||
`} | ||
> | ||
{children} | ||
</Cell> | ||
); | ||
|
||
Heading.propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
}; | ||
|
||
export default Heading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/core'; | ||
import Cell from './Cell'; | ||
|
||
const Session = ({ inactive, time, speaker, title, span }) => ( | ||
<Cell | ||
inactive={inactive} | ||
css={css` | ||
grid-column: span ${span}; | ||
text-align: center; | ||
`} | ||
> | ||
<h4 | ||
css={css` | ||
font-size: 1rem; | ||
font-weight: 700; | ||
margin-bottom: 0.25rem; | ||
`} | ||
> | ||
{title} | ||
</h4> | ||
<div | ||
css={css` | ||
display: block; | ||
font-size: 0.75rem; | ||
text-transform: uppercase; | ||
letter-spacing: 0.05rem; | ||
font-weight: normal; | ||
user-select: text; | ||
`} | ||
> | ||
{speaker} | ||
</div> | ||
</Cell> | ||
); | ||
|
||
Session.propTypes = { | ||
inactive: PropTypes.bool, | ||
time: PropTypes.string, | ||
speaker: PropTypes.string, | ||
title: PropTypes.string, | ||
span: PropTypes.number, | ||
}; | ||
|
||
Session.defaultProps = { | ||
span: 1, | ||
}; | ||
|
||
export default Session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import styled from '@emotion/styled'; | ||
import Cell from './Cell'; | ||
|
||
const Time = styled(Cell)` | ||
font-weight: 700; | ||
display: flex; | ||
align-items: center; | ||
color: var(--heading-text-color); | ||
`; | ||
|
||
export default Time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Agenda'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters