Skip to content

Commit

Permalink
[changed] DropdownButton, SplitButton, DropdownMenu, MenuItem complet…
Browse files Browse the repository at this point in the history
…ely rewritten

Adds:
- Keyboard Navigation
- Aria properties for Assistive Technology
- Option to use custom menu with any of the dropdown variations
- `NavDropdown` component (Similar to `DropdownButton` but specifically
  for use within `Nav` components.
- `DropdownToggle` Component which can be used as an alternative to the
  `DropdownButton` `title` prop. Can either be directly imported or used
  as a static property of the `DropdownButton` with
  `DropdownButton.Toggle`. _(Useful should you want to use glyphicons or
  custom html within the toggle that's not a simple string.)_
- `SplitToggle` Similar to the `DropdownToggle` but targeted at the
  `SplitButton`'s toggle.
- Generic `Dropdown` component for easy dropdown customization.

Changed:
- Event handling of all these components to be in line with react-bootstrap#419
- Written with ES6 class syntax

Removed:
- DropdownStateMixin - Everything is using ES6 class syntax so no more
  mixin usage
  • Loading branch information
mtscout6 committed Aug 21, 2015
1 parent 6f13e04 commit 346501e
Show file tree
Hide file tree
Showing 55 changed files with 2,150 additions and 938 deletions.
2 changes: 2 additions & 0 deletions .ackrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--ignore-dir=.coverage
--ignore-dir=lib
--ignore-dir=dist
--ignore-dir=amd
Expand All @@ -7,3 +8,4 @@
--ignore-dir=tmp-bower-repo
--ignore-file=match:test_bundle.js
--ignore-file=match:components.html
--ignore-file=match:.orig
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"parser": "babel-eslint",
"plugins": [
"react",
"babel"
"babel",
"lodash"
],
"rules": {
"constructor-super": 2,
Expand All @@ -32,11 +33,12 @@
"react/no-did-mount-set-state": 2,
"react/no-did-update-set-state": 2,
"react/no-multi-comp": 2,
"react/prop-types": [2, { "ignore": [ "children", "className" ] }],
"react/prop-types": [1, { "ignore": [ "children", "className" ] }],
"react/react-in-jsx-scope": 2,
"react/self-closing-comp": 2,
"react/wrap-multilines": 2,
"react/jsx-uses-vars": 2,
"lodash/import": 2,
"space-infix-ops": 2,
"strict": [2, "never"]
}
Expand Down
4 changes: 4 additions & 0 deletions .projections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"src/*.js": { "alternate": "test/{}Spec.js" },
"test/*Spec.js": { "alternate": "src/{}.js" }
}
35 changes: 34 additions & 1 deletion docs/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ body {
}
}

.navbar>.container .navbar-brand, .navbar>.container-fluid .navbar-brand {
.bs-docs-nav .navbar-brand {
color: #00d8ff;
}

Expand Down Expand Up @@ -173,6 +173,29 @@ body {

}

.bs-example .super-colors {
background: -moz-linear-gradient( top ,
rgba(255, 0, 0, 1) 0%,
rgba(255, 255, 0, 1) 15%,
rgba(0, 255, 0, 1) 30%,
rgba(0, 255, 255, 1) 50%,
rgba(0, 0, 255, 1) 65%,
rgba(255, 0, 255, 1) 80%,
rgba(255, 0, 0, 1) 100%);
background: -webkit-gradient(linear, left top, left bottom,
color-stop(0%, rgba(255, 0, 0, 1)),
color-stop(15%, rgba(255, 255, 0, 1)),
color-stop(30%, rgba(0, 255, 0, 1)),
color-stop(50%, rgba(0, 255, 255, 1)),
color-stop(65%, rgba(0, 0, 255, 1)),
color-stop(80%, rgba(255, 0, 255, 1)),
color-stop(100%, rgba(255, 0, 0, 1)));
}

/*.bs-example .custom-menu > ul > li {
padding: 0 20px;
}*/

.anchor,
.anchor:hover,
.anchor:active,
Expand All @@ -199,3 +222,13 @@ h4:hover .anchor-icon,
h4 a:focus .anchor-icon {
opacity: 0.5;
}

.prop-desc pre {
border-radius: 0;
border-width: 0;
border-left-width: 3px;
}

.prop-desc-heading {
margin-bottom: 10px;
}
3 changes: 3 additions & 0 deletions docs/examples/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"Carousel",
"CarouselItem",
"Col",
"Dropdown",
"DropdownButton",
"DropdownMenu",
"FormControls",
"Glyphicon",
"Grid",
Expand All @@ -30,6 +32,7 @@
"ListGroupItem",
"Nav",
"Navbar",
"NavDropdown",
"NavItem",
"MenuItem",
"Modal",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/ButtonGroupJustified.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const buttonGroupInstance = (
<ButtonGroup justified>
<Button href='#'>Left</Button>
<Button href='#'>Middle</Button>
<DropdownButton title='Dropdown'>
<DropdownButton title='Dropdown' id='bg-justified-dropdown'>
<MenuItem eventKey='1'>Dropdown link</MenuItem>
<MenuItem eventKey='2'>Dropdown link</MenuItem>
</DropdownButton>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/ButtonGroupNested.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const buttonGroupInstance = (
<ButtonGroup>
<Button>1</Button>
<Button>2</Button>
<DropdownButton title='Dropdown'>
<DropdownButton title='Dropdown' id='bg-nested-dropdown'>
<MenuItem eventKey='1'>Dropdown link</MenuItem>
<MenuItem eventKey='2'>Dropdown link</MenuItem>
</DropdownButton>
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/ButtonGroupVertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ const buttonGroupInstance = (
<ButtonGroup vertical>
<Button>Button</Button>
<Button>Button</Button>
<DropdownButton title='Dropdown'>
<DropdownButton title='Dropdown' id='bg-vertical-dropdown-1'>
<MenuItem eventKey='1'>Dropdown link</MenuItem>
<MenuItem eventKey='2'>Dropdown link</MenuItem>
</DropdownButton>
<Button>Button</Button>
<Button>Button</Button>
<DropdownButton title='Dropdown'>
<DropdownButton title='Dropdown' id='bg-vertical-dropdown-2'>
<MenuItem eventKey='1'>Dropdown link</MenuItem>
<MenuItem eventKey='2'>Dropdown link</MenuItem>
</DropdownButton>
<DropdownButton title='Dropdown'>
<DropdownButton title='Dropdown' id='bg-vertical-dropdown-3'>
<MenuItem eventKey='1'>Dropdown link</MenuItem>
<MenuItem eventKey='2'>Dropdown link</MenuItem>
</DropdownButton>
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/CollapsibleNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const navbarInstance = (
<Nav navbar>
<NavItem eventKey={1} href='#'>Link</NavItem>
<NavItem eventKey={2} href='#'>Link</NavItem>
<DropdownButton eventKey={3} title='Dropdown'>
<NavDropdown eventKey={3} title='Dropdown' id='collapsible-nav-dropdown'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3'>Something else here</MenuItem>
<MenuItem divider />
<MenuItem eventKey='4'>Separated link</MenuItem>
</DropdownButton>
</NavDropdown>
</Nav>
<Nav navbar right>
<NavItem eventKey={1} href='#'>Link Right</NavItem>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/DropdownButtonBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const BUTTONS = ['Default', 'Primary', 'Success', 'Info', 'Warning', 'Danger', '

function renderDropdownButton (title, i) {
return (
<DropdownButton bsStyle={title.toLowerCase()} title={title} key={i}>
<DropdownButton bsStyle={title.toLowerCase()} title={title} key={i} id={`dropdown-basic-${i}`}>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3' active>Active Item</MenuItem>
Expand Down
35 changes: 35 additions & 0 deletions docs/examples/DropdownButtonCustom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const dropdownInstance = (
<ButtonToolbar>
<Dropdown id='dropdown-custom-1'>
<Dropdown.Toggle>
<Glyphicon glyph='star' />
Pow! Zoom!
</Dropdown.Toggle>
<Dropdown.Menu className='super-colors'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3' active>Active Item</MenuItem>
<MenuItem divider />
<MenuItem eventKey='4'>Separated link</MenuItem>
</Dropdown.Menu>
</Dropdown>

<Dropdown id='dropdown-custom-2'>
<Button bsStyle='info'>
mix it up style-wise
</Button>
<Dropdown.Toggle bsStyle='success'/>
<Dropdown.Menu className='super-colors'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3' active>Active Item</MenuItem>
<MenuItem divider />
<MenuItem eventKey='4'>Separated link</MenuItem>
</Dropdown.Menu>
</Dropdown>

</ButtonToolbar>
);

React.render(dropdownInstance, mountNode);
75 changes: 75 additions & 0 deletions docs/examples/DropdownButtonCustomMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

class CustomMenu extends React.Component {

constructor(...args){
super(...args);
this.state = { value: '' };
this.onChange = e => this.setState({ value: e.target.value });
}

render(){
let { className, ...props } = this.props;

return (
<div
className={'dropdown-menu'}
style={{ padding: '5px 10px'}}
>
<input
ref={input => this.input = input}
type='text'
className='form-control'
placeholder='type to filter...'
onChange={this.onChange}
value={this.state.value}
/>
<ul className='list-unstyled'>
{ this.filterChildren() }
</ul>
</div>
);
}

filterChildren(){
let { children } = this.props;
let { value } = this.state;
let filtered = [];

let matches = child => child.props.children.indexOf(value) !== -1;

React.Children.forEach(children, child => {
if (!value.trim() || matches(child)) {
filtered.push(child);
}
});

return filtered;
}

focusNext() {
let input = React.findDOMNode(this.input);

if (input) {
input.focus();
}
}
}

let preventDefault = e => e.preventDefault();

let dropdownExample = (
<Dropdown id='dropdown-custom-menu'>
<a href='#' bsRole='toggle' onClick={preventDefault}>
custom Toggle
</a>

<CustomMenu bsRole='menu'>
<MenuItem eventKey='1'>Red</MenuItem>
<MenuItem eventKey='2'>Blue</MenuItem>
<MenuItem eventKey='3' active>Orange</MenuItem>
<MenuItem eventKey='1'>Red-Orange</MenuItem>
</CustomMenu>
</Dropdown>
);

React.render(dropdownExample, mountNode);
2 changes: 1 addition & 1 deletion docs/examples/DropdownButtonNoCaret.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const buttonInstance = (
<ButtonToolbar>
<DropdownButton bsStyle='default' title='No caret' noCaret>
<DropdownButton bsStyle='default' title='No caret' noCaret id='dropdown-no-caret'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3'>Something else here</MenuItem>
Expand Down
16 changes: 13 additions & 3 deletions docs/examples/DropdownButtonSizes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const buttonsInstance = (
<div>
<ButtonToolbar>
<DropdownButton bsSize='large' title='Large button'>
<DropdownButton bsSize='large' title='Large button' id='dropdown-size-large'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3'>Something else here</MenuItem>
Expand All @@ -11,7 +11,7 @@ const buttonsInstance = (
</ButtonToolbar>

<ButtonToolbar>
<DropdownButton bsSize='small' title='Small button'>
<DropdownButton bsSize='medium' title='Small button' id='dropdown-size-medium'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3'>Something else here</MenuItem>
Expand All @@ -21,7 +21,17 @@ const buttonsInstance = (
</ButtonToolbar>

<ButtonToolbar>
<DropdownButton bsSize='xsmall' title='Extra small button'>
<DropdownButton bsSize='small' title='Small button' id='dropdown-size-small'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3'>Something else here</MenuItem>
<MenuItem divider />
<MenuItem eventKey='4'>Separated link</MenuItem>
</DropdownButton>
</ButtonToolbar>

<ButtonToolbar>
<DropdownButton bsSize='xsmall' title='Extra small button' id='dropdown-size-extra-small'>
<MenuItem eventKey='1'>Action</MenuItem>
<MenuItem eventKey='2'>Another action</MenuItem>
<MenuItem eventKey='3'>Something else here</MenuItem>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/InputAddons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const innerGlyphicon = <Glyphicon glyph='music' />;
const innerButton = <Button>Before</Button>;
const innerDropdown = (
<DropdownButton title='Action'>
<DropdownButton title='Action' id='input-dropdown-addon'>
<MenuItem key='1'>Item</MenuItem>
</DropdownButton>
);
Expand Down
8 changes: 3 additions & 5 deletions docs/examples/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ function onSelectAlert(eventKey, href, target) {
alert('Alert from menu item.\neventKey: "' + eventKey + '"\nhref: "' + href + '"');
}

function preventDefault() {}

const MenuItems = (
<div className="clearfix">
<ul className="dropdown-menu open">
<MenuItem header>Header</MenuItem>
<MenuItem onSelect={preventDefault}>link</MenuItem>
<MenuItem>link</MenuItem>
<MenuItem divider/>
<MenuItem header>Header</MenuItem>
<MenuItem onSelect={preventDefault}>link</MenuItem>
<MenuItem>link</MenuItem>
<MenuItem disabled>disabled</MenuItem>
<MenuItem title="See? I have a title." onSelect={preventDefault}>
<MenuItem title="See? I have a title.">
link with title
</MenuItem>
<MenuItem eventKey={1} href="#someHref" onSelect={onSelectAlert}>
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/NavDropdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const NavDropdown = React.createClass({
const NavDropdownExample = React.createClass({
handleSelect(selectedKey) {
alert('selected ' + selectedKey);
},
Expand All @@ -9,16 +9,16 @@ const NavDropdown = React.createClass({
<NavItem eventKey={1} href='/home'>NavItem 1 content</NavItem>
<NavItem eventKey={2} title='Item'>NavItem 2 content</NavItem>
<NavItem eventKey={3} disabled>NavItem 3 content</NavItem>
<DropdownButton eventKey={4} title='Dropdown' navItem>
<NavDropdown eventKey={4} title='Dropdown' id='nav-dropdown'>
<MenuItem eventKey='4.1'>Action</MenuItem>
<MenuItem eventKey='4.2'>Another action</MenuItem>
<MenuItem eventKey='4.3'>Something else here</MenuItem>
<MenuItem divider />
<MenuItem eventKey='4.4'>Separated link</MenuItem>
</DropdownButton>
</NavDropdown>
</Nav>
);
}
});

React.render(<NavDropdown />, mountNode);
React.render(<NavDropdownExample />, mountNode);
Loading

0 comments on commit 346501e

Please sign in to comment.