joyent-portal/packages/ui-toolkit/src/card/options.js

129 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-02-27 17:41:08 +02:00
import { Subscriber } from 'react-broadcast';
import styled from 'styled-components';
import { Nav } from 'normalized-styled-components';
import Baseline from '../baseline';
import remcalc from 'remcalc';
import is, { isNot } from 'styled-is';
import PropTypes from 'prop-types';
import Button from '../button';
import React from 'react';
2017-01-09 14:13:12 +02:00
const StyledNav = Nav.extend`
2017-01-09 14:13:12 +02:00
flex: 0 0 ${remcalc(47)};
border-left: ${remcalc(1)} solid ${props => props.theme.grey};
2017-02-27 17:41:08 +02:00
box-sizing: border-box;
${is('fromHeader')`
border-left-color: ${props => props.theme.primaryDesaturatedActive};
`};
${isNot('active')`
border-left-color: ${props => props.theme.grey};
`};
2017-01-09 14:13:12 +02:00
`;
const StyledButton = Button.extend`
2017-03-20 17:58:47 +02:00
position: relative;
2017-01-09 14:13:12 +02:00
border-width: 0;
box-shadow: none;
width: 100%;
min-width: ${remcalc(46)} !important;
height: ${remcalc(124)};
2017-02-27 17:41:08 +02:00
display: flex;
justify-content: center;
align-items: center;
2017-02-27 17:41:08 +02:00
overflow-x: visible;
overflow-y: visible;
${is('collapsed')`
height: ${remcalc(46)};
`};
2017-01-09 14:13:12 +02:00
&:focus {
border-width: 0;
}
&:hover {
border-width: 0;
}
&:active,
&:active:hover,
&:active:focus {
border-width: 0;
}
${isNot('active')`
background-color: ${props => props.theme.disabled};
border-color: ${props => props.theme.grey};
&:focus,
&:hover,
&:active,
&:active:hover,
&:active:focus {
background-color: ${props => props.theme.grey};
}
`}
2017-01-09 14:13:12 +02:00
`;
2017-03-20 17:58:47 +02:00
const StyledContainer = styled.div`
position: absolute;
left: 50%;
top: 35%; /* I don't know why this doesn't center with 50% */
2017-03-20 17:58:47 +02:00
`;
const StyledCircle = styled.div`
margin: 0 0 ${remcalc(2)} ${remcalc(-2)};
2017-03-20 17:58:47 +02:00
border-radius: 50%;
background-color: ${props => props.theme.white};
width: ${remcalc(4)};
height: ${remcalc(4)};
${is('secondary')`
background-color: ${props => props.theme.secondary};
`};
${isNot('active')`
background-color: ${props => props.theme.text};
`};
2017-03-20 17:58:47 +02:00
`;
const Options = ({ children, ...rest }) => {
const render = ({
fromHeader = false,
collapsed = false,
active = true
}) =>
<StyledNav active={active} fromHeader={fromHeader} name="card-options">
2017-02-27 17:41:08 +02:00
<StyledButton
secondary={!fromHeader}
collapsed={collapsed}
active={active}
2017-02-27 17:41:08 +02:00
rect
{...rest}
2017-02-27 17:41:08 +02:00
>
2017-03-20 17:58:47 +02:00
<StyledContainer>
<StyledCircle active={active} secondary={!fromHeader} />
<StyledCircle active={active} secondary={!fromHeader} />
<StyledCircle active={active} secondary={!fromHeader} />
2017-03-20 17:58:47 +02:00
</StyledContainer>
2017-02-27 17:41:08 +02:00
</StyledButton>
2017-06-12 01:58:22 +03:00
</StyledNav>;
2017-02-27 17:41:08 +02:00
return (
<Subscriber channel="card">
2017-02-27 17:41:08 +02:00
{render}
</Subscriber>
);
};
2017-01-09 14:13:12 +02:00
Options.propTypes = {
collapsed: PropTypes.bool,
fromHeader: PropTypes.bool
2017-01-09 14:13:12 +02:00
};
export default Baseline(Options);