import * as React from 'react'; import styled from 'styled-components'; // @ts-ignore const colorable = require('colorable'); // @ts-ignore import { CopyToClipboard } from 'react-copy-to-clipboard'; import { HeaderProps, PassFailProps, ColorPropertyProps, ColorProps } from './interface'; import * as tokens from '@tokens'; const ColorCard = styled.div` display: flex; flex-direction: row; margin-bottom: 15px; border: 1px solid ${tokens.colorGrey5}; `; const Container = styled.div` flex: 1 0 50%; padding: 15px; `; const Header = styled(Container)` background: ${(props: HeaderProps) => props.hsl || props.gradient}; border-right: 1px solid ${tokens.colorGrey5}; display: flex; justify-content: center; min-height: 70px; position: relative; `; const PassFailGroup = styled.div` display: inline-flex; padding: 0 7.5px; margin-top: auto; `; const PassFailItem = styled.div` display: inline-flex; flex-direction: column; text-align: center; padding: 0 5px; `; const PassFailKey = styled.span` color: ${(props: PassFailProps) => props.color}; font-size: ${(props: PassFailProps) => (props.size === 'aaLarge' ? `16px` : `14px`)}; line-height: 24px; `; const PassFailStatus = styled.span` font-size: 11px; text-transform: uppercase; font-weight: 600; background: #000; color: #fff; padding: 2px 4px; line-height: 10px; border-radius: 4px; letter-spacing: 0.05em; `; const Body = styled(Container)` background: ${tokens.colorGrey1}; `; const Property = styled.div` margin-bottom: 7.5px; display: flex; flex-direction: row; `; const Key = styled.span` flex: 0 0 100px; font-weight: 600; margin-right: 7.5px; text-transform: uppercase; `; const Value = styled.span` flex: 1 1 auto; font-family: Rapha Serif Head, serif; `; const CopyHex = styled.span` background: ${tokens.colorGrey5}; border-radius: 3px; font-size: 10px; font-weight: ${tokens.fontWeightBold}; opacity: 0; padding: 5px 10px; position: absolute; right: 15px; top: 15px; transition: opacity 0.1s ease-in-out; ${/* sc-selector */ Header}:hover & { opacity: 1; } `; const ColorProperty: React.FC = ({ label, value }) => ( {label} {value} ); const Color: React.FC = ({ color }) => { const [contrast] = colorable([`${color.hex}`, '#000', '#FFF']); return (
{contrast.combinations.map((combination: any) => { const { aaa, aaaLarge, ...accessibility } = combination.accessibility; return Object.keys(accessibility).map(key => ( A {combination.accessibility[key] ? 'pass' : 'fail'} )); })} Copy HSL
{color.name && } {color.id && } {color.hsl && } {color.scss && } {color.js && } {color.hex && } {color.gradient && }
); }; export default Color;