If you're interested in utilizing the <Chip>
component, one approach is to leverage &::before
for styling within the Chip.
For example:
const Chip = styled(MuiChip)(({ chipTitle }) => ({
"&::before": {
content: `"${chipTitle}"`,
position: "absolute",
top: "-8px",
left: "16px",
backgroundColor: "#fff",
padding: "0 8px"
}
}));
To use it:
<Chip
label="Salary Proposal - 500k$"
variant="outlined"
onDelete={handleDelete}
chipTitle="Hello"
/>
Explore this CodeSandbox. Personal styling may vary slightly, so adjust as needed.
For Typescript users:
Begin by extending the default ChipProps
type.
eg:
import {styled, Chip as MuiChip, ChipProps as MuiChipProps} from '@mui/material'
interface ChipProps extends MuiChipProps {
chipTitle: string
}
Then update the styled()
function like so:
const Chip = styled(MuiChip)<ChipProps>(({ chipTitle }) => ({
"&::before": {
content: `"${chipTitle}"`,
position: "absolute",
top: "-8px",
left: "16px",
backgroundColor: "#fff",
padding: "0 8px"
}
}));