import * as _ from "lodash"; import classnames from "classnames"; import MorePropTypes from "../utils/MorePropTypes"; import * as Overlay from "react-bootstrap/lib/Overlay"; import * as React from "react"; import * as PropTypes from "prop-types"; import * as FontAwesome from "react-fontawesome"; import FlexBox from "../flex/FlexBox"; import FlexItem from "../flex/FlexItem"; import Menu from "./Menu"; import Option from "./Option"; import { Type, ArrowType } from "./Type"; import { Button, Props as ButtonProps } from "../Button/Button"; import { ChildrenOf, Values } from "../utils/types"; import "./Caret.less"; import "./DropdownButton.less"; export interface Props { ariaLabelSecondaryButton?: string; children?: ChildrenOf; className?: string; disabled?: boolean; href?: string; label: React.ReactNode; onClick?: Function; size?: ButtonProps["size"]; target?: "_self" | "_blank"; type?: Values; arrowType?: Values; } interface State { expanded: boolean; } const propTypes = { ariaLabelSecondaryButton: PropTypes.string, children: MorePropTypes.oneOrManyOf(MorePropTypes.instanceOfComponent(Option)), className: PropTypes.string, disabled: PropTypes.bool, href: PropTypes.string, label: PropTypes.node.isRequired, onClick: PropTypes.func, size: PropTypes.oneOf(_.values(Button.Size)), target: PropTypes.oneOf(["_self", "_blank"]), type: PropTypes.oneOf(_.values(Type)), arrowType: PropTypes.oneOf(_.values(ArrowType)), }; const defaultProps = { size: Button.Size.M, type: Type.SECONDARY, arrowType: ArrowType.CARET, }; export const cssClass = { BUTTONS: "DropdownButton--buttons", CARET_CONTAINER: "DropdownButton--Caret--container", CARET: "DropdownButton--Caret", CONTAINER: "DropdownButton", MAIN: "DropdownButton--main", POPUP: "DropdownButton--popup", SECTION: "DropdownButton--section", TOGGLE: "DropdownButton--toggle", }; export default class DropdownButton extends React.PureComponent { static propTypes = propTypes; static defaultProps = defaultProps; static Option = Option; static Size = Button.Size; static Type = Type; static ArrowType = ArrowType; constructor(props: Props) { super(props); this.state = { expanded: false, }; } _renderMainButton() { const { disabled, href, label, onClick, size, target, type } = this.props; return ( ); } render() { const { ariaLabelSecondaryButton, children, className, disabled, size, type, arrowType, } = this.props; const passthroughProps = _.omit( this.props, Object.keys(propTypes) as (keyof typeof propTypes)[], ); const { expanded } = this.state; if (React.Children.count(children) === 0) { return (
{this._renderMainButton()}
); } let arrowTypeRender; if (arrowType === ArrowType.CARET) { arrowTypeRender = ( ); } else { arrowTypeRender = ( ); } return (
{this._renderMainButton()}
); } }