11import React , { Component } from 'react' ;
2- import { createPortal } from 'react-dom' ;
32import { environment } from '#store/environment' ;
43import { observer } from 'mobx-react' ;
54import {
@@ -8,46 +7,50 @@ import {
87 SortableHandle ,
98} from 'react-sortable-hoc' ;
109import { hexToMDHex } from '#formats/palette' ;
11- import ColorPicker from 'rc-color- picker' ;
12- import { SketchPicker } from 'react-color ' ;
10+ import Picker from './ picker' ;
11+ import Trigger from 'rc-trigger ' ;
1312
1413const Handle = SortableHandle ( ( { lineIndex } ) => (
1514 < div className = "index" > { lineIndex } </ div >
1615) ) ;
1716
18- const container = document . body . appendChild ( document . createElement ( 'div' ) ) ;
19- container . className = 'palette-color-picker' ;
17+ // anim, colour, placement
2018
2119const SortableItem = SortableElement (
22- observer ( ( { line, lineIndex, onClick } ) => {
20+ observer ( ( { line, lineIndex } ) => {
2321 return (
2422 < div className = "line" >
2523 < Handle lineIndex = { lineIndex } />
2624 { line . map ( ( color , colorIndex ) => {
2725 return (
28- < div
26+ < Trigger
2927 key = { colorIndex }
30- className = "color"
31- style = { {
32- backgroundColor : color ,
33- textAlign : 'center' ,
28+ action = { [ 'click' ] }
29+ prefixCls = "color-picker"
30+ popup = { (
31+ < Picker
32+ color = { color }
33+ onChange = { ( { hex } ) => {
34+ environment . palettes [ lineIndex ] [
35+ colorIndex
36+ ] = hexToMDHex ( hex ) ;
37+ } }
38+ />
39+ ) }
40+ popupAlign = { {
41+ points : [ 'tl' , 'bl' ] ,
42+ offset : [ 0 , 3 ]
3443 } }
35- onClick = { ( e ) => onClick ( lineIndex , colorIndex , e ) }
44+ destroyPopupOnHide
3645 >
37- < ColorPicker
38- animation = "slide-up"
39- color = { color }
40- enableAlpha = { false }
41- mode = "RGB"
42- onChange = { ( { color } ) => {
43- environment . palettes [ lineIndex ] [
44- colorIndex
45- ] = hexToMDHex ( color ) ;
46+ < div
47+ className = "color"
48+ style = { {
49+ backgroundColor : color ,
50+ textAlign : 'center' ,
4651 } }
47- >
48- < div className = "picker" />
49- </ ColorPicker >
50- </ div >
52+ />
53+ </ Trigger >
5154 ) ;
5255 } ) }
5356 </ div >
@@ -68,7 +71,6 @@ const SortableList = SortableContainer(
6871 index = { index }
6972 line = { line }
7073 lineIndex = { index }
71- onClick = { this . props . onClick }
7274 />
7375 ) ) }
7476 </ div >
@@ -81,7 +83,7 @@ const SortableList = SortableContainer(
8183
8284@observer
8385export class Palettes extends Component {
84- state = { vert : false , picker : false } ;
86+ state = { vert : false } ;
8587 mounted = false ;
8688
8789 onRef = ( node ) => {
@@ -112,24 +114,8 @@ export class Palettes extends Component {
112114 environment . swapPalette ( oldIndex , newIndex ) ;
113115 } ;
114116
115- onClickColor = ( lineIndex , colorIndex , e ) => {
116- const rect = e . target . getBoundingClientRect ( ) ;
117- const { picker } = this . state ;
118- if (
119- picker &&
120- lineIndex === picker . lineIndex &&
121- colorIndex === picker . colorIndex
122- ) {
123- this . closePicker ( ) ;
124- } else {
125- this . setState ( { picker : { lineIndex, colorIndex, rect } } ) ;
126- }
127- } ;
128-
129- closePicker = ( ) => this . setState ( { picker : false } ) ;
130-
131117 render ( ) {
132- const { vert, picker } = this . state ;
118+ const { vert } = this . state ;
133119 const { palettes } = environment ;
134120 return (
135121 < div ref = { this . onRef } className = "paletteWrap" >
@@ -142,22 +128,8 @@ export class Palettes extends Component {
142128 useDragHandle = { true }
143129 vert = { vert }
144130 onSortEnd = { this . onSortEnd }
145- onClick = { this . onClickColor }
146131 />
147- { createPortal (
148- picker && (
149- < div
150- style = { {
151- left : picker . rect . x + 'px' ,
152- top : picker . rect . y + picker . rect . height + 'px' ,
153- position : 'absolute' ,
154- } }
155- >
156- < SketchPicker />
157- </ div >
158- ) ,
159- container ,
160- ) }
132+
161133 </ div >
162134 ) ;
163135 }
0 commit comments