forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lab] Add new experimental Tabs API (mui#20806)
- Loading branch information
Showing
28 changed files
with
775 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown'; | ||
|
||
const pageFilename = 'api/tab-context'; | ||
const requireRaw = require.context('!raw-loader!./', false, /\/tab-context\.md$/); | ||
|
||
export default function Page({ docs }) { | ||
return <MarkdownDocs docs={docs} />; | ||
} | ||
|
||
Page.getInitialProps = () => { | ||
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw }); | ||
return { demos, docs }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
filename: /packages/material-ui-lab/src/TabContext/TabContext.js | ||
--- | ||
|
||
<!--- This documentation is automatically generated, do not try to edit it. --> | ||
|
||
# TabContext API | ||
|
||
<p class="description">The API documentation of the TabContext React component. Learn more about the props and the CSS customization points.</p> | ||
|
||
## Import | ||
|
||
```js | ||
import TabContext from '@material-ui/lab/TabContext'; | ||
// or | ||
import { TabContext } from '@material-ui/lab'; | ||
``` | ||
|
||
You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/). | ||
|
||
|
||
|
||
|
||
|
||
## Props | ||
|
||
| Name | Type | Default | Description | | ||
|:-----|:-----|:--------|:------------| | ||
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the component. | | ||
| <span class="prop-name required">value *</span> | <span class="prop-type">string</span> | | The value of the currently selected `Tab`. | | ||
|
||
The component cannot hold a ref. | ||
|
||
Any other props supplied will be provided to the root element (native element). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown'; | ||
|
||
const pageFilename = 'api/tab-list'; | ||
const requireRaw = require.context('!raw-loader!./', false, /\/tab-list\.md$/); | ||
|
||
export default function Page({ docs }) { | ||
return <MarkdownDocs docs={docs} />; | ||
} | ||
|
||
Page.getInitialProps = () => { | ||
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw }); | ||
return { demos, docs }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
filename: /packages/material-ui-lab/src/TabList/TabList.js | ||
--- | ||
|
||
<!--- This documentation is automatically generated, do not try to edit it. --> | ||
|
||
# TabList API | ||
|
||
<p class="description">The API documentation of the TabList React component. Learn more about the props and the CSS customization points.</p> | ||
|
||
## Import | ||
|
||
```js | ||
import TabList from '@material-ui/lab/TabList'; | ||
// or | ||
import { TabList } from '@material-ui/lab'; | ||
``` | ||
|
||
You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/). | ||
|
||
|
||
|
||
|
||
|
||
## Props | ||
|
||
| Name | Type | Default | Description | | ||
|:-----|:-----|:--------|:------------| | ||
| <span class="prop-name">children</span> | <span class="prop-type">Array<element></span> | | | | ||
|
||
The `ref` is forwarded to the root element. | ||
|
||
Any other props supplied will be provided to the root element ([Tabs](/api/tabs/)). | ||
|
||
## Inheritance | ||
|
||
The props of the [Tabs](/api/tabs/) component are also available. | ||
You can take advantage of this behavior to [target nested components](/guides/api/#spread). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown'; | ||
|
||
const pageFilename = 'api/tab-panel'; | ||
const requireRaw = require.context('!raw-loader!./', false, /\/tab-panel\.md$/); | ||
|
||
export default function Page({ docs }) { | ||
return <MarkdownDocs docs={docs} />; | ||
} | ||
|
||
Page.getInitialProps = () => { | ||
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw }); | ||
return { demos, docs }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
filename: /packages/material-ui-lab/src/TabPanel/TabPanel.js | ||
--- | ||
|
||
<!--- This documentation is automatically generated, do not try to edit it. --> | ||
|
||
# TabPanel API | ||
|
||
<p class="description">The API documentation of the TabPanel React component. Learn more about the props and the CSS customization points.</p> | ||
|
||
## Import | ||
|
||
```js | ||
import TabPanel from '@material-ui/lab/TabPanel'; | ||
// or | ||
import { TabPanel } from '@material-ui/lab'; | ||
``` | ||
|
||
You can learn more about the difference by [reading this guide](/guides/minimizing-bundle-size/). | ||
|
||
|
||
|
||
## Component name | ||
|
||
The `MuiTabPanel` name can be used for providing [default props](/customization/globals/#default-props) or [style overrides](/customization/globals/#css) at the theme level. | ||
|
||
## Props | ||
|
||
| Name | Type | Default | Description | | ||
|:-----|:-----|:--------|:------------| | ||
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the component. | | ||
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. | | ||
| <span class="prop-name required">value *</span> | <span class="prop-type">string</span> | | The `value` of the corresponding `Tab`. Must use the index of the `Tab` when no `value` was passed to `Tab`. | | ||
|
||
The `ref` is forwarded to the root element. | ||
|
||
Any other props supplied will be provided to the root element (native element). | ||
|
||
## CSS | ||
|
||
| Rule name | Global class | Description | | ||
|:-----|:-------------|:------------| | ||
| <span class="prop-name">root</span> | <span class="prop-name">.MuiTabPanel-root</span> | Styles applied to the root element. | ||
|
||
You can override the style of the component thanks to one of these customization points: | ||
|
||
- With a rule name of the [`classes` object prop](/customization/components/#overriding-styles-with-classes). | ||
- With a [global class name](/customization/components/#overriding-styles-with-global-class-names). | ||
- With a theme and an [`overrides` property](/customization/globals/#css). | ||
|
||
If that's not sufficient, you can check the [implementation of the component](https://github.com/mui-org/material-ui/blob/master/packages/material-ui-lab/src/TabPanel/TabPanel.js) for more detail. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Tab from '@material-ui/core/Tab'; | ||
import TabContext from '@material-ui/lab/TabContext'; | ||
import TabList from '@material-ui/lab/TabList'; | ||
import TabPanel from '@material-ui/lab/TabPanel'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
flexGrow: 1, | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
export default function LabTabs() { | ||
const classes = useStyles(); | ||
const [value, setValue] = React.useState('1'); | ||
|
||
const handleChange = (event, newValue) => { | ||
setValue(newValue); | ||
}; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<TabContext value={value}> | ||
<AppBar position="static"> | ||
<TabList onChange={handleChange} aria-label="simple tabs example"> | ||
<Tab label="Item One" value="1" /> | ||
<Tab label="Item Two" value="2" /> | ||
<Tab label="Item Three" value="3" /> | ||
</TabList> | ||
</AppBar> | ||
<TabPanel value="1">Item One</TabPanel> | ||
<TabPanel value="2">Item Two</TabPanel> | ||
<TabPanel value="3">Item Three</TabPanel> | ||
</TabContext> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { makeStyles, Theme } from '@material-ui/core/styles'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Tab from '@material-ui/core/Tab'; | ||
import TabContext from '@material-ui/lab/TabContext'; | ||
import TabList from '@material-ui/lab/TabList'; | ||
import TabPanel from '@material-ui/lab/TabPanel'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
root: { | ||
flexGrow: 1, | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
export default function LabTabs() { | ||
const classes = useStyles(); | ||
const [value, setValue] = React.useState('1'); | ||
|
||
const handleChange = (event: React.ChangeEvent<{}>, newValue: string) => { | ||
setValue(newValue); | ||
}; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<TabContext value={value}> | ||
<AppBar position="static"> | ||
<TabList onChange={handleChange} aria-label="simple tabs example"> | ||
<Tab label="Item One" value="1" /> | ||
<Tab label="Item Two" value="2" /> | ||
<Tab label="Item Three" value="3" /> | ||
</TabList> | ||
</AppBar> | ||
<TabPanel value="1">Item One</TabPanel> | ||
<TabPanel value="2">Item Two</TabPanel> | ||
<TabPanel value="3">Item Three</TabPanel> | ||
</TabContext> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
|
||
export interface TabContextValue { | ||
idPrefix: string; | ||
value: string; | ||
} | ||
|
||
export interface TabContextProps { | ||
children?: React.ReactNode; | ||
/** | ||
* The value of the currently selected `Tab`. | ||
*/ | ||
value: string; | ||
} | ||
/** | ||
* | ||
* API: | ||
* | ||
* - [TabContext API](https://material-ui.com/api/tab-context/) | ||
*/ | ||
export default function TabContext(props: TabContextProps): JSX.Element; | ||
export function useTabContext(): TabContextValue | null; | ||
export function getPanelId(context: TabContextValue, tabValue: string): string; | ||
export function getTabId(context: TabContextValue, tabValue: string): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import * as PropTypes from 'prop-types'; | ||
|
||
/** | ||
* @type {React.Context<{ idPrefix: string; value: string } | null>} | ||
*/ | ||
const Context = React.createContext(null); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Context.displayName = 'TabContext'; | ||
} | ||
|
||
function useUniquePrefix() { | ||
const [id, setId] = React.useState(null); | ||
React.useEffect(() => { | ||
setId(`mui-p-${Math.round(Math.random() * 1e5)}`); | ||
}, []); | ||
return id; | ||
} | ||
|
||
export default function TabContext(props) { | ||
const { children, value } = props; | ||
const idPrefix = useUniquePrefix(); | ||
|
||
const context = React.useMemo(() => { | ||
return { idPrefix, value }; | ||
}, [idPrefix, value]); | ||
|
||
return <Context.Provider value={context}>{children}</Context.Provider>; | ||
} | ||
|
||
TabContext.propTypes = { | ||
// ----------------------------- Warning -------------------------------- | ||
// | These PropTypes are generated from the TypeScript type definitions | | ||
// | To update them edit the d.ts file and run "yarn proptypes" | | ||
// ---------------------------------------------------------------------- | ||
/** | ||
* The content of the component. | ||
*/ | ||
children: PropTypes.node, | ||
/** | ||
* The value of the currently selected `Tab`. | ||
*/ | ||
value: PropTypes.string.isRequired, | ||
}; | ||
|
||
/** | ||
* @returns {unknown} | ||
*/ | ||
export function useTabContext() { | ||
return React.useContext(Context); | ||
} | ||
|
||
export function getPanelId(context, value) { | ||
const { idPrefix } = context; | ||
if (idPrefix === null) { | ||
return null; | ||
} | ||
return `${context.idPrefix}-P-${value}`; | ||
} | ||
|
||
export function getTabId(context, value) { | ||
const { idPrefix } = context; | ||
if (idPrefix === null) { | ||
return null; | ||
} | ||
return `${context.idPrefix}-T-${value}`; | ||
} |
Oops, something went wrong.