Skip to content

Commit

Permalink
Merge pull request #285 from primer/colocate-css
Browse files Browse the repository at this point in the history
Colocate Primer CSS global injections with components that need them
  • Loading branch information
shawnbot authored Sep 26, 2018
2 parents efa0ce0 + 000d3a7 commit 09fe10c
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 171 deletions.
22 changes: 0 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"predist": "rm -rf dist",
"dist": "NODE_ENV=production rollup -c",
"postdist": "du -ha dist",
"prepack": "script/npm-pack-check",
"prepack": "script/npm-prepack",
"prepublishOnly": "npm run dist",
"lint": "eslint src pages",
"test": "jest",
Expand Down Expand Up @@ -40,7 +40,6 @@
"classnames": "^2.2.5",
"d3-shape": "^1.2.0",
"emotion": "9.2.8",
"preval.macro": "3.0.0",
"primer-alerts": "1.5.9",
"primer-avatars": "1.5.6",
"primer-branch-name": "1.0.7",
Expand Down
43 changes: 33 additions & 10 deletions pages/components/docs/Details.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@

# Details

```.jsx
<ExampleHeading>With static children</ExampleHeading>
The Details component is an HTML `<details>` element without native browser styling that optionally uses the [render props pattern](https://reactjs.org/docs/render-props.html) to pass its state to child components.

You are responsible for rendering your own `<summary>`. To style your summary element like a [Button](./Button), you can use the `is` prop:

```jsx
<Button is="summary">Summary text</Button>
```

## With static children
```.jsx
<Details>
<summary className="btn">Click me</summary>
<Button is="summary">Click me</Button>
<p>This should show and hide</p>
</Details>
```

## With children as a function
The render function gets an object with two keys:

<ExampleHeading>With children as a function</ExampleHeading>
* `open` is a boolean reflecting the `<details>` element's `open` attribute, and can be used to conditionally show or hide content.
* `toggle` is a function that can be assigned to event handlers to trigger toggling of the `open` state.

If you use this form or the render prop (see below), **you must attach the `toggle` prop as an event listener**. If you don't the render function will not be called when the element is toggled by the native browser behavior.

```.jsx
<Details>
{({open, toggle}) => (
<React.Fragment>
<summary className="btn" onClick={toggle}>
<>
<Button is="summary" onClick={toggle}>
{open ? 'Hide' : 'Show'}
</summary>
</Button>
<p>This should show and hide</p>
</React.Fragment>
</>
)}
</Details>
```

<ExampleHeading>With render prop</ExampleHeading>
<Details render={() => 'hi'} />
## With render prop
The Details component also accepts a `render` function prop.

```.jsx
<Details render={({open, toggle}) => (
<>
<Button is="summary" onClick={toggle}>Open? {String(open)}</Button>
<p>This is the content.</p>
</>
)} />
```
## System props
Expand Down
8 changes: 4 additions & 4 deletions pages/components/docs/Dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
## Default example
```.jsx
<Dropdown scheme="primary" minWidth="5em">
<Box is="ul" m={0} p={0} className="list-style-none">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<Box role="list">
<Box role="listitem">Item 1</Box>
<Box role="listitem">Item 2</Box>
<Box role="listitem">Item 3</Box>
</Box>
</Dropdown>
```
Expand Down
2 changes: 1 addition & 1 deletion pages/components/docs/Position.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ExampleHeading my={2}>Sticky</ExampleHeading>

<Box border={1} borderColor="green.5" height={1000}>
<Sticky top={0} bg="green.2" p={4}>
<Sticky top={0} bg="green.2" p={6}>
I'm sticky!
</Sticky>
</Box>
Expand Down
6 changes: 5 additions & 1 deletion pages/components/docs/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Default example
```.jsx
<Text is="div" fontWeight="bold" lineHeight="condensed">Text</Text>
<Text fontWeight="bold">bold</Text>
{' '}
<Text color="red.6">red color</Text>
{' '}
<Text color="white" bg="gray.9" p={2}>white on black</Text>
```

## System props
Expand Down
3 changes: 0 additions & 3 deletions pages/primer-custom.scss

This file was deleted.

3 changes: 1 addition & 2 deletions script/npm-pack-check → script/npm-prepack
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const config = {
'dist/index.umd.js',
'dist/css.js',
'src/index.js',
'src/system-props.js',
'src/primer-components.scss'
'src/system-props.js'
],
missing: [
'pages',
Expand Down
7 changes: 0 additions & 7 deletions src/BaseStyles.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {injectGlobal} from 'emotion'
import {withSystemProps, TYPOGRAPHY} from './system-props'
// eslint-disable-next-line no-unused
import sass from 'sass.macro'

injectGlobal(sass`
@import "./primer-components.scss";
`)

const BaseStyles = withSystemProps(
{
Expand Down
6 changes: 6 additions & 0 deletions src/BranchName.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-branch-name/index.scss";
`)

function BranchName({children, href, is: Tag, className}) {
// We don't want someone to use href on a non tag
if (Tag !== 'a') {
Expand Down
6 changes: 6 additions & 0 deletions src/Button.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react'
import classnames from 'classnames'
import PropTypes from 'prop-types'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-buttons/index.scss";
`)

function Button({is: Tag, children, size, block, linkStyle, grouped, scheme, onClick, disabled, className, ...rest}) {
const classes = classnames(
className,
Expand Down
7 changes: 7 additions & 0 deletions src/CircleBadge.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-avatars/lib/circle-badge.scss";
`)

const ICON_CLASS = 'CircleBadge-icon'

const sizeMapper = (size = 'medium') => {
Expand Down
7 changes: 7 additions & 0 deletions src/CounterLabel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-labels/lib/counters.scss";
`)

function CounterLabel({scheme, children, className}) {
return <span className={classnames(className, 'Counter', scheme && `Counter--${scheme}`)}>{children}</span>
}
Expand Down
20 changes: 16 additions & 4 deletions src/Details.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import styled from 'react-emotion'
import {withSystemProps, COMMON, withoutPropTypes} from './system-props'

const DetailsReset = styled('details')`
& > summary {
list-style: none;
}
& > summary::before {
display: none;
}
& > summary::-webkit-details-marker {
display: none;
}
`

class Details extends React.Component {
constructor(props) {
super(props)
Expand All @@ -18,13 +30,13 @@ class Details extends React.Component {
}

render() {
const {className, children, render = getRenderer(children), ...rest} = this.props
const {children, render = getRenderer(children), ...rest} = this.props
const {open} = this.state

return (
<details {...rest} className={classnames('details-reset', className)} open={open}>
<DetailsReset {...rest} open={open}>
{render({open, toggle: this.toggle})}
</details>
</DetailsReset>
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/FilterList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-navigation/lib/filter-list.scss";
`)

export const ITEM_CLASS = 'filter-item'
export const SELECTED_CLASS = 'selected'

Expand Down
6 changes: 6 additions & 0 deletions src/Flash.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-alerts/index.scss";
`)

const schemeMap = {
green: 'success',
red: 'error',
Expand Down
7 changes: 7 additions & 0 deletions src/Label.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-labels/lib/labels.scss";
`)

const colorScheme = (scheme, outline) => {
if (outline) {
return {
Expand Down
7 changes: 7 additions & 0 deletions src/StateLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import React from 'react'
import PropTypes from 'prop-types'
import Octicon, {GitMerge, IssueClosed, IssueOpened, IssueReopened} from '@githubprimer/octicons-react'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {colors} from './theme'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-labels/lib/states.scss";
`)

const stateColorMap = {
open: 'green',
opened: 'green',
Expand Down
7 changes: 7 additions & 0 deletions src/TextInput.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-forms/lib/form-control.scss";
`)

function TextInput({autocomplete, block, className, disabled, id, name, onChange, placeholder, required, size, value}) {
const classes = classnames(className, 'form-control', {
'input-block': block,
Expand Down
6 changes: 6 additions & 0 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import sass from 'sass.macro'
import {injectGlobal} from 'emotion'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-tooltips/index.scss";
`)

function Tooltip({direction, children, className, text, noDelay, align, wrap}) {
const classes = classnames(
className,
Expand Down
7 changes: 7 additions & 0 deletions src/UnderlineNav.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import {injectGlobal} from 'emotion'
import sass from 'sass.macro'
import {withSystemProps, COMMON} from './system-props'

injectGlobal(sass`
@import "primer-support/index.scss";
@import "primer-navigation/lib/underline-nav.scss";
`)

export const ITEM_CLASS = 'UnderlineNav-item no-underline'
export const SELECTED_CLASS = 'selected'

Expand Down
Loading

0 comments on commit 09fe10c

Please sign in to comment.