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: add dropdown to pages, rename visible to open
- Loading branch information
1 parent
1144b25
commit 5b18a8a
Showing
4 changed files
with
137 additions
and
9 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
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,77 @@ | ||
import Dropdown from '../../lsg/patterns/dropdown'; | ||
import DropdownItem, { | ||
DropdownItemLinkAttribute, | ||
DropdownItemLinkAttributeItem | ||
} from '../../lsg/patterns/dropdown-item'; | ||
import { IconName } from '../../lsg/patterns/icons'; | ||
import * as MobX from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import { PageRef } from '../../store/project/page_ref'; | ||
import { Project } from '../../store/project'; | ||
import * as React from 'react'; | ||
import { Store } from '../../store'; | ||
|
||
export interface PageListProps { | ||
store: Store; | ||
} | ||
|
||
@observer | ||
export class PageList extends React.Component<PageListProps> { | ||
@MobX.observable protected pageListVisible: boolean = false; | ||
public constructor(props: PageListProps) { | ||
super(props); | ||
|
||
this.handleDropdownToggle = this.handleDropdownToggle.bind(this); | ||
this.handlePageClick = this.handlePageClick.bind(this); | ||
} | ||
|
||
public render(): JSX.Element { | ||
const currentPage = this.props.store.getCurrentPage(); | ||
let currentPageName = ''; | ||
if (currentPage) { | ||
currentPageName = currentPage.getName(); | ||
} | ||
return ( | ||
<Dropdown | ||
label={currentPageName} | ||
handleClick={this.handleDropdownToggle} | ||
open={this.pageListVisible} | ||
> | ||
{this.getProjectPages().map((page: PageRef, index) => ( | ||
<DropdownItem | ||
name={page.getName()} | ||
key={index} | ||
handleClick={(e: React.MouseEvent<HTMLElement>) => { | ||
e.preventDefault(); | ||
this.handlePageClick(page.getId()); | ||
}} | ||
> | ||
<DropdownItemLinkAttribute> | ||
<DropdownItemLinkAttributeItem>Edit</DropdownItemLinkAttributeItem> | ||
<DropdownItemLinkAttributeItem>Delete</DropdownItemLinkAttributeItem> | ||
</DropdownItemLinkAttribute> | ||
</DropdownItem> | ||
))} | ||
<DropdownItem name="New page" icon={IconName.Robo} /> | ||
</Dropdown> | ||
); | ||
} | ||
|
||
public getProjectPages(): PageRef[] { | ||
const project: Project | undefined = this.props.store.getCurrentProject(); | ||
let projectPages: PageRef[] = []; | ||
if (project) { | ||
projectPages = project.getPages(); | ||
} | ||
return projectPages; | ||
} | ||
|
||
@MobX.action | ||
protected handleDropdownToggle(): void { | ||
this.pageListVisible = !this.pageListVisible; | ||
} | ||
|
||
protected handlePageClick(id: string): void { | ||
this.props.store.openPage(id); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,42 +1,91 @@ | ||
import { 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 DropdownProps { | ||
chrome?: boolean; | ||
visible?: boolean; | ||
} | ||
label?: string; | ||
open?: boolean; | ||
|
||
handleClick?: React.MouseEventHandler<HTMLElement>; | ||
} | ||
export interface StyledChromeDropdownProps { | ||
open?: boolean; | ||
} | ||
export interface StyledDropdownProps { | ||
visible?: boolean; | ||
open?: boolean; | ||
} | ||
|
||
export interface StyledLabelProps { | ||
open?: boolean; | ||
handleClick?: React.MouseEventHandler<HTMLElement>; | ||
} | ||
|
||
export interface StyledIconProps { | ||
open?: boolean; | ||
} | ||
|
||
export interface StyledFlyoutProps { | ||
open?: 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 StyledLabel = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: ${getSpace(SpaceSize.S)}px; | ||
cursor: pointer; | ||
`; | ||
|
||
const StyledIcon = styled(Icon)` | ||
margin-left: ${getSpace(SpaceSize.XS)}px; | ||
fill: ${colors.grey36.toString()}; | ||
transition: transform 0.2s; | ||
${(props: StyledIconProps) => (props.open ? 'transform: rotate(90deg)' : '')}; | ||
`; | ||
|
||
const StyledFlyout = styled.div` | ||
${(props: StyledFlyoutProps) => (props.open ? 'display: block' : 'display: none')}; | ||
padding: 0 ${getSpace(SpaceSize.S)}px ${getSpace(SpaceSize.L)}px; | ||
`; | ||
|
||
const StyledChromeDropdown = styled(StyledDropdown)` | ||
${(props: StyledChromeDropdownProps) => (props.open ? 'display: block' : 'display: none')}; | ||
position: absolute; | ||
top: 45px; | ||
left: 50%; | ||
min-width: 200px; | ||
padding: ${getSpace(SpaceSize.S)}px ${getSpace(SpaceSize.S)}px ${getSpace(SpaceSize.L)}px; | ||
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}> | ||
<StyledChromeDropdown open={this.props.open}> | ||
{this.props.children} | ||
</StyledChromeDropdown> | ||
); | ||
} | ||
return <StyledDropdown visible={this.props.visible}>{this.props.children}</StyledDropdown>; | ||
return ( | ||
<StyledDropdown> | ||
<StyledLabel onClick={this.props.handleClick}> | ||
{this.props.label} | ||
<StyledIcon name={IconName.Arrow} size={IconSize.XXS} open={this.props.open} /> | ||
</StyledLabel> | ||
<StyledFlyout open={this.props.open}>{this.props.children}</StyledFlyout> | ||
</StyledDropdown> | ||
); | ||
} | ||
} |