Last active
July 11, 2020 22:01
-
-
Save s-barrah/1905988be93d34b02e006ddf4e7449e8 to your computer and use it in GitHub Desktop.
RichText component
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 * as React from 'react'; | |
import * as PropTypes from 'prop-types'; | |
import styled from 'styled-components'; | |
interface IInnerProps { | |
align: string; | |
} | |
interface IRichTextProps extends IInnerProps { | |
markup: string; | |
} | |
const Inner = styled.div<IInnerProps>` | |
text-align: ${(props) => props.align}; | |
`; | |
const RichText = ({ | |
align, | |
markup = '', | |
...rest | |
}: IRichTextProps): JSX.Element => { | |
return ( | |
<Inner | |
align={align} | |
dangerouslySetInnerHTML={{ __html: markup }} | |
{...rest} | |
/> | |
); | |
}; | |
RichText.propTypes = { | |
/** Align text */ | |
align: PropTypes.oneOf(['left', 'center', 'right']), | |
/** Text markup */ | |
markup: PropTypes.string.isRequired, | |
}; | |
RichText.defaultProps = { | |
align: 'left', | |
}; | |
export default RichText; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment