@@ -18,10 +18,14 @@ import {
1818 withJsonFormsLayoutProps ,
1919} from '@jsonforms/react' ;
2020import { Grid , makeStyles } from '@material-ui/core' ;
21+ import EditIcon from '@material-ui/icons/Edit' ;
22+ import SpeedDial from '@material-ui/lab/SpeedDial' ;
23+ import SpeedDialAction from '@material-ui/lab/SpeedDialAction' ;
24+ import SpeedDialIcon from '@material-ui/lab/SpeedDialIcon' ;
2125import React from 'react' ;
2226import { useDrop } from 'react-dnd' ;
2327
24- import { useDispatch , useSchema } from '../context' ;
28+ import { useDispatch , usePaletteService , useSchema } from '../context' ;
2529import {
2630 canDropIntoLayout ,
2731 canMoveSchemaElementTo ,
@@ -73,12 +77,12 @@ export const DroppableLayout: React.FC<DroppableLayoutProps> = ({
7377 spacing = { direction === 'row' ? 2 : 0 }
7478 wrap = 'nowrap'
7579 >
76- < DropPoint index = { 0 } layout = { layout } key = { `${ path } -${ 0 } -drop` } />
80+ < DropPoint index = { 0 } layout = { layout } key = { `${ layout . uuid } -${ 0 } -drop` } />
7781 { layout . elements . map ( ( child , index ) => (
78- < React . Fragment key = { `${ path } -${ index } -fragment` } >
82+ < React . Fragment key = { `${ layout . uuid } -${ index } -fragment` } >
7983 < Grid
8084 item
81- key = { `${ path } -${ index } ` }
85+ key = { `${ layout . uuid } -${ index } ` }
8286 className = { classes . jsonformsGridItem }
8387 xs
8488 >
@@ -95,14 +99,70 @@ export const DroppableLayout: React.FC<DroppableLayoutProps> = ({
9599 < DropPoint
96100 index = { index + 1 }
97101 layout = { layout }
98- key = { `${ path } -${ index + 1 } -drop` }
102+ key = { `${ layout . uuid } -${ index + 1 } -drop` }
99103 />
100104 </ React . Fragment >
101105 ) ) }
102106 </ Grid >
103107 ) ;
104108} ;
105109
110+ const useActionBarStyles = makeStyles ( ( theme ) => ( {
111+ speedDial : {
112+ bottom : theme . spacing ( 2 ) ,
113+ right : theme . spacing ( 2 ) ,
114+ } ,
115+ } ) ) ;
116+ interface InlineActionBarProps {
117+ layout : EditorLayout ;
118+ index : number ;
119+ }
120+ const InlineActionBar = ( { layout, index } : InlineActionBarProps ) => {
121+ const classes = useActionBarStyles ( ) ;
122+ const paletteService = usePaletteService ( ) ;
123+ const dispatch = useDispatch ( ) ;
124+ const [ open , setOpen ] = React . useState ( false ) ;
125+ const handleOpen = ( ) => {
126+ setOpen ( true ) ;
127+ } ;
128+
129+ const handleClose = ( ) => {
130+ setOpen ( false ) ;
131+ } ;
132+ return (
133+ < SpeedDial
134+ ariaLabel = 'SpeedDial openIcon example'
135+ className = { classes . speedDial }
136+ icon = { < SpeedDialIcon openIcon = { < EditIcon /> } /> }
137+ onClose = { handleClose }
138+ onOpen = { handleOpen }
139+ open = { open }
140+ direction = { layout . type === 'HorizontalLayout' ? 'down' : 'right' }
141+ >
142+ { paletteService
143+ . getPaletteElements ( )
144+ . map ( ( { type, label, icon, uiSchemaElementProvider } ) => (
145+ < SpeedDialAction
146+ key = { type }
147+ color = 'primary'
148+ icon = { icon as any }
149+ tooltipTitle = { label }
150+ onClick = { ( ) => {
151+ dispatch (
152+ Actions . addUnscopedElementToLayout (
153+ uiSchemaElementProvider ( ) ,
154+ layout . uuid ,
155+ index
156+ )
157+ ) ;
158+ handleClose ( ) ;
159+ } }
160+ />
161+ ) ) }
162+ </ SpeedDial >
163+ ) ;
164+ } ;
165+
106166interface DropPointProps {
107167 layout : EditorLayout ;
108168 index : number ;
@@ -116,10 +176,16 @@ const useDropPointStyles = makeStyles((theme) => ({
116176 : 'none' ,
117177 backgroundSize : 'calc(10 * 1px) calc(10 * 1px)' ,
118178 backgroundClip : 'content-box' ,
119- minWidth : '2em ' ,
120- minHeight : props . isOver ? '8em' : '2em ' ,
121- maxWidth : props . fillWidth || props . isOver ? 'inherit' : '2em ' ,
179+ minWidth : '3em ' ,
180+ minHeight : props . isOver ? '8em' : '3em ' ,
181+ maxWidth : props . fillWidth ? 'inherit' : '3em ' ,
122182 } ) ,
183+ actions : {
184+ opacity : 0 ,
185+ '&:hover' : {
186+ opacity : 1 ,
187+ } ,
188+ } ,
123189} ) ) ;
124190
125191const DropPoint : React . FC < DropPointProps > = ( { layout, index } ) => {
@@ -195,8 +261,13 @@ const DropPoint: React.FC<DropPointProps> = ({ layout, index }) => {
195261 ref = { drop }
196262 className = { classes . dropPointGridItem }
197263 data-cy = { `${ getDataPath ( layout ) } -drop-${ index } ` }
264+ alignItems = 'stretch'
198265 xs
199- > </ Grid >
266+ >
267+ < Grid className = { classes . actions } item xs >
268+ < InlineActionBar layout = { layout } index = { index } />
269+ </ Grid >
270+ </ Grid >
200271 ) ;
201272} ;
202273
0 commit comments