Counter Example - Material-ui Typing CST Test
Loading…
Counter Example — Material-ui Code
Demonstrates a simple counter layout using Material-UI components and React for interactivity.
import React, { useState } from 'react';
import { Button, Typography, Box, ThemeProvider, createTheme } from '@mui/material';
const Counter = () => {
const [count, setCount] = useState(0);
const [isDark, setIsDark] = useState(false);
const toggleTheme = () => setIsDark(!isDark);
return (
<ThemeProvider theme={createTheme({ palette: { mode: isDark ? 'dark' : 'light' } })}>
<Box sx={{ textAlign: 'center', mt: 5 }}>
<Typography variant='h4'>Counter: {count}</Typography>
<Box sx={{ mt: 2 }}>
<Button variant='contained' color='primary' onClick={() => setCount(count + 1)}>+</Button>
<Button variant='contained' color='error' onClick={() => setCount(count - 1)}>-</Button>
<Button variant='contained' color='secondary' onClick={() => setCount(0)}>Reset</Button>
</Box>
<Button sx={{ mt: 2 }} variant='contained' color='warning' onClick={toggleTheme}>Switch Theme</Button>
</Box>
</ThemeProvider>
);
};
export default Counter;Material-ui Language Guide
Material-UI (MUI) is a React-based front-end framework that implements Google's Material Design system with prebuilt, customizable components and styling solutions.
Primary Use Cases
- ▸React-based web applications
- ▸Admin dashboards and enterprise apps
- ▸Interactive UI with Material Design
- ▸Rapid prototyping with React components
- ▸Projects needing highly customizable UI themes
Notable Features
- ▸Prebuilt React components (buttons, cards, tables, dialogs)
- ▸Responsive design system and grid layout
- ▸Theme customization via MUI ThemeProvider
- ▸Accessibility-focused components (ARIA support)
- ▸Integration with React ecosystem
Origin & Creator
Created by Olivier Tassinari in 2014 as a React implementation of Material Design.
Industrial Note
MUI is widely used in React projects where Material Design consistency, prebuilt components, and developer productivity are prioritized.