portfolio/components/ui/StatusMessage.tsx
Ryan Freeman 36532bc1f1
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m11s
Add subscription feature
2025-04-22 17:31:10 +01:00

30 lines
1.2 KiB
TypeScript

import clsx from 'clsx'
import React, {ReactNode} from 'react'
import {CheckIcon} from '@/components/icons/CheckIcon'
import {CrossIcon} from '@/components/icons/CrossIcon'
type StatusMessageProps = {
children: ReactNode
className?: string
errorConditions?: string[]
}
export function StatusMessage({children, className, errorConditions}: StatusMessageProps) {
const _errorConditions = ['error', 'problem', ...errorConditions ?? []]
const isError = _errorConditions.some(condition => children?.toString().toLowerCase().includes(condition))
return (
<>
{children &&
<div className={clsx(`flex items-start sm:items-center ${className ?? ''}`)}>
{!isError ? <CheckIcon className="size-5 mt-0.5 sm:mt-0 mr-1 text-green-800 dark:text-green-600"/>
: <CrossIcon className="size-5 mt-0.5 sm:mt-0 mr-1 text-red-800 dark:text-red-600"/>}
<p aria-live="polite" role="status"
className={clsx('text-sm font-semibold', !isError ? 'text-green-800 dark:text-green-600' : 'text-red-800 dark:text-red-600')}>
{children}
</p>
</div>
}
</>
)
}