-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
36,278 additions
and
108 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import _uniqueId from 'lodash/uniqueId'; | ||
import InlineForm from '@plone/volto/components/manage/Form/InlineForm'; | ||
import { SidebarPortal } from '@plone/volto/components'; | ||
import View from './ViewEdit'; | ||
import config from '@plone/volto/registry'; | ||
import { makeSchema } from './schema'; | ||
|
||
const Edit = (props) => { | ||
const [state, setState] = useState({ | ||
schema: makeSchema({ ...props, providerUrl: config.settings.providerUrl }), | ||
id: _uniqueId('block_'), | ||
}); | ||
useEffect(() => { | ||
setState({ | ||
...state, | ||
schema: makeSchema({ | ||
...props, | ||
}), | ||
}); | ||
/* eslint-disable-next-line */ | ||
}, [props.data.isExpandable]); | ||
return ( | ||
<div> | ||
<SidebarPortal selected={props.selected}> | ||
<InlineForm | ||
schema={state.schema} | ||
title={state.schema.title} | ||
onChangeField={(field, data) => { | ||
props.onChangeBlock(props.block, { | ||
...(props.data || {}), | ||
[field]: data, | ||
}); | ||
}} | ||
formData={props.data || {}} | ||
block={props.block} | ||
/> | ||
</SidebarPortal> | ||
<View {...props} id={state.id} mode="edit" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
pathname: state.router.location.pathname, | ||
})), | ||
)(Edit); |
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,73 @@ | ||
/* REACT */ | ||
import React, { useState } from 'react'; | ||
import { compose } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import { Icon } from '@plone/volto/components'; | ||
import DOMPurify from 'dompurify'; | ||
import move from 'lodash-move'; | ||
import cx from 'classnames'; | ||
import dragSVG from '@plone/volto/icons/drag.svg'; | ||
import './style.css'; | ||
const View = ({ content, ...props }) => { | ||
const [state, setState] = useState({ | ||
activeItem: '', | ||
}); | ||
const isExpandable = props.data?.isExpandable; | ||
const listItemTitleClassname = props.data?.listItemTitleClassname; | ||
const listItemDescriptionClassname = props.data?.listItemDescriptionClassname; | ||
const listClassname = props.data?.listClassname; | ||
const items = props.data?.items || []; | ||
const ordered = props.data?.ordered; | ||
|
||
return ( | ||
<div className={cx('expandable-list', listClassname)}> | ||
{props.mode === 'edit' && !items.length ? <p>Expandable list</p> : ''} | ||
{items | ||
? Object.entries(items).map(([key, value], index) => ( | ||
<div className="list-item" key={`list-item-${key}`}> | ||
<button | ||
className={cx( | ||
'list-item-title', | ||
listItemTitleClassname ? listItemTitleClassname : '', | ||
isExpandable ? 'expandable' : 'no-expandable', | ||
)} | ||
onClick={() => { | ||
if (isExpandable && state.activeItem === key) { | ||
setState({ ...state, activeItem: '' }); | ||
} else if (isExpandable) { | ||
setState({ ...state, activeItem: key }); | ||
} | ||
}} | ||
> | ||
<span className="count">{ordered ? `${index + 1}. ` : ''}</span> | ||
<span>{value.title}</span> | ||
</button> | ||
<div | ||
className={cx( | ||
'list-item-description', | ||
listItemDescriptionClassname | ||
? listItemDescriptionClassname | ||
: '', | ||
isExpandable | ||
? state.activeItem === key | ||
? 'show' | ||
: 'hide' | ||
: '', | ||
)} | ||
dangerouslySetInnerHTML={{ | ||
__html: DOMPurify.sanitize(value.description), | ||
}} | ||
/> | ||
</div> | ||
)) | ||
: ''} | ||
</div> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
content: | ||
state.prefetch?.[state.router.location.pathname] || state.content.data, | ||
})), | ||
)(View); |
133 changes: 133 additions & 0 deletions
133
src/components/manage/Blocks/ExpendableList/ViewEdit.jsx
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,133 @@ | ||
/* REACT */ | ||
import React, { useState } from 'react'; | ||
import { compose } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import { Icon } from '@plone/volto/components'; | ||
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd'; | ||
import DOMPurify from 'dompurify'; | ||
import move from 'lodash-move'; | ||
import cx from 'classnames'; | ||
import dragSVG from '@plone/volto/icons/drag.svg'; | ||
import './style.css'; | ||
const View = ({ content, ...props }) => { | ||
const [state, setState] = useState({ | ||
activeItem: '', | ||
}); | ||
const isExpandable = props.data?.isExpandable; | ||
const listItemTitleClassname = props.data?.listItemTitleClassname; | ||
const listItemDescriptionClassname = props.data?.listItemDescriptionClassname; | ||
const listClassname = props.data?.listClassname; | ||
const items = props.data?.items || []; | ||
const ordered = props.data?.ordered; | ||
|
||
const onDragEnd = (result) => { | ||
const { source, destination } = result; | ||
if (!destination) { | ||
return; | ||
} | ||
if (source.droppableId === destination.droppableId) { | ||
props.onChangeBlock(props.block, { | ||
...props.data, | ||
items: move(props.data.items, source.index, destination.index), | ||
}); | ||
} else { | ||
// WIP | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={cx('expandable-list', listClassname)}> | ||
{props.mode === 'edit' && !items.length ? <p>Expandable list</p> : ''} | ||
{items ? ( | ||
<DragDropContext onDragEnd={onDragEnd}> | ||
<Droppable droppableId="list-item"> | ||
{(providedDroppable) => ( | ||
<> | ||
<div ref={providedDroppable.innerRef}> | ||
{Object.entries(items).map(([key, value], index) => ( | ||
<Draggable key={key} draggableId={key} index={index}> | ||
{(providedItem) => ( | ||
<div | ||
ref={providedItem.innerRef} | ||
{...providedItem.draggableProps} | ||
> | ||
<div | ||
style={{ | ||
position: 'relative', | ||
height: '100%', | ||
}} | ||
> | ||
<div | ||
style={{ | ||
visibility: 'visible', | ||
display: 'inline-block', | ||
}} | ||
{...providedItem.dragHandleProps} | ||
className="drag handle wrapper" | ||
> | ||
<Icon name={dragSVG} size="18px" /> | ||
</div> | ||
<div className="list-item" key={`list-item-${key}`}> | ||
<button | ||
className={cx( | ||
'list-item-title', | ||
listItemTitleClassname | ||
? listItemTitleClassname | ||
: '', | ||
isExpandable ? 'expandable' : 'no-expandable', | ||
)} | ||
onClick={() => { | ||
if ( | ||
isExpandable && | ||
state.activeItem === key | ||
) { | ||
setState({ ...state, activeItem: '' }); | ||
} else if (isExpandable) { | ||
setState({ ...state, activeItem: key }); | ||
} | ||
}} | ||
> | ||
{ordered ? `${index + 1}. ` : ''} | ||
{value.title} | ||
</button> | ||
<div | ||
className={cx( | ||
'list-item-description', | ||
listItemDescriptionClassname | ||
? listItemDescriptionClassname | ||
: '', | ||
isExpandable | ||
? state.activeItem === key | ||
? 'show' | ||
: 'hide' | ||
: '', | ||
)} | ||
dangerouslySetInnerHTML={{ | ||
__html: DOMPurify.sanitize(value.description), | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</Draggable> | ||
))} | ||
</div> | ||
{providedDroppable.placeholder} | ||
</> | ||
)} | ||
</Droppable> | ||
</DragDropContext> | ||
) : ( | ||
'' | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
content: | ||
state.prefetch?.[state.router.location.pathname] || state.content.data, | ||
})), | ||
)(View); |
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,80 @@ | ||
const getListSchema = (props) => { | ||
return { | ||
title: 'List item', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['title', 'description'], | ||
}, | ||
], | ||
properties: { | ||
title: { | ||
title: 'Title', | ||
widget: 'text', | ||
}, | ||
description: { | ||
title: 'Description', | ||
widget: 'textarea', | ||
}, | ||
}, | ||
required: [], | ||
}; | ||
}; | ||
|
||
export const makeSchema = (props) => { | ||
return { | ||
title: props.schemaTitle || 'Title', | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: [], | ||
}, | ||
{ | ||
id: 'list-items', | ||
title: 'List items', | ||
fields: ['items'], | ||
}, | ||
{ | ||
id: 'settings', | ||
title: 'Settings', | ||
fields: [ | ||
'ordered', | ||
'isExpandable', | ||
'listClassname', | ||
'listItemTitleClassname', | ||
'listItemDescriptionClassname', | ||
], | ||
}, | ||
], | ||
properties: { | ||
items: { | ||
title: 'List items', | ||
widget: 'object_list', | ||
schema: getListSchema(), | ||
}, | ||
ordered: { | ||
title: 'Ordered', | ||
type: 'boolean', | ||
}, | ||
isExpandable: { | ||
title: 'Is expandable', | ||
type: 'boolean', | ||
}, | ||
listClassname: { | ||
title: 'List classname', | ||
type: 'text', | ||
}, | ||
listItemTitleClassname: { | ||
title: 'Title class name', | ||
type: 'text', | ||
}, | ||
listItemDescriptionClassname: { | ||
title: 'Description class name', | ||
type: 'text', | ||
}, | ||
}, | ||
required: [], | ||
}; | ||
}; |
Oops, something went wrong.