AgentSkillsCN

Mui Styling

Mui 样式设计

SKILL.md

MUI Styling Skill

Material-UI styling standards and best practices.

When to Apply

  • Creating styled components
  • Implementing responsive design
  • Theme customization
  • UI consistency review

Styling Approach Priority

PriorityApproachUse When
1stsx propMost styling needs
2ndstyled() APIReusable styled components
3rdTheme overridesGlobal component defaults
AvoidInline CSS / CSS filesNever use in MUI projects

Spacing System

Spacing Scale

ValuePixelsUsage
0.54pxTight spacing
18pxDefault small
216pxDefault medium
324pxSection spacing
432pxLarge spacing

Spacing Props

PropCSS Property
mmargin
ppadding
mt, mr, mb, mlmargin-top/right/bottom/left
pt, pr, pb, plpadding-top/right/bottom/left
mx, mymargin x/y axis
px, pypadding x/y axis
gapflex/grid gap

Color System

Theme Colors

CategoryValues
Primaryprimary.main, primary.light, primary.dark, primary.contrastText
Secondarysecondary.main, secondary.light, secondary.dark
Statuserror.main, warning.main, info.main, success.main
Greygrey.100 through grey.900
Backgroundbackground.default, background.paper
Texttext.primary, text.secondary, text.disabled

Color Usage Guidelines

Use CaseColor
Primary actionsprimary.main
Secondary actionssecondary.main
Error stateserror.main
Success feedbacksuccess.main
Backgroundsbackground.paper or background.default
Body texttext.primary
Helper texttext.secondary

Responsive Design

Breakpoints

KeyMin WidthTarget
xs0pxMobile phones
sm600pxTablets portrait
md900pxTablets landscape
lg1200pxDesktops
xl1536pxLarge screens

Responsive Syntax

SyntaxDescription
{ xs: value }Mobile first, applies to xs and up
{ sm: value }Applies to sm and up
Object syntax{ xs: '100%', sm: 400, md: 600 }

Responsive Guidelines

GuidelineDescription
Mobile firstStart with xs, override for larger
Test all breakpointsVerify layout at each breakpoint
Use relative unitsPrefer %, vh, vw over fixed px
Hide/show elementsUse display: { xs: 'none', md: 'block' }

Layout Components

Component Selection

ComponentUse When
BoxGeneric container, flexbox layouts
StackVertical/horizontal lists with spacing
Grid12-column grid layouts
ContainerCentered max-width wrapper

Flexbox with Box

PropertyValues
display'flex', 'inline-flex'
flexDirection'row', 'column'
justifyContent'flex-start', 'center', 'space-between'
alignItems'flex-start', 'center', 'stretch'
gapSpacing value (1, 2, 3...)

Grid System

PropDescription
containerDefines grid container
itemDefines grid item
xs, sm, md, lgColumns at breakpoint (1-12)
spacingGap between items

Typography Standards

Variant Usage

VariantUse For
h1 - h6Headings (use semantic hierarchy)
body1Primary body text
body2Secondary body text
captionSmall helper text
buttonButton text

Typography Guidelines

GuidelineDescription
Semantic hierarchyh1 > h2 > h3 (don't skip levels)
Color for emphasisUse text.secondary for less important
Consistent variantsSame content type = same variant

Component Styling Standards

Button Styling

VariantUse When
containedPrimary actions
outlinedSecondary actions
textTertiary actions, links

Card Styling

ElementStandard
Paddingp: 2 or p: 3
Border radiusUse theme default
ShadowUse theme shadows (1-24)

Form Styling

ElementStandard
TextFieldfullWidth for forms
SpacingStack spacing={2} between fields
LabelsAlways provide label prop

Anti-Patterns

AvoidUse Instead
Inline CSS objectssx prop with theme values
!importantIncrease specificity via sx
Fixed pixel valuestheme.spacing() values
Hardcoded colorstheme.palette colors
CSS classessx prop or styled()
External CSS filesMUI styling system

Performance Guidelines

DO

  • Use sx prop for one-off styles
  • Use styled() for reusable styled components
  • Leverage theme values for consistency
  • Use responsive object syntax

DON'T

  • Create inline style objects (new reference each render)
  • Override theme styles unnecessarily
  • Use CSS-in-JS libraries alongside MUI
  • Nest sx props deeply

Accessibility Standards

StandardImplementation
Color contrastUse theme colors (WCAG compliant)
Focus indicatorsDon't remove, customize if needed
Touch targetsMinimum 44x44px for buttons
Semantic HTMLUse correct MUI component for purpose

Code Review Checklist

  • Uses sx prop or styled(), not inline CSS
  • Colors from theme palette
  • Spacing from theme scale
  • Responsive breakpoints applied
  • No hardcoded pixel values
  • Typography variants used correctly
  • Accessibility standards met