Repository navigation
Expand file tree
/
Copy pathTooltip.js
More file actions
70 lines (57 loc) · 1.75 KB
/
Copy pathTooltip.js
File metadata and controls
70 lines (57 loc) · 1.75 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// @flow
import React, { Component } from 'react';
import type { ComponentType, Element } from 'react';
// internal components
import { withTheme } from './HOC/withTheme';
// internal utility functions
import { composeTheme, addThemeId, didThemePropsChange } from '../utils/themes';
// import constants
import { IDENTIFIERS } from '../themes/API';
type Props = {
className: string,
context: {
theme: Object,
ROOT_THEME_API: Object
},
isAligningRight: boolean,
isBounded: boolean,
isOpeningUpward: boolean,
isTransparent: boolean,
skin: ComponentType<any>,
theme: Object, // will take precedence over theme in context if passed
themeOverrides: Object, // custom css/scss from user that adheres to component's theme API
themeId: string,
tip: string | Element<any>
};
type State = {
composedTheme: Object
};
class TooltipBase extends Component<Props, State> {
static defaultProps = {
isOpeningUpward: true,
isTransparent: true,
theme: null,
themeId: IDENTIFIERS.TOOLTIP,
themeOverrides: {}
};
constructor(props: Props) {
super(props);
const { context, themeId, theme, themeOverrides } = props;
this.state = {
composedTheme: composeTheme(
addThemeId(theme || context.theme, themeId),
addThemeId(themeOverrides, themeId),
context.ROOT_THEME_API
)
};
}
componentWillReceiveProps(nextProps: Props) {
didThemePropsChange(this.props, nextProps, this.setState.bind(this));
}
render() {
// destructuring props ensures only the "...rest" get passed down
const { skin: TooltipSkin, theme, themeOverrides, context, ...rest } = this.props;
return <TooltipSkin theme={this.state.composedTheme} {...rest} />;
}
}
export const Tooltip = withTheme(TooltipBase);