generated from graasp/graasp-app-starter-ts-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
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
16 changed files
with
603 additions
and
25 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
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
29 changes: 29 additions & 0 deletions
29
src/modules/builder/configuration/AddLabelsStep/imageDimensionContext.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,29 @@ | ||
import React, { createContext, useContext, useMemo, useRef } from 'react'; | ||
|
||
const ImageDimensionsContext = createContext<ImageDimensionContextType>({ | ||
imgRef: null, | ||
}); | ||
|
||
type Props = { | ||
children: JSX.Element; | ||
}; | ||
|
||
type ImageDimensionContextType = { | ||
imgRef: React.MutableRefObject<HTMLImageElement | null> | null; | ||
}; | ||
export const ImageDimensionsProvider = ({ children }: Props): JSX.Element => { | ||
const imgRef = useRef<HTMLImageElement | null>(null); | ||
const value: ImageDimensionContextType = useMemo( | ||
() => ({ imgRef }), | ||
[imgRef], | ||
); | ||
|
||
return ( | ||
<ImageDimensionsContext.Provider value={value}> | ||
{children} | ||
</ImageDimensionsContext.Provider> | ||
); | ||
}; | ||
|
||
export const useImageDimensionsContext = (): ImageDimensionContextType => | ||
useContext<ImageDimensionContextType>(ImageDimensionsContext); |
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
src/modules/builder/configuration/PreviewStep/DraggableFrameWithLabels.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,60 @@ | ||
import React from 'react'; | ||
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch'; | ||
|
||
import { Box } from '@mui/material'; | ||
|
||
import { DraggableLabel } from '@/@types'; | ||
|
||
import ImageFrame from './ImageFrame'; | ||
import LabelPin, { GroupContainer } from './LabelPin'; | ||
|
||
type Props = { | ||
isDragging?: boolean; | ||
labels: DraggableLabel[]; | ||
imageSettingId: string; | ||
}; | ||
|
||
const DraggableFrameWithLabels = ({ | ||
isDragging, | ||
labels, | ||
imageSettingId, | ||
}: Props): JSX.Element => { | ||
const renderDraggableLabels = (): JSX.Element | JSX.Element[] => { | ||
const Labels = labels.map((label) => ( | ||
<GroupContainer key={label.ind} top={label.y} left={label.x}> | ||
<LabelPin label={label} /> | ||
</GroupContainer> | ||
)); | ||
|
||
return Labels; | ||
}; | ||
|
||
return ( | ||
<Box sx={{ position: 'relative' }}> | ||
<TransformWrapper | ||
initialScale={1} | ||
panning={{ disabled: isDragging }} | ||
pinch={{ disabled: isDragging }} | ||
wheel={{ disabled: isDragging }} | ||
zoomAnimation={{ disabled: isDragging }} | ||
alignmentAnimation={{ disabled: isDragging }} | ||
velocityAnimation={{ disabled: isDragging }} | ||
> | ||
<TransformComponent | ||
contentStyle={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<ImageFrame appSettingId={imageSettingId} /> | ||
{renderDraggableLabels()} | ||
</TransformComponent> | ||
</TransformWrapper> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default DraggableFrameWithLabels; |
31 changes: 31 additions & 0 deletions
31
src/modules/builder/configuration/PreviewStep/ImageFrame.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,31 @@ | ||
import { hooks } from '@/config/queryClient'; | ||
|
||
type Props = { | ||
appSettingId: string; | ||
}; | ||
|
||
const ImageFrame = ({ appSettingId }: Props): JSX.Element | null => { | ||
const { data: dataFile } = hooks.useAppSettingFile({ | ||
appSettingId, | ||
}); | ||
|
||
return dataFile ? ( | ||
<img | ||
src={URL.createObjectURL(dataFile)} | ||
alt="frame" | ||
className="image-lina" | ||
style={{ | ||
maxWidth: '100%', | ||
maxHeight: '100%', | ||
objectFit: 'cover', | ||
pointerEvents: 'auto', | ||
cursor: 'cell', | ||
// position: 'absolute', | ||
// top: '0px', | ||
// left: '0px', | ||
}} | ||
/> | ||
) : null; | ||
}; | ||
|
||
export default ImageFrame; |
87 changes: 87 additions & 0 deletions
87
src/modules/builder/configuration/PreviewStep/LabelPin.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,87 @@ | ||
import React from 'react'; | ||
import { Draggable, Droppable } from 'react-beautiful-dnd'; | ||
|
||
import { Box, styled } from '@mui/material'; | ||
|
||
import { DraggableLabel } from '@/@types'; | ||
|
||
export const Label = styled('div')<{ isDraggable: boolean }>( | ||
({ theme, isDraggable }) => ({ | ||
background: 'red', | ||
color: 'white', | ||
borderRadius: theme.spacing(1), | ||
userSelect: 'none', | ||
padding: theme.spacing(0.5), | ||
...(isDraggable && { | ||
left: 'auto !important', | ||
top: 'auto !important', | ||
}), | ||
}), | ||
); | ||
|
||
export const GroupContainer = styled(Box)<{ | ||
top: string; | ||
left: string; | ||
}>(({ theme, top, left }) => ({ | ||
borderRadius: theme.spacing(1), | ||
background: 'white', | ||
position: 'absolute', | ||
top, | ||
left, | ||
display: 'flex', | ||
gap: theme.spacing(1), | ||
border: '1px solid white', | ||
borderColor: 'black', | ||
minHeight: '4ch', | ||
minWidth: '8ch', | ||
})); | ||
|
||
type Props = { | ||
label: DraggableLabel; | ||
draggingOverItem?: boolean; | ||
}; | ||
|
||
const LabelPin = ({ label }: Props): JSX.Element => ( | ||
<Droppable | ||
droppableId={`${label.ind}`} | ||
// isDropDisabled={!draggingOverItem} | ||
> | ||
{(provided) => ( | ||
<div | ||
ref={provided.innerRef} | ||
{...provided.droppableProps} | ||
style={{ background: 'green', display: 'flex' }} | ||
> | ||
{label.choices?.map((item, index) => ( | ||
<Draggable | ||
key={item?.id} | ||
draggableId={item?.id} | ||
index={index} | ||
// isDragDisabled={!draggingOverItem} | ||
> | ||
{(dragProvided, dragSnapshot) => ( | ||
<Label | ||
ref={dragProvided.innerRef} | ||
{...dragProvided.draggableProps} | ||
{...dragProvided.dragHandleProps} | ||
isDraggable={dragSnapshot.isDragging} | ||
> | ||
<Box | ||
display="flex" | ||
sx={{ | ||
position: 'relative', | ||
}} | ||
> | ||
{item.content} | ||
</Box> | ||
</Label> | ||
)} | ||
</Draggable> | ||
))} | ||
{provided.placeholder} | ||
</div> | ||
)} | ||
</Droppable> | ||
); | ||
|
||
export default LabelPin; |
Oops, something went wrong.