Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: integrate pattern list items
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexpeschel committed Dec 13, 2017
1 parent a968f87 commit e7e6abd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
40 changes: 25 additions & 15 deletions src/component/container/pattern_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { action } from 'mobx';
import { observer } from 'mobx-react';
import { PageElement } from '../../store/page/page_element';
import { Pattern } from '../../store/pattern';
import PatternListItem from '../../lsg/patterns/pattern-list-item';
import * as React from 'react';
import { Store } from '../../store';

Expand Down Expand Up @@ -36,7 +37,7 @@ export class PatternList extends React.Component<PatternListProps> {
const list = this.createList(this.items);
return (
<div>
<Input handleChange={this.handleSearchInputChange} />
<Input handleChange={this.handleSearchInputChange} placeholder="Search"/>
<List headline="Patterns">{list}</List>
</div>
);
Expand Down Expand Up @@ -75,20 +76,29 @@ export class PatternList extends React.Component<PatternListProps> {
{items.map((props: ListItemProps, index: number) => {
const labelComponent = props.label ? <Label>{props.label}:</Label> : null;
const nextLevel = props.children ? this.createList(props.children) : null;

return (
<Li
draggable={props.draggable}
handleDragStart={props.handleDragStart}
key={index}
active={props.active}
onClick={props.onClick}
>
{labelComponent}
<Value>{props.value}</Value>
{nextLevel}
</Li>
);
if (nextLevel) {
return (
<Li key={index}>
{labelComponent}
<Value>{props.value}</Value>
{nextLevel}
</Li>
);
} else {
return (
<PatternListItem
draggable={props.draggable}
handleDragStart={props.handleDragStart}
key={index}
active={props.active}
onClick={props.onClick}
>
{labelComponent}
<Value>{props.value}</Value>
{nextLevel}
</PatternListItem>
);
}
})}
</Ul>
);
Expand Down
2 changes: 1 addition & 1 deletion src/lsg/patterns/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface LiProps {

const StyledUl = styledComponents.ul`
box-sizing: border-box;
padding: 0 0 0 15px;
padding: 0;
margin: 0;
width: 100%;
`;
Expand Down
8 changes: 5 additions & 3 deletions src/lsg/patterns/pattern-list-item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { colors } from '../colors';
import { fonts } from '../fonts';
import { Icon, IconName, Size as IconSize } from '../icons';
import { LiProps } from '../list';
import * as React from 'react';
import { getSpace, Size } from '../space';
import styled from 'styled-components';

export interface PatternListItemProps {
export interface PatternListItemProps extends LiProps {
className?: string;
icon?: string;
}
Expand All @@ -16,6 +17,7 @@ const StyledPatternListItem = styled.li`
cursor: default;
padding: ${getSpace(Size.S)}px;
border: 1px solid ${colors.grey90.toString()};
margin: 0 0 ${getSpace(Size.S)}px 0;
border-radius: 3px;
background: ${colors.white.toString()};
font-family: ${fonts().NORMAL_FONT};
Expand All @@ -33,10 +35,10 @@ const StyledIcon = styled(Icon)`
`;

const PatternListItem: React.StatelessComponent<PatternListItemProps> = props => (
<StyledPatternListItem className={props.className}>
<StyledPatternListItem {...props}>
{props.icon
? <StyledSVG>
<use xlinkHref={props.icon} />
{props.icon}
</StyledSVG>
: <StyledIcon name={IconName.Robo} size={IconSize.XS} color={colors.grey70} />
}
Expand Down

0 comments on commit e7e6abd

Please sign in to comment.