-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mod: code review
- Loading branch information
Showing
29 changed files
with
733 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
@blue: #2F80ED; | ||
@lightGray: #E9EDEF; | ||
@lightBlue: #F3F6F9; | ||
@darkBlue: #465B7A; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.icon-instruction { | ||
margin: 0 2px; | ||
color: rgba(140, 140, 140, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Tooltip } from 'antd'; | ||
import Icon from '@app/components/Icon'; | ||
import React from 'react'; | ||
|
||
import './index.less'; | ||
|
||
const Instruction = (props: { description: string; onClick?: () => void }) => { | ||
return ( | ||
<Tooltip title={props.description} placement="right"> | ||
<Icon | ||
type="icon-nav-help" | ||
className="icon-instruction" | ||
onClick={props.onClick} | ||
/> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default Instruction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/pages/Schema/SchemaConfig/Create/IndexCreate/DraggableTags.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Tag } from 'antd'; | ||
import React, { Component } from 'react'; | ||
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd'; | ||
|
||
const reorder = (list: string[], startIndex: number, endIndex: number) => { | ||
const result = Array.from(list); | ||
|
||
const [removed] = result.splice(startIndex, 1); | ||
|
||
result.splice(endIndex, 0, removed); | ||
return result; | ||
}; | ||
|
||
const getItemStyle = (_isDragging, draggableStyle) => ({ | ||
...draggableStyle, | ||
}); | ||
|
||
interface IProps { | ||
data: string[]; | ||
updateData: (data: string[]) => void; | ||
removeData: (field: string) => void; | ||
} | ||
|
||
export default class DraggableTags extends Component<IProps> { | ||
constructor(props) { | ||
super(props); | ||
this.onDragEnd = this.onDragEnd.bind(this); | ||
} | ||
|
||
onDragEnd(result) { | ||
if (!result.destination) { | ||
return; | ||
} | ||
// adjust tag order when drop the element | ||
const items: string[] = reorder( | ||
this.props.data, | ||
result.source.index, | ||
result.destination.index, | ||
); | ||
this.props.updateData(items); | ||
} | ||
|
||
render() { | ||
const list = this.props.data.map(item => ({ | ||
id: `field-${item}`, | ||
content: ( | ||
<Tag className="drag-item" closable={true} onClose={() => this.props.removeData(item)}> | ||
{item} | ||
</Tag> | ||
), | ||
})); | ||
return ( | ||
<DragDropContext onDragEnd={this.onDragEnd}> | ||
<Droppable droppableId="droppable" direction="horizontal"> | ||
{(provided, _snapshot) => ( | ||
<div | ||
{...provided.droppableProps} | ||
ref={provided.innerRef} | ||
style={{ | ||
display: 'flex', | ||
overflow: 'auto', | ||
}} | ||
> | ||
{list.map((item, index) => ( | ||
<Draggable key={item.id} draggableId={item.id} index={index}> | ||
{(provided, snapshot) => ( | ||
<div | ||
ref={provided.innerRef} | ||
{...provided.draggableProps} | ||
{...provided.dragHandleProps} | ||
style={getItemStyle( | ||
snapshot.isDragging, | ||
provided.draggableProps.style, | ||
)} | ||
> | ||
{item.content} | ||
</div> | ||
)} | ||
</Draggable> | ||
))} | ||
{provided.placeholder} | ||
</div> | ||
)} | ||
</Droppable> | ||
</DragDropContext> | ||
); | ||
} | ||
} |
Oops, something went wrong.