Typed layer for class names. For React and SolidJS.
const SomeButton = ma.button`
text-normal
md:text-lg
mt-5
border-1
transition-all
${someConfig.transitionDurationEaseClass}
${({ $isLoading }) => $isLoading && 'opacity-90 pointer-events-none'}
`Create a new component based on an existing one, while adding or overriding styles. Best for creating variations of a component without duplicating code.
import ma from '@marmo/react'
const Button = ma.button`
rounded-md px-4 py-2
bg-primary text-primary-content
`
const SubmitButton = ma.extend(Button)`
w-full
${({ $loading }) => $loading && 'pointer-events-none opacity-60'}
`
const FormActions = () => (
<SubmitButton type="submit" $loading>
Saving…
</SubmitButton>
)Let's you modify the props of a component before they are passed down to the underlying element. Or transform them on the spot.
import ma from '@marmo/react'
const Button = ma.button`
rounded-md px-4 py-2
bg-primary text-primary-content
`
const LinkButton = ma.transform(Button).a`
inline-flex no-underline
`
const Navigation = () => <LinkButton href="/docs">Read the docs</LinkButton>
// short version: use the "$_as" prop
const OtherNavigation = () => (
<Button $_as="a" href="/docs">
Read the docs
</Button>
)Seen and loved for in CVA: Create reusable components with different styles and behaviors based on props.
<Alert /><Alert $isActive /><Alert $severity="warning" /><Alert $severity="warning" $isActive />* Examples are using tailwindcss + daisyUI
import ma from '@marmo/react'
const Alert = ma.div.variants({
base: ({ $isActive }) => `p-4 rounded-md ${$isActive ? 'shadow-lg' : ''}`,
variants: {
$severity: {
info: 'bg-info text-info-content',
warning: 'bg-warning text-warning-content',
error: ({ style, $ringColor }) =>
`bg-error text-error-content ${style({ outlineColor: $ringColor })}`
},
$outlined: {
true: 'outline outline-2',
false: 'outline-none'
}
},
defaultVariants: {
$severity: 'info',
$outlined: false
}
})