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 | petrpan-code/mui/material-ui/docs/data/base/components/modal/ModalUnstyled.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 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<
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;
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;
}
`,
);
| 300 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/NestedModal.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';
import { Button } from '@mui/base/Button';
export default function NestedModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="parent-modal-title"
aria-describedby="parent-modal-description"
slots={{ backdrop: StyledBackdrop }}
>
<ModalContent sx={style}>
<h2 id="parent-modal-title" className="modal-title">
Text in a modal
</h2>
<p id="parent-modal-description" className="modal-description">
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</p>
<ChildModal />
</ModalContent>
</Modal>
</div>
);
}
function ChildModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<React.Fragment>
<ModalButton onClick={handleOpen}>Open Child Modal</ModalButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="child-modal-title"
aria-describedby="child-modal-description"
slots={{ backdrop: StyledBackdrop }}
>
<ModalContent sx={[style, { width: '240px' }]}>
<h2 id="child-modal-title" className="modal-title">
Text in a child modal
</h2>
<p id="child-modal-description" className="modal-description">
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</p>
<ModalButton onClick={handleClose}>Close Child Modal</ModalButton>
</ModalContent>
</Modal>
</React.Fragment>
);
}
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 = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
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;
}
`,
);
const ModalButton = styled(Button)(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&:disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 301 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/NestedModal.tsx | import * as React from 'react';
import clsx from 'clsx';
import { styled, Box } from '@mui/system';
import { Modal as BaseModal } from '@mui/base/Modal';
import { Button } from '@mui/base/Button';
export default function NestedModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="parent-modal-title"
aria-describedby="parent-modal-description"
slots={{ backdrop: StyledBackdrop }}
>
<ModalContent sx={style}>
<h2 id="parent-modal-title" className="modal-title">
Text in a modal
</h2>
<p id="parent-modal-description" className="modal-description">
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</p>
<ChildModal />
</ModalContent>
</Modal>
</div>
);
}
function ChildModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<React.Fragment>
<ModalButton onClick={handleOpen}>Open Child Modal</ModalButton>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="child-modal-title"
aria-describedby="child-modal-description"
slots={{ backdrop: StyledBackdrop }}
>
<ModalContent sx={[style, { width: '240px' }]}>
<h2 id="child-modal-title" className="modal-title">
Text in a child modal
</h2>
<p id="child-modal-description" className="modal-description">
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</p>
<ModalButton onClick={handleClose}>Close Child Modal</ModalButton>
</ModalContent>
</Modal>
</React.Fragment>
);
}
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;
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 = {
position: 'absolute' as 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
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;
}
`,
);
const ModalButton = styled(Button)(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&:disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 302 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/ServerModal.js | import * as React from 'react';
import { Modal as BaseModal } from '@mui/base/Modal';
import { Box, styled } from '@mui/system';
export default function ServerModal() {
const rootRef = React.useRef(null);
return (
<Box
sx={{
height: 300,
flexGrow: 1,
minWidth: 300,
transform: 'translateZ(0)',
// The position fixed scoping doesn't work in IE11.
// Disable this demo to preserve the others.
'@media all and (-ms-high-contrast: none)': {
display: 'none',
},
}}
ref={rootRef}
>
<Modal
disablePortal
disableEnforceFocus
disableAutoFocus
open
aria-labelledby="server-modal-title"
aria-describedby="server-modal-description"
container={() => rootRef.current}
>
<ModalContent sx={style}>
<h2 id="server-modal-title" className="modal-title">
Server-side modal
</h2>
<span id="server-modal-description" className="modal-description">
If you disable JavaScript, you will still see me.
</span>
</ModalContent>
</Modal>
</Box>
);
}
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;
&.MuiModal-hidden {
visibility: hidden;
}
`;
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]};
}
`,
);
| 303 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/ServerModal.tsx | import * as React from 'react';
import { Modal as BaseModal } from '@mui/base/Modal';
import { Box, styled } from '@mui/system';
export default function ServerModal() {
const rootRef = React.useRef<HTMLDivElement>(null);
return (
<Box
sx={{
height: 300,
flexGrow: 1,
minWidth: 300,
transform: 'translateZ(0)',
// The position fixed scoping doesn't work in IE11.
// Disable this demo to preserve the others.
'@media all and (-ms-high-contrast: none)': {
display: 'none',
},
}}
ref={rootRef}
>
<Modal
disablePortal
disableEnforceFocus
disableAutoFocus
open
aria-labelledby="server-modal-title"
aria-describedby="server-modal-description"
container={() => rootRef.current}
>
<ModalContent sx={style}>
<h2 id="server-modal-title" className="modal-title">
Server-side modal
</h2>
<span id="server-modal-description" className="modal-description">
If you disable JavaScript, you will still see me.
</span>
</ModalContent>
</Modal>
</Box>
);
}
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;
&.MuiModal-hidden {
visibility: hidden;
}
`;
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]};
}
`,
);
| 304 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/SpringModal.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Box, styled } from '@mui/system';
import { Modal as BaseModal } from '@mui/base/Modal';
import { Button } from '@mui/base/Button';
import { useSpring, animated } from '@react-spring/web';
export default function SpringModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
aria-labelledby="spring-modal-title"
aria-describedby="spring-modal-description"
open={open}
onClose={handleClose}
closeAfterTransition
slots={{ backdrop: StyledBackdrop }}
>
<Fade in={open}>
<ModalContent sx={style}>
<h2 id="spring-modal-title" className="modal-title">
Text in a modal
</h2>
<span id="spring-modal-description" className="modal-description">
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</span>
</ModalContent>
</Fade>
</Modal>
</div>
);
}
const Backdrop = React.forwardRef((props, ref) => {
const { open, ...other } = props;
return <Fade ref={ref} in={open} {...other} />;
});
Backdrop.propTypes = {
open: PropTypes.bool.isRequired,
};
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 Fade = React.forwardRef(function Fade(props, ref) {
const { in: open, children, onEnter, onExited, ...other } = props;
const style = useSpring({
from: { opacity: 0 },
to: { opacity: open ? 1 : 0 },
onStart: () => {
if (open && onEnter) {
onEnter(null, true);
}
},
onRest: () => {
if (!open && onExited) {
onExited(null, true);
}
},
});
return (
<animated.div ref={ref} style={style} {...other}>
{children}
</animated.div>
);
});
Fade.propTypes = {
children: PropTypes.element.isRequired,
in: PropTypes.bool,
onEnter: PropTypes.func,
onExited: PropTypes.func,
};
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 style = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
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;
}
`,
);
| 305 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/SpringModal.tsx | import * as React from 'react';
import { Box, styled } from '@mui/system';
import { Modal as BaseModal } from '@mui/base/Modal';
import { Button } from '@mui/base/Button';
import { useSpring, animated } from '@react-spring/web';
export default function SpringModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
aria-labelledby="spring-modal-title"
aria-describedby="spring-modal-description"
open={open}
onClose={handleClose}
closeAfterTransition
slots={{ backdrop: StyledBackdrop }}
>
<Fade in={open}>
<ModalContent sx={style}>
<h2 id="spring-modal-title" className="modal-title">
Text in a modal
</h2>
<span id="spring-modal-description" className="modal-description">
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</span>
</ModalContent>
</Fade>
</Modal>
</div>
);
}
const Backdrop = React.forwardRef<
HTMLDivElement,
{ children: React.ReactElement; open: boolean }
>((props, ref) => {
const { open, ...other } = props;
return <Fade ref={ref} in={open} {...other} />;
});
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;
`;
interface FadeProps {
children: React.ReactElement;
in?: boolean;
onClick?: any;
onEnter?: (node: HTMLElement, isAppearing: boolean) => void;
onExited?: (node: HTMLElement, isAppearing: boolean) => void;
}
const Fade = React.forwardRef<HTMLDivElement, FadeProps>(function Fade(props, ref) {
const { in: open, children, onEnter, onExited, ...other } = props;
const style = useSpring({
from: { opacity: 0 },
to: { opacity: open ? 1 : 0 },
onStart: () => {
if (open && onEnter) {
onEnter(null as any, true);
}
},
onRest: () => {
if (!open && onExited) {
onExited(null as any, true);
}
},
});
return (
<animated.div ref={ref} style={style} {...other}>
{children}
</animated.div>
);
});
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 style = {
position: 'absolute' as 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
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;
}
`,
);
| 306 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/TransitionsModal.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Box, styled } from '@mui/system';
import { Modal as BaseModal } from '@mui/base/Modal';
import Fade from '@mui/material/Fade';
import { Button } from '@mui/base/Button';
export default function TransitionsModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={open}
onClose={handleClose}
closeAfterTransition
slots={{ backdrop: StyledBackdrop }}
>
<Fade in={open}>
<ModalContent sx={style}>
<h2 id="transition-modal-title" className="modal-title">
Text in a child modal
</h2>
<p id="transition-modal-description" className="modal-description">
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</p>
</ModalContent>
</Fade>
</Modal>
</div>
);
}
const Backdrop = React.forwardRef((props, ref) => {
const { open, ...other } = props;
return (
<Fade in={open}>
<div ref={ref} {...other} />
</Fade>
);
});
Backdrop.propTypes = {
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 = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
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;
}
`,
);
| 307 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/TransitionsModal.tsx | import * as React from 'react';
import { Box, styled } from '@mui/system';
import { Modal as BaseModal } from '@mui/base/Modal';
import Fade from '@mui/material/Fade';
import { Button } from '@mui/base/Button';
export default function TransitionsModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={open}
onClose={handleClose}
closeAfterTransition
slots={{ backdrop: StyledBackdrop }}
>
<Fade in={open}>
<ModalContent sx={style}>
<h2 id="transition-modal-title" className="modal-title">
Text in a child modal
</h2>
<p id="transition-modal-description" className="modal-description">
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</p>
</ModalContent>
</Fade>
</Modal>
</div>
);
}
const Backdrop = React.forwardRef<HTMLDivElement, { open?: boolean }>(
(props, ref) => {
const { open, ...other } = props;
return (
<Fade in={open}>
<div ref={ref} {...other} />
</Fade>
);
},
);
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 = {
position: 'absolute' as 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
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;
}
`,
);
| 308 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/UseModal.js | 'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/system';
import { Portal } from '@mui/base/Portal';
import { FocusTrap } from '@mui/base/FocusTrap';
import { Button } from '@mui/base/Button';
import { unstable_useModal as useModal } from '@mui/base/unstable_useModal';
import Fade from '@mui/material/Fade';
export default function UseModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={open}
onClose={handleClose}
closeAfterTransition
>
<Fade in={open}>
<ModalContent sx={style}>
<h2 id="transition-modal-title" className="modal-title">
Text in a modal
</h2>
<span id="transition-modal-description" className="modal-description">
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</span>
</ModalContent>
</Fade>
</Modal>
</div>
);
}
const Modal = React.forwardRef(function Modal(props, forwardedRef) {
const {
children,
closeAfterTransition = false,
container,
disableAutoFocus = false,
disableEnforceFocus = false,
disableEscapeKeyDown = false,
disablePortal = false,
disableRestoreFocus = false,
disableScrollLock = false,
hideBackdrop = false,
keepMounted = false,
onClose,
open,
onTransitionEnter,
onTransitionExited,
...other
} = props;
const propsWithDefaults = {
...props,
closeAfterTransition,
disableAutoFocus,
disableEnforceFocus,
disableEscapeKeyDown,
disablePortal,
disableRestoreFocus,
disableScrollLock,
hideBackdrop,
keepMounted,
};
const {
getRootProps,
getBackdropProps,
getTransitionProps,
portalRef,
isTopModal,
exited,
hasTransition,
} = useModal({
...propsWithDefaults,
rootRef: forwardedRef,
});
const classes = {
hidden: !open && exited,
};
const childProps = {};
if (children.props.tabIndex === undefined) {
childProps.tabIndex = '-1';
}
// It's a Transition like component
if (hasTransition) {
const { onEnter, onExited } = getTransitionProps();
childProps.onEnter = onEnter;
childProps.onExited = onExited;
}
const rootProps = {
...other,
className: clsx(classes),
...getRootProps(other),
};
const backdropProps = {
open,
...getBackdropProps(),
};
if (!keepMounted && !open && (!hasTransition || exited)) {
return null;
}
return (
<Portal ref={portalRef} container={container} disablePortal={disablePortal}>
{/*
* Marking an element with the role presentation indicates to assistive technology
* that this element should be ignored; it exists to support the web application and
* is not meant for humans to interact with directly.
* https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
*/}
<CustomModalRoot {...rootProps}>
{!hideBackdrop ? <CustomModalBackdrop {...backdropProps} /> : null}
<FocusTrap
disableEnforceFocus={disableEnforceFocus}
disableAutoFocus={disableAutoFocus}
disableRestoreFocus={disableRestoreFocus}
isEnabled={isTopModal}
open={open}
>
{React.cloneElement(children, childProps)}
</FocusTrap>
</CustomModalRoot>
</Portal>
);
});
Modal.propTypes = {
children: PropTypes.element.isRequired,
closeAfterTransition: PropTypes.bool,
container: PropTypes.oneOfType([
function (props, propName) {
if (props[propName] == null) {
return new Error("Prop '" + propName + "' is required but wasn't specified");
} else if (
typeof props[propName] !== 'object' ||
props[propName].nodeType !== 1
) {
return new Error("Expected prop '" + propName + "' to be of type Element");
}
},
PropTypes.func,
]),
disableAutoFocus: PropTypes.bool,
disableEnforceFocus: PropTypes.bool,
disableEscapeKeyDown: PropTypes.bool,
disablePortal: PropTypes.bool,
disableRestoreFocus: PropTypes.bool,
disableScrollLock: PropTypes.bool,
hideBackdrop: PropTypes.bool,
keepMounted: PropTypes.bool,
onClose: PropTypes.func,
onTransitionEnter: PropTypes.func,
onTransitionExited: PropTypes.func,
open: PropTypes.bool.isRequired,
};
const Backdrop = React.forwardRef((props, ref) => {
const { open, ...other } = props;
return (
<Fade in={open}>
<div ref={ref} {...other} />
</Fade>
);
});
Backdrop.propTypes = {
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 style = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
};
const ModalContent = styled('div')(
({ theme }) => `
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.50)' : 'rgba(0,0,0, 0.20)'
};
padding: 1rem;
color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]};
font-family: IBM Plex Sans, sans-serif;
font-weight: 500;
text-align: start;
position: relative;
& .modal-title {
margin: 0;
line-height: 1.5rem;
margin-right: 0.5rem;
}
& .modal-description {
margin: 0;
line-height: 1.5rem;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]};
}
`,
);
const CustomModalRoot = styled('div')`
position: fixed;
z-index: 1300;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
`;
const CustomModalBackdrop = styled(Backdrop)`
z-index: -1;
position: fixed;
inset: 0;
background-color: rgb(0 0 0 / 0.5);
-webkit-tap-highlight-color: transparent;
`;
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;
}
`,
);
| 309 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/UseModal.tsx | 'use client';
import * as React from 'react';
import clsx from 'clsx';
import { styled } from '@mui/system';
import { Portal } from '@mui/base/Portal';
import { FocusTrap } from '@mui/base/FocusTrap';
import { Button } from '@mui/base/Button';
import { unstable_useModal as useModal } from '@mui/base/unstable_useModal';
import Fade from '@mui/material/Fade';
export default function UseModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<div>
<TriggerButton onClick={handleOpen}>Open modal</TriggerButton>
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={open}
onClose={handleClose}
closeAfterTransition
>
<Fade in={open}>
<ModalContent sx={style}>
<h2 id="transition-modal-title" className="modal-title">
Text in a modal
</h2>
<span id="transition-modal-description" className="modal-description">
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</span>
</ModalContent>
</Fade>
</Modal>
</div>
);
}
interface ModalProps {
children: React.ReactElement;
closeAfterTransition?: boolean;
container?: Element | (() => Element | null) | null;
disableAutoFocus?: boolean;
disableEnforceFocus?: boolean;
disableEscapeKeyDown?: boolean;
disablePortal?: boolean;
disableRestoreFocus?: boolean;
disableScrollLock?: boolean;
hideBackdrop?: boolean;
keepMounted?: boolean;
onClose?: (event: {}, reason: 'backdropClick' | 'escapeKeyDown') => void;
onTransitionEnter?: () => void;
onTransitionExited?: () => void;
open: boolean;
}
const Modal = React.forwardRef(function Modal(
props: ModalProps,
forwardedRef: React.ForwardedRef<HTMLElement>,
) {
const {
children,
closeAfterTransition = false,
container,
disableAutoFocus = false,
disableEnforceFocus = false,
disableEscapeKeyDown = false,
disablePortal = false,
disableRestoreFocus = false,
disableScrollLock = false,
hideBackdrop = false,
keepMounted = false,
onClose,
open,
onTransitionEnter,
onTransitionExited,
...other
} = props;
const propsWithDefaults = {
...props,
closeAfterTransition,
disableAutoFocus,
disableEnforceFocus,
disableEscapeKeyDown,
disablePortal,
disableRestoreFocus,
disableScrollLock,
hideBackdrop,
keepMounted,
};
const {
getRootProps,
getBackdropProps,
getTransitionProps,
portalRef,
isTopModal,
exited,
hasTransition,
} = useModal({
...propsWithDefaults,
rootRef: forwardedRef,
});
const classes = {
hidden: !open && exited,
};
const childProps: {
onEnter?: () => void;
onExited?: () => void;
tabIndex?: string;
} = {};
if (children.props.tabIndex === undefined) {
childProps.tabIndex = '-1';
}
// It's a Transition like component
if (hasTransition) {
const { onEnter, onExited } = getTransitionProps();
childProps.onEnter = onEnter;
childProps.onExited = onExited;
}
const rootProps = {
...other,
className: clsx(classes),
...getRootProps(other),
};
const backdropProps = {
open,
...getBackdropProps(),
};
if (!keepMounted && !open && (!hasTransition || exited)) {
return null;
}
return (
<Portal ref={portalRef} container={container} disablePortal={disablePortal}>
{/*
* Marking an element with the role presentation indicates to assistive technology
* that this element should be ignored; it exists to support the web application and
* is not meant for humans to interact with directly.
* https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md
*/}
<CustomModalRoot {...rootProps}>
{!hideBackdrop ? <CustomModalBackdrop {...backdropProps} /> : null}
<FocusTrap
disableEnforceFocus={disableEnforceFocus}
disableAutoFocus={disableAutoFocus}
disableRestoreFocus={disableRestoreFocus}
isEnabled={isTopModal}
open={open}
>
{React.cloneElement(children, childProps)}
</FocusTrap>
</CustomModalRoot>
</Portal>
);
});
const Backdrop = React.forwardRef<HTMLDivElement, { open?: boolean }>(
(props, ref) => {
const { open, ...other } = props;
return (
<Fade in={open}>
<div ref={ref} {...other} />
</Fade>
);
},
);
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 style = {
position: 'absolute' as 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
};
const ModalContent = styled('div')(
({ theme }) => `
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.50)' : 'rgba(0,0,0, 0.20)'
};
padding: 1rem;
color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]};
font-family: IBM Plex Sans, sans-serif;
font-weight: 500;
text-align: start;
position: relative;
& .modal-title {
margin: 0;
line-height: 1.5rem;
margin-right: 0.5rem;
}
& .modal-description {
margin: 0;
line-height: 1.5rem;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]};
}
`,
);
const CustomModalRoot = styled('div')`
position: fixed;
z-index: 1300;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
`;
const CustomModalBackdrop = styled(Backdrop)`
z-index: -1;
position: fixed;
inset: 0;
background-color: rgb(0 0 0 / 0.5);
-webkit-tap-highlight-color: transparent;
`;
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;
}
`,
);
| 310 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/modal/modal.md | ---
productId: base-ui
title: React Modal component
components: Modal
hooks: useModal
githubLabel: 'component: modal'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
---
# Modal
<p class="description">The Modal component lets you create dialogs, popovers, lightboxes, and other elements that force the user to take action before continuing.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
Modal is a utility component that renders its children in front of a backdrop.
This lets you create an element that your users must interact with before continuing in the parent application.
:::info
The term "modal" is sometimes used interchangeably with "dialog," but this is incorrect.
A dialog may be _modal_ or _nonmodal (modeless)_.
A modal [blocks interaction with the rest of the application](https://en.wikipedia.org/wiki/Modal_window), forcing the user to take action.
As such, it should be used sparingly—only when the app _requires_ user input before it can continue.
:::
<!-- Uncomment the next line, once an unstyled dialog component is added in @mui/base -->
<!-- If you are creating a modal dialog, the [`Dialog`](/material-ui/dialog/) component is better suited for this specific use case. -->
Modal is a lower-level construct that is used in the following Material UI components:
- [Dialog](/material-ui/react-dialog/)
- [Drawer](/material-ui/react-drawer/)
- [Menu](/material-ui/react-menu/)
- [Popover](/material-ui/react-popover/)
## Component
```jsx
import { Modal } from '@mui/base/Modal';
```
The following demo shows how to create and style a basic modal.
Click **Open modal** to see how it behaves:
{{"demo": "ModalUnstyled.js", "defaultCodeOpen": false }}
## Customization
### Nested modal
:::warning
Though it is possible to create nested Modals—for example, a select modal within a dialog—stacking more than two at a time is discouraged.
This is because each successive Modal blocks interaction with all elements behind it, making prior states inaccessible and overly complicated for the user to navigate through.
:::
The following demo shows how to nest one Modal within another:
{{"demo": "NestedModal.js", "defaultCodeOpen": false}}
### Transitions
You can animate the open and close states of a Modal using a transition component, as long as that component fulfills the following requirements:
- Is a direct child descendant of the Modal
- Has an `in` prop—this corresponds to the open/close state
- Calls the `onEnter` callback prop when the enter transition starts
- Calls the `onExited` callback prop when the exit transition is completed
:::info
The `onEnter` and `onExited` callbacks tell the Modal to unmount the child content when closed and fully transitioned.
:::
Modal has built-in support for [react-transition-group](https://github.com/reactjs/react-transition-group):
{{"demo": "TransitionsModal.js", "defaultCodeOpen": false}}
You can also use [react-spring](https://github.com/pmndrs/react-spring) with Modal, but it will require additional custom configuration:
{{"demo": "SpringModal.js", "defaultCodeOpen": false}}
### Performance
The Modal's content is unmounted when it's not open.
This means that it will need to be re-mounted each time it's opened.
If you're rendering expensive component trees inside your Modal, and you want to optimize for interaction responsiveness, you can change this default behavior by enabling the `keepMounted` prop.
You can also use the `keepMounted` prop if you want to make the content of the Modal available to search engines (even when the Modal is closed).
The following demo shows how to apply this prop to keep the Modal mounted:
{{"demo": "KeepMountedModal.js", "defaultCodeOpen": false}}
:::info
You can use the `MuiModal-hidden` class to hide the modal when it is not open.
:::
As with any performance optimization, the `keepMounted` prop won't necessarily solve all of your problems.
Explore other possible bottlenecks in performance where you could make more considerable improvements before implementing this prop.
### Server-side modal
React [doesn't support](https://github.com/facebook/react/issues/13097) the [`createPortal()`](https://react.dev/reference/react-dom/createPortal) API on the server.
In order to display a Modal rendered on the server, you need to disable the portal feature with the `disablePortal` prop, as shown in the following demo:
{{"demo": "ServerModal.js", "defaultCodeOpen": false}}
## Limitations
### Overflow layout shift
The Modal disables the page scrolling while open by setting `overflow: hidden` as inline-style on the relevant scroll container, this hides the scrollbar and hence impacts the page layout.
To compensate for this offset and avoid a layout shift, the Modal also set a padding property on the scroll container (~15px under normal conditions).
This can create a layout shift with `position: fixed` and `position: sticky` elements.
You need to add the `.mui-fixed` class name on these elements so the Modal can add a CSS padding property when the scroll is disabled.
```jsx
<Box sx={{ position: 'sticky', right: 0, top: 0, left: 0 }} className="mui-fixed">
```
### Focus trap
Modal moves the focus back to the body of the component if the focus tries to escape it.
This is done for accessibility purposes, but it can potentially create issues for your users.
If the user needs to interact with another part of the page—for example, to interact with a chatbot window while a Modal is open in the parent app—you can disable the default behavior with the `disableEnforceFocus` prop.
## Hook
```js
import useModal from '@mui/base/unstable_useModal';
```
The `useModal` hook lets you apply the functionality of a Modal 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 following demo shows how to build the same Modal as the one found in the [Component](#component) section above, but with the `useModal` hook:
{{"demo": "UseModal.js", "defaultCodeOpen": true}}
If you use a ref to store a reference to the root element, pass it to the `useModal`'s `ref` parameter, as shown in the demo above.
It will get merged with a ref used internally in the hook.
:::warning
Do not add the `ref` parameter to the root element manually, as the correct ref is already a part of the object returned by the `getRootProps` function.
:::
## Accessibility
See the [WAI-ARIA guide on the Dialog (Modal) pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) for complete details on accessibility best practices.
- All interactive elements must have an [accessible name](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby). Use the `aria-labelledby="id..."` to give your Modal component an accessible name.
You can also use `aria-describedby="id..."` to provide a description of the Modal:
```jsx
<Modal aria-labelledby="modal-title" aria-describedby="modal-description">
<h2 id="modal-title">My Title</h2>
<p id="modal-description">My Description</p>
</Modal>
```
- Follow the [WAI-ARIA authoring practices](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/dialog/) to help you set the initial focus on the most relevant element based on the content of the Modal.
:::warning
A modal window can sit on top of either the parent application, or another modal window.
_All_ windows under the topmost modal are **inert**, meaning the user cannot interact with them.
This can lead to [conflicting behaviors](#focus-trap).
:::
| 311 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/no-ssr/FrameDeferring.js | import * as React from 'react';
import { NoSsr } from '@mui/base/NoSsr';
import { Box } from '@mui/system';
function LargeTree() {
return Array.from(new Array(5000)).map((_, index) => <span key={index}>.</span>);
}
export default function FrameDeferring() {
const [state, setState] = React.useState({
open: false,
defer: false,
});
return (
<div>
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: false,
})
}
>
{'Render NoSsr defer="false"'}
</button>
<br />
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: true,
})
}
>
{'Render NoSsr defer="true"'}
</button>
<br />
<br />
<Box sx={{ width: 300, display: 'flex', flexWrap: 'wrap' }}>
{state.open ? (
<React.Fragment>
<div>Outside NoSsr</div>
<NoSsr defer={state.defer}>
.....Inside NoSsr
<LargeTree />
</NoSsr>
</React.Fragment>
) : null}
</Box>
</div>
);
}
| 312 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/no-ssr/FrameDeferring.tsx | import * as React from 'react';
import { NoSsr } from '@mui/base/NoSsr';
import { Box } from '@mui/system';
function LargeTree(): any {
return Array.from(new Array(5000)).map((_, index) => <span key={index}>.</span>);
}
export default function FrameDeferring() {
const [state, setState] = React.useState({
open: false,
defer: false,
});
return (
<div>
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: false,
})
}
>
{'Render NoSsr defer="false"'}
</button>
<br />
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: true,
})
}
>
{'Render NoSsr defer="true"'}
</button>
<br />
<br />
<Box sx={{ width: 300, display: 'flex', flexWrap: 'wrap' }}>
{state.open ? (
<React.Fragment>
<div>Outside NoSsr</div>
<NoSsr defer={state.defer}>
.....Inside NoSsr
<LargeTree />
</NoSsr>
</React.Fragment>
) : null}
</Box>
</div>
);
}
| 313 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/no-ssr/SimpleNoSsr.js | import * as React from 'react';
import { NoSsr } from '@mui/base/NoSsr';
import { Box } from '@mui/system';
export default function SimpleNoSsr() {
return (
<div>
<Box sx={{ p: 2, bgcolor: 'primary.main', color: 'primary.contrastText' }}>
Server and Client
</Box>
<NoSsr>
<Box
sx={{ p: 2, bgcolor: 'secondary.main', color: 'secondary.contrastText' }}
>
Client only
</Box>
</NoSsr>
</div>
);
}
| 314 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/no-ssr/SimpleNoSsr.tsx | import * as React from 'react';
import { NoSsr } from '@mui/base/NoSsr';
import { Box } from '@mui/system';
export default function SimpleNoSsr() {
return (
<div>
<Box sx={{ p: 2, bgcolor: 'primary.main', color: 'primary.contrastText' }}>
Server and Client
</Box>
<NoSsr>
<Box
sx={{ p: 2, bgcolor: 'secondary.main', color: 'secondary.contrastText' }}
>
Client only
</Box>
</NoSsr>
</div>
);
}
| 315 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/no-ssr/SimpleNoSsr.tsx.preview | <Box sx={{ p: 2, bgcolor: 'primary.main', color: 'primary.contrastText' }}>
Server and Client
</Box>
<NoSsr>
<Box
sx={{ p: 2, bgcolor: 'secondary.main', color: 'secondary.contrastText' }}
>
Client only
</Box>
</NoSsr> | 316 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/no-ssr/no-ssr.md | ---
productId: base-ui
title: No SSR React component
components: NoSsr
---
# No SSR
<p class="description">The No-SSR component defers the rendering of children components from the server to the client.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
No-SSR is a utility component that prevents its children from being rendered on the server.
This component can be useful in a variety of situations:
- To create an escape hatch for broken dependencies that don't support server-side rendering (SSR)
- To improve the time to first paint by only rendering above the fold
- To reduce the rendering time on the server
- To turn on service degradation when the server load is too heavy
- To improve the Time to Interactive (TTI) by only rendering what's important (using the `defer` prop)
## Component
```jsx
import { NoSsr } from '@mui/base/NoSsr';
```
At its core, the No-SSR component's purpose is to defer rendering from the server to the client, as shown in the following demo:
{{"demo": "SimpleNoSsr.js"}}
## Customization
### Delay client-side rendering
You can also use No-SSR to delay the rendering of specific components on the client side—for example, to let the rest of the application load before an especially complex or data-heavy component.
The following demo shows how to use the `defer` prop to prioritize rendering the rest of the app outside of what is nested within No-SSR:
{{"demo": "FrameDeferring.js"}}
:::warning
When using No-SSR in this way, React applies [two commits](https://react.dev/learn/render-and-commit) instead of one.
:::
| 317 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputAdornments.js | import * as React from 'react';
import { Box, styled } from '@mui/system';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
const NumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
return (
<BaseNumberInput
slots={{
root: InputRoot,
input: InputElement,
incrementButton: Button,
decrementButton: Button,
}}
slotProps={{
incrementButton: {
children: <span className="arrow">▴</span>,
},
decrementButton: {
children: <span className="arrow">▾</span>,
},
}}
{...props}
ref={ref}
/>
);
});
export default function NumberInputAdornments() {
return (
<Box
sx={{
display: 'flex',
flexDirection: { xs: 'column', sm: 'row' },
gap: 2,
}}
>
<NumberInput
startAdornment={
<InputAdornment>
<svg
// From Feather: https://feathericons.com/?query=dollar-sign
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<line x1="12" y1="1" x2="12" y2="23" />
<path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
</svg>
</InputAdornment>
}
/>
<NumberInput endAdornment={<InputAdornment>kg</InputAdornment>} />
</Box>
);
}
const InputAdornment = styled('div')(
({ theme }) => `
margin: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[500] : grey[700]};
`,
);
const blue = {
100: '#DAECFF',
200: '#B6DAFF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 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[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)'
};
display: grid;
grid-template-columns: auto 1fr auto 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
padding: 4px;
&.${numberInputClasses.focused} {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : 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;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const Button = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 20px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
cursor: pointer;
}
&.${numberInputClasses.incrementButton} {
grid-column: 4/5;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
&.${numberInputClasses.decrementButton} {
grid-column: 4/5;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
& .arrow {
transform: translateY(-1px);
}
& .arrow {
transform: translateY(-1px);
}
`,
);
| 318 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputAdornments.tsx | import * as React from 'react';
import { Box, styled } from '@mui/system';
import {
Unstable_NumberInput as BaseNumberInput,
NumberInputProps,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
const NumberInput = React.forwardRef(function CustomNumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<BaseNumberInput
slots={{
root: InputRoot,
input: InputElement,
incrementButton: Button,
decrementButton: Button,
}}
slotProps={{
incrementButton: {
children: <span className="arrow">▴</span>,
},
decrementButton: {
children: <span className="arrow">▾</span>,
},
}}
{...props}
ref={ref}
/>
);
});
export default function NumberInputAdornments() {
return (
<Box
sx={{
display: 'flex',
flexDirection: { xs: 'column', sm: 'row' },
gap: 2,
}}
>
<NumberInput
startAdornment={
<InputAdornment>
<svg
// From Feather: https://feathericons.com/?query=dollar-sign
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.5"
strokeLinecap="round"
strokeLinejoin="round"
>
<line x1="12" y1="1" x2="12" y2="23" />
<path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
</svg>
</InputAdornment>
}
/>
<NumberInput endAdornment={<InputAdornment>kg</InputAdornment>} />
</Box>
);
}
const InputAdornment = styled('div')(
({ theme }) => `
margin: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[500] : grey[700]};
`,
);
const blue = {
100: '#DAECFF',
200: '#B6DAFF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 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[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)'
};
display: grid;
grid-template-columns: auto 1fr auto 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
padding: 4px;
&.${numberInputClasses.focused} {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : 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;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const Button = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 20px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
cursor: pointer;
}
&.${numberInputClasses.incrementButton} {
grid-column: 4/5;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
&.${numberInputClasses.decrementButton} {
grid-column: 4/5;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
& .arrow {
transform: translateY(-1px);
}
& .arrow {
transform: translateY(-1px);
}
`,
);
| 319 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/QuantityInput.js | import * as React from 'react';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import { styled } from '@mui/system';
import RemoveIcon from '@mui/icons-material/Remove';
import AddIcon from '@mui/icons-material/Add';
const NumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
return (
<BaseNumberInput
slots={{
root: StyledInputRoot,
input: StyledInput,
incrementButton: StyledButton,
decrementButton: StyledButton,
}}
slotProps={{
incrementButton: {
children: <AddIcon fontSize="small" />,
className: 'increment',
},
decrementButton: {
children: <RemoveIcon fontSize="small" />,
},
}}
{...props}
ref={ref}
/>
);
});
export default function QuantityInput() {
return <NumberInput aria-label="Quantity Input" min={1} max={99} />;
}
const blue = {
100: '#daecff',
200: '#b6daff',
300: '#66b2ff',
400: '#3399ff',
500: '#007fff',
600: '#0072e5',
700: '#0059B2',
800: '#004c99',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.375;
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)'
};
border-radius: 8px;
margin: 0 8px;
padding: 10px 12px;
outline: 0;
min-width: 0;
width: 4rem;
text-align: center;
&:hover {
border-color: ${blue[400]};
}
&:focus {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledButton = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
line-height: 1.5;
border: 1px solid;
border-radius: 999px;
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
width: 32px;
height: 32px;
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
cursor: pointer;
background: ${theme.palette.mode === 'dark' ? blue[700] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[500] : blue[400]};
color: ${grey[50]};
}
&:focus-visible {
outline: 0;
}
&.increment {
order: 1;
}
`,
);
| 320 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/QuantityInput.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
NumberInputProps,
} from '@mui/base/Unstable_NumberInput';
import { styled } from '@mui/system';
import RemoveIcon from '@mui/icons-material/Remove';
import AddIcon from '@mui/icons-material/Add';
const NumberInput = React.forwardRef(function CustomNumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<BaseNumberInput
slots={{
root: StyledInputRoot,
input: StyledInput,
incrementButton: StyledButton,
decrementButton: StyledButton,
}}
slotProps={{
incrementButton: {
children: <AddIcon fontSize="small" />,
className: 'increment',
},
decrementButton: {
children: <RemoveIcon fontSize="small" />,
},
}}
{...props}
ref={ref}
/>
);
});
export default function QuantityInput() {
return <NumberInput aria-label="Quantity Input" min={1} max={99} />;
}
const blue = {
100: '#daecff',
200: '#b6daff',
300: '#66b2ff',
400: '#3399ff',
500: '#007fff',
600: '#0072e5',
700: '#0059B2',
800: '#004c99',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.375;
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)'
};
border-radius: 8px;
margin: 0 8px;
padding: 10px 12px;
outline: 0;
min-width: 0;
width: 4rem;
text-align: center;
&:hover {
border-color: ${blue[400]};
}
&:focus {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledButton = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
line-height: 1.5;
border: 1px solid;
border-radius: 999px;
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
width: 32px;
height: 32px;
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
cursor: pointer;
background: ${theme.palette.mode === 'dark' ? blue[700] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[500] : blue[400]};
color: ${grey[50]};
}
&:focus-visible {
outline: 0;
}
&.increment {
order: 1;
}
`,
);
| 321 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/QuantityInput.tsx.preview | <NumberInput aria-label="Quantity Input" min={1} max={99} /> | 322 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/UseNumberInput.js | import * as React from 'react';
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
const CustomNumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
const {
getRootProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps,
focused,
} = useNumberInput(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 (
<StyledInputRoot {...getRootProps()} className={focused ? 'focused' : null}>
<StyledStepperButton {...getIncrementButtonProps()} className="increment">
▴
</StyledStepperButton>
<StyledStepperButton {...getDecrementButtonProps()} className="decrement">
▾
</StyledStepperButton>
<StyledInputElement {...inputProps} />
</StyledInputRoot>
);
});
export default function UseNumberInput() {
return (
<CustomNumberInput aria-label="Demo number input" placeholder="Type a number…" />
);
}
const blue = {
100: '#DAECFF',
200: '#B6DAFF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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)'
};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
& button:hover {
background: ${blue[400]};
}
// firefox
&:focus-visible {
outline: 0;
}
`,
);
const StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const StyledStepperButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&.increment {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
&.decrement {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
`,
);
| 323 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/UseNumberInput.tsx | import * as React from 'react';
import {
unstable_useNumberInput as useNumberInput,
UseNumberInputParameters,
} from '@mui/base/unstable_useNumberInput';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
const CustomNumberInput = React.forwardRef(function CustomNumberInput(
props: UseNumberInputParameters & React.InputHTMLAttributes<HTMLInputElement>,
ref: React.ForwardedRef<HTMLInputElement>,
) {
const {
getRootProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps,
focused,
} = useNumberInput(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 (
<StyledInputRoot {...getRootProps()} className={focused ? 'focused' : null}>
<StyledStepperButton {...getIncrementButtonProps()} className="increment">
▴
</StyledStepperButton>
<StyledStepperButton {...getDecrementButtonProps()} className="decrement">
▾
</StyledStepperButton>
<StyledInputElement {...inputProps} />
</StyledInputRoot>
);
});
export default function UseNumberInput() {
return (
<CustomNumberInput aria-label="Demo number input" placeholder="Type a number…" />
);
}
const blue = {
100: '#DAECFF',
200: '#B6DAFF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 StyledInputRoot: React.ElementType = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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)'
};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
& button:hover {
background: ${blue[400]};
}
// firefox
&:focus-visible {
outline: 0;
}
`,
);
const StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const StyledStepperButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&.increment {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
&.decrement {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
`,
);
| 324 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/UseNumberInput.tsx.preview | <CustomNumberInput aria-label="Demo number input" placeholder="Type a number…" /> | 325 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/UseNumberInputCompact.js | import * as React from 'react';
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropUpRoundedIcon from '@mui/icons-material/ArrowDropUpRounded';
import ArrowDropDownRoundedIcon from '@mui/icons-material/ArrowDropDownRounded';
const CompactNumberInput = React.forwardRef(function CompactNumberInput(props, ref) {
const {
getRootProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps,
} = useNumberInput(props);
const inputProps = getInputProps();
inputProps.ref = useForkRef(inputProps.ref, ref);
return (
<StyledInputRoot {...getRootProps()}>
<StyledStepperButton className="increment" {...getIncrementButtonProps()}>
<ArrowDropUpRoundedIcon />
</StyledStepperButton>
<StyledStepperButton className="decrement" {...getDecrementButtonProps()}>
<ArrowDropDownRoundedIcon />
</StyledStepperButton>
<HiddenInput {...inputProps} />
</StyledInputRoot>
);
});
export default function UseNumberInputCompact() {
const [value, setValue] = React.useState();
return (
<Layout>
<CompactNumberInput
aria-label="Compact number input"
placeholder="Type a number…"
readOnly
value={value}
onChange={(event, val) => setValue(val)}
/>
<Pre>Current value: {value ?? ' '}</Pre>
</Layout>
);
}
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 StyledInputRoot = styled('div')(
({ theme }) => `
display: grid;
grid-template-columns: 2rem;
grid-template-rows: 2rem 2rem;
grid-template-areas:
"increment"
"decrement";
row-gap: 1px;
overflow: auto;
border-radius: 8px;
border-style: solid;
border-width: 1px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const HiddenInput = styled('input')`
visibility: hidden;
position: absolute;
`;
const StyledStepperButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: nowrap;
justify-content: center;
align-items: center;
font-size: 0.875rem;
box-sizing: border-box;
border: 0;
padding: 0;
color: inherit;
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
&:hover {
cursor: pointer;
background: ${theme.palette.mode === 'dark' ? blue[700] : blue[500]};
color: ${grey[50]};
}
&:focus-visible {
outline: 0;
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&.increment {
grid-area: increment;
}
&.decrement {
grid-area: decrement;
}
`,
);
const Layout = styled('div')`
display: flex;
flex-flow: row nowrap;
align-items: center;
column-gap: 1rem;
`;
const Pre = styled('pre')`
font-size: 0.75rem;
`;
| 326 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/UseNumberInputCompact.tsx | import * as React from 'react';
import {
unstable_useNumberInput as useNumberInput,
UseNumberInputParameters,
} from '@mui/base/unstable_useNumberInput';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropUpRoundedIcon from '@mui/icons-material/ArrowDropUpRounded';
import ArrowDropDownRoundedIcon from '@mui/icons-material/ArrowDropDownRounded';
const CompactNumberInput = React.forwardRef(function CompactNumberInput(
props: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> &
UseNumberInputParameters,
ref: React.ForwardedRef<HTMLInputElement>,
) {
const {
getRootProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps,
} = useNumberInput(props);
const inputProps = getInputProps();
inputProps.ref = useForkRef(inputProps.ref, ref);
return (
<StyledInputRoot {...getRootProps()}>
<StyledStepperButton className="increment" {...getIncrementButtonProps()}>
<ArrowDropUpRoundedIcon />
</StyledStepperButton>
<StyledStepperButton className="decrement" {...getDecrementButtonProps()}>
<ArrowDropDownRoundedIcon />
</StyledStepperButton>
<HiddenInput {...inputProps} />
</StyledInputRoot>
);
});
export default function UseNumberInputCompact() {
const [value, setValue] = React.useState<number | undefined>();
return (
<Layout>
<CompactNumberInput
aria-label="Compact number input"
placeholder="Type a number…"
readOnly
value={value}
onChange={(event, val) => setValue(val)}
/>
<Pre>Current value: {value ?? ' '}</Pre>
</Layout>
);
}
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 StyledInputRoot = styled('div')(
({ theme }) => `
display: grid;
grid-template-columns: 2rem;
grid-template-rows: 2rem 2rem;
grid-template-areas:
"increment"
"decrement";
row-gap: 1px;
overflow: auto;
border-radius: 8px;
border-style: solid;
border-width: 1px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const HiddenInput = styled('input')`
visibility: hidden;
position: absolute;
`;
const StyledStepperButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: nowrap;
justify-content: center;
align-items: center;
font-size: 0.875rem;
box-sizing: border-box;
border: 0;
padding: 0;
color: inherit;
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
&:hover {
cursor: pointer;
background: ${theme.palette.mode === 'dark' ? blue[700] : blue[500]};
color: ${grey[50]};
}
&:focus-visible {
outline: 0;
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&.increment {
grid-area: increment;
}
&.decrement {
grid-area: decrement;
}
`,
);
const Layout = styled('div')`
display: flex;
flex-flow: row nowrap;
align-items: center;
column-gap: 1rem;
`;
const Pre = styled('pre')`
font-size: 0.75rem;
`;
| 327 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/UseNumberInputCompact.tsx.preview | <Layout>
<CompactNumberInput
aria-label="Compact number input"
placeholder="Type a number…"
readOnly
value={value}
onChange={(event, val) => setValue(val)}
/>
<Pre>Current value: {value ?? ' '}</Pre>
</Layout> | 328 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/number-input/number-input.md | ---
productId: base-ui
title: React Number Input component and hook
components: NumberInput
hooks: useNumberInput
githubLabel: 'component: number input'
---
# Number Input
<p class="description">The Number Input component provides users with a field for integer values, and buttons to increment or decrement the value.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
A number input is a UI element that accepts numeric values from the user.
Base UI's Number Input component is a customizable replacement for the native HTML `<input type="number">` that solves common usability issues of its native counterpart, such as:
- Inconsistencies across browsers in the appearance and behavior of the stepper buttons
- Allowing certain non-numeric characters ('e', '+', '-', '.') and silently discarding others
- Incompatibilities with assistive technologies and limited accessibility features
:::info
See [_Why the GOV.UK Design System team changed the input type for numbers_](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/) for a more detailed explanation of the limitations of `<input type="number">`.
:::
{{"demo": "NumberInputIntroduction", "defaultCodeOpen": false, "bg": "gradient"}}
## Component
```jsx
import { Unstable_NumberInput as NumberInput } from '@mui/base/Unstable_NumberInput';
```
The following demo shows how to create a Number Input component, apply some styling, and write the latest value to a state variable using the `onChange` prop:
{{"demo": "NumberInputBasic"}}
### Anatomy
The Base UI Number Input component consists of four slots:
- `root`: an outer `<div>` containing the other interior slots
- `input`: an `<input>` element
- `incrementButton`: a `<button>` for increasing the value
- `decrementButton`: a `<button>` for decreasing the value
```html
<div class="MuiNumberInput-root">
<button class="MuiNumberInput-decrementButton" />
<button class="MuiNumberInput-incrementButton" />
<input class="MuiNumberInput-input" />
</div>
```
### Custom structure
Use the `slots` prop to override the root slot or any interior slots:
```jsx
<NumberInput
slots={{
root: 'aside',
incrementButton: CustomButton,
decrementButton: CustomButton,
}}
/>
```
:::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-num-input` to the input slot
- passes a `direction` prop to the `CustomButton` components in the increment and decrement button slots
```jsx
<NumberInput
slotProps={{
input: { className: 'my-num-input' },
incrementButton: { direction: 'UP' },
decrementButton: { direction: 'DOWN' },
}}
/>
```
## Hook
```js
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput';
```
The `useNumberInput` hook lets you apply the functionality of a Number 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).
:::
Here's an example of a custom component built using the `useNumberInput` hook with all the required props:
{{"demo": "UseNumberInput.js", "defaultCodeOpen": false}}
Here's an example of a "compact" number input component using the hook that only consists of the stepper buttons.
In this demo, [`onChange`](#events) is used to write the latest value of the component to a state variable.
{{"demo": "UseNumberInputCompact.js", "defaultCodeOpen": false}}
## Customization
### Minimum and maximum
Use the `min` and `max` props to define a range of accepted values.
If you only define one or the other, the opposite end of the range will be open-ended.
```jsx
// accepts any value:
<NumberInput />
// only accepts values between -10 and 10:
<NumberInput min={-10} max={10} />
// only accepts values greater than 0:
<NumberInput min={0} />
```
The demo below shows a Number Input with a an accepted range of 1 to 99:
{{"demo": "QuantityInput.js", "defaultCodeOpen": false}}
### Incremental steps
Use the `step` prop to define the granularity of the change in value when incrementing or decrementing.
For example, if `min={0}` and `step={2}`, valid values for the component would be 0, 2, 4, and on, since the value can only be changed in increments of 2.
```jsx
// valid values: 0, 2, 4, 6, 8...
<NumberInput min={0} step={2} />
```
:::warning
Support for decimal values and step sizes isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38518) to see it arrive sooner.
:::
When the input field is in focus, you can enter values that fall outside the valid range.
The value will be clamped based on `min`, `max` and `step` once the input field is blurred.
### Shift multiplier
Holding down the <kbd class="key">Shift</kbd> key when interacting with the stepper buttons applies a multiplier (default 10x) to the value change of each step.
You can customize this behavior with the `shiftMultiplier` prop.
In the following snippet, if <kbd class="key">Shift</kbd> is held when clicking the increment button, the value will change from 0, to 5, to 10, and on.
```jsx
<NumberInput min={0} step={1} shiftMultiplier={5} />
```
### Events
The Number Input component and hook provide two props–`onChange` and `onInputChange`–that accept event handlers for when the value of the component changes.
#### onChange
`onChange` accepts a custom event handler that is called with two arguments: the underlying event, and the latest "clamped" value.
```ts
onChange: (
event: React.FocusEvent<HTMLInputElement> | React.PointerEvent | React.KeyboardEvent,
value: number | undefined,
) => void;
```
It's called when the `<input>` element is blurred, or when the stepper buttons are clicked, after the value has been clamped based on the [`min`, `max`](#minimum-and-maximum), or [`step`](#incremental-steps) props.
:::info
When using the component, `onChange` can only be passed as a prop on the component—not through `slotProps`.
:::
```jsx
// ✅ Works
<NumberInput
onChange={(event, newValue) => console.log(`${event.type} event: the new value is ${newValue}`)}
/>
// ❌ Doesn't work
<NumberInput
slotProps={{
input: {
// expects a native input change event handler, newValue is always undefined
onChange: (event, newValue) => { ... },
},
}}
/>
```
#### onInputChange
`onInputChange` accepts a native input change handler that's passed to the `<input>` element:
```ts
onInputChange: React.ChangeEventHandler<HTMLInputElement>;
```
It's called whenever the value of the textbox changes–for example, on every keystroke typed into it, before clamping is applied.
In other words, it's possible for `event.target.value` to contain out-of-range values or non-numerical characters.
:::info
When using the component, `onInputChange` can only be passed as a prop on the component. If you prefer to use `slotProps`, pass it as `slotProps.input.onChange` instead. Both ways–`onInputChange` and `slotProps.input.onChange`–work the same.
:::
```jsx
// ✅ Works
<NumberInput
onInputChange={(event) => console.log(`the input value is: ${event.target.value}`)}
/>
// ✅ Works
<NumberInput
slotProps={{
input: {
// this exactly the same as onInputChange above
onChange: (event) => console.log(`the input value is: ${event.target.value}`),
},
}}
/>
// ❌ Doesn't work
<NumberInput
slotProps={{
input: {
// This will throw "unknown event handler"
onInputChange: () => {},
},
}}
/>
```
### Adornments
You can use the `startAdornment` and `endAdornment` props to add a prefix or suffix, respectively, to a Number Input.
Adornments can be useful for displaying units of measure, like weight or currency, alongside values.
{{"demo": "NumberInputAdornments.js", "defaultCodeOpen": false}}
| 329 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/css/index.js | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
export default function NumberInputBasic() {
return (
<React.Fragment>
<BaseNumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<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>
{`
.CustomNumberInput {
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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]};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
}
.CustomNumberInput:hover {
border-color: ${cyan[400]};
}
.CustomNumberInput.${numberInputClasses.focused} {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]};
}
.CustomNumberInput .input {
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}
.CustomNumberInput .input:focus-visible {
outline: 0;
}
.CustomNumberInput .btn {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 0;
color: ${isDarkMode ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}
.CustomNumberInput .btn:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}
.CustomNumberInput .btn.increment {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
&:hover {
cursor: pointer;
background: ${cyan[400]};
color: ${grey[50]};
}
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
}
.CustomNumberInput .btn.decrement {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
&:hover {
cursor: pointer;
background: ${cyan[400]};
color: ${grey[50]};
}
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
}
& .arrow {
transform: translateY(-1px);
}
`}
</style>
);
}
| 330 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/css/index.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
export default function NumberInputBasic() {
return (
<React.Fragment>
<BaseNumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<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>
{`
.CustomNumberInput {
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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]};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
}
.CustomNumberInput:hover {
border-color: ${cyan[400]};
}
.CustomNumberInput.${numberInputClasses.focused} {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]};
}
.CustomNumberInput .input {
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}
.CustomNumberInput .input:focus-visible {
outline: 0;
}
.CustomNumberInput .btn {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 0;
color: ${isDarkMode ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}
.CustomNumberInput .btn:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}
.CustomNumberInput .btn.increment {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
&:hover {
cursor: pointer;
background: ${cyan[400]};
color: ${grey[50]};
}
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
}
.CustomNumberInput .btn.decrement {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
&:hover {
cursor: pointer;
background: ${cyan[400]};
color: ${grey[50]};
}
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
}
& .arrow {
transform: translateY(-1px);
}
`}
</style>
);
}
| 331 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/css/index.tsx.preview | <React.Fragment>
<BaseNumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<Styles />
</React.Fragment> | 332 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/system/index.js | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { styled } from '@mui/system';
const NumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
return (
<BaseNumberInput
slots={{
root: StyledInputRoot,
input: StyledInputElement,
incrementButton: StyledButton,
decrementButton: StyledButton,
}}
slotProps={{
incrementButton: {
children: '▴',
},
decrementButton: {
children: '▾',
},
}}
{...props}
ref={ref}
/>
);
});
export default function NumberInputBasic() {
const [value, setValue] = React.useState();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
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 StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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]};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
&.${numberInputClasses.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 StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const StyledButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
cursor: pointer;
}
&.${numberInputClasses.incrementButton} {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
&:hover {
cursor: pointer;
background: ${blue[400]};
color: ${grey[50]};
}
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
}
&.${numberInputClasses.decrementButton} {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
&:hover {
cursor: pointer;
background: ${blue[400]};
color: ${grey[50]};
}
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
}
& .arrow {
transform: translateY(-1px);
}
`,
);
| 333 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/system/index.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
NumberInputProps,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { styled } from '@mui/system';
const NumberInput = React.forwardRef(function CustomNumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<BaseNumberInput
slots={{
root: StyledInputRoot,
input: StyledInputElement,
incrementButton: StyledButton,
decrementButton: StyledButton,
}}
slotProps={{
incrementButton: {
children: '▴',
},
decrementButton: {
children: '▾',
},
}}
{...props}
ref={ref}
/>
);
});
export default function NumberInputBasic() {
const [value, setValue] = React.useState<number | undefined>();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
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 StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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]};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
&.${numberInputClasses.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 StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const StyledButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
cursor: pointer;
}
&.${numberInputClasses.incrementButton} {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
&:hover {
cursor: pointer;
background: ${blue[400]};
color: ${grey[50]};
}
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
}
&.${numberInputClasses.decrementButton} {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
&:hover {
cursor: pointer;
background: ${blue[400]};
color: ${grey[50]};
}
border-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
}
& .arrow {
transform: translateY(-1px);
}
`,
);
| 334 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/system/index.tsx.preview | <NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/> | 335 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/tailwind/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import clsx from 'clsx';
export default function NumberInputBasic() {
const [value, setValue] = React.useState();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn);
const NumberInput = React.forwardRef(function NumberInput(props, ref) {
return (
<BaseNumberInput
{...props}
ref={ref}
slotProps={{
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'grid grid-cols-[1fr_8px] grid-rows-2 overflow-hidden font-sans rounded-lg text-slate-900 dark:text-slate-300 border border-solid bg-white dark:bg-slate-900 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 p-1',
ownerState.focused
? 'border-violet-400 dark:border-violet-400 shadow-lg shadow-outline-purple dark:shadow-outline-purple'
: 'border-slate-300 dark:border-slate-600 shadow-md shadow-slate-100 dark:shadow-slate-900',
resolvedSlotProps?.className,
),
};
},
input: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.input,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'col-start-1 col-end-2 row-start-1 row-end-3 text-sm font-sans leading-normal text-slate-900 bg-inherit border-0 rounded-[inherit] dark:text-slate-300 px-3 py-2 outline-0 focus-visible:outline-0 focus-visible:outline-none',
resolvedSlotProps?.className,
),
};
},
incrementButton: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.incrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▴',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-t-md border-slate-200 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-1 row-end-2',
resolvedSlotProps?.className,
),
};
},
decrementButton: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.decrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▾',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-b-md border-slate-200 border-t-0 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-2 row-end-3',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
NumberInput.propTypes = {
/**
* The props used for each slot inside the NumberInput.
* @default {}
*/
slotProps: PropTypes.shape({
decrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
incrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};
| 336 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/tailwind/index.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
NumberInputProps,
NumberInputOwnerState,
} from '@mui/base/Unstable_NumberInput';
import clsx from 'clsx';
export default function NumberInputBasic() {
const [value, setValue] = React.useState<number | undefined>();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
const resolveSlotProps = (fn: any, args: any) =>
typeof fn === 'function' ? fn(args) : fn;
const NumberInput = React.forwardRef(function NumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<BaseNumberInput
{...props}
ref={ref}
slotProps={{
root: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'grid grid-cols-[1fr_8px] grid-rows-2 overflow-hidden font-sans rounded-lg text-slate-900 dark:text-slate-300 border border-solid bg-white dark:bg-slate-900 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 p-1',
ownerState.focused
? 'border-violet-400 dark:border-violet-400 shadow-lg shadow-outline-purple dark:shadow-outline-purple'
: 'border-slate-300 dark:border-slate-600 shadow-md shadow-slate-100 dark:shadow-slate-900',
resolvedSlotProps?.className,
),
};
},
input: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.input,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'col-start-1 col-end-2 row-start-1 row-end-3 text-sm font-sans leading-normal text-slate-900 bg-inherit border-0 rounded-[inherit] dark:text-slate-300 px-3 py-2 outline-0 focus-visible:outline-0 focus-visible:outline-none',
resolvedSlotProps?.className,
),
};
},
incrementButton: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.incrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▴',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-t-md border-slate-200 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-1 row-end-2',
resolvedSlotProps?.className,
),
};
},
decrementButton: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.decrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▾',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-b-md border-slate-200 border-t-0 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-2 row-end-3',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
| 337 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputBasic/tailwind/index.tsx.preview | <NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/> | 338 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/css/index.js | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
export default function NumberInputIntroduction() {
return (
<React.Fragment>
<BaseNumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<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>
{`
.CustomNumberInput {
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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)'
};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
}
.CustomNumberInput:hover {
border-color: ${cyan[400]};
}
.CustomNumberInput.${numberInputClasses.focused} {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
.CustomNumberInput .input {
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}
.CustomNumberInput .input:focus-visible {
outline: 0;
}
.CustomNumberInput .btn {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 0;
color: ${isDarkMode ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}
.CustomNumberInput .btn:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}
.CustomNumberInput .btn.increment {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${isDarkMode ? cyan[100] : cyan[500]};
border-color: ${isDarkMode ? cyan[400] : cyan[600]};
}
}
.CustomNumberInput .btn.decrement {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${isDarkMode ? cyan[100] : cyan[500]};
border-color: ${isDarkMode ? cyan[400] : cyan[600]};
}
}
& .arrow {
transform: translateY(-1px);
}
`}
</style>
);
}
| 339 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/css/index.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
export default function NumberInputIntroduction() {
return (
<React.Fragment>
<BaseNumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<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>
{`
.CustomNumberInput {
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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)'
};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
}
.CustomNumberInput:hover {
border-color: ${cyan[400]};
}
.CustomNumberInput.${numberInputClasses.focused} {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
.CustomNumberInput .input {
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}
.CustomNumberInput .input:focus-visible {
outline: 0;
}
.CustomNumberInput .btn {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 0;
color: ${isDarkMode ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}
.CustomNumberInput .btn:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}
.CustomNumberInput .btn.increment {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${isDarkMode ? cyan[100] : cyan[500]};
border-color: ${isDarkMode ? cyan[400] : cyan[600]};
}
}
.CustomNumberInput .btn.decrement {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${isDarkMode ? grey[800] : grey[200]};
background: ${isDarkMode ? grey[900] : grey[50]};
color: ${isDarkMode ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${isDarkMode ? cyan[100] : cyan[500]};
border-color: ${isDarkMode ? cyan[400] : cyan[600]};
}
}
& .arrow {
transform: translateY(-1px);
}
`}
</style>
);
}
| 340 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/css/index.tsx.preview | <React.Fragment>
<BaseNumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<Styles />
</React.Fragment> | 341 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/system/index.js | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { styled } from '@mui/system';
const CustomNumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
return (
<BaseNumberInput
slots={{
root: StyledInputRoot,
input: StyledInputElement,
incrementButton: StyledButton,
decrementButton: StyledButton,
}}
slotProps={{
incrementButton: {
children: '▴',
},
decrementButton: {
children: '▾',
},
}}
{...props}
ref={ref}
/>
);
});
export default function NumberInputIntroduction() {
return (
<CustomNumberInput aria-label="Demo number input" placeholder="Type a number…" />
);
}
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 StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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)'
};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
&.${numberInputClasses.focused} {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
// firefox
&:focus-visible {
outline: 0;
}
`,
);
const StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const StyledButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
cursor: pointer;
}
&.${numberInputClasses.incrementButton} {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
&.${numberInputClasses.decrementButton} {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
}
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
& .arrow {
transform: translateY(-1px);
}
& .arrow {
transform: translateY(-1px);
}
`,
);
| 342 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/system/index.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
NumberInputProps,
numberInputClasses,
} from '@mui/base/Unstable_NumberInput';
import { styled } from '@mui/system';
const CustomNumberInput = React.forwardRef(function CustomNumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<BaseNumberInput
slots={{
root: StyledInputRoot,
input: StyledInputElement,
incrementButton: StyledButton,
decrementButton: StyledButton,
}}
slotProps={{
incrementButton: {
children: '▴',
},
decrementButton: {
children: '▾',
},
}}
{...props}
ref={ref}
/>
);
});
export default function NumberInputIntroduction() {
return (
<CustomNumberInput aria-label="Demo number input" placeholder="Type a number…" />
);
}
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 StyledInputRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
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)'
};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
column-gap: 8px;
padding: 4px;
&.${numberInputClasses.focused} {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
// firefox
&:focus-visible {
outline: 0;
}
`,
);
const StyledInputElement = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
`,
);
const StyledButton = styled('button')(
({ theme }) => `
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
line-height: 1;
box-sizing: border-box;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 0;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
cursor: pointer;
}
&.${numberInputClasses.incrementButton} {
grid-column: 2/3;
grid-row: 1/2;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border: 1px solid;
border-bottom: 0;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
}
&.${numberInputClasses.decrementButton} {
grid-column: 2/3;
grid-row: 2/3;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border: 1px solid;
border-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]};
}
&:hover {
cursor: pointer;
color: #FFF;
background: ${theme.palette.mode === 'dark' ? blue[600] : blue[500]};
border-color: ${theme.palette.mode === 'dark' ? blue[400] : blue[600]};
}
& .arrow {
transform: translateY(-1px);
}
& .arrow {
transform: translateY(-1px);
}
`,
);
| 343 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/system/index.tsx.preview | <CustomNumberInput aria-label="Demo number input" placeholder="Type a number…" /> | 344 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/tailwind/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import clsx from 'clsx';
export default function NumberInputIntroduction() {
const [value, setValue] = React.useState();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn);
const NumberInput = React.forwardRef(function NumberInput(props, ref) {
return (
<BaseNumberInput
{...props}
ref={ref}
slotProps={{
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'grid grid-cols-[1fr_8px] grid-rows-2 overflow-hidden font-sans rounded-lg text-slate-900 dark:text-slate-300 border border-solid bg-white dark:bg-slate-900 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 p-1',
ownerState.focused
? 'border-violet-400 dark:border-violet-400 shadow-lg shadow-outline-purple dark:shadow-outline-purple'
: 'border-slate-300 dark:border-slate-600 shadow-md shadow-slate-100 dark:shadow-slate-900',
resolvedSlotProps?.className,
),
};
},
input: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.input,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'col-start-1 col-end-2 row-start-1 row-end-3 text-sm font-sans leading-normal text-slate-900 bg-inherit border-0 rounded-[inherit] dark:text-slate-300 px-3 py-2 outline-0 focus-visible:outline-0 focus-visible:outline-none',
resolvedSlotProps?.className,
),
};
},
incrementButton: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.incrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▴',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-t-md border-slate-200 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-1 row-end-2',
resolvedSlotProps?.className,
),
};
},
decrementButton: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.decrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▾',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-b-md border-slate-200 border-t-0 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-2 row-end-3',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
NumberInput.propTypes = {
/**
* The props used for each slot inside the NumberInput.
* @default {}
*/
slotProps: PropTypes.shape({
decrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
incrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};
| 345 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/tailwind/index.tsx | import * as React from 'react';
import {
Unstable_NumberInput as BaseNumberInput,
NumberInputProps,
NumberInputOwnerState,
} from '@mui/base/Unstable_NumberInput';
import clsx from 'clsx';
export default function NumberInputIntroduction() {
const [value, setValue] = React.useState<number | undefined>();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
const resolveSlotProps = (fn: any, args: any) =>
typeof fn === 'function' ? fn(args) : fn;
const NumberInput = React.forwardRef(function NumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
return (
<BaseNumberInput
{...props}
ref={ref}
slotProps={{
root: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'grid grid-cols-[1fr_8px] grid-rows-2 overflow-hidden font-sans rounded-lg text-slate-900 dark:text-slate-300 border border-solid bg-white dark:bg-slate-900 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 p-1',
ownerState.focused
? 'border-violet-400 dark:border-violet-400 shadow-lg shadow-outline-purple dark:shadow-outline-purple'
: 'border-slate-300 dark:border-slate-600 shadow-md shadow-slate-100 dark:shadow-slate-900',
resolvedSlotProps?.className,
),
};
},
input: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.input,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'col-start-1 col-end-2 row-start-1 row-end-3 text-sm font-sans leading-normal text-slate-900 bg-inherit border-0 rounded-[inherit] dark:text-slate-300 px-3 py-2 outline-0 focus-visible:outline-0 focus-visible:outline-none',
resolvedSlotProps?.className,
),
};
},
incrementButton: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.incrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▴',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-t-md border-slate-200 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-1 row-end-2',
resolvedSlotProps?.className,
),
};
},
decrementButton: (ownerState: NumberInputOwnerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.decrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▾',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center p-0 w-[19px] h-[19px] border border-solid outline-none text-sm box-border leading-[1.2] rounded-b-md border-slate-200 border-t-0 bg-slate-50 dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-purple-500 hover:text-slate-50 dark:hover:bg-slate-800 dark:border-slate-600 col-start-3 col-end-3 row-start-2 row-end-3',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
| 346 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/number-input/NumberInputIntroduction/tailwind/index.tsx.preview | <NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/> | 347 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/pagination/pagination.md | ---
productId: base-ui
title: React Pagination component
githubLabel: 'component: Pagination'
---
# Pagination 🚧
<p class="description">The Pagination component lets the user select a specific page from a range of pages.</p>
:::warning
The Base UI Pagination component isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38042) to see it arrive sooner.
:::
| 348 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popper/PlacementPopper.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Popper } from '@mui/base/Popper';
function Radio({ value, ...props }) {
return (
<span>
<input
type="radio"
id={`placement-${value}-radio`}
name="placement"
value={value}
style={{ margin: '0 0.375rem 0 1rem' }}
{...props}
/>
<label htmlFor={`placement-${value}-radio`}>{value}</label>
</span>
);
}
Radio.propTypes = {
value: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.string),
PropTypes.number,
PropTypes.string,
]),
};
function PlacementForm({ setPlacement }) {
return (
<div
style={{
backgroundColor: 'rgba(0,0,0,0.05)',
borderRadius: '8px',
padding: '0.5rem',
}}
>
<div style={{ textAlign: 'center' }}>
<b>Placement value:</b>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['top-start', 'top', 'top-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
padding: '0.5rem 0px',
}}
>
<div>
{['left-start', 'left', 'left-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
<div>
{['right-start', 'right', 'right-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['bottom-start', 'bottom', 'bottom-end'].map((value) => (
<Radio
key={value}
value={value}
defaultChecked={value === 'bottom'}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
</div>
);
}
PlacementForm.propTypes = {
setPlacement: PropTypes.func.isRequired,
};
export default function PlacementPopper() {
const [anchorEl, setAnchorEl] = React.useState(null);
const [placement, setPlacement] = React.useState(undefined);
return (
<div style={{ width: '100%' }}>
<PlacementForm setPlacement={setPlacement} />
<div style={{ padding: '4rem 0', textAlign: 'center' }}>
<span
ref={(elm) => setAnchorEl(elm)}
aria-describedby="placement-popper"
style={{
display: 'inline-block',
backgroundColor: 'rgba(0,0,0,0.05)',
padding: '0.5rem 1rem',
borderRadius: '0.5rem',
}}
>
Anchor
</span>
<Popper
id="placement-popper"
open={Boolean(anchorEl)}
anchorEl={anchorEl}
placement={placement}
>
<div
style={{
padding: '0.5rem 1rem',
border: '1px solid',
borderColor: 'rgba(0,0,0,0.2)',
margin: '0.5rem',
borderRadius: '0.5rem',
boxShadow: '0 2px 8px 0 rgba(0,0,0,0.1)',
}}
>
The content of the Popper.
</div>
</Popper>
</div>
</div>
);
}
| 349 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popper/PlacementPopper.tsx | import * as React from 'react';
import { Popper, PopperPlacementType } from '@mui/base/Popper';
function Radio({ value, ...props }: JSX.IntrinsicElements['input']) {
return (
<span>
<input
type="radio"
id={`placement-${value}-radio`}
name="placement"
value={value}
style={{ margin: '0 0.375rem 0 1rem' }}
{...props}
/>
<label htmlFor={`placement-${value}-radio`}>{value}</label>
</span>
);
}
function PlacementForm({
setPlacement,
}: {
setPlacement: (placement: PopperPlacementType) => void;
}) {
return (
<div
style={{
backgroundColor: 'rgba(0,0,0,0.05)',
borderRadius: '8px',
padding: '0.5rem',
}}
>
<div style={{ textAlign: 'center' }}>
<b>Placement value:</b>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['top-start', 'top', 'top-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value as PopperPlacementType);
}}
/>
))}
</div>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
padding: '0.5rem 0px',
}}
>
<div>
{['left-start', 'left', 'left-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value as PopperPlacementType);
}}
/>
))}
</div>
<div>
{['right-start', 'right', 'right-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value as PopperPlacementType);
}}
/>
))}
</div>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['bottom-start', 'bottom', 'bottom-end'].map((value) => (
<Radio
key={value}
value={value}
defaultChecked={value === 'bottom'}
onChange={(event) => {
setPlacement(event.target.value as PopperPlacementType);
}}
/>
))}
</div>
</div>
);
}
export default function PlacementPopper() {
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);
const [placement, setPlacement] = React.useState<PopperPlacementType | undefined>(
undefined,
);
return (
<div style={{ width: '100%' }}>
<PlacementForm setPlacement={setPlacement} />
<div style={{ padding: '4rem 0', textAlign: 'center' }}>
<span
ref={(elm) => setAnchorEl(elm)}
aria-describedby="placement-popper"
style={{
display: 'inline-block',
backgroundColor: 'rgba(0,0,0,0.05)',
padding: '0.5rem 1rem',
borderRadius: '0.5rem',
}}
>
Anchor
</span>
<Popper
id="placement-popper"
open={Boolean(anchorEl)}
anchorEl={anchorEl}
placement={placement}
>
<div
style={{
padding: '0.5rem 1rem',
border: '1px solid',
borderColor: 'rgba(0,0,0,0.2)',
margin: '0.5rem',
borderRadius: '0.5rem',
boxShadow: '0 2px 8px 0 rgba(0,0,0,0.1)',
}}
>
The content of the Popper.
</div>
</Popper>
</div>
</div>
);
}
| 350 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popper/SimplePopper.js | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
export default function SimplePopper() {
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<div>
<button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</button>
<Popper id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</Popper>
</div>
);
}
const StyledPopperDiv = styled('div')(
({ theme }) => `
padding: 0.5rem;
border: 1px solid;
background-color: ${theme.palette.mode === 'dark' ? '#121212' : '#fff'};
opacity: 1;
margin: 0.25rem 0px;
`,
);
| 351 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popper/SimplePopper.tsx | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { styled, Theme } from '@mui/system';
export default function SimplePopper() {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<div>
<button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</button>
<Popper id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</Popper>
</div>
);
}
const StyledPopperDiv = styled('div')(
({ theme }: { theme: Theme }) => `
padding: 0.5rem;
border: 1px solid;
background-color: ${theme.palette.mode === 'dark' ? '#121212' : '#fff'};
opacity: 1;
margin: 0.25rem 0px;
`,
);
| 352 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popper/SimplePopper.tsx.preview | <button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</button>
<Popper id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</Popper> | 353 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popper/popper.md | ---
productId: base-ui
title: React Popper component
components: Popper
githubLabel: 'component: Popper'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/
---
# Popper
<p class="description">The Popper component lets you create tooltips and popovers that display information about an element on the page.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
The Popper is a utility component for creating various kinds of popups.
It relies on the third-party library ([Popper.js v2](https://popper.js.org/docs/v2/)) for positioning.
:::warning
The Popper.js library is no longer maintained.
It has been replaced by a new library: [Floating UI](https://floating-ui.com/).
Base UI offers the [Popup](/base-ui/react-popup/) component based on this new library.
It has features and an API similar to the Popper component, but is still in development and its API may change.
Once the [Popup](/base-ui/react-popup/) is stable, we will deprecate and, later, remove our Popper component.
:::
## Component
```jsx
import { Popper } from '@mui/base/Popper';
```
By default, the Popper is mounted to the DOM when its `open` prop is set to `true`, and removed from the DOM when `open` is `false`.
`anchorEl` is passed as the reference object to create a new `Popper.js` instance.
The children are placed in a [Portal](/base-ui/react-portal/) prepended to the body of the document to avoid rendering problems.
You can disable this behavior with `disablePortal` prop.
The following demo shows how to create and style a basic Popper.
Click **Toggle Popper** to see how it behaves:
{{"demo": "UnstyledPopperBasic", "defaultCodeOpen": true}}
:::warning
By default, clicking outside the popper does not hide it.
If you need this behavior, you can use the [Click-Away Listener](/base-ui/react-click-away-listener/) component.
:::
## Customization
### Placement
The Popper's default placement is `bottom`.
You can change it using the `placement` prop.
Try changing this value to `top` in the interactive demo below to see how it works:
{{"demo": "PlacementPopper.js"}}
### Transitions
You can animate the open and close states of the Popper with a render prop child and a transition component, as long as the component meets these conditions:
- Is a direct child descendant of the Popper
- Calls the `onEnter` callback prop when the enter transition starts
- Calls the `onExited` callback prop when the exit transition is completed
These two callbacks allow the Popper to unmount the child content when closed and fully transitioned.
| 354 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/css/index.js | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { useTheme } from '@mui/system';
export default function SimplePopper() {
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<React.Fragment>
<button
type="button"
aria-describedby={id}
className="Button"
onClick={handleClick}
>
Toggle Popper
</button>
<Popper id={id} open={open} anchorEl={anchorEl}>
<div className="CustomPopper">The content of the Popper.</div>
</Popper>
<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>{`
.Button {
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${cyan[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${cyan[500]};
box-shadow: 0 2px 1px ${
isDarkMode ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${cyan[400]}, inset 0 -2px 1px ${cyan[600]};
&:hover {
background-color: ${cyan[600]};
}
&:active {
background-color: ${cyan[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]};
outline: none;
}
}
.CustomPopper{
background-color: ${isDarkMode ? grey[900] : '#FFF'};
border-radius: 8px;
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: ${
isDarkMode ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)`
};
padding: 0.75rem;
color: ${isDarkMode ? grey[100] : grey[700]};
font-size: 0.875rem;
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
opacity: 1;
margin: 0.25rem 0px;
}
`}</style>
);
}
| 355 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/css/index.tsx | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { useTheme } from '@mui/system';
export default function SimplePopper() {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<React.Fragment>
<button
type="button"
aria-describedby={id}
className="Button"
onClick={handleClick}
>
Toggle Popper
</button>
<Popper id={id} open={open} anchorEl={anchorEl}>
<div className="CustomPopper">The content of the Popper.</div>
</Popper>
<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>{`
.Button {
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${cyan[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${cyan[500]};
box-shadow: 0 2px 1px ${
isDarkMode ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${cyan[400]}, inset 0 -2px 1px ${cyan[600]};
&:hover {
background-color: ${cyan[600]};
}
&:active {
background-color: ${cyan[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]};
outline: none;
}
}
.CustomPopper{
background-color: ${isDarkMode ? grey[900] : '#FFF'};
border-radius: 8px;
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: ${
isDarkMode ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)`
};
padding: 0.75rem;
color: ${isDarkMode ? grey[100] : grey[700]};
font-size: 0.875rem;
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
opacity: 1;
margin: 0.25rem 0px;
}
`}</style>
);
}
| 356 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/css/index.tsx.preview | <React.Fragment>
<button
type="button"
aria-describedby={id}
className="Button"
onClick={handleClick}
>
Toggle Popper
</button>
<Popper id={id} open={open} anchorEl={anchorEl}>
<div className="CustomPopper">The content of the Popper.</div>
</Popper>
<Styles />
</React.Fragment> | 357 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/system/index.js | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { styled, css } from '@mui/system';
export default function SimplePopper() {
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<div>
<TriggerButton aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</TriggerButton>
<Popper id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</Popper>
</div>
);
}
const blue = {
50: '#F0F7FF',
100: '#C2E0FF',
200: '#99CCF3',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 TriggerButton = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
const StyledPopperDiv = styled('div')(
({ theme }) => css`
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: ${theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`};
padding: 0.75rem;
color: ${theme.palette.mode === 'dark' ? grey[100] : grey[700]};
font-size: 0.875rem;
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
opacity: 1;
margin: 0.25rem 0;
`,
);
| 358 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/system/index.tsx | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { styled, css } from '@mui/system';
export default function SimplePopper() {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<div>
<TriggerButton aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</TriggerButton>
<Popper id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</Popper>
</div>
);
}
const blue = {
50: '#F0F7FF',
100: '#C2E0FF',
200: '#99CCF3',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 TriggerButton = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
const StyledPopperDiv = styled('div')(
({ theme }) => css`
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: ${theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`};
padding: 0.75rem;
color: ${theme.palette.mode === 'dark' ? grey[100] : grey[700]};
font-size: 0.875rem;
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
opacity: 1;
margin: 0.25rem 0;
`,
);
| 359 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/system/index.tsx.preview | <TriggerButton aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popper
</TriggerButton>
<Popper id={id} open={open} anchorEl={anchorEl}>
<StyledPopperDiv>The content of the Popper.</StyledPopperDiv>
</Popper> | 360 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/tailwind/index.js | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function SimplePopper() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
const [anchorEl, setAnchorEl] = React.useState(null);
const handleClick = (event) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<div className={`${isDarkMode ? 'dark' : ''}`}>
<button
className="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 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed disabled:shadow-none"
aria-describedby={id}
type="button"
onClick={handleClick}
>
Toggle Popper
</button>
<Popper
id={id}
open={open}
anchorEl={anchorEl}
className={`${isDarkMode ? 'dark' : ''}`}
>
<div className=" z-50 rounded-lg font-medium font-sans text-sm m-1 p-3 border border-solid border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 shadow-md text-slate-900 dark:text-slate-100">
The content of the Popper.
</div>
</Popper>
</div>
);
}
| 361 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic | petrpan-code/mui/material-ui/docs/data/base/components/popper/UnstyledPopperBasic/tailwind/index.tsx | import * as React from 'react';
import { Popper } from '@mui/base/Popper';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function SimplePopper() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchorEl(anchorEl ? null : event.currentTarget);
};
const open = Boolean(anchorEl);
const id = open ? 'simple-popper' : undefined;
return (
<div className={`${isDarkMode ? 'dark' : ''}`}>
<button
className="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 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed disabled:shadow-none"
aria-describedby={id}
type="button"
onClick={handleClick}
>
Toggle Popper
</button>
<Popper
id={id}
open={open}
anchorEl={anchorEl}
className={`${isDarkMode ? 'dark' : ''}`}
>
<div className=" z-50 rounded-lg font-medium font-sans text-sm m-1 p-3 border border-solid border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 shadow-md text-slate-900 dark:text-slate-100">
The content of the Popper.
</div>
</Popper>
</div>
);
}
| 362 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/AnimatedPopup.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/system';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
export default function AnimatedPopup() {
const [anchor, setAnchor] = React.useState(null);
const [open, setOpen] = React.useState(false);
return (
<div>
<Button ref={setAnchor} onClick={() => setOpen((o) => !o)} type="button">
Toggle Popup
</Button>
<BasePopup anchor={anchor} open={open} withTransition>
{(props) => (
<PopAnimation {...props}>
<PopupBody>This is an animated popup.</PopupBody>
</PopAnimation>
)}
</BasePopup>
</div>
);
}
function Animated(props) {
const { requestOpen, onEnter, onExited, children, className } = props;
React.useEffect(() => {
if (requestOpen) {
onEnter();
}
}, [onEnter, requestOpen]);
const handleAnimationEnd = React.useCallback(() => {
if (!requestOpen) {
onExited();
}
}, [onExited, requestOpen]);
return (
<div
onAnimationEnd={handleAnimationEnd}
className={className + (requestOpen ? ' open' : ' close')}
>
{children}
</div>
);
}
Animated.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
onEnter: PropTypes.func.isRequired,
onExited: PropTypes.func.isRequired,
requestOpen: PropTypes.bool.isRequired,
};
const PopAnimation = styled(Animated)`
@keyframes open-animation {
0% {
opacity: 0;
transform: translateY(-8px) scale(0.95);
}
50% {
opacity: 1;
transform: translateY(4px) scale(1.05);
}
100% {
opacity: 1;
transform: translateY(0) scale(1);
}
}
@keyframes close-animation {
0% {
opacity: 1;
transform: translateY(0) scale(1);
}
50% {
opacity: 1;
transform: translateY(4px) scale(1.05);
}
100% {
opacity: 0;
transform: translateY(-8px) scale(0.95);
}
}
&.open {
animation: open-animation 0.4s ease-in forwards;
}
&.close {
animation: close-animation 0.4s ease-in forwards;
}
`;
const grey = {
50: '#f6f8fa',
200: '#d0d7de',
500: '#6e7781',
700: '#424a53',
900: '#24292f',
};
const PopupBody = styled('div')(
({ theme }) => `
width: max-content;
padding: 0.5rem 1rem;
margin: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
border-radius: 8px;
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
min-height: 3rem;
display: flex;
align-items: center;
`,
);
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 363 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/AnimatedPopup.tsx | import * as React from 'react';
import { styled, Theme } from '@mui/system';
import {
Unstable_Popup as BasePopup,
PopupChildrenProps,
} from '@mui/base/Unstable_Popup';
export default function AnimatedPopup() {
const [anchor, setAnchor] = React.useState<HTMLButtonElement | null>(null);
const [open, setOpen] = React.useState(false);
return (
<div>
<Button ref={setAnchor} onClick={() => setOpen((o) => !o)} type="button">
Toggle Popup
</Button>
<BasePopup anchor={anchor} open={open} withTransition>
{(props: PopupChildrenProps) => (
<PopAnimation {...props}>
<PopupBody>This is an animated popup.</PopupBody>
</PopAnimation>
)}
</BasePopup>
</div>
);
}
function Animated(
props: React.PropsWithChildren<{
className?: string;
requestOpen: boolean;
onEnter: () => void;
onExited: () => void;
}>,
) {
const { requestOpen, onEnter, onExited, children, className } = props;
React.useEffect(() => {
if (requestOpen) {
onEnter();
}
}, [onEnter, requestOpen]);
const handleAnimationEnd = React.useCallback(() => {
if (!requestOpen) {
onExited();
}
}, [onExited, requestOpen]);
return (
<div
onAnimationEnd={handleAnimationEnd}
className={className + (requestOpen ? ' open' : ' close')}
>
{children}
</div>
);
}
const PopAnimation = styled(Animated)`
@keyframes open-animation {
0% {
opacity: 0;
transform: translateY(-8px) scale(0.95);
}
50% {
opacity: 1;
transform: translateY(4px) scale(1.05);
}
100% {
opacity: 1;
transform: translateY(0) scale(1);
}
}
@keyframes close-animation {
0% {
opacity: 1;
transform: translateY(0) scale(1);
}
50% {
opacity: 1;
transform: translateY(4px) scale(1.05);
}
100% {
opacity: 0;
transform: translateY(-8px) scale(0.95);
}
}
&.open {
animation: open-animation 0.4s ease-in forwards;
}
&.close {
animation: close-animation 0.4s ease-in forwards;
}
`;
const grey = {
50: '#f6f8fa',
200: '#d0d7de',
500: '#6e7781',
700: '#424a53',
900: '#24292f',
};
const PopupBody = styled('div')(
({ theme }: { theme: Theme }) => `
width: max-content;
padding: 0.5rem 1rem;
margin: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
border-radius: 8px;
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
min-height: 3rem;
display: flex;
align-items: center;
`,
);
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 364 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/AnimatedPopup.tsx.preview | <Button ref={setAnchor} onClick={() => setOpen((o) => !o)} type="button">
Toggle Popup
</Button>
<BasePopup anchor={anchor} open={open} withTransition>
{(props: PopupChildrenProps) => (
<PopAnimation {...props}>
<PopupBody>This is an animated popup.</PopupBody>
</PopAnimation>
)}
</BasePopup> | 365 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/DisabledPortalPopup.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { Box, styled } from '@mui/system';
export default function DisabledPortalPopup() {
return (
<Box
sx={{
display: 'flex',
gap: '10px',
overflowY: 'auto',
position: 'relative',
padding: '40px',
}}
>
<PopupWithTrigger id="popup-with-portal" buttonLabel="With a portal" />
<PopupWithTrigger
id="popup-without-portal"
buttonLabel="No portal, default strategy"
disablePortal
/>
<PopupWithTrigger
id="popup-without-portal-fixed"
buttonLabel="No portal, 'fixed' strategy"
disablePortal
strategy="fixed"
/>
</Box>
);
}
function PopupWithTrigger(props) {
const { id, buttonLabel, ...other } = props;
const [anchor, setAnchor] = React.useState(null);
const handleClick = (event) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
return (
<div>
<Button aria-describedby={id} type="button" onClick={handleClick}>
{buttonLabel}
</Button>
<Popup id={id} open={open} anchor={anchor} {...other}>
<PopupBody>{buttonLabel}</PopupBody>
</Popup>
</div>
);
}
PopupWithTrigger.propTypes = {
buttonLabel: PropTypes.string.isRequired,
id: PropTypes.string,
};
const Popup = styled(BasePopup)`
z-index: 1;
`;
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const PopupBody = styled('div')(
({ theme }) => `
width: max-content;
height: 150px;
display: flex;
align-items: center;
padding: 16px;
margin: 8px;
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
`,
);
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 366 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/DisabledPortalPopup.tsx | import * as React from 'react';
import { Unstable_Popup as BasePopup, PopupProps } from '@mui/base/Unstable_Popup';
import { Box, styled, Theme } from '@mui/system';
export default function DisabledPortalPopup() {
return (
<Box
sx={{
display: 'flex',
gap: '10px',
overflowY: 'auto',
position: 'relative',
padding: '40px',
}}
>
<PopupWithTrigger id="popup-with-portal" buttonLabel="With a portal" />
<PopupWithTrigger
id="popup-without-portal"
buttonLabel="No portal, default strategy"
disablePortal
/>
<PopupWithTrigger
id="popup-without-portal-fixed"
buttonLabel="No portal, 'fixed' strategy"
disablePortal
strategy="fixed"
/>
</Box>
);
}
function PopupWithTrigger(props: PopupProps & { buttonLabel: string }) {
const { id, buttonLabel, ...other } = props;
const [anchor, setAnchor] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
return (
<div>
<Button aria-describedby={id} type="button" onClick={handleClick}>
{buttonLabel}
</Button>
<Popup id={id} open={open} anchor={anchor} {...other}>
<PopupBody>{buttonLabel}</PopupBody>
</Popup>
</div>
);
}
const Popup = styled(BasePopup)`
z-index: 1;
`;
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const PopupBody = styled('div')(
({ theme }: { theme: Theme }) => `
width: max-content;
height: 150px;
display: flex;
align-items: center;
padding: 16px;
margin: 8px;
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
`,
);
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 367 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/DisabledPortalPopup.tsx.preview | <PopupWithTrigger id="popup-with-portal" buttonLabel="With a portal" />
<PopupWithTrigger
id="popup-without-portal"
buttonLabel="No portal, default strategy"
disablePortal
/>
<PopupWithTrigger
id="popup-without-portal-fixed"
buttonLabel="No portal, 'fixed' strategy"
disablePortal
strategy="fixed"
/> | 368 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/Placement.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { styled, css } from '@mui/system';
function Radio({ value, ...props }) {
return (
<span>
<input
type="radio"
id={`placement-${value}-radio`}
name="placement"
value={value}
style={{ margin: '0 0.375rem 0 1rem' }}
{...props}
/>
<label htmlFor={`placement-${value}-radio`}>{value}</label>
</span>
);
}
Radio.propTypes = {
value: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.string),
PropTypes.number,
PropTypes.string,
]),
};
function PlacementForm({ setPlacement }) {
return (
<PlacementFormBackground>
<div style={{ textAlign: 'center' }}>
<b>Placement value:</b>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['top-start', 'top', 'top-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
padding: '0.5rem 0px',
}}
>
<div>
{['left-start', 'left', 'left-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
<div>
{['right-start', 'right', 'right-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['bottom-start', 'bottom', 'bottom-end'].map((value) => (
<Radio
key={value}
value={value}
defaultChecked={value === 'bottom'}
onChange={(event) => {
setPlacement(event.target.value);
}}
/>
))}
</div>
</PlacementFormBackground>
);
}
PlacementForm.propTypes = {
setPlacement: PropTypes.func.isRequired,
};
export default function Placement() {
const [anchor, setAnchor] = React.useState(null);
const [placement, setPlacement] = React.useState('bottom');
return (
<div style={{ width: '100%' }}>
<PlacementForm setPlacement={setPlacement} />
<div style={{ padding: '4rem 0', textAlign: 'center' }}>
<Anchor ref={setAnchor} aria-describedby="placement-popper">
Anchor
</Anchor>
<BasePopup
id="placement-popper"
open={Boolean(anchor)}
anchor={anchor}
placement={placement}
offset={4}
>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div>
</div>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const PopupBody = styled('div')(
({ theme }) => css`
padding: 0.5rem 1rem;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
border-radius: 8px;
box-shadow: ${theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`};
min-height: 3rem;
display: flex;
align-items: center;
`,
);
const Anchor = styled('span')(
({ theme }) => css`
display: inline-block;
background-color: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
padding: 0.5rem 1rem;
border-radius: 0.5rem;
`,
);
const PlacementFormBackground = styled('div')`
background-color: rgb(0 0 0 / 0.05);
border-radius: 8px;
padding: 0.5rem;
font-family: 'IBM Plex Sans', sans-serif;
& input {
font-family: inherit;
}
`;
| 369 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/Placement.tsx | import * as React from 'react';
import {
Unstable_Popup as BasePopup,
PopupPlacement,
} from '@mui/base/Unstable_Popup';
import { styled, css, Theme } from '@mui/system';
function Radio({ value, ...props }: JSX.IntrinsicElements['input']) {
return (
<span>
<input
type="radio"
id={`placement-${value}-radio`}
name="placement"
value={value}
style={{ margin: '0 0.375rem 0 1rem' }}
{...props}
/>
<label htmlFor={`placement-${value}-radio`}>{value}</label>
</span>
);
}
function PlacementForm({
setPlacement,
}: {
setPlacement: (placement: PopupPlacement) => void;
}) {
return (
<PlacementFormBackground>
<div style={{ textAlign: 'center' }}>
<b>Placement value:</b>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['top-start', 'top', 'top-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value as PopupPlacement);
}}
/>
))}
</div>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
padding: '0.5rem 0px',
}}
>
<div>
{['left-start', 'left', 'left-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value as PopupPlacement);
}}
/>
))}
</div>
<div>
{['right-start', 'right', 'right-end'].map((value) => (
<Radio
key={value}
value={value}
onChange={(event) => {
setPlacement(event.target.value as PopupPlacement);
}}
/>
))}
</div>
</div>
<div style={{ textAlign: 'center', padding: '0.5rem 0px' }}>
{['bottom-start', 'bottom', 'bottom-end'].map((value) => (
<Radio
key={value}
value={value}
defaultChecked={value === 'bottom'}
onChange={(event) => {
setPlacement(event.target.value as PopupPlacement);
}}
/>
))}
</div>
</PlacementFormBackground>
);
}
export default function Placement() {
const [anchor, setAnchor] = React.useState<HTMLElement | null>(null);
const [placement, setPlacement] = React.useState<PopupPlacement>('bottom');
return (
<div style={{ width: '100%' }}>
<PlacementForm setPlacement={setPlacement} />
<div style={{ padding: '4rem 0', textAlign: 'center' }}>
<Anchor ref={setAnchor} aria-describedby="placement-popper">
Anchor
</Anchor>
<BasePopup
id="placement-popper"
open={Boolean(anchor)}
anchor={anchor}
placement={placement}
offset={4}
>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div>
</div>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const PopupBody = styled('div')(
({ theme }: { theme: Theme }) => css`
padding: 0.5rem 1rem;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
border-radius: 8px;
box-shadow: ${theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`};
min-height: 3rem;
display: flex;
align-items: center;
`,
);
const Anchor = styled('span')(
({ theme }: { theme: Theme }) => css`
display: inline-block;
background-color: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
padding: 0.5rem 1rem;
border-radius: 0.5rem;
`,
);
const PlacementFormBackground = styled('div')`
background-color: rgb(0 0 0 / 0.05);
border-radius: 8px;
padding: 0.5rem;
font-family: 'IBM Plex Sans', sans-serif;
& input {
font-family: inherit;
}
`;
| 370 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/Placement.tsx.preview | <PlacementForm setPlacement={setPlacement} />
<div style={{ padding: '4rem 0', textAlign: 'center' }}>
<Anchor ref={setAnchor} aria-describedby="placement-popper">
Anchor
</Anchor>
<BasePopup
id="placement-popper"
open={Boolean(anchor)}
anchor={anchor}
placement={placement}
offset={4}
>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div> | 371 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/SimplePopup.js | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { styled } from '@mui/system';
export default function SimplePopup() {
const [anchor, setAnchor] = React.useState(null);
const handleClick = (event) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popper' : undefined;
return (
<div>
<Button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popup
</Button>
<BasePopup id={id} open={open} anchor={anchor}>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const PopupBody = styled('div')(
({ theme }) => `
width: max-content;
padding: 12px 16px;
margin: 8px;
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
z-index: 1;
`,
);
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 372 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/SimplePopup.tsx | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { styled } from '@mui/system';
export default function SimplePopup() {
const [anchor, setAnchor] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popper' : undefined;
return (
<div>
<Button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popup
</Button>
<BasePopup id={id} open={open} anchor={anchor}>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const PopupBody = styled('div')(
({ theme }) => `
width: max-content;
padding: 12px 16px;
margin: 8px;
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
z-index: 1;
`,
);
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 1px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 373 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/SimplePopup.tsx.preview | <Button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popup
</Button>
<BasePopup id={id} open={open} anchor={anchor}>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup> | 374 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/popup/popup.md | ---
productId: base-ui
title: React Popup component
components: Popup
githubLabel: 'component: popup'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/
---
# Popup
<p class="description">The Popup component is a utility that lets you display content in tooltips and popovers.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
The Popup is a utility component for creating various kinds of popups.
It relies on the third-party [Floating UI](https://floating-ui.com/) library for positioning.
{{"demo": "UnstyledPopupIntroduction", "defaultCodeOpen": false, "bg": "gradient"}}
:::info
The Popup component, once stable, is intended to replace the [Popper](/base-ui/react-popper/) component, which will be phased out in a future release of Base UI.
:::
## Component
```jsx
import { Unstable_Popup as Popup } from '@mui/base/Unstable_Popup';
```
By default, the Popup is mounted to the DOM when its `open` prop is set to `true`, and removed from the DOM when `open` is `false`.
`anchor` is passed as the reference element to Floating UI's [`useFloating`](https://floating-ui.com/docs/react#positioning) hook.
The children are placed in a [Portal](/base-ui/react-portal/) prepended to the body of the document to avoid rendering problems.
You can disable this behavior with `disablePortal` prop.
See how it's done in the [Disable portal](#disable-portal) section below.
The following demo shows how to create and style a basic Popup.
Click **Toggle Popup** to see how it behaves:
{{"demo": "SimplePopup.js", "defaultCodeOpen": true}}
:::warning
By default, clicking outside the Popup doesn't hide it.
If you need this behavior, you can use the [Click-Away Listener](/base-ui/react-click-away-listener/) component.
:::
## Customization
### Placement
The Popup's default placement is `bottom`.
You can change it using the `placement` prop.
Try changing this value to `top` in the interactive demo below to see how it works:
{{"demo": "Placement.js", "defaultCodeOpen": false }}
### Transitions
You can animate the opening and closing of the Popup using CSS transitions, CSS animations, or third-party animation libraries.
To enable transitions, first set the `withTransition` prop.
This will make the Popup wait for the exit animation to finish before unmounting.
Then, instead of placing the Popup contents directly as its children, wrap them in a function that receives an object with `requestOpen: boolean`, `onEnter: () => void`, and `onExited: () => void` fields.
Run the open transition when `requestOpen` becomes `true` and the close transition when it changes to `false`.
Call the `onEnter` once the entering transition is about to start.
When the exit transition finishes, call the provided `onExited` function to let the Popup know it can be unmounted.
If using CSS transitions or animations, you can use the `onTransitionEnd` or `onAnimationEnd` events, respectively, to detect when the transition is over.
{{"demo": "AnimatedPopup.js"}}
### Disable portal
To render the Popup where it's defined in the source, without using [React portals](https://react.dev/reference/react-dom/createPortal), pass in the `disablePortal` prop.
Note that it may cause visual clipping if a Popup is placed in a container without visible overflow.
You can use fixed positioning to prevent clipping when not using portals.
The Popup has the `strategy` prop which is responsible for determining how the position is calculated.
When set to `"fixed"`, the fixed CSS position will be used and the Popup won't be subject to overflow hiding.
{{"demo": "DisabledPortalPopup.js"}}
### Floating UI middleware
If you need to modify the underlying [Floating UI middleware](https://floating-ui.com/docs/middleware), you can do so via the `middleware` prop.
By default, the Popup uses the [`offset`](https://floating-ui.com/docs/offset) (with the value provided in the `offset` prop) and [`flip`](https://floating-ui.com/docs/flip) functions.
If you provide your own middleware array, these defaults won't be applied.
| 375 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/css/index.js | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { useTheme } from '@mui/system';
export default function SimplePopup() {
const [anchor, setAnchor] = React.useState(null);
const handleClick = (event) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popup' : undefined;
return (
<React.Fragment>
<button
type="button"
aria-describedby={id}
className="Button"
onClick={handleClick}
>
Toggle Popup
</button>
<BasePopup id={id} open={open} anchor={anchor}>
<div className="CustomPopup">The content of the Popup.</div>
</BasePopup>
<Styles />
</React.Fragment>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};
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>{`
.Button {
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${cyan[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${cyan[500]};
box-shadow: 0 2px 4px ${
isDarkMode ? 'rgba(0, 0, 0, 0.5)' : 'rgba(13, 84, 99, 0.5)'
}, inset 0 1.5px 1px ${cyan[400]}, inset 0 -2px 1px ${cyan[600]};
&:hover {
background-color: ${cyan[600]};
}
&:active {
background-color: ${cyan[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]};
outline: none;
}
}
.CustomPopup{
background-color: ${isDarkMode ? grey[900] : '#FFF'};
border-radius: 8px;
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: ${
isDarkMode ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)`
};
padding: 0.75rem;
color: ${isDarkMode ? cyan[100] : cyan[700]};
font-size: 0.875rem;
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
opacity: 1;
margin: 0.5rem 0px;
}
`}</style>
);
}
| 376 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/css/index.tsx | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { useTheme } from '@mui/system';
export default function SimplePopup() {
const [anchor, setAnchor] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popup' : undefined;
return (
<React.Fragment>
<button
type="button"
aria-describedby={id}
className="Button"
onClick={handleClick}
>
Toggle Popup
</button>
<BasePopup id={id} open={open} anchor={anchor}>
<div className="CustomPopup">The content of the Popup.</div>
</BasePopup>
<Styles />
</React.Fragment>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};
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>{`
.Button {
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${cyan[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${cyan[500]};
box-shadow: 0 2px 4px ${
isDarkMode ? 'rgba(0, 0, 0, 0.5)' : 'rgba(13, 84, 99, 0.5)'
}, inset 0 1.5px 1px ${cyan[400]}, inset 0 -2px 1px ${cyan[600]};
&:hover {
background-color: ${cyan[600]};
}
&:active {
background-color: ${cyan[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]};
outline: none;
}
}
.CustomPopup{
background-color: ${isDarkMode ? grey[900] : '#FFF'};
border-radius: 8px;
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: ${
isDarkMode ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)`
};
padding: 0.75rem;
color: ${isDarkMode ? cyan[100] : cyan[700]};
font-size: 0.875rem;
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
opacity: 1;
margin: 0.5rem 0px;
}
`}</style>
);
}
| 377 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/css/index.tsx.preview | <React.Fragment>
<button
type="button"
aria-describedby={id}
className="Button"
onClick={handleClick}
>
Toggle Popup
</button>
<BasePopup id={id} open={open} anchor={anchor}>
<div className="CustomPopup">The content of the Popup.</div>
</BasePopup>
<Styles />
</React.Fragment> | 378 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/system/index.js | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { styled } from '@mui/system';
export default function SimplePopup() {
const [anchor, setAnchor] = React.useState(null);
const handleClick = (event) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popup' : undefined;
return (
<div>
<Button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popup
</Button>
<BasePopup id={id} open={open} anchor={anchor}>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const PopupBody = styled('div')(
({ theme }) => `
width: max-content;
padding: 12px 16px;
margin: 8px;
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
font-size: 0.875rem;
z-index: 1;
`,
);
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 127, 255, 0.5)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 379 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/system/index.tsx | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { styled } from '@mui/system';
export default function SimplePopup() {
const [anchor, setAnchor] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popup' : undefined;
return (
<div>
<Button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popup
</Button>
<BasePopup id={id} open={open} anchor={anchor}>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup>
</div>
);
}
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const blue = {
200: '#99CCFF',
300: '#66B2FF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0066CC',
};
const PopupBody = styled('div')(
({ theme }) => `
width: max-content;
padding: 12px 16px;
margin: 8px;
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'};
box-shadow: ${
theme.palette.mode === 'dark'
? `0px 4px 8px rgb(0 0 0 / 0.7)`
: `0px 4px 8px rgb(0 0 0 / 0.1)`
};
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 500;
font-size: 0.875rem;
z-index: 1;
`,
);
const Button = styled('button')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
background-color: ${blue[500]};
padding: 8px 16px;
border-radius: 8px;
color: white;
transition: all 150ms ease;
cursor: pointer;
border: 1px solid ${blue[500]};
box-shadow: 0 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 127, 255, 0.5)'
}, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]};
&:hover {
background-color: ${blue[600]};
}
&:active {
background-color: ${blue[700]};
box-shadow: none;
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
opacity: 0.4;
cursor: not-allowed;
box-shadow: none;
&:hover {
background-color: ${blue[500]};
}
}
`,
);
| 380 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/system/index.tsx.preview | <Button aria-describedby={id} type="button" onClick={handleClick}>
Toggle Popup
</Button>
<BasePopup id={id} open={open} anchor={anchor}>
<PopupBody>The content of the Popup.</PopupBody>
</BasePopup> | 381 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/tailwind/index.js | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function SimplePopup() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
const [anchor, setAnchor] = React.useState(null);
const handleClick = (event) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popup' : undefined;
return (
<div className={`${isDarkMode ? 'dark' : undefined}`}>
<button
className="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 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed disabled:shadow-none"
aria-describedby={id}
type="button"
onClick={handleClick}
>
Toggle Popup
</button>
<BasePopup
id={id}
open={open}
anchor={anchor}
disablePortal
className="z-50 rounded-lg font-sans font-medium text-sm mt-2 p-3 border border-solid border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 shadow-md text-slate-900 dark:text-slate-100"
>
<div>The content of the Popup.</div>
</BasePopup>
</div>
);
}
| 382 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/popup/UnstyledPopupIntroduction/tailwind/index.tsx | import * as React from 'react';
import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function SimplePopup() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
const [anchor, setAnchor] = React.useState<null | HTMLElement>(null);
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
setAnchor(anchor ? null : event.currentTarget);
};
const open = Boolean(anchor);
const id = open ? 'simple-popup' : undefined;
return (
<div className={`${isDarkMode ? 'dark' : undefined}`}>
<button
className="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 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed disabled:shadow-none"
aria-describedby={id}
type="button"
onClick={handleClick}
>
Toggle Popup
</button>
<BasePopup
id={id}
open={open}
anchor={anchor}
disablePortal
className="z-50 rounded-lg font-sans font-medium text-sm mt-2 p-3 border border-solid border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 shadow-md text-slate-900 dark:text-slate-100"
>
<div>The content of the Popup.</div>
</BasePopup>
</div>
);
}
| 383 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/portal/SimplePortal.js | import * as React from 'react';
import { Portal } from '@mui/base/Portal';
import { Box } from '@mui/system';
export default function SimplePortal() {
const [show, setShow] = React.useState(false);
const container = React.useRef(null);
const handleClick = () => {
setShow(!show);
};
return (
<div>
<button type="button" onClick={handleClick}>
{show ? 'Unmount children' : 'Mount children'}
</button>
<Box sx={{ p: 1, my: 1, border: '1px solid' }}>
It looks like I will render here.
{show ? (
<Portal container={container.current}>
<span>But I actually render here!</span>
</Portal>
) : null}
</Box>
<Box sx={{ p: 1, my: 1, border: '1px solid' }} ref={container} />
</div>
);
}
| 384 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/portal/SimplePortal.tsx | import * as React from 'react';
import { Portal } from '@mui/base/Portal';
import { Box } from '@mui/system';
export default function SimplePortal() {
const [show, setShow] = React.useState(false);
const container = React.useRef(null);
const handleClick = () => {
setShow(!show);
};
return (
<div>
<button type="button" onClick={handleClick}>
{show ? 'Unmount children' : 'Mount children'}
</button>
<Box sx={{ p: 1, my: 1, border: '1px solid' }}>
It looks like I will render here.
{show ? (
<Portal container={container.current}>
<span>But I actually render here!</span>
</Portal>
) : null}
</Box>
<Box sx={{ p: 1, my: 1, border: '1px solid' }} ref={container} />
</div>
);
}
| 385 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/portal/SimplePortal.tsx.preview | <button type="button" onClick={handleClick}>
{show ? 'Unmount children' : 'Mount children'}
</button>
<Box sx={{ p: 1, my: 1, border: '1px solid' }}>
It looks like I will render here.
{show ? (
<Portal container={container.current}>
<span>But I actually render here!</span>
</Portal>
) : null}
</Box>
<Box sx={{ p: 1, my: 1, border: '1px solid' }} ref={container} /> | 386 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/portal/portal.md | ---
productId: base-ui
title: React Portal component
components: Portal
githubLabel: 'component: Portal'
---
# Portal
<p class="description">The Portal component lets you render its children into a DOM node that exists outside of the Portal's own DOM hierarchy.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
Portal is a utility component built around [React's `createPortal()` API](https://react.dev/reference/react-dom/createPortal).
It gives you the functionality of `createPortal()` in a convenient component form.
The Portal component is used internally by the [Modal](/base-ui/react-modal/) and [Popper](/base-ui/react-popper/) components.
## Component
```jsx
import { Portal } from '@mui/base/Portal';
```
Normally, children of a component are rendered within that component's DOM tree.
But sometimes it's necessary to mount a child at a different location in the DOM.
:::info
According to [the React docs](https://react.dev/reference/react-dom/createPortal), portals are useful when "you need the child element to visually 'break out' of its container"—for instance, modals and tooltips, which need to exist outside of the normal flow of the document.
:::
The Portal component accepts a `container` prop that passes a `ref` to the DOM node where its children will be mounted.
The following demo shows how a `<span>` nested within a Portal can be appended to a node outside of the Portal's DOM hierarchy—click **Mount children** to see how it behaves:
{{"demo": "SimplePortal.js"}}
### Server-side
:::error
React doesn't support the [`createPortal()` API](https://react.dev/reference/react-dom/createPortal) on the server.
See [this GitHub issue](https://github.com/facebook/react/issues/13097) for details.
:::
The Portal component cannot be used to render child elements on the server—client-side hydration is necessary.
| 387 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/radio-button/radio-button.md | ---
productId: base-ui
title: React Radio Button component
githubLabel: 'component: radio'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/radio/
---
# Radio Button 🚧
<p class="description">Radio buttons enable the user to select one option from a set.</p>
:::warning
The Base UI Radio Button component isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38038) to see it arrive sooner.
:::
| 388 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/rating/rating.md | ---
productId: base-ui
title: React Rating component
githubLabel: 'component: rating'
waiAria: https://www.w3.org/WAI/tutorials/forms/custom-controls/#a-star-rating
---
# Rating 🚧
<p class="description">Rating components provide users with a simple action to give feedback as well as assess the opinions of others.</p>
:::warning
The Base UI Rating component isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38043) to see it arrive sooner.
:::
| 389 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectControlled.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Select as BaseSelect, selectClasses } from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectControlled() {
const [value, setValue] = React.useState(10);
return (
<div>
<Select value={value} onChange={(_, newValue) => setValue(newValue)}>
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
<Paragraph>Selected value: {value}</Paragraph>
</div>
);
}
function Select(props) {
const slots = {
root: StyledButton,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} slots={slots} />;
}
Select.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};
const blue = {
100: '#DAECFF',
200: '#99CCF3',
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 CustomButton = React.forwardRef(function CustomButton(props, ref) {
const { ownerState, ...other } = props;
return (
<button
type="button"
{...other}
ref={ref}
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<span>{other.children}</span>
<UnfoldMoreRoundedIcon />
</button>
);
});
CustomButton.propTypes = {
children: PropTypes.node,
ownerState: PropTypes.object.isRequired,
};
const StyledButton = styled(CustomButton, { shouldForwardProp: () => true })(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
& > svg {
font-size: 1rem;
vertical-align: middle;
}
`,
);
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: 320px;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const Popper = styled(BasePopper)`
z-index: 1;
`;
const Paragraph = styled('p')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
margin: 10px 0;
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]};
`,
);
| 390 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectControlled.tsx | import * as React from 'react';
import {
Select as BaseSelect,
SelectProps,
selectClasses,
SelectRootSlotProps,
} from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectControlled() {
const [value, setValue] = React.useState<number | null>(10);
return (
<div>
<Select value={value} onChange={(_, newValue) => setValue(newValue)}>
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
<Paragraph>Selected value: {value}</Paragraph>
</div>
);
}
function Select(props: SelectProps<number, false>) {
const slots: SelectProps<number, false>['slots'] = {
root: StyledButton,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} slots={slots} />;
}
const blue = {
100: '#DAECFF',
200: '#99CCF3',
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 CustomButton = React.forwardRef(function CustomButton(
props: SelectRootSlotProps<number, false>,
ref: React.ForwardedRef<HTMLButtonElement>,
) {
const { ownerState, ...other } = props;
return (
<button
type="button"
{...other}
ref={ref}
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<span>{other.children}</span>
<UnfoldMoreRoundedIcon />
</button>
);
});
const StyledButton = styled(CustomButton, { shouldForwardProp: () => true })(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
& > svg {
font-size: 1rem;
vertical-align: middle;
}
`,
);
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: 320px;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const Popper = styled(BasePopper)`
z-index: 1;
`;
const Paragraph = styled('p')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
margin: 10px 0;
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]};
`,
);
| 391 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectControlled.tsx.preview | <Select value={value} onChange={(_, newValue) => setValue(newValue)}>
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
<Paragraph>Selected value: {value}</Paragraph> | 392 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectCustomRenderValue.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Select as BaseSelect, selectClasses } from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectCustomRenderValue() {
return (
<Select
defaultValue={10}
renderValue={(option) => {
if (option == null || option.value === null) {
return 'Select an option…';
}
return `${option.label} (${option.value})`;
}}
>
<Option value={null}>None</Option>
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
);
}
function Select(props) {
const slots = {
root: Button,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} slots={slots} />;
}
Select.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};
const blue = {
100: '#DAECFF',
200: '#99CCF3',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 Button = React.forwardRef(function Button(props, ref) {
const { ownerState, ...other } = props;
return (
<StyledButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledButton>
);
});
Button.propTypes = {
children: PropTypes.node,
ownerState: PropTypes.object.isRequired,
};
const StyledButton = styled('button', { shouldForwardProp: () => true })(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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]};
position: relative;
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
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: 320px;
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 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const Popper = styled(BasePopper)`
z-index: 1;
`;
| 393 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectCustomRenderValue.tsx | import * as React from 'react';
import {
Select as BaseSelect,
SelectProps,
selectClasses,
SelectRootSlotProps,
} from '@mui/base/Select';
import { SelectOption } from '@mui/base/useOption';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectCustomRenderValue() {
return (
<Select
defaultValue={10}
renderValue={(option: SelectOption<number> | null) => {
if (option == null || option.value === null) {
return 'Select an option…';
}
return `${option.label} (${option.value})`;
}}
>
<Option value={null}>None</Option>
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
);
}
function Select(props: SelectProps<number, false>) {
const slots: SelectProps<number, false>['slots'] = {
root: Button,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} slots={slots} />;
}
const blue = {
100: '#DAECFF',
200: '#99CCF3',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
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 Button = React.forwardRef(function Button<
TValue extends {},
Multiple extends boolean,
>(
props: SelectRootSlotProps<TValue, Multiple>,
ref: React.ForwardedRef<HTMLButtonElement>,
) {
const { ownerState, ...other } = props;
return (
<StyledButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledButton>
);
});
const StyledButton = styled('button', { shouldForwardProp: () => true })(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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]};
position: relative;
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
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: 320px;
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 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const Popper = styled(BasePopper)`
z-index: 1;
`;
| 394 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectCustomRenderValue.tsx.preview | <Select
defaultValue={10}
renderValue={(option: SelectOption<number> | null) => {
if (option == null || option.value === null) {
return 'Select an option…';
}
return `${option.label} (${option.value})`;
}}
>
<Option value={null}>None</Option>
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select> | 395 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectForm.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Select as BaseSelect, selectClasses } from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled, Box } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectForm() {
return (
<div>
<Box sx={{ mb: 2 }}>
<Label htmlFor="unnamed-select">Default</Label>
<Select defaultValue={10} id="unnamed-select">
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
</Box>
<div>
<Label htmlFor="named-select">
With the <code>name</code> prop
</Label>
<Select defaultValue={10} id="named-select" name="demo-select">
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
</div>
</div>
);
}
const Select = React.forwardRef(function CustomSelect(props, ref) {
const slots = {
root: Button,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} ref={ref} slots={slots} />;
});
const blue = {
100: '#DAECFF',
200: '#99CCF3',
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 Button = React.forwardRef(function Button(props, ref) {
const { ownerState, ...other } = props;
return (
<StyledButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledButton>
);
});
Button.propTypes = {
children: PropTypes.node,
ownerState: PropTypes.object.isRequired,
};
const StyledButton = styled('button', { shouldForwardProp: () => true })(
({ theme }) => `
position: relative;
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
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: 320px;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const Popper = styled(BasePopper)`
z-index: 1;
`;
const Label = styled('label')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.85rem;
display: block;
margin-bottom: 4px;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]};
`,
);
| 396 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectForm.tsx | import * as React from 'react';
import {
Select as BaseSelect,
SelectProps,
selectClasses,
SelectRootSlotProps,
} from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled, Box } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectForm() {
return (
<div>
<Box sx={{ mb: 2 }}>
<Label htmlFor="unnamed-select">Default</Label>
<Select defaultValue={10} id="unnamed-select">
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
</Box>
<div>
<Label htmlFor="named-select">
With the <code>name</code> prop
</Label>
<Select defaultValue={10} id="named-select" name="demo-select">
<Option value={10}>Ten</Option>
<Option value={20}>Twenty</Option>
<Option value={30}>Thirty</Option>
</Select>
</div>
</div>
);
}
const Select = React.forwardRef(function CustomSelect<
TValue extends {},
Multiple extends boolean,
>(props: SelectProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>) {
const slots: SelectProps<TValue, Multiple>['slots'] = {
root: Button,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} ref={ref} slots={slots} />;
}) as <TValue extends {}, Multiple extends boolean>(
props: SelectProps<TValue, Multiple> & React.RefAttributes<HTMLButtonElement>,
) => JSX.Element;
const blue = {
100: '#DAECFF',
200: '#99CCF3',
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 Button = React.forwardRef(function Button<
TValue extends {},
Multiple extends boolean,
>(
props: SelectRootSlotProps<TValue, Multiple>,
ref: React.ForwardedRef<HTMLButtonElement>,
) {
const { ownerState, ...other } = props;
return (
<StyledButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledButton>
);
});
const StyledButton = styled('button', { shouldForwardProp: () => true })(
({ theme }) => `
position: relative;
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
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: 320px;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const Popper = styled(BasePopper)`
z-index: 1;
`;
const Label = styled('label')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.85rem;
display: block;
margin-bottom: 4px;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]};
`,
);
| 397 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectGrouping.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Select as BaseSelect, selectClasses } from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { OptionGroup as BaseOptionGroup } from '@mui/base/OptionGroup';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectGrouping() {
return (
<Select placeholder="Choose a character…">
<OptionGroup label="Hobbits">
<Option value="Frodo">Frodo</Option>
<Option value="Sam">Sam</Option>
<Option value="Merry">Merry</Option>
<Option value="Pippin">Pippin</Option>
</OptionGroup>
<OptionGroup label="Elves">
<Option value="Galadriel">Galadriel</Option>
<Option value="Legolas">Legolas</Option>
</OptionGroup>
</Select>
);
}
function Select(props) {
const slots = {
root: Button,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} slots={slots} />;
}
Select.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};
const OptionGroup = React.forwardRef(function CustomOptionGroup(props, ref) {
const slots = {
root: GroupRoot,
label: GroupHeader,
list: GroupOptions,
...props.slots,
};
return <BaseOptionGroup {...props} ref={ref} slots={slots} />;
});
OptionGroup.propTypes = {
/**
* The components used for each slot inside the OptionGroup.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
label: PropTypes.elementType,
list: PropTypes.elementType,
root: PropTypes.elementType,
}),
};
const blue = {
100: '#DAECFF',
200: '#99CCF3',
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 Button = React.forwardRef(function Button(props, ref) {
const { ownerState, ...other } = props;
return (
<StyledButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledButton>
);
});
Button.propTypes = {
children: PropTypes.node,
ownerState: PropTypes.object.isRequired,
};
const StyledButton = styled('button', { shouldForwardProp: () => true })(
({ theme }) => `
position: relative;
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
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: 320px;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const GroupRoot = styled('li')`
list-style: none;
`;
const GroupHeader = styled('span')`
display: block;
padding: 15px 0 5px 10px;
font-size: 0.75em;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05rem;
color: ${grey[600]};
`;
const GroupOptions = styled('ul')`
list-style: none;
margin-left: 0;
padding: 0;
> li {
padding-left: 20px;
}
`;
const Popper = styled(BasePopper)`
z-index: 1;
`;
| 398 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectGrouping.tsx | import * as React from 'react';
import {
Select as BaseSelect,
SelectProps,
selectClasses,
SelectRootSlotProps,
} from '@mui/base/Select';
import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import {
OptionGroup as BaseOptionGroup,
OptionGroupProps,
} from '@mui/base/OptionGroup';
import { Popper as BasePopper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';
export default function UnstyledSelectGrouping() {
return (
<Select placeholder="Choose a character…">
<OptionGroup label="Hobbits">
<Option value="Frodo">Frodo</Option>
<Option value="Sam">Sam</Option>
<Option value="Merry">Merry</Option>
<Option value="Pippin">Pippin</Option>
</OptionGroup>
<OptionGroup label="Elves">
<Option value="Galadriel">Galadriel</Option>
<Option value="Legolas">Legolas</Option>
</OptionGroup>
</Select>
);
}
function Select(props: SelectProps<string, false>) {
const slots: SelectProps<string, false>['slots'] = {
root: Button,
listbox: Listbox,
popper: Popper,
...props.slots,
};
return <BaseSelect {...props} slots={slots} />;
}
const OptionGroup = React.forwardRef(function CustomOptionGroup(
props: OptionGroupProps,
ref: React.ForwardedRef<any>,
) {
const slots: OptionGroupProps['slots'] = {
root: GroupRoot,
label: GroupHeader,
list: GroupOptions,
...props.slots,
};
return <BaseOptionGroup {...props} ref={ref} slots={slots} />;
});
const blue = {
100: '#DAECFF',
200: '#99CCF3',
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 Button = React.forwardRef(function Button<
TValue extends {},
Multiple extends boolean,
>(
props: SelectRootSlotProps<TValue, Multiple>,
ref: React.ForwardedRef<HTMLButtonElement>,
) {
const { ownerState, ...other } = props;
return (
<StyledButton type="button" {...other} ref={ref}>
{other.children}
<UnfoldMoreRoundedIcon />
</StyledButton>
);
});
const StyledButton = styled('button', { shouldForwardProp: () => true })(
({ theme }) => `
position: relative;
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
min-width: 320px;
padding: 8px 12px;
border-radius: 8px;
text-align: left;
line-height: 1.5;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&.${selectClasses.focusVisible} {
outline: 0;
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
& > svg {
font-size: 1rem;
position: absolute;
height: 100%;
top: 0;
right: 10px;
}
`,
);
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: 320px;
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 2px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const Option = styled(BaseOption)(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.highlighted} {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.${optionClasses.highlighted}.${optionClasses.selected} {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.${optionClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${optionClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);
const GroupRoot = styled('li')`
list-style: none;
`;
const GroupHeader = styled('span')`
display: block;
padding: 15px 0 5px 10px;
font-size: 0.75em;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.05rem;
color: ${grey[600]};
`;
const GroupOptions = styled('ul')`
list-style: none;
margin-left: 0;
padding: 0;
> li {
padding-left: 20px;
}
`;
const Popper = styled(BasePopper)`
z-index: 1;
`;
| 399 |
Subsets and Splits