glass-app-manager
Version:
Informatica's Glass Framework CLI for bootstrapping
56 lines (44 loc) • 1.57 kB
JavaScript
//@flow
import * as React from "react";
export type Props = {
/**
* Additional class selectors to pass to the button component.
*/
className?: string,
/**
* Content to pass to the button as a string or an array of elements.
*/
children: React.ChildrenArray<string | React.Element<any>>,
/**
* Provide a custom renderer for the `Button` component by providing
* the element to represent the button as (e.g. `a`)
*/
component?: React.ElementType,
/**
* Applies disabled styles and props (depending on component type)
*/
disabled?: boolean,
};
const BaseButton = React.forwardRef(
({ className = "", children, component = "button", disabled = false, ...rest }: Props, ref) => {
return React.createElement(
component,
{
ref,
className,
tabIndex: "0",
// Add the `aria-disabled` prop in case the component is changed to one that doesn't
// natively support the "disabled" prop
...(disabled ? { "aria-disabled": true } : {}),
// Add some button-specific properties if a button, otherwise
// set the button role
...(component === "button" ? { type: "button" } : { role: "button" }),
disabled,
...rest,
},
children
);
}
);
BaseButton.displayName = "BaseButton";
export default BaseButton;