make accordeon ccs-only

This commit is contained in:
neri 2020-01-14 20:55:53 +01:00
parent dcaff99369
commit 8dc888e7c6
2 changed files with 28 additions and 14 deletions

View File

@ -1,19 +1,19 @@
import React, { useState } from "react" import React from "react"
import accordionStyles from "./accordion.module.css" import accordionStyles from "./accordion.module.css"
export default ({ title, initial, children }) => { export default ({ title, children }) => {
const [open, setOpen] = useState(initial)
return ( return (
<> <div>
<div <input
className={accordionStyles.header} hidden={true}
onClick={() => setOpen(open => !open)} type="checkbox"
> id={`tab-${title}`}
<span>{title}</span> name={`tab-${title}`}
<span>{open ? "" : "∧"}</span> />
</div> <label htmlFor={`tab-${title}`} className={accordionStyles.header}>
{open ? <div className={accordionStyles.content}>{children}</div> : null} {title}
</> </label>
<div className={accordionStyles.content}>{children}</div>
</div>
) )
} }

View File

@ -7,7 +7,21 @@
justify-content: space-between; justify-content: space-between;
} }
label:after {
content: "";
right: 1em;
}
input:checked + label:after {
content: "∧";
}
.content { .content {
margin-bottom: 1.5em; margin-bottom: 1.5em;
padding: 0 2em; padding: 0 2em;
display: none;
}
input:checked ~ .content {
display: block;
} }