Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

379
Vistas
Making tailwind/react component change color on prop - component only works with certain colors

I have an alert component which gets the prop alert_type based on which it should change it's icon and colour. When I pass 'good' or 'warn' it works fine but if I pass 'bad' it does not accept the colour red. Further when I just edit the colour (both on 'good' and on 'bad') to be 'red' or any other color it does not work except 'yellow' and 'green' always work. How can this be?

/* This example requires Tailwind CSS v2.0+ */
import {
  CheckCircleIcon,
  ExclamationIcon,
  XCircleIcon,
} from '@heroicons/react/solid'

interface AlertProps {
  title: string
  alert_type?: string
  children?: React.ReactNode
}

export function Alert({ title, alert_type = 'good', children }: AlertProps) {
  const [colour, Icon] = (() => {
    switch (alert_type) {
      case 'good':
        return ['green', CheckCircleIcon]
      case 'warn':
        return ['yellow', ExclamationIcon]
      case 'bad':
        return ['red', XCircleIcon]
      default:
        return ['green', CheckCircleIcon]
    }
  })()

  const colours = {
    bg: 'bg-' + colour + '-50',
    icon: 'text-' + colour + '-400',
    title: 'text-' + colour + '-800',
    content: 'text-' + colour + '-700',
  }

  return (
    <div className={'rounded-md p-4 ' + colours.bg}>
      <div className="flex">
        <div className="flex-shrink-0">
          <Icon className={'h-5 w-5 ' + colours.icon} aria-hidden="true" />
        </div>
        <div className="ml-3">
          <h3 className={'text-sm font-medium ' + colours.title}>{title}</h3>
          <div className={'mt-2 text-sm ' + colours.content}>{children}</div>
        </div>
      </div>
    </div>
  )
}

Edit: Without changing anything, green has now also stopped working.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem was that I am using string concatenation to build the classes. When Tailwind parses the file to detect which css classes to create it fails to pick those up. https://tailwindcss.com/docs/content-configuration#class-detection-in-depth

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda