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/benchmark/server | petrpan-code/mui/material-ui/benchmark/server/scenarios/server.js | /* eslint-disable no-console */
import express from 'express';
import * as React from 'react';
import * as ReactDOMServer from 'react-dom/server';
import { SheetsRegistry } from 'jss';
import { createTheme } from '@mui/material/styles';
import {
styled as materialStyled,
StylesProvider,
ThemeProvider,
createGenerateClassName,
} from '@mui/styles';
import { green, red } from '@mui/material/colors';
import Pricing from 'docs/data/material/getting-started/templates/pricing/Pricing';
import { spacing, palette, unstable_styleFunctionSx as styleFunction } from '@mui/system';
import Avatar from '@mui/material/Avatar';
import Box from '@mui/material/Box';
const StyledFunction = materialStyled('div')({
color: 'blue',
});
function renderFullPage(html, css) {
return `
<!DOCTYPE html>
<html>
<head>
<title>My page</title>
<style id="jss-server-side">${css}</style>
</head>
<body>
<div id="root">${html}</div>
</body>
</html>
`;
}
const theme = createTheme({
palette: {
primary: green,
accent: red,
},
});
function renderPricing(req, res) {
const sheetsRegistry = new SheetsRegistry();
const html = ReactDOMServer.renderToString(
<StylesProvider
sheetsRegistry={sheetsRegistry}
generateClassName={createGenerateClassName()}
sheetsManager={new Map()}
>
<ThemeProvider theme={theme}>
<Pricing />
</ThemeProvider>
</StylesProvider>,
);
const css = sheetsRegistry.toString();
res.send(renderFullPage(html, css));
}
function renderBox(req, res) {
const sheetsRegistry = new SheetsRegistry();
const html = ReactDOMServer.renderToString(
<StylesProvider
sheetsRegistry={sheetsRegistry}
generateClassName={createGenerateClassName()}
sheetsManager={new Map()}
>
<ThemeProvider theme={theme}>
{Array.from(new Array(1000)).map((_, index) => (
<Box key={String(index)} sx={{ m: 1 }} />
))}
</ThemeProvider>
</StylesProvider>,
);
const css = sheetsRegistry.toString();
res.send(renderFullPage(html, css));
}
function renderAvatar(req, res) {
const sheetsRegistry = new SheetsRegistry();
const html = ReactDOMServer.renderToString(
<StylesProvider
sheetsRegistry={sheetsRegistry}
generateClassName={createGenerateClassName()}
sheetsManager={new Map()}
>
{Array.from(new Array(1)).map((_, index) => (
<Avatar key={String(index)}>Avatar</Avatar>
))}
</StylesProvider>,
);
const css = sheetsRegistry.toString();
res.send(renderFullPage(html, css));
}
function renderStyledFunction(req, res) {
const sheetsRegistry = new SheetsRegistry();
const html = ReactDOMServer.renderToString(
<StylesProvider
sheetsRegistry={sheetsRegistry}
generateClassName={createGenerateClassName()}
sheetsManager={new Map()}
>
{Array.from(new Array(1000)).map((_, index) => (
<StyledFunction key={String(index)} />
))}
</StylesProvider>,
);
const css = sheetsRegistry.toString();
res.send(renderFullPage(html, css));
}
function renderSpacing(req, res) {
for (let i = 0; i < 10000; i += 1) {
spacing({
theme: {},
p: [1, 2, 3],
});
}
res.send(renderFullPage('hello', ''));
}
function renderPalette(req, res) {
for (let i = 0; i < 10000; i += 1) {
palette({
theme: {},
bgColor: ['blue', 'red'],
});
}
res.send(renderFullPage('hello', ''));
}
function renderSystem(req, res) {
for (let i = 0; i < 10000; i += 1) {
styleFunction({
theme: {},
sx: {
color: 'primary.main',
bgColor: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
border: {
sm: 1,
md: 2,
},
},
});
}
res.send(renderFullPage('hello', ''));
}
const app = express();
app.get('/', renderPricing);
app.get('/spacing', renderSpacing);
app.get('/palette', renderPalette);
app.get('/system', renderSystem);
app.get('/avatar', renderAvatar);
app.get('/styled-function', renderStyledFunction);
app.get('/box', renderBox);
const port = 3001;
app.listen(port, () => {
console.log(`listening on port ${port}`);
});
| 100 |
0 | petrpan-code/mui/material-ui/benchmark/server | petrpan-code/mui/material-ui/benchmark/server/scenarios/styles.js | /* eslint-disable no-console */
import Benchmark from 'benchmark';
import * as React from 'react';
import * as ReactDOMServer from 'react-dom/server';
import styledComponents, { ServerStyleSheet } from 'styled-components';
import styledEmotion from '@emotion/styled';
import { css } from '@emotion/react';
import { renderStylesToString } from '@emotion/server';
import injectSheet, { JssProvider, SheetsRegistry } from 'react-jss';
import { styled as styledMui, withStyles, makeStyles, StylesProvider } from '@mui/styles';
import jss, { getDynamicStyles } from 'jss';
import Box from '@mui/material/Box';
const suite = new Benchmark.Suite('styles', {
onError: (event) => {
console.log(event.target.error);
},
});
Benchmark.options.minSamples = 100;
const cssContent = `
display: inline-flex;
align-items: center;
justify-content: center;
position: relative;
background-color: transparent;
outline: 0;
border: 0;
margin: 0;
border-radius: 0;
padding: 0;
cursor: pointer;
user-select: none;
vertical-align: middle;
-moz-appearance: none;
-webkit-appearance: none;
text-decoration: none`;
const cssObject = {
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent',
outline: 0,
border: 0,
margin: 0,
borderRadius: 0,
padding: 0,
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
MozAppearance: 'none', // Reset
WebkitAppearance: 'none', // Reset
textDecoration: 'none',
},
// system: () => ({
// color: 'blue',
// }),
};
const emotionCss = css`
${cssContent}
`;
const JSSButton = injectSheet(cssObject)((props) => (
<button type="button" className={props.classes.root} {...props} />
));
const WithStylesButton = withStyles(cssObject)((props) => (
<button type="submit" className={props.classes.root} {...props} />
));
const EmotionButton = styledEmotion('button')(cssObject.root);
const StyledMuiButton = styledMui('button')(cssObject.root);
const StyledComponentsButton = styledComponents.button`${cssContent}`;
const useStyles = makeStyles(cssObject);
function HookButton(props) {
const classes = useStyles();
return <button type="button" className={classes.root} {...props} />;
}
function NakedButton(props) {
return <button type="submit" {...props} />;
}
function EmotionCssButton(props) {
// eslint-disable-next-line react/no-unknown-property
return <button type="submit" css={emotionCss} {...props} />;
}
suite
.add('StyledMuiButton', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<StylesProvider sheetsManager={new Map()} sheetsRegistry={sheetsRegistry}>
{Array.from(new Array(5)).map((_, index) => (
<StyledMuiButton key={String(index)}>MUI</StyledMuiButton>
))}
</StylesProvider>,
);
sheetsRegistry.toString();
})
.add('Box', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<StylesProvider sheetsManager={new Map()} sheetsRegistry={sheetsRegistry}>
{Array.from(new Array(5)).map((_, index) => (
<Box key={String(index)} p={2}>
MUI
</Box>
))}
</StylesProvider>,
);
sheetsRegistry.toString();
})
.add('JSS naked', () => {
const sheetsRegistry = new SheetsRegistry();
const staticStyles = cssObject;
const dynamicStyles = getDynamicStyles(staticStyles);
const staticSheet = jss.createStyleSheet(staticStyles);
staticSheet.attach({
link: false,
});
sheetsRegistry.add(staticSheet);
if (dynamicStyles) {
const dynamicSheet = jss.createStyleSheet(dynamicStyles, {
link: true,
});
dynamicSheet.update({});
dynamicSheet.attach();
sheetsRegistry.add(dynamicSheet);
}
ReactDOMServer.renderToString(
<JssProvider registry={sheetsRegistry}>
{Array.from(new Array(5)).map((_, index) => (
<button key={String(index)} type="submit">
MUI
</button>
))}
</JssProvider>,
);
sheetsRegistry.toString();
})
.add('JSSButton', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<JssProvider registry={sheetsRegistry}>
<React.Fragment>
{Array.from(new Array(5)).map((_, index) => (
<JSSButton key={String(index)}>MUI</JSSButton>
))}
</React.Fragment>
</JssProvider>,
);
sheetsRegistry.toString();
})
.add('WithStylesButton', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<StylesProvider sheetsManager={new Map()} sheetsRegistry={sheetsRegistry}>
{Array.from(new Array(5)).map((_, index) => (
<WithStylesButton key={String(index)}>MUI</WithStylesButton>
))}
</StylesProvider>,
);
sheetsRegistry.toString();
})
.add('HookButton', () => {
const sheetsRegistry = new SheetsRegistry();
ReactDOMServer.renderToString(
<StylesProvider sheetsManager={new Map()} sheetsRegistry={sheetsRegistry}>
{Array.from(new Array(5)).map((_, index) => (
<HookButton key={String(index)}>MUI</HookButton>
))}
</StylesProvider>,
);
sheetsRegistry.toString();
})
.add('StyledComponentsButton', () => {
const sheet = new ServerStyleSheet();
ReactDOMServer.renderToString(
sheet.collectStyles(
<React.Fragment>
{Array.from(new Array(5)).map((_, index) => (
<StyledComponentsButton key={String(index)}>MUI</StyledComponentsButton>
))}
</React.Fragment>,
),
);
sheet.getStyleTags();
})
.add('EmotionButton', () => {
ReactDOMServer.renderToString(
<StylesProvider>
{Array.from(new Array(5)).map((_, index) => (
<EmotionButton key={String(index)}>MUI</EmotionButton>
))}
</StylesProvider>,
);
})
.add('EmotionCssButton', () => {
ReactDOMServer.renderToString(
<StylesProvider>
{Array.from(new Array(5)).map((_, index) => (
<EmotionCssButton key={String(index)}>MUI</EmotionCssButton>
))}
</StylesProvider>,
);
})
.add('EmotionServerCssButton', () => {
renderStylesToString(
ReactDOMServer.renderToString(
<StylesProvider>
{Array.from(new Array(5)).map((_, index) => (
<EmotionCssButton key={String(index)}>MUI</EmotionCssButton>
))}
</StylesProvider>,
),
);
})
.add('Naked', () => {
ReactDOMServer.renderToString(
<StylesProvider>
{Array.from(new Array(5)).map((_, index) => (
<NakedButton key={String(index)}>MUI</NakedButton>
))}
</StylesProvider>,
);
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.run();
| 101 |
0 | petrpan-code/mui/material-ui/benchmark/server | petrpan-code/mui/material-ui/benchmark/server/scenarios/system.js | /* eslint-disable no-console */
import Benchmark from 'benchmark';
import { unstable_styleFunctionSx as styleFunctionSx } from '@mui/system';
import styledSystemCss from '@styled-system/css';
import { createTheme } from '@mui/material/styles';
import { css as chakraCss } from '@chakra-ui/system';
const suite = new Benchmark.Suite('system', {
onError: (event) => {
console.log(event.target.error);
},
});
Benchmark.options.minSamples = 100;
const materialSystemTheme = createTheme();
const styledSystemTheme = {
breakpoints: ['40em', '52em', '64em'],
colors: {
primary: materialSystemTheme.palette.primary,
background: materialSystemTheme.palette.background,
},
fontSizes: materialSystemTheme.typography,
fonts: materialSystemTheme.typography,
};
styledSystemTheme.breakpoints.base = styledSystemTheme.breakpoints[0];
styledSystemTheme.breakpoints.sm = styledSystemTheme.breakpoints[1];
styledSystemTheme.breakpoints.lg = styledSystemTheme.breakpoints[2];
suite
// ---
.add('@styled-system/css', () => {
styledSystemCss({
color: 'primary.main',
bg: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
})({ theme: styledSystemTheme });
})
// ---
.add('@chakra-ui/system/css', () => {
chakraCss({
color: 'primary.main',
bg: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
})({ theme: styledSystemTheme });
})
// ---
.add('@mui/system styleFunctionSx', () => {
styleFunctionSx({
theme: materialSystemTheme,
sx: {
color: 'primary.main',
bgcolor: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
},
});
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.run();
| 102 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/.env | FEEDBACK_URL=https://hgvi836wi8.execute-api.us-east-1.amazonaws.com | 103 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/.link-check-errors.txt | Broken links found by `yarn docs:link-check` that exist:
- https://mui.com/blog/material-ui-v4-is-out/#premium-themes-store-✨
- https://mui.com/size-snapshot/
| 104 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/README.md | # MUI docs
This is the documentation website of MUI.
To start the docs site in development mode, from the project root, run:
```bash
yarn && yarn docs:dev
```
If you do not have yarn installed, select your OS and follow the instructions on the [Yarn website](https://yarnpkg.com/lang/en/docs/install/#mac-stable).
_DO NOT USE NPM, use Yarn to install the dependencies._
## How can I add a new demo to the documentation?
[You can follow this guide](https://github.com/mui/material-ui/blob/HEAD/CONTRIBUTING.md)
on how to get started contributing to MUI.
## How do I help to improve the translations?
Please visit https://crowdin.com/project/material-ui-docs where you will be able to select a language and edit the translations.
Please don't submit pull requests directly.
| 105 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/babel.config.js | const path = require('path');
const fse = require('fs-extra');
const errorCodesPath = path.resolve(__dirname, './public/static/error-codes.json');
const alias = {
'@mui/material': '../packages/mui-material/src',
'@mui/docs': '../packages/mui-docs/src',
'@mui/icons-material': '../packages/mui-icons-material/lib',
'@mui/lab': '../packages/mui-lab/src',
'@mui/styles': '../packages/mui-styles/src',
'@mui/styled-engine-sc': '../packages/mui-styled-engine-sc/src',
// Swap the comments on the next two lines for using the styled-components as style engine
'@mui/styled-engine': '../packages/mui-styled-engine/src',
// '@mui/styled-engine': '../packages/mui-styled-engine-sc/src',
'@mui/system': '../packages/mui-system/src',
'@mui/private-theming': '../packages/mui-private-theming/src',
'@mui/utils': '../packages/mui-utils/src',
'@mui/base': '../packages/mui-base/src',
'@mui/material-next': '../packages/mui-material-next/src',
'@mui/joy': '../packages/mui-joy/src',
docs: './',
modules: '../modules',
pages: './pages',
};
const { version: transformRuntimeVersion } = fse.readJSONSync(
require.resolve('@babel/runtime-corejs2/package.json'),
);
module.exports = {
// TODO: Enable once nextjs uses babel 7.13
// assumptions: {
// noDocumentAll: true,
// },
presets: [
// backport of https://github.com/vercel/next.js/pull/9511
[
'next/babel',
{
'preset-react': { runtime: 'automatic' },
'transform-runtime': { corejs: 2, version: transformRuntimeVersion },
},
],
],
plugins: [
[
'babel-plugin-macros',
{
muiError: {
errorCodesPath,
},
},
],
'babel-plugin-optimize-clsx',
// for IE11 support
'@babel/plugin-transform-object-assign',
[
'babel-plugin-module-resolver',
{
alias,
transformFunctions: ['require', 'require.context'],
},
],
],
ignore: [/@babel[\\|/]runtime/], // Fix a Windows issue.
env: {
production: {
plugins: [
'@babel/plugin-transform-react-constant-elements',
['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }],
['babel-plugin-transform-react-remove-prop-types', { mode: 'remove' }],
],
},
},
};
| 106 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/config.d.ts | export const LANGUAGES: string[];
export const LANGUAGES_SSR: string[];
export const LANGUAGES_IN_PROGRESS: string[];
export const LANGUAGES_IGNORE_PAGES: (pathname: string) => boolean;
| 107 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/config.js | // Valid languages to server-side render in production
const LANGUAGES = ['en'];
// Server side rendered languages
const LANGUAGES_SSR = ['en'];
// Work in progress
const LANGUAGES_IN_PROGRESS = LANGUAGES.slice();
const LANGUAGES_IGNORE_PAGES = (pathname) => {
// We don't have the bandwidth like Qt to translate our blog posts
// https://www.qt.io/zh-cn/blog
if (pathname === '/blog' || pathname.startsWith('/blog/')) {
return true;
}
if (pathname === '/size-snapshot/') {
return true;
}
return false;
};
module.exports = {
LANGUAGES,
LANGUAGES_IN_PROGRESS,
LANGUAGES_SSR,
LANGUAGES_IGNORE_PAGES,
};
| 108 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/next-env.d.ts | /// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
| 109 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/next.config.js | const path = require('path');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const pkg = require('../package.json');
const withDocsInfra = require('./nextConfigDocsInfra');
const { findPages } = require('./src/modules/utils/find');
const {
LANGUAGES,
LANGUAGES_SSR,
LANGUAGES_IGNORE_PAGES,
LANGUAGES_IN_PROGRESS,
} = require('./config');
const workspaceRoot = path.join(__dirname, '../');
const l10nPRInNetlify = /^l10n_/.test(process.env.HEAD) && process.env.NETLIFY === 'true';
const vercelDeploy = Boolean(process.env.VERCEL);
const isDeployPreview = Boolean(process.env.PULL_REQUEST_ID);
// For crowdin PRs we want to build all locales for testing.
const buildOnlyEnglishLocale = isDeployPreview && !l10nPRInNetlify && !vercelDeploy;
module.exports = withDocsInfra({
webpack: (config, options) => {
const plugins = config.plugins.slice();
if (process.env.DOCS_STATS_ENABLED) {
plugins.push(
// For all options see https://github.com/th0r/webpack-bundle-analyzer#as-plugin
new BundleAnalyzerPlugin({
analyzerMode: 'server',
generateStatsFile: true,
analyzerPort: options.isServer ? 8888 : 8889,
reportTitle: `${options.isServer ? 'server' : 'client'} docs bundle`,
// Will be available at `.next/${statsFilename}`
statsFilename: `stats-${options.isServer ? 'server' : 'client'}.json`,
}),
);
}
// next includes node_modules in webpack externals. Some of those have dependencies
// on the aliases defined above. If a module is an external those aliases won't be used.
// We need tell webpack to not consider those packages as externals.
if (
options.isServer &&
// Next executes this twice on the server with React 18 (once per runtime).
// We only care about Node runtime at this point.
(options.nextRuntime === undefined || options.nextRuntime === 'nodejs')
) {
const [nextExternals, ...externals] = config.externals;
config.externals = [
(ctx, callback) => {
const { request } = ctx;
const hasDependencyOnRepoPackages = [
'notistack',
'@mui/x-data-grid',
'@mui/x-data-grid-pro',
'@mui/x-date-pickers',
'@mui/x-date-pickers-pro',
'@mui/x-data-grid-generator',
'@mui/x-charts',
'@mui/x-tree-view',
'@mui/x-license-pro',
].some((dep) => request.startsWith(dep));
if (hasDependencyOnRepoPackages) {
return callback(null);
}
return nextExternals(ctx, callback);
},
...externals,
];
}
config.module.rules.forEach((r) => {
r.resourceQuery = { not: [/raw/] };
});
return {
...config,
plugins,
resolve: {
...config.resolve,
// resolve .tsx first
extensions: [
'.tsx',
...config.resolve.extensions.filter((extension) => extension !== '.tsx'),
],
},
module: {
...config.module,
rules: config.module.rules.concat([
{
test: /\.md$/,
oneOf: [
{
resourceQuery: /@mui\/markdown/,
use: [
options.defaultLoaders.babel,
{
loader: require.resolve('@mui/markdown/loader'),
options: {
ignoreLanguagePages: LANGUAGES_IGNORE_PAGES,
languagesInProgress: LANGUAGES_IN_PROGRESS,
env: {
SOURCE_CODE_REPO: options.config.env.SOURCE_CODE_REPO,
LIB_VERSION: options.config.env.LIB_VERSION,
},
},
},
],
},
{
// used in some /getting-started/templates
type: 'asset/source',
},
],
},
// transpile 3rd party packages with dependencies in this repository
{
test: /\.(js|mjs|jsx)$/,
resourceQuery: { not: [/raw/] },
include:
/node_modules(\/|\\)(notistack|@mui(\/|\\)x-data-grid|@mui(\/|\\)x-data-grid-pro|@mui(\/|\\)x-license-pro|@mui(\/|\\)x-data-grid-generator|@mui(\/|\\)x-date-pickers-pro|@mui(\/|\\)x-date-pickers|@mui(\/|\\)x-charts|@mui(\/|\\)x-tree-view)/,
use: {
loader: 'babel-loader',
options: {
// on the server we use the transpiled commonJS build, on client ES6 modules
// babel needs to figure out in what context to parse the file
sourceType: 'unambiguous',
plugins: [
[
'babel-plugin-module-resolver',
{
alias: {
// all packages in this monorepo
'@mui/material': '../packages/mui-material/src',
'@mui/docs': '../packages/mui-docs/src',
'@mui/icons-material': '../packages/mui-icons-material/lib',
'@mui/lab': '../packages/mui-lab/src',
'@mui/styled-engine': '../packages/mui-styled-engine/src',
'@mui/styles': '../packages/mui-styles/src',
'@mui/system': '../packages/mui-system/src',
'@mui/private-theming': '../packages/mui-private-theming/src',
'@mui/utils': '../packages/mui-utils/src',
'@mui/base': '../packages/mui-base/src',
'@mui/material-next': '../packages/mui-material-next/src',
'@mui/joy': '../packages/mui-joy/src',
},
// transformFunctions: ['require'],
},
],
],
},
},
},
// required to transpile ../packages/
{
test: /\.(js|mjs|tsx|ts)$/,
resourceQuery: { not: [/raw/] },
include: [workspaceRoot],
exclude: /(node_modules|mui-icons-material)/,
use: options.defaultLoaders.babel,
},
{
resourceQuery: /raw/,
type: 'asset/source',
},
]),
},
};
},
env: {
GITHUB_AUTH: process.env.GITHUB_AUTH
? `Basic ${Buffer.from(process.env.GITHUB_AUTH).toString('base64')}`
: null,
LIB_VERSION: pkg.version,
FEEDBACK_URL: process.env.FEEDBACK_URL,
SOURCE_GITHUB_BRANCH: 'master', // #default-branch-switch
SOURCE_CODE_REPO: 'https://github.com/mui/material-ui',
GITHUB_TEMPLATE_DOCS_FEEDBACK: '4.docs-feedback.yml',
BUILD_ONLY_ENGLISH_LOCALE: buildOnlyEnglishLocale,
},
// Next.js provides a `defaultPathMap` argument, we could simplify the logic.
// However, we don't in order to prevent any regression in the `findPages()` method.
exportPathMap: () => {
const pages = findPages();
const map = {};
function traverse(pages2, userLanguage) {
const prefix = userLanguage === 'en' ? '' : `/${userLanguage}`;
pages2.forEach((page) => {
// The experiments pages are only meant for experiments, they shouldn't leak to production.
if (
(page.pathname.startsWith('/experiments/') || page.pathname === '/experiments') &&
process.env.DEPLOY_ENV === 'production'
) {
return;
}
// The blog is not translated
if (userLanguage !== 'en' && LANGUAGES_IGNORE_PAGES(page.pathname)) {
return;
}
if (!page.children) {
// map api-docs to api
// i: /api-docs/* > /api/* (old structure)
// ii: /*/api-docs/* > /*/api/* (for new structure)
map[`${prefix}${page.pathname.replace(/^(\/[^/]+)?\/api-docs\/(.*)/, '$1/api/$2')}`] = {
page: page.pathname,
query: {
userLanguage,
},
};
return;
}
traverse(page.children, userLanguage);
});
}
// We want to speed-up the build of pull requests.
// For this, consider only English language on deploy previews, except for crowdin PRs.
if (buildOnlyEnglishLocale) {
// eslint-disable-next-line no-console
console.log('Considering only English for SSR');
traverse(pages, 'en');
} else {
// eslint-disable-next-line no-console
console.log('Considering various locales for SSR');
LANGUAGES_SSR.forEach((userLanguage) => {
traverse(pages, userLanguage);
});
}
return map;
},
// rewrites has no effect when run `next export` for production
rewrites: async () => {
return [
{ source: `/:lang(${LANGUAGES.join('|')})?/:rest*`, destination: '/:rest*' },
// Make sure to include the trailing slash if `trailingSlash` option is set
{ source: '/api/:rest*/', destination: '/api-docs/:rest*/' },
{ source: `/static/x/:rest*`, destination: 'http://0.0.0.0:3001/static/x/:rest*' },
];
},
});
| 110 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/nextConfigDocsInfra.js | /**
* See the docs of the Netlify environment variables:
* https://docs.netlify.com/configure-builds/environment-variables/#build-metadata.
*
* A few comments:
* - process.env.CONTEXT === 'production' means that the branch in Netlify was configured as production.
* For example, the `master` branch of the Core team is considered a `production` build on Netlify based
* on https://app.netlify.com/sites/material-ui/settings/deploys#branches.
* - Each team has different site https://app.netlify.com/teams/mui/sites.
* The following logic must be compatible with all of them.
*/
let DEPLOY_ENV = 'development';
// Same as process.env.PULL_REQUEST_ID
if (process.env.CONTEXT === 'deploy-preview') {
DEPLOY_ENV = 'pull-request';
}
if (process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') {
DEPLOY_ENV = 'production';
}
// The 'master' and 'next' branches are NEVER a production environment. We use these branches for staging.
if (
(process.env.CONTEXT === 'production' || process.env.CONTEXT === 'branch-deploy') &&
(process.env.HEAD === 'master' || process.env.HEAD === 'next')
) {
DEPLOY_ENV = 'staging';
}
/**
* ====================================================================================
*/
process.env.DEPLOY_ENV = DEPLOY_ENV;
function withDocsInfra(nextConfig) {
return {
trailingSlash: true,
// Can be turned on when https://github.com/vercel/next.js/issues/24640 is fixed
optimizeFonts: false,
reactStrictMode: true,
...nextConfig,
env: {
BUILD_ONLY_ENGLISH_LOCALE: true, // disable translations by default
// production | staging | pull-request | development
DEPLOY_ENV,
...nextConfig.env,
// https://docs.netlify.com/configure-builds/environment-variables/#git-metadata
// reference ID (also known as "SHA" or "hash") of the commit we're building.
COMMIT_REF: process.env.COMMIT_REF,
// ID of the PR and the Deploy Preview it generated (for example, 1211)
PULL_REQUEST_ID: process.env.REVIEW_ID,
// This can be set manually in the .env to see the ads in dev mode.
ENABLE_AD_IN_DEV_MODE: process.env.ENABLE_AD_IN_DEV_MODE,
// URL representing the unique URL for an individual deploy, e.g.
// https://5b243e66dd6a547b4fee73ae--petsof.netlify.app
NETLIFY_DEPLOY_URL: process.env.DEPLOY_URL,
// Name of the site, its Netlify subdomain; for example, material-ui-docs
NETLIFY_SITE_NAME: process.env.SITE_NAME,
},
experimental: {
scrollRestoration: true,
esmExternals: false,
...nextConfig.experimental,
},
eslint: {
ignoreDuringBuilds: true,
...nextConfig.eslint,
},
typescript: {
// Motivated by https://github.com/vercel/next.js/issues/7687
ignoreBuildErrors: true,
...nextConfig.typescript,
},
};
}
module.exports = withDocsInfra;
| 111 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/notifications.json | [
{
"id": 68,
"title": "<b>Check out Base UI today</b> 💥",
"text": "Love Material UI, but don't need Material Design? Try Base UI, the new \"unstyled\" alternative. <a style=\"color: inherit;\" data-ga-event-category=\"Blog\" data-ga-event-action=\"notification\" data-ga-event-label=\"introducing-base-ui\" href=\"/blog/introducing-base-ui/\">Read more in this announcement</a>."
},
{
"id": 74,
"title": "<b>Introducing MUI X v6.0.0</b>",
"text": "<a style=\"color: inherit;\" data-ga-event-category=\"Blog\" data-ga-event-action=\"notification\" data-ga-event-label=\"mui-x-v6\" href=\"/blog/mui-x-v6/\">Explore</a> what's new and what's next in the new stable version of the advanced components."
},
{
"id": 75,
"title": "<b>Try the new time picker UI now</b>",
"text": "The new time-picking experience is designed for desktops, and it's available in the <a style=\"color: inherit;\" data-ga-event-category=\"Announcement\" data-ga-event-action=\"notification\" data-ga-event-label=\"mui-x-v6\" href=\"https://mui.com/x/react-date-pickers/time-picker/\">Time Picker</a> as well as a <a style=\"color: inherit;\" data-ga-event-category=\"Announcement\" data-ga-event-action=\"notification\" data-ga-event-label=\"mui-x-v6\" href=\"https://mui.com/x/react-date-pickers/digital-clock/\">standalone component</a>."
},
{
"id": 76,
"title": "<b>Unveiling Charts: Alpha release is live</b>",
"text": "We're starting with bars, lines, and scatter charts. <a style=\"color: inherit;\" data-ga-event-category=\"Announcement\" data-ga-event-action=\"notification\" data-ga-event-label=\"mui-x-introduce-charts\" href=\"https://mui.com/x/react-charts/\">Try X Charts now</a>, and let us know what you need."
},
{
"id": 77,
"title": "<b>MUI Toolpad is now in Beta</b>",
"text": "Import in your codebase, connect to datasources and build your UI in minutes! Read our <a style=\"color: inherit;\" data-ga-event-category=\"Announcement\" data-ga-event-action=\"notification\" data-ga-event-label=\"mui-toolpad-introduce-beta\" href=\"https://mui.com/blog/2023-toolpad-beta-announcement/\"> Beta announcement</a>, try toolpad and share your feedback."
}
]
| 112 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/package.json | {
"name": "docs",
"version": "5.0.0",
"private": true,
"author": "MUI Team",
"license": "MIT",
"scripts": {
"build": "cross-env NODE_ENV=production NODE_OPTIONS=--max_old_space_size=4096 next build --profile",
"build:clean": "rimraf .next && yarn build",
"build-sw": "node ./scripts/buildServiceWorker.js",
"dev": "next dev",
"deploy": "git push material-ui-docs master:latest",
"export": "rimraf docs/export && next export --threads=3 -o export && yarn build-sw",
"icons": "rimraf --glob public/static/icons/* && node ./scripts/buildIcons.js",
"start": "next start",
"create-playground": "cpy --cwd=scripts playground.template.tsx ../../pages/playground --rename=index.tsx",
"typescript": "tsc -p tsconfig.json && tsc -p scripts/tsconfig.json",
"typescript:transpile": "echo 'Use `yarn docs:typescript:formatted'` instead && exit 1",
"typescript:transpile:dev": "echo 'Use `yarn docs:typescript'` instead && exit 1",
"link-check": "node ./scripts/reportBrokenLinks.js"
},
"dependencies": {
"@babel/core": "^7.23.3",
"@babel/plugin-transform-object-assign": "^7.23.3",
"@babel/runtime": "^7.23.2",
"@babel/runtime-corejs2": "^7.23.2",
"@docsearch/react": "^3.5.2",
"@emotion/cache": "^11.11.0",
"@emotion/react": "^11.11.1",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mui/base": "5.0.0-beta.24",
"@mui/docs": "^5.14.18",
"@mui/icons-material": "^5.14.18",
"@mui/joy": "5.0.0-beta.15",
"@mui/lab": "5.0.0-alpha.153",
"@mui/markdown": "^5.0.0",
"@mui/material": "^5.14.18",
"@mui/material-next": "6.0.0-alpha.110",
"@mui/styled-engine": "^5.14.18",
"@mui/styled-engine-sc": "6.0.0-alpha.6",
"@mui/styles": "^5.14.18",
"@mui/system": "^5.14.18",
"@mui/types": "^7.2.9",
"@mui/utils": "^5.14.18",
"@mui/x-charts": "6.18.1",
"@mui/x-data-grid": "6.18.1",
"@mui/x-data-grid-generator": "6.18.1",
"@mui/x-data-grid-premium": "6.18.1",
"@mui/x-data-grid-pro": "6.18.1",
"@mui/x-date-pickers": "6.18.1",
"@mui/x-date-pickers-pro": "6.18.1",
"@mui/x-license-pro": "6.10.2",
"@mui/x-tree-view": "6.17.0",
"@popperjs/core": "^2.11.8",
"@react-spring/web": "^9.7.3",
"autoprefixer": "^10.4.16",
"autosuggest-highlight": "^3.3.4",
"babel-plugin-module-resolver": "^5.0.0",
"babel-plugin-optimize-clsx": "^2.6.2",
"babel-plugin-react-remove-properties": "^0.3.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"clean-css": "^5.3.2",
"clipboard-copy": "^4.0.1",
"clsx": "^2.0.0",
"core-js": "^2.6.11",
"cross-env": "^7.0.3",
"css-mediaquery": "^0.1.2",
"date-fns": "^2.30.0",
"date-fns-jalali": "^2.21.3-1",
"feed": "^4.2.2",
"fg-loadcss": "^3.1.0",
"final-form": "^4.20.10",
"flexsearch": "^0.7.31",
"fs-extra": "^11.1.1",
"json2mq": "^0.2.0",
"jss": "^10.10.0",
"jss-plugin-template": "^10.10.0",
"jss-rtl": "^0.3.0",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"markdown-to-jsx": "^7.3.2",
"material-ui-popup-state": "^5.0.10",
"next": "13.4.19",
"notistack": "3.0.1",
"nprogress": "^0.2.0",
"postcss": "^8.4.30",
"postcss-import": "^15.1.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"react-final-form": "^6.5.9",
"react-imask": "^7.1.3",
"react-intersection-observer": "^9.5.3",
"react-is": "^18.2.0",
"react-number-format": "^5.3.1",
"react-router-dom": "^6.18.0",
"react-runner": "^1.0.3",
"react-simple-code-editor": "^0.13.1",
"react-swipeable-views": "^0.14.0",
"react-swipeable-views-utils": "^0.14.0",
"react-transition-group": "^4.4.5",
"react-virtuoso": "^4.6.2",
"react-window": "^1.8.9",
"recharts": "2.9.3",
"rimraf": "^5.0.5",
"styled-components": "^6.1.1",
"stylis": "4.2.0",
"stylis-plugin-rtl": "^2.1.1",
"use-count-up": "^3.0.1",
"webpack-bundle-analyzer": "^4.9.1"
},
"devDependencies": {
"@babel/plugin-transform-react-constant-elements": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@mui-internal/docs-utilities": "^1.0.0",
"@mui-internal/test-utils": "^1.0.0",
"@types/autosuggest-highlight": "^3.2.3",
"@types/chai": "^4.3.10",
"@types/css-mediaquery": "^0.1.4",
"@types/json2mq": "^0.2.2",
"@types/markdown-to-jsx": "^7.0.1",
"@types/node": "^18.18.10",
"@types/prop-types": "^15.7.10",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/react-swipeable-views": "^0.13.5",
"@types/react-swipeable-views-utils": "^0.13.7",
"@types/react-transition-group": "^4.4.9",
"@types/react-window": "^1.8.8",
"@types/stylis": "^4.2.0",
"chai": "^4.3.10",
"cross-fetch": "^4.0.0",
"gm": "^1.25.0",
"marked": "^5.1.2",
"playwright": "^1.39.0",
"prettier": "^2.8.8",
"tailwindcss": "^3.3.5",
"typescript-to-proptypes": "^5.0.0",
"yargs": "^17.7.2"
}
}
| 113 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/postcss.config.js | module.exports = {
plugins: {
'postcss-import': {},
'tailwindcss/nesting': {},
tailwindcss: {},
},
};
| 114 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/tailwind.config.js | /** @type {import('tailwindcss/plugin')} */
// eslint-disable-next-line import/no-import-module-exports
import plugin from 'tailwindcss/plugin';
const defaultTheme = require('tailwindcss/defaultTheme');
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: ['class'],
content: [
'./data/**/*.{js,ts,jsx,tsx,mdx}',
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./src/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {
animation: {
appear: 'in-right 200ms',
},
border: {
3: '3px',
},
boxShadow: {
'outline-purple': '0 0 0 4px rgba(192, 132, 252, 0.25)',
'outline-purple-light': '0 0 0 4px rgba(245, 208, 254, 0.25)',
'outline-purple-xs': '0 0 0 1px rgba(192, 132, 252, 0.25)',
'outline-switch': '0 0 1px 3px rgba(168, 85, 247, 0.35)',
},
cursor: {
inherit: 'inherit',
},
fontFamily: {
sans: ['IBM Plex Sans', ...defaultTheme.fontFamily.sans],
},
keyframes: {
'in-right': {
from: { transform: 'translateX(100%)' },
to: { transform: 'translateX(0)' },
},
},
lineHeight: {
5.5: '1.375rem',
},
maxWidth: {
snackbar: '560px',
},
minHeight: {
badge: '22px',
},
minWidth: {
badge: '22px',
listbox: '200px',
snackbar: '300px',
'tabs-list': '400px',
},
},
},
corePlugins: {
// Remove the Tailwind CSS preflight styles so it can use Material UI's preflight instead (CssBaseline).
preflight: false,
},
plugins: [
plugin(({ addVariant }) => {
[
'active',
'checked',
'completed',
'disabled',
'readOnly',
'error',
'expanded',
'focused',
'required',
'selected',
].forEach((state) => {
addVariant(`ui-${state}`, [`&[class~="Mui-${state}"]`]);
addVariant(`ui-not-${state}`, [`&:not([class~="Mui-${state}"])`]);
});
// for focus-visible, use the same selector as headlessui
// https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-tailwindcss/src/index.ts#LL35C11-L35C11
addVariant(`ui-focus-visible`, [`&[class~="Mui-focusVisible"]`, `&:focus-visible`]);
addVariant(`ui-not-focus-visible`, [`&:not([class~="Mui-focusVisible"])`]);
}),
],
};
| 115 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/tsconfig.json | {
"extends": "../tsconfig.json",
"include": ["next-env.d.ts", "types", "src", "pages", "data"],
"compilerOptions": {
"allowJs": true,
"isolatedModules": true,
/* files are emitted by babel */
"noEmit": true,
"noUnusedLocals": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"esModuleInterop": true,
"types": ["react"],
"incremental": true
},
"exclude": ["node_modules"]
}
| 116 |
0 | petrpan-code/mui/material-ui | petrpan-code/mui/material-ui/docs/tslint.json | {
"extends": "../tslint.json",
"rules": {
"no-irregular-whitespace": false,
"no-object-literal-type-assertion": false,
"no-trailing-whitespace": [true, "ignore-template-strings"]
}
}
| 117 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/about/teamMembers.json | [
{
"name": "Olivier Tassinari",
"title": "Co-founder, CEO",
"location": "Paris, France",
"locationCountry": "fr",
"about": "Exercise addict and lifelong learner",
"twitter": "olivtassinari",
"github": "oliviertassinari"
},
{
"name": "Matt Brookes",
"title": "Co-founder, Head of Sales",
"location": "London, UK",
"locationCountry": "gb",
"about": "When I'm not 👨🏻💻, I'm 🧗🏼♂️",
"twitter": "randomtechdude",
"github": "mbrookes"
},
{
"name": "Marija Najdova",
"title": "Engineering Manager - Core",
"location": "Skopje, North Macedonia",
"locationCountry": "mk",
"about": "I do karate 🥋 and read 📚. A lot!",
"twitter": "marijanajdova",
"github": "mnajdova"
},
{
"name": "Danail Hadjiatanasov",
"title": "Engineering Manager - X",
"location": "Sofia, Bulgaria",
"locationCountry": "bg",
"about": "Boringly normal, geek deep down. I like 🚗 and 🏂",
"twitter": "danail_h",
"github": "DanailH"
},
{
"name": "Michał Dudak",
"title": "Software Engineer - Core",
"location": "Silesia, Poland",
"locationCountry": "pl",
"about": "Motorcyclist, gamer, and coder (UI and more!)",
"twitter": "michaldudak",
"github": "michaldudak"
},
{
"name": "Siriwat Kunaporn",
"title": "Software Engineer - Core",
"location": "Bangkok, Thailand",
"locationCountry": "th",
"about": "UI Lover and ⛷ skiing newbie.",
"twitter": "siriwatknp",
"github": "siriwatknp"
},
{
"name": "Danilo Leal",
"title": "Lead Designer",
"location": "São Paulo, Brazil",
"locationCountry": "br",
"about": "Music production, hiking, and traveling!",
"github": "danilo-leal",
"twitter": "danilobleal"
},
{
"name": "Flavien Delangle",
"title": "Tech Lead - X",
"location": "Lille, France",
"about": "Love cycling 🚴♂️ and reading 📚",
"locationCountry": "fr",
"github": "flaviendelangle"
},
{
"name": "Alexandre Fauquette",
"title": "Software Engineer - X",
"location": "Nancy, France",
"locationCountry": "fr",
"about": "Love hacking and cycling 🚴♂️",
"twitter": "AleFauquette",
"github": "alexfauquette"
},
{
"name": "Bharat Kashyap",
"title": "Software Engineer - Toolpad",
"location": "New Delhi, India",
"locationCountry": "in",
"about": "Trains 🚅 , architecture 🏛️ , and psychology 🧠 ",
"twitter": "bharattttttt",
"github": "bharatkashyap"
},
{
"name": "Jan Potoms",
"title": "Tech Lead - Toolpad",
"location": "Brussels, Belgium",
"locationCountry": "be",
"about": "Always curious, I enjoy cinema and hiking",
"github": "janpot"
},
{
"name": "Prakhar Gupta",
"title": "Product Manager - Toolpad",
"location": "New Delhi, India",
"locationCountry": "in",
"about": "Into sports and hiking!",
"twitter": "gprakhar123",
"github": "prakhargupta1"
},
{
"name": "José Freitas",
"title": "Technical Product Manager - X",
"location": "Augsburg, Germany",
"locationCountry": "de",
"about": "Art, fiction, and bar philosophy",
"twitter": "zehdefreitas",
"github": "joserodolfofreitas"
},
{
"name": "Andrii Cherniavskyi",
"title": "Tech Lead - X",
"location": "Wrocław, Poland",
"locationCountry": "pl",
"about": "Love playing music - electric and bass guitar 🎸",
"twitter": "iamcherniavskii",
"github": "cherniavskii"
},
{
"name": "Sam Sycamore",
"title": "Developer Advocate",
"location": "Saint Paul, Minnesota, USA",
"locationCountry": "us",
"about": "Musician and edible wild plant enthusiast 🌱",
"twitter": "tanoaksam",
"github": "samuelsycamore"
},
{
"name": "Pedro Ferreira",
"title": "Software Engineer - Toolpad",
"location": "Porto, Portugal",
"locationCountry": "pt",
"about": "Passionate about videogames and football",
"github": "apedroferreira"
},
{
"name": "Greg Abaoag",
"title": "Executive Assistant",
"location": "Philippines",
"locationCountry": "ph",
"about": "Loves DIY, singing and learning",
"github": "zannager"
},
{
"name": "Tina Deinekhovska",
"title": "Business Administrator",
"location": "London, UK",
"locationCountry": "gb",
"about": "Empathic art-lover, incurable optimist keen on biking, gardening"
},
{
"name": "Lukas Tyla",
"title": "Software Engineer - X",
"location": "Vilnius, Lithuania",
"locationCountry": "lt",
"about": "Learning and experimenting 📚",
"github": "LukasTy"
},
{
"name": "Bilal Shafi",
"title": "Software Engineer - X",
"location": "Islamabad, Pakistan",
"locationCountry": "pk",
"about": "DIY 🛠️, Learning 📚 and 🏓",
"twitter": "MBilalShafi",
"github": "MBilalShafi"
},
{
"name": "Albert Yu",
"title": "Software Engineer - Core",
"location": "Hong Kong",
"locationCountry": "hk",
"about": "Minimalist, dog lover 🏔🐕",
"github": "mj12albert",
"twitter": "mj12albert"
},
{
"name": "Mikaila Read",
"title": "Senior People & Culture Partner",
"location": "Newcastle Upon Tyne, UK",
"locationCountry": "gb",
"about": "🧗♂️ Amateur indoor climber & ex-philosophy geek"
},
{
"name": "Romain Grégoire",
"title": "Software Engineer - X",
"location": "Montréal, Canada",
"locationCountry": "ca",
"about": "Open-source tinkerer",
"github": "romgrk"
},
{
"name": "Victor Zanivan",
"title": "Senior Designer - Core",
"location": "São Paulo, Brazil",
"locationCountry": "br",
"about": "Very geek 🎮 and love to watch/play football ⚽️",
"github": "zanivan",
"twitter": "Zanivan_"
},
{
"name": "Diego Andai",
"title": "Software Engineer - Core",
"location": "Santiago, Chile",
"locationCountry": "cl",
"about": "I love tennis 🎾 and cats 🐈",
"twitter": "DiegoAndaiC",
"github": "DiegoAndai"
},
{
"name": "Brijesh Bittu",
"title": "Software Engineer - Core",
"location": "Bengaluru, India",
"locationCountry": "in",
"about": "🏊🏼 Swimming and 🚗 driving newbie. Loves cooking.",
"github": "brijeshb42"
},
{
"name": "David Cnoops",
"title": "Design Engineer - Core",
"location": "Leuven, Belgium",
"locationCountry": "be",
"about": "Volleyball, Cycling, Parenting, Movies",
"github": "DavidCnoops"
},
{
"name": "Raffaella Luzi",
"title": "Head of Operations",
"location": "Rome, Italy",
"locationCountry": "it",
"about": "NYT crossword 📝 in one hand and a croissant 🥐 in the other",
"github": "rluzists1"
},
{
"name": "Nora Leonte",
"title": "Design Engineer - X",
"location": "Cluj-Napoca, Romania",
"locationCountry": "ro",
"about": "Art enthusiast 🎨 outdoor person 🌳 animal lover 🐾",
"github": "noraleonte"
},
{
"name": "Michel Engelen",
"title": "React Community Engineer - X",
"location": "Zeven, Germany",
"locationCountry": "de",
"about": "Geeking out on Badminton 🏸, everything Japan 🇯🇵 and Pizza 🍕",
"twitter": "jsNerdic",
"github": "michelengelen"
},
{
"name": "Vadym Raksha",
"title": "Product Engineer - Store",
"location": "Prague, Czech Republic",
"locationCountry": "cz",
"about": "Product experience geek \uD83D\uDECB, Mediterranean vibes \uD83C\uDF4A",
"twitter": "vadym_raksha",
"github": "hasdfa"
}
]
| 118 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/base/pages.ts | import type { MuiPage } from 'docs/src/MuiPage';
import pagesApi from 'docs/data/base/pagesApi';
const pages: readonly MuiPage[] = [
{
pathname: '/base-ui/getting-started-group',
title: 'Getting started',
children: [
{ pathname: '/base-ui/getting-started', title: 'Overview' },
{ pathname: '/base-ui/getting-started/quickstart', title: 'Quickstart' },
{ pathname: '/base-ui/getting-started/usage', title: 'Usage' },
{ pathname: '/base-ui/getting-started/customization', title: 'Customization' },
{ pathname: '/base-ui/getting-started/accessibility', title: 'Accessibility' },
],
},
{
pathname: '/base-ui/react-',
title: 'Components',
children: [
{ pathname: '/base-ui/all-components', title: 'All components' },
{
pathname: '/base-ui/components/inputs',
subheader: 'inputs',
children: [
{ pathname: '/base-ui/react-autocomplete', title: 'Autocomplete' },
{ pathname: '/base-ui/react-button', title: 'Button' },
{ pathname: '/base-ui/react-checkbox', title: 'Checkbox', planned: true },
{ pathname: '/base-ui/react-input', title: 'Input' },
{ pathname: '/base-ui/react-number-input', title: 'Number Input', unstable: true },
{ pathname: '/base-ui/react-radio-button', title: 'Radio Button', planned: true },
{ pathname: '/base-ui/react-rating', title: 'Rating', planned: true },
{ pathname: '/base-ui/react-select', title: 'Select' },
{ pathname: '/base-ui/react-slider', title: 'Slider' },
{ pathname: '/base-ui/react-switch', title: 'Switch' },
{
pathname: '/base-ui/react-toggle-button-group',
title: 'Toggle Button Group',
planned: true,
},
],
},
{
pathname: '/base-ui/components/data-display',
subheader: 'data-display',
children: [
{ pathname: '/base-ui/react-badge', title: 'Badge' },
{ pathname: '/base-ui/react-tooltip', title: 'Tooltip', planned: true },
],
},
{
pathname: '/base-ui/components/feedback',
subheader: 'feedback',
children: [
{
pathname: '/base-ui/react-snackbar',
title: 'Snackbar',
},
],
},
{
pathname: '/base-ui/components/surfaces',
subheader: 'surfaces',
children: [
{
pathname: '/base-ui/react-accordion',
title: 'Accordion',
planned: true,
},
],
},
{
pathname: '/base-ui/components/navigation',
subheader: 'navigation',
children: [
{ pathname: '/base-ui/react-drawer', title: 'Drawer', planned: true },
{ pathname: '/base-ui/react-menu', title: 'Menu' },
{ pathname: '/base-ui/react-pagination', title: 'Pagination', planned: true },
{ pathname: '/base-ui/react-table-pagination', title: 'Table Pagination' },
{ pathname: '/base-ui/react-tabs', title: 'Tabs' },
],
},
{
pathname: '/base-ui/components/utils',
subheader: 'utils',
children: [
{ pathname: '/base-ui/react-click-away-listener', title: 'Click-Away Listener' },
{ pathname: '/base-ui/react-focus-trap', title: 'Focus Trap' },
{ pathname: '/base-ui/react-form-control', title: 'Form Control' },
{ pathname: '/base-ui/react-modal', title: 'Modal' },
{ pathname: '/base-ui/react-no-ssr', title: 'No-SSR' },
{ pathname: '/base-ui/react-popper', title: 'Popper' },
{ pathname: '/base-ui/react-popup', title: 'Popup', unstable: true },
{ pathname: '/base-ui/react-portal', title: 'Portal' },
{ pathname: '/base-ui/react-textarea-autosize', title: 'Textarea Autosize' },
],
},
],
},
{
title: 'APIs',
pathname: '/base-ui/api',
children: pagesApi,
},
{
pathname: '/base-ui/guides',
title: 'How-to guides',
children: [
{
pathname: '/base-ui/guides/working-with-tailwind-css',
title: 'Working with Tailwind CSS',
},
{
pathname: '/base-ui/guides/overriding-component-structure',
title: 'Overriding component structure',
},
{
pathname: '/base-ui/guides/next-js-app-router',
title: 'Next.js App Router',
},
],
},
];
export default pages;
| 119 |
0 | petrpan-code/mui/material-ui/docs/data | petrpan-code/mui/material-ui/docs/data/base/pagesApi.js | module.exports = [
{ pathname: '/base-ui/react-badge/components-api/#badge', title: 'Badge' },
{ pathname: '/base-ui/react-button/components-api/#button', title: 'Button' },
{
pathname:
'/base-ui/react-click-away-listener/components-api/#click-away-listener',
title: 'ClickAwayListener',
},
{ pathname: '/base-ui/react-menu/components-api/#dropdown', title: 'Dropdown' },
{
pathname: '/base-ui/react-focus-trap/components-api/#focus-trap',
title: 'FocusTrap',
},
{
pathname: '/base-ui/react-form-control/components-api/#form-control',
title: 'FormControl',
},
{ pathname: '/base-ui/react-input/components-api/#input', title: 'Input' },
{ pathname: '/base-ui/react-menu/components-api/#menu', title: 'Menu' },
{
pathname: '/base-ui/react-menu/components-api/#menu-button',
title: 'MenuButton',
},
{ pathname: '/base-ui/react-menu/components-api/#menu-item', title: 'MenuItem' },
{ pathname: '/base-ui/react-modal/components-api/#modal', title: 'Modal' },
{ pathname: '/base-ui/react-no-ssr/components-api/#no-ssr', title: 'NoSsr' },
{
pathname: '/base-ui/react-number-input/components-api/#number-input',
title: 'NumberInput',
},
{ pathname: '/base-ui/react-select/components-api/#option', title: 'Option' },
{
pathname: '/base-ui/react-select/components-api/#option-group',
title: 'OptionGroup',
},
{ pathname: '/base-ui/react-popper/components-api/#popper', title: 'Popper' },
{ pathname: '/base-ui/react-popup/components-api/#popup', title: 'Popup' },
{ pathname: '/base-ui/react-portal/components-api/#portal', title: 'Portal' },
{ pathname: '/base-ui/react-select/components-api/#select', title: 'Select' },
{ pathname: '/base-ui/react-slider/components-api/#slider', title: 'Slider' },
{
pathname: '/base-ui/react-snackbar/components-api/#snackbar',
title: 'Snackbar',
},
{ pathname: '/base-ui/react-switch/components-api/#switch', title: 'Switch' },
{ pathname: '/base-ui/react-tabs/components-api/#tab', title: 'Tab' },
{ pathname: '/base-ui/react-tabs/components-api/#tab-panel', title: 'TabPanel' },
{
pathname: '/base-ui/react-table-pagination/components-api/#table-pagination',
title: 'TablePagination',
},
{ pathname: '/base-ui/react-tabs/components-api/#tabs', title: 'Tabs' },
{ pathname: '/base-ui/react-tabs/components-api/#tabs-list', title: 'TabsList' },
{
pathname: '/base-ui/react-textarea-autosize/components-api/#textarea-autosize',
title: 'TextareaAutosize',
},
{
pathname: '/base-ui/react-autocomplete/hooks-api/#use-autocomplete',
title: 'useAutocomplete',
},
{ pathname: '/base-ui/react-badge/hooks-api/#use-badge', title: 'useBadge' },
{ pathname: '/base-ui/react-button/hooks-api/#use-button', title: 'useButton' },
{ pathname: '/base-ui/react-menu/hooks-api/#use-dropdown', title: 'useDropdown' },
{
pathname: '/base-ui/react-form-control/hooks-api/#use-form-control-context',
title: 'useFormControlContext',
},
{ pathname: '/base-ui/react-input/hooks-api/#use-input', title: 'useInput' },
{ pathname: '/base-ui/react-menu/hooks-api/#use-menu', title: 'useMenu' },
{
pathname: '/base-ui/react-menu/hooks-api/#use-menu-button',
title: 'useMenuButton',
},
{ pathname: '/base-ui/react-menu/hooks-api/#use-menu-item', title: 'useMenuItem' },
{
pathname: '/base-ui/react-menu/hooks-api/#use-menu-item-context-stabilizer',
title: 'useMenuItemContextStabilizer',
},
{ pathname: '/base-ui/react-modal/hooks-api/#use-modal', title: 'useModal' },
{
pathname: '/base-ui/react-number-input/hooks-api/#use-number-input',
title: 'useNumberInput',
},
{ pathname: '/base-ui/react-select/hooks-api/#use-option', title: 'useOption' },
{
pathname: '/base-ui/react-select/hooks-api/#use-option-context-stabilizer',
title: 'useOptionContextStabilizer',
},
{ pathname: '/base-ui/react-select/hooks-api/#use-select', title: 'useSelect' },
{ pathname: '/base-ui/react-slider/hooks-api/#use-slider', title: 'useSlider' },
{
pathname: '/base-ui/react-snackbar/hooks-api/#use-snackbar',
title: 'useSnackbar',
},
{ pathname: '/base-ui/react-switch/hooks-api/#use-switch', title: 'useSwitch' },
{ pathname: '/base-ui/react-tabs/hooks-api/#use-tab', title: 'useTab' },
{ pathname: '/base-ui/react-tabs/hooks-api/#use-tab-panel', title: 'useTabPanel' },
{ pathname: '/base-ui/react-tabs/hooks-api/#use-tabs', title: 'useTabs' },
{ pathname: '/base-ui/react-tabs/hooks-api/#use-tabs-list', title: 'useTabsList' },
];
| 120 |
0 | petrpan-code/mui/material-ui/docs/data/base | petrpan-code/mui/material-ui/docs/data/base/all-components/all-components.md | # Base UI components
<p class="description">Every Base UI component available so far, sorted alphabetically.</p>
{{"component": "modules/components/BaseUIComponents.js"}}
| 121 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/accordion/accordion.md | ---
productId: base-ui
title: React Accordion component
githubLabel: 'component: accordion'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/accordion/
---
# Accordion 🚧
<p class="description">Accordions let users show and hide sections of related content on a page.</p>
:::warning
The Base UI Accordion component isn't available yet, but you can upvote [this GitHub issue](https://github.com/mui/material-ui/issues/38037) to see it arrive sooner.
:::
| 122 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/ControlledStates.js | import * as React from 'react';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { styled } from '@mui/system';
const options = ['Firefox', 'Google Chrome', 'Microsoft Edge', 'Safari', 'Opera'];
export default function ControlledStates() {
const [value, setValue] = React.useState(options[0]);
const [inputValue, setInputValue] = React.useState('');
const {
getRootProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,
focused,
} = useAutocomplete({
id: 'controlled-state-demo',
options,
value,
onChange: (event, newValue) => setValue(newValue),
inputValue,
onInputChange: (event, newInputValue) => setInputValue(newInputValue),
});
return (
<Layout>
<Pre>
value: <code>{value ?? ' '}</code>
</Pre>
<Pre>
inputValue: <code>{inputValue ?? ' '}</code>
</Pre>
<StyledAutocomplete>
<StyledInputRoot {...getRootProps()} className={focused ? 'focused' : ''}>
<StyledInput {...getInputProps()} />
</StyledInputRoot>
{groupedOptions.length > 0 && (
<StyledListbox {...getListboxProps()}>
{groupedOptions.map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option}
</StyledOption>
))}
</StyledListbox>
)}
</StyledAutocomplete>
</Layout>
);
}
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 StyledAutocomplete = styled('div')`
position: relative;
`;
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[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
const StyledListbox = styled('ul')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
max-width: 320px;
border-radius: 12px;
overflow: auto;
outline: 0px;
max-height: 300px;
z-index: 1;
position: absolute;
left: 0;
right: 0;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
const Layout = styled('div')`
display: flex;
flex-flow: column nowrap;
gap: 4px;
`;
const Pre = styled('pre')(({ theme }) => ({
margin: '0.5rem 0',
fontSize: '0.75rem',
'& code': {
backgroundColor: theme.palette.mode === 'light' ? grey[100] : grey[900],
border: '1px solid',
borderColor: theme.palette.mode === 'light' ? grey[300] : grey[700],
color: theme.palette.mode === 'light' ? '#000' : '#fff',
padding: '0.125rem 0.25rem',
borderRadius: 3,
},
}));
| 123 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/ControlledStates.tsx | import * as React from 'react';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { styled } from '@mui/system';
const options = ['Firefox', 'Google Chrome', 'Microsoft Edge', 'Safari', 'Opera'];
export default function ControlledStates() {
const [value, setValue] = React.useState<string | null>(options[0]);
const [inputValue, setInputValue] = React.useState('');
const {
getRootProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,
focused,
} = useAutocomplete({
id: 'controlled-state-demo',
options,
value,
onChange: (event, newValue) => setValue(newValue),
inputValue,
onInputChange: (event, newInputValue) => setInputValue(newInputValue),
});
return (
<Layout>
<Pre>
value: <code>{value ?? ' '}</code>
</Pre>
<Pre>
inputValue: <code>{inputValue ?? ' '}</code>
</Pre>
<StyledAutocomplete>
<StyledInputRoot {...getRootProps()} className={focused ? 'focused' : ''}>
<StyledInput {...getInputProps()} />
</StyledInputRoot>
{groupedOptions.length > 0 && (
<StyledListbox {...getListboxProps()}>
{(groupedOptions as string[]).map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option}
</StyledOption>
))}
</StyledListbox>
)}
</StyledAutocomplete>
</Layout>
);
}
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 StyledAutocomplete = styled('div')`
position: relative;
`;
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[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
const StyledListbox = styled('ul')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
max-width: 320px;
border-radius: 12px;
overflow: auto;
outline: 0px;
max-height: 300px;
z-index: 1;
position: absolute;
left: 0;
right: 0;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
const Layout = styled('div')`
display: flex;
flex-flow: column nowrap;
gap: 4px;
`;
const Pre = styled('pre')(({ theme }) => ({
margin: '0.5rem 0',
fontSize: '0.75rem',
'& code': {
backgroundColor: theme.palette.mode === 'light' ? grey[100] : grey[900],
border: '1px solid',
borderColor: theme.palette.mode === 'light' ? grey[300] : grey[700],
color: theme.palette.mode === 'light' ? '#000' : '#fff',
padding: '0.125rem 0.25rem',
borderRadius: 3,
},
}));
| 124 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/UseAutocomplete.js | import * as React from 'react';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { styled } from '@mui/system';
export default function UseAutocomplete() {
const [value, setValue] = React.useState(null);
const {
getRootProps,
getInputLabelProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,
focused,
} = useAutocomplete({
id: 'use-autocomplete-demo',
options: top100Films,
getOptionLabel: (option) => option.label,
value,
onChange: (event, newValue) => setValue(newValue),
});
return (
<div style={{ marginBottom: 24 }}>
<StyledLabel {...getInputLabelProps()}>Pick a movie</StyledLabel>
<StyledAutocompleteRoot
{...getRootProps()}
className={focused ? 'focused' : ''}
>
<StyledInput {...getInputProps()} />
</StyledAutocompleteRoot>
{groupedOptions.length > 0 && (
<StyledListbox {...getListboxProps()}>
{groupedOptions.map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option.label}
</StyledOption>
))}
</StyledListbox>
)}
</div>
);
}
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 StyledLabel = styled('label')`
display: block;
font-family: sans-serif;
font-size: 14px;
font-weight: 500;
margin-bottom: 4px;
`;
const StyledAutocompleteRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
const StyledListbox = styled('ul')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
width: 320px;
border-radius: 12px;
overflow: auto;
outline: 0px;
max-height: 300px;
z-index: 1;
position: absolute;
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 3px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 125 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/UseAutocomplete.tsx | import * as React from 'react';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { styled } from '@mui/system';
export default function UseAutocomplete() {
const [value, setValue] = React.useState<(typeof top100Films)[number] | null>(
null,
);
const {
getRootProps,
getInputLabelProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,
focused,
} = useAutocomplete({
id: 'use-autocomplete-demo',
options: top100Films,
getOptionLabel: (option) => option.label,
value,
onChange: (event, newValue) => setValue(newValue),
});
return (
<div style={{ marginBottom: 24 }}>
<StyledLabel {...getInputLabelProps()}>Pick a movie</StyledLabel>
<StyledAutocompleteRoot
{...getRootProps()}
className={focused ? 'focused' : ''}
>
<StyledInput {...getInputProps()} />
</StyledAutocompleteRoot>
{groupedOptions.length > 0 && (
<StyledListbox {...getListboxProps()}>
{(groupedOptions as typeof top100Films).map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option.label}
</StyledOption>
))}
</StyledListbox>
)}
</div>
);
}
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 StyledLabel = styled('label')`
display: block;
font-family: sans-serif;
font-size: 14px;
font-weight: 500;
margin-bottom: 4px;
`;
const StyledAutocompleteRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
const StyledListbox = styled('ul')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
width: 320px;
border-radius: 12px;
overflow: auto;
outline: 0px;
max-height: 300px;
z-index: 1;
position: absolute;
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 3px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 126 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/UseAutocomplete.tsx.preview | <StyledLabel {...getInputLabelProps()}>Pick a movie</StyledLabel>
<StyledAutocompleteRoot
{...getRootProps()}
className={focused ? 'focused' : ''}
>
<StyledInput {...getInputProps()} />
</StyledAutocompleteRoot>
{groupedOptions.length > 0 && (
<StyledListbox {...getListboxProps()}>
{(groupedOptions as typeof top100Films).map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option.label}
</StyledOption>
))}
</StyledListbox>
)} | 127 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/UseAutocompletePopper.js | import * as React from 'react';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import useForkRef from '@mui/utils/useForkRef';
const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
const {
getRootProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,
focused,
popupOpen,
anchorEl,
setAnchorEl,
} = useAutocomplete(props);
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<StyledAutocompleteRoot
{...getRootProps()}
ref={rootRef}
className={focused ? 'focused' : ''}
>
<StyledInput {...getInputProps()} />
</StyledAutocompleteRoot>
{anchorEl && (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slots={{
root: StyledPopper,
}}
>
<StyledListbox {...getListboxProps()}>
{groupedOptions.length > 0 ? (
groupedOptions.map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option.label}
</StyledOption>
))
) : (
<StyledNoOptions>No results</StyledNoOptions>
)}
</StyledListbox>
</Popper>
)}
</React.Fragment>
);
});
export default function UseAutocompletePopper() {
const [value, setValue] = React.useState(null);
const handleChange = (event, newValue) => setValue(newValue);
return (
<Autocomplete options={top100Films} value={value} onChange={handleChange} />
);
}
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 StyledAutocompleteRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
margin: 1.5rem 0;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
// ComponentPageTabs has z-index: 1000
const StyledPopper = styled('div')`
position: relative;
z-index: 1001;
width: 320px;
`;
const StyledListbox = 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;
max-height: 300px;
z-index: 1;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
const StyledNoOptions = styled('li')`
list-style: none;
padding: 8px;
cursor: default;
`;
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 128 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/UseAutocompletePopper.tsx | import * as React from 'react';
import { useAutocomplete, UseAutocompleteProps } from '@mui/base/useAutocomplete';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import useForkRef from '@mui/utils/useForkRef';
const Autocomplete = React.forwardRef(function Autocomplete(
props: UseAutocompleteProps<(typeof top100Films)[number], false, false, false>,
ref: React.ForwardedRef<HTMLDivElement>,
) {
const {
getRootProps,
getInputProps,
getListboxProps,
getOptionProps,
groupedOptions,
focused,
popupOpen,
anchorEl,
setAnchorEl,
} = useAutocomplete(props);
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<StyledAutocompleteRoot
{...getRootProps()}
ref={rootRef}
className={focused ? 'focused' : ''}
>
<StyledInput {...getInputProps()} />
</StyledAutocompleteRoot>
{anchorEl && (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slots={{
root: StyledPopper,
}}
>
<StyledListbox {...getListboxProps()}>
{groupedOptions.length > 0 ? (
(groupedOptions as typeof top100Films).map((option, index) => (
<StyledOption {...getOptionProps({ option, index })}>
{option.label}
</StyledOption>
))
) : (
<StyledNoOptions>No results</StyledNoOptions>
)}
</StyledListbox>
</Popper>
)}
</React.Fragment>
);
});
export default function UseAutocompletePopper() {
const [value, setValue] = React.useState<(typeof top100Films)[number] | null>(
null,
);
const handleChange = (
event: React.SyntheticEvent,
newValue: (typeof top100Films)[number] | null,
) => setValue(newValue);
return (
<Autocomplete options={top100Films} value={value} onChange={handleChange} />
);
}
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 StyledAutocompleteRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
margin: 1.5rem 0;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
border-color: ${blue[400]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
// ComponentPageTabs has z-index: 1000
const StyledPopper = styled('div')`
position: relative;
z-index: 1001;
width: 320px;
`;
const StyledListbox = 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;
max-height: 300px;
z-index: 1;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
const StyledNoOptions = styled('li')`
list-style: none;
padding: 8px;
cursor: default;
`;
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 129 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/UseAutocompletePopper.tsx.preview | <Autocomplete options={top100Films} value={value} onChange={handleChange} /> | 130 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/autocomplete.md | ---
productId: base-ui
title: React Autocomplete hook
hooks: useAutocomplete
githubLabel: 'component: autocomplete'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/
---
# Autocomplete
<p class="description">An autocomplete component is a text input enhanced by a panel of suggested options.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
An autocomplete component is an enhanced text input that shows a list of suggested options as users type, and lets them select an option from the list.
Base UI provides the `useAutocomplete` hook for building a custom Autocomplete.
It implements the WAI-ARIA Combobox pattern, and is typically used to assist users in completing form inputs or search queries faster.
{{"demo": "AutocompleteIntroduction", "defaultCodeOpen": false, "bg": "gradient"}}
:::warning
Material UI and Joy UI have Autocomplete components that are built using the `useAutocomplete` hook, and they include many features not yet described here.
To learn more about implementing a custom Autocomplete, you can explore the [`useAutocomplete` API docs](/base-ui/react-autocomplete/hooks-api/#use-autocomplete), or reference the Material UI and Joy UI implementations:
- [Material UI Autocomplete](/material-ui/react-autocomplete/)
- [Joy UI Autocomplete](/joy-ui/react-autocomplete/)
:::
## Hook
```jsx
import { useAutocomplete } from '@mui/base/useAutocomplete';
```
The `useAutocomplete` hook requires a list of `options` to be displayed when the textbox receives focus.
The value must be chosen from a predefined set of values.
The following demo shows how to create a simple combobox, apply styles, and write the selected value to a state variable using the `onChange` prop:
{{"demo": "UseAutocomplete.js"}}
## Customization
### Rendering options
By default, the `options` prop accepts an array of `string`s or `{ label: string }`:
```js
const options = [
{ label: 'The Godfather', id: 1 },
{ label: 'Pulp Fiction', id: 2 },
];
// or
const options = ['The Godfather', 'Pulp Fiction'];
```
If you need to use a different structure for options, you must provide a function to the `getOptionLabel` prop that resolves each option to a unique value.
```js
const options = [
{ issuer: 'Bank of America', brand: 'Visa', last4: '1234' },
{ issuer: 'Bank of America', brand: 'MasterCard', last4: '5678' },
{ issuer: 'Barclays', brand: 'Visa', last4: '4698' },
// ...
];
const {
getRootProps,
// etc
} = useAutocomplete({
getOptionLabel: (option) => option.last4,
});
```
### Controlled states
The `useAutocomplete` hook has two states that can be controlled:
1. the "value" state with the `value`/`onChange` props combination. This state represents the value selected by the user, for instance when pressing <kbd class="key">Enter</kbd>.
2. the "input value" state with the `inputValue`/`onInputChange` props combination. This state represents the value displayed in the textbox.
These two states are isolated, and should be controlled independently.
:::info
- A component is **controlled** when it's managed by its parent using props.
- A component is **uncontrolled** when it's managed by its own local state.
Learn more about controlled and uncontrolled components in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components).
:::
{{"demo": "ControlledStates.js"}}
### Using a portal
React Portals can be used to render the listbox outside of the DOM hierarchy, making it easier to allow it to "float" above adjacent elements.
Base UI provides a [Popper](/base-ui/react-popper/) component built around React's `createPortal()` for exactly this purpose, and additionally helps you manage keyboard focus as it moves in and out of the portal.
To render the listbox in Base UI's Popper, the `ref`s must be merged as follows:
```jsx
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { Popper } from '@mui/base/Popper';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
export default function App(props) {
const {
getRootProps,
getInputProps,
getListboxProps,
getOptionProps,
popupOpen,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete(props);
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<div {...getRootProps()} ref={rootRef}>
<input {...getInputProps()} />
</div>
{anchorEl && (
<Popper open={popupOpen} anchorEl={anchorEl}>
{groupedOptions.length > 0 && (
<ul {...getListboxProps()}>
{groupedOptions.map((option, index) => (
<li {...getOptionProps({ option, index })}>{option.label}</li>
))}
</ul>
)}
</Popper>
)}
</React.Fragment>
);
}
```
Here's a complete demo that renders the listbox inside a Popper:
{{"demo": "UseAutocompletePopper.js", "defaultCodeOpen": false}}
| 131 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/css/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { Button } from '@mui/base/Button';
import { Input } from '@mui/base/Input';
import { Popper } from '@mui/base/Popper';
import { useTheme } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import ClearIcon from '@mui/icons-material/Clear';
import clsx from 'clsx';
const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
const {
disableClearable = false,
disabled = false,
readOnly = false,
options,
...other
} = props;
const {
getRootProps,
getInputProps,
getPopupIndicatorProps,
getClearProps,
getListboxProps,
getOptionProps,
dirty,
id,
popupOpen,
focused,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete({
...props,
componentName: 'BaseAutocompleteIntroduction',
});
const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<div
{...getRootProps(other)}
ref={rootRef}
className={clsx('Autocomplete__root', focused && 'focused')}
>
<Input
id={id}
ref={setAnchorEl}
disabled={disabled}
readOnly={readOnly}
slotProps={{
root: {
className: 'Autocomplete__input-root',
},
input: {
className: 'Autocomplete__input',
...getInputProps(),
},
}}
/>
{hasClearIcon && (
<Button
{...getClearProps()}
className="Autocomplete__indicator clear-indicator"
>
<ClearIcon />
</Button>
)}
<Button
{...getPopupIndicatorProps()}
className={clsx(
'Autocomplete__indicator',
'popup-indicator',
popupOpen && 'popupOpen',
)}
>
<ArrowDropDownIcon />
</Button>
</div>
{anchorEl ? (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slotProps={{
root: { className: 'Autocomplete__popper' },
}}
modifiers={[
{ name: 'flip', enabled: false },
{ name: 'preventOverflow', enabled: false },
]}
>
<ul {...getListboxProps()} className="Autocomplete__listbox">
{groupedOptions.map((option, index) => {
const optionProps = getOptionProps({ option, index });
return (
<li {...optionProps} className="Autocomplete__option">
{option.label}
</li>
);
})}
{groupedOptions.length === 0 && (
<li className="Autocomplete__no-options">No results</li>
)}
</ul>
</Popper>
) : null}
<Styles />
</React.Fragment>
);
});
Autocomplete.propTypes = {
/**
* If `true`, the input can't be cleared.
* @default false
*/
disableClearable: PropTypes.oneOf([false]),
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* Array of options.
*/
options: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
year: PropTypes.number.isRequired,
}),
).isRequired,
/**
* If `true`, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
* @default false
*/
readOnly: PropTypes.bool,
};
export default function AutocompleteIntroduction() {
return <Autocomplete options={top100Films} />;
}
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>
{`
.Autocomplete__root {
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
color: ${isDarkMode ? grey[300] : grey[900]};
box-shadow: 0px 2px 4px ${
isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
&:hover {
border-color: ${cyan[400]};
}
&:focus-visible {
outline: 0;
}
}
.Autocomplete__popper {
position: relative;
z-index: 1001;
width: 320px;
}
.Autocomplete__input-root {
background: inherit;
border-radius: inherit;
flex: 1 0 auto;
}
.Autocomplete__input {
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}
.Autocomplete__indicator {
outline: 0;
box-shadow: none;
border: 0;
border-radius: 4px;
background-color: transparent;
align-self: center;
padding: 0 2px;
margin-right: 4px;
&:hover {
background-color: ${isDarkMode ? grey[700] : cyan[100]};
cursor: pointer;
}
}
.Autocomplete__indicator.popup-indicator > svg {
transform: translateY(2px);
}
.Autocomplete__indicator.popup-indicator.popupOpen > svg {
transform: translateY(2px) rotate(180deg);
}
.Autocomplete__indicator.clear-indicator > svg {
transform: translateY(2px) scale(0.9);
}
.Autocomplete__listbox {
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
width: 100%;
border-radius: 12px;
overflow: auto;
outline: 0px;
max-height: 300px;
z-index: 1;
position: absolute;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
color: ${isDarkMode ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
}
.Autocomplete__option {
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${isDarkMode ? cyan[900] : cyan[100]};
color: ${isDarkMode ? cyan[100] : cyan[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${isDarkMode ? grey[800] : grey[100]};
color: ${isDarkMode ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${isDarkMode ? cyan[900] : cyan[100]};
color: ${isDarkMode ? cyan[100] : cyan[900]};
}
}
.Autocomplete__no-options {
list-style: none;
padding: 8px;
cursor: default;
}
`}
</style>
);
}
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 132 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/css/index.tsx | import * as React from 'react';
import { useAutocomplete, UseAutocompleteProps } from '@mui/base/useAutocomplete';
import { Button } from '@mui/base/Button';
import { Input } from '@mui/base/Input';
import { Popper } from '@mui/base/Popper';
import { useTheme } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import ClearIcon from '@mui/icons-material/Clear';
import clsx from 'clsx';
const Autocomplete = React.forwardRef(function Autocomplete(
props: UseAutocompleteProps<(typeof top100Films)[number], false, false, false>,
ref: React.ForwardedRef<HTMLDivElement>,
) {
const {
disableClearable = false,
disabled = false,
readOnly = false,
options,
...other
} = props;
const {
getRootProps,
getInputProps,
getPopupIndicatorProps,
getClearProps,
getListboxProps,
getOptionProps,
dirty,
id,
popupOpen,
focused,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete({
...props,
componentName: 'BaseAutocompleteIntroduction',
});
const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<div
{...getRootProps(other)}
ref={rootRef}
className={clsx('Autocomplete__root', focused && 'focused')}
>
<Input
id={id}
ref={setAnchorEl}
disabled={disabled}
readOnly={readOnly}
slotProps={{
root: {
className: 'Autocomplete__input-root',
},
input: {
className: 'Autocomplete__input',
...getInputProps(),
},
}}
/>
{hasClearIcon && (
<Button
{...getClearProps()}
className="Autocomplete__indicator clear-indicator"
>
<ClearIcon />
</Button>
)}
<Button
{...getPopupIndicatorProps()}
className={clsx(
'Autocomplete__indicator',
'popup-indicator',
popupOpen && 'popupOpen',
)}
>
<ArrowDropDownIcon />
</Button>
</div>
{anchorEl ? (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slotProps={{
root: { className: 'Autocomplete__popper' },
}}
modifiers={[
{ name: 'flip', enabled: false },
{ name: 'preventOverflow', enabled: false },
]}
>
<ul {...getListboxProps()} className="Autocomplete__listbox">
{(groupedOptions as typeof top100Films).map((option, index) => {
const optionProps = getOptionProps({ option, index });
return (
<li {...optionProps} className="Autocomplete__option">
{option.label}
</li>
);
})}
{groupedOptions.length === 0 && (
<li className="Autocomplete__no-options">No results</li>
)}
</ul>
</Popper>
) : null}
<Styles />
</React.Fragment>
);
});
export default function AutocompleteIntroduction() {
return <Autocomplete options={top100Films} />;
}
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>
{`
.Autocomplete__root {
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
color: ${isDarkMode ? grey[300] : grey[900]};
box-shadow: 0px 2px 4px ${
isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
&:hover {
border-color: ${cyan[400]};
}
&:focus-visible {
outline: 0;
}
}
.Autocomplete__popper {
position: relative;
z-index: 1001;
width: 320px;
}
.Autocomplete__input-root {
background: inherit;
border-radius: inherit;
flex: 1 0 auto;
}
.Autocomplete__input {
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}
.Autocomplete__indicator {
outline: 0;
box-shadow: none;
border: 0;
border-radius: 4px;
background-color: transparent;
align-self: center;
padding: 0 2px;
margin-right: 4px;
&:hover {
background-color: ${isDarkMode ? grey[700] : cyan[100]};
cursor: pointer;
}
}
.Autocomplete__indicator.popup-indicator > svg {
transform: translateY(2px);
}
.Autocomplete__indicator.popup-indicator.popupOpen > svg {
transform: translateY(2px) rotate(180deg);
}
.Autocomplete__indicator.clear-indicator > svg {
transform: translateY(2px) scale(0.9);
}
.Autocomplete__listbox {
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
padding: 6px;
margin: 12px 0;
width: 100%;
border-radius: 12px;
overflow: auto;
outline: 0px;
max-height: 300px;
z-index: 1;
position: absolute;
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
color: ${isDarkMode ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)'
};
}
.Autocomplete__option {
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${isDarkMode ? cyan[900] : cyan[100]};
color: ${isDarkMode ? cyan[100] : cyan[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${isDarkMode ? grey[800] : grey[100]};
color: ${isDarkMode ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${isDarkMode ? cyan[900] : cyan[100]};
color: ${isDarkMode ? cyan[100] : cyan[900]};
}
}
.Autocomplete__no-options {
list-style: none;
padding: 8px;
cursor: default;
}
`}
</style>
);
}
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 133 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/css/index.tsx.preview | <Autocomplete options={top100Films} /> | 134 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/system/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { Button } from '@mui/base/Button';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import ClearIcon from '@mui/icons-material/Clear';
const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
const {
disableClearable = false,
disabled = false,
readOnly = false,
...other
} = props;
const {
getRootProps,
getInputProps,
getPopupIndicatorProps,
getClearProps,
getListboxProps,
getOptionProps,
dirty,
id,
popupOpen,
focused,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete({
...props,
componentName: 'BaseAutocompleteIntroduction',
});
const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<StyledAutocompleteRoot
{...getRootProps(other)}
ref={rootRef}
className={focused ? 'focused' : undefined}
>
<StyledInput
id={id}
disabled={disabled}
readOnly={readOnly}
{...getInputProps()}
/>
{hasClearIcon && (
<StyledClearIndicator {...getClearProps()}>
<ClearIcon />
</StyledClearIndicator>
)}
<StyledPopupIndicator
{...getPopupIndicatorProps()}
className={popupOpen ? 'popupOpen' : undefined}
>
<ArrowDropDownIcon />
</StyledPopupIndicator>
</StyledAutocompleteRoot>
{anchorEl ? (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slots={{
root: StyledPopper,
}}
modifiers={[
{ name: 'flip', enabled: false },
{ name: 'preventOverflow', enabled: false },
]}
>
<StyledListbox {...getListboxProps()}>
{groupedOptions.map((option, index) => {
const optionProps = getOptionProps({ option, index });
return <StyledOption {...optionProps}>{option.label}</StyledOption>;
})}
{groupedOptions.length === 0 && (
<StyledNoOptions>No results</StyledNoOptions>
)}
</StyledListbox>
</Popper>
) : null}
</React.Fragment>
);
});
Autocomplete.propTypes = {
/**
* If `true`, the input can't be cleared.
* @default false
*/
disableClearable: PropTypes.oneOf([false]),
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* If `true`, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
* @default false
*/
readOnly: PropTypes.bool,
};
export default function AutocompleteIntroduction() {
return <Autocomplete options={top100Films} />;
}
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 StyledAutocompleteRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
// ComponentPageTabs has z-index: 1000
const StyledPopper = styled('div')`
position: relative;
z-index: 1001;
width: 320px;
`;
const StyledListbox = 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;
max-height: 300px;
z-index: 1;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.3)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
const StyledPopupIndicator = styled(Button)(
({ theme }) => `
outline: 0;
box-shadow: none;
border: 0;
border-radius: 4px;
background-color: transparent;
align-self: center;
padding: 0 2px;
&:hover {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : blue[100]};
cursor: pointer;
}
& > svg {
transform: translateY(2px);
}
&.popupOpen > svg {
transform: translateY(2px) rotate(180deg);
}
`,
);
const StyledClearIndicator = styled(Button)(
({ theme }) => `
outline: 0;
box-shadow: none;
border: 0;
border-radius: 4px;
background-color: transparent;
align-self: center;
padding: 0 2px;
&:hover {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : blue[100]};
cursor: pointer;
}
& > svg {
transform: translateY(2px) scale(0.9);
}
`,
);
const StyledNoOptions = styled('li')`
list-style: none;
padding: 8px;
cursor: default;
`;
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 135 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/system/index.tsx | import * as React from 'react';
import { useAutocomplete, UseAutocompleteProps } from '@mui/base/useAutocomplete';
import { Button } from '@mui/base/Button';
import { Popper } from '@mui/base/Popper';
import { styled } from '@mui/system';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import ClearIcon from '@mui/icons-material/Clear';
const Autocomplete = React.forwardRef(function Autocomplete(
props: UseAutocompleteProps<(typeof top100Films)[number], false, false, false>,
ref: React.ForwardedRef<HTMLDivElement>,
) {
const {
disableClearable = false,
disabled = false,
readOnly = false,
...other
} = props;
const {
getRootProps,
getInputProps,
getPopupIndicatorProps,
getClearProps,
getListboxProps,
getOptionProps,
dirty,
id,
popupOpen,
focused,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete({
...props,
componentName: 'BaseAutocompleteIntroduction',
});
const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<StyledAutocompleteRoot
{...getRootProps(other)}
ref={rootRef}
className={focused ? 'focused' : undefined}
>
<StyledInput
id={id}
disabled={disabled}
readOnly={readOnly}
{...getInputProps()}
/>
{hasClearIcon && (
<StyledClearIndicator {...getClearProps()}>
<ClearIcon />
</StyledClearIndicator>
)}
<StyledPopupIndicator
{...getPopupIndicatorProps()}
className={popupOpen ? 'popupOpen' : undefined}
>
<ArrowDropDownIcon />
</StyledPopupIndicator>
</StyledAutocompleteRoot>
{anchorEl ? (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slots={{
root: StyledPopper,
}}
modifiers={[
{ name: 'flip', enabled: false },
{ name: 'preventOverflow', enabled: false },
]}
>
<StyledListbox {...getListboxProps()}>
{(groupedOptions as typeof top100Films).map((option, index) => {
const optionProps = getOptionProps({ option, index });
return <StyledOption {...optionProps}>{option.label}</StyledOption>;
})}
{groupedOptions.length === 0 && (
<StyledNoOptions>No results</StyledNoOptions>
)}
</StyledListbox>
</Popper>
) : null}
</React.Fragment>
);
});
export default function AutocompleteIntroduction() {
return <Autocomplete options={top100Films} />;
}
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 StyledAutocompleteRoot = styled('div')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 400;
border-radius: 8px;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[500]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
display: flex;
gap: 5px;
padding-right: 5px;
overflow: hidden;
width: 320px;
&.focused {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
}
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]};
}
&:focus-visible {
outline: 0;
}
`,
);
const StyledInput = styled('input')(
({ theme }) => `
font-size: 0.875rem;
font-family: inherit;
font-weight: 400;
line-height: 1.5;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: inherit;
border: none;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
flex: 1 0 auto;
`,
);
// ComponentPageTabs has z-index: 1000
const StyledPopper = styled('div')`
position: relative;
z-index: 1001;
width: 320px;
`;
const StyledListbox = 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;
max-height: 300px;
z-index: 1;
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
box-shadow: 0px 4px 6px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.3)' : 'rgba(0,0,0, 0.05)'
};
`,
);
const StyledOption = styled('li')(
({ theme }) => `
list-style: none;
padding: 8px;
border-radius: 8px;
cursor: default;
&:last-of-type {
border-bottom: none;
}
&:hover {
cursor: pointer;
}
&[aria-selected=true] {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
&.Mui-focused,
&.Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
&.Mui-focusVisible {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[500] : blue[200]};
}
&[aria-selected=true].Mui-focused,
&[aria-selected=true].Mui-focusVisible {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);
const StyledPopupIndicator = styled(Button)(
({ theme }) => `
outline: 0;
box-shadow: none;
border: 0;
border-radius: 4px;
background-color: transparent;
align-self: center;
padding: 0 2px;
&:hover {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : blue[100]};
cursor: pointer;
}
& > svg {
transform: translateY(2px);
}
&.popupOpen > svg {
transform: translateY(2px) rotate(180deg);
}
`,
);
const StyledClearIndicator = styled(Button)(
({ theme }) => `
outline: 0;
box-shadow: none;
border: 0;
border-radius: 4px;
background-color: transparent;
align-self: center;
padding: 0 2px;
&:hover {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : blue[100]};
cursor: pointer;
}
& > svg {
transform: translateY(2px) scale(0.9);
}
`,
);
const StyledNoOptions = styled('li')`
list-style: none;
padding: 8px;
cursor: default;
`;
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 136 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/system/index.tsx.preview | <Autocomplete options={top100Films} /> | 137 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/tailwind/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { useAutocomplete } from '@mui/base/useAutocomplete';
import { Button } from '@mui/base/Button';
import { Popper } from '@mui/base/Popper';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import ClearIcon from '@mui/icons-material/Clear';
import clsx from 'clsx';
const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
const {
disableClearable = false,
disabled = false,
readOnly = false,
options,
isOptionEqualToValue,
...other
} = props;
const {
getRootProps,
getInputProps,
getPopupIndicatorProps,
getClearProps,
getListboxProps,
getOptionProps,
dirty,
id,
popupOpen,
focused,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete({
...props,
componentName: 'BaseAutocompleteIntroduction',
});
const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<div
{...getRootProps(other)}
ref={rootRef}
className={clsx(
'flex gap-[5px] pr-[5px] overflow-hidden w-80 rounded-lg bg-white dark:bg-gray-800 border border-solid border-gray-200 dark:border-gray-700 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 shadow-[0_2px_4px_rgb(0_0_0_/_0.05)] dark:shadow-[0_2px_4px_rgb(0_0_0_/_0.5)]',
!focused &&
'shadow-[0_2px_2px_transparent] shadow-gray-50 dark:shadow-gray-900',
focused &&
'border-violet-400 dark:border-violet-400 shadow-[0_0_0_3px_transparent] shadow-violet-200 dark:shadow-violet-500',
)}
>
<input
id={id}
disabled={disabled}
readOnly={readOnly}
{...getInputProps()}
className="text-sm leading-[1.5] text-gray-900 dark:text-gray-300 bg-inherit border-0 rounded-[inherit] px-3 py-2 outline-0 grow shrink-0 basis-auto"
/>
{hasClearIcon && (
<Button
{...getClearProps()}
className="self-center outline-0 shadow-none border-0 py-0 px-0.5 rounded-[4px] bg-transparent hover:bg-violet-100 dark:hover:bg-gray-700 hover:cursor-pointer"
>
<ClearIcon className="translate-y-[2px] scale-90" />
</Button>
)}
<Button
{...getPopupIndicatorProps()}
className="self-center outline-0 shadow-none border-0 py-0 px-0.5 rounded-[4px] bg-transparent hover:bg-violet-100 dark:hover:bg-gray-700 hover:cursor-pointer"
>
<ArrowDropDownIcon
className={clsx('translate-y-[2px]', popupOpen && 'rotate-180')}
/>
</Button>
</div>
{anchorEl && (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slotProps={{
root: {
className: 'relative z-[1001] w-80', // z-index: 1001 is needed to override ComponentPageTabs with z-index: 1000
},
}}
modifiers={[
{ name: 'flip', enabled: false },
{ name: 'preventOverflow', enabled: false },
]}
>
<ul
{...getListboxProps()}
className="text-sm box-border p-1.5 my-3 mx-0 min-w-[320px] rounded-xl overflow-auto outline-0 max-h-[300px] z-[1] bg-white dark:bg-gray-800 border border-solid border-gray-200 dark:border-gray-900 text-gray-900 dark:text-gray-200 shadow-[0_4px_30px_transparent] shadow-gray-200 dark:shadow-gray-900"
>
{groupedOptions.map((option, index) => {
const optionProps = getOptionProps({ option, index });
return (
<li
{...optionProps}
className="list-none p-2 rounded-lg cursor-default last-of-type:border-b-0 hover:cursor-pointer aria-selected:bg-violet-100 dark:aria-selected:bg-violet-900 aria-selected:text-violet-900 dark:aria-selected:text-violet-100 ui-focused:bg-gray-100 dark:ui-focused:bg-gray-700 ui-focus-visible:bg-gray-100 dark:ui-focus-visible:bg-gray-800 ui-focused:text-gray-900 dark:ui-focused:text-gray-300 ui-focus-visible:text-gray-900 dark:ui-focus-visible:text-gray-300 ui-focus-visible:shadow-[0_0_0_3px_transparent] ui-focus-visible:shadow-violet-200 dark:ui-focus-visible:shadow-violet-500 ui-focused:aria-selected:bg-violet-100 dark:ui-focused:aria-selected:bg-violet-900 ui-focus-visible:aria-selected:bg-violet-100 dark:ui-focus-visible:aria-selected:bg-violet-900 ui-focused:aria-selected:text-violet-900 dark:ui-focused:aria-selected:text-violet-100 ui-focus-visible:aria-selected:text-violet-900 dark:ui-focus-visible:aria-selected:text-violet-100"
>
{option.label}
</li>
);
})}
{groupedOptions.length === 0 && (
<li className="list-none p-2 cursor-default">No results</li>
)}
</ul>
</Popper>
)}
</React.Fragment>
);
});
Autocomplete.propTypes = {
/**
* If `true`, the input can't be cleared.
* @default false
*/
disableClearable: PropTypes.oneOf([false]),
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
/**
* Used to determine if the option represents the given value.
* Uses strict equality by default.
* ⚠️ Both arguments need to be handled, an option can only match with one value.
*
* @param {Value} option The option to test.
* @param {Value} value The value to test against.
* @returns {boolean}
*/
isOptionEqualToValue: PropTypes.func,
/**
* Array of options.
*/
options: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
year: PropTypes.number.isRequired,
}),
).isRequired,
/**
* If `true`, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
* @default false
*/
readOnly: PropTypes.bool,
};
export default function AutocompleteIntroduction() {
return (
<Autocomplete
options={top100Films}
isOptionEqualToValue={(option, value) => option.label === value.label}
/>
);
}
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 138 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/tailwind/index.tsx | import * as React from 'react';
import { useAutocomplete, UseAutocompleteProps } from '@mui/base/useAutocomplete';
import { Button } from '@mui/base/Button';
import { Popper } from '@mui/base/Popper';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import ClearIcon from '@mui/icons-material/Clear';
import clsx from 'clsx';
const Autocomplete = React.forwardRef(function Autocomplete(
props: UseAutocompleteProps<(typeof top100Films)[number], false, false, false>,
ref: React.ForwardedRef<HTMLDivElement>,
) {
const {
disableClearable = false,
disabled = false,
readOnly = false,
options,
isOptionEqualToValue,
...other
} = props;
const {
getRootProps,
getInputProps,
getPopupIndicatorProps,
getClearProps,
getListboxProps,
getOptionProps,
dirty,
id,
popupOpen,
focused,
anchorEl,
setAnchorEl,
groupedOptions,
} = useAutocomplete({
...props,
componentName: 'BaseAutocompleteIntroduction',
});
const hasClearIcon = !disableClearable && !disabled && dirty && !readOnly;
const rootRef = useForkRef(ref, setAnchorEl);
return (
<React.Fragment>
<div
{...getRootProps(other)}
ref={rootRef}
className={clsx(
'flex gap-[5px] pr-[5px] overflow-hidden w-80 rounded-lg bg-white dark:bg-gray-800 border border-solid border-gray-200 dark:border-gray-700 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 shadow-[0_2px_4px_rgb(0_0_0_/_0.05)] dark:shadow-[0_2px_4px_rgb(0_0_0_/_0.5)]',
!focused &&
'shadow-[0_2px_2px_transparent] shadow-gray-50 dark:shadow-gray-900',
focused &&
'border-violet-400 dark:border-violet-400 shadow-[0_0_0_3px_transparent] shadow-violet-200 dark:shadow-violet-500',
)}
>
<input
id={id}
disabled={disabled}
readOnly={readOnly}
{...getInputProps()}
className="text-sm leading-[1.5] text-gray-900 dark:text-gray-300 bg-inherit border-0 rounded-[inherit] px-3 py-2 outline-0 grow shrink-0 basis-auto"
/>
{hasClearIcon && (
<Button
{...getClearProps()}
className="self-center outline-0 shadow-none border-0 py-0 px-0.5 rounded-[4px] bg-transparent hover:bg-violet-100 dark:hover:bg-gray-700 hover:cursor-pointer"
>
<ClearIcon className="translate-y-[2px] scale-90" />
</Button>
)}
<Button
{...getPopupIndicatorProps()}
className="self-center outline-0 shadow-none border-0 py-0 px-0.5 rounded-[4px] bg-transparent hover:bg-violet-100 dark:hover:bg-gray-700 hover:cursor-pointer"
>
<ArrowDropDownIcon
className={clsx('translate-y-[2px]', popupOpen && 'rotate-180')}
/>
</Button>
</div>
{anchorEl && (
<Popper
open={popupOpen}
anchorEl={anchorEl}
slotProps={{
root: {
className: 'relative z-[1001] w-80', // z-index: 1001 is needed to override ComponentPageTabs with z-index: 1000
},
}}
modifiers={[
{ name: 'flip', enabled: false },
{ name: 'preventOverflow', enabled: false },
]}
>
<ul
{...getListboxProps()}
className="text-sm box-border p-1.5 my-3 mx-0 min-w-[320px] rounded-xl overflow-auto outline-0 max-h-[300px] z-[1] bg-white dark:bg-gray-800 border border-solid border-gray-200 dark:border-gray-900 text-gray-900 dark:text-gray-200 shadow-[0_4px_30px_transparent] shadow-gray-200 dark:shadow-gray-900"
>
{(groupedOptions as typeof top100Films).map((option, index) => {
const optionProps = getOptionProps({ option, index });
return (
<li
{...optionProps}
className="list-none p-2 rounded-lg cursor-default last-of-type:border-b-0 hover:cursor-pointer aria-selected:bg-violet-100 dark:aria-selected:bg-violet-900 aria-selected:text-violet-900 dark:aria-selected:text-violet-100 ui-focused:bg-gray-100 dark:ui-focused:bg-gray-700 ui-focus-visible:bg-gray-100 dark:ui-focus-visible:bg-gray-800 ui-focused:text-gray-900 dark:ui-focused:text-gray-300 ui-focus-visible:text-gray-900 dark:ui-focus-visible:text-gray-300 ui-focus-visible:shadow-[0_0_0_3px_transparent] ui-focus-visible:shadow-violet-200 dark:ui-focus-visible:shadow-violet-500 ui-focused:aria-selected:bg-violet-100 dark:ui-focused:aria-selected:bg-violet-900 ui-focus-visible:aria-selected:bg-violet-100 dark:ui-focus-visible:aria-selected:bg-violet-900 ui-focused:aria-selected:text-violet-900 dark:ui-focused:aria-selected:text-violet-100 ui-focus-visible:aria-selected:text-violet-900 dark:ui-focus-visible:aria-selected:text-violet-100"
>
{option.label}
</li>
);
})}
{groupedOptions.length === 0 && (
<li className="list-none p-2 cursor-default">No results</li>
)}
</ul>
</Popper>
)}
</React.Fragment>
);
});
export default function AutocompleteIntroduction() {
return (
<Autocomplete
options={top100Films}
isOptionEqualToValue={(option, value) => option.label === value.label}
/>
);
}
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];
| 139 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/autocomplete/AutocompleteIntroduction/tailwind/index.tsx.preview | <Autocomplete
options={top100Films}
isOptionEqualToValue={(option, value) => option.label === value.label}
/> | 140 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/AccessibleBadges.js | import * as React from 'react';
import { styled } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
import MailIcon from '@mui/icons-material/Mail';
function notificationsLabel(count) {
if (count === 0) {
return 'no notifications';
}
if (count > 99) {
return 'more than 99 notifications';
}
return `${count} notifications`;
}
export default function AccessibleBadges() {
return (
<div aria-label={notificationsLabel(100)}>
<Badge badgeContent={100}>
<MailIcon />
</Badge>
</div>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 141 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/AccessibleBadges.tsx | import * as React from 'react';
import { styled } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
import MailIcon from '@mui/icons-material/Mail';
function notificationsLabel(count: number) {
if (count === 0) {
return 'no notifications';
}
if (count > 99) {
return 'more than 99 notifications';
}
return `${count} notifications`;
}
export default function AccessibleBadges() {
return (
<div aria-label={notificationsLabel(100)}>
<Badge badgeContent={100}>
<MailIcon />
</Badge>
</div>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 142 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/AccessibleBadges.tsx.preview | <Badge badgeContent={100}>
<MailIcon />
</Badge> | 143 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/BadgeMax.js | import * as React from 'react';
import Stack from '@mui/material/Stack';
import { styled } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
import MailIcon from '@mui/icons-material/Mail';
export default function BadgeMax() {
return (
<Stack spacing={4} direction="row">
<Badge badgeContent={99}>
<MailIcon />
</Badge>
<Badge badgeContent={100}>
<MailIcon />
</Badge>
<Badge badgeContent={1000} max={999}>
<MailIcon />
</Badge>
</Stack>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 144 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/BadgeMax.tsx | import * as React from 'react';
import Stack from '@mui/material/Stack';
import { styled } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
import MailIcon from '@mui/icons-material/Mail';
export default function BadgeMax() {
return (
<Stack spacing={4} direction="row">
<Badge badgeContent={99}>
<MailIcon />
</Badge>
<Badge badgeContent={100}>
<MailIcon />
</Badge>
<Badge badgeContent={1000} max={999}>
<MailIcon />
</Badge>
</Stack>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 145 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/BadgeMax.tsx.preview | <Badge badgeContent={99}>
<MailIcon />
</Badge>
<Badge badgeContent={100}>
<MailIcon />
</Badge>
<Badge badgeContent={1000} max={999}>
<MailIcon />
</Badge> | 146 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/BadgeVisibility.js | import * as React from 'react';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
// Auxiliary demo components
import { styled, Stack } from '@mui/system';
import { Button, buttonClasses } from '@mui/base/Button';
import { Switch, switchClasses } from '@mui/base/Switch';
import Divider from '@mui/material/Divider';
// Icons
import AddIcon from '@mui/icons-material/Add';
import RemoveIcon from '@mui/icons-material/Remove';
import MailIcon from '@mui/icons-material/Mail';
const blue = {
200: '#99CCF3',
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
position: relative;
display: flex;
align-self: center;
margin: 0;
padding: 0;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
font-size: 14px;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
& .${badgeClasses.invisible} {
opacity: 0;
pointer-events: none;
}
`,
);
const StyledButton = styled(Button)(
({ theme }) => `
cursor: pointer;
padding: 4px 8px;
display: flex;
align-items: center;
border-radius: 8px;
transition: all 150ms ease;
background-color: transparent;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
}
&.${buttonClasses.active} {
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[100]};
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 3px 20px 0 rgba(61, 71, 82, 0.1), 0 0 0 4px rgba(0, 127, 255, 0.5);
outline: none;
}
`,
);
const Root = styled('span')(
({ theme }) => `
position: relative;
display: inline-block;
width: 32px;
height: 20px;
cursor: pointer;
& .${switchClasses.track} {
background: ${theme.palette.mode === 'dark' ? grey[600] : grey[400]};
border-radius: 16px;
display: block;
height: 100%;
width: 100%;
position: absolute;
}
& .${switchClasses.thumb} {
position: relative;
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}
&.${switchClasses.focusVisible} .${switchClasses.track} {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? grey[700] : blue[200]};
}
&.${switchClasses.checked} {
.${switchClasses.thumb} {
left: 15px;
top: 3px;
background-color: #fff;
}
.${switchClasses.track} {
background: ${blue[500]};
}
}
& .${switchClasses.input} {
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
}
`,
);
const StyledLabel = styled('label')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
`,
);
export default function BadgeVisibility() {
const [count, setCount] = React.useState(1);
const [invisible, setInvisible] = React.useState(false);
const handleBadgeVisibility = () => {
setInvisible(!invisible);
};
return (
<Stack direction="column" justifyContent="center" spacing={1} useFlexGap>
<Badge badgeContent={count} invisible={invisible}>
<MailIcon />
</Badge>
<Divider sx={{ my: 2 }} />
<Stack
direction="row"
justifyContent="center"
alignItems="center"
gap={1}
useFlexGap
>
<StyledButton
aria-label="decrease"
onClick={() => {
setCount(Math.max(count - 1, 0));
}}
>
<RemoveIcon fontSize="small" color="primary" />
</StyledButton>
<StyledButton
aria-label="increase"
onClick={() => {
setCount(count + 1);
}}
>
<AddIcon fontSize="small" color="primary" />
</StyledButton>
<Divider orientation="vertical" />
<Stack direction="row" spacing={1} useFlexGap>
<StyledLabel>Show badge</StyledLabel>
<Switch
slots={{
root: Root,
}}
checked={!invisible}
onChange={handleBadgeVisibility}
/>
</Stack>
</Stack>
</Stack>
);
}
| 147 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/BadgeVisibility.tsx | import * as React from 'react';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
// Auxiliary demo components
import { styled, Stack } from '@mui/system';
import { Button, buttonClasses } from '@mui/base/Button';
import { Switch, switchClasses } from '@mui/base/Switch';
import Divider from '@mui/material/Divider';
// Icons
import AddIcon from '@mui/icons-material/Add';
import RemoveIcon from '@mui/icons-material/Remove';
import MailIcon from '@mui/icons-material/Mail';
const blue = {
200: '#99CCF3',
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
position: relative;
display: flex;
align-self: center;
margin: 0;
padding: 0;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
font-size: 14px;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
& .${badgeClasses.invisible} {
opacity: 0;
pointer-events: none;
}
`,
);
const StyledButton = styled(Button)(
({ theme }) => `
cursor: pointer;
padding: 4px 8px;
display: flex;
align-items: center;
border-radius: 8px;
transition: all 150ms ease;
background-color: transparent;
border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]};
&:hover {
background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]};
}
&.${buttonClasses.active} {
background: ${theme.palette.mode === 'dark' ? grey[900] : grey[100]};
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 3px 20px 0 rgba(61, 71, 82, 0.1), 0 0 0 4px rgba(0, 127, 255, 0.5);
outline: none;
}
`,
);
const Root = styled('span')(
({ theme }) => `
position: relative;
display: inline-block;
width: 32px;
height: 20px;
cursor: pointer;
& .${switchClasses.track} {
background: ${theme.palette.mode === 'dark' ? grey[600] : grey[400]};
border-radius: 16px;
display: block;
height: 100%;
width: 100%;
position: absolute;
}
& .${switchClasses.thumb} {
position: relative;
display: block;
width: 14px;
height: 14px;
top: 3px;
left: 3px;
border-radius: 16px;
background-color: #fff;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}
&.${switchClasses.focusVisible} .${switchClasses.track} {
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? grey[700] : blue[200]};
}
&.${switchClasses.checked} {
.${switchClasses.thumb} {
left: 15px;
top: 3px;
background-color: #fff;
}
.${switchClasses.track} {
background: ${blue[500]};
}
}
& .${switchClasses.input} {
cursor: inherit;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
z-index: 1;
margin: 0;
}
`,
);
const StyledLabel = styled('label')(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
`,
);
export default function BadgeVisibility() {
const [count, setCount] = React.useState(1);
const [invisible, setInvisible] = React.useState(false);
const handleBadgeVisibility = () => {
setInvisible(!invisible);
};
return (
<Stack direction="column" justifyContent="center" spacing={1} useFlexGap>
<Badge badgeContent={count} invisible={invisible}>
<MailIcon />
</Badge>
<Divider sx={{ my: 2 }} />
<Stack
direction="row"
justifyContent="center"
alignItems="center"
gap={1}
useFlexGap
>
<StyledButton
aria-label="decrease"
onClick={() => {
setCount(Math.max(count - 1, 0));
}}
>
<RemoveIcon fontSize="small" color="primary" />
</StyledButton>
<StyledButton
aria-label="increase"
onClick={() => {
setCount(count + 1);
}}
>
<AddIcon fontSize="small" color="primary" />
</StyledButton>
<Divider orientation="vertical" />
<Stack direction="row" spacing={1} useFlexGap>
<StyledLabel>Show badge</StyledLabel>
<Switch
slots={{
root: Root,
}}
checked={!invisible}
onChange={handleBadgeVisibility}
/>
</Stack>
</Stack>
</Stack>
);
}
| 148 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/ShowZeroBadge.js | import * as React from 'react';
import Stack from '@mui/material/Stack';
import { styled } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
import MailIcon from '@mui/icons-material/Mail';
export default function ShowZeroBadge() {
return (
<Stack spacing={4} direction="row">
<Badge badgeContent={0}>
<MailIcon />
</Badge>
<Badge badgeContent={0} showZero>
<MailIcon />
</Badge>
</Stack>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
& .${badgeClasses.invisible} {
display: none;
}
`,
);
| 149 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/ShowZeroBadge.tsx | import * as React from 'react';
import Stack from '@mui/material/Stack';
import { styled } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
import MailIcon from '@mui/icons-material/Mail';
export default function ShowZeroBadge() {
return (
<Stack spacing={4} direction="row">
<Badge badgeContent={0}>
<MailIcon />
</Badge>
<Badge badgeContent={0} showZero>
<MailIcon />
</Badge>
</Stack>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 6x ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
& .${badgeClasses.invisible} {
display: none;
}
`,
);
| 150 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/ShowZeroBadge.tsx.preview | <Badge badgeContent={0}>
<MailIcon />
</Badge>
<Badge badgeContent={0} showZero>
<MailIcon />
</Badge> | 151 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/badge/badge.md | ---
productId: base-ui
title: React Badge component and hook
components: Badge
hooks: useBadge
githubLabel: 'component: badge'
---
# Badge
<p class="description">The Badge component generates a small label that is attached to its child element.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
A badge is a small descriptor for UI elements.
It typically sits on or near an element and indicates the status of that element by displaying a number, icon, or other short set of characters.
The Badge component creates a badge that is applied to its child element.
{{"demo": "UnstyledBadgeIntroduction", "defaultCodeOpen": false, "bg": "gradient"}}
## Component
```jsx
import { Badge } from '@mui/base/Badge';
```
The Badge wraps around the UI element that it's attached to.
### Anatomy
The Badge component is composed of a root `<span>` that houses the element that the Badge is attached to, followed by a `<span>` slot to represent the Badge itself:
```html
<span class="BaseBadge-root">
<!-- the element the badge is attached to is nested here -->
<span class="BaseBadge-badge">badge content</span>
</span>
```
### Custom structure
Use the `slots` prop to override the root or any other interior slot:
```jsx
<Badge slots={{ root: 'div', badge: 'div' }} />
```
:::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-badge` to the badge slot:
```jsx
<Badge slotProps={{ badge: { className: 'my-badge' } }} />
```
### Usage with TypeScript
In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component.
This way, you can safely provide the custom root's props directly on the component:
```tsx
<Badge<typeof CustomComponent> slots={{ root: CustomComponent }} customProp />
```
The same applies for props specific to custom primitive elements:
```tsx
<Badge<'img'> slots={{ root: 'img' }} src="badge.png" />
```
## Hook
```jsx
import { useBadge } from '@mui/base/useBadge';
```
The `useBadge` hook lets you apply the functionality of a Badge 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).
:::
## Customization
:::info
The following features can be used with both components and hooks.
For the sake of simplicity, demos and code snippets primarily feature components.
:::
### Badge content
The `badgeContent` prop defines the content that's displayed inside the Badge.
When this content is a number, there are additional props you can use for further customization—see the [Numerical Badges section](#numerical-badges) below.
The following demo shows how to create and style a typical numerical Badge that's attached to a generic box element:
{{"demo": "UnstyledBadge", "defaultCodeOpen": false}}
### Badge visibility
You can control the visibility of a Badge by using the `invisible` prop.
Setting a Badge to `invisible` does not actually hide it—instead, this prop adds the `BaseBadge-invisible` class to the Badge, which you can target with styles to hide however you prefer:
{{"demo": "BadgeVisibility.js"}}
### Numerical Badges
The following props are useful when `badgeContent` is a number.
#### The showZero prop
By default, Badges automatically hide when `badgeContent={0}`.
You can override this behavior with the `showZero` prop:
{{"demo": "ShowZeroBadge.js"}}
#### The max prop
You can use the `max` prop to set a maximum value for `badgeContent`.
The default is 99.
{{"demo": "BadgeMax.js"}}
## Accessibility
Screen readers may not provide users with enough information about a Badge's contents.
To make your badge accessible, you must provide a full description with `aria-label`, as shown in the demo below:
{{"demo": "AccessibleBadges.js"}}
| 152 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/css/index.js | import * as React from 'react';
import { Badge } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
export default function UnstyledBadge() {
return (
<React.Fragment>
<Badge
slotProps={{
root: { className: 'CustomBadge' },
badge: { className: 'CustomBadge--badge' },
}}
badgeContent={5}
>
<span className="CustomBadge--content" />
</Badge>
<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>
{`
.CustomBadge {
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
}
.CustomBadge--badge {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${cyan[500]};
box-shadow: 0px 4px 8px ${isDarkMode ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
.CustomBadge--content {
width: 40px;
height: 40px;
border-radius: 12px;
background: ${isDarkMode ? grey[400] : grey[300]};
display: inline-block;
vertical-align: middle;
}
`}
</style>
);
}
| 153 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/css/index.tsx | import * as React from 'react';
import { Badge } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
export default function UnstyledBadge() {
return (
<React.Fragment>
<Badge
slotProps={{
root: { className: 'CustomBadge' },
badge: { className: 'CustomBadge--badge' },
}}
badgeContent={5}
>
<span className="CustomBadge--content" />
</Badge>
<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>
{`
.CustomBadge {
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
}
.CustomBadge--badge {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${cyan[500]};
box-shadow: 0px 4px 8px ${isDarkMode ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
.CustomBadge--content {
width: 40px;
height: 40px;
border-radius: 12px;
background: ${isDarkMode ? grey[400] : grey[300]};
display: inline-block;
vertical-align: middle;
}
`}
</style>
);
}
| 154 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/css/index.tsx.preview | <React.Fragment>
<Badge
slotProps={{
root: { className: 'CustomBadge' },
badge: { className: 'CustomBadge--badge' },
}}
badgeContent={5}
>
<span className="CustomBadge--content" />
</Badge>
<Styles />
</React.Fragment> | 155 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/system/index.js | import * as React from 'react';
import { styled, Box } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
function BadgeContent() {
return (
<Box
component="span"
sx={{
width: 40,
height: 40,
borderRadius: '12px',
background: (theme) =>
theme.palette.mode === 'dark' ? grey[400] : grey[300],
display: 'inline-block',
verticalAlign: 'middle',
}}
/>
);
}
export default function UnstyledBadge() {
return (
<Badge badgeContent={5}>
<BadgeContent />
</Badge>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 8px ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 156 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/system/index.tsx | import * as React from 'react';
import { styled, Box } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
function BadgeContent() {
return (
<Box
component="span"
sx={{
width: 40,
height: 40,
borderRadius: '12px',
background: (theme) =>
theme.palette.mode === 'dark' ? grey[400] : grey[300],
display: 'inline-block',
verticalAlign: 'middle',
}}
/>
);
}
export default function UnstyledBadge() {
return (
<Badge badgeContent={5}>
<BadgeContent />
</Badge>
);
}
const blue = {
500: '#007FFF',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 4px 8px ${theme.palette.mode === 'dark' ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 157 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/system/index.tsx.preview | <Badge badgeContent={5}>
<BadgeContent />
</Badge> | 158 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/tailwind/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { Badge as BaseBadge } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function UnstyledBadge() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<div className={isDarkMode ? 'dark' : ''}>
<Badge badgeContent={5}>
<span className="w-10 h-10 rounded-xl bg-slate-300 dark:bg-slate-400 inline-block align-middle" />
</Badge>
</div>
);
}
const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn);
const Badge = React.forwardRef((props, ref) => {
return (
<BaseBadge
ref={ref}
{...props}
slotProps={{
...props.slotProps,
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'box-border m-0 p-0 text-xs font-sans list-none relative inline-block leading-none',
resolvedSlotProps?.className,
),
};
},
badge: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.badge,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'z-auto absolute top-0 right-0 min-w-badge min-h-badge font-sans p-0 text-white font-semibold font-xs rounded-xl bg-purple-500 leading-5.5 whitespace-nowrap text-center translate-x-1/2 -translate-y-1/2 drop-shadow-lg origin-right',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
Badge.propTypes = {
/**
* The props used for each slot inside the Badge.
* @default {}
*/
slotProps: PropTypes.shape({
badge: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};
| 159 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/tailwind/index.tsx | import * as React from 'react';
import clsx from 'clsx';
import { Badge as BaseBadge, BadgeProps } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function UnstyledBadge() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<div className={isDarkMode ? 'dark' : ''}>
<Badge badgeContent={5}>
<span className="w-10 h-10 rounded-xl bg-slate-300 dark:bg-slate-400 inline-block align-middle" />
</Badge>
</div>
);
}
const resolveSlotProps = (fn: any, args: any) =>
typeof fn === 'function' ? fn(args) : fn;
const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref) => {
return (
<BaseBadge
ref={ref}
{...props}
slotProps={{
...props.slotProps,
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'box-border m-0 p-0 text-xs font-sans list-none relative inline-block leading-none',
resolvedSlotProps?.className,
),
};
},
badge: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.badge,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'z-auto absolute top-0 right-0 min-w-badge min-h-badge font-sans p-0 text-white font-semibold font-xs rounded-xl bg-purple-500 leading-5.5 whitespace-nowrap text-center translate-x-1/2 -translate-y-1/2 drop-shadow-lg origin-right',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
| 160 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadge/tailwind/index.tsx.preview | <Badge badgeContent={5}>
<span className="w-10 h-10 rounded-xl bg-slate-300 dark:bg-slate-400 inline-block align-middle" />
</Badge> | 161 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/css/index.js | import * as React from 'react';
import { Badge } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
export default function UnstyledBadgeIntroduction() {
return (
<React.Fragment>
<Badge
slotProps={{
root: { className: 'CustomBadgeIntroduction' },
badge: { className: 'CustomBadgeIntroduction--badge' },
}}
badgeContent={5}
>
<span className="CustomBadgeIntroduction--content" />
</Badge>
<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>
{`
.CustomBadgeIntroduction {
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
}
.CustomBadgeIntroduction--badge {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${cyan[500]};
box-shadow: 0px 2px 24px ${isDarkMode ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
.CustomBadgeIntroduction--content {
width: 40px;
height: 40px;
border-radius: 12px;
background: ${isDarkMode ? grey[700] : grey[200]};
display: inline-block;
vertical-align: middle;
}
`}
</style>
);
}
| 162 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/css/index.tsx | import * as React from 'react';
import { Badge } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
export default function UnstyledBadgeIntroduction() {
return (
<React.Fragment>
<Badge
slotProps={{
root: { className: 'CustomBadgeIntroduction' },
badge: { className: 'CustomBadgeIntroduction--badge' },
}}
badgeContent={5}
>
<span className="CustomBadgeIntroduction--content" />
</Badge>
<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>
{`
.CustomBadgeIntroduction {
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
}
.CustomBadgeIntroduction--badge {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${cyan[500]};
box-shadow: 0px 2px 24px ${isDarkMode ? grey[900] : grey[300]};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
.CustomBadgeIntroduction--content {
width: 40px;
height: 40px;
border-radius: 12px;
background: ${isDarkMode ? grey[700] : grey[200]};
display: inline-block;
vertical-align: middle;
}
`}
</style>
);
}
| 163 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/css/index.tsx.preview | <React.Fragment>
<Badge
slotProps={{
root: { className: 'CustomBadgeIntroduction' },
badge: { className: 'CustomBadgeIntroduction--badge' },
}}
badgeContent={5}
>
<span className="CustomBadgeIntroduction--content" />
</Badge>
<Styles />
</React.Fragment> | 164 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/system/index.js | import * as React from 'react';
import { styled, Box } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
const blue = {
100: '#DAECFF',
500: '#007FFF',
900: '#003A75',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
function BadgeContent() {
return (
<Box
component="span"
sx={{
width: 40,
height: 40,
borderRadius: '12px',
background: (theme) =>
theme.palette.mode === 'dark' ? grey[700] : grey[200],
display: 'inline-block',
verticalAlign: 'middle',
}}
/>
);
}
export default function UnstyledBadgeIntroduction() {
return (
<Badge badgeContent={5}>
<BadgeContent />
</Badge>
);
}
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 2px 24px ${
theme.palette.mode === 'dark' ? blue[900] : blue[100]
};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 165 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/system/index.tsx | import * as React from 'react';
import { styled, Box } from '@mui/system';
import { Badge as BaseBadge, badgeClasses } from '@mui/base/Badge';
const blue = {
100: '#DAECFF',
500: '#007FFF',
900: '#003A75',
};
const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};
function BadgeContent() {
return (
<Box
component="span"
sx={{
width: 40,
height: 40,
borderRadius: '12px',
background: (theme) =>
theme.palette.mode === 'dark' ? grey[700] : grey[200],
display: 'inline-block',
verticalAlign: 'middle',
}}
/>
);
}
export default function UnstyledBadgeIntroduction() {
return (
<Badge badgeContent={5}>
<BadgeContent />
</Badge>
);
}
const Badge = styled(BaseBadge)(
({ theme }) => `
box-sizing: border-box;
margin: 0;
padding: 0;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-family: IBM Plex Sans, sans-serif;
position: relative;
display: inline-block;
line-height: 1;
& .${badgeClasses.badge} {
z-index: auto;
position: absolute;
top: 0;
right: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
color: #fff;
font-weight: 600;
font-size: 12px;
line-height: 22px;
white-space: nowrap;
text-align: center;
border-radius: 12px;
background: ${blue[500]};
box-shadow: 0px 2px 24px ${
theme.palette.mode === 'dark' ? blue[900] : blue[100]
};
transform: translate(50%, -50%);
transform-origin: 100% 0;
}
`,
);
| 166 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/system/index.tsx.preview | <Badge badgeContent={5}>
<BadgeContent />
</Badge> | 167 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/tailwind/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { Badge as BaseBadge } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function UnstyledBadgeIntroduction() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<div className={isDarkMode ? 'dark' : ''}>
<Badge badgeContent={5}>
<span className="w-10 h-10 rounded-xl bg-slate-300 dark:bg-slate-400 inline-block align-middle" />
</Badge>
</div>
);
}
const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn);
const Badge = React.forwardRef((props, ref) => {
return (
<BaseBadge
ref={ref}
{...props}
slotProps={{
...props.slotProps,
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'box-border m-0 p-0 text-xs list-none relative inline-block leading-none',
resolvedSlotProps?.className,
),
};
},
badge: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.badge,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'z-auto absolute top-0 right-0 min-w-badge min-h-badge font-sans p-0 text-white font-semibold font-xs font-sans rounded-xl bg-purple-500 leading-5.5 whitespace-nowrap text-center translate-x-1/2 -translate-y-1/2 drop-shadow-lg origin-right',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
Badge.propTypes = {
/**
* The props used for each slot inside the Badge.
* @default {}
*/
slotProps: PropTypes.shape({
badge: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};
| 168 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/tailwind/index.tsx | import * as React from 'react';
import clsx from 'clsx';
import { Badge as BaseBadge, BadgeProps } from '@mui/base/Badge';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function UnstyledBadgeIntroduction() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<div className={isDarkMode ? 'dark' : ''}>
<Badge badgeContent={5}>
<span className="w-10 h-10 rounded-xl bg-slate-300 dark:bg-slate-400 inline-block align-middle" />
</Badge>
</div>
);
}
const resolveSlotProps = (fn: any, args: any) =>
typeof fn === 'function' ? fn(args) : fn;
const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>((props, ref) => {
return (
<BaseBadge
ref={ref}
{...props}
slotProps={{
...props.slotProps,
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'box-border m-0 p-0 text-xs list-none relative inline-block leading-none',
resolvedSlotProps?.className,
),
};
},
badge: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.badge,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'z-auto absolute top-0 right-0 min-w-badge min-h-badge font-sans p-0 text-white font-semibold font-xs font-sans rounded-xl bg-purple-500 leading-5.5 whitespace-nowrap text-center translate-x-1/2 -translate-y-1/2 drop-shadow-lg origin-right',
resolvedSlotProps?.className,
),
};
},
}}
/>
);
});
| 169 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/badge/UnstyledBadgeIntroduction/tailwind/index.tsx.preview | <Badge badgeContent={5}>
<span className="w-10 h-10 rounded-xl bg-slate-300 dark:bg-slate-400 inline-block align-middle" />
</Badge> | 170 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonCustom.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Button, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
const ButtonRoot = React.forwardRef(function ButtonRoot(props, ref) {
const { children, ...other } = props;
return (
<svg width="150" height="50" {...other} ref={ref}>
<polygon points="0,50 0,0 150,0 150,50" className="bg" />
<polygon points="0,50 0,0 150,0 150,50" className="borderEffect" />
<foreignObject x="0" y="0" width="150" height="50">
<div className="content">{children}</div>
</foreignObject>
</svg>
);
});
ButtonRoot.propTypes = {
children: PropTypes.node,
};
const SvgButton = React.forwardRef(function SvgButton(props, ref) {
return <Button {...props} slots={{ root: CustomButtonRoot }} ref={ref} />;
});
export default function UnstyledButtonCustom() {
return <SvgButton>Button</SvgButton>;
}
const blue = {
50: '#F0F7FF',
100: '#C2E0FF',
200: '#99CCF3',
400: '#3399FF',
500: '#007FFF',
600: '#0072E6',
700: '#0059B3',
800: '#004C99',
900: '#003A75',
};
const CustomButtonRoot = styled(ButtonRoot)(
({ theme }) => `
overflow: visible;
cursor: pointer;
--main-color: ${theme.palette.mode === 'light' ? blue[600] : blue[200]};
--hover-color: ${theme.palette.mode === 'light' ? blue[50] : blue[900]};
--active-color: ${theme.palette.mode === 'light' ? blue[100] : blue[800]};
& polygon {
fill: transparent;
transition: all 800ms ease;
pointer-events: none;
}
& .bg {
stroke: var(--main-color);
stroke-width: 1;
filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.1));
fill: transparent;
}
& .borderEffect {
stroke: var(--main-color);
stroke-width: 2;
stroke-dasharray: 120 600;
stroke-dashoffset: 120;
fill: transparent;
}
&:hover,
&.${buttonClasses.focusVisible} {
.borderEffect {
stroke-dashoffset: -600;
}
.bg {
fill: var(--hover-color);
}
}
&:focus,
&.${buttonClasses.focusVisible} {
outline: 2px solid ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
outline-offset: 2px;
}
&.${buttonClasses.active} {
& .bg {
fill: var(--active-color);
transition: fill 150ms ease-out;
}
}
& foreignObject {
pointer-events: none;
& .content {
font-size: 0.875rem;
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
line-height: 1.5;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: var(--main-color);
}
& svg {
margin: 0 4px;
}
}`,
);
| 171 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonCustom.tsx | import * as React from 'react';
import { Button, ButtonProps, buttonClasses } from '@mui/base/Button';
import { styled, Theme } from '@mui/system';
const ButtonRoot = React.forwardRef(function ButtonRoot(
props: React.PropsWithChildren<{}>,
ref: React.ForwardedRef<any>,
) {
const { children, ...other } = props;
return (
<svg width="150" height="50" {...other} ref={ref}>
<polygon points="0,50 0,0 150,0 150,50" className="bg" />
<polygon points="0,50 0,0 150,0 150,50" className="borderEffect" />
<foreignObject x="0" y="0" width="150" height="50">
<div className="content">{children}</div>
</foreignObject>
</svg>
);
});
const SvgButton = React.forwardRef(function SvgButton(
props: ButtonProps,
ref: React.ForwardedRef<any>,
) {
return <Button {...props} slots={{ root: CustomButtonRoot }} ref={ref} />;
});
export default function UnstyledButtonCustom() {
return <SvgButton>Button</SvgButton>;
}
const blue = {
50: '#F0F7FF',
100: '#C2E0FF',
200: '#99CCF3',
400: '#3399FF',
500: '#007FFF',
600: '#0072E6',
700: '#0059B3',
800: '#004C99',
900: '#003A75',
};
const CustomButtonRoot = styled(ButtonRoot)(
({ theme }: { theme: Theme }) => `
overflow: visible;
cursor: pointer;
--main-color: ${theme.palette.mode === 'light' ? blue[600] : blue[200]};
--hover-color: ${theme.palette.mode === 'light' ? blue[50] : blue[900]};
--active-color: ${theme.palette.mode === 'light' ? blue[100] : blue[800]};
& polygon {
fill: transparent;
transition: all 800ms ease;
pointer-events: none;
}
& .bg {
stroke: var(--main-color);
stroke-width: 1;
filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.1));
fill: transparent;
}
& .borderEffect {
stroke: var(--main-color);
stroke-width: 2;
stroke-dasharray: 120 600;
stroke-dashoffset: 120;
fill: transparent;
}
&:hover,
&.${buttonClasses.focusVisible} {
.borderEffect {
stroke-dashoffset: -600;
}
.bg {
fill: var(--hover-color);
}
}
&:focus,
&.${buttonClasses.focusVisible} {
outline: 2px solid ${theme.palette.mode === 'dark' ? blue[700] : blue[200]};
outline-offset: 2px;
}
&.${buttonClasses.active} {
& .bg {
fill: var(--active-color);
transition: fill 150ms ease-out;
}
}
& foreignObject {
pointer-events: none;
& .content {
font-size: 0.875rem;
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
line-height: 1.5;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: var(--main-color);
}
& svg {
margin: 0 4px;
}
}`,
);
| 172 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonCustom.tsx.preview | <SvgButton>Button</SvgButton> | 173 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsDisabledFocus.js | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsDisabledFocus() {
return (
<Stack spacing={2}>
<Button disabled>{'focusableWhenDisabled = false'}</Button>
<Button disabled focusableWhenDisabled>
{'focusableWhenDisabled = true'}
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 174 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsDisabledFocus.tsx | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsDisabledFocus() {
return (
<Stack spacing={2}>
<Button disabled>{'focusableWhenDisabled = false'}</Button>
<Button disabled focusableWhenDisabled>
{'focusableWhenDisabled = true'}
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 175 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsDisabledFocus.tsx.preview | <Button disabled>{'focusableWhenDisabled = false'}</Button>
<Button disabled focusableWhenDisabled>
{'focusableWhenDisabled = true'}
</Button> | 176 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsDisabledFocusCustom.js | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsDisabledFocusCustom() {
return (
<Stack spacing={2}>
<Button slots={{ root: 'span' }} disabled>
{'focusableWhenDisabled = false'}
</Button>
<Button slots={{ root: 'span' }} disabled focusableWhenDisabled>
{'focusableWhenDisabled = true'}
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 177 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsDisabledFocusCustom.tsx | import * as React from 'react';
import {
Button as BaseButton,
buttonClasses,
ButtonTypeMap,
} from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
import { PolymorphicComponent } from '@mui/base/utils';
export default function UnstyledButtonsDisabledFocusCustom() {
return (
<Stack spacing={2}>
<Button slots={{ root: 'span' }} disabled>
{'focusableWhenDisabled = false'}
</Button>
<Button slots={{ root: 'span' }} disabled focusableWhenDisabled>
{'focusableWhenDisabled = true'}
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
) as PolymorphicComponent<ButtonTypeMap>;
| 178 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsDisabledFocusCustom.tsx.preview | <Button slots={{ root: 'span' }} disabled>
{'focusableWhenDisabled = false'}
</Button>
<Button slots={{ root: 'span' }} disabled focusableWhenDisabled>
{'focusableWhenDisabled = true'}
</Button> | 179 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsSimple.js | import * as React from 'react';
import { Button as BaseButton } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsSimple() {
return (
<Stack spacing={2} direction="row">
<Button>Button</Button>
<Button disabled>Disabled</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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;
transform: scale(0.99);
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.Mui-disabled {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 180 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsSimple.tsx | import * as React from 'react';
import { Button as BaseButton } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsSimple() {
return (
<Stack spacing={2} direction="row">
<Button>Button</Button>
<Button disabled>Disabled</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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;
transform: scale(0.99);
}
&:focus-visible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.Mui-disabled {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 181 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsSimple.tsx.preview | <Button>Button</Button>
<Button disabled>Disabled</Button> | 182 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsSpan.js | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsSpan() {
return (
<Stack spacing={2} direction="row">
<Button slots={{ root: 'span' }}>Button</Button>
<Button slots={{ root: 'span' }} disabled>
Disabled
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 183 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsSpan.tsx | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsSpan() {
return (
<Stack spacing={2} direction="row">
<Button slots={{ root: 'span' }}>Button</Button>
<Button slots={{ root: 'span' }} disabled>
Disabled
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 184 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonsSpan.tsx.preview | <Button slots={{ root: 'span' }}>Button</Button>
<Button slots={{ root: 'span' }} disabled>
Disabled
</Button> | 185 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledLinkButton.js | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { prepareForSlot } from '@mui/base/utils';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
import Link from 'next/link';
const LinkSlot = prepareForSlot(Link);
export default function UnstyledLinkButton() {
return (
<Stack spacing={2} direction="row">
<Button href="https://mui.com/">Standard link</Button>
<Button href="https://mui.com/" slots={{ root: LinkSlot }}>
Next.js link
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
text-decoration: none;
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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 186 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledLinkButton.tsx | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { prepareForSlot } from '@mui/base/utils';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
import Link from 'next/link';
const LinkSlot = prepareForSlot(Link);
export default function UnstyledLinkButton() {
return (
<Stack spacing={2} direction="row">
<Button href="https://mui.com/">Standard link</Button>
<Button href="https://mui.com/" slots={{ root: LinkSlot }}>
Next.js link
</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ theme }) => `
font-family: IBM Plex Sans, sans-serif;
font-weight: 600;
font-size: 0.875rem;
line-height: 1.5;
text-decoration: none;
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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 187 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledLinkButton.tsx.preview | <Button href="https://mui.com/">Standard link</Button>
<Button href="https://mui.com/" slots={{ root: LinkSlot }}>
Next.js link
</Button> | 188 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UseButton.js | import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
import { useButton } from '@mui/base/useButton';
const CustomButton = React.forwardRef(function CustomButton(props, ref) {
const { children, disabled } = props;
const { active, focusVisible, getRootProps } = useButton({
...props,
rootRef: ref,
});
return (
<CustomButtonRoot
{...getRootProps()}
className={clsx({
active,
disabled,
focusVisible,
})}
>
{children}
</CustomButtonRoot>
);
});
CustomButton.propTypes = {
children: PropTypes.node,
/**
* If `true`, the component is disabled.
* @default false
*/
disabled: PropTypes.bool,
};
export default function UseButton() {
return (
<Stack spacing={2} direction="row">
<CustomButton onClick={() => console.log('click!')}>Button</CustomButton>
<CustomButton disabled>Disabled</CustomButton>
</Stack>
);
}
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 CustomButtonRoot = 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;
transform: scale(0.99);
}
&.focusVisible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 189 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UseButton.tsx | import * as React from 'react';
import clsx from 'clsx';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
import { useButton } from '@mui/base/useButton';
import { ButtonProps } from '@mui/base/Button';
const CustomButton = React.forwardRef(function CustomButton(
props: ButtonProps,
ref: React.ForwardedRef<any>,
) {
const { children, disabled } = props;
const { active, focusVisible, getRootProps } = useButton({
...props,
rootRef: ref,
});
return (
<CustomButtonRoot
{...getRootProps()}
className={clsx({
active,
disabled,
focusVisible,
})}
>
{children}
</CustomButtonRoot>
);
});
export default function UseButton() {
return (
<Stack spacing={2} direction="row">
<CustomButton onClick={() => console.log('click!')}>Button</CustomButton>
<CustomButton disabled>Disabled</CustomButton>
</Stack>
);
}
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 CustomButtonRoot = 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;
transform: scale(0.99);
}
&.focusVisible {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.disabled {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 190 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/UseButton.tsx.preview | <CustomButton onClick={() => console.log('click!')}>Button</CustomButton>
<CustomButton disabled>Disabled</CustomButton> | 191 |
0 | petrpan-code/mui/material-ui/docs/data/base/components | petrpan-code/mui/material-ui/docs/data/base/components/button/button.md | ---
productId: base-ui
title: React Button component and hook
components: Button
hooks: useButton
githubLabel: 'component: button'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/button/
---
# Button
<p class="description">Buttons let users take actions and make choices with a single tap.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
{{"component": "modules/components/ComponentPageTabs.js"}}
## Introduction
The Button component replaces the native HTML `<button>` element, and offers expanded options for styling and accessibility.
{{"demo": "UnstyledButtonIntroduction", "defaultCodeOpen": false, "bg": "gradient"}}
## Component
```jsx
import { Button } from '@mui/base/Button';
```
The Button behaves similar to the native HTML `<button>`, so it wraps around the text that will be displayed on its surface.
The following demo shows how to create and style two basic buttons.
Notice that the second button cannot be clicked due to the `disabled` prop:
{{"demo": "UnstyledButtonsSimple.js"}}
### Anatomy
The Button component is composed of a root `<button>` slot with no interior slots:
```html
<button class="MuiButton-root">
<!-- button text goes here -->
</button>
```
### Custom structure
Use the `slots.root` prop to override the root slot with a custom element:
```jsx
<Button slots={{ root: 'div' }} />
```
:::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.
:::
If you provide a non-interactive element such as a `<span>`, the Button component will automatically add the necessary accessibility attributes.
Compare the attributes on the `<span>` in this demo with the Button from the previous demo—try inspecting them both with your browser's dev tools:
{{"demo": "UnstyledButtonsSpan.js"}}
:::warning
If a Button is customized with a non-button element (for instance, `<Button slots={{ root: "span" }} />`), it will not submit the form it's in when clicked.
Similarly, `<Button slots={{ root: "span" }} type="reset">` will not reset its parent form.
:::
### Usage with TypeScript
In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component:
```tsx
<Button<typeof CustomComponent> slots={{ root: CustomComponent }} customProp />
```
The same applies for props specific to custom primitive elements:
```tsx
<Button<'img'> slots={{ root: 'img' }} src="button.png" />
```
## Hook
```js
import { useButton } from '@mui/base/useButton';
```
The `useButton` hook lets you apply the functionality of a Button 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 buttons as those found in the [Component](#component) section above, but with the `useButton` hook:
{{"demo": "UseButton.js", "defaultCodeOpen": true}}
If you use a ref to store a reference to the button, pass it to the `useButton`'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 button element manually, as the correct ref is already a part of the object returned by the `getRootProps` function.
:::
## Customization
:::info
The following features can be used with both components and hooks.
For the sake of simplicity, demos and code snippets primarily feature components.
:::
### Custom elements
The Button accepts a wide range of custom elements beyond HTML elements.
You can even use SVGs, as shown in the demo below:
{{"demo": "UnstyledButtonCustom.js", "defaultCodeOpen": false}}
### Using with links
The following demo illustrates how to use the Button as a link, whether using the Base UI Button itself for the `href`, or with the [Next.js Link component](https://nextjs.org/docs/pages/api-reference/components/link):
{{"demo": "UnstyledLinkButton.js", "defaultCodeOpen": true}}
### Focus on disabled buttons
Similarly to the native HTML `<button>` element, the Button component can't receive focus when it's disabled.
This may reduce its accessibility, as screen readers won't be able to announce the existence and state of the button.
The `focusableWhenDisabled` prop lets you change this behavior.
When this prop is set, the underlying Button does not set the `disabled` prop.
Instead, `aria-disabled` is used, which makes the Button focusable.
This should be used whenever the disabled Button needs to be read by screen readers.
Base UI uses this prop internally in [menu items](/base-ui/react-menu/), making it possible to use the keyboard to navigate to disabled items (in compliance with [ARIA guidelines](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#x6-7-focusability-of-disabled-controls)).
The following demo shows how the `focusableWhenDisabled` prop works—use the <kbd class="key">Tab</kbd> key to navigate within this document to see that only the second Button accepts the focus:
{{"demo": "UnstyledButtonsDisabledFocus.js"}}
The `focusableWhenDisabled` prop works the same when the root slot is customized, except that the `aria-disabled` attribute is used no regardless of the prop's state.
The ability to receive focus is controlled internally by the `tabindex` attribute.
{{"demo": "UnstyledButtonsDisabledFocusCustom.js"}}
| 192 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/css/index.js | import * as React from 'react';
import { Button } from '@mui/base/Button';
import { useTheme } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsIntroduction() {
return (
<React.Fragment>
<Stack spacing={2} direction="row">
<Button className="IntroductionButton">Button</Button>
<Button className="IntroductionButton" disabled>
Disabled
</Button>
</Stack>
<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>{`
.IntroductionButton {
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]};
}
.IntroductionButton:hover {
background-color: ${cyan[600]};
}
.IntroductionButton.Mui-active {
background-color: ${cyan[700]};
box-shadow: none;
transform: scale(0.99);
}
.IntroductionButton.Mui-focusVisible {
box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]};
outline: none;
}
.IntroductionButton.Mui-disabled {
background-color: ${isDarkMode ? grey[700] : grey[200]};
color: ${isDarkMode ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`}</style>
);
}
| 193 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/css/index.tsx | import * as React from 'react';
import { Button } from '@mui/base/Button';
import { useTheme } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsIntroduction() {
return (
<React.Fragment>
<Stack spacing={2} direction="row">
<Button className="IntroductionButton">Button</Button>
<Button className="IntroductionButton" disabled>
Disabled
</Button>
</Stack>
<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>{`
.IntroductionButton {
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]};
}
.IntroductionButton:hover {
background-color: ${cyan[600]};
}
.IntroductionButton.Mui-active {
background-color: ${cyan[700]};
box-shadow: none;
transform: scale(0.99);
}
.IntroductionButton.Mui-focusVisible {
box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]};
outline: none;
}
.IntroductionButton.Mui-disabled {
background-color: ${isDarkMode ? grey[700] : grey[200]};
color: ${isDarkMode ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`}</style>
);
}
| 194 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/css/index.tsx.preview | <React.Fragment>
<Stack spacing={2} direction="row">
<Button className="IntroductionButton">Button</Button>
<Button className="IntroductionButton" disabled>
Disabled
</Button>
</Stack>
<Styles />
</React.Fragment> | 195 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/system/index.js | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsIntroduction() {
return (
<Stack spacing={2} direction="row">
<Button>Button</Button>
<Button disabled>Disabled</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 196 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/system/index.tsx | import * as React from 'react';
import { Button as BaseButton, buttonClasses } from '@mui/base/Button';
import { styled } from '@mui/system';
import Stack from '@mui/material/Stack';
export default function UnstyledButtonsIntroduction() {
return (
<Stack spacing={2} direction="row">
<Button>Button</Button>
<Button disabled>Disabled</Button>
</Stack>
);
}
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 Button = styled(BaseButton)(
({ 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]};
}
&.${buttonClasses.active} {
background-color: ${blue[700]};
box-shadow: none;
transform: scale(0.99);
}
&.${buttonClasses.focusVisible} {
box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]};
outline: none;
}
&.${buttonClasses.disabled} {
background-color: ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]};
border: 0;
cursor: default;
box-shadow: none;
transform: scale(1);
}
`,
);
| 197 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/system/index.tsx.preview | <Button>Button</Button>
<Button disabled>Disabled</Button> | 198 |
0 | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction | petrpan-code/mui/material-ui/docs/data/base/components/button/UnstyledButtonIntroduction/tailwind/index.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { Button as BaseButton } from '@mui/base/Button';
import Stack from '@mui/material/Stack';
import clsx from 'clsx';
import { useTheme } from '@mui/system';
function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}
export default function UnstyledButtonsIntroduction() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<div className={`${isDarkMode ? 'dark' : undefined}`}>
<Stack spacing={2} direction="row">
<CustomButton>Button</CustomButton>
<CustomButton disabled>Disabled</CustomButton>
</Stack>
</div>
);
}
const CustomButton = React.forwardRef((props, ref) => {
const { className, ...other } = props;
return (
<BaseButton
ref={ref}
className={clsx(
'cursor-pointer transition text-sm font-sans font-semibold leading-normal bg-violet-500 text-white rounded-lg px-4 py-2 border border-solid border-violet-500 shadow-[0_2px_1px_rgb(45_45_60_/_0.2),_inset_0_1.5px_1px_#a78bfa,_inset_0_-2px_1px_#7c3aed] dark:shadow-[0_2px_1px_rgb(0_0_0/_0.5),_inset_0_1.5px_1px_#a78bfa,_inset_0_-2px_1px_#7c3aed] hover:bg-violet-600 active:bg-violet-700 active:shadow-none active:scale-[0.99] focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none ui-disabled:text-slate-700 ui-disabled:dark:text-slate-200 ui-disabled:bg-slate-200 ui-disabled:dark:bg-slate-700 ui-disabled:cursor-default ui-disabled:shadow-none ui-disabled:dark:shadow-none ui-disabled:hover:bg-slate-200 ui-disabled:hover:dark:bg-slate-700 ui-disabled:border-none',
className,
)}
{...other}
/>
);
});
CustomButton.propTypes = {
className: PropTypes.string,
};
| 199 |