Skip to content

Gpinto lookup modifications #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions components/SLDSLookup/Menu/Item/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
import React, { Component } from 'react';
import {Icon} from "../../../SLDSIcons";
import {EventUtil} from '../../../utils';
import escapeRegExp from 'lodash.escaperegexp';

class Item extends React.Component {
constructor(props) {
super(props);
}

componentWillReceiveProps(nextProps){
if(nextProps.isActive !== this.props.isActive && nextProps.isActive === true){
if (nextProps.isActive !== this.props.isActive && nextProps.isActive === true) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sublime text 3 babel javascript syntax highlighter treats if(<condition){<code>} as if if was a function call. if (<condition>) {<code>} highlights it as a conditional instead. Let me know if we want to use the first way anyways.

this.scrollFocus();
this.props.setFocus(this.props.id);
}
}

boldSearchText(children) {
const term = this.props.searchTerm;
if(!children || !term) return children;
const regex = new RegExp('(' + term + ')', 'gi');
let regex = this.props.boldRegex
if (!regex) {
const term = this.props.searchTerm;
if(!children || !term) return children;
regex = new RegExp('(' + escapeRegExp(term) + ')', 'gi');
}
return React.Children.map(children, c => {
return (typeof c === 'string') ? <span dangerouslySetInnerHTML={{ __html: c.replace(regex, '<mark>$1</mark>')}}></span> : c;
});
Expand Down Expand Up @@ -83,7 +87,8 @@ Item.propTypes = {
setFocus: React.PropTypes.func,
handleItemFocus: React.PropTypes.func,
onSelect: React.PropTypes.func,
data: React.PropTypes.object
data: React.PropTypes.object,
boldRegex: React.PropTypes.instanceOf(RegExp)
};

Item.defaultProps = {
Expand Down
24 changes: 13 additions & 11 deletions components/SLDSLookup/Menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ class Menu extends React.Component {
const id = c.id;
let isActive = false;
if(this.props.header){
isActive = this.props.focusIndex === i + 1? true : false;
isActive = this.props.focusIndex === i + 1 ? true : false;
}else{
isActive = this.props.focusIndex === i ? true : false;
}
return <Item
key={id}
id={id}
type={this.props.type}
searchTerm={this.props.searchTerm}
index={i}
isActive={isActive}
setFocus={this.props.setFocus}
handleItemFocus={this.handleItemFocus.bind(this)}
onSelect={this.props.onSelect}
data={c.data}
key={id}
id={id}
type={this.props.type}
searchTerm={this.props.searchTerm}
index={i}
isActive={isActive}
setFocus={this.props.setFocus}
handleItemFocus={this.handleItemFocus.bind(this)}
onSelect={this.props.onSelect}
data={c.data}
boldRegex={this.props.boldRegex}
>
{c}
</Item>
Expand Down Expand Up @@ -106,6 +107,7 @@ Menu.propTypes = {
filterWith: React.PropTypes.func,
getListLength: React.PropTypes.func,
setFocus: React.PropTypes.func,
boldRegex: React.PropTypes.instanceOf(RegExp),
};

Menu.defaultProps = {
Expand Down
8 changes: 5 additions & 3 deletions components/SLDSLookup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class SLDSLookup extends React.Component {
listLength:this.props.items.length,
items:[]
};


}

componentDidMount(){
Expand Down Expand Up @@ -97,6 +95,7 @@ class SLDSLookup extends React.Component {
selectedIndex: null,
isOpen: true,
});
if(this.props.onItemUnselect) this.props.onItemUnselect();
}

//=================================================
Expand Down Expand Up @@ -231,6 +230,7 @@ class SLDSLookup extends React.Component {
onSelect={this.selectItem.bind(this)}
header={this.getHeader()}
footer={this.getFooter()}
boldRegex={this.props.boldRegex}
/>;
}
}
Expand All @@ -254,7 +254,7 @@ class SLDSLookup extends React.Component {
{this.renderMenuContent()}
</SLDSPopover>;
}
};
}

renderSelectedItem(){
let selectedItem = this.props.items[this.state.selectedIndex].label;
Expand Down Expand Up @@ -343,9 +343,11 @@ SLDSLookup.propTypes = {
type: React.PropTypes.string,
filterWith: React.PropTypes.func,
onItemSelect: React.PropTypes.func,
onItemUnselect: React.PropTypes.func,
onChange: React.PropTypes.func,
modal: React.PropTypes.bool,
disabled: React.PropTypes.bool,
boldRegex: React.PropTypes.instanceOf(RegExp),
};

SLDSLookup.defaultProps = {
Expand Down