Skip to content

Instantly share code, notes, and snippets.

@SebastianHGonzalez
Created August 23, 2019 20:35
Show Gist options
  • Select an option

  • Save SebastianHGonzalez/c1b5dcd42f07e24c934580993a8c9968 to your computer and use it in GitHub Desktop.

Select an option

Save SebastianHGonzalez/c1b5dcd42f07e24c934580993a8c9968 to your computer and use it in GitHub Desktop.
import React from "react";
import { string, bool } from "prop-types";
import styled from "styled-components";
import { Collapse } from "react-collapse";
const Legend = styled.legend`
display: flex;
width: 100%;
justify-content: space-between;
`;
const Title = styled.h2`
font-weight: 500;
display: grid;
grid-gap: 1rem;
grid-template-columns: auto auto;
`;
const Controls = styled.div`
display: inline-flex;
align-items: center;
`;
function Fieldset({ className, title, controls, collapsed, onToggleCollapsed, children }) {
return (
<fieldset className={className} >
<Legend>
<Title onClick={onToggleCollapsed}>{title}</Title>
<Controls>{controls}</Controls>
</Legend>
<Collapse isOpened={!collapsed}>{children}</Collapse>
</fieldset>
);
}
Fieldset.propTypes = {
className: string,
collapsed: bool
};
Fieldset.defaultProps = {
className: undefined,
collapsed: false
};
export default styled(Fieldset)`
border: 0;
border-bottom: 1px solid ${({ theme }) => theme.table.separator};
margin-top: 0;
padding-top: 0;
margin-bottom: 2rem;
padding-bottom: 2rem;
${Legend}+* {
max-width: 70rem;
}
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment