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

92 lines
1.9 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'
2019-08-02 16:27:05 +09:00
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-03 16:44:48 +09:00
<AvailabilityContainer key={name}>
{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-03 16:44:48 +09:00
<AvailabilityContainer key={name}>
{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>
)
}
2019-08-02 04:23:21 +09:00
export const Cards = styled.div``
2019-08-01 13:21:23 +09:00
export const CardContainer = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
${mobile} {
flex-direction: column;
}
`
2019-07-31 13:11:00 +09:00
const CardWrapper = styled.div`
padding: 40px;
${mobile} {
2019-08-01 13:21:23 +09:00
margin-bottom: 40px;
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-08-02 04:23:21 +09:00
font-size: 1rem;
2019-07-31 18:41:44 +09:00
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`
2019-08-02 16:48:54 +09:00
margin-top: 5px;
2019-07-31 13:11:00 +09:00
display: inline-block;
padding: 5px 0;
border: none;
border-bottom: 1px dashed black;
cursor: pointer;
font-family: monospace;
2019-08-02 16:27:05 +09:00
font-size: 0.8em;
2019-07-31 13:11:00 +09:00
`