Files
flipper/src/ui/components/Heading.js
Daniel Büchele 726966fdc0 convert to emotion
Summary:
My benchmarks have shown react-emotion to be faster than the current implementation of `styled`. For this reason, I am converting all styling to [emotion](https://emotion.sh).

Benchmark results:
{F136839093}

The syntax is very similar between the two libraries. The main difference is that emotion only allows a single function for the whole style attribute, whereas the old implementation had functions for every style-attirbute.

Before:
```
{
  color: props => props.color,
  fontSize: props => props.size,
}
```

After:
```
props => ({
  color: props.color,
  fontSize: props.size,
})
```

Reviewed By: jknoxville

Differential Revision: D9479893

fbshipit-source-id: 2c39e4618f7e52ceacb67bbec8ae26114025723f
2018-08-23 09:42:18 -07:00

58 lines
1.3 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import styled from '../styled/index.js';
const LargeHeading = styled('div')({
fontSize: 18,
fontWeight: 'bold',
lineHeight: '20px',
borderBottom: '1px solid #ddd',
marginBottom: 10,
});
const SmallHeading = styled('div')({
fontSize: 12,
color: '#90949c',
fontWeight: 'bold',
marginBottom: 10,
textTransform: 'uppercase',
});
/**
* A heading component.
*
* @example Heading 1
* <Heading level={1}>I'm a heading</Heading>
* @example Heading 2
* <Heading level={2}>I'm a heading</Heading>
* @example Heading 3
* <Heading level={3}>I'm a heading</Heading>
* @example Heading 4
* <Heading level={4}>I'm a heading</Heading>
* @example Heading 5
* <Heading level={5}>I'm a heading</Heading>
* @example Heading 6
* <Heading level={6}>I'm a heading</Heading>
*/
export default function Heading(props: {
/**
* Level of the heading. A number from 1-6. Where 1 is the largest heading.
*/
level?: number,
/**
* Children.
*/
children?: React$Node,
}) {
if (props.level === 1) {
return <LargeHeading>{props.children}</LargeHeading>;
} else {
return <SmallHeading>{props.children}</SmallHeading>;
}
}