| name | add-component |
| description | Add a new React component with Material UI |
Add Component Skill
Add React components to apps/artagent/frontend/src/components/.
Component Template
import { memo, useCallback, useState } from 'react';
import { Box, Typography, Button } from '@mui/material';
const ComponentName = memo(function ComponentName({ prop1, prop2, onAction }) {
const [state, setState] = useState(null);
const handleAction = useCallback(() => {
onAction?.(state);
}, [onAction, state]);
return (
<Box
sx={{
p: 2,
display: 'flex',
flexDirection: 'column',
gap: 2,
}}
>
<Typography variant="h6">{prop1}</Typography>
<Button onClick={handleAction} variant="contained">
Action
</Button>
</Box>
);
});
export default ComponentName;
Steps
- Create file in
src/components/ComponentName.jsx
- Import required MUI components
- Use
memo() for performance optimization
- Use
useCallback() for event handlers
- Apply
sx prop for styling with theme values
- Export as default
Styling with sx Prop
<Box
sx={{
p: 2,
mt: 1,
bgcolor: 'background.paper',
borderRadius: 1,
display: 'flex',
gap: 2,
}}
/>
<Stack
direction={{ xs: 'column', sm: 'row' }}
spacing={{ xs: 1, sm: 2, md: 4 }}
/>
Common MUI Imports
import { Box, Stack, Container, Grid } from '@mui/material';
import { TextField, Button, IconButton } from '@mui/material';
import { Typography, List, Chip, Avatar } from '@mui/material';
import { Dialog, Snackbar, Alert, CircularProgress } from '@mui/material';
import { Send, Mic, Settings, Close } from '@mui/icons-material';
Accessibility
<IconButton aria-label="Send message" onClick={handleSend}>
<SendIcon />
</IconButton>
<Typography component="h1" variant="h4">
Page Title
</Typography>
Props Pattern
const Component = ({
title = 'Default',
isLoading = false,
onSubmit,
children,
}) => { ... };
Hook Extraction
For complex logic, create custom hook in hooks/:
export const useComponentLogic = (initialValue) => {
const [value, setValue] = useState(initialValue);
const handleChange = useCallback((newValue) => {
setValue(newValue);
}, []);
return { value, handleChange };
};