Skip to content

Commit 5411620

Browse files
committed
fix: make properties in theme prop optional
this doesn't work right now, but should work from flow 0.57 onwards
1 parent 8542439 commit 5411620

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

docs/pages/2.theming.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function Main() {
4848

4949
You can change the theme prop dynamically and all the components will automatically update to reflect the new theme.
5050

51-
A theme contains the following properties:
51+
A theme usually contains the following properties:
5252

5353
- `dark` (`boolean`): whether this is a dark theme or light theme.
5454
- `roundness` (`number`): roundness of common elements, such as buttons.
@@ -60,7 +60,7 @@ A theme contains the following properties:
6060
- `text` - text color for content.
6161
- `disabled` - color for disabled elements.
6262
- `placeholder` - color for placeholder text, such as input placeholder.
63-
- `fonts` (`object`): various fonts used throught different elements
63+
- `fonts` (`object`): various fonts used throught different elements.
6464
- `regular`
6565
- `medium`
6666
- `light`

src/core/withTheme.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ const isClassComponent = (Component: Function) => !!Component.prototype.render;
1010

1111
export default function withTheme<Props: {}>(
1212
Comp: React.ComponentType<Props>
13-
): React.ComponentType<$Diff<Props, { theme: Theme }>> {
13+
): React.ComponentType<
14+
$Diff<Props, { theme: Theme }> & { theme?: $Shape<Theme> }
15+
> {
1416
class ThemedComponent extends React.Component<*> {
1517
/* $FlowFixMe */
1618
static displayName = `withTheme(${Comp.displayName || Comp.name})`;
1719

18-
_previous: ?{ a: Theme, b: ?Theme, result: Theme };
19-
_merge = (a: Theme, b: ?Theme) => {
20+
_previous: ?{ a: Theme, b: ?$Shape<Theme>, result: Theme };
21+
_merge = (a: Theme, b: ?$Shape<Theme>) => {
2022
const previous = this._previous;
2123

2224
if (previous && previous.a === a && previous.b === b) {

0 commit comments

Comments
 (0)