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

Commit

Permalink
feat(lsg): introduce dropdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexpeschel committed Dec 18, 2017
1 parent 3517990 commit 5c60539
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
99 changes: 99 additions & 0 deletions src/lsg/patterns/dropdown-item/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Color, colors } from '../colors';
import { Icon, IconName, Size as IconSize } from '../icons';
import * as React from 'react';
import { getSpace, Size as SpaceSize } from '../space';
import styled from 'styled-components';

export interface DropdownItemProps {
// active?: boolean;
color?: Color;
name: string;
icon?: IconName;
handleClick?: React.MouseEventHandler<HTMLElement>;
}

export interface StyledDropdownItemLinkProps {
color?: Color;
handleClick?: React.MouseEventHandler<HTMLElement>;
}

const StyledDropdownItem = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: ${getSpace(SpaceSize.S)}px;
:last-child {
margin-bottom: 0;
}
`;

const StyledDropdownItemLink = styled.a`
display: flex;
align-items: center;
flex-grow: 1;
font-size: 12px;
cursor: pointer;
${(props: StyledDropdownItemLinkProps) =>
props.color ? `color: ${props.color.toString()}` : 'color: inherit'};
:hover {
color: ${colors.blueLight.toString()};
}
`;

const StyledDropdownItemIcon = styled(Icon)`
margin-right: ${getSpace(SpaceSize.XS)}px;
`;

const StyledDropdownItemLinkAttribute = styled.div`
display: none;
${StyledDropdownItem}:hover & {
display: flex;
}
`;

const StyledDropdownItemLinkAttributeItem = styled.a`
font-size: 10px;
color: ${colors.grey70.toString()};
margin-right: ${getSpace(SpaceSize.XXS)}px;
cursor: pointer;
:hover {
color: ${colors.blueLight.toString()};
}
`;

export default class DropdownItem extends React.Component<DropdownItemProps> {
public render(): JSX.Element {
return (
<StyledDropdownItem>
<StyledDropdownItemLink handleClick={this.props.handleClick}>
{this.props.icon && (
<StyledDropdownItemIcon size={IconSize.XXS} name={this.props.icon} />
)}
{this.props.name}
</StyledDropdownItemLink>
{this.props.children}
</StyledDropdownItem>
);
}
}

export class DropdownItemLinkAttribute extends React.Component<{}> {
public render(): JSX.Element {
return (
<StyledDropdownItemLinkAttribute>{this.props.children}</StyledDropdownItemLinkAttribute>
);
}
}

export class DropdownItemLinkAttributeItem extends React.Component<{}> {
public render(): JSX.Element {
return (
<StyledDropdownItemLinkAttributeItem>
{this.props.children}
</StyledDropdownItemLinkAttributeItem>
);
}
}
7 changes: 7 additions & 0 deletions src/lsg/patterns/dropdown-item/pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "dropdown-item",
"displayName": "Dropdown Item",
"flag": "alpha",
"version": "1.0.0",
"tags": ["dropdown-item"]
}
42 changes: 42 additions & 0 deletions src/lsg/patterns/dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { colors } from '../colors';
import * as React from 'react';
import { getSpace, Size as SpaceSize } from '../space';
import styled from 'styled-components';

export interface DropdownProps {
chrome?: boolean;
visible?: boolean;
}

export interface StyledDropdownProps {
visible?: boolean;
}

const StyledDropdown = styled.div`
${(props: StyledDropdownProps) => (props.visible ? 'display: block' : 'display: none')};
padding: ${getSpace(SpaceSize.S)}px ${getSpace(SpaceSize.S)}px ${getSpace(SpaceSize.L)}px;
border: 1px solid ${colors.grey90.toString()};
background: ${colors.white.toString()};
border-radius: 3px;
`;

const StyledChromeDropdown = styled(StyledDropdown)`
position: absolute;
top: 45px;
left: 50%;
min-width: 200px;
transform: translateX(-50%);
`;

export default class Dropdown extends React.Component<DropdownProps> {
public render(): JSX.Element {
if (this.props.chrome) {
return (
<StyledChromeDropdown visible={this.props.visible}>
{this.props.children}
</StyledChromeDropdown>
);
}
return <StyledDropdown visible={this.props.visible}>{this.props.children}</StyledDropdown>;
}
}
7 changes: 7 additions & 0 deletions src/lsg/patterns/dropdown/pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "dropdown",
"displayName": "Dropdown",
"flag": "alpha",
"version": "1.0.0",
"tags": ["dropdown"]
}

0 comments on commit 5c60539

Please sign in to comment.