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

Commit

Permalink
feat(component): toggle for elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Küchler committed Dec 7, 2017
1 parent 6fa0dca commit ce93c6a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
44 changes: 44 additions & 0 deletions src/component/container/elementWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Element from '../../lsg/patterns/element';
import * as React from 'react';

export interface ElementWrapperState {
open?: boolean;
}

export interface ElementWrapperProps {
active?: boolean;
open?: boolean;
title: string;
}

export class ElementWrapper extends React.Component<ElementWrapperProps, ElementWrapperState> {
public constructor(props: ElementWrapperProps) {
super(props);

this.state = {
open: this.props.open
};

this.handleIconClick = this.handleIconClick.bind(this);
}

private handleIconClick(): void {
this.setState({
open: !this.state.open
});
}

public render(): JSX.Element {
const { active, children, title } = this.props;
return (
<Element
title={title}
open={!this.state.open}
active={active}
handleIconClick={this.handleIconClick}
>
{children}
</Element>
);
}
}
6 changes: 3 additions & 3 deletions src/component/container/element_list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Element from '../../lsg/patterns/element';
import { ElementWrapper } from './elementWrapper';
import { ListPropsListItem } from '../presentation/list';
import { observer } from 'mobx-react';
import { Page } from '../../store/page';
Expand Down Expand Up @@ -29,9 +29,9 @@ export class ElementList extends React.Component<ElementListProps> {

public renderList(item: ListPropsListItem, key?: number): JSX.Element {
return (
<Element title={item.value} key={key}>
<ElementWrapper title={item.value} key={key}>
{item.children && item.children.map((child, index) => this.renderList(child, index))}
</Element>
</ElementWrapper>
);
}

Expand Down

0 comments on commit ce93c6a

Please sign in to comment.