forked from input-output-hk/react-polymorph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
75 lines (62 loc) · 1.73 KB
/
Button.js
File metadata and controls
75 lines (62 loc) · 1.73 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
71
72
73
74
75
// @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
},
disabled: boolean,
label: string | Element<any>,
loading: boolean,
onClick: Function,
skin: ComponentType<any>,
theme: Object, // will take precedence over theme in context if passed
themeId: string,
themeOverrides: Object // custom css/scss from user that adheres to component's theme API
};
type State = {
composedTheme: Object
};
class ButtonBase extends Component<Props, State> {
static defaultProps = {
disabled: false,
loading: false,
theme: null,
themeId: IDENTIFIERS.BUTTON,
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: ButtonSkin,
theme,
themeOverrides,
context,
...rest
} = this.props;
return <ButtonSkin theme={this.state.composedTheme} {...rest} />;
}
}
export const Button = withTheme(ButtonBase);