Skip to content

Instantly share code, notes, and snippets.

@s-barrah
Last active July 11, 2020 22:01
Show Gist options
  • Save s-barrah/1905988be93d34b02e006ddf4e7449e8 to your computer and use it in GitHub Desktop.
Save s-barrah/1905988be93d34b02e006ddf4e7449e8 to your computer and use it in GitHub Desktop.
RichText component
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