Last active
October 13, 2017 12:46
-
-
Save YiDaoJ/bcf7d3e338aecb15758dae226aa67f58 to your computer and use it in GitHub Desktop.
ARc example: React.createElement() + styled-components https://github.com/diegohaz/arc/blob/master/src-example/components/atoms/Heading/index.js
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 from 'react' | |
import PropTypes from 'prop-types' | |
import styled, { css } from 'styled-components' | |
import { font, palette } from 'styled-theme' | |
const fontSize = ({ level }) => `${0.75 + (1 * (1 / level))}rem` | |
const styles = css` | |
font-family: ${font('primary')}; | |
font-weight: 500; | |
font-size: ${fontSize}; | |
margin: 0; | |
margin-top: 0.85714em; | |
margin-bottom: 0.57142em; | |
color: ${palette({ grayscale: 0 }, 1)}; | |
` | |
const Heading = styled(({ level, children, reverse, palette, theme, ...props }) => | |
React.createElement(`h${level}`, props, children) // 去JSX化 | |
// React.createElement(component, props, ...children) | |
)`${styles}` | |
// const Heading = styled.html-Tag `` | |
// https://www.styled-components.com/docs/basics#styling-any-components | |
Heading.propTypes = { | |
level: PropTypes.number, | |
children: PropTypes.node, | |
palette: PropTypes.string, | |
reverse: PropTypes.bool, | |
} | |
Heading.defaultProps = { | |
level: 1, | |
palette: 'grayscale', | |
} | |
export default Heading |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment