Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created May 16, 2026 20:00
Show Gist options
  • Select an option

  • Save fayimora/827b6a4362928a862fcbe928d5a0f204 to your computer and use it in GitHub Desktop.

Select an option

Save fayimora/827b6a4362928a862fcbe928d5a0f204 to your computer and use it in GitHub Desktop.
import { Button, type ButtonProps } from '@mui/material'
type PillButtonTone = 'primary' | 'secondary' | 'danger' | 'neutral'
type PillButtonProps = ButtonProps & {
tone?: PillButtonTone
}
export function PillButton({
tone = 'primary',
variant,
color,
sx,
...props
}: PillButtonProps) {
const muiVariant =
variant ??
(tone === 'danger' || tone === 'neutral' ? 'outlined' : 'contained')
const muiColor =
color ??
(tone === 'danger'
? 'error'
: tone === 'secondary'
? 'secondary'
: 'primary')
return (
<Button
variant={muiVariant}
color={muiColor}
sx={[
{ borderRadius: 999 },
tone === 'neutral' && {
color: 'text.primary',
borderColor: 'divider',
'&:hover': {
borderColor: 'text.secondary',
bgcolor: 'action.hover',
},
},
...(Array.isArray(sx) ? sx : [sx]),
]}
{...props}
/>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment