mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-27 15:54:23 +02:00
User dropdown for tag selector
This commit is contained in:
parent
e35e843a29
commit
956dac1600
@ -83,7 +83,7 @@ let DemoPage = React.createClass({
|
|||||||
items={[
|
items={[
|
||||||
{name: 'tag1', color: 'blue'},
|
{name: 'tag1', color: 'blue'},
|
||||||
{name: 'suggestion', color: '#ff6900'},
|
{name: 'suggestion', color: '#ff6900'},
|
||||||
{name: 'tag3', color: 'yellow'},
|
{name: 'tag3', color: 'red'},
|
||||||
{name: 'tag4', color: 'green'},
|
{name: 'tag4', color: 'green'},
|
||||||
{name: 'bug', color: '#eb144c'},
|
{name: 'bug', color: '#eb144c'},
|
||||||
]}
|
]}
|
||||||
|
@ -50,11 +50,12 @@ class DropDown extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let animation = this.getAnimationStyles();
|
let animation = this.getAnimationStyles();
|
||||||
let selectedItem = this.props.items[this.getSelectedIndex()];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={this.getClass()}>
|
<div className={this.getClass()}>
|
||||||
{this.renderCurrentItem(selectedItem)}
|
<div {...this.getCurrentItemProps()}>
|
||||||
|
{this.props.children ? this.props.children : this.renderCurrentItem()}
|
||||||
|
</div>
|
||||||
<Motion defaultStyle={animation.defaultStyle} style={animation.style} onRest={this.onAnimationFinished.bind(this)}>
|
<Motion defaultStyle={animation.defaultStyle} style={animation.style} onRest={this.onAnimationFinished.bind(this)}>
|
||||||
{this.renderList.bind(this)}
|
{this.renderList.bind(this)}
|
||||||
</Motion>
|
</Motion>
|
||||||
@ -72,15 +73,17 @@ class DropDown extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCurrentItem(item) {
|
renderCurrentItem() {
|
||||||
var iconNode = null;
|
let item = this.props.items[this.getSelectedIndex()];
|
||||||
|
let iconNode = null;
|
||||||
|
|
||||||
|
|
||||||
if (item.icon) {
|
if (item.icon) {
|
||||||
iconNode = <Icon className="drop-down__current-item-icon" name={item.icon} />;
|
iconNode = <Icon className="drop-down__current-item-icon" name={item.icon} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div {...this.getCurrentItemProps()}>
|
<div>
|
||||||
{iconNode}{item.content}
|
{iconNode}{item.content}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import Icon from 'core-components/icon';
|
import Icon from 'core-components/icon';
|
||||||
|
import DropDown from 'core-components/drop-down';
|
||||||
|
|
||||||
class TagSelector extends React.Component {
|
class TagSelector extends React.Component {
|
||||||
|
|
||||||
@ -16,12 +17,9 @@ class TagSelector extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="tag-selector">
|
<div className="tag-selector">
|
||||||
<div className="tag-selector__selected-tags">
|
<DropDown className="tag-selector__drop-down" items={this.renderTagOptions().map(tag => ({content: tag}))} selectedIndex={-1} size="large">
|
||||||
{this.renderSelectedTags()}
|
{this.renderSelectedTags()}
|
||||||
</div>
|
</DropDown>
|
||||||
<div className="tag-selector__tag-options">
|
|
||||||
{this.renderTagOptions()}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -35,7 +33,7 @@ class TagSelector extends React.Component {
|
|||||||
|
|
||||||
renderSelectedTag(item,index) {
|
renderSelectedTag(item,index) {
|
||||||
return (
|
return (
|
||||||
<div className="tag-selector__selected-tag" style={{backgroundColor:item.color}} key={index}>
|
<div className="tag-selector__selected-tag" style={{backgroundColor:item.color}} onClick={event => event.stopPropagation()} key={index}>
|
||||||
<span className="tag-selector__selected-tag-name">{item.name}</span>
|
<span className="tag-selector__selected-tag-name">{item.name}</span>
|
||||||
<span onClick={this.onRemoveClick.bind(this,item.name)} className="tag-selector__selected-tag-remove" >
|
<span onClick={this.onRemoveClick.bind(this,item.name)} className="tag-selector__selected-tag-remove" >
|
||||||
<Icon name="times-circle" size="small"/>
|
<Icon name="times-circle" size="small"/>
|
||||||
@ -52,20 +50,22 @@ class TagSelector extends React.Component {
|
|||||||
|
|
||||||
renderTagOption(item,index) {
|
renderTagOption(item,index) {
|
||||||
return (
|
return (
|
||||||
<div onClick={this.onTagSelected.bind(this,item.name)} className="tag-selector__tag-option" style={{backgroundColor:item.color}} key={index}>
|
<div onClick={this.onTagSelected.bind(this,item.name)} className="tag-selector__tag-option" key={index}>
|
||||||
|
<span className="tag-selector__tag-option-square" style={{backgroundColor:item.color}}/>
|
||||||
<span className="tag-selector__tag-option-name" >{item.name}</span>
|
<span className="tag-selector__tag-option-name" >{item.name}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemoveClick(name) {
|
onRemoveClick(tag) {
|
||||||
|
|
||||||
if(this.props.onRemoveClick){
|
if(this.props.onRemoveClick){
|
||||||
this.props.onRemoveClick(name);
|
this.props.onRemoveClick(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onTagSelected(name) {
|
onTagSelected(tag) {
|
||||||
if(this.props.onTagSelected){
|
if(this.props.onTagSelected){
|
||||||
this.props.onTagSelected(name);
|
this.props.onTagSelected(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,27 +3,45 @@
|
|||||||
.tag-selector{
|
.tag-selector{
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
&__selected-tags {
|
|
||||||
border-radius: 3px;
|
&__drop-down {
|
||||||
background-color:white;
|
.drop-down__current-item {
|
||||||
padding:3px 1px;
|
cursor: text;
|
||||||
|
background-color: white;
|
||||||
|
border: 1px solid $grey;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: $primary-blue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__selected-tag,
|
&__selected-tags {
|
||||||
&__tag-option {
|
|
||||||
color:white;
|
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
margin-left: 5px;
|
background-color: white;
|
||||||
padding:3px;
|
padding: 3px 1px;
|
||||||
font-size: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__selected-tag {
|
&__selected-tag {
|
||||||
|
color: white;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
border-radius: 3px;
|
||||||
|
margin-left: 5px;
|
||||||
|
padding: 3px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__selected-tag {
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
&-remove {
|
&-remove {
|
||||||
margin-left: 10px;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
margin-left: 10px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: $light-grey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,9 +51,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__tag-option {
|
&__tag-option {
|
||||||
cursor: pointer;
|
color: $primary-black;
|
||||||
&-name {
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&-square {
|
||||||
|
display: inline-block;
|
||||||
|
height: 15px;
|
||||||
|
width: 15px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-name {
|
||||||
|
margin-left: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user