From f14e12f78561fcffa43b87cd6f8405118fb2c1a3 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 21 Feb 2019 15:11:13 +0100 Subject: [PATCH] [ExpansionPanel] Add context --- .../ExpansionPanel/ExpansionPanelContext.js | 18 ++++++++++++++++++ .../material-ui/src/ExpansionPanel/index.js | 1 + .../src/ExpansionPanel/useExpansionPanel.d.ts | 11 +++++++++++ .../src/ExpansionPanel/useExpansionPanel.js | 6 ++++++ 4 files changed, 36 insertions(+) create mode 100644 packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js create mode 100644 packages/material-ui/src/ExpansionPanel/useExpansionPanel.d.ts create mode 100644 packages/material-ui/src/ExpansionPanel/useExpansionPanel.js diff --git a/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js b/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js new file mode 100644 index 00000000000000..b02367c1d9d484 --- /dev/null +++ b/packages/material-ui/src/ExpansionPanel/ExpansionPanelContext.js @@ -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; diff --git a/packages/material-ui/src/ExpansionPanel/index.js b/packages/material-ui/src/ExpansionPanel/index.js index 323f2104b6c6f7..5d7e7b6af11d2f 100644 --- a/packages/material-ui/src/ExpansionPanel/index.js +++ b/packages/material-ui/src/ExpansionPanel/index.js @@ -1 +1,2 @@ export { default } from './ExpansionPanel'; +export { default as useExpansionPanel } from './useExpansionPanel'; diff --git a/packages/material-ui/src/ExpansionPanel/useExpansionPanel.d.ts b/packages/material-ui/src/ExpansionPanel/useExpansionPanel.d.ts new file mode 100644 index 00000000000000..7ef1363e6e99e3 --- /dev/null +++ b/packages/material-ui/src/ExpansionPanel/useExpansionPanel.d.ts @@ -0,0 +1,11 @@ +import * as React from 'react'; + +interface ExpansionPanelContext { + disabled: boolean; + expanded: boolean; + onChange: (event: Event, expanded: boolean) => void; +} + +export default function useExpansionPanel< + ChangeEvent = React.SyntheticEvent +>(): ExpansionPanelContext; diff --git a/packages/material-ui/src/ExpansionPanel/useExpansionPanel.js b/packages/material-ui/src/ExpansionPanel/useExpansionPanel.js new file mode 100644 index 00000000000000..d2b2fcdae4d4fc --- /dev/null +++ b/packages/material-ui/src/ExpansionPanel/useExpansionPanel.js @@ -0,0 +1,6 @@ +import React from 'react'; +import ExpansionPanelContext from './ExpansionPanelContext'; + +export default function useExpansionPanel() { + return React.useContext(ExpansionPanelContext); +}