Add title option to Button and remove IconButton

This commit is contained in:
Florian Scholdei
2019-11-12 17:30:37 +01:00
parent 6d2bdb6f29
commit 9132167a6c
5 changed files with 16 additions and 80 deletions

View File

@@ -282,26 +282,6 @@ exports[`Storyshots Buttons|EditButton Default 1`] = `
</div>
`;
exports[`Storyshots Buttons|IconButton Default 1`] = `
<div
className="sc-htoDjs bIDNS"
>
<button
className="button is-default"
onClick={[Function]}
type="button"
>
<span
className="icon is-medium"
>
<i
className="fas fa-icons has-text-inherit"
/>
</span>
</button>
</div>
`;
exports[`Storyshots Buttons|SubmitButton Default 1`] = `
<div
className="sc-htoDjs bIDNS"

View File

@@ -18,6 +18,7 @@ export type ButtonProps = {
type Props = ButtonProps &
RouteComponentProps & {
title?: string;
type?: "button" | "submit" | "reset";
color?: string;
};
@@ -38,7 +39,19 @@ class Button extends React.Component<Props> {
};
render() {
const { label, loading, disabled, type, color, className, icon, fullWidth, reducedMobile, children } = this.props;
const {
label,
title,
loading,
disabled,
type,
color,
className,
icon,
fullWidth,
reducedMobile,
children
} = this.props;
const loadingClass = loading ? "is-loading" : "";
const fullWidthClass = fullWidth ? "is-fullwidth" : "";
const reducedMobileClass = reducedMobile ? "is-reduced-mobile" : "";
@@ -46,6 +59,7 @@ class Button extends React.Component<Props> {
return (
<button
type={type}
title={title}
disabled={disabled}
onClick={this.onClick}
className={classNames("button", "is-" + color, loadingClass, fullWidthClass, reducedMobileClass, className)}
@@ -63,6 +77,7 @@ class Button extends React.Component<Props> {
return (
<button
type={type}
title={title}
disabled={disabled}
onClick={this.onClick}
className={classNames("button", "is-" + color, loadingClass, fullWidthClass, className)}

View File

@@ -1,56 +0,0 @@
import React, { MouseEvent } from "react";
import { withRouter, RouteComponentProps } from "react-router-dom";
import classNames from "classnames";
import Icon from "../Icon";
export type ButtonProps = {
icon: string;
title?: string;
loading?: boolean;
disabled?: boolean;
action?: (event: MouseEvent) => void;
link?: string;
className?: string;
};
type Props = ButtonProps &
RouteComponentProps & {
type?: "button" | "submit" | "reset";
color?: string;
};
class IconButton extends React.Component<Props> {
static defaultProps: Partial<Props> = {
type: "button",
color: "default"
};
onClick = (event: React.MouseEvent) => {
const { action, link, history } = this.props;
if (action) {
action(event);
} else if (link) {
history.push(link);
}
};
render() {
const { icon, title, loading, disabled, type, color, className } = this.props;
const loadingClass = loading ? "is-loading" : "";
return (
<button
className={classNames("button", "is-" + color, loadingClass, className)}
title={title}
type={type}
disabled={disabled}
onClick={this.onClick}
>
<span className="icon is-medium">
<Icon name={icon} color="inherit" />
</span>
</button>
);
}
}
export default withRouter(IconButton);

View File

@@ -3,7 +3,6 @@ import Button from "./Button";
import { storiesOf } from "@storybook/react";
import styled from "styled-components";
import { MemoryRouter } from "react-router-dom";
import IconButton from "./IconButton";
import AddButton from "./AddButton";
import CreateButton from "./CreateButton";
import DeleteButton from "./DeleteButton";
@@ -49,7 +48,6 @@ const buttonStory = (name: string, storyFn: () => ReactElement) => {
.addDecorator(SpacingDecorator)
.add("Default", storyFn);
};
buttonStory("IconButton", () => <IconButton icon="icons" />);
buttonStory("AddButton", () => <AddButton>Add</AddButton>);
buttonStory("CreateButton", () => <CreateButton>Create</CreateButton>);
buttonStory("DeleteButton", () => <DeleteButton>Delete</DeleteButton>);

View File

@@ -2,7 +2,6 @@
export { default as AddButton } from "./AddButton";
export { default as Button } from "./Button";
export { default as IconButton } from "./IconButton";
export { default as CreateButton } from "./CreateButton";
export { default as DeleteButton } from "./DeleteButton";
export { default as EditButton } from "./EditButton";