Guest User

Untitled

a guest
Apr 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // Modules
  2. import React from 'react';
  3. import styled from 'styled-components';
  4. import PropTypes from 'prop-types';
  5.  
  6. // Data
  7. import styleData from '../../../data/styles';
  8.  
  9. const SupplementaryTitle = styled.span`
  10. display: block;
  11. text-align: right;
  12. `
  13.  
  14. const Title = (props) => {
  15. const HeadingLevel = props.headingLevel ? props.headingLevel : 'h2';
  16. const StyledHeading = styled(HeadingLevel)`
  17. margin: 0;
  18. font-weight: ${styleData['typography_settings']['title'][props.typographySize]['weight']};
  19. font-size: ${styleData['typography_settings']['title'][props.typographySize]['size']};
  20. font-family: ${styleData['typography_settings']['title'][props.typographySize]['font']};
  21. line-height: ${styleData['typography_settings']['title'][props.typographySize]['line_height']};
  22. `
  23.  
  24. const hasSupplementaryTitle = props.supplementaryTitle;
  25.  
  26. if (hasSupplementaryTitle) {
  27. return (
  28. <StyledHeading>
  29. {props.children}
  30. <SupplementaryTitle>{props.supplementaryTitle}</SupplementaryTitle>
  31. </StyledHeading>
  32. )
  33. }
  34.  
  35. return (
  36. <StyledHeading>{props.children}</StyledHeading>
  37. )
  38. }
  39.  
  40. Title.propTypes = {
  41. children: PropTypes.string.isRequired,
  42. headingLevel: PropTypes.string,
  43. typographySize: PropTypes.oneOf([
  44. 'small', 'medium', 'large'
  45. ]).isRequired,
  46. supplementaryTitle: PropTypes.string,
  47. }
  48.  
  49. export default Title;
  50.  
  51. const Heading = styled.h2`
  52. margin: 0;
  53. ...lots of css...
  54. `;
  55.  
  56. const Title = (props) => {
  57. const StyledHeading = Heading.withComponent(props.headingLevel || "h2");
  58. ...
  59. };
  60.  
  61. font-weight: ${styleData['typography_settings']['title'][props.typographySize]['weight']};
  62.  
  63. if (props.supplementaryTitle) {
Add Comment
Please, Sign In to add comment