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/base/components/button/UnstyledButtonIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/tailwind/index.tsx
import * as React from 'react'; import { Button as BaseButton, ButtonProps } from '@mui/base/Button'; import Stack from '@mui/material/Stack'; import clsx from 'clsx'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledButtonsIntroduction() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={`${isDarkMode ? 'dark' : undefined}`}> <Stack spacing={2} direction="row"> <CustomButton>Button</CustomButton> <CustomButton disabled>Disabled</CustomButton> </Stack> </div> ); } const CustomButton = React.forwardRef<HTMLButtonElement, ButtonProps>( (props, ref) => { const { className, ...other } = props; return ( <BaseButton ref={ref} className={clsx( 'cursor-pointer transition text-sm font-sans font-semibold leading-normal bg-violet-500 text-white rounded-lg px-4 py-2 border border-solid border-violet-500 shadow-[0_2px_1px_rgb(45_45_60_/_0.2),_inset_0_1.5px_1px_#a78bfa,_inset_0_-2px_1px_#7c3aed] dark:shadow-[0_2px_1px_rgb(0_0_0/_0.5),_inset_0_1.5px_1px_#a78bfa,_inset_0_-2px_1px_#7c3aed] hover:bg-violet-600 active:bg-violet-700 active:shadow-none active:scale-[0.99] focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none ui-disabled:text-slate-700 ui-disabled:dark:text-slate-200 ui-disabled:bg-slate-200 ui-disabled:dark:bg-slate-700 ui-disabled:cursor-default ui-disabled:shadow-none ui-disabled:dark:shadow-none ui-disabled:hover:bg-slate-200 ui-disabled:hover:dark:bg-slate-700 ui-disabled:border-none', className, )} {...other} /> ); }, );
200
0
petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/tailwind/index.tsx.preview
<Stack spacing={2} direction="row"> <CustomButton>Button</CustomButton> <CustomButton disabled>Disabled</CustomButton> </Stack>
201
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/checkbox/checkbox.md
--- productId: base-ui title: React Checkbox component githubLabel: 'component: checkbox' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/ --- # Checkbox 🚧 <p class="description">Checkboxes give users binary choices when presented with multiple options in a series.</p> :::warning The Base UI Checkbox component isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38036) to see it arrive sooner. :::
202
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/ClickAway.js
import * as React from 'react'; import Box from '@mui/material/Box'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; export default function ClickAway() { const [open, setOpen] = React.useState(false); const handleClick = () => { setOpen((prev) => !prev); }; const handleClickAway = () => { setOpen(false); }; const styles = { position: 'absolute', top: 28, right: 0, left: 0, zIndex: 1, border: '1px solid', p: 1, bgcolor: 'background.paper', }; return ( <ClickAwayListener onClickAway={handleClickAway}> <Box sx={{ position: 'relative' }}> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> ) : null} </Box> </ClickAwayListener> ); }
203
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/ClickAway.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { SxProps } from '@mui/system'; export default function ClickAway() { const [open, setOpen] = React.useState(false); const handleClick = () => { setOpen((prev) => !prev); }; const handleClickAway = () => { setOpen(false); }; const styles: SxProps = { position: 'absolute', top: 28, right: 0, left: 0, zIndex: 1, border: '1px solid', p: 1, bgcolor: 'background.paper', }; return ( <ClickAwayListener onClickAway={handleClickAway}> <Box sx={{ position: 'relative' }}> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> ) : null} </Box> </ClickAwayListener> ); }
204
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/ClickAway.tsx.preview
<ClickAwayListener onClickAway={handleClickAway}> <Box sx={{ position: 'relative' }}> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> ) : null} </Box> </ClickAwayListener>
205
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/LeadingClickAway.js
import * as React from 'react'; import Box from '@mui/material/Box'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; export default function LeadingClickAway() { const [open, setOpen] = React.useState(false); const handleClick = () => { setOpen((prev) => !prev); }; const handleClickAway = () => { setOpen(false); }; const styles = { position: 'absolute', top: 28, right: 0, left: 0, zIndex: 1, border: '1px solid', p: 1, bgcolor: 'background.paper', }; return ( <ClickAwayListener mouseEvent="onMouseDown" touchEvent="onTouchStart" onClickAway={handleClickAway} > <Box sx={{ position: 'relative' }}> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> ) : null} </Box> </ClickAwayListener> ); }
206
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/LeadingClickAway.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { SxProps } from '@mui/system'; export default function LeadingClickAway() { const [open, setOpen] = React.useState(false); const handleClick = () => { setOpen((prev) => !prev); }; const handleClickAway = () => { setOpen(false); }; const styles: SxProps = { position: 'absolute', top: 28, right: 0, left: 0, zIndex: 1, border: '1px solid', p: 1, bgcolor: 'background.paper', }; return ( <ClickAwayListener mouseEvent="onMouseDown" touchEvent="onTouchStart" onClickAway={handleClickAway} > <Box sx={{ position: 'relative' }}> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> ) : null} </Box> </ClickAwayListener> ); }
207
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/LeadingClickAway.tsx.preview
<ClickAwayListener mouseEvent="onMouseDown" touchEvent="onTouchStart" onClickAway={handleClickAway} > <Box sx={{ position: 'relative' }}> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> ) : null} </Box> </ClickAwayListener>
208
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/PortalClickAway.js
import * as React from 'react'; import Box from '@mui/material/Box'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { Portal } from '@mui/base/Portal'; export default function PortalClickAway() { const [open, setOpen] = React.useState(false); const handleClick = () => { setOpen((prev) => !prev); }; const handleClickAway = () => { setOpen(false); }; const styles = { position: 'fixed', width: 200, top: '50%', left: '50%', transform: 'translate(-50%, -50%)', border: '1px solid', p: 1, bgcolor: 'background.paper', }; return ( <ClickAwayListener onClickAway={handleClickAway}> <div> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Portal> <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> </Portal> ) : null} </div> </ClickAwayListener> ); }
209
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/PortalClickAway.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { Portal } from '@mui/base/Portal'; import { SxProps } from '@mui/system'; export default function PortalClickAway() { const [open, setOpen] = React.useState(false); const handleClick = () => { setOpen((prev) => !prev); }; const handleClickAway = () => { setOpen(false); }; const styles: SxProps = { position: 'fixed', width: 200, top: '50%', left: '50%', transform: 'translate(-50%, -50%)', border: '1px solid', p: 1, bgcolor: 'background.paper', }; return ( <ClickAwayListener onClickAway={handleClickAway}> <div> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Portal> <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> </Portal> ) : null} </div> </ClickAwayListener> ); }
210
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/PortalClickAway.tsx.preview
<ClickAwayListener onClickAway={handleClickAway}> <div> <button type="button" onClick={handleClick}> Open menu dropdown </button> {open ? ( <Portal> <Box sx={styles}> Click me, I will stay visible until you click outside. </Box> </Portal> ) : null} </div> </ClickAwayListener>
211
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/click-away-listener/click-away-listener.md
--- productId: base-ui title: Detect click outside React component components: ClickAwayListener githubLabel: 'component: ClickAwayListener' --- # Click-Away Listener <p class="description">The Click-Away Listener component detects when a click event happens outside of its child element.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction Click-Away Listener is a utility component that listens for click events outside of its child. (Note that it only accepts _one_ child element.) This is useful for components like the [Popper](/base-ui/react-popper/) which should close when the user clicks anywhere else in the document. Click-Away Listener also supports the [Portal](/base-ui/react-portal/) component. ## Component ```jsx import { ClickAwayListener } from '@mui/base/ClickAwayListener'; ``` The demo below shows how to hide a menu dropdown when users click anywhere else on the page: {{"demo": "ClickAway.js"}} ### Usage with Portal The following demo uses the [Portal](/base-ui/react-portal/) component to render the dropdown into a new subtree outside of the current DOM hierarchy: {{"demo": "PortalClickAway.js"}} ## Customization ### Listening for leading events By default, the Click-Away Listener component responds to **trailing events**—the _end_ of a click or touch. You can set the component to listen for **leading events** (the start of a click or touch) using the `mouseEvent` and `touchEvent` props, as shown in the following demo: {{"demo": "LeadingClickAway.js"}} :::warning When the component is set to listen for leading events, interactions with the scrollbar are ignored. ::: ## Accessibility By default, Click-Away Listener will add an `onClick` handler to its child. This can result in screen readers announcing that the child is clickable, even though this `onClick` handler has no effect on the child itself. To prevent this behavior, add `role="presentation"` to the child element: ```tsx <ClickAwayListener> <div role="presentation"> <h1>non-interactive heading</h1> </div> </ClickAwayListener> ``` This is also required to fix a known issue in NVDA when using Firefox that prevents the announcement of alert messages—see [mui/material-ui#29080](https://github.com/mui/material-ui/issues/29080) for details.
212
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/drawer/drawer.md
--- productId: base-ui title: React Drawer component githubLabel: 'component: drawer' --- # Drawer 🚧 <p class="description">Navigation drawers (also known as sidebars) provide ergonomic access to different destinations without taking the user out of context.</p> :::warning The Base UI Drawer component isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38181) to see it arrive sooner. :::
213
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/BasicFocusTrap.js
import * as React from 'react'; import Box from '@mui/system/Box'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function BasicFocusTrap() { const [open, setOpen] = React.useState(false); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} </Box> ); }
214
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/BasicFocusTrap.tsx
import * as React from 'react'; import Box from '@mui/system/Box'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function BasicFocusTrap() { const [open, setOpen] = React.useState(false); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} </Box> ); }
215
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/BasicFocusTrap.tsx.preview
<button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )}
216
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/ContainedToggleTrappedFocus.js
import * as React from 'react'; import Stack from '@mui/system/Stack'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function ContainedToggleTrappedFocus() { const [open, setOpen] = React.useState(false); return ( <FocusTrap open={open} disableRestoreFocus disableAutoFocus> <Stack alignItems="center" spacing={2}> <button type="button" onClick={() => setOpen(!open)}> {open ? 'Close' : 'Open'} </button> {open && ( <label> First name: <input type="text" /> </label> )} </Stack> </FocusTrap> ); }
217
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/ContainedToggleTrappedFocus.tsx
import * as React from 'react'; import Stack from '@mui/system/Stack'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function ContainedToggleTrappedFocus() { const [open, setOpen] = React.useState(false); return ( <FocusTrap open={open} disableRestoreFocus disableAutoFocus> <Stack alignItems="center" spacing={2}> <button type="button" onClick={() => setOpen(!open)}> {open ? 'Close' : 'Open'} </button> {open && ( <label> First name: <input type="text" /> </label> )} </Stack> </FocusTrap> ); }
218
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/ContainedToggleTrappedFocus.tsx.preview
<FocusTrap open={open} disableRestoreFocus disableAutoFocus> <Stack alignItems="center" spacing={2}> <button type="button" onClick={() => setOpen(!open)}> {open ? 'Close' : 'Open'} </button> {open && ( <label> First name: <input type="text" /> </label> )} </Stack> </FocusTrap>
219
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/DisableEnforceFocus.js
import * as React from 'react'; import Box from '@mui/system/Box'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function DisableEnforceFocus() { const [open, setOpen] = React.useState(false); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap disableEnforceFocus open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} </Box> ); }
220
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/DisableEnforceFocus.tsx
import * as React from 'react'; import Box from '@mui/system/Box'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function DisableEnforceFocus() { const [open, setOpen] = React.useState(false); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap disableEnforceFocus open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} </Box> ); }
221
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/DisableEnforceFocus.tsx.preview
<button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap disableEnforceFocus open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )}
222
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/LazyFocusTrap.js
import * as React from 'react'; import Box from '@mui/system/Box'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function LazyFocusTrap() { const [open, setOpen] = React.useState(false); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open disableAutoFocus> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} </Box> ); }
223
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/LazyFocusTrap.tsx
import * as React from 'react'; import Box from '@mui/system/Box'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function LazyFocusTrap() { const [open, setOpen] = React.useState(false); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open disableAutoFocus> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} </Box> ); }
224
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/LazyFocusTrap.tsx.preview
<button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open disableAutoFocus> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )}
225
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/PortalFocusTrap.js
import * as React from 'react'; import Box from '@mui/system/Box'; import { Portal } from '@mui/base/Portal'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function PortalFocusTrap() { const [open, setOpen] = React.useState(false); const [container, setContainer] = React.useState(null); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <Portal container={container}> <label> Last name: <input type="text" /> </label> <br /> </Portal> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} <div ref={setContainer} /> </Box> ); }
226
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/PortalFocusTrap.tsx
import * as React from 'react'; import Box from '@mui/system/Box'; import { Portal } from '@mui/base/Portal'; import { FocusTrap } from '@mui/base/FocusTrap'; export default function PortalFocusTrap() { const [open, setOpen] = React.useState(false); const [container, setContainer] = React.useState<HTMLElement | null>(null); return ( <Box sx={{ display: 'flex', alignItems: 'center', flexDirection: 'column', '& [tabindex]:focus': { outline: '1px solid green' }, }} > <button type="button" onClick={() => setOpen(true)}> Open </button> {open && ( <FocusTrap open> <Box tabIndex={-1} sx={{ mt: 1, p: 1 }}> <label> First name: <input type="text" /> </label> <br /> <Portal container={container}> <label> Last name: <input type="text" /> </label> <br /> </Portal> <button type="button" onClick={() => setOpen(false)}> Close </button> </Box> </FocusTrap> )} <div ref={setContainer} /> </Box> ); }
227
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/focus-trap/focus-trap.md
--- productId: base-ui title: React Focus Trap component components: FocusTrap githubLabel: 'component: FocusTrap' --- # Focus Trap <p class="description">The Focus Trap component prevents the user's focus from escaping its children components.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction Focus Trap is a utility component that's useful when implementing an overlay such as a [modal dialog](/base-ui/react-modal/), which should block all interactions outside of it while open. ## Component ```jsx import { FocusTrap } from '@mui/base/FocusTrap'; ``` Focus Trap wraps around the UI elements that should hold the user's focus. For instance, if the focus needs to stay inside of an [Menu](/base-ui/react-menu/), then the component will be structured like this: ```jsx <FocusTrap> <Menu> <MenuItem>{/* item one */}</MenuItem> <MenuItem>{/* item two */}</MenuItem> </Menu> </FocusTrap> ``` The following demo shows a `<button>` that opens a [Box](/material-ui/react-box/) component nested inside of a Focus Trap. As long as the Box is open, the user's keyboard cannot interact with the rest of the app. Press the **Open** button and then use the <kbd class="key">Tab</kbd> key to move the focus—notice that it will not leave the Box: {{"demo": "BasicFocusTrap.js"}} :::error Because the Focus Trap component blocks interaction with the rest of the app by default, the demo above also behaves this way. If you leave the Box open in the demo, you won't be able to click on other buttons in this document. Click **Close** in the demo to resolve this. The next section explains how to change this default behavior. ::: ## Customization ### Disable enforced focus By default, clicks outside of the Focus Trap component are blocked. You can disable this behavior with the `disableEnforceFocus` prop. Compare the following demo with the demo from the [Component](#component) section—notice how that demo prevents you from clicking outside of it, while this one allows it: {{"demo": "DisableEnforceFocus.js"}} ### Lazy activation By default, the Focus Trap component automatically moves the focus to the first of its children when the `open` prop is present. You can disable this behavior and make it lazy with the `disableAutoFocus` prop. When auto focus is disabled—as in the demo below—the component only traps the focus once the user moves it there: {{"demo": "LazyFocusTrap.js"}} ### Escape the focus loop The following demo uses the [Portal](/base-ui/react-portal/) component to render a subset of the Focus Trap children into a new "subtree" outside of the current DOM hierarchy, so they are no longer part of the focus loop: {{"demo": "PortalFocusTrap.js"}} ### Using a toggle inside the trap The most common use-case for the Focus Trap component is to maintain focus within a [Modal](/base-ui/react-modal/) component that is entirely separate from the element that opens the modal. But you can also create a toggle button for the `open` prop of the Focus Trap component that is stored inside of the component itself, as shown in the following demo: {{"demo": "ContainedToggleTrappedFocus.js"}}
228
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/FormControlFunctionChild.js
import * as React from 'react'; import { FormControl } from '@mui/base/FormControl'; import { Input, inputClasses } from '@mui/base/Input'; import { styled } from '@mui/system'; export default function FormControlFunctionChild() { return ( <FormControl defaultValue="" required> {({ filled, focused }) => ( <React.Fragment> <StyledInput className={filled ? 'filled' : ''} /> {filled && !focused && <OkMark>✔</OkMark>} </React.Fragment> )} </FormControl> ); } const StyledInput = styled(Input)( ({ theme }) => ` display: inline-block; .${inputClasses.input} { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; &:hover { border-color: ${blue[400]}; } &:focus { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } } &.filled .${inputClasses.input} { box-shadow: 0 0 2px 2px rgba(125, 200, 0, 0.25); } `, ); const OkMark = styled('span')` margin-left: 8px; margin-top: 10px; position: absolute; color: rgb(125 200 0 / 1); `; const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 600: '#0072E5', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', };
229
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/FormControlFunctionChild.tsx
import * as React from 'react'; import { FormControl, FormControlState } from '@mui/base/FormControl'; import { Input, inputClasses } from '@mui/base/Input'; import { styled } from '@mui/system'; export default function FormControlFunctionChild() { return ( <FormControl defaultValue="" required> {({ filled, focused }: FormControlState) => ( <React.Fragment> <StyledInput className={filled ? 'filled' : ''} /> {filled && !focused && <OkMark>✔</OkMark>} </React.Fragment> )} </FormControl> ); } const StyledInput = styled(Input)( ({ theme }) => ` display: inline-block; .${inputClasses.input} { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; &:hover { border-color: ${blue[400]}; } &:focus { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } } &.filled .${inputClasses.input} { box-shadow: 0 0 2px 2px rgba(125, 200, 0, 0.25); } `, ); const OkMark = styled('span')` margin-left: 8px; margin-top: 10px; position: absolute; color: rgb(125 200 0 / 1); `; const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 600: '#0072E5', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', };
230
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/FormControlFunctionChild.tsx.preview
<FormControl defaultValue="" required> {({ filled, focused }: FormControlState) => ( <React.Fragment> <StyledInput className={filled ? 'filled' : ''} /> {filled && !focused && <OkMark>✔</OkMark>} </React.Fragment> )} </FormControl>
231
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/UseFormControl.js
import * as React from 'react'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; export default function UseFormControl() { return ( <FormControl defaultValue="" required> <CustomInput /> <ControlStateDisplay /> </FormControl> ); } function CustomInput() { const formControlContext = useFormControlContext(); if (formControlContext === undefined) { return null; } const { value, required, onChange, disabled, onFocus, onBlur } = formControlContext; return ( <input value={value} required={required} onChange={onChange} disabled={disabled} onFocus={onFocus} onBlur={onBlur} /> ); } function ControlStateDisplay() { const formControlContext = useFormControlContext(); if (formControlContext === undefined) { return null; } const { filled, focused } = formControlContext; return ( <p> {filled ? 'filled' : 'empty'}&nbsp;|&nbsp; {focused ? 'focused' : 'not focused'} </p> ); }
232
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/UseFormControl.tsx
import * as React from 'react'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; export default function UseFormControl() { return ( <FormControl defaultValue="" required> <CustomInput /> <ControlStateDisplay /> </FormControl> ); } function CustomInput() { const formControlContext = useFormControlContext(); if (formControlContext === undefined) { return null; } const { value, required, onChange, disabled, onFocus, onBlur } = formControlContext; return ( <input value={value as string} required={required} onChange={onChange} disabled={disabled} onFocus={onFocus} onBlur={onBlur} /> ); } function ControlStateDisplay() { const formControlContext = useFormControlContext(); if (formControlContext === undefined) { return null; } const { filled, focused } = formControlContext; return ( <p> {filled ? 'filled' : 'empty'}&nbsp;|&nbsp; {focused ? 'focused' : 'not focused'} </p> ); }
233
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/UseFormControl.tsx.preview
<FormControl defaultValue="" required> <CustomInput /> <ControlStateDisplay /> </FormControl>
234
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/form-control/form-control.md
--- productId: base-ui title: React Form Control component and hook components: FormControl hooks: useFormControlContext githubLabel: 'component: FormControl' --- # Form Control <p class="description">The Form Control component is a utility that lets you associate a form input with auxiliary components, such as labels, error indicators, or helper text.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction Form Control is a utility that wraps an input component with other associated components in order to make the state of the input available to those components. For instance, you may want to show an additional element asking the user to enter a value if the input is empty, or display a warning icon if the entered value is incorrect. ## Component ```jsx import { FormControl } from '@mui/base/FormControl'; ``` Form Control wraps around the elements of a form that need access to the state of an `<input>`. For instance, if the form's **Submit** button needs to change states after the user enters information, then the component will be structured like this: ```jsx <FormControl> <input> <button>Submit</button> </FormControl> ``` The following demo shows how to create and style a form that uses Form Control to wrap the elements of the form. Note that it also uses the `useFormControlContext` hook in order to pass props to the custom Input—see the [Hook](#hook) section below for more details. {{"demo": "BasicFormControl"}} ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component: ```tsx <FormControl<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies for props specific to custom primitive elements: ```tsx <FormControl<'button'> slots={{ root: 'button' }} onClick={() => {}} /> ``` ## Hook ```jsx import { useFormControlContext } from '@mui/base/FormControl'; ``` The `useFormControlContext` hook reads the context provided by Form Control. This hook lets you work with custom input components inside of the Form Control. You can also use it to read the form control's state and react to its changes in a custom component. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). :::info Hooks give you the most room for customization, but require more work to implement. With hooks, you can take full control over how your component is rendered, and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires significantly different [structure](#anatomy). ::: The demo below shows how to integrate this hook with its component counterpart: - `CustomInput` is a wrapper around a native HTML `<input>` that adds Form Control integration. - `ControlStateDisplay` reads the state of the form control and displays it as text. {{"demo": "UseFormControl.js", "defaultCodeOpen": false}} Note that even though Form Control supports both controlled and uncontrolled-style APIs (i.e. it accepts `value` and `defaultValue` props), `useFormControlContext` returns only the controlled `value`. This way, you don't have to implement both in your custom input—Form Control does this for you. :::info - A component is **controlled** when it's managed by its parent using props. - A component is **uncontrolled** when it's managed by its own local state. Learn more about controlled and uncontrolled components in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components). ::: ## Customization :::info The following features can be used with both components and hooks. For the sake of simplicity, demos and code snippets primarily feature components. ::: ### Accessing the form control state You can access the state of the Form Control by providing a function as a child. The state will be provided as a parameter to this function. The following demo shows how to access the state of the Form Control in an Input component nested inside: {{"demo": "FormControlFunctionChild.js"}}
235
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/css/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; import { Input, inputClasses } from '@mui/base/Input'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; export default function BasicFormControl() { return ( <React.Fragment> <FormControl defaultValue="" required> <Label>Name</Label> <Input placeholder="Write your name here" className="CustomInput" /> <HelperText /> </FormControl> <Styles /> </React.Fragment> ); } const Label = React.forwardRef(({ className: classNameProp, children }, ref) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return <p className={clsx('text-sm mb-1', classNameProp)}>{children}</p>; } const { error, required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return ( <p ref={ref} className={clsx( 'text-sm mb-1', classNameProp, error || showRequiredError ? 'invalid text-red-500' : '', )} > {children} {required ? ' *' : ''} </p> ); }); const HelperText = React.forwardRef((props, ref) => { const { className, ...other } = props; const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return null; } const { required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return showRequiredError ? ( <p ref={ref} className={clsx('text-sm', className)} {...other}> This field is required. </p> ) : null; }); HelperText.propTypes = { className: PropTypes.string, }; const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomInput .${inputClasses.input} { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${isDarkMode ? grey[300] : grey[900]}; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]}; } .CustomInput .${inputClasses.input}:hover { border-color: ${cyan[400]}; } .CustomInput .${inputClasses.input}:focus { outline: 0; border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } `} </style> ); }
236
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/css/index.tsx
import * as React from 'react'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; import { Input, inputClasses } from '@mui/base/Input'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; export default function BasicFormControl() { return ( <React.Fragment> <FormControl defaultValue="" required> <Label>Name</Label> <Input placeholder="Write your name here" className="CustomInput" /> <HelperText /> </FormControl> <Styles /> </React.Fragment> ); } const Label = React.forwardRef< HTMLParagraphElement, { className?: string; children?: React.ReactNode } >(({ className: classNameProp, children }, ref) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return <p className={clsx('text-sm mb-1', classNameProp)}>{children}</p>; } const { error, required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return ( <p ref={ref} className={clsx( 'text-sm mb-1', classNameProp, error || showRequiredError ? 'invalid text-red-500' : '', )} > {children} {required ? ' *' : ''} </p> ); }); const HelperText = React.forwardRef<HTMLParagraphElement, { className?: string }>( (props, ref) => { const { className, ...other } = props; const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return null; } const { required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return showRequiredError ? ( <p ref={ref} className={clsx('text-sm', className)} {...other}> This field is required. </p> ) : null; }, ); const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomInput .${inputClasses.input} { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${isDarkMode ? grey[300] : grey[900]}; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]}; } .CustomInput .${inputClasses.input}:hover { border-color: ${cyan[400]}; } .CustomInput .${inputClasses.input}:focus { outline: 0; border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } `} </style> ); }
237
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/css/index.tsx.preview
<React.Fragment> <FormControl defaultValue="" required> <Label>Name</Label> <Input placeholder="Write your name here" className="CustomInput" /> <HelperText /> </FormControl> <Styles /> </React.Fragment>
238
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/system/index.js
import * as React from 'react'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; import { Input, inputClasses } from '@mui/base/Input'; import { styled } from '@mui/system'; import clsx from 'clsx'; export default function BasicFormControl() { return ( <FormControl defaultValue="" required> <Label>Name</Label> <StyledInput placeholder="Write your name here" /> <HelperText /> </FormControl> ); } const StyledInput = styled(Input)( ({ theme }) => ` .${inputClasses.input} { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; &:hover { border-color: ${blue[400]}; } &:focus { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } } `, ); const Label = styled(({ children, className }) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return <p>{children}</p>; } const { error, required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return ( <p className={clsx(className, error || showRequiredError ? 'invalid' : '')}> {children} {required ? ' *' : ''} </p> ); })` font-family: 'IBM Plex Sans', sans-serif; font-size: 0.875rem; margin-bottom: 4px; &.invalid { color: red; } `; const HelperText = styled((props) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return null; } const { required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return showRequiredError ? <p {...props}>This field is required.</p> : null; })` font-family: 'IBM Plex Sans', sans-serif; font-size: 0.875rem; `; const blue = { 100: '#DAECFF', 200: '#b6daff', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', };
239
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/system/index.tsx
import * as React from 'react'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; import { Input, inputClasses } from '@mui/base/Input'; import { styled } from '@mui/system'; import clsx from 'clsx'; export default function BasicFormControl() { return ( <FormControl defaultValue="" required> <Label>Name</Label> <StyledInput placeholder="Write your name here" /> <HelperText /> </FormControl> ); } const StyledInput = styled(Input)( ({ theme }) => ` .${inputClasses.input} { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; &:hover { border-color: ${blue[400]}; } &:focus { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } } `, ); const Label = styled( ({ children, className }: { children?: React.ReactNode; className?: string }) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return <p>{children}</p>; } const { error, required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return ( <p className={clsx(className, error || showRequiredError ? 'invalid' : '')}> {children} {required ? ' *' : ''} </p> ); }, )` font-family: 'IBM Plex Sans', sans-serif; font-size: 0.875rem; margin-bottom: 4px; &.invalid { color: red; } `; const HelperText = styled((props: {}) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return null; } const { required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return showRequiredError ? <p {...props}>This field is required.</p> : null; })` font-family: 'IBM Plex Sans', sans-serif; font-size: 0.875rem; `; const blue = { 100: '#DAECFF', 200: '#b6daff', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', };
240
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/system/index.tsx.preview
<FormControl defaultValue="" required> <Label>Name</Label> <StyledInput placeholder="Write your name here" /> <HelperText /> </FormControl>
241
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function BasicFormControl() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <FormControl defaultValue="" className="font-sans" required> <Label>Name</Label> <Input placeholder="Write your name here" slotProps={{ input: { className: 'w-80 text-sm font-sans font-normal leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', }, }} /> <HelperText /> </FormControl> </div> ); } const Label = React.forwardRef(({ className: classNameProp, children }, ref) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return <p className={clsx('text-sm mb-1', classNameProp)}>{children}</p>; } const { error, required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return ( <p ref={ref} className={clsx( 'text-sm mb-1', classNameProp, error || showRequiredError ? 'invalid text-red-500' : '', )} > {children} {required ? ' *' : ''} </p> ); }); const HelperText = React.forwardRef((props, ref) => { const { className, ...other } = props; const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return null; } const { required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return showRequiredError ? ( <p ref={ref} className={clsx('text-sm', className)} {...other}> This field is required. </p> ) : null; }); HelperText.propTypes = { className: PropTypes.string, };
242
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/tailwind/index.tsx
import * as React from 'react'; import { FormControl, useFormControlContext } from '@mui/base/FormControl'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function BasicFormControl() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <FormControl defaultValue="" className="font-sans" required> <Label>Name</Label> <Input placeholder="Write your name here" slotProps={{ input: { className: 'w-80 text-sm font-sans font-normal leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', }, }} /> <HelperText /> </FormControl> </div> ); } const Label = React.forwardRef< HTMLParagraphElement, { className?: string; children?: React.ReactNode } >(({ className: classNameProp, children }, ref) => { const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return <p className={clsx('text-sm mb-1', classNameProp)}>{children}</p>; } const { error, required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return ( <p ref={ref} className={clsx( 'text-sm mb-1', classNameProp, error || showRequiredError ? 'invalid text-red-500' : '', )} > {children} {required ? ' *' : ''} </p> ); }); const HelperText = React.forwardRef<HTMLParagraphElement, { className?: string }>( (props, ref) => { const { className, ...other } = props; const formControlContext = useFormControlContext(); const [dirty, setDirty] = React.useState(false); React.useEffect(() => { if (formControlContext?.filled) { setDirty(true); } }, [formControlContext]); if (formControlContext === undefined) { return null; } const { required, filled } = formControlContext; const showRequiredError = dirty && required && !filled; return showRequiredError ? ( <p ref={ref} className={clsx('text-sm', className)} {...other}> This field is required. </p> ) : null; }, );
243
0
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl
petrpan-code/mui/material-ui/docs/data/base/components/form-control/BasicFormControl/tailwind/index.tsx.preview
<FormControl defaultValue="" className="font-sans" required> <Label>Name</Label> <Input placeholder="Write your name here" slotProps={{ input: { className: 'w-80 text-sm font-sans font-normal leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', }, }} /> <HelperText /> </FormControl>
244
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputAdornments.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Box, styled } from '@mui/system'; import { Button } from '@mui/base/Button'; import { Input as BaseInput, inputClasses } from '@mui/base/Input'; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; const Input = React.forwardRef(function CustomInput(props, ref) { const { slots, ...other } = props; return ( <BaseInput slots={{ root: InputRoot, input: InputElement, ...slots, }} {...other} ref={ref} /> ); }); Input.propTypes = { /** * The components used for each slot inside the InputBase. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ input: PropTypes.elementType, root: PropTypes.elementType, textarea: PropTypes.elementType, }), }; export default function InputAdornments() { const [values, setValues] = React.useState({ amount: '', password: '', weight: '', weightRange: '', showPassword: false, }); const handleChange = (prop) => (event) => { setValues({ ...values, [prop]: event.target.value }); }; const handleClickShowPassword = () => { setValues({ ...values, showPassword: !values.showPassword, }); }; const handleMouseDownPassword = (event) => { event.preventDefault(); }; return ( <Box sx={{ display: 'flex', flexDirection: { xs: 'column', sm: 'row' }, gap: 2, }} > <Input id="outlined-start-adornment" startAdornment={<InputAdornment>kg</InputAdornment>} /> <Input id="outlined-adornment-password" type={values.showPassword ? 'text' : 'password'} value={values.password} onChange={handleChange('password')} endAdornment={ <InputAdornment> <IconButton size="small" aria-label="toggle password visibility" onClick={handleClickShowPassword} onMouseDown={handleMouseDownPassword} > {values.showPassword ? ( <VisibilityOff fontSize="small" /> ) : ( <Visibility fontSize="small" /> )} </IconButton> </InputAdornment> } /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const InputRoot = styled('div')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 400; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; display: flex; align-items: center; justify-content: center; &.${inputClasses.focused} { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } &:hover { border-color: ${blue[400]}; } // firefox &:focus-visible { outline: 0; } `, ); const InputElement = styled('input')( ({ theme }) => ` font-size: 0.875rem; font-family: inherit; font-weight: 400; line-height: 1.5; flex-grow: 1; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: inherit; border: none; border-radius: inherit; padding: 8px 12px; outline: 0; `, ); const IconButton = styled(Button)( ({ theme }) => ` display: inline-flex; align-items: center; justify-content: center; border: none; background: inherit; cursor: pointer; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[700]}; `, ); const InputAdornment = styled('div')` margin: 8px; display: inline-flex; align-items: center; justify-content: center; `;
245
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputAdornments.tsx
import * as React from 'react'; import { Box, styled } from '@mui/system'; import { Button } from '@mui/base/Button'; import { Input as BaseInput, InputProps, inputClasses } from '@mui/base/Input'; import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; const Input = React.forwardRef(function CustomInput( props: InputProps, ref: React.ForwardedRef<HTMLDivElement>, ) { const { slots, ...other } = props; return ( <BaseInput slots={{ root: InputRoot, input: InputElement, ...slots, }} {...other} ref={ref} /> ); }); interface State { amount: string; password: string; weight: string; weightRange: string; showPassword: boolean; } export default function InputAdornments() { const [values, setValues] = React.useState<State>({ amount: '', password: '', weight: '', weightRange: '', showPassword: false, }); const handleChange = (prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => { setValues({ ...values, [prop]: event.target.value }); }; const handleClickShowPassword = () => { setValues({ ...values, showPassword: !values.showPassword, }); }; const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement>) => { event.preventDefault(); }; return ( <Box sx={{ display: 'flex', flexDirection: { xs: 'column', sm: 'row' }, gap: 2, }} > <Input id="outlined-start-adornment" startAdornment={<InputAdornment>kg</InputAdornment>} /> <Input id="outlined-adornment-password" type={values.showPassword ? 'text' : 'password'} value={values.password} onChange={handleChange('password')} endAdornment={ <InputAdornment> <IconButton size="small" aria-label="toggle password visibility" onClick={handleClickShowPassword} onMouseDown={handleMouseDownPassword} > {values.showPassword ? ( <VisibilityOff fontSize="small" /> ) : ( <Visibility fontSize="small" /> )} </IconButton> </InputAdornment> } /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const InputRoot = styled('div')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 400; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; display: flex; align-items: center; justify-content: center; &.${inputClasses.focused} { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } &:hover { border-color: ${blue[400]}; } // firefox &:focus-visible { outline: 0; } `, ); const InputElement = styled('input')( ({ theme }) => ` font-size: 0.875rem; font-family: inherit; font-weight: 400; line-height: 1.5; flex-grow: 1; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: inherit; border: none; border-radius: inherit; padding: 8px 12px; outline: 0; `, ); const IconButton = styled(Button)( ({ theme }) => ` display: inline-flex; align-items: center; justify-content: center; border: none; background: inherit; cursor: pointer; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[700]}; `, ); const InputAdornment = styled('div')` margin: 8px; display: inline-flex; align-items: center; justify-content: center; `;
246
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputMultiline.js
import * as React from 'react'; import { Input as BaseInput } from '@mui/base/Input'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput(props, ref) { return ( <BaseInput slots={{ root: RootDiv, input: 'input', textarea: TextareaElement, }} {...props} ref={ref} /> ); }); export default function InputMultiline() { return <Input aria-label="Demo input" multiline placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const RootDiv = styled('div')` display: flex; max-width: 100%; `; const TextareaElement = styled('textarea', { shouldForwardProp: (prop) => !['ownerState', 'minRows', 'maxRows'].includes(prop.toString()), })( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5rem; padding: 8px 12px; border-radius: 8px 8px 0 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
247
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputMultiline.tsx
import * as React from 'react'; import { Input as BaseInput, InputProps } from '@mui/base/Input'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput( props: InputProps, ref: React.ForwardedRef<HTMLDivElement>, ) { return ( <BaseInput slots={{ root: RootDiv, input: 'input', textarea: TextareaElement, }} {...props} ref={ref} /> ); }); export default function InputMultiline() { return <Input aria-label="Demo input" multiline placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const RootDiv = styled('div')` display: flex; max-width: 100%; `; const TextareaElement = styled('textarea', { shouldForwardProp: (prop) => !['ownerState', 'minRows', 'maxRows'].includes(prop.toString()), })( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5rem; padding: 8px 12px; border-radius: 8px 8px 0 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
248
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputMultiline.tsx.preview
<Input aria-label="Demo input" multiline placeholder="Type something…" />
249
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputMultilineAutosize.js
import * as React from 'react'; import { Input as BaseInput } from '@mui/base/Input'; import { TextareaAutosize } from '@mui/base/TextareaAutosize'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput(props, ref) { return ( <BaseInput slots={{ root: RootDiv, input: 'input', textarea: TextareaElement, }} {...props} ref={ref} /> ); }); export default function InputMultilineAutosize() { return <Input aria-label="Demo input" multiline placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const RootDiv = styled('div')` display: flex; max-width: 100%; `; const TextareaElement = styled(TextareaAutosize)( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5rem; padding: 8px 12px; border-radius: 8px 8px 0 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
250
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputMultilineAutosize.tsx
import * as React from 'react'; import { Input as BaseInput, InputProps } from '@mui/base/Input'; import { TextareaAutosize } from '@mui/base/TextareaAutosize'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput( props: InputProps, ref: React.ForwardedRef<HTMLDivElement>, ) { return ( <BaseInput slots={{ root: RootDiv, input: 'input', textarea: TextareaElement, }} {...props} ref={ref} /> ); }); export default function InputMultilineAutosize() { return <Input aria-label="Demo input" multiline placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const RootDiv = styled('div')` display: flex; max-width: 100%; `; const TextareaElement = styled(TextareaAutosize)( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5rem; padding: 8px 12px; border-radius: 8px 8px 0 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
251
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/InputMultilineAutosize.tsx.preview
<Input aria-label="Demo input" multiline placeholder="Type something…" />
252
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/UseInput.js
import * as React from 'react'; import { useInput } from '@mui/base/useInput'; import { styled } from '@mui/system'; import { unstable_useForkRef as useForkRef } from '@mui/utils'; const CustomInput = React.forwardRef(function CustomInput(props, ref) { const { getRootProps, getInputProps } = useInput(props); const inputProps = getInputProps(); // Make sure that both the forwarded ref and the ref returned from the getInputProps are applied on the input element inputProps.ref = useForkRef(inputProps.ref, ref); return ( <div {...getRootProps()}> <StyledInputElement {...props} {...inputProps} /> </div> ); }); export default function UseInput() { return <CustomInput aria-label="Demo input" placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const StyledInputElement = styled('input')( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
253
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/UseInput.tsx
import * as React from 'react'; import { useInput } from '@mui/base/useInput'; import { styled } from '@mui/system'; import { unstable_useForkRef as useForkRef } from '@mui/utils'; const CustomInput = React.forwardRef(function CustomInput( props: React.InputHTMLAttributes<HTMLInputElement>, ref: React.ForwardedRef<HTMLInputElement>, ) { const { getRootProps, getInputProps } = useInput(props); const inputProps = getInputProps(); // Make sure that both the forwarded ref and the ref returned from the getInputProps are applied on the input element inputProps.ref = useForkRef(inputProps.ref, ref); return ( <div {...getRootProps()}> <StyledInputElement {...props} {...inputProps} /> </div> ); }); export default function UseInput() { return <CustomInput aria-label="Demo input" placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const StyledInputElement = styled('input')( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
254
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/UseInput.tsx.preview
<CustomInput aria-label="Demo input" placeholder="Type something…" />
255
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/input/input.md
--- productId: base-ui title: React Input component and hook components: Input hooks: useInput githubLabel: 'component: input' --- # Input <p class="description">The Input component provides users with a field to enter and edit text.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction An input is a UI element that accepts text data from the user. The Input component replaces the native HTML `<input>` tag, and offers expanded customization and accessibility features. It can also be transformed into a `<textarea>` as needed. {{"demo": "UnstyledInputIntroduction", "defaultCodeOpen": false, "bg": "gradient"}} ## Component ```jsx import { Input } from '@mui/base/Input'; ``` Input behaves similarly to the native HTML `<input>`, except that it's nested inside of a root `<div>`—see [Anatomy](#anatomy) for details. The following demo shows how to create and style an input component, including `placeholder` text: {{"demo": "UnstyledInputBasic", "defaultCodeOpen": false}} ### Anatomy The Input component is composed of a root `<div>` slot that houses one interior `<input>` slot: ```html <div class="MuiInput-root"> <input class="MuiInput-input" /> </div> ``` ### Custom structure Use the `slots` prop to override the root or any other interior slot: ```jsx <Input slots={{ root: 'aside', input: CustomInput }} /> ``` :::info The `slots` prop is available on all non-utility Base components. See [Overriding component structure](/base-ui/guides/overriding-component-structure/) for full details. ::: Use the `slotProps` prop to pass custom props to internal slots. The following code snippet applies a CSS class called `my-input` to the input slot: ```jsx <Input slotProps={{ input: { className: 'my-input' } }} /> ``` ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component: ```tsx <Input<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies for props specific to custom primitive elements: ```tsx <Input<'textarea'> slots={{ root: 'textarea' }} rows={2} /> ``` ## Hook ```js import { useInput } from '@mui/base/useInput'; ``` The `useInput` hook lets you apply the functionality of an Input to a fully custom component. It returns props to be placed on the custom component, along with fields representing the component's internal state. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). :::info Hooks give you the most room for customization, but require more work to implement. With hooks, you can take full control over how your component is rendered, and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires significantly different [structure](#anatomy). ::: The demo below shows how to use the `useInput` hook to create a custom input component that receives all the necessary props: {{"demo": "UseInput.js", "defaultCodeOpen": false}} ## Customization :::info The following features can be used with both components and hooks. For the sake of simplicity, demos and code snippets primarily feature components. ::: ### Adornments You can use the `startAdornment` and `endAdornment` props to add a prefix, suffix, or an action to an Input. Common use cases of adornments include: - when an Input receives a specific unit of measure (like weight or currency) - when an icon button toggles hiding/showing a password The following demo shows examples of both of these use cases: {{"demo": "InputAdornments.js", "defaultCodeOpen": false}} ### Multiline The `multiline` prop transforms the `<input>` field into a `<textarea>` element, as shown below: {{"demo": "InputMultiline.js"}} If you want the `<textarea>` to grow with the content, you can use the [Textarea Autosize](/base-ui/react-textarea-autosize/) component within the input. When using Textarea Autosize, the height of the `<textarea>` element dynamically matches its content unless you set the `rows` prop. To set minimum and maximum sizes, add the `minRows` and `maxRows` props. The following demo shows how to insert a Textarea Autosize component into an Input so that its height grows with the length of the content: {{"demo": "InputMultilineAutosize.js"}}
256
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/css/index.js
import * as React from 'react'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; export default function UnstyledInputBasic() { return ( <React.Fragment> <Input slotProps={{ input: { className: 'CustomInput' } }} aria-label="Demo input" placeholder="Type something…" /> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomInput { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${isDarkMode ? grey[300] : grey[900]}; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]}; &:hover { border-color: ${cyan[400]}; } &:focus { border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } &:focus-visible { outline: 0; } } `} </style> ); }
257
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/css/index.tsx
import * as React from 'react'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; export default function UnstyledInputBasic() { return ( <React.Fragment> <Input slotProps={{ input: { className: 'CustomInput' } }} aria-label="Demo input" placeholder="Type something…" /> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomInput { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${isDarkMode ? grey[300] : grey[900]}; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]}; &:hover { border-color: ${cyan[400]}; } &:focus { border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } &:focus-visible { outline: 0; } } `} </style> ); }
258
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/css/index.tsx.preview
<React.Fragment> <Input slotProps={{ input: { className: 'CustomInput' } }} aria-label="Demo input" placeholder="Type something…" /> <Styles /> </React.Fragment>
259
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/system/index.js
import * as React from 'react'; import { Input as BaseInput } from '@mui/base/Input'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput(props, ref) { return <BaseInput slots={{ input: InputElement }} {...props} ref={ref} />; }); export default function UnstyledInputBasic() { return <Input aria-label="Demo input" placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const InputElement = styled('input')( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
260
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/system/index.tsx
import * as React from 'react'; import { Input as BaseInput, InputProps } from '@mui/base/Input'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput( props: InputProps, ref: React.ForwardedRef<HTMLDivElement>, ) { return <BaseInput slots={{ input: InputElement }} {...props} ref={ref} />; }); export default function UnstyledInputBasic() { return <Input aria-label="Demo input" placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#80BFFF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const InputElement = styled('input')( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
261
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/system/index.tsx.preview
<Input aria-label="Demo input" placeholder="Type something…" />
262
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/tailwind/index.js
import * as React from 'react'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledInputBasic() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <Input className={isDarkMode ? 'dark' : ''} slotProps={{ input: { className: 'w-80 text-sm font-sans font-normal leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', }, }} aria-label="Demo input" placeholder="Type something…" /> ); }
263
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/tailwind/index.tsx
import * as React from 'react'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledInputBasic() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <Input className={isDarkMode ? 'dark' : ''} slotProps={{ input: { className: 'w-80 text-sm font-sans font-normal leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', }, }} aria-label="Demo input" placeholder="Type something…" /> ); }
264
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputBasic/tailwind/index.tsx.preview
<Input className={isDarkMode ? 'dark' : ''} slotProps={{ input: { className: 'w-80 text-sm font-sans font-normal leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', }, }} aria-label="Demo input" placeholder="Type something…" />
265
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/css/index.js
import * as React from 'react'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; export default function UnstyledInputIntroduction() { return ( <React.Fragment> <Input slotProps={{ input: { className: 'CustomInputIntroduction' } }} aria-label="Demo input" placeholder="Type something…" /> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomInputIntroduction { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${isDarkMode ? grey[300] : grey[900]}; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${cyan[400]}; } &:focus { border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } &:focus-visible { outline: 0; } } `} </style> ); }
266
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/css/index.tsx
import * as React from 'react'; import { Input } from '@mui/base/Input'; import { useTheme } from '@mui/system'; export default function UnstyledInputIntroduction() { return ( <React.Fragment> <Input slotProps={{ input: { className: 'CustomInputIntroduction' } }} aria-label="Demo input" placeholder="Type something…" /> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomInputIntroduction { width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${isDarkMode ? grey[300] : grey[900]}; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${cyan[400]}; } &:focus { border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } &:focus-visible { outline: 0; } } `} </style> ); }
267
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/css/index.tsx.preview
<React.Fragment> <Input slotProps={{ input: { className: 'CustomInputIntroduction' } }} aria-label="Demo input" placeholder="Type something…" /> <Styles /> </React.Fragment>
268
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/system/index.js
import * as React from 'react'; import { Input as BaseInput } from '@mui/base/Input'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput(props, ref) { return <BaseInput slots={{ input: InputElement }} {...props} ref={ref} />; }); export default function UnstyledInputIntroduction() { return <Input aria-label="Demo input" placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#b6daff', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const InputElement = styled('input')( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
269
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/system/index.tsx
import * as React from 'react'; import { Input as BaseInput } from '@mui/base/Input'; import { styled } from '@mui/system'; const Input = React.forwardRef(function CustomInput( props: React.InputHTMLAttributes<HTMLInputElement>, ref: React.ForwardedRef<HTMLDivElement>, ) { return <BaseInput slots={{ input: InputElement }} {...props} ref={ref} />; }); export default function UnstyledInputIntroduction() { return <Input aria-label="Demo input" placeholder="Type something…" />; } const blue = { 100: '#DAECFF', 200: '#b6daff', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const InputElement = styled('input')( ({ theme }) => ` width: 320px; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; font-weight: 400; line-height: 1.5; padding: 8px 12px; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; &:hover { border-color: ${blue[400]}; } &:focus { border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } // firefox &:focus-visible { outline: 0; } `, );
270
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/system/index.tsx.preview
<Input aria-label="Demo input" placeholder="Type something…" />
271
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Input as BaseInput } from '@mui/base/Input'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; export default function UnstyledInputIntroduction() { return <Input aria-label="Demo input" placeholder="Type something…" />; } function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); const Input = React.forwardRef((props, ref) => { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseInput ref={ref} {...props} className={clsx(isDarkMode ? 'dark' : '', props.className)} slotProps={{ ...props.slotProps, input: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.input, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'w-80 text-sm font-normal font-sans leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple dark:outline-purple-600 focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-600 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', resolvedSlotProps?.className, ), }; }, }} /> ); }); Input.propTypes = { /** * Class name applied to the root element. */ className: PropTypes.string, /** * The props used for each slot inside the Input. * @default {} */ slotProps: PropTypes.shape({ input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), }), };
272
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/tailwind/index.tsx
import * as React from 'react'; import { Input as BaseInput, InputProps } from '@mui/base/Input'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; export default function UnstyledInputIntroduction() { return <Input aria-label="Demo input" placeholder="Type something…" />; } function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } const resolveSlotProps = (fn: any, args: any) => typeof fn === 'function' ? fn(args) : fn; const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseInput ref={ref} {...props} className={clsx(isDarkMode ? 'dark' : '', props.className)} slotProps={{ ...props.slotProps, input: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.input, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'w-80 text-sm font-normal font-sans leading-5 px-3 py-2 rounded-lg shadow-md shadow-slate-100 dark:shadow-slate-900 focus:shadow-outline-purple dark:focus:shadow-outline-purple dark:outline-purple-600 focus:shadow-lg border border-solid border-slate-300 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-600 dark:border-slate-600 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 focus-visible:outline-0', resolvedSlotProps?.className, ), }; }, }} /> ); });
273
0
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/input/UnstyledInputIntroduction/tailwind/index.tsx.preview
<Input aria-label="Demo input" placeholder="Type something…" />
274
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/menu/UseMenu.js
import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { useMenu, MenuProvider } from '@mui/base/useMenu'; import { useMenuItem } from '@mui/base/useMenuItem'; import { Popper } from '@mui/base/Popper'; import { useDropdown, DropdownContext } from '@mui/base/useDropdown'; import { useMenuButton } from '@mui/base/useMenuButton'; import { useTheme } from '@mui/system'; const Menu = React.forwardRef(function Menu(props, ref) { const { children, ...other } = props; const { open, triggerElement, contextValue, getListboxProps } = useMenu({ listboxRef: ref, }); return ( <Popper open={open} anchorEl={triggerElement}> <ul className="menu-root" {...other} {...getListboxProps()}> <MenuProvider value={contextValue}>{children}</MenuProvider> </ul> </Popper> ); }); Menu.propTypes = { children: PropTypes.node, }; const MenuItem = React.forwardRef(function MenuItem(props, ref) { const { children, onClick, ...other } = props; const { getRootProps, disabled, focusVisible } = useMenuItem({ rootRef: ref }); const classes = { 'focus-visible': focusVisible, 'menu-item': true, disabled, }; return ( <li {...other} {...getRootProps({ onClick: onClick ?? (() => {}) })} className={clsx(classes)} > {children} </li> ); }); MenuItem.propTypes = { children: PropTypes.node, onClick: PropTypes.func, }; const MenuButton = React.forwardRef(function MenuButton(props, forwardedRef) { const { getRootProps: getButtonProps } = useMenuButton({ rootRef: forwardedRef }); return ( <button type="button" {...props} {...getButtonProps()} className="button" /> ); }); export default function UseMenu() { const { contextValue: dropdownContextValue } = useDropdown(); const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <React.Fragment> <DropdownContext.Provider value={dropdownContextValue}> <MenuButton>Theme</MenuButton> <Menu id="hooks-menu"> <MenuItem onClick={createHandleMenuClick('OS Default')}> OS default </MenuItem> <MenuItem onClick={createHandleMenuClick('Light')}>Light</MenuItem> <MenuItem onClick={createHandleMenuClick('Dark')}>Dark</MenuItem> </Menu> </DropdownContext.Provider> <Styles /> </React.Fragment> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .menu-root { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 5px; margin: 10px 0; min-width: 200px; background: #fff; border: 1px solid ${grey[200]}; border-radius: 0.75em; color: ${grey[900]}; overflow: auto; outline: 0px; box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.05); } .mode-dark .menu-root { background: ${grey[900]}; border-color: ${grey[700]}; color: ${grey[300]}; box-shadow: 0px 2px 6px rgba(0,0,0, 0.50); } .menu-item { list-style: none; padding: 8px; border-radius: 0.45em; cursor: default; user-select: none; } .menu-item:last-of-type { border-bottom: none; } .menu-item.focus-visible { background-color: ${grey[100]}; color: ${grey[900]}; outline: 0; } .mode-dark .menu-item.focus-visible { background-color: ${grey[800]}; color: ${grey[300]}; } .menu-item.disabled { color: ${grey[400]}; } .mode-dark .menu-item.disabled { color: ${grey[700]}; } .menu-item:hover:not(.disabled) { background-color: ${grey[100]}; color: ${grey[900]}; } .mode-dark .menu-item:hover:not(.disabled){ background-color: ${grey[800]}; color: ${grey[300]}; } .button { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? blue[300] : blue[200]}; outline: none; } } `}</style> ); }
275
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/menu/UseMenu.tsx
import * as React from 'react'; import clsx from 'clsx'; import { useMenu, MenuProvider } from '@mui/base/useMenu'; import { useMenuItem } from '@mui/base/useMenuItem'; import { Popper } from '@mui/base/Popper'; import { useDropdown, DropdownContext } from '@mui/base/useDropdown'; import { useMenuButton } from '@mui/base/useMenuButton'; import { useTheme } from '@mui/system'; const Menu = React.forwardRef(function Menu( props: React.ComponentPropsWithoutRef<'ul'>, ref: React.Ref<HTMLUListElement>, ) { const { children, ...other } = props; const { open, triggerElement, contextValue, getListboxProps } = useMenu({ listboxRef: ref, }); return ( <Popper open={open} anchorEl={triggerElement}> <ul className="menu-root" {...other} {...getListboxProps()}> <MenuProvider value={contextValue}>{children}</MenuProvider> </ul> </Popper> ); }); const MenuItem = React.forwardRef(function MenuItem( props: React.ComponentPropsWithoutRef<'li'>, ref: React.Ref<any>, ) { const { children, onClick, ...other } = props; const { getRootProps, disabled, focusVisible } = useMenuItem({ rootRef: ref }); const classes = { 'focus-visible': focusVisible, 'menu-item': true, disabled, }; return ( <li {...other} {...getRootProps({ onClick: onClick ?? (() => {}) })} className={clsx(classes)} > {children} </li> ); }); const MenuButton = React.forwardRef(function MenuButton( props: React.PropsWithChildren<{}>, forwardedRef: React.ForwardedRef<HTMLButtonElement>, ) { const { getRootProps: getButtonProps } = useMenuButton({ rootRef: forwardedRef }); return ( <button type="button" {...props} {...getButtonProps()} className="button" /> ); }); export default function UseMenu() { const { contextValue: dropdownContextValue } = useDropdown(); const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <React.Fragment> <DropdownContext.Provider value={dropdownContextValue}> <MenuButton>Theme</MenuButton> <Menu id="hooks-menu"> <MenuItem onClick={createHandleMenuClick('OS Default')}> OS default </MenuItem> <MenuItem onClick={createHandleMenuClick('Light')}>Light</MenuItem> <MenuItem onClick={createHandleMenuClick('Dark')}>Dark</MenuItem> </Menu> </DropdownContext.Provider> <Styles /> </React.Fragment> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .menu-root { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 5px; margin: 10px 0; min-width: 200px; background: #fff; border: 1px solid ${grey[200]}; border-radius: 0.75em; color: ${grey[900]}; overflow: auto; outline: 0px; box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.05); } .mode-dark .menu-root { background: ${grey[900]}; border-color: ${grey[700]}; color: ${grey[300]}; box-shadow: 0px 2px 6px rgba(0,0,0, 0.50); } .menu-item { list-style: none; padding: 8px; border-radius: 0.45em; cursor: default; user-select: none; } .menu-item:last-of-type { border-bottom: none; } .menu-item.focus-visible { background-color: ${grey[100]}; color: ${grey[900]}; outline: 0; } .mode-dark .menu-item.focus-visible { background-color: ${grey[800]}; color: ${grey[300]}; } .menu-item.disabled { color: ${grey[400]}; } .mode-dark .menu-item.disabled { color: ${grey[700]}; } .menu-item:hover:not(.disabled) { background-color: ${grey[100]}; color: ${grey[900]}; } .mode-dark .menu-item:hover:not(.disabled){ background-color: ${grey[800]}; color: ${grey[300]}; } .button { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? blue[300] : blue[200]}; outline: none; } } `}</style> ); }
276
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/menu/UseMenu.tsx.preview
<React.Fragment> <DropdownContext.Provider value={dropdownContextValue}> <MenuButton>Theme</MenuButton> <Menu id="hooks-menu"> <MenuItem onClick={createHandleMenuClick('OS Default')}> OS default </MenuItem> <MenuItem onClick={createHandleMenuClick('Light')}>Light</MenuItem> <MenuItem onClick={createHandleMenuClick('Dark')}>Dark</MenuItem> </Menu> </DropdownContext.Provider> <Styles /> </React.Fragment>
277
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/menu/WrappedMenuItems.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Dropdown } from '@mui/base/Dropdown'; import { Menu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { styled } from '@mui/system'; function MenuSection({ children, label }) { return ( <MenuSectionRoot role="group"> <MenuSectionLabel>{label}</MenuSectionLabel> <ul>{children}</ul> </MenuSectionRoot> ); } MenuSection.propTypes = { children: PropTypes.node, label: PropTypes.string.isRequired, }; export default function WrappedMenuItems() { const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton>Options</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuSection label="Navigation"> <MenuItem onClick={createHandleMenuClick('Back')}>Back</MenuItem> <MenuItem onClick={createHandleMenuClick('Forward')} disabled> Forward </MenuItem> <MenuItem onClick={createHandleMenuClick('Refresh')}>Refresh</MenuItem> </MenuSection> <MenuSection label="Page"> <MenuItem onClick={createHandleMenuClick('Save as...')}> Save as... </MenuItem> <MenuItem onClick={createHandleMenuClick('Print...')}>Print...</MenuItem> </MenuSection> <MenuSection label="View"> <MenuItem onClick={createHandleMenuClick('Zoom in')}>Zoom in</MenuItem> <MenuItem onClick={createHandleMenuClick('Zoom out')}>Zoom out</MenuItem> </MenuSection> <li className="helper">Current zoom level: 100%</li> </Menu> </Dropdown> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; z-index: 1; `, ); const MenuItem = styled(BaseMenuItem)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; &:last-of-type { border-bottom: none; } &.${menuItemClasses.focusVisible} { outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${menuItemClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${menuItemClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const MenuButton = styled(BaseMenuButton)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const MenuSectionRoot = styled('li')` list-style: none; & > ul { padding-left: 1em; } `; const MenuSectionLabel = styled('span')` display: block; padding: 10px 0 5px 10px; font-size: 0.75em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05rem; color: ${grey[600]}; `;
278
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/menu/WrappedMenuItems.tsx
import * as React from 'react'; import { Dropdown } from '@mui/base/Dropdown'; import { Menu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { styled } from '@mui/system'; function MenuSection({ children, label }: MenuSectionProps) { return ( <MenuSectionRoot role="group"> <MenuSectionLabel>{label}</MenuSectionLabel> <ul>{children}</ul> </MenuSectionRoot> ); } export default function WrappedMenuItems() { const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton>Options</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuSection label="Navigation"> <MenuItem onClick={createHandleMenuClick('Back')}>Back</MenuItem> <MenuItem onClick={createHandleMenuClick('Forward')} disabled> Forward </MenuItem> <MenuItem onClick={createHandleMenuClick('Refresh')}>Refresh</MenuItem> </MenuSection> <MenuSection label="Page"> <MenuItem onClick={createHandleMenuClick('Save as...')}> Save as... </MenuItem> <MenuItem onClick={createHandleMenuClick('Print...')}>Print...</MenuItem> </MenuSection> <MenuSection label="View"> <MenuItem onClick={createHandleMenuClick('Zoom in')}>Zoom in</MenuItem> <MenuItem onClick={createHandleMenuClick('Zoom out')}>Zoom out</MenuItem> </MenuSection> <li className="helper">Current zoom level: 100%</li> </Menu> </Dropdown> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; z-index: 1; `, ); const MenuItem = styled(BaseMenuItem)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; &:last-of-type { border-bottom: none; } &.${menuItemClasses.focusVisible} { outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${menuItemClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${menuItemClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const MenuButton = styled(BaseMenuButton)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); interface MenuSectionProps { children: React.ReactNode; label: string; } const MenuSectionRoot = styled('li')` list-style: none; & > ul { padding-left: 1em; } `; const MenuSectionLabel = styled('span')` display: block; padding: 10px 0 5px 10px; font-size: 0.75em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05rem; color: ${grey[600]}; `;
279
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/menu/menu.md
--- productId: base-ui title: React Menu components and hooks components: Menu, MenuItem, MenuButton, Dropdown hooks: useMenu, useMenuItem, useMenuButton, useDropdown, useMenuItemContextStabilizer githubLabel: 'component: menu' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/ --- # Menu <p class="description">The Dropdown Menu components provide end users with a list of options on temporary surfaces.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction The Base UI Dropdown Menu is implemented using a collection of related components: - Dropdown - The outermost container that houses all Menu components. - Menu Button - The button that toggles the visibility of the Menu. - Menu - The unordered list of Menu Items. - Menu Item - The individual list items of the Menu. {{"demo": "MenuIntroduction", "defaultCodeOpen": false, "bg": "gradient"}} ## Components ```jsx import { Dropdown } from '@mui/base/Dropdown'; import { MenuButton } from '@mui/base/MenuButton'; import { Menu } from '@mui/base/Menu'; import { MenuItem } from '@mui/base/MenuItem'; ``` The demo below shows how to create and style a Dropdown Menu. Click **Dashboard** to view the menu. Note that it uses the built-in [Popper](/base-ui/react-popper/) component to visually break out of its parent container: {{"demo": "MenuSimple"}} The `<Dropdown />` should be the outermost component—all other Menu-related components must be placed as its children (but not necessarily as direct ones). If you need to control the open state of the Menu or react to its changes, place `open`/`onOpenChange` props on the `<Dropdown />`. The `<Dropdown />` must only contain one `<MenuButton />` and one `<Menu />`. It will wire them together, so that pressing the Button will open the Menu. It also takes care of assigning proper accessibility attributes, so the Dropdown Menu can be used with assistive technologies or a keyboard. The `<Menu />` hosts `<MenuItem />` components can be wrapped in arbitrary tags and components, as well as grouped together. Clicking on a Menu Item closes its associated Menu. ### Anatomy - The `<Dropdown />` does not render any HTML element—it only provides the context that links a Menu Button to a Menu, so you don't have to. - The `<MenuButton />` renders a `<button>`. - The `<Menu />` component renders a `<div>` with a `<ul>` nested inside. - The `<MenuItem />` renders a `<li>`. ```html <button class="MuiMenuButton-root">Click me</button> <div class="MuiMenu-root"> <ul class="MuiMenu-listbox"> <li class="MuiMenuItem-root">List item</li> </ul> </div> ``` ### Custom structure Use the `slots` prop to override the slots on any component except the `<Dropdown />` (since it renders no HTML): ```jsx <Menu slots={{ listbox: 'ol' }} /> ``` :::info The `slots` prop is available on all non-utility Base components. See [Overriding component structure](/base-ui/guides/overriding-component-structure/) for complete details. ::: Use the `slotProps` prop to pass custom props to internal slots. The following code snippet applies a CSS class called `my-listbox` to the listbox slot on the Menu: ```jsx <Menu slotProps={{ listbox: { className: 'my-listbox' } }} /> ``` ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component: ```tsx <Menu<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies to props specific to custom primitive elements: ```tsx <Menu<'ol'> slots={{ root: 'ol' }} start={5} /> ``` ## Hooks ```jsx import { useDropdown } from '@mui/base/useDropdown'; import { useMenuButton } from '@mui/base/useMenuButton'; import { useMenu } from '@mui/base/useMenu'; import { useMenuItem } from '@mui/base/useMenuItem'; ``` The Dropdown Menu hooks let you apply the functionality of the Dropdown Menu suite to fully custom components. They return props to be placed on the custom components, along with fields representing the components' internal states. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). :::info Hooks give you the most room for customization but require more work to implement. With hooks, you can take complete control over how your component is rendered and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires a significantly different [structure](#anatomy). ::: The following demo shows how to build a Dropdown Menu using hooks: {{"demo": "UseMenu.js"}} Components and their corresponding hooks work interchangeably with one another—for example, you can create a Menu component that contains custom menu items built with the `useMenuItem` hook. ### Performance The `useMenuItem` hook listens to changes in a context that is set up by the parent Menu component. This context changes every time an item is highlighted. Usually, it shouldn't be a problem, however, when your menu has hundreds of items, you may notice it's not very responsive, as every item is rerendered whenever highlight changes. To improve performance by preventing menu items from rendering unnecessarily, you can create a component that wraps the menu item. Inside this component, call `useMenuItemContextStabilizer` and create a ListContext with the value from the hook's result: ```tsx const StableMenuItem = React.forwardRef(function StableMenuItem( props: MenuItemProps, ref: React.ForwardedRef<Element>, ) { const { contextValue, id } = useMenuItemContextStabilizer(props.id); return ( <ListContext.Provider value={contextValue}> <MenuItem {...props} id={id} ref={ref} /> </ListContext.Provider> ); }); ``` The `useMenuItemContextStabilizer` hook ensures that the context value changes only when the state of the menu item is updated. ## Customization :::info The following features can be used with both components and hooks. For the sake of simplicity, demos and code snippets primarily feature components. ::: ### Wrapping Menu Items Menu Item components don't have to be direct children of a Menu component. You can wrap them in any component needed to achieve the desired appearance. In addition to Menu Item components, the Menu component can also contain non-interactive children, such as helper text. The following demo shows an example of a Dropdown Menu with Items grouped under non-interactive headers, along with helper text that displays the **Current zoom level**: {{"demo": "WrappedMenuItems.js"}}
280
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/css/index.js
import * as React from 'react'; import { Menu } from '@mui/base/Menu'; import { MenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { MenuButton } from '@mui/base/MenuButton'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; export default function MenuIntroduction() { const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton className="TriggerButtonIntroduction">My account</MenuButton> <Menu className="CustomMenuIntroduction" slotProps={{ listbox: { className: 'CustomMenuIntroduction--listbox' }, }} > <MenuItem className="CustomMenuIntroduction--item" onClick={createHandleMenuClick('Profile')} > Profile </MenuItem> <MenuItem className="CustomMenuIntroduction--item" onClick={createHandleMenuClick('Language settings')} > Language settings </MenuItem> <MenuItem className="CustomMenuIntroduction--item" onClick={createHandleMenuClick('Log out')} > Log out </MenuItem> </Menu> <Styles /> </Dropdown> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomMenuIntroduction--listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 30px ${isDarkMode ? grey[900] : grey[200]}; } .CustomMenuIntroduction--item { list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; } .CustomMenuIntroduction--item:last-of-type { border-bottom: none; } .CustomMenuIntroduction--item.${menuItemClasses.focusVisible} { outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]}; background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .CustomMenuIntroduction--item.${menuItemClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } .CustomMenuIntroduction--item:hover:not(.${menuItemClasses.disabled}) { background-color: ${isDarkMode ? cyan[800] : cyan[50]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .TriggerButtonIntroduction { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomMenuIntroduction { z-index: 1; } `}</style> ); }
281
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/css/index.tsx
import * as React from 'react'; import { Menu } from '@mui/base/Menu'; import { MenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { MenuButton } from '@mui/base/MenuButton'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; export default function MenuIntroduction() { const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton className="TriggerButtonIntroduction">My account</MenuButton> <Menu className="CustomMenuIntroduction" slotProps={{ listbox: { className: 'CustomMenuIntroduction--listbox' }, }} > <MenuItem className="CustomMenuIntroduction--item" onClick={createHandleMenuClick('Profile')} > Profile </MenuItem> <MenuItem className="CustomMenuIntroduction--item" onClick={createHandleMenuClick('Language settings')} > Language settings </MenuItem> <MenuItem className="CustomMenuIntroduction--item" onClick={createHandleMenuClick('Log out')} > Log out </MenuItem> </Menu> <Styles /> </Dropdown> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomMenuIntroduction--listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 30px ${isDarkMode ? grey[900] : grey[200]}; } .CustomMenuIntroduction--item { list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; } .CustomMenuIntroduction--item:last-of-type { border-bottom: none; } .CustomMenuIntroduction--item.${menuItemClasses.focusVisible} { outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]}; background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .CustomMenuIntroduction--item.${menuItemClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } .CustomMenuIntroduction--item:hover:not(.${menuItemClasses.disabled}) { background-color: ${isDarkMode ? cyan[800] : cyan[50]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .TriggerButtonIntroduction { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomMenuIntroduction { z-index: 1; } `}</style> ); }
282
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/system/index.js
import * as React from 'react'; import { Dropdown } from '@mui/base/Dropdown'; import { Menu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { styled } from '@mui/system'; export default function MenuIntroduction() { const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton>My account</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 4px 30px ${theme.palette.mode === 'dark' ? grey[900] : grey[200]}; z-index: 1; `, ); const MenuItem = styled(BaseMenuItem)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; &:last-of-type { border-bottom: none; } &.${menuItemClasses.focusVisible} { outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${menuItemClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${menuItemClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } `, ); const MenuButton = styled(BaseMenuButton)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
283
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/system/index.tsx
import * as React from 'react'; import { Dropdown } from '@mui/base/Dropdown'; import { Menu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { styled } from '@mui/system'; export default function MenuIntroduction() { const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton>My account</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 4px 30px ${theme.palette.mode === 'dark' ? grey[900] : grey[200]}; z-index: 1; `, ); const MenuItem = styled(BaseMenuItem)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; &:last-of-type { border-bottom: none; } &.${menuItemClasses.focusVisible} { outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${menuItemClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${menuItemClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } `, ); const MenuButton = styled(BaseMenuButton)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
284
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/system/index.tsx.preview
<Dropdown> <MenuButton>My account</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown>
285
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { Menu as BaseMenu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem } from '@mui/base/MenuItem'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function MenuIntroduction() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <Dropdown> <MenuButton>My account</MenuButton> <Menu> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> </div> ); } const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); const Menu = React.forwardRef((props, ref) => { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseMenu ref={ref} {...props} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'text-sm box-border font-sans p-1.5 my-3 mx-0 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 min-w-listbox shadow-md dark:shadow-slate-900', resolvedSlotProps?.className, ), }; }, }} /> ); }); Menu.propTypes = { /** * The props used for each slot inside the Menu. * @default {} */ slotProps: PropTypes.shape({ listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), }), }; const MenuButton = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( <BaseMenuButton ref={ref} className={clsx( 'cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm', className, )} {...other} /> ); }); MenuButton.propTypes = { /** * Class name applied to the root element. */ className: PropTypes.string, }; const MenuItem = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( <BaseMenuItem ref={ref} className={clsx( 'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300', className, )} {...other} /> ); }); MenuItem.propTypes = { className: PropTypes.string, };
286
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/tailwind/index.tsx
import * as React from 'react'; import clsx from 'clsx'; import { Menu as BaseMenu, MenuProps } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton, MenuButtonProps } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, MenuItemProps } from '@mui/base/MenuItem'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function MenuIntroduction() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <Dropdown> <MenuButton>My account</MenuButton> <Menu> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> </div> ); } const resolveSlotProps = (fn: any, args: any) => typeof fn === 'function' ? fn(args) : fn; const Menu = React.forwardRef<HTMLDivElement, MenuProps>((props, ref) => { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseMenu ref={ref} {...props} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'text-sm box-border font-sans p-1.5 my-3 mx-0 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 min-w-listbox shadow-md dark:shadow-slate-900', resolvedSlotProps?.className, ), }; }, }} /> ); }); const MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>( (props, ref) => { const { className, ...other } = props; return ( <BaseMenuButton ref={ref} className={clsx( 'cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm', className, )} {...other} /> ); }, ); const MenuItem = React.forwardRef<HTMLLIElement, MenuItemProps>((props, ref) => { const { className, ...other } = props; return ( <BaseMenuItem ref={ref} className={clsx( 'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300', className, )} {...other} /> ); });
287
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuIntroduction/tailwind/index.tsx.preview
<Dropdown> <MenuButton>My account</MenuButton> <Menu> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown>
288
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/css/index.js
import * as React from 'react'; import { Menu } from '@mui/base/Menu'; import { MenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { MenuButton } from '@mui/base/MenuButton'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; export default function MenuSimple() { const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton className="TriggerButtonSimple">My account</MenuButton> <Menu className="CustomMenuSimple" slotProps={{ listbox: { className: 'CustomMenuSimple--listbox' }, }} > <MenuItem className="CustomMenuSimple--item" onClick={createHandleMenuClick('Profile')} > Profile </MenuItem> <MenuItem className="CustomMenuSimple--item" onClick={createHandleMenuClick('Language settings')} > Language settings </MenuItem> <MenuItem className="CustomMenuSimple--item" onClick={createHandleMenuClick('Log out')} > Log out </MenuItem> </Menu> <Styles /> </Dropdown> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomMenuSimple--listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; } .CustomMenuSimple--item { list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; } .CustomMenuSimple--item:last-of-type { border-bottom: none; } .CustomMenuSimple--item.${menuItemClasses.focusVisible} { outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]}; background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .CustomMenuSimple--item.${menuItemClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } .CustomMenuSimple--item:hover:not(.${menuItemClasses.disabled}) { background-color: ${isDarkMode ? cyan[800] : cyan[50]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .TriggerButtonSimple { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomMenuSimple { z-index: 1; } `}</style> ); }
289
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/css/index.tsx
import * as React from 'react'; import { Menu } from '@mui/base/Menu'; import { MenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { MenuButton } from '@mui/base/MenuButton'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; export default function MenuSimple() { const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton className="TriggerButtonSimple">My account</MenuButton> <Menu className="CustomMenuSimple" slotProps={{ listbox: { className: 'CustomMenuSimple--listbox' }, }} > <MenuItem className="CustomMenuSimple--item" onClick={createHandleMenuClick('Profile')} > Profile </MenuItem> <MenuItem className="CustomMenuSimple--item" onClick={createHandleMenuClick('Language settings')} > Language settings </MenuItem> <MenuItem className="CustomMenuSimple--item" onClick={createHandleMenuClick('Log out')} > Log out </MenuItem> </Menu> <Styles /> </Dropdown> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomMenuSimple--listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; } .CustomMenuSimple--item { list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; } .CustomMenuSimple--item:last-of-type { border-bottom: none; } .CustomMenuSimple--item.${menuItemClasses.focusVisible} { outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]}; background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .CustomMenuSimple--item.${menuItemClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } .CustomMenuSimple--item:hover:not(.${menuItemClasses.disabled}) { background-color: ${isDarkMode ? cyan[800] : cyan[50]}; color: ${isDarkMode ? grey[300] : grey[900]}; } .TriggerButtonSimple { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomMenuSimple { z-index: 1; } `}</style> ); }
290
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/system/index.js
import * as React from 'react'; import { Dropdown } from '@mui/base/Dropdown'; import { Menu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { styled } from '@mui/system'; export default function MenuSimple() { const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton>My account</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; z-index: 1; `, ); const MenuItem = styled(BaseMenuItem)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; &:last-of-type { border-bottom: none; } &.${menuItemClasses.focusVisible} { outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${menuItemClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${menuItemClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } `, ); const MenuButton = styled(BaseMenuButton)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
291
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/system/index.tsx
import * as React from 'react'; import { Dropdown } from '@mui/base/Dropdown'; import { Menu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem'; import { styled } from '@mui/system'; export default function MenuSimple() { const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <Dropdown> <MenuButton>My account</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E6', 700: '#0059B3', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 200px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; z-index: 1; `, ); const MenuItem = styled(BaseMenuItem)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; user-select: none; &:last-of-type { border-bottom: none; } &.${menuItemClasses.focusVisible} { outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${menuItemClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${menuItemClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } `, ); const MenuButton = styled(BaseMenuButton)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
292
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/system/index.tsx.preview
<Dropdown> <MenuButton>My account</MenuButton> <Menu slots={{ listbox: Listbox }}> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown>
293
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { Menu as BaseMenu } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem } from '@mui/base/MenuItem'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function MenuSimple() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); const createHandleMenuClick = (menuItem) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <Dropdown> <MenuButton>My account</MenuButton> <Menu> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> </div> ); } const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); const Menu = React.forwardRef((props, ref) => { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseMenu ref={ref} {...props} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'text-sm box-border font-sans p-1.5 my-3 mx-0 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 min-w-listbox shadow-md dark:shadow-slate-900', resolvedSlotProps?.className, ), }; }, }} /> ); }); Menu.propTypes = { /** * The props used for each slot inside the Menu. * @default {} */ slotProps: PropTypes.shape({ listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), }), }; const MenuButton = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( <BaseMenuButton ref={ref} className={clsx( 'cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm active:shadow-none', className, )} {...other} /> ); }); MenuButton.propTypes = { /** * Class name applied to the root element. */ className: PropTypes.string, }; const MenuItem = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( <BaseMenuItem ref={ref} className={clsx( 'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300', className, )} {...other} /> ); }); MenuItem.propTypes = { className: PropTypes.string, };
294
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/tailwind/index.tsx
import * as React from 'react'; import clsx from 'clsx'; import { Menu as BaseMenu, MenuProps } from '@mui/base/Menu'; import { MenuButton as BaseMenuButton, MenuButtonProps } from '@mui/base/MenuButton'; import { MenuItem as BaseMenuItem, MenuItemProps } from '@mui/base/MenuItem'; import { Dropdown } from '@mui/base/Dropdown'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function MenuSimple() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); const createHandleMenuClick = (menuItem: string) => { return () => { console.log(`Clicked on ${menuItem}`); }; }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <Dropdown> <MenuButton>My account</MenuButton> <Menu> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown> </div> ); } const resolveSlotProps = (fn: any, args: any) => typeof fn === 'function' ? fn(args) : fn; const Menu = React.forwardRef<HTMLDivElement, MenuProps>((props, ref) => { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseMenu ref={ref} {...props} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'text-sm box-border font-sans p-1.5 my-3 mx-0 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 min-w-listbox shadow-md dark:shadow-slate-900', resolvedSlotProps?.className, ), }; }, }} /> ); }); const MenuButton = React.forwardRef<HTMLButtonElement, MenuButtonProps>( (props, ref) => { const { className, ...other } = props; return ( <BaseMenuButton ref={ref} className={clsx( 'cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm active:shadow-none', className, )} {...other} /> ); }, ); const MenuItem = React.forwardRef<HTMLLIElement, MenuItemProps>((props, ref) => { const { className, ...other } = props; return ( <BaseMenuItem ref={ref} className={clsx( 'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300', className, )} {...other} /> ); });
295
0
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple
petrpan-code/mui/material-ui/docs/data/base/components/menu/MenuSimple/tailwind/index.tsx.preview
<Dropdown> <MenuButton>My account</MenuButton> <Menu> <MenuItem onClick={createHandleMenuClick('Profile')}>Profile</MenuItem> <MenuItem onClick={createHandleMenuClick('Language settings')}> Language settings </MenuItem> <MenuItem onClick={createHandleMenuClick('Log out')}>Log out</MenuItem> </Menu> </Dropdown>
296
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/modal/KeepMountedModal.js
import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { styled, Box } from '@mui/system'; import { Modal as BaseModal } from '@mui/base/Modal'; export default function KeepMountedModal() { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); return ( <div> <TriggerButton type="button" onClick={handleOpen}> Open modal </TriggerButton> <Modal aria-labelledby="keep-mounted-modal-title" aria-describedby="keep-mounted-modal-description" open={open} onClose={handleClose} slots={{ backdrop: StyledBackdrop }} keepMounted > <ModalContent sx={style}> <h2 id="keep-mounted-modal-title" className="modal-title"> Text in a modal </h2> <p id="keep-mounted-modal-description" className="modal-description"> Aliquid amet deserunt earum! </p> </ModalContent> </Modal> </div> ); } const Backdrop = React.forwardRef((props, ref) => { const { open, className, ...other } = props; return ( <div className={clsx({ 'MuiBackdrop-open': open }, className)} ref={ref} {...other} /> ); }); Backdrop.propTypes = { className: PropTypes.string.isRequired, open: PropTypes.bool, }; const blue = { 200: '#99CCFF', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Modal = styled(BaseModal)(` position: fixed; z-index: 1300; right: 0; bottom: 0; top: 0; left: 0; display: flex; align-items: center; justify-content: center; &.MuiModal-hidden { visibility: hidden; } `); const StyledBackdrop = styled(Backdrop)` z-index: -1; position: fixed; inset: 0; background-color: rgb(0 0 0 / 0.5); -webkit-tap-highlight-color: transparent; `; const style = { width: 400, }; const ModalContent = styled(Box)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; display: flex; flex-direction: column; gap: 8px; overflow: hidden; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 4px 12px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.20)' }; padding: 16px; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; & .modal-title { margin: 0; line-height: 1.5rem; } & .modal-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]}; } `, ); const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
297
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/modal/KeepMountedModal.tsx
import * as React from 'react'; import clsx from 'clsx'; import { styled, Box } from '@mui/system'; import { Modal as BaseModal } from '@mui/base/Modal'; export default function KeepMountedModal() { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); return ( <div> <TriggerButton type="button" onClick={handleOpen}> Open modal </TriggerButton> <Modal aria-labelledby="keep-mounted-modal-title" aria-describedby="keep-mounted-modal-description" open={open} onClose={handleClose} slots={{ backdrop: StyledBackdrop }} keepMounted > <ModalContent sx={style}> <h2 id="keep-mounted-modal-title" className="modal-title"> Text in a modal </h2> <p id="keep-mounted-modal-description" className="modal-description"> Aliquid amet deserunt earum! </p> </ModalContent> </Modal> </div> ); } const Backdrop = React.forwardRef< HTMLDivElement, { open?: boolean; className: string } >((props, ref) => { const { open, className, ...other } = props; return ( <div className={clsx({ 'MuiBackdrop-open': open }, className)} ref={ref} {...other} /> ); }); const blue = { 200: '#99CCFF', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Modal = styled(BaseModal)(` position: fixed; z-index: 1300; right: 0; bottom: 0; top: 0; left: 0; display: flex; align-items: center; justify-content: center; &.MuiModal-hidden { visibility: hidden; } `); const StyledBackdrop = styled(Backdrop)` z-index: -1; position: fixed; inset: 0; background-color: rgb(0 0 0 / 0.5); -webkit-tap-highlight-color: transparent; `; const style = { width: 400, }; const ModalContent = styled(Box)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; display: flex; flex-direction: column; gap: 8px; overflow: hidden; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 4px 12px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.20)' }; padding: 16px; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; & .modal-title { margin: 0; line-height: 1.5rem; } & .modal-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]}; } `, ); const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
298
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/modal/ModalUnstyled.js
import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { styled, Box } from '@mui/system'; import { Modal as BaseModal } from '@mui/base/Modal'; export default function ModalUnstyled() { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); return ( <div> <TriggerButton type="button" onClick={handleOpen}> Open modal </TriggerButton> <Modal aria-labelledby="unstyled-modal-title" aria-describedby="unstyled-modal-description" open={open} onClose={handleClose} slots={{ backdrop: StyledBackdrop }} > <ModalContent sx={style}> <h2 id="unstyled-modal-title" className="modal-title"> Text in a modal </h2> <p id="unstyled-modal-description" className="modal-description"> Aliquid amet deserunt earum! </p> </ModalContent> </Modal> </div> ); } const Backdrop = React.forwardRef((props, ref) => { const { open, className, ...other } = props; return ( <div className={clsx({ 'MuiBackdrop-open': open }, className)} ref={ref} {...other} /> ); }); Backdrop.propTypes = { className: PropTypes.string.isRequired, open: PropTypes.bool, }; const blue = { 200: '#99CCFF', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Modal = styled(BaseModal)` position: fixed; z-index: 1300; inset: 0; display: flex; align-items: center; justify-content: center; `; const StyledBackdrop = styled(Backdrop)` z-index: -1; position: fixed; inset: 0; background-color: rgb(0 0 0 / 0.5); -webkit-tap-highlight-color: transparent; `; const style = { width: 400, }; const ModalContent = styled(Box)( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; display: flex; flex-direction: column; gap: 8px; overflow: hidden; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: 0px 4px 12px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.20)' }; padding: 16px; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; & .modal-title { margin: 0; line-height: 1.5rem; } & .modal-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]}; } `, ); const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, );
299