Skip to content

Commit

Permalink
[ExpansionPanel] Add context
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 21, 2019
1 parent dd68463 commit f14e12f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import warning from 'warning';

const ExpansionPanelContext = React.createContext({
disabled: false,
expanded: false,
onChange: () => {
warning(
false,
[
'Material-UI: You called onChange from a component that is not a child of a ',
'ExpansionPanel component.',
].join(''),
);
},
});

export default ExpansionPanelContext;
1 change: 1 addition & 0 deletions packages/material-ui/src/ExpansionPanel/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './ExpansionPanel';
export { default as useExpansionPanel } from './useExpansionPanel';
11 changes: 11 additions & 0 deletions packages/material-ui/src/ExpansionPanel/useExpansionPanel.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';

interface ExpansionPanelContext<ChangeEvent> {
disabled: boolean;
expanded: boolean;
onChange: (event: Event, expanded: boolean) => void;
}

export default function useExpansionPanel<
ChangeEvent = React.SyntheticEvent
>(): ExpansionPanelContext<ChangeEvent>;
6 changes: 6 additions & 0 deletions packages/material-ui/src/ExpansionPanel/useExpansionPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import ExpansionPanelContext from './ExpansionPanelContext';

export default function useExpansionPanel() {
return React.useContext(ExpansionPanelContext);
}

0 comments on commit f14e12f

Please sign in to comment.