Skip to content

Instantly share code, notes, and snippets.

@YiDaoJ
Last active October 13, 2017 12:46
Show Gist options
  • Save YiDaoJ/bcf7d3e338aecb15758dae226aa67f58 to your computer and use it in GitHub Desktop.
Save YiDaoJ/bcf7d3e338aecb15758dae226aa67f58 to your computer and use it in GitHub Desktop.
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