This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lsg): introduce dropdown component
- Loading branch information
1 parent
3517990
commit 5c60539
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |