-
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.
* Save working in the preview view, but not updating the UI yet * Update notion of a "prompt part" to include {prompt, children} * In-progress * Add output document to the mock form * - PDF field mappings - working on drag/drop for preview page * Make FormElementValue a generic that takes FormElement as a parameter * Support grouping in the PDF import, and remove redundant input text attributes. * Linting * Fieldset legends * Add PDF field mapping for the AL form, to map the PDFLib fields to the extracted data
- Loading branch information
1 parent
b0a85af
commit 96d315d
Showing
40 changed files
with
891 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../packages/design/static/uswds |
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
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
128 changes: 128 additions & 0 deletions
128
packages/design/src/FormManager/FormEdit/DraggableList.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,128 @@ | ||
import React, { Children, useState } from 'react'; | ||
import { | ||
DndContext, | ||
closestCenter, | ||
KeyboardSensor, | ||
PointerSensor, | ||
useSensor, | ||
useSensors, | ||
} from '@dnd-kit/core'; | ||
import { | ||
arrayMove, | ||
SortableContext, | ||
sortableKeyboardCoordinates, | ||
useSortable, | ||
verticalListSortingStrategy, | ||
} from '@dnd-kit/sortable'; | ||
import { CSS } from '@dnd-kit/utilities'; | ||
|
||
import { | ||
getFormElement, | ||
type FormDefinition, | ||
type FormElement, | ||
FormElementId, | ||
} from '@atj/forms'; | ||
|
||
import { SequenceElement } from '@atj/forms/src/config/elements/sequence'; | ||
|
||
const SortableItem = ({ | ||
id, | ||
children, | ||
}: { | ||
id: string; | ||
children: React.ReactNode; | ||
}) => { | ||
const { attributes, listeners, setNodeRef, transform, transition } = | ||
useSortable({ id }); | ||
|
||
const style = { | ||
transform: CSS.Transform.toString(transform), | ||
transition, | ||
}; | ||
|
||
return ( | ||
<li ref={setNodeRef} style={style}> | ||
<div className="editFieldsRowWrapper grid-row grid-gap"> | ||
<div | ||
className="editPageGrabButtonWrapper grid-col-1 grid-col" | ||
{...listeners} | ||
{...attributes} | ||
style={{ cursor: 'grab' }} | ||
> | ||
<span className="grabber1">:::</span> | ||
<span className="grabber2">:::</span> | ||
</div> | ||
<div className="editFieldsWrapper grid-col-11 grid-col">{children}</div> | ||
</div> | ||
</li> | ||
); | ||
}; | ||
|
||
type DraggableListProps = React.PropsWithChildren<{ | ||
element: FormElement<SequenceElement>; | ||
form: FormDefinition; | ||
setSelectedElement: (element: FormElement) => void; | ||
}>; | ||
export const DraggableList: React.FC<DraggableListProps> = ({ | ||
element, | ||
form, | ||
setSelectedElement, | ||
children, | ||
}) => { | ||
const [elements, setElements] = useState<FormElement[]>( | ||
element.data.elements.map((elementId: FormElementId) => { | ||
return getFormElement(form, elementId); | ||
}) | ||
); | ||
const sensors = useSensors( | ||
useSensor(PointerSensor), | ||
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }) | ||
); | ||
|
||
const arrayChildren = Children.toArray(children); | ||
return ( | ||
<DndContext | ||
sensors={sensors} | ||
collisionDetection={closestCenter} | ||
onDragEnd={event => { | ||
const { active, over } = event; | ||
if (over === null) { | ||
return; | ||
} | ||
if (active.id !== over.id) { | ||
const oldIndex = elements.findIndex(element => { | ||
return element.id === active.id; | ||
}); | ||
const newIndex = elements.findIndex(element => { | ||
return element.id === over.id; | ||
}); | ||
const newOrder = arrayMove(elements, oldIndex, newIndex); | ||
setElements(newOrder); | ||
setSelectedElement({ | ||
id: element.id, | ||
type: element.type, | ||
data: { | ||
elements: newOrder.map(element => element.id), | ||
}, | ||
default: { | ||
elements: [], | ||
}, | ||
required: element.required, | ||
} satisfies SequenceElement); | ||
} | ||
}} | ||
> | ||
<SortableContext items={elements} strategy={verticalListSortingStrategy}> | ||
<ul className="editFormWrapper"> | ||
{arrayChildren.map((child, index) => ( | ||
<SortableItem key={index} id={elements[index].id}> | ||
{child} | ||
</SortableItem> | ||
))} | ||
</ul> | ||
</SortableContext> | ||
</DndContext> | ||
); | ||
}; | ||
|
||
export default DraggableList; |
Oops, something went wrong.