Skip to content

Commit 7fea5fc

Browse files
committed
fix: export theme context
1 parent a0eae87 commit 7fea5fc

7 files changed

Lines changed: 141 additions & 131 deletions

File tree

src/components/Badge/Badge.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ menu: Components
55

66
import { Playground, PropsTable } from 'docz';
77
import Badge from './Badge';
8-
import { ThemeConsumer } from '../../theme';
8+
import { ThemeContext } from '../../theme';
99
import { Box } from '../Layout';
1010

1111
## Usage
@@ -15,7 +15,7 @@ import { Box } from '../Layout';
1515
### Default
1616

1717
<Playground>
18-
<ThemeConsumer>
18+
<ThemeContext.Consumer>
1919
{theme => (
2020
<Box>
2121
{Object.keys(theme.fills.solid).map(color => (
@@ -28,13 +28,13 @@ import { Box } from '../Layout';
2828
))}
2929
</Box>
3030
)}
31-
</ThemeConsumer>
31+
</ThemeContext.Consumer>
3232
</Playground>
3333

3434
### Pills
3535

3636
<Playground>
37-
<ThemeConsumer>
37+
<ThemeContext.Consumer>
3838
{theme => (
3939
<Box>
4040
{Object.keys(theme.fills.solid).map(color => (
@@ -49,7 +49,7 @@ import { Box } from '../Layout';
4949
))}
5050
</Box>
5151
)}
52-
</ThemeConsumer>
52+
</ThemeContext.Consumer>
5353
</Playground>
5454

5555
## Props

src/components/Modal/ModalBase.web.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class ModalBase extends React.PureComponent<ModalBaseProps> {
9090
}
9191
};
9292

93-
public render() {
93+
public render(): React.ReactPortal | null {
9494
const { transparent, visible, isBackgroundScrollable = false } = this.props;
9595

9696
if (!visible || !this.el) return null;

src/components/SelectList/SelectList.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@ const SelectListBase = (props: SelectListProps): any => {
3333
}
3434
};
3535

36-
return React.Children.map(children, (child, index) => {
37-
if (!React.isValidElement(child)) {
38-
return child;
36+
return React.Children.map(children, (selectListItem, index) => {
37+
if (!React.isValidElement(selectListItem)) {
38+
return selectListItem;
3939
}
4040

41-
// @ts-ignore
42-
const selectListItem = child as React.ReactElement<SelectListItemBaseProps>;
43-
4441
const isSelected =
4542
isMulti && Array.isArray(selectedValue)
4643
? selectedValue.some(selVal => selVal === selectListItem.props.value)

src/components/Typography/List.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ export interface ListProps {
1515
export const List = (props: ListProps) => {
1616
const { listType, children, icon, size = 'medium' } = props;
1717

18-
const finalChildren = React.Children.map(children, (child, index) => {
19-
if (!React.isValidElement(child)) {
20-
return child;
18+
const finalChildren = React.Children.map(children, (listItem, index) => {
19+
if (!React.isValidElement(listItem)) {
20+
return listItem;
2121
}
2222

23-
// @ts-ignore
24-
const listItem = child as React.ReactElement<ListItemProps>;
25-
2623
return React.cloneElement(listItem, {
2724
// Prefer more granularly defined icon if present
2825
icon: listItem.props.icon || icon,

src/theme/ThemeContext.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ import * as React from 'react';
22

33
import { defaultTheme } from './default-theme';
44

5-
const {
6-
Provider: ThemeProvider,
7-
Consumer: ThemeConsumer,
8-
} = React.createContext(defaultTheme);
9-
10-
export { ThemeProvider, ThemeConsumer };
5+
export const ThemeContext = React.createContext(defaultTheme);

src/theme/withTheme.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import { ThemeConsumer } from './ThemeContext';
3+
import { ThemeContext } from './ThemeContext';
44
import { Theme } from './ThemeInterface';
55

66
export interface ThemeProps {
@@ -27,12 +27,12 @@ const withTheme = <TWrappedComponentProps extends any>(
2727

2828
public render() {
2929
return (
30-
<ThemeConsumer>
30+
<ThemeContext.Consumer>
3131
{theme => {
3232
// @ts-ignore TODO: https://github.com/Microsoft/TypeScript/issues/28748
3333
return <WrappedComponent theme={theme} {...this.props} />;
3434
}}
35-
</ThemeConsumer>
35+
</ThemeContext.Consumer>
3636
);
3737
}
3838
};

0 commit comments

Comments
 (0)