Skip to content

Commit

Permalink
feat(react-i18n): allow react element in HtmlTrans element prop
Browse files Browse the repository at this point in the history
  • Loading branch information
flepretre committed Dec 18, 2018
1 parent 654b030 commit ce7a012
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/react-i18n/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default const MyComponent = ({ nbExample, t }) => {
* **number**: amount used for plural forms
* **data**: object containing key/values used for interpolation in the translation
* **general**: use general plural form if truthy
* **element**: HTML element used to generate ReactElement. (default value: `span`)
* **element**: HTML element, or React element used for rendering. (default value: `span`)

Note that **number** and **data** can be used together.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ exports[`i18n.renderProps should return html translation in a div 1`] = `
}
/>
`;

exports[`i18n.renderProps should return html translation in a react element 1`] = `
<Dummy
dangerouslySetInnerHTML={
Object {
"__html": "<div>foo.bar</div>",
}
}
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ describe('i18n.renderProps', () => {

expect(wrapper.shallow()).toMatchSnapshot();
});

it('should return html translation in a react element', () => {
const Dummy = props => <dummy {...props} />;
const wrapper = getWrapper({ element: Dummy });

expect(wrapper.shallow()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HtmlTrans.defaultProps = {
};

HtmlTrans.propTypes = {
element: PropTypes.string,
element: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
i18nKey: PropTypes.string.isRequired,
data: PropTypes.object,
number: PropTypes.number,
Expand Down

0 comments on commit ce7a012

Please sign in to comment.