1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-19 13:30:32 +09:00
namae/web/src/components/Cards.js

75 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-08-01 00:58:44 +09:00
import React, { useState } from 'react'
2019-07-31 13:11:00 +09:00
import styled from 'styled-components'
2019-08-01 00:58:44 +09:00
import { AvailabilityContainer } from './Availability'
2019-07-31 13:11:00 +09:00
import { mobile } from '../util/css'
export function Card({ title, nameList, alternativeList = [], children }) {
2019-07-31 18:41:44 +09:00
const [revealAlternatives, setRevealAlternatives] = useState(false)
2019-07-31 13:11:00 +09:00
function onClick() {
2019-07-31 18:41:44 +09:00
setRevealAlternatives(true)
2019-07-31 13:11:00 +09:00
}
return (
<CardWrapper>
<CardTitle>{title}</CardTitle>
2019-08-01 00:58:44 +09:00
<CardList>
2019-07-31 13:11:00 +09:00
{nameList.map((name) => (
2019-08-01 00:58:44 +09:00
<AvailabilityContainer>{children(name)}</AvailabilityContainer>
2019-07-31 13:11:00 +09:00
))}
2019-07-31 18:41:44 +09:00
{revealAlternatives &&
alternativeList.map((name) => (
2019-08-01 00:58:44 +09:00
<AvailabilityContainer>{children(name)}</AvailabilityContainer>
2019-07-31 18:41:44 +09:00
))}
2019-08-01 00:58:44 +09:00
{alternativeList.length > 0 && !revealAlternatives ? (
<ShowAlternativesButton onClick={onClick}>
show more
</ShowAlternativesButton>
) : null}
</CardList>
2019-07-31 13:11:00 +09:00
</CardWrapper>
)
}
const CardWrapper = styled.div`
2019-08-01 00:58:44 +09:00
margin-bottom: 40px;
2019-07-31 13:11:00 +09:00
padding: 40px;
${mobile} {
2019-08-01 00:58:44 +09:00
padding: 0px;
2019-07-31 13:11:00 +09:00
}
`
2019-07-31 18:41:44 +09:00
const CardTitle = styled.div`
2019-08-01 01:48:55 +09:00
margin-bottom: 15px;
2019-07-31 18:41:44 +09:00
font-size: 0.8rem;
font-weight: bold;
2019-08-01 00:58:44 +09:00
${mobile} {
padding-left: 20px;
}
`
const CardList = styled.div`
border-radius: 2px;
${mobile} {
padding: 20px;
box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
2019-08-01 01:48:55 +09:00
background: white;
2019-08-01 00:58:44 +09:00
border-radius: 0;
}
2019-07-31 18:41:44 +09:00
`
2019-07-31 13:11:00 +09:00
const ShowAlternativesButton = styled.div`
display: inline-block;
margin-top: 10px;
padding: 5px 0;
border: none;
border-bottom: 1px dashed black;
cursor: pointer;
font-family: monospace;
font-size: 1rem;
`