sx-styled
БесплатноБез исполняемых скриптовНе проверенMUI sx prop and styled() API for component styling
от TheLobbi★ 22 звезды на GitHubОб этом скилле
MUI sx Prop and styled() API
Overview
MUI provides two primary APIs for styling components: the sx prop (inline, one-off
styles with full theme access) and the styled() function (reusable styled components
built on Emotion). Choose based on reuse: sx for single-use overrides, styled() for
components used more than once.
sx Prop
The sx prop accepts a superset of CSS where values can reference theme tokens, respond
to breakpoints, and use shorthand aliases. It is available on every MUI component and on
the Box primitive.
Basic usage
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
// Plain CSS properties — camelCase
<Box sx={{ backgroundColor: 'white', borderRadius: 2, boxShadow: 3 }}>
content
</Box>
// Theme token references
<Box sx={{ color: 'primary.main', bgcolor: 'background.paper' }} />
// Typography variants
<Box sx={{ typography: 'h4' }}>Heading text</Box>
System shorthands
MUI maps single-letter aliases to CSS properties. These only work inside sx (and
styled with the system utilities), not in plain Emotion.
<Box
sx={{
m: 2, // margin: theme.spacing(2)
p: 3, // padding: theme.spacing(3)
mx: 'auto', // marginLeft + marginRight: auto
my: 1, // marginTop + marginBottom
px: 2, // paddingLeft + paddingRight
py: 1, // paddingTop + paddingBottom
mt: 4, // marginTop
mb: 2, // marginBottom
ml: 1, // marginLeft
mr: 1, // marginRight
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'space-between',
gap: 2, // gap: theme.spacing(2)
width: 1, // width: 100% (fractions map to %)
height: '100vh',
}}
/>
Theme-aware callback
Use the callback form (theme) => ({...}) when you need theme values that cannot be
expressed as token strings, such as palette computed colors or custom spacing math.
<Box
sx={(theme) => ({
backgroundColor: theme.palette.mode === 'dark'
? theme.palette.grey[900]
: theme.palette.grey[100],
padding: theme.spacing(2, 3), // shorthand: vertical, horizontal
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.shape.borderRadius,
transition: theme.transitions.create(['background-color'], {
duration: theme.transitions.duration.short,
}),
})}
/>
Responsive values — object syntax
Pass an object keyed by breakpoint names. Values are applied from the named breakpoint upward (mobile-first).
<Box
sx={{
width: {
xs: '100%', // 0px+
sm: '80%', // 600px+
md: '60%', // 900px+
lg: '50%', // 1200px+
},
fontSize: { xs: 14, md: 16, lg: 18 },
display: { xs: 'block', md: 'flex' },
flexDirection: { xs: 'column', md: 'row' },
gap: { xs: 1, md: 2 },
}}
/>
Responsive values — array syntax
Arrays map values to breakpoints in order [xs, sm, md, lg, xl]. Use null to skip
a breakpoint without changing the value.
<Box
sx={{
padding: [1, 2, 3], // xs=1, sm=2, md=3
fontSize: [12, null, 16], // xs=12, sm unchanged, md=16
display: ['block', 'flex'], // xs=block, sm+=flex
}}
/>
Pseudo-selectors and nested selectors
The sx prop supports any CSS selector string as a key, enabling hover states,
focus-visible, and targeting MUI's internal slot class names.
<Button
sx={{
'&:hover': {
backgroundColor: 'primary.dark',
transform: 'translateY(-1px)',
},
'&:active': {
transform: 'translateY(0)',
},
'&:focus-visible': {
outline: '3px solid',
outlineColor: 'primary.light',
},
// Target MUI internal slot classes
'& .MuiButton-startIcon': {
marginRight: 0.5,
},
// Target child elements
'& span': {
fontWeight: 700,
},
// Sibling state
'&.Mui-disabled': {
opacity: 0.5,
},
}}
>
Click me
</Button>
styled() Function
styled() is the Emotion styled function extended with MUI's theme and system
shorthands. Use it to create reusable, named components.
Basic styled component
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
const HeroSection = styled(Box)(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
padding: theme.spacing(8, 2),
backgroundColor: theme.palette.background.default,
[theme.breakpoints.up('md')]: {
flexDirection: 'row',
padding: theme.spacing(12, 4),
},
}));
// Usage
<HeroSection component="section">
<h1>Welcome</h1>
</HeroSection>
Styled with props
Accept custom props to drive conditional styles. Use TypeScript generics to type them.
interface CardContainerProps {
variant?: 'elevated' | 'outlined' | 'filled';
selected?: boolean;
}
const CardContainer = styled
Установить sx-styled в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGlobGrepWriteEditFAQ
Что делает скилл sx-styled?
MUI sx prop and styled() API for component styling
Как установить скилл sx-styled?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sx-styled запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic