-
Notifications
You must be signed in to change notification settings - Fork 4
/
WithRemoveButton.tsx
42 lines (39 loc) · 1 KB
/
WithRemoveButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as React from "react";
import { Button } from "library-simplified-reusable-components";
import TrashIcon from "./icons/TrashIcon";
export interface WithRemoveButtonProps {
disabled: boolean;
onRemove: () => void;
}
/** When wrapped around an element, renders a remove button next to the element. */
export default class WithRemoveButton extends React.Component<
WithRemoveButtonProps,
{}
> {
static defaultProps = {
disabled: false,
};
render(): JSX.Element {
const removeContent = (
<span>
Delete <TrashIcon />
</span>
);
return (
<div className="with-remove-button">
<span>{this.props.children}</span>
<Button
className="remove-btn danger small"
callback={this.onClick.bind(this)}
content={removeContent}
type="button"
disabled={this.props.disabled}
/>
</div>
);
}
onClick(e: Event) {
e.preventDefault();
!this.props.disabled && this.props.onRemove();
}
}