Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the way dropdowns look in Chrome
- Loading branch information
1 parent
e04b0ba
commit 27596a4
Showing
14 changed files
with
304 additions
and
266 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
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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
import React from "react"; | ||
import { Button } from "../Buttons"; | ||
|
||
export interface BasicToolbarItemData { | ||
icon?: string; | ||
items?: BasicToolbarItemData[]; | ||
text?: string; | ||
} | ||
|
||
export interface ToolbarItemData extends BasicToolbarItemData { | ||
action?: (() => void) | ((event: React.MouseEvent) => void); | ||
|
||
/** Whether or not text should be hidden when displayed on toolbar */ | ||
condensedButton?: boolean; | ||
|
||
content?: React.ReactElement; | ||
items?: ToolbarItemData[]; | ||
shortcut?: string; | ||
}; | ||
|
||
export interface ToolbarButtonProps { | ||
action?: (() => void) | ((event: React.MouseEvent) => void); | ||
condensedButton?: boolean; | ||
disabled?: boolean; | ||
icon?: string; | ||
dropdownChild ?: boolean; | ||
text?: string; | ||
shortcut ?: string; | ||
} | ||
|
||
/** | ||
* A basic toolbar button | ||
* @param props | ||
*/ | ||
export default function ToolbarButton(props: ToolbarButtonProps) { | ||
const text = props.condensedButton && !props.dropdownChild ? | ||
<></> : <span className="button-text">{props.text}</span> | ||
const icon = props.icon ? <i className={`icofont-${props.icon}`} /> : <></> | ||
const shortcut = props.shortcut ? <span className="button-shortcut">{props.shortcut}</span> : <></> | ||
|
||
let Container = Button; | ||
if (props.dropdownChild) { | ||
/** Thank you Google Chrome for allowing me to | ||
* craft this beautiful hack because you won't allow | ||
* buttons to be grid containers | ||
*/ | ||
Container = (props) => { | ||
return ( | ||
<Button {...props}> | ||
<div> | ||
{props.children} | ||
</div> | ||
</Button> | ||
); | ||
}; | ||
} | ||
|
||
return ( | ||
<Container disabled={props.disabled} onClick={props.action}> | ||
{icon} {text} {shortcut} | ||
</Container> | ||
); | ||
} |
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,43 @@ | ||
import React from "react"; | ||
|
||
import ToolbarButton, { ToolbarItemData } from "./ToolbarButton"; | ||
import { PureDropdown, PureMenuItem } from "../menus/PureMenu"; | ||
|
||
export interface ToolbarItemProps extends ToolbarItemData { | ||
dropdownChild?: boolean; | ||
} | ||
|
||
/** | ||
* Factory function for rendering toolbar items | ||
* @param props | ||
*/ | ||
export default function ToolbarItemFactory(props: ToolbarItemProps) { | ||
if (props.content) { | ||
return <PureMenuItem>{props.content}</PureMenuItem> | ||
} | ||
|
||
if (!props.icon && !props.text) { | ||
return <></> | ||
} | ||
|
||
/** Group of buttons */ | ||
if (props.items) { | ||
return ( | ||
<PureDropdown | ||
trigger={<ToolbarButton icon={props.icon} text={props.text} />}> | ||
{props.items.map((value, index) => | ||
<ToolbarItemFactory key={index} dropdownChild={true} {...value} /> | ||
)} | ||
</PureDropdown> | ||
); | ||
} | ||
|
||
return ( | ||
<PureMenuItem> | ||
<ToolbarButton | ||
{...props} | ||
disabled={!props.action && !props.items} | ||
/> | ||
</PureMenuItem> | ||
); | ||
} |
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
Oops, something went wrong.