From 6fa0dca9d4c6db82f710ba40ff57758a154bcc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20K=C3=BCchler?= Date: Thu, 7 Dec 2017 14:36:24 +0100 Subject: [PATCH] feat(lsg): handleClick for element and icons pattern --- src/lsg/patterns/element/demo.tsx | 22 +++++++++++++- src/lsg/patterns/element/index.tsx | 28 ++++++++++++++++-- src/lsg/patterns/icons/index.tsx | 46 +++++++++++++++--------------- 3 files changed, 70 insertions(+), 26 deletions(-) diff --git a/src/lsg/patterns/element/demo.tsx b/src/lsg/patterns/element/demo.tsx index add6d1353..ae529c53a 100644 --- a/src/lsg/patterns/element/demo.tsx +++ b/src/lsg/patterns/element/demo.tsx @@ -1,3 +1,4 @@ +import { IconName, IconRegistry } from '../icons'; import Element from './index'; import * as React from 'react'; import styled from 'styled-components'; @@ -11,11 +12,30 @@ const StyledTestDiv = styled.div` const ElementDemo: React.StatelessComponent = (): JSX.Element => (
- Child + { + console.log('Clicked'); + }} + title="Element" + > + Child + + + + + Child + + + + Child + + + +
); diff --git a/src/lsg/patterns/element/index.tsx b/src/lsg/patterns/element/index.tsx index 69c387d97..8f052e98a 100644 --- a/src/lsg/patterns/element/index.tsx +++ b/src/lsg/patterns/element/index.tsx @@ -1,13 +1,24 @@ import { colors } from '../colors'; +import { Icon, IconName, Size as IconSize } from '../icons'; import * as React from 'react'; import styled from 'styled-components'; export interface ElementProps { active?: boolean; + open?: boolean; title: string; + + handleIconClick?: React.MouseEventHandler; +} + +export interface StyledElementChildProps { + open?: boolean; } const StyledElement = styled.div` + display: flex; + flex-wrap: wrap; + align-items: center; padding: 0 15px; line-height: 30px; margin-top: 0; @@ -25,16 +36,29 @@ const StyledElement = styled.div` `; const StyledElementChild = styled.div` + flex-basis: 100%; padding-left: 15px; + ${(props: StyledElementChildProps) => (props.open ? 'display: block;' : 'display: none;')}; +`; + +const StyledIcon = styled(Icon)` + margin-right: 20px; + fill: ${colors.grey70.toString()}; `; const Element: React.StatelessComponent = props => { - const { children, title, active } = props; + const { children, title, active, open, handleIconClick } = props; return ( + {title} - {children} + {children} ); }; diff --git a/src/lsg/patterns/icons/index.tsx b/src/lsg/patterns/icons/index.tsx index 13bd5e3fb..f81aa6d3c 100644 --- a/src/lsg/patterns/icons/index.tsx +++ b/src/lsg/patterns/icons/index.tsx @@ -14,6 +14,7 @@ export interface IconProps { color?: Color; name: IconName | null; size?: Size; + handleClick?: React.MouseEventHandler; } export enum Size { @@ -33,9 +34,7 @@ interface IconRegistrySymbolProps { const icons: { readonly [key: string]: JSX.Element[][] | JSX.Element[] } = { [IconName.Robo]: [ - [ - - ] + [] ] }; @@ -47,38 +46,31 @@ const StyledIcon = styled.svg` width: ${(props: StyledIconProps) => props.size || Size.S}px; height: ${(props: StyledIconProps) => props.size || Size.S}px; - color: ${(props: StyledIconProps) => props.iconColor - ? props.iconColor.toString() - : 'inherit' - }; + color: ${(props: StyledIconProps) => (props.iconColor ? props.iconColor.toString() : 'inherit')}; fill: currentColor; stroke: none; stroke-miterlimit: 10; - - @media (max-resolution: 124dpi) { + @media (max-resolution: 124dpi) { stroke-width: 1.2px; } `; -const IconRegistrySymbol: React.StatelessComponent = props => - ( - - {props.children} - - ); +const IconRegistrySymbol: React.StatelessComponent = props => ( + + {props.children} + +); -export const IconRegistry: React.StatelessComponent = (props): JSX.Element => -( +export const IconRegistry: React.StatelessComponent = (props): JSX.Element => ( {reduce(props.names, (name, e) => { const iconReg = icons[e]; return [ - {iconReg} + + {iconReg} + ]; })} @@ -91,13 +83,21 @@ function getIconRef(name: string): string { export const Icon: React.StatelessComponent = (props): JSX.Element => { const icon = typeof props.name === 'number' ? IconName[props.name] : null; return ( - + {icon !== null && } ); }; -export function reduce(e: typeof IconName, cb: (name: string, e: number) => JSX.Element[]): JSX.Element[] { +export function reduce( + e: typeof IconName, + cb: (name: string, e: number) => JSX.Element[] +): JSX.Element[] { const results = []; for (const name in e) { if (isNaN(Number(name))) {