Skip to content

Instantly share code, notes, and snippets.

@JoshK2
Last active March 23, 2023 02:21
Show Gist options
  • Save JoshK2/f4781ab6e2efc51b5eb93687b7775b2c to your computer and use it in GitHub Desktop.
Save JoshK2/f4781ab6e2efc51b5eb93687b7775b2c to your computer and use it in GitHub Desktop.
simple Alert component - build react typescript component in isolation
import React, { Component, CSSProperties } from 'react';
import Link from './Link';
type AlertProps = {
text: string,
bgColor?: string,
link?: string
}
const css: CSSProperties = {
display: 'inline-block',
position: 'relative',
padding: '0.75rem 1.25rem',
border: '1px solid transparent',
borderRadius: '0.25rem',
width: 'fit-content',
fontSize: 16,
color: '#fafafa'
}
export default class Alert extends Component<AlertProps, {}> {
render() {
const { text, bgColor = 'green', link } = this.props;
if (link) {
return (
<Link link={link}>
<div style={{ backgroundColor: bgColor, ...css }}>
{text}
</div>
</Link>
)
}
return (
<div style={{ backgroundColor: bgColor, ...css }}>
{text}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment