Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4246955
wip button dropdown
Jun 6, 2018
8e9a197
fix typo in Details
Jun 6, 2018
31c7601
wrap details in Toggle
Jun 6, 2018
49fa5fb
refactor button & details to accommodate dropdowns
Jun 6, 2018
1531c5c
remove dropdown
Jun 6, 2018
0aa8ab7
add todo
Jun 6, 2018
0ec80eb
add dropdown component back
Jun 6, 2018
c9e401c
add title and scheme props to dropdown
Jun 6, 2018
58cddff
renove item prop from other buttons
Jun 6, 2018
f821318
remove toggle component
Jun 6, 2018
df6b0f7
bring back in other button options
Jun 6, 2018
c7c1d16
arrow should be static
Jun 6, 2018
7bce127
add classnames syntax back
Jun 6, 2018
038e491
add prop types to button, delete button variations
Jun 6, 2018
7f0ce42
Merge branch 'button-refactor' into task/dropdown
Jun 6, 2018
deaa7b5
revert back to classnames for now
Jun 6, 2018
19c877f
remove click handler in example
Jun 6, 2018
9314948
use classifier
Jun 6, 2018
6ed7a1a
Revert "use classifier"
Jun 7, 2018
b090fdd
test fixes
Jun 7, 2018
c0349b8
add disabled tag to button
Jun 7, 2018
a835b3b
fix render test
Jun 7, 2018
330e1d0
clean up details
Jun 7, 2018
6c15a2b
remove uncessary classnames import
Jun 7, 2018
d571e6e
Merge branch 'release-0.0.3-beta' into task/dropdown
shawnbot Jun 7, 2018
903675f
switch to regular react component, remove unecessary imports
Jun 7, 2018
ee38f4b
update docs
shawnbot Jun 7, 2018
5382a37
default the reset styles on Details
Jun 7, 2018
3d4b87b
Merge branch 'task/dropdown' of github.com:primer/primer-react into t…
Jun 7, 2018
110ec87
import classnames
Jun 7, 2018
ee5c3d9
add white background and z-index to dropdown content
Jun 7, 2018
d0abe8b
change zindex value
Jun 7, 2018
fe8b23f
Merge branch 'release-0.0.3-beta' into task/dropdown
Jun 7, 2018
8ffe5bc
Merge branch 'release-0.0.3-beta' into task/dropdown
Jun 7, 2018
acc07eb
add caret
Jun 7, 2018
c031939
replace arrow with css arrow
Jun 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions docs/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Details,
DonutChart,
DonutSlice,
Dropdown,
Flash,
Heading,
Label,
Expand Down Expand Up @@ -181,7 +182,7 @@ const Index = props => (
</Details>
</Block>
<Block my={4}>
<Heading tag='h2'>With render prop</Heading>
<Heading tag='h2'>With children as a function</Heading>
<Details>{({open, toggle}) => (
<React.Fragment>
<summary className='btn' onClick={toggle}>{open ? 'Hide' : 'Show'}</summary>
Expand All @@ -190,6 +191,42 @@ const Index = props => (
)}
</Details>
</Block>
<Block my={4}>
<Heading tag='h2'>With render prop</Heading>
<Details render={() => 'hi'}/>
</Block>
</Example>
<Example name="Dropdown">
<Block my={4}>
<Heading tag="h2">Dropdown Primary</Heading>
<Dropdown scheme={"primary"}>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</Dropdown>
</Block>
<Block my={4}>
<Heading tag="h2">Dropdown</Heading>
<Dropdown>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</Dropdown>
</Block>
<Block my={4}>
<Heading tag="h2">Dropdown with title</Heading>
<Dropdown title="Options">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</Dropdown>
</Block>
</Example>
<Example name='DonutChart'>
<Box mb={2}>
Expand Down
103 changes: 58 additions & 45 deletions package-lock.json

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

60 changes: 38 additions & 22 deletions src/Button.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
import React from 'react'
import classnames from 'classnames'
import PropTypes from 'prop-types'

const Button = ({
block,
function Button({
tag: Tag = 'button',
children,
disabled,
size,
block,
linkStyle,
onClick,
grouped,
scheme,
size
}) => (
<button
disabled={disabled}
onClick={disabled ? undefined : onClick}
type="button"
className={classnames(
linkStyle ? 'btn-link' : 'btn',
scheme ? `btn-${scheme}` : null,
{
'btn-sm': size === 'small',
'btn-large': size === 'large',
'btn-block': block,
}
)}
>
onClick,
disabled,
...props
}) {
const classes = classnames(
Copy link
Author

@emplums emplums Jun 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shawnbot I ended up using classnames here instead of the classifier method because I was having trouble getting it to work while also transforming the Tag prop 🤔 I went back and forth a bunch, but I also feel like this method is a bit more straightforward to read so going to go forward with it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! Let's nix the import map, { classifier } from './props' above then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schwoops! i'll nix that

{
'btn': !linkStyle,
'btn-link': linkStyle,
'btn-sm': size === 'sm',
'btn-large': size === 'large',
'btn-block': block,
'BtnGroup-item': grouped,
},
scheme ? `btn-${scheme}` : null
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semicolon!! 😱 :trollface:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we decided not to use semicolons as a team?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's pretty much the house style at GitHub; see the prettier config in eslint-plugin-github. I tried to get us linting with that in #28, but quoted JSX attributes were a problem. ☹️

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dang! I'd love to work on that a bit more to see if we can get linting set up sometime this week! :D I'll take a look!


return (
<Tag {...props} type="button" disabled={disabled} onClick={disabled ? undefined : onClick} className={classes}>
{children}
</button>
)
</Tag>
)
}

Button.propTypes = {
block: PropTypes.bool,
grouped: PropTypes.bool,
scheme: PropTypes.string,
size: PropTypes.oneOf(['sm', 'large']),
tag: PropTypes.oneOf(['button', 'a', 'summary']),
linkStyle: PropTypes.bool,
disabled: PropTypes.bool,
onClick: PropTypes.func
}

export default Button
22 changes: 2 additions & 20 deletions src/ButtonPrimary.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import React from 'react'
import classnames from 'classnames'
import Button from './Button'

const ButtonPrimary = ({ size, disabled, block, linkStyle, onClick, children }) => (
<button
disabled={disabled}
onClick={onClick}
type="button"
className={classnames(
'btn-primary',
{
'btn': !linkStyle,
'btn-link': linkStyle,
'btn-sm': size === 'small',
'btn-large': size === 'large',
'btn-block': block,
}
)}
>
{children}
</button>
)
const ButtonPrimary = props => <Button {...props} scheme='primary' />

export default ButtonPrimary
16 changes: 9 additions & 7 deletions src/Details.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'

function getRenderer(children) {
return typeof children === 'function'
? children
: () => children
return typeof children === 'function' ? children : () => children
}

export default class Details extends React.PureComponent {
export default class Details extends React.Component {
constructor(props) {
super(props)
this.state = {open: Boolean(props.open)}
Expand All @@ -18,17 +17,20 @@ export default class Details extends React.PureComponent {
if (event) {
event.preventDefault()
}
this.setState({open: !this.state.open})
this.setState({ open: !this.state.open })
}

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

return (
<details open={open} className='details-reset'>
<details {...props} className={classnames('details-reset', className)} open={open}>
{render({open, toggle: this.toggle})}
</details>
)
Expand Down
Loading