Skip to content

Commit 8a1d53a

Browse files
author
Emily
authored
Merge pull request #387 from primer/q4-cat-toad
Q4 Cat Toad Release PR
2 parents 36840f0 + f53c693 commit 8a1d53a

File tree

20 files changed

+717
-312
lines changed

20 files changed

+717
-312
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,49 @@ export default () => (
7676

7777
This will set the `color`, `font-family`, and `line-height` CSS properties to the same ones used in [primer-base](https://github.com/primer/primer/blob/master/modules/primer-base/lib/base.scss#L15).
7878

79+
#### Theming
80+
81+
Components are styled using Primer's [theme](https://github.com/primer/components/blob/master/src/theme.js) by default, but you can provide your own theme by using [styled-component's][styled-components] `<ThemeProvider>`. If you'd like to fully replace the Primer [theme](https://github.com/primer/components/blob/master/src/theme.js) with your custom theme, pass your theme to the `<ThemeProvider>` in the root of your application like so:
82+
83+
```jsx
84+
import {ThemeProvider} from 'styled-components'
85+
86+
const theme = { ... }
87+
88+
const App = (props) => {
89+
return (
90+
<div>
91+
<ThemeProvider theme={theme}>
92+
<div>your app here</div>
93+
</ThemeProvider>
94+
</div>
95+
)
96+
}
97+
98+
```
99+
100+
If you'd like to merge the Primer theme with your theme, you can do so importing the Primer theme and merging using Object.assign:
101+
102+
```jsx
103+
import {ThemeProvider} from 'styled-components'
104+
import {theme} from '@primer/components'
105+
106+
const customTheme = { ... }
107+
108+
109+
const App = (props) => {
110+
return (
111+
<div>
112+
<ThemeProvider theme={Object.assign({}, theme, customTheme)}> // matching keys in customTheme will override keys in the Primer theme
113+
<div>your app here</div>
114+
</ThemeProvider>
115+
</div>
116+
)
117+
}
118+
```
119+
120+
*Note that using `Object.assign` will only create a shallow merge. This means that if both themes have a `color` object, the _entire_ `color` object will be replaced with the new `color` object, instead of only replacing duplicate values from the original theme's color object.
121+
79122
#### Static CSS rendering
80123

81124
If you're rendering React components both server-side _and_ client-side, we suggest following [styled-component's server-side rendering instructions](https://www.styled-components.com/docs/advanced#server-side-rendering) to avoid the flash of unstyled content for server-rendered components. This repo's [documentation template component](https://github.com/primer/components/blob/master/pages/_document.js) demonstrates how to do this in [Next.js].

contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Default values for system props can be set in `Component.defaultProps`.
6363

6464
Prop Types from system props such as `COMMON` or `TYPOGRAPHY` as well as styled-system functions can be spread in the component's prop types declaration (see example below).
6565

66-
⚠️ **Make sure to always set the default `theme` prop to our theme! This allows consumers of our components to access our theme values without a ThemeProvider.**
66+
⚠️ **Make sure to always set the default `theme` prop to our [theme](https://github.com/primer/components/blob/master/src/theme.js)! This allows consumers of our components to access our theme values without a ThemeProvider.**
6767

6868

6969
```jsx

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primer/components",
3-
"version": "8.2.0-beta",
3+
"version": "9.0.0-beta",
44
"description": "Primer react components",
55
"main": "dist/index.umd.js",
66
"module": "dist/index.esm.js",

pages/components/docs/Dropdown.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,41 @@
33

44
The Dropdown component is a lightweight context menu for housing navigation and actions.
55

6+
Dropdown.Button is used to trigger opening and closing the dropdown.
7+
8+
Dropdown.Menu wraps your menu content. Be sure to pass a `direction` prop to this component to position the menu in relation to the Dropdown.Button.
9+
610
## Default example
711
```.jsx
812
<Dropdown scheme="primary" minWidth="5em">
9-
<Box role="list">
10-
<Box role="listitem">Item 1</Box>
11-
<Box role="listitem">Item 2</Box>
12-
<Box role="listitem">Item 3</Box>
13-
</Box>
13+
<Dropdown.Button>Dropdown </Dropdown.Button>
14+
<Dropdown.Menu direction='sw'>
15+
<Dropdown.Item>Item 1</Dropdown.Item>
16+
<Dropdown.Item>Item 2</Dropdown.Item>
17+
<Dropdown.Item>Item 3</Dropdown.Item>
18+
</Dropdown.Menu>
1419
</Dropdown>
1520
```
1621

1722
## System props
1823

19-
Dropdown components get `COMMON` system props. Read our [System Props](/components/docs/system-props) doc page for a full list of available props.
24+
Dropdown, Dropdown.Menu, Dropdown.Button, and Dropdown.Item all get `COMMON` system props. Read our [System Props](/components/docs/system-props) doc page for a full list of available props.
2025

2126
## Component props
2227

28+
#### Dropdown.Menu
2329
| Name | Type | Default | Description |
2430
| :- | :- | :-: | :- |
25-
| scheme | String | | Button scheme used to style the component, can be one of `danger`, `outline` or `primary` |
26-
| title | String | | Optional prop to set the text in the Dropdown button
31+
| direction | String | 'sw' | Sets the direction of the dropdown menu. |
32+
33+
#### Dropdown.Item
34+
No additional props.
35+
36+
#### Dropdown.Button
37+
No additional props.
38+
39+
#### Dropdown
40+
No additional props.
41+
2742

2843
export const meta = {displayName: 'Dropdown'}

pages/components/docs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {meta as CircleBadge} from './CircleBadge.md'
77
export {meta as CircleOcticon} from './CircleOcticon.md'
88
export {meta as CounterLabel} from './CounterLabel.md'
99
export {meta as Details} from './Details.md'
10+
export {meta as Dropdown} from './Dropdown.md'
1011
export {meta as Donut} from './Donut.md'
1112
export {meta as FilterList} from './FilterList.md'
1213
export {meta as Flash} from './Flash.md'

pages/components/docs/primer-theme.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Custom theming is an optional way to override the Primer values that control col
2020

2121
There are two ways to change the theme of Primer components:
2222

23-
1. You can override the theme for an entire tree of components using the `<ThemeProvider>` from [styled-components]:
23+
1. You can override the entire theme for an entire tree of components using the `<ThemeProvider>` from [styled-components]:
2424

2525
```jsx
2626
import {Block, Button, Text, theme as primer} from '@primer/components'
@@ -46,8 +46,27 @@ There are two ways to change the theme of Primer components:
4646
```
4747

4848
**⚠️ Note: [styled-components]'s `<ThemeProvider>` only allows exactly one child.**
49+
2. You can merge the Primer theme with your custom theme using Object.assign:
4950
50-
1. You can theme individual components by passing the `theme` prop directly:
51+
```jsx
52+
import {ThemeProvider} from `styled-components`
53+
import {theme} from '@primer/components'
54+
55+
const customTheme = { ... }
56+
57+
58+
const App = (props) => {
59+
return (
60+
<div>
61+
<ThemeProvider theme={Object.assign({}, theme, customTheme)}> // matching keys in customTheme will override keys in the Primer theme
62+
<div>your app here</div>
63+
</ThemeProvider>
64+
</div>
65+
)
66+
}
67+
```
68+
69+
3. You can theme individual components by passing the `theme` prop directly:
5170
5271
```jsx
5372
import {Text} from '@primer/components'
@@ -65,6 +84,7 @@ There are two ways to change the theme of Primer components:
6584

6685
**☝️ This is an intentionally convoluted example, since you can use `<Text color='#f0f'>` out of the box.**
6786

87+
6888
Read the [styled-system docs](http://jxnblk.com/styled-system/getting-started#theming) for more information on theming in styled-system.
6989

7090
[styled-components]: https://styled-components.com/

src/Avatar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PropTypes from 'prop-types'
22
import styled from 'styled-components'
3-
import {themeGet, space} from 'styled-system'
3+
import {get} from './constants'
4+
import {space} from 'styled-system'
45
import theme from './theme'
56

67
function borderRadius({size}) {
@@ -15,7 +16,7 @@ const Avatar = styled.img.attrs(props => ({
1516
}))`
1617
display: inline-block;
1718
overflow: hidden; // Ensure page layout in Firefox should images fail to load
18-
line-height: ${themeGet('lineHeights.condensedUltra', 1)};
19+
line-height: ${get('lineHeights.condensedUltra')};
1920
vertical-align: middle;
2021
${borderRadius};
2122
${space};

src/AvatarPair.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import styled from 'styled-components'
4-
import {themeGet} from 'styled-system'
4+
import {get} from './constants'
55
import Avatar from './Avatar'
66
import theme from './theme'
77

8-
const getBackgroundColor = themeGet('colors.white', '#fff')
8+
const getBackgroundColor = get('colors.white')
99

1010
const Wrapper = styled('div')`
1111
display: inline-flex;
@@ -15,7 +15,7 @@ const Wrapper = styled('div')`
1515
const childStyles = props => ({
1616
display: 'inline-block',
1717
overflow: 'hidden', // Ensure page layout in Firefox should images fail to load
18-
lineHeight: `${themeGet('lineHeights.condensedUltra', 1)}`,
18+
lineHeight: `${get('lineHeights.condensedUltra')}`,
1919
verticalAlign: 'middle',
2020
borderRadius: '2px',
2121
position: 'absolute',

src/BranchName.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import PropTypes from 'prop-types'
22
import styled from 'styled-components'
3-
import {themeGet} from 'styled-system'
43
import theme from './theme'
5-
import {COMMON, Base} from './constants'
4+
import {COMMON, Base, get} from './constants'
65

76
const BranchName = styled(Base)`
87
display: inline-block;
98
padding: 2px 6px;
10-
font-size: ${themeGet('fontSizes.0', theme.fontSizes[0])}px;
11-
font-family: ${themeGet('fonts.mono', theme.fonts.mono)};
9+
font-size: ${get('fontSizes.0')}px;
10+
font-family: ${get('fonts.mono')};
1211
color: rgba(27, 31, 35, 0.6);
1312
background-color: #eaf5ff;
1413
border-radius: 3px;

src/Button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function fontSize({size = '14px', ...props}) {
1212
}
1313
}
1414

15-
const ButtonBase = ({is: Tag = 'div', onClick, disabled, theme, ...rest}) => {
15+
const ButtonBase = ({is: Tag, onClick, disabled, theme, ...rest}) => {
1616
return <Tag disabled={disabled} onClick={disabled ? undefined : onClick} {...rest} />
1717
}
1818

0 commit comments

Comments
 (0)