Last active
March 23, 2023 02:21
-
-
Save JoshK2/f4781ab6e2efc51b5eb93687b7775b2c to your computer and use it in GitHub Desktop.
simple Alert component - build react typescript component in isolation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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