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

Commit

Permalink
feat(lsg): new pattern boolean-item
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Küchler authored and lkuechler committed Dec 11, 2017
1 parent 94cbcc6 commit 872d910
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/lsg/patterns/property-items/boolean-item/demo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import BooleanItem from './index';
import * as React from 'react';
import styled from 'styled-components';

const StyledDemo = styled.div`
width: 200px;
margin-bottom: 20px;
`;

export interface BooleanItemDemoState {
checked?: boolean;
}

export class BooleanItemDemo extends React.Component<{}, BooleanItemDemoState> {
public constructor(props: {}) {
super(props);

this.state = {
checked: false
};

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

private handleChange(e: React.SyntheticEvent<HTMLElement>): void {
this.setState({
checked: !this.state.checked
});
}

public render(): JSX.Element {
return (
<div>
<StyledDemo>
<BooleanItem
label="Visibility"
checked={this.state.checked}
handleChange={this.handleChange}
/>
</StyledDemo>
<StyledDemo>
<BooleanItem
label="Spacing"
checked={!this.state.checked}
handleChange={this.handleChange}
/>
</StyledDemo>
</div>
);
}
}

export default BooleanItemDemo;
89 changes: 89 additions & 0 deletions src/lsg/patterns/property-items/boolean-item/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { colors } from '../../colors';
import { fonts } from '../../fonts';
import * as React from 'react';
import styled from 'styled-components';

export interface BooleanItemProps {
label: string;
checked?: boolean;
className?: string;
handleChange?: React.ChangeEventHandler<HTMLElement>;
}

interface IndicatorProps {
checked?: boolean;
}

const StyledBooleanItem = styled.div`
width: 100%;
`;

const StyledLabelWrapper = styled.label`
display: flex;
justify-content: space-between;
align-items: center;
`;

const indicatorWidth = 18;
const indicatorHeight = 8;
const indicatorBorderWidth = 1;

const StyledIndicator = styled.span`
position: relative;
display: inline-block;
width: ${indicatorWidth}px;
height: ${indicatorHeight}px;
border-radius: 5px;
box-sizing: border-box;
border: ${indicatorBorderWidth}px solid transparent;
box-shadow: 0 0 0 ${indicatorBorderWidth}px ${colors.grey70.toString()};
&::after {
content: '';
display: block;
width: 6px;
height: 6px;
transform: translateX(0px);
border-radius: 100%;
background: ${colors.grey70.toString()};
transition: transform ease-in-out 0.5s;
}
${(props: IndicatorProps) =>
props.checked
? `
background: ${colors.blue.toString()};
border-color: ${colors.blue.toString()};
box-shadow: 0 0 0 ${indicatorBorderWidth}px ${colors.blue.toString()};
&::after {
transform: translateX(${indicatorWidth / 2 + indicatorBorderWidth}px);
background: ${colors.white.toString()};
}
`
: ''};
`;

const StyledLabel = styled.span`
font-size: 14px;
font-family: ${fonts().NORMAL_FONT};
color: ${colors.grey70.toString()};
`;

const StyledInput = styled.input`
display: none;
`;

export const BooleanItem: React.StatelessComponent<BooleanItemProps> = props => {
const { className, label, children, checked, handleChange } = props;

return (
<StyledBooleanItem className={className}>
<StyledLabelWrapper>
<StyledLabel>{label}</StyledLabel>
<StyledInput onChange={handleChange} type="checkbox" />
<StyledIndicator checked={checked} />
</StyledLabelWrapper>
{children}
</StyledBooleanItem>
);
};

export default BooleanItem;
5 changes: 5 additions & 0 deletions src/lsg/patterns/property-items/boolean-item/pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "boolean-item",
"displayName": "Boolean Item",
"version": "1.0.0"
}

0 comments on commit 872d910

Please sign in to comment.