slate/components/core/Section.js

122 lines
2.8 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
const STYLES_SECTION = css`
2020-08-09 06:52:22 +03:00
flex-shrink: 0;
width: 100%;
min-width: 960px;
box-shadow: 0 0 0 1px ${Constants.system.gray}, 0 1px 4px rgba(0, 0, 0, 0.04);
border-radius: 4px;
font-weight: 400;
margin-top: 24px;
2020-09-09 20:56:35 +03:00
white-space: pre-wrap;
:first-child {
margin-top: 0px;
}
`;
const STYLES_HEADER = css`
background: ${Constants.system.foreground};
border-bottom: 1px solid ${Constants.system.border};
font-family: ${Constants.font.medium};
font-size: ${Constants.typescale.lvl1};
border-radius: 4px 4px 0 0;
2020-07-27 12:50:25 +03:00
padding: 24px 24px 24px 20px;
overflow: hidden;
display: flex;
2020-08-09 06:52:22 +03:00
width: 100%;
align-items: center;
justify-content: space-between;
`;
const STYLES_LEFT = css`
min-width: 5%;
width: 100%;
overflow-wrap: break-word;
white-space: pre-wrap;
`;
const STYLES_RIGHT = css`
flex-shrink: 0;
`;
const STYLES_CHILDREN = css`
background: ${Constants.system.white};
border-radius: 0 0 4px 4px;
2020-08-09 06:52:22 +03:00
width: 100%;
`;
const STYLES_BUTTON = css`
border-radius: 4px;
outline: 0;
border: 0;
min-height: 32px;
padding: 6px 16px 6px 16px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 12px;
letter-spacing: 0.2px;
font-family: ${Constants.font.semiBold};
transition: 200ms ease all;
box-shadow: 0 0 0 1px ${Constants.system.border}, 0 1px 4px rgba(0, 0, 0, 0.07);
cursor: pointer;
background-color: ${Constants.system.white};
color: ${Constants.system.black};
margin-left: 16px;
:first-child {
margin-left: 0px;
}
:hover {
background-color: #f2f4f8;
}
:focus {
box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.3) inset;
outline: 0;
border: 0;
}
`;
export const Section = (props) => {
return (
<div css={STYLES_SECTION} style={props.style}>
<header css={STYLES_HEADER}>
{props.title ? <div css={STYLES_LEFT}>{props.title}</div> : null}
{props.buttons ? (
<div css={STYLES_RIGHT}>
{props.buttons.map((b) => {
if (b.onClick) {
return (
<label key={b.name} css={STYLES_BUTTON} onClick={b.onClick}>
{b.name}
</label>
);
}
return (
2020-09-23 14:17:56 +03:00
<label
key={b.name}
2020-09-23 14:17:56 +03:00
htmlFor={b.type}
css={STYLES_BUTTON}
2020-09-23 14:17:56 +03:00
onClick={b.type !== "file" ? () => props.onAction(b) : null}
>
{b.name}
2020-09-23 14:17:56 +03:00
</label>
);
})}
</div>
) : null}
</header>
<div css={STYLES_CHILDREN}>{props.children}</div>
</div>
);
};
export default Section;