1 | import * as React from 'react';
|
2 | import * as PropTypes from 'prop-types';
|
3 | import { InlineFlexProps as ReakitInlineFlexProps } from 'reakit/ts';
|
4 |
|
5 | import _get from 'lodash/get';
|
6 |
|
7 | import _Badge from './styled';
|
8 |
|
9 | export type LocalBadgeProps = {
|
10 | children?: React.ReactNode;
|
11 | isAbsolute?: boolean;
|
12 | palette?: string;
|
13 | };
|
14 | export type BadgeProps = ReakitInlineFlexProps & LocalBadgeProps;
|
15 |
|
16 | export const badgePropTypes = {
|
17 | children: PropTypes.node,
|
18 | isAbsolute: PropTypes.bool,
|
19 | palette: PropTypes.string
|
20 | };
|
21 |
|
22 | export const badgeDefaultProps = {
|
23 | children: undefined,
|
24 | isAbsolute: false,
|
25 | palette: 'text'
|
26 | };
|
27 |
|
28 | export class Badge extends React.Component<LocalBadgeProps> {
|
29 | static propTypes = badgePropTypes;
|
30 | static defaultProps = badgeDefaultProps;
|
31 |
|
32 | badge = React.createRef();
|
33 |
|
34 | state = {
|
35 | parentElement: undefined
|
36 | };
|
37 |
|
38 | componentDidMount = () => {
|
39 | const parentElement = _get(this.badge, 'current.parentElement');
|
40 | parentElement.setAttribute('style', 'position:relative;');
|
41 | this.setState({ parentElement });
|
42 | };
|
43 |
|
44 | render = () => {
|
45 | const { children, ...props } = this.props;
|
46 | return (
|
47 | <_Badge elementRef={this.badge} {...props}>
|
48 | {children}
|
49 | </_Badge>
|
50 | );
|
51 | };
|
52 | }
|
53 |
|
54 |
|
55 | const C: React.FunctionComponent<BadgeProps> = Badge;
|
56 | export default C;
|