index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/modal/SpringModal.tsx
import * as React from 'react'; import Backdrop from '@mui/material/Backdrop'; import Box from '@mui/material/Box'; import Modal from '@mui/material/Modal'; import Button from '@mui/material/Button'; import Typography from '@mui/material/Typography'; import { useSpring, animated } from '@react-spring/web'; interface FadeProps { children: React.ReactElement; in?: boolean; onClick?: any; onEnter?: (node: HTMLElement, isAppearing: boolean) => void; onExited?: (node: HTMLElement, isAppearing: boolean) => void; ownerState?: any; } const Fade = React.forwardRef<HTMLDivElement, FadeProps>(function Fade(props, ref) { const { children, in: open, onClick, onEnter, onExited, ownerState, ...other } = props; const style = useSpring({ from: { opacity: 0 }, to: { opacity: open ? 1 : 0 }, onStart: () => { if (open && onEnter) { onEnter(null as any, true); } }, onRest: () => { if (!open && onExited) { onExited(null as any, true); } }, }); return ( <animated.div ref={ref} style={style} {...other}> {React.cloneElement(children, { onClick })} </animated.div> ); }); const style = { position: 'absolute' as 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 400, bgcolor: 'background.paper', border: '2px solid #000', boxShadow: 24, p: 4, }; export default function SpringModal() { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); return ( <div> <Button onClick={handleOpen}>Open modal</Button> <Modal aria-labelledby="spring-modal-title" aria-describedby="spring-modal-description" open={open} onClose={handleClose} closeAfterTransition slots={{ backdrop: Backdrop }} slotProps={{ backdrop: { TransitionComponent: Fade, }, }} > <Fade in={open}> <Box sx={style}> <Typography id="spring-modal-title" variant="h6" component="h2"> Text in a modal </Typography> <Typography id="spring-modal-description" sx={{ mt: 2 }}> Duis mollis, est non commodo luctus, nisi erat porttitor ligula. </Typography> </Box> </Fade> </Modal> </div> ); }
2,700
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/modal/TransitionsModal.js
import * as React from 'react'; import Backdrop from '@mui/material/Backdrop'; import Box from '@mui/material/Box'; import Modal from '@mui/material/Modal'; import Fade from '@mui/material/Fade'; import Button from '@mui/material/Button'; import Typography from '@mui/material/Typography'; const style = { position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 400, bgcolor: 'background.paper', border: '2px solid #000', boxShadow: 24, p: 4, }; export default function TransitionsModal() { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); return ( <div> <Button onClick={handleOpen}>Open modal</Button> <Modal aria-labelledby="transition-modal-title" aria-describedby="transition-modal-description" open={open} onClose={handleClose} closeAfterTransition slots={{ backdrop: Backdrop }} slotProps={{ backdrop: { timeout: 500, }, }} > <Fade in={open}> <Box sx={style}> <Typography id="transition-modal-title" variant="h6" component="h2"> Text in a modal </Typography> <Typography id="transition-modal-description" sx={{ mt: 2 }}> Duis mollis, est non commodo luctus, nisi erat porttitor ligula. </Typography> </Box> </Fade> </Modal> </div> ); }
2,701
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/modal/TransitionsModal.tsx
import * as React from 'react'; import Backdrop from '@mui/material/Backdrop'; import Box from '@mui/material/Box'; import Modal from '@mui/material/Modal'; import Fade from '@mui/material/Fade'; import Button from '@mui/material/Button'; import Typography from '@mui/material/Typography'; const style = { position: 'absolute' as 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 400, bgcolor: 'background.paper', border: '2px solid #000', boxShadow: 24, p: 4, }; export default function TransitionsModal() { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); return ( <div> <Button onClick={handleOpen}>Open modal</Button> <Modal aria-labelledby="transition-modal-title" aria-describedby="transition-modal-description" open={open} onClose={handleClose} closeAfterTransition slots={{ backdrop: Backdrop }} slotProps={{ backdrop: { timeout: 500, }, }} > <Fade in={open}> <Box sx={style}> <Typography id="transition-modal-title" variant="h6" component="h2"> Text in a modal </Typography> <Typography id="transition-modal-description" sx={{ mt: 2 }}> Duis mollis, est non commodo luctus, nisi erat porttitor ligula. </Typography> </Box> </Fade> </Modal> </div> ); }
2,702
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/modal/modal.md
--- productId: material-ui title: React Modal component components: Modal githubLabel: 'component: modal' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/ unstyled: /base-ui/react-modal/ --- # Modal <p class="description">The modal component provides a solid foundation for creating dialogs, popovers, lightboxes, or whatever else.</p> The component renders its `children` node in front of a backdrop component. The `Modal` offers important features: - πŸ’„ Manages modal stacking when one-at-a-time just isn't enough. - πŸ” Creates a backdrop, for disabling interaction below the modal. - πŸ” It disables scrolling of the page content while open. - ♿️ It properly manages focus; moving to the modal content, and keeping it there until the modal is closed. - ♿️ Adds the appropriate ARIA roles automatically. {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} :::info The term "modal" is sometimes used to mean "dialog", but this is a misnomer. A modal window describes parts of a UI. An element is considered modal if [it blocks interaction with the rest of the application](https://en.wikipedia.org/wiki/Modal_window). ::: If you are creating a modal dialog, you probably want to use the [Dialog](/material-ui/react-dialog/) component rather than directly using Modal. Modal is a lower-level construct that is leveraged by the following components: - [Dialog](/material-ui/react-dialog/) - [Drawer](/material-ui/react-drawer/) - [Menu](/material-ui/react-menu/) - [Popover](/material-ui/react-popover/) ## Basic modal {{"demo": "BasicModal.js"}} Notice that you can disable the outline (often blue or gold) with the `outline: 0` CSS property. ## Nested modal Modals can be nested, for example a select within a dialog, but stacking of more than two modals, or any two modals with a backdrop is discouraged. {{"demo": "NestedModal.js"}} ## Transitions The open/close state of the modal can be animated with a transition component. This component should respect the following conditions: - Be a direct child descendent of the modal. - Have an `in` prop. This corresponds to the open/close state. - Call the `onEnter` callback prop when the enter transition starts. - Call the `onExited` callback prop when the exit transition is completed. These two callbacks allow the modal to unmount the child content when closed and fully transitioned. Modal has built-in support for [react-transition-group](https://github.com/reactjs/react-transition-group). {{"demo": "TransitionsModal.js"}} Alternatively, you can use [react-spring](https://github.com/pmndrs/react-spring). {{"demo": "SpringModal.js"}} ## Performance The content of modal is unmounted when closed. If you need to make the content available to search engines or render expensive component trees inside your modal while optimizing for interaction responsiveness it might be a good idea to change this default behavior by enabling the `keepMounted` prop: ```jsx <Modal keepMounted /> ``` {{"demo": "KeepMountedModal.js", "defaultCodeOpen": false}} As with any performance optimization, this is not a silver bullet. Be sure to identify bottlenecks first, and then try out these optimization strategies. ## Server-side modal React [doesn't support](https://github.com/facebook/react/issues/13097) the [`createPortal()`](https://react.dev/reference/react-dom/createPortal) API on the server. In order to display the modal, you need to disable the portal feature with the `disablePortal` prop: {{"demo": "ServerModal.js"}} ## Limitations ### Focus trap The modal moves the focus back to the body of the component if the focus tries to escape it. This is done for accessibility purposes. However, it might create issues. In the event the users need to interact with another part of the page, e.g. with a chatbot window, you can disable the behavior: ```jsx <Modal disableEnforceFocus /> ``` ## Accessibility (WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) - Be sure to add `aria-labelledby="id..."`, referencing the modal title, to the `Modal`. Additionally, you may give a description of your modal with the `aria-describedby="id..."` prop on the `Modal`. ```jsx <Modal aria-labelledby="modal-title" aria-describedby="modal-description"> <h2 id="modal-title">My Title</h2> <p id="modal-description">My Description</p> </Modal> ``` - The [WAI-ARIA authoring practices](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/dialog/) can help you set the initial focus on the most relevant element, based on your modal content. - Keep in mind that a "modal window" overlays on either the primary window or another modal window. Windows under a modal are **inert**. That is, users cannot interact with content outside an active modal window. This might create [conflicting behaviors](#focus-trap).
2,703
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/no-ssr/FrameDeferring.js
import * as React from 'react'; import Box from '@mui/material/Box'; import NoSsr from '@mui/material/NoSsr'; function LargeTree() { return Array.from(new Array(5000)).map((_, index) => <span key={index}>.</span>); } export default function FrameDeferring() { const [state, setState] = React.useState({ open: false, defer: false, }); return ( <div> <button type="button" onClick={() => setState({ open: !state.open, defer: false, }) } > {'Render NoSsr defer="false"'} </button> <br /> <button type="button" onClick={() => setState({ open: !state.open, defer: true, }) } > {'Render NoSsr defer="true"'} </button> <br /> <br /> <Box sx={{ width: 300, display: 'flex', flexWrap: 'wrap' }}> {state.open ? ( <React.Fragment> <div>Outside NoSsr</div> <NoSsr defer={state.defer}> .....Inside NoSsr <LargeTree /> </NoSsr> </React.Fragment> ) : null} </Box> </div> ); }
2,704
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/no-ssr/FrameDeferring.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import NoSsr from '@mui/material/NoSsr'; function LargeTree(): any { return Array.from(new Array(5000)).map((_, index) => <span key={index}>.</span>); } export default function FrameDeferring() { const [state, setState] = React.useState({ open: false, defer: false, }); return ( <div> <button type="button" onClick={() => setState({ open: !state.open, defer: false, }) } > {'Render NoSsr defer="false"'} </button> <br /> <button type="button" onClick={() => setState({ open: !state.open, defer: true, }) } > {'Render NoSsr defer="true"'} </button> <br /> <br /> <Box sx={{ width: 300, display: 'flex', flexWrap: 'wrap' }}> {state.open ? ( <React.Fragment> <div>Outside NoSsr</div> <NoSsr defer={state.defer}> .....Inside NoSsr <LargeTree /> </NoSsr> </React.Fragment> ) : null} </Box> </div> ); }
2,705
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/no-ssr/SimpleNoSsr.js
import * as React from 'react'; import NoSsr from '@mui/material/NoSsr'; import Box from '@mui/material/Box'; export default function SimpleNoSsr() { return ( <div> <Box sx={{ p: 2, bgcolor: 'primary.main', color: 'primary.contrastText' }}> Server and Client </Box> <NoSsr> <Box sx={{ p: 2, bgcolor: 'secondary.main', color: 'secondary.contrastText' }} > Client only </Box> </NoSsr> </div> ); }
2,706
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/no-ssr/SimpleNoSsr.tsx
import * as React from 'react'; import NoSsr from '@mui/material/NoSsr'; import Box from '@mui/material/Box'; export default function SimpleNoSsr() { return ( <div> <Box sx={{ p: 2, bgcolor: 'primary.main', color: 'primary.contrastText' }}> Server and Client </Box> <NoSsr> <Box sx={{ p: 2, bgcolor: 'secondary.main', color: 'secondary.contrastText' }} > Client only </Box> </NoSsr> </div> ); }
2,707
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/no-ssr/SimpleNoSsr.tsx.preview
<Box sx={{ p: 2, bgcolor: 'primary.main', color: 'primary.contrastText' }}> Server and Client </Box> <NoSsr> <Box sx={{ p: 2, bgcolor: 'secondary.main', color: 'secondary.contrastText' }} > Client only </Box> </NoSsr>
2,708
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/no-ssr/no-ssr.md
--- productId: material-ui title: No SSR React component components: NoSsr --- # No SSR <p class="description">The No-SSR component defers the rendering of children components from the server to the client.</p> ## This document has moved :::warning Please refer to the [No-SSR](/base-ui/react-no-ssr/) component page in the Base UI docs for demos and details on usage. No-SSR is a part of the standalone [Base UI](/base-ui/) component library. It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version, after `@mui/base` gets a stable release. :::
2,709
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/BasicPagination.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function BasicPagination() { return ( <Stack spacing={2}> <Pagination count={10} /> <Pagination count={10} color="primary" /> <Pagination count={10} color="secondary" /> <Pagination count={10} disabled /> </Stack> ); }
2,710
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/BasicPagination.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function BasicPagination() { return ( <Stack spacing={2}> <Pagination count={10} /> <Pagination count={10} color="primary" /> <Pagination count={10} color="secondary" /> <Pagination count={10} disabled /> </Stack> ); }
2,711
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/BasicPagination.tsx.preview
<Pagination count={10} /> <Pagination count={10} color="primary" /> <Pagination count={10} color="secondary" /> <Pagination count={10} disabled />
2,712
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/CustomIcons.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import PaginationItem from '@mui/material/PaginationItem'; import Stack from '@mui/material/Stack'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; export default function CustomIcons() { return ( <Stack spacing={2}> <Pagination count={10} renderItem={(item) => ( <PaginationItem slots={{ previous: ArrowBackIcon, next: ArrowForwardIcon }} {...item} /> )} /> </Stack> ); }
2,713
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/CustomIcons.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import PaginationItem from '@mui/material/PaginationItem'; import Stack from '@mui/material/Stack'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; export default function CustomIcons() { return ( <Stack spacing={2}> <Pagination count={10} renderItem={(item) => ( <PaginationItem slots={{ previous: ArrowBackIcon, next: ArrowForwardIcon }} {...item} /> )} /> </Stack> ); }
2,714
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/CustomIcons.tsx.preview
<Pagination count={10} renderItem={(item) => ( <PaginationItem slots={{ previous: ArrowBackIcon, next: ArrowForwardIcon }} {...item} /> )} />
2,715
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationButtons.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationButtons() { return ( <Stack spacing={2}> <Pagination count={10} showFirstButton showLastButton /> <Pagination count={10} hidePrevButton hideNextButton /> </Stack> ); }
2,716
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationButtons.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationButtons() { return ( <Stack spacing={2}> <Pagination count={10} showFirstButton showLastButton /> <Pagination count={10} hidePrevButton hideNextButton /> </Stack> ); }
2,717
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationButtons.tsx.preview
<Pagination count={10} showFirstButton showLastButton /> <Pagination count={10} hidePrevButton hideNextButton />
2,718
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationControlled.js
import * as React from 'react'; import Typography from '@mui/material/Typography'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationControlled() { const [page, setPage] = React.useState(1); const handleChange = (event, value) => { setPage(value); }; return ( <Stack spacing={2}> <Typography>Page: {page}</Typography> <Pagination count={10} page={page} onChange={handleChange} /> </Stack> ); }
2,719
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationControlled.tsx
import * as React from 'react'; import Typography from '@mui/material/Typography'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationControlled() { const [page, setPage] = React.useState(1); const handleChange = (event: React.ChangeEvent<unknown>, value: number) => { setPage(value); }; return ( <Stack spacing={2}> <Typography>Page: {page}</Typography> <Pagination count={10} page={page} onChange={handleChange} /> </Stack> ); }
2,720
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationControlled.tsx.preview
<Typography>Page: {page}</Typography> <Pagination count={10} page={page} onChange={handleChange} />
2,721
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationLink.js
import * as React from 'react'; import { Link, MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'; import Pagination from '@mui/material/Pagination'; import PaginationItem from '@mui/material/PaginationItem'; function Content() { const location = useLocation(); const query = new URLSearchParams(location.search); const page = parseInt(query.get('page') || '1', 10); return ( <Pagination page={page} count={10} renderItem={(item) => ( <PaginationItem component={Link} to={`/inbox${item.page === 1 ? '' : `?page=${item.page}`}`} {...item} /> )} /> ); } export default function PaginationLink() { return ( <MemoryRouter initialEntries={['/inbox']} initialIndex={0}> <Routes> <Route path="*" element={<Content />} /> </Routes> </MemoryRouter> ); }
2,722
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationLink.tsx
import * as React from 'react'; import { Link, MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'; import Pagination from '@mui/material/Pagination'; import PaginationItem from '@mui/material/PaginationItem'; function Content() { const location = useLocation(); const query = new URLSearchParams(location.search); const page = parseInt(query.get('page') || '1', 10); return ( <Pagination page={page} count={10} renderItem={(item) => ( <PaginationItem component={Link} to={`/inbox${item.page === 1 ? '' : `?page=${item.page}`}`} {...item} /> )} /> ); } export default function PaginationLink() { return ( <MemoryRouter initialEntries={['/inbox']} initialIndex={0}> <Routes> <Route path="*" element={<Content />} /> </Routes> </MemoryRouter> ); }
2,723
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationLink.tsx.preview
<MemoryRouter initialEntries={['/inbox']} initialIndex={0}> <Routes> <Route path="*" element={<Content />} /> </Routes> </MemoryRouter>
2,724
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationOutlined.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationOutlined() { return ( <Stack spacing={2}> <Pagination count={10} variant="outlined" /> <Pagination count={10} variant="outlined" color="primary" /> <Pagination count={10} variant="outlined" color="secondary" /> <Pagination count={10} variant="outlined" disabled /> </Stack> ); }
2,725
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationOutlined.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationOutlined() { return ( <Stack spacing={2}> <Pagination count={10} variant="outlined" /> <Pagination count={10} variant="outlined" color="primary" /> <Pagination count={10} variant="outlined" color="secondary" /> <Pagination count={10} variant="outlined" disabled /> </Stack> ); }
2,726
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationOutlined.tsx.preview
<Pagination count={10} variant="outlined" /> <Pagination count={10} variant="outlined" color="primary" /> <Pagination count={10} variant="outlined" color="secondary" /> <Pagination count={10} variant="outlined" disabled />
2,727
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationRanges.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationRanges() { return ( <Stack spacing={2}> <Pagination count={11} defaultPage={6} siblingCount={0} /> <Pagination count={11} defaultPage={6} /> {/* Default ranges */} <Pagination count={11} defaultPage={6} siblingCount={0} boundaryCount={2} /> <Pagination count={11} defaultPage={6} boundaryCount={2} /> </Stack> ); }
2,728
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationRanges.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationRanges() { return ( <Stack spacing={2}> <Pagination count={11} defaultPage={6} siblingCount={0} /> <Pagination count={11} defaultPage={6} /> {/* Default ranges */} <Pagination count={11} defaultPage={6} siblingCount={0} boundaryCount={2} /> <Pagination count={11} defaultPage={6} boundaryCount={2} /> </Stack> ); }
2,729
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationRanges.tsx.preview
<Pagination count={11} defaultPage={6} siblingCount={0} /> <Pagination count={11} defaultPage={6} /> {/* Default ranges */} <Pagination count={11} defaultPage={6} siblingCount={0} boundaryCount={2} /> <Pagination count={11} defaultPage={6} boundaryCount={2} />
2,730
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationRounded.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationRounded() { return ( <Stack spacing={2}> <Pagination count={10} shape="rounded" /> <Pagination count={10} variant="outlined" shape="rounded" /> </Stack> ); }
2,731
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationRounded.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationRounded() { return ( <Stack spacing={2}> <Pagination count={10} shape="rounded" /> <Pagination count={10} variant="outlined" shape="rounded" /> </Stack> ); }
2,732
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationRounded.tsx.preview
<Pagination count={10} shape="rounded" /> <Pagination count={10} variant="outlined" shape="rounded" />
2,733
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationSize.js
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationSize() { return ( <Stack spacing={2}> <Pagination count={10} size="small" /> <Pagination count={10} /> <Pagination count={10} size="large" /> </Stack> ); }
2,734
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationSize.tsx
import * as React from 'react'; import Pagination from '@mui/material/Pagination'; import Stack from '@mui/material/Stack'; export default function PaginationSize() { return ( <Stack spacing={2}> <Pagination count={10} size="small" /> <Pagination count={10} /> <Pagination count={10} size="large" /> </Stack> ); }
2,735
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/PaginationSize.tsx.preview
<Pagination count={10} size="small" /> <Pagination count={10} /> <Pagination count={10} size="large" />
2,736
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/TablePaginationDemo.js
import * as React from 'react'; import TablePagination from '@mui/material/TablePagination'; export default function TablePaginationDemo() { const [page, setPage] = React.useState(2); const [rowsPerPage, setRowsPerPage] = React.useState(10); const handleChangePage = (event, newPage) => { setPage(newPage); }; const handleChangeRowsPerPage = (event) => { setRowsPerPage(parseInt(event.target.value, 10)); setPage(0); }; return ( <TablePagination component="div" count={100} page={page} onPageChange={handleChangePage} rowsPerPage={rowsPerPage} onRowsPerPageChange={handleChangeRowsPerPage} /> ); }
2,737
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/TablePaginationDemo.tsx
import * as React from 'react'; import TablePagination from '@mui/material/TablePagination'; export default function TablePaginationDemo() { const [page, setPage] = React.useState(2); const [rowsPerPage, setRowsPerPage] = React.useState(10); const handleChangePage = ( event: React.MouseEvent<HTMLButtonElement> | null, newPage: number, ) => { setPage(newPage); }; const handleChangeRowsPerPage = ( event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, ) => { setRowsPerPage(parseInt(event.target.value, 10)); setPage(0); }; return ( <TablePagination component="div" count={100} page={page} onPageChange={handleChangePage} rowsPerPage={rowsPerPage} onRowsPerPageChange={handleChangeRowsPerPage} /> ); }
2,738
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/TablePaginationDemo.tsx.preview
<TablePagination component="div" count={100} page={page} onPageChange={handleChangePage} rowsPerPage={rowsPerPage} onRowsPerPageChange={handleChangeRowsPerPage} />
2,739
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/UsePagination.js
import * as React from 'react'; import usePagination from '@mui/material/usePagination'; import { styled } from '@mui/material/styles'; const List = styled('ul')({ listStyle: 'none', padding: 0, margin: 0, display: 'flex', }); export default function UsePagination() { const { items } = usePagination({ count: 10, }); return ( <nav> <List> {items.map(({ page, type, selected, ...item }, index) => { let children = null; if (type === 'start-ellipsis' || type === 'end-ellipsis') { children = '…'; } else if (type === 'page') { children = ( <button type="button" style={{ fontWeight: selected ? 'bold' : undefined, }} {...item} > {page} </button> ); } else { children = ( <button type="button" {...item}> {type} </button> ); } return <li key={index}>{children}</li>; })} </List> </nav> ); }
2,740
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/UsePagination.tsx
import * as React from 'react'; import usePagination from '@mui/material/usePagination'; import { styled } from '@mui/material/styles'; const List = styled('ul')({ listStyle: 'none', padding: 0, margin: 0, display: 'flex', }); export default function UsePagination() { const { items } = usePagination({ count: 10, }); return ( <nav> <List> {items.map(({ page, type, selected, ...item }, index) => { let children = null; if (type === 'start-ellipsis' || type === 'end-ellipsis') { children = '…'; } else if (type === 'page') { children = ( <button type="button" style={{ fontWeight: selected ? 'bold' : undefined, }} {...item} > {page} </button> ); } else { children = ( <button type="button" {...item}> {type} </button> ); } return <li key={index}>{children}</li>; })} </List> </nav> ); }
2,741
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/pagination/pagination.md
--- productId: material-ui title: React Pagination component components: Pagination, PaginationItem, TablePagination githubLabel: 'component: pagination' --- # Pagination <p class="description">The Pagination component enables the user to select a specific page from a range of pages.</p> {{"component": "modules/components/ComponentLinkHeader.js"}} ## Basic pagination {{"demo": "BasicPagination.js"}} ## Outlined pagination {{"demo": "PaginationOutlined.js"}} ## Rounded pagination {{"demo": "PaginationRounded.js"}} ## Pagination size {{"demo": "PaginationSize.js"}} ## Buttons You can optionally enable first-page and last-page buttons, or disable the previous-page and next-page buttons. {{"demo": "PaginationButtons.js"}} ## Custom icons It's possible to customize the control icons. {{"demo": "CustomIcons.js"}} ## Pagination ranges You can specify how many digits to display either side of current page with the `siblingCount` prop, and adjacent to the start and end page number with the `boundaryCount` prop. {{"demo": "PaginationRanges.js"}} ## Controlled pagination {{"demo": "PaginationControlled.js"}} ## Router integration {{"demo": "PaginationLink.js"}} ## `usePagination` For advanced customization use cases, a headless `usePagination()` hook is exposed. It accepts almost the same options as the Pagination component minus all the props related to the rendering of JSX. The Pagination component is built on this hook. ```jsx import usePagination from '@mui/material/usePagination'; ``` {{"demo": "UsePagination.js"}} ## Table pagination The `Pagination` component was designed to paginate a list of arbitrary items when infinite loading isn't used. It's preferred in contexts where SEO is important, for instance, a blog. For the pagination of a large set of tabular data, you should use the `TablePagination` component. {{"demo": "TablePaginationDemo.js"}} :::warning Note that the `Pagination` page prop starts at 1 to match the requirement of including the value in the URL, while the `TablePagination` page prop starts at 0 to match the requirement of zero-based JavaScript arrays that comes with rendering a lot of tabular data. ::: You can learn more about this use case in the [table section](/material-ui/react-table/#custom-pagination-options) of the documentation. ## Accessibility ### ARIA The root node has a role of "navigation" and aria-label "pagination navigation" by default. The page items have an aria-label that identifies the purpose of the item ("go to first page", "go to previous page", "go to page 1" etc.). You can override these using the `getItemAriaLabel` prop. ### Keyboard The pagination items are in tab order, with a tabindex of "0".
2,742
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/Elevation.js
import * as React from 'react'; import Grid from '@mui/material/Grid'; import Paper from '@mui/material/Paper'; import Box from '@mui/material/Box'; import { createTheme, ThemeProvider, styled } from '@mui/material/styles'; const Item = styled(Paper)(({ theme }) => ({ ...theme.typography.body2, textAlign: 'center', color: theme.palette.text.secondary, height: 60, lineHeight: '60px', })); const darkTheme = createTheme({ palette: { mode: 'dark' } }); const lightTheme = createTheme({ palette: { mode: 'light' } }); export default function Elevation() { return ( <Grid container spacing={2}> {[lightTheme, darkTheme].map((theme, index) => ( <Grid item xs={6} key={index}> <ThemeProvider theme={theme}> <Box sx={{ p: 2, borderRadius: 2, bgcolor: 'background.default', display: 'grid', gridTemplateColumns: { md: '1fr 1fr' }, gap: 2, }} > {[0, 1, 2, 3, 4, 6, 8, 12, 16, 24].map((elevation) => ( <Item key={elevation} elevation={elevation}> {`elevation=${elevation}`} </Item> ))} </Box> </ThemeProvider> </Grid> ))} </Grid> ); }
2,743
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/Elevation.tsx
import * as React from 'react'; import Grid from '@mui/material/Grid'; import Paper from '@mui/material/Paper'; import Box from '@mui/material/Box'; import { createTheme, ThemeProvider, styled } from '@mui/material/styles'; const Item = styled(Paper)(({ theme }) => ({ ...theme.typography.body2, textAlign: 'center', color: theme.palette.text.secondary, height: 60, lineHeight: '60px', })); const darkTheme = createTheme({ palette: { mode: 'dark' } }); const lightTheme = createTheme({ palette: { mode: 'light' } }); export default function Elevation() { return ( <Grid container spacing={2}> {[lightTheme, darkTheme].map((theme, index) => ( <Grid item xs={6} key={index}> <ThemeProvider theme={theme}> <Box sx={{ p: 2, borderRadius: 2, bgcolor: 'background.default', display: 'grid', gridTemplateColumns: { md: '1fr 1fr' }, gap: 2, }} > {[0, 1, 2, 3, 4, 6, 8, 12, 16, 24].map((elevation) => ( <Item key={elevation} elevation={elevation}> {`elevation=${elevation}`} </Item> ))} </Box> </ThemeProvider> </Grid> ))} </Grid> ); }
2,744
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/SimplePaper.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Paper from '@mui/material/Paper'; export default function SimplePaper() { return ( <Box sx={{ display: 'flex', flexWrap: 'wrap', '& > :not(style)': { m: 1, width: 128, height: 128, }, }} > <Paper elevation={0} /> <Paper /> <Paper elevation={3} /> </Box> ); }
2,745
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/SimplePaper.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Paper from '@mui/material/Paper'; export default function SimplePaper() { return ( <Box sx={{ display: 'flex', flexWrap: 'wrap', '& > :not(style)': { m: 1, width: 128, height: 128, }, }} > <Paper elevation={0} /> <Paper /> <Paper elevation={3} /> </Box> ); }
2,746
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/SimplePaper.tsx.preview
<Paper elevation={0} /> <Paper /> <Paper elevation={3} />
2,747
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/SquareCorners.js
import * as React from 'react'; import Stack from '@mui/material/Stack'; import Paper from '@mui/material/Paper'; import { styled } from '@mui/material/styles'; const DemoPaper = styled(Paper)(({ theme }) => ({ width: 120, height: 120, padding: theme.spacing(2), ...theme.typography.body2, textAlign: 'center', })); export default function SquareCorners() { return ( <Stack direction="row" spacing={2}> <DemoPaper square={false}>rounded corners</DemoPaper> <DemoPaper square>square corners</DemoPaper> </Stack> ); }
2,748
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/SquareCorners.tsx
import * as React from 'react'; import Stack from '@mui/material/Stack'; import Paper from '@mui/material/Paper'; import { styled } from '@mui/material/styles'; const DemoPaper = styled(Paper)(({ theme }) => ({ width: 120, height: 120, padding: theme.spacing(2), ...theme.typography.body2, textAlign: 'center', })); export default function SquareCorners() { return ( <Stack direction="row" spacing={2}> <DemoPaper square={false}>rounded corners</DemoPaper> <DemoPaper square>square corners</DemoPaper> </Stack> ); }
2,749
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/SquareCorners.tsx.preview
<DemoPaper square={false}>rounded corners</DemoPaper> <DemoPaper square>square corners</DemoPaper>
2,750
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/Variants.js
import * as React from 'react'; import Stack from '@mui/material/Stack'; import Paper from '@mui/material/Paper'; import { styled } from '@mui/material/styles'; const DemoPaper = styled(Paper)(({ theme }) => ({ width: 120, height: 120, padding: theme.spacing(2), ...theme.typography.body2, textAlign: 'center', })); export default function Variants() { return ( <Stack direction="row" spacing={2}> <DemoPaper variant="elevation">default variant</DemoPaper> <DemoPaper variant="outlined">outlined variant</DemoPaper> </Stack> ); }
2,751
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/Variants.tsx
import * as React from 'react'; import Stack from '@mui/material/Stack'; import Paper from '@mui/material/Paper'; import { styled } from '@mui/material/styles'; const DemoPaper = styled(Paper)(({ theme }) => ({ width: 120, height: 120, padding: theme.spacing(2), ...theme.typography.body2, textAlign: 'center', })); export default function Variants() { return ( <Stack direction="row" spacing={2}> <DemoPaper variant="elevation">default variant</DemoPaper> <DemoPaper variant="outlined">outlined variant</DemoPaper> </Stack> ); }
2,752
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/Variants.tsx.preview
<DemoPaper variant="elevation">default variant</DemoPaper> <DemoPaper variant="outlined">outlined variant</DemoPaper>
2,753
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/paper/paper.md
--- productId: material-ui title: React Paper component components: Paper githubLabel: 'component: Paper' materialDesign: https://m2.material.io/design/environment/elevation.html --- # Paper <p class="description">The Paper component is a container for displaying content on an elevated surface.</p> {{"component": "modules/components/ComponentLinkHeader.js"}} ## Introduction In Material Design, surface components and shadow styles are heavily influenced by their real-world physical counterparts. Material UI implements this concept with the Paper component, a container-like surface that features the [`elevation`](#elevation) prop for pulling box-shadow values from the theme. :::success The Paper component is ideally suited for designs that follow [Material Design's elevation system](https://m2.material.io/design/environment/elevation.html#elevation-in-material-design), which is meant to replicate how light casts shadows in the physical world. If you just need a generic container, you may prefer to use the [Box](/material-ui/react-box/) or [Container](/material-ui/react-container/) components. ::: {{"demo": "SimplePaper.js", "bg": true}} ## Component ```jsx import Paper from '@mui/material/Paper'; ``` ## Customization ### Elevation Use the `elevation` prop to establish hierarchy through the use of shadows. The Paper component's default elevation level is `1`. The prop accepts values from `0` to `24`. The higher the number, the further away the Paper appears to be from its background. In dark mode, increasing the elevation also makes the background color lighter. This is done by applying a semi-transparent gradient with the `background-image` CSS property. :::warning The aforementioned dark mode behavior can lead to confusion when overriding the Paper component, because changing the `background-color` property won't affect the lighter shading. To override it, you must either use a new background value, or customize the values for both `background-color` and `background-image`. ::: {{"demo": "Elevation.js", "bg": "outlined"}} ### Variants Set the `variant` prop to `"outlined"` for a flat, outlined Paper with no shadows: {{"demo": "Variants.js", "bg": true}} ### Corners The Paper component features rounded corners by default. Add the `square` prop for square corners: {{"demo": "SquareCorners.js", "bg": true}} ## Anatomy The Paper component is composed of a single root `<div>` that wraps around its contents: ```html <div class="MuiPaper-root"> <!-- Paper contents --> </div> ```
2,754
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/AnchorPlayground.js
import * as React from 'react'; import FormControl from '@mui/material/FormControl'; import FormLabel from '@mui/material/FormLabel'; import FormControlLabel from '@mui/material/FormControlLabel'; import RadioGroup from '@mui/material/RadioGroup'; import Radio from '@mui/material/Radio'; import Grid from '@mui/material/Grid'; import { green } from '@mui/material/colors'; import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Popover from '@mui/material/Popover'; import Input from '@mui/material/Input'; import InputLabel from '@mui/material/InputLabel'; import HighlightedCode from 'docs/src/modules/components/HighlightedCode'; const inlineStyles = { anchorVertical: { top: { top: -5, }, center: { top: 'calc(50% - 5px)', }, bottom: { bottom: -5, }, }, anchorHorizontal: { left: { left: -5, }, center: { left: 'calc(50% - 5px)', }, right: { right: -5, }, }, }; function AnchorPlayground() { const anchorRef = React.useRef(); const [state, setState] = React.useState({ open: false, anchorOriginVertical: 'top', anchorOriginHorizontal: 'left', transformOriginVertical: 'top', transformOriginHorizontal: 'left', positionTop: 200, // Just so the popover can be spotted more easily positionLeft: 400, // Same as above anchorReference: 'anchorEl', }); const { open, anchorOriginVertical, anchorOriginHorizontal, transformOriginVertical, transformOriginHorizontal, positionTop, positionLeft, anchorReference, } = state; const handleChange = (event) => { setState({ ...state, [event.target.name]: event.target.value, }); }; const handleNumberInputChange = (key) => (event) => { setState({ ...state, [key]: parseInt(event.target.value, 10), }); }; const handleClickButton = () => { setState({ ...state, open: true, }); }; const handleClose = () => { setState({ ...state, open: false, }); }; let mode = ''; if (anchorReference === 'anchorPosition') { mode = ` anchorReference="${anchorReference}" anchorPosition={{ top: ${positionTop}, left: ${positionLeft} }}`; } const jsx = ` <Popover ${mode} anchorOrigin={{ vertical: '${anchorOriginVertical}', horizontal: '${anchorOriginHorizontal}', }} transformOrigin={{ vertical: '${transformOriginVertical}', horizontal: '${transformOriginHorizontal}', }} > The content of the Popover. </Popover> `; const radioAnchorClasses = { color: green[600], '&.Mui-checked': { color: green[500], }, }; return ( <div> <Grid container justifyContent="center"> <Grid item sx={{ position: 'relative', mb: 4 }}> <Button ref={anchorRef} variant="contained" onClick={handleClickButton}> Open Popover </Button> {anchorReference === 'anchorEl' && ( <Box sx={{ bgcolor: green[500], width: 10, height: 10, borderRadius: '50%', position: 'absolute', }} style={{ ...inlineStyles.anchorVertical[anchorOriginVertical], ...inlineStyles.anchorHorizontal[anchorOriginHorizontal], }} /> )} </Grid> </Grid> <Popover open={open} anchorEl={anchorRef.current} anchorReference={anchorReference} anchorPosition={{ top: positionTop, left: positionLeft, }} onClose={handleClose} anchorOrigin={{ vertical: anchorOriginVertical, horizontal: anchorOriginHorizontal, }} transformOrigin={{ vertical: transformOriginVertical, horizontal: transformOriginHorizontal, }} > <Typography sx={{ m: 2 }}>The content of the Popover.</Typography> </Popover> <Grid container spacing={2}> <Grid item xs={12} sm={6}> <FormControl component="fieldset"> <FormLabel component="legend">anchorReference</FormLabel> <RadioGroup row aria-label="anchor reference" name="anchorReference" value={anchorReference} onChange={handleChange} > <FormControlLabel value="anchorEl" control={<Radio />} label="anchorEl" /> <FormControlLabel value="anchorPosition" control={<Radio />} label="anchorPosition" /> </RadioGroup> </FormControl> </Grid> <Grid item xs={12} sm={6}> <FormControl variant="standard"> <InputLabel htmlFor="position-top">anchorPosition.top</InputLabel> <Input id="position-top" type="number" value={positionTop} onChange={handleNumberInputChange('positionTop')} /> </FormControl> &nbsp; <FormControl variant="standard"> <InputLabel htmlFor="position-left">anchorPosition.left</InputLabel> <Input id="position-left" type="number" value={positionLeft} onChange={handleNumberInputChange('positionLeft')} /> </FormControl> </Grid> <Grid item xs={12} sm={6}> <FormControl component="fieldset"> <FormLabel component="legend">anchorOrigin.vertical</FormLabel> <RadioGroup aria-label="anchor origin vertical" name="anchorOriginVertical" value={anchorOriginVertical} onChange={handleChange} > <FormControlLabel value="top" control={<Radio sx={radioAnchorClasses} />} label="Top" /> <FormControlLabel value="center" control={<Radio sx={radioAnchorClasses} />} label="Center" /> <FormControlLabel value="bottom" control={<Radio sx={radioAnchorClasses} />} label="Bottom" /> </RadioGroup> </FormControl> </Grid> <Grid item xs={12} sm={6}> <FormControl component="fieldset"> <FormLabel component="legend">transformOrigin.vertical</FormLabel> <RadioGroup aria-label="transform origin vertical" name="transformOriginVertical" value={transformOriginVertical} onChange={handleChange} > <FormControlLabel value="top" control={<Radio />} label="Top" /> <FormControlLabel value="center" control={<Radio color="primary" />} label="Center" /> <FormControlLabel value="bottom" control={<Radio color="primary" />} label="Bottom" /> </RadioGroup> </FormControl> </Grid> <Grid item xs={12} sm={6}> <FormControl component="fieldset"> <FormLabel component="legend">anchorOrigin.horizontal</FormLabel> <RadioGroup row aria-label="anchor origin horizontal" name="anchorOriginHorizontal" value={anchorOriginHorizontal} onChange={handleChange} > <FormControlLabel value="left" control={<Radio sx={radioAnchorClasses} />} label="Left" /> <FormControlLabel value="center" control={<Radio sx={radioAnchorClasses} />} label="Center" /> <FormControlLabel value="right" control={<Radio sx={radioAnchorClasses} />} label="Right" /> </RadioGroup> </FormControl> </Grid> <Grid item xs={12} sm={6}> <FormControl component="fieldset"> <FormLabel component="legend">transformOrigin.horizontal</FormLabel> <RadioGroup row aria-label="transform origin horizontal" name="transformOriginHorizontal" value={transformOriginHorizontal} onChange={handleChange} > <FormControlLabel value="left" control={<Radio color="primary" />} label="Left" /> <FormControlLabel value="center" control={<Radio color="primary" />} label="Center" /> <FormControlLabel value="right" control={<Radio color="primary" />} label="Right" /> </RadioGroup> </FormControl> </Grid> </Grid> <HighlightedCode code={jsx} language="jsx" /> </div> ); } export default AnchorPlayground;
2,755
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/BasicPopover.js
import * as React from 'react'; import Popover from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; export default function BasicPopover() { const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (event) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); const id = open ? 'simple-popover' : undefined; return ( <div> <Button aria-describedby={id} variant="contained" onClick={handleClick}> Open Popover </Button> <Popover id={id} open={open} anchorEl={anchorEl} onClose={handleClose} anchorOrigin={{ vertical: 'bottom', horizontal: 'left', }} > <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Popover> </div> ); }
2,756
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/BasicPopover.tsx
import * as React from 'react'; import Popover from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; export default function BasicPopover() { const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null); const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); const id = open ? 'simple-popover' : undefined; return ( <div> <Button aria-describedby={id} variant="contained" onClick={handleClick}> Open Popover </Button> <Popover id={id} open={open} anchorEl={anchorEl} onClose={handleClose} anchorOrigin={{ vertical: 'bottom', horizontal: 'left', }} > <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Popover> </div> ); }
2,757
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/BasicPopover.tsx.preview
<Button aria-describedby={id} variant="contained" onClick={handleClick}> Open Popover </Button> <Popover id={id} open={open} anchorEl={anchorEl} onClose={handleClose} anchorOrigin={{ vertical: 'bottom', horizontal: 'left', }} > <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Popover>
2,758
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/MouseOverPopover.js
import * as React from 'react'; import Popover from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; export default function MouseOverPopover() { const [anchorEl, setAnchorEl] = React.useState(null); const handlePopoverOpen = (event) => { setAnchorEl(event.currentTarget); }; const handlePopoverClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); return ( <div> <Typography aria-owns={open ? 'mouse-over-popover' : undefined} aria-haspopup="true" onMouseEnter={handlePopoverOpen} onMouseLeave={handlePopoverClose} > Hover with a Popover. </Typography> <Popover id="mouse-over-popover" sx={{ pointerEvents: 'none', }} open={open} anchorEl={anchorEl} anchorOrigin={{ vertical: 'bottom', horizontal: 'left', }} transformOrigin={{ vertical: 'top', horizontal: 'left', }} onClose={handlePopoverClose} disableRestoreFocus > <Typography sx={{ p: 1 }}>I use Popover.</Typography> </Popover> </div> ); }
2,759
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/MouseOverPopover.tsx
import * as React from 'react'; import Popover from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; export default function MouseOverPopover() { const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null); const handlePopoverOpen = (event: React.MouseEvent<HTMLElement>) => { setAnchorEl(event.currentTarget); }; const handlePopoverClose = () => { setAnchorEl(null); }; const open = Boolean(anchorEl); return ( <div> <Typography aria-owns={open ? 'mouse-over-popover' : undefined} aria-haspopup="true" onMouseEnter={handlePopoverOpen} onMouseLeave={handlePopoverClose} > Hover with a Popover. </Typography> <Popover id="mouse-over-popover" sx={{ pointerEvents: 'none', }} open={open} anchorEl={anchorEl} anchorOrigin={{ vertical: 'bottom', horizontal: 'left', }} transformOrigin={{ vertical: 'top', horizontal: 'left', }} onClose={handlePopoverClose} disableRestoreFocus > <Typography sx={{ p: 1 }}>I use Popover.</Typography> </Popover> </div> ); }
2,760
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/PopoverPopupState.js
import * as React from 'react'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import Popover from '@mui/material/Popover'; import PopupState, { bindTrigger, bindPopover } from 'material-ui-popup-state'; export default function PopoverPopupState() { return ( <PopupState variant="popover" popupId="demo-popup-popover"> {(popupState) => ( <div> <Button variant="contained" {...bindTrigger(popupState)}> Open Popover </Button> <Popover {...bindPopover(popupState)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center', }} transformOrigin={{ vertical: 'top', horizontal: 'center', }} > <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Popover> </div> )} </PopupState> ); }
2,761
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/PopoverPopupState.tsx
import * as React from 'react'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import Popover from '@mui/material/Popover'; import PopupState, { bindTrigger, bindPopover } from 'material-ui-popup-state'; export default function PopoverPopupState() { return ( <PopupState variant="popover" popupId="demo-popup-popover"> {(popupState) => ( <div> <Button variant="contained" {...bindTrigger(popupState)}> Open Popover </Button> <Popover {...bindPopover(popupState)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center', }} transformOrigin={{ vertical: 'top', horizontal: 'center', }} > <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Popover> </div> )} </PopupState> ); }
2,762
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/VirtualElementPopover.js
import * as React from 'react'; import Popover from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; import Paper from '@mui/material/Paper'; export default function VirtualElementPopover() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const handleClose = () => { setOpen(false); }; const handleMouseUp = () => { const selection = window.getSelection(); // Skip if selection has a length of 0 if (!selection || selection.anchorOffset === selection.focusOffset) { return; } const getBoundingClientRect = () => { return selection.getRangeAt(0).getBoundingClientRect(); }; setOpen(true); setAnchorEl({ getBoundingClientRect, nodeType: 1 }); }; const id = open ? 'virtual-element-popover' : undefined; return ( <div> <Typography aria-describedby={id} onMouseUp={handleMouseUp}> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus, bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan metus vel maximus consequat. Suspendisse lacinia tellus a libero volutpat maximus. </Typography> <Popover id={id} open={open} anchorEl={anchorEl} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }} onClose={handleClose} > <Paper> <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Paper> </Popover> </div> ); }
2,763
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/VirtualElementPopover.tsx
import * as React from 'react'; import Popover, { PopoverProps } from '@mui/material/Popover'; import Typography from '@mui/material/Typography'; import Paper from '@mui/material/Paper'; export default function VirtualElementPopover() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState<PopoverProps['anchorEl']>(null); const handleClose = () => { setOpen(false); }; const handleMouseUp = () => { const selection = window.getSelection(); // Skip if selection has a length of 0 if (!selection || selection.anchorOffset === selection.focusOffset) { return; } const getBoundingClientRect = () => { return selection.getRangeAt(0).getBoundingClientRect(); }; setOpen(true); setAnchorEl({ getBoundingClientRect, nodeType: 1 }); }; const id = open ? 'virtual-element-popover' : undefined; return ( <div> <Typography aria-describedby={id} onMouseUp={handleMouseUp}> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus, bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan metus vel maximus consequat. Suspendisse lacinia tellus a libero volutpat maximus. </Typography> <Popover id={id} open={open} anchorEl={anchorEl} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }} onClose={handleClose} > <Paper> <Typography sx={{ p: 2 }}>The content of the Popover.</Typography> </Paper> </Popover> </div> ); }
2,764
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popover/popover.md
--- productId: material-ui title: React Popover component components: Grow, Popover githubLabel: 'component: Popover' --- # Popover <p class="description">A Popover can be used to display some content on top of another.</p> Things to know when using the `Popover` component: - The component is built on top of the [`Modal`](/material-ui/react-modal/) component. - The scroll and click away are blocked unlike with the [`Popper`](/material-ui/react-popper/) component. {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} ## Basic Popover {{"demo": "BasicPopover.js"}} ## Anchor playground Use the radio buttons to adjust the `anchorOrigin` and `transformOrigin` positions. You can also set the `anchorReference` to `anchorPosition` or `anchorEl`. When it is `anchorPosition`, the component will, instead of `anchorEl`, refer to the `anchorPosition` prop which you can adjust to set the position of the popover. {{"demo": "AnchorPlayground.js", "hideToolbar": true}} ## Mouse over interaction This demo demonstrates how to use the `Popover` component and the mouseover event to achieve popover behavior. {{"demo": "MouseOverPopover.js"}} ## Virtual element The value of the `anchorEl` prop can be a reference to a fake DOM element. You need to provide an object with the following interface: ```ts interface PopoverVirtualElement { nodeType: 1; getBoundingClientRect: () => DOMRect; } ``` Highlight part of the text to see the popover: {{"demo": "VirtualElementPopover.js"}} For more information on the virtual element's properties, see the following resources: - [getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) - [DOMRect](https://drafts.fxtf.org/geometry-1/#domrectreadonly) - [Node types](https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType) :::warning The usage of a virtual element for the Popover component requires the `nodeType` property. This is different from virtual elements used for the [`Popper`](/material-ui/react-popper/#virtual-element) or [`Tooltip`](/material-ui/react-tooltip/#virtual-element) components, both of which don't require the property. ::: ## Complementary projects For more advanced use cases, you might be able to take advantage of: ### material-ui-popup-state ![stars](https://img.shields.io/github/stars/jcoreio/material-ui-popup-state?style=social&label=Star) ![npm downloads](https://img.shields.io/npm/dm/material-ui-popup-state.svg) The package [`material-ui-popup-state`](https://github.com/jcoreio/material-ui-popup-state) that takes care of popover state for you in most cases. {{"demo": "PopoverPopupState.js"}}
2,765
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/PopperPopupState.js
import * as React from 'react'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import Popper from '@mui/material/Popper'; import PopupState, { bindToggle, bindPopper } from 'material-ui-popup-state'; import Fade from '@mui/material/Fade'; import Paper from '@mui/material/Paper'; export default function PopperPopupState() { return ( <PopupState variant="popper" popupId="demo-popup-popper"> {(popupState) => ( <div> <Button variant="contained" {...bindToggle(popupState)}> Toggle Popper </Button> <Popper {...bindPopper(popupState)} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Paper> <Typography sx={{ p: 2 }}>The content of the Popper.</Typography> </Paper> </Fade> )} </Popper> </div> )} </PopupState> ); }
2,766
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/PopperPopupState.tsx
import * as React from 'react'; import Typography from '@mui/material/Typography'; import Button from '@mui/material/Button'; import Popper from '@mui/material/Popper'; import PopupState, { bindToggle, bindPopper } from 'material-ui-popup-state'; import Fade from '@mui/material/Fade'; import Paper from '@mui/material/Paper'; export default function PopperPopupState() { return ( <PopupState variant="popper" popupId="demo-popup-popper"> {(popupState) => ( <div> <Button variant="contained" {...bindToggle(popupState)}> Toggle Popper </Button> <Popper {...bindPopper(popupState)} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Paper> <Typography sx={{ p: 2 }}>The content of the Popper.</Typography> </Paper> </Fade> )} </Popper> </div> )} </PopupState> ); }
2,767
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/PositionedPopper.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; import Typography from '@mui/material/Typography'; import Grid from '@mui/material/Grid'; import Button from '@mui/material/Button'; import Fade from '@mui/material/Fade'; import Paper from '@mui/material/Paper'; export default function PositionedPopper() { const [anchorEl, setAnchorEl] = React.useState(null); const [open, setOpen] = React.useState(false); const [placement, setPlacement] = React.useState(); const handleClick = (newPlacement) => (event) => { setAnchorEl(event.currentTarget); setOpen((prev) => placement !== newPlacement || !prev); setPlacement(newPlacement); }; return ( <Box sx={{ width: 500 }}> <Popper open={open} anchorEl={anchorEl} placement={placement} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Paper> <Typography sx={{ p: 2 }}>The content of the Popper.</Typography> </Paper> </Fade> )} </Popper> <Grid container justifyContent="center"> <Grid item> <Button onClick={handleClick('top-start')}>top-start</Button> <Button onClick={handleClick('top')}>top</Button> <Button onClick={handleClick('top-end')}>top-end</Button> </Grid> </Grid> <Grid container justifyContent="center"> <Grid item xs={6}> <Button onClick={handleClick('left-start')}>left-start</Button> <br /> <Button onClick={handleClick('left')}>left</Button> <br /> <Button onClick={handleClick('left-end')}>left-end</Button> </Grid> <Grid item container xs={6} alignItems="flex-end" direction="column"> <Grid item> <Button onClick={handleClick('right-start')}>right-start</Button> </Grid> <Grid item> <Button onClick={handleClick('right')}>right</Button> </Grid> <Grid item> <Button onClick={handleClick('right-end')}>right-end</Button> </Grid> </Grid> </Grid> <Grid container justifyContent="center"> <Grid item> <Button onClick={handleClick('bottom-start')}>bottom-start</Button> <Button onClick={handleClick('bottom')}>bottom</Button> <Button onClick={handleClick('bottom-end')}>bottom-end</Button> </Grid> </Grid> </Box> ); }
2,768
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/PositionedPopper.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper, { PopperPlacementType } from '@mui/material/Popper'; import Typography from '@mui/material/Typography'; import Grid from '@mui/material/Grid'; import Button from '@mui/material/Button'; import Fade from '@mui/material/Fade'; import Paper from '@mui/material/Paper'; export default function PositionedPopper() { const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null); const [open, setOpen] = React.useState(false); const [placement, setPlacement] = React.useState<PopperPlacementType>(); const handleClick = (newPlacement: PopperPlacementType) => (event: React.MouseEvent<HTMLButtonElement>) => { setAnchorEl(event.currentTarget); setOpen((prev) => placement !== newPlacement || !prev); setPlacement(newPlacement); }; return ( <Box sx={{ width: 500 }}> <Popper open={open} anchorEl={anchorEl} placement={placement} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Paper> <Typography sx={{ p: 2 }}>The content of the Popper.</Typography> </Paper> </Fade> )} </Popper> <Grid container justifyContent="center"> <Grid item> <Button onClick={handleClick('top-start')}>top-start</Button> <Button onClick={handleClick('top')}>top</Button> <Button onClick={handleClick('top-end')}>top-end</Button> </Grid> </Grid> <Grid container justifyContent="center"> <Grid item xs={6}> <Button onClick={handleClick('left-start')}>left-start</Button> <br /> <Button onClick={handleClick('left')}>left</Button> <br /> <Button onClick={handleClick('left-end')}>left-end</Button> </Grid> <Grid item container xs={6} alignItems="flex-end" direction="column"> <Grid item> <Button onClick={handleClick('right-start')}>right-start</Button> </Grid> <Grid item> <Button onClick={handleClick('right')}>right</Button> </Grid> <Grid item> <Button onClick={handleClick('right-end')}>right-end</Button> </Grid> </Grid> </Grid> <Grid container justifyContent="center"> <Grid item> <Button onClick={handleClick('bottom-start')}>bottom-start</Button> <Button onClick={handleClick('bottom')}>bottom</Button> <Button onClick={handleClick('bottom-end')}>bottom-end</Button> </Grid> </Grid> </Box> ); }
2,769
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/ScrollPlayground.js
import * as React from 'react'; import { styled } from '@mui/material/styles'; import FormControlLabel from '@mui/material/FormControlLabel'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import MuiPopper from '@mui/material/Popper'; import Paper from '@mui/material/Paper'; import DialogActions from '@mui/material/DialogActions'; import DialogContent from '@mui/material/DialogContent'; import DialogContentText from '@mui/material/DialogContentText'; import DialogTitle from '@mui/material/DialogTitle'; import Switch from '@mui/material/Switch'; import TextField from '@mui/material/TextField'; import FormGroup from '@mui/material/FormGroup'; import HighlightedCode from 'docs/src/modules/components/HighlightedCode'; const Popper = styled(MuiPopper, { shouldForwardProp: (prop) => prop !== 'arrow', })(({ theme, arrow }) => ({ zIndex: 1, '& > div': { position: 'relative', }, '&[data-popper-placement*="bottom"]': { '& > div': { marginTop: arrow ? 2 : 0, }, '& .MuiPopper-arrow': { top: 0, left: 0, marginTop: '-0.9em', width: '3em', height: '1em', '&::before': { borderWidth: '0 1em 1em 1em', borderColor: `transparent transparent ${theme.palette.background.paper} transparent`, }, }, }, '&[data-popper-placement*="top"]': { '& > div': { marginBottom: arrow ? 2 : 0, }, '& .MuiPopper-arrow': { bottom: 0, left: 0, marginBottom: '-0.9em', width: '3em', height: '1em', '&::before': { borderWidth: '1em 1em 0 1em', borderColor: `${theme.palette.background.paper} transparent transparent transparent`, }, }, }, '&[data-popper-placement*="right"]': { '& > div': { marginLeft: arrow ? 2 : 0, }, '& .MuiPopper-arrow': { left: 0, marginLeft: '-0.9em', height: '3em', width: '1em', '&::before': { borderWidth: '1em 1em 1em 0', borderColor: `transparent ${theme.palette.background.paper} transparent transparent`, }, }, }, '&[data-popper-placement*="left"]': { '& > div': { marginRight: arrow ? 2 : 0, }, '& .MuiPopper-arrow': { right: 0, marginRight: '-0.9em', height: '3em', width: '1em', '&::before': { borderWidth: '1em 0 1em 1em', borderColor: `transparent transparent transparent ${theme.palette.background.paper}`, }, }, }, })); const Arrow = styled('div')({ position: 'absolute', fontSize: 7, width: '3em', height: '3em', '&::before': { content: '""', margin: 'auto', display: 'block', width: 0, height: 0, borderStyle: 'solid', }, }); export default function ScrollPlayground() { const anchorRef = React.useRef(null); const [open, setOpen] = React.useState(false); const [placement, setPlacement] = React.useState('bottom'); const [disablePortal, setDisablePortal] = React.useState(false); const [flip, setFlip] = React.useState({ enabled: true, altBoundary: true, rootBoundary: 'document', }); const [preventOverflow, setPreventOverflow] = React.useState({ enabled: true, altAxis: true, altBoundary: true, tether: true, rootBoundary: 'document', }); const [arrow, setArrow] = React.useState(false); const [arrowRef, setArrowRef] = React.useState(null); const handleClickButton = () => { setOpen((prevOpen) => !prevOpen); }; const centerScroll = (element) => { if (!element) { return; } const container = element.parentElement; container.scrollTop = element.clientHeight / 4; container.scrollLeft = element.clientWidth / 4; }; const jsx = ` <Popper placement="${placement}" disablePortal={${disablePortal}} modifiers={[ { name: 'flip', enabled: ${flip.enabled}, options: { altBoundary: ${flip.altBoundary}, rootBoundary: '${flip.rootBoundary}', padding: 8, }, }, { name: 'preventOverflow', enabled: ${preventOverflow.enabled}, options: { altAxis: ${preventOverflow.altAxis}, altBoundary: ${preventOverflow.altBoundary}, tether: ${preventOverflow.tether}, rootBoundary: '${preventOverflow.rootBoundary}', padding: 8, }, }, { name: 'arrow', enabled: ${arrow}, options: { element: arrowRef, }, }, ]} > `; const id = open ? 'scroll-playground' : null; return ( <Box sx={{ flexGrow: 1 }}> <Box sx={{ height: 400, overflow: 'auto', mb: 3 }}> <Grid sx={{ position: 'relative', width: '230%', bgcolor: 'background.paper', height: '230%', }} container alignItems="center" justifyContent="center" ref={centerScroll} > <div> <Button ref={anchorRef} variant="contained" onClick={handleClickButton} aria-describedby={id} > Toggle Popper </Button> <Typography sx={{ mt: 2, maxWidth: 300 }}> Scroll around this container to experiment with flip and preventOverflow modifiers. </Typography> <Popper id={id} open={open} arrow={arrow} anchorEl={anchorRef.current} placement={placement} disablePortal={disablePortal} modifiers={[ { name: 'flip', enabled: flip.enabled, options: { altBoundary: flip.altBoundary, rootBoundary: flip.rootBoundary, padding: 8, }, }, { name: 'preventOverflow', enabled: preventOverflow.enabled, options: { altAxis: preventOverflow.altAxis, altBoundary: preventOverflow.altBoundary, tether: preventOverflow.tether, rootBoundary: preventOverflow.rootBoundary, padding: 8, }, }, { name: 'arrow', enabled: arrow, options: { element: arrowRef, }, }, ]} > <div> {arrow ? ( <Arrow ref={setArrowRef} className="MuiPopper-arrow" /> ) : null} <Paper sx={{ maxWidth: 400, overflow: 'auto' }}> <DialogTitle>{"Use Google's location service?"}</DialogTitle> <DialogContent> <DialogContentText> Let Google help apps determine location. </DialogContentText> </DialogContent> <DialogActions> <Button onClick={handleClickButton}>Disagree</Button> <Button onClick={handleClickButton}>Agree</Button> </DialogActions> </Paper> </div> </Popper> </div> </Grid> </Box> <Grid container spacing={2}> <Grid container item xs={12}> <Grid item xs={12}> <Typography variant="h6" component="div"> Appearance </Typography> </Grid> <Grid item xs={6}> <TextField margin="dense" sx={{ width: 200 }} label="Placement" select InputLabelProps={{ id: 'scroll-playground-placement-label', }} SelectProps={{ native: true, inputProps: { 'aria-labelledby': 'scroll-playground-placement-label', }, }} value={placement} onChange={(event) => { setPlacement(event.target.value); }} variant="standard" > <option value="top-start">top-start</option> <option value="top">top</option> <option value="top-end">top-end</option> <option value="left-start">left-start</option> <option value="left">left</option> <option value="left-end">left-end</option> <option value="right-start">right-start</option> <option value="right">right</option> <option value="right-end">right-end</option> <option value="bottom-start">bottom-start</option> <option value="bottom">bottom</option> <option value="bottom-end">bottom-end</option> </TextField> </Grid> <Grid item xs={6}> <FormControlLabel control={ <Switch checked={disablePortal} onChange={(event) => { setDisablePortal(event.target.checked); }} value="disablePortal" /> } label="Disable portal" /> <Typography display="block" variant="caption" color="text.secondary"> (the children stay within their parent DOM hierarchy) </Typography> </Grid> </Grid> <Grid item xs={12}> <Typography variant="h6" component="div"> Modifiers (options from Popper.js) </Typography> </Grid> <Grid container item xs={12} spacing={1}> <Grid item xs={6}> <FormGroup> <Typography variant="subtitle1">Prevent Overflow</Typography> <FormControlLabel control={ <Switch checked={preventOverflow.enabled} onChange={(event) => { setPreventOverflow((old) => ({ ...old, enabled: event.target.checked, })); }} value="arrow" /> } label="Enable" /> <FormControlLabel control={ <Switch checked={preventOverflow.altAxis} onChange={(event) => { setPreventOverflow((old) => ({ ...old, altAxis: event.target.checked, })); }} value="alt-axis" /> } label="Alt axis" /> <FormControlLabel control={ <Switch checked={preventOverflow.altBoundary} onChange={(event) => { setPreventOverflow((old) => ({ ...old, altBoundary: event.target.checked, })); }} value="alt-boundary" /> } label="Alt Boundary" /> <FormControlLabel control={ <Switch checked={preventOverflow.tether} onChange={(event) => { setPreventOverflow((old) => ({ ...old, tether: event.target.checked, })); }} value="tether" /> } label="Tether" /> <TextField margin="dense" size="small" label="Root Boundary" select InputLabelProps={{ id: 'scroll-playground-prevent-overflow-root-boundary', }} SelectProps={{ native: true, inputProps: { 'aria-labelledby': 'scroll-playground-prevent-overflow-root-boundary', }, }} value={preventOverflow.rootBoundary} onChange={(event) => { setPreventOverflow((old) => ({ ...old, rootBoundary: event.target.value, })); }} variant="standard" > <option value="document">document</option> <option value="viewport">viewport</option> </TextField> </FormGroup> </Grid> <Grid item xs={6}> <FormGroup> <Typography variant="subtitle1">Flip</Typography> <FormControlLabel control={ <Switch checked={flip.enabled} onChange={(event) => { setFlip((old) => ({ ...old, enabled: event.target.checked, })); }} value="enabled" /> } label="Enable" /> <FormControlLabel control={ <Switch checked={flip.altBoundary} onChange={(event) => { setFlip((old) => ({ ...old, altBoundary: event.target.checked, })); }} value="alt-boundary" /> } label="Alt Boundary" /> <TextField margin="dense" size="small" label="Root Boundary" select InputLabelProps={{ id: 'scroll-playground-flip-root-boundary', }} SelectProps={{ native: true, inputProps: { 'aria-labelledby': 'scroll-playground-flip-root-boundary', }, }} value={flip.rootBoundary} onChange={(event) => { setFlip((old) => ({ ...old, rootBoundary: event.target.value, })); }} variant="standard" > <option value="document">document</option> <option value="viewport">viewport</option> </TextField> </FormGroup> <FormGroup> <Typography variant="subtitle1">Arrow</Typography> <FormControlLabel control={ <Switch checked={arrow} onChange={(event) => { setArrow(event.target.checked); }} value="arrow" /> } label="Enable" /> </FormGroup> </Grid> </Grid> </Grid> <HighlightedCode code={jsx} language="jsx" /> </Box> ); }
2,770
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/SimplePopper.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; export default function SimplePopper() { const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (event) => { setAnchorEl(anchorEl ? null : event.currentTarget); }; const open = Boolean(anchorEl); const id = open ? 'simple-popper' : undefined; return ( <div> <button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Popper> </div> ); }
2,771
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/SimplePopper.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; export default function SimplePopper() { const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); const handleClick = (event: React.MouseEvent<HTMLElement>) => { setAnchorEl(anchorEl ? null : event.currentTarget); }; const open = Boolean(anchorEl); const id = open ? 'simple-popper' : undefined; return ( <div> <button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Popper> </div> ); }
2,772
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/SimplePopper.tsx.preview
<button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Popper>
2,773
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/SpringPopper.js
import * as React from 'react'; import PropTypes from 'prop-types'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; import { useSpring, animated } from '@react-spring/web'; const Fade = React.forwardRef(function Fade(props, ref) { const { in: open, children, onEnter, onExited, ...other } = props; const style = useSpring({ from: { opacity: 0 }, to: { opacity: open ? 1 : 0 }, onStart: () => { if (open && onEnter) { onEnter(); } }, onRest: () => { if (!open && onExited) { onExited(); } }, }); return ( <animated.div ref={ref} style={style} {...other}> {children} </animated.div> ); }); Fade.propTypes = { children: PropTypes.element, in: PropTypes.bool, onEnter: PropTypes.func, onExited: PropTypes.func, }; export default function SpringPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (event) => { setAnchorEl(event.currentTarget); setOpen((previousOpen) => !previousOpen); }; const canBeOpen = open && Boolean(anchorEl); const id = canBeOpen ? 'spring-popper' : undefined; return ( <div> <button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Fade> )} </Popper> </div> ); }
2,774
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/SpringPopper.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; import { useSpring, animated } from '@react-spring/web'; interface FadeProps { children?: React.ReactElement; in?: boolean; onEnter?: () => void; onExited?: () => void; } const Fade = React.forwardRef<HTMLDivElement, FadeProps>(function Fade(props, ref) { const { in: open, children, onEnter, onExited, ...other } = props; const style = useSpring({ from: { opacity: 0 }, to: { opacity: open ? 1 : 0 }, onStart: () => { if (open && onEnter) { onEnter(); } }, onRest: () => { if (!open && onExited) { onExited(); } }, }); return ( <animated.div ref={ref} style={style} {...other}> {children} </animated.div> ); }); export default function SpringPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); const handleClick = (event: React.MouseEvent<HTMLElement>) => { setAnchorEl(event.currentTarget); setOpen((previousOpen) => !previousOpen); }; const canBeOpen = open && Boolean(anchorEl); const id = canBeOpen ? 'spring-popper' : undefined; return ( <div> <button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Fade> )} </Popper> </div> ); }
2,775
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/SpringPopper.tsx.preview
<button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Fade> )} </Popper>
2,776
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/TransitionsPopper.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; import Fade from '@mui/material/Fade'; export default function TransitionsPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const handleClick = (event) => { setAnchorEl(event.currentTarget); setOpen((previousOpen) => !previousOpen); }; const canBeOpen = open && Boolean(anchorEl); const id = canBeOpen ? 'transition-popper' : undefined; return ( <div> <button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Fade> )} </Popper> </div> ); }
2,777
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/TransitionsPopper.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Popper from '@mui/material/Popper'; import Fade from '@mui/material/Fade'; export default function TransitionsPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); const handleClick = (event: React.MouseEvent<HTMLElement>) => { setAnchorEl(event.currentTarget); setOpen((previousOpen) => !previousOpen); }; const canBeOpen = open && Boolean(anchorEl); const id = canBeOpen ? 'transition-popper' : undefined; return ( <div> <button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Fade> )} </Popper> </div> ); }
2,778
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/TransitionsPopper.tsx.preview
<button aria-describedby={id} type="button" onClick={handleClick}> Toggle Popper </button> <Popper id={id} open={open} anchorEl={anchorEl} transition> {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Box sx={{ border: 1, p: 1, bgcolor: 'background.paper' }}> The content of the Popper. </Box> </Fade> )} </Popper>
2,779
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/VirtualElementPopper.js
import * as React from 'react'; import Popper from '@mui/material/Popper'; import Typography from '@mui/material/Typography'; import Fade from '@mui/material/Fade'; import Paper from '@mui/material/Paper'; export default function VirtualElementPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const previousAnchorElPosition = React.useRef(undefined); React.useEffect(() => { if (anchorEl) { if (typeof anchorEl === 'object') { previousAnchorElPosition.current = anchorEl.getBoundingClientRect(); } else { previousAnchorElPosition.current = anchorEl().getBoundingClientRect(); } } }, [anchorEl]); const handleClose = () => { setOpen(false); }; const handleMouseUp = () => { const selection = window.getSelection(); // Resets when the selection has a length of 0 if (!selection || selection.anchorOffset === selection.focusOffset) { handleClose(); return; } const getBoundingClientRect = () => { if (selection.rangeCount === 0 && previousAnchorElPosition.current) { setOpen(false); return previousAnchorElPosition.current; } return selection.getRangeAt(0).getBoundingClientRect(); }; setOpen(true); setAnchorEl({ getBoundingClientRect }); }; const id = open ? 'virtual-element-popper' : undefined; return ( <div onMouseLeave={handleClose}> <Typography aria-describedby={id} onMouseUp={handleMouseUp}> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus, bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan metus vel maximus consequat. Suspendisse lacinia tellus a libero volutpat maximus. </Typography> <Popper id={id} open={open} anchorEl={anchorEl} transition placement="bottom-start" > {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Paper> <Typography sx={{ p: 2 }}>The content of the Popper.</Typography> </Paper> </Fade> )} </Popper> </div> ); }
2,780
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/VirtualElementPopper.tsx
import * as React from 'react'; import Popper, { PopperProps } from '@mui/material/Popper'; import Typography from '@mui/material/Typography'; import Fade from '@mui/material/Fade'; import Paper from '@mui/material/Paper'; export default function VirtualElementPopper() { const [open, setOpen] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState<PopperProps['anchorEl']>(null); const previousAnchorElPosition = React.useRef<DOMRect | undefined>(undefined); React.useEffect(() => { if (anchorEl) { if (typeof anchorEl === 'object') { previousAnchorElPosition.current = anchorEl.getBoundingClientRect(); } else { previousAnchorElPosition.current = anchorEl().getBoundingClientRect(); } } }, [anchorEl]); const handleClose = () => { setOpen(false); }; const handleMouseUp = () => { const selection = window.getSelection(); // Resets when the selection has a length of 0 if (!selection || selection.anchorOffset === selection.focusOffset) { handleClose(); return; } const getBoundingClientRect = () => { if (selection.rangeCount === 0 && previousAnchorElPosition.current) { setOpen(false); return previousAnchorElPosition.current; } return selection.getRangeAt(0).getBoundingClientRect(); }; setOpen(true); setAnchorEl({ getBoundingClientRect }); }; const id = open ? 'virtual-element-popper' : undefined; return ( <div onMouseLeave={handleClose}> <Typography aria-describedby={id} onMouseUp={handleMouseUp}> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus, bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan metus vel maximus consequat. Suspendisse lacinia tellus a libero volutpat maximus. </Typography> <Popper id={id} open={open} anchorEl={anchorEl} transition placement="bottom-start" > {({ TransitionProps }) => ( <Fade {...TransitionProps} timeout={350}> <Paper> <Typography sx={{ p: 2 }}>The content of the Popper.</Typography> </Paper> </Fade> )} </Popper> </div> ); }
2,781
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/popper/popper.md
--- productId: material-ui title: React Popper component components: Popper githubLabel: 'component: Popper' unstyled: /base-ui/react-popper/ --- # Popper <p class="description">A Popper can be used to display some content on top of another. It's an alternative to react-popper.</p> Some important features of the `Popper` component: - πŸ•· Popper relies on the 3rd party library ([Popper.js](https://popper.js.org/)) for perfect positioning. - πŸ’„ It's an alternative API to react-popper. It aims for simplicity. - πŸ“¦ [24.9 kB gzipped](/size-snapshot/). - The children is [`Portal`](/material-ui/react-portal/) to the body of the document to avoid rendering problems. You can disable this behavior with `disablePortal`. - The scroll isn't blocked like with the [`Popover`](/material-ui/react-popover/) component. The placement of the popper updates with the available area in the viewport. - Clicking away does not hide the `Popper` component. If you need this behavior, you can use [`ClickAwayListener`](/material-ui/react-click-away-listener/) - see the example in the [menu documentation section](/material-ui/react-menu/#menulist-composition). - The `anchorEl` is passed as the reference object to create a new `Popper.js` instance. {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} ## Basic popper {{"demo": "SimplePopper.js"}} ## Transitions The open/close state of the popper can be animated with a render prop child and a transition component. This component should respect the following conditions: - Be a direct child descendent of the popper. - Call the `onEnter` callback prop when the enter transition starts. - Call the `onExited` callback prop when the exit transition is completed. These two callbacks allow the popper to unmount the child content when closed and fully transitioned. Popper has built-in support for [react-transition-group](https://github.com/reactjs/react-transition-group). {{"demo": "TransitionsPopper.js"}} Alternatively, you can use [react-spring](https://github.com/pmndrs/react-spring). {{"demo": "SpringPopper.js"}} ## Positioned popper {{"demo": "PositionedPopper.js"}} ## Scroll playground {{"demo": "ScrollPlayground.js", "hideToolbar": true, "bg": true}} ## Virtual element The value of the `anchorEl` prop can be a reference to a fake DOM element. You need to create an object shaped like the [`VirtualElement`](https://popper.js.org/docs/v2/virtual-elements/). Highlight part of the text to see the popper: {{"demo": "VirtualElementPopper.js"}} ## Complementary projects For more advanced use cases you might be able to take advantage of: ### material-ui-popup-state ![stars](https://img.shields.io/github/stars/jcoreio/material-ui-popup-state?style=social&label=Star) ![npm downloads](https://img.shields.io/npm/dm/material-ui-popup-state.svg) The package [`material-ui-popup-state`](https://github.com/jcoreio/material-ui-popup-state) that takes care of popper state for you in most cases. {{"demo": "PopperPopupState.js"}}
2,782
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/portal/SimplePortal.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Portal from '@mui/material/Portal'; export default function SimplePortal() { const [show, setShow] = React.useState(false); const container = React.useRef(null); const handleClick = () => { setShow(!show); }; return ( <div> <button type="button" onClick={handleClick}> {show ? 'Unmount children' : 'Mount children'} </button> <Box sx={{ p: 1, my: 1, border: '1px solid' }}> It looks like I will render here. {show ? ( <Portal container={container.current}> <span>But I actually render here!</span> </Portal> ) : null} </Box> <Box sx={{ p: 1, my: 1, border: '1px solid' }} ref={container} /> </div> ); }
2,783
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/portal/SimplePortal.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Portal from '@mui/material/Portal'; export default function SimplePortal() { const [show, setShow] = React.useState(false); const container = React.useRef(null); const handleClick = () => { setShow(!show); }; return ( <div> <button type="button" onClick={handleClick}> {show ? 'Unmount children' : 'Mount children'} </button> <Box sx={{ p: 1, my: 1, border: '1px solid' }}> It looks like I will render here. {show ? ( <Portal container={container.current}> <span>But I actually render here!</span> </Portal> ) : null} </Box> <Box sx={{ p: 1, my: 1, border: '1px solid' }} ref={container} /> </div> ); }
2,784
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/portal/SimplePortal.tsx.preview
<button type="button" onClick={handleClick}> {show ? 'Unmount children' : 'Mount children'} </button> <Box sx={{ p: 1, my: 1, border: '1px solid' }}> It looks like I will render here. {show ? ( <Portal container={container.current}> <span>But I actually render here!</span> </Portal> ) : null} </Box> <Box sx={{ p: 1, my: 1, border: '1px solid' }} ref={container} />
2,785
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/portal/portal.md
--- productId: material-ui title: React Portal component components: Portal githubLabel: 'component: Portal' --- # Portal <p class="description">The Portal component lets you render its children into a DOM node that exists outside of the Portal's own DOM hierarchy.</p> ## This document has moved :::warning Please refer to the [Portal](/base-ui/react-portal/) component page in the Base UI docs for demos and details on usage. Portal is a part of the standalone [Base UI](/base-ui/) component library. It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version, after `@mui/base` gets a stable release. :::
2,786
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularColor.js
import * as React from 'react'; import Stack from '@mui/material/Stack'; import CircularProgress from '@mui/material/CircularProgress'; export default function CircularColor() { return ( <Stack sx={{ color: 'grey.500' }} spacing={2} direction="row"> <CircularProgress color="secondary" /> <CircularProgress color="success" /> <CircularProgress color="inherit" /> </Stack> ); }
2,787
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularColor.tsx
import * as React from 'react'; import Stack from '@mui/material/Stack'; import CircularProgress from '@mui/material/CircularProgress'; export default function CircularColor() { return ( <Stack sx={{ color: 'grey.500' }} spacing={2} direction="row"> <CircularProgress color="secondary" /> <CircularProgress color="success" /> <CircularProgress color="inherit" /> </Stack> ); }
2,788
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularColor.tsx.preview
<CircularProgress color="secondary" /> <CircularProgress color="success" /> <CircularProgress color="inherit" />
2,789
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularDeterminate.js
import * as React from 'react'; import Stack from '@mui/material/Stack'; import CircularProgress from '@mui/material/CircularProgress'; export default function CircularDeterminate() { const [progress, setProgress] = React.useState(0); React.useEffect(() => { const timer = setInterval(() => { setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10)); }, 800); return () => { clearInterval(timer); }; }, []); return ( <Stack spacing={2} direction="row"> <CircularProgress variant="determinate" value={25} /> <CircularProgress variant="determinate" value={50} /> <CircularProgress variant="determinate" value={75} /> <CircularProgress variant="determinate" value={100} /> <CircularProgress variant="determinate" value={progress} /> </Stack> ); }
2,790
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularDeterminate.tsx
import * as React from 'react'; import Stack from '@mui/material/Stack'; import CircularProgress from '@mui/material/CircularProgress'; export default function CircularDeterminate() { const [progress, setProgress] = React.useState(0); React.useEffect(() => { const timer = setInterval(() => { setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10)); }, 800); return () => { clearInterval(timer); }; }, []); return ( <Stack spacing={2} direction="row"> <CircularProgress variant="determinate" value={25} /> <CircularProgress variant="determinate" value={50} /> <CircularProgress variant="determinate" value={75} /> <CircularProgress variant="determinate" value={100} /> <CircularProgress variant="determinate" value={progress} /> </Stack> ); }
2,791
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularDeterminate.tsx.preview
<CircularProgress variant="determinate" value={25} /> <CircularProgress variant="determinate" value={50} /> <CircularProgress variant="determinate" value={75} /> <CircularProgress variant="determinate" value={100} /> <CircularProgress variant="determinate" value={progress} />
2,792
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularIndeterminate.js
import * as React from 'react'; import CircularProgress from '@mui/material/CircularProgress'; import Box from '@mui/material/Box'; export default function CircularIndeterminate() { return ( <Box sx={{ display: 'flex' }}> <CircularProgress /> </Box> ); }
2,793
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularIndeterminate.tsx
import * as React from 'react'; import CircularProgress from '@mui/material/CircularProgress'; import Box from '@mui/material/Box'; export default function CircularIndeterminate() { return ( <Box sx={{ display: 'flex' }}> <CircularProgress /> </Box> ); }
2,794
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularIndeterminate.tsx.preview
<CircularProgress />
2,795
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularIntegration.js
import * as React from 'react'; import Box from '@mui/material/Box'; import CircularProgress from '@mui/material/CircularProgress'; import { green } from '@mui/material/colors'; import Button from '@mui/material/Button'; import Fab from '@mui/material/Fab'; import CheckIcon from '@mui/icons-material/Check'; import SaveIcon from '@mui/icons-material/Save'; export default function CircularIntegration() { const [loading, setLoading] = React.useState(false); const [success, setSuccess] = React.useState(false); const timer = React.useRef(); const buttonSx = { ...(success && { bgcolor: green[500], '&:hover': { bgcolor: green[700], }, }), }; React.useEffect(() => { return () => { clearTimeout(timer.current); }; }, []); const handleButtonClick = () => { if (!loading) { setSuccess(false); setLoading(true); timer.current = window.setTimeout(() => { setSuccess(true); setLoading(false); }, 2000); } }; return ( <Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ m: 1, position: 'relative' }}> <Fab aria-label="save" color="primary" sx={buttonSx} onClick={handleButtonClick} > {success ? <CheckIcon /> : <SaveIcon />} </Fab> {loading && ( <CircularProgress size={68} sx={{ color: green[500], position: 'absolute', top: -6, left: -6, zIndex: 1, }} /> )} </Box> <Box sx={{ m: 1, position: 'relative' }}> <Button variant="contained" sx={buttonSx} disabled={loading} onClick={handleButtonClick} > Accept terms </Button> {loading && ( <CircularProgress size={24} sx={{ color: green[500], position: 'absolute', top: '50%', left: '50%', marginTop: '-12px', marginLeft: '-12px', }} /> )} </Box> </Box> ); }
2,796
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularIntegration.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import CircularProgress from '@mui/material/CircularProgress'; import { green } from '@mui/material/colors'; import Button from '@mui/material/Button'; import Fab from '@mui/material/Fab'; import CheckIcon from '@mui/icons-material/Check'; import SaveIcon from '@mui/icons-material/Save'; export default function CircularIntegration() { const [loading, setLoading] = React.useState(false); const [success, setSuccess] = React.useState(false); const timer = React.useRef<number>(); const buttonSx = { ...(success && { bgcolor: green[500], '&:hover': { bgcolor: green[700], }, }), }; React.useEffect(() => { return () => { clearTimeout(timer.current); }; }, []); const handleButtonClick = () => { if (!loading) { setSuccess(false); setLoading(true); timer.current = window.setTimeout(() => { setSuccess(true); setLoading(false); }, 2000); } }; return ( <Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ m: 1, position: 'relative' }}> <Fab aria-label="save" color="primary" sx={buttonSx} onClick={handleButtonClick} > {success ? <CheckIcon /> : <SaveIcon />} </Fab> {loading && ( <CircularProgress size={68} sx={{ color: green[500], position: 'absolute', top: -6, left: -6, zIndex: 1, }} /> )} </Box> <Box sx={{ m: 1, position: 'relative' }}> <Button variant="contained" sx={buttonSx} disabled={loading} onClick={handleButtonClick} > Accept terms </Button> {loading && ( <CircularProgress size={24} sx={{ color: green[500], position: 'absolute', top: '50%', left: '50%', marginTop: '-12px', marginLeft: '-12px', }} /> )} </Box> </Box> ); }
2,797
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularUnderLoad.js
import * as React from 'react'; import CircularProgress from '@mui/material/CircularProgress'; export default function CircularUnderLoad() { return <CircularProgress disableShrink />; }
2,798
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/progress/CircularUnderLoad.tsx
import * as React from 'react'; import CircularProgress from '@mui/material/CircularProgress'; export default function CircularUnderLoad() { return <CircularProgress disableShrink />; }
2,799