Component factory for utility-first UI

Typed layer for class names. For React and SolidJS.

SomeButton.js
const SomeButton = ma.button`
  text-normal
  md:text-lg
  mt-5
  border-1
  transition-all
  ${someConfig.transitionDurationEaseClass}
  ${({ $isLoading }) => $isLoading && 'opacity-90 pointer-events-none'}
`

Extension and Transformation

Extend

Extend allows you to create a new component based on an existing one, while adding or overriding styles. This is useful for creating variations of a component without duplicating code.

SubmitButton.jsx
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>
)
Read "extend" docs

Transform

Transform allows you to modify the props of a component before they are passed down to the underlying element. This is useful for creating higher-order components that can modify the behavior of existing components.

LinkButton.jsx
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>
Read "transform" docs

Advanced Styling with Variants

With variants, you can easily create reusable components with different styles and behaviors based on props. This allows for a more maintainable and scalable codebase.

Examples
<Alert />
<Alert $isActive />
<Alert $severity="warning" />
<Alert $severity="warning" $isActive />
StyledAlert.js
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
  }
})