Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/image-cloze-association/src/possible-response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ const StyledSpan = styled(StaticHTMLSpan)(() => ({
},
}));

const PossibleResponse = ({ canDrag, containerStyle, data, onDragBegin, answerChoiceTransparency }) => {
const PossibleResponse = ({ canDrag, containerStyle, data, onDragBegin, answerChoiceTransparency, isOverlay }) => {
const rootRef = useRef(null);
const longPressTimer = useRef(null);

const { setNodeRef, attributes, listeners } = useDraggable({
const { setNodeRef, attributes, listeners, isDragging } = useDraggable({
id: `possible-response-${data.id}`,
data: {
id: data.id,
Expand Down Expand Up @@ -110,9 +110,9 @@ const PossibleResponse = ({ canDrag, containerStyle, data, onDragBegin, answerCh
const containsImage = imgRegex.test(data.value);

const containerClassNames = classNames({
answerChoiceTransparency,
answerChoiceTransparency: answerChoiceTransparency && !isDragging,
[correctnessClass]: !!correctnessClass,
textAnswerChoiceStyle: !containsImage,
textAnswerChoiceStyle: !containsImage && !isOverlay,
});

const promptClassNames = classNames({ hiddenSpan: data.hidden });
Expand Down Expand Up @@ -140,11 +140,13 @@ PossibleResponse.propTypes = {
data: PropTypes.object.isRequired,
onDragBegin: PropTypes.func.isRequired,
answerChoiceTransparency: PropTypes.bool,
isOverlay: PropTypes.bool,
};

PossibleResponse.defaultProps = {
containerStyle: {},
answerChoiceTransparency: false,
isOverlay: false,
};

export default PossibleResponse;
27 changes: 16 additions & 11 deletions packages/image-cloze-association/src/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,23 @@ export class ImageClozeAssociationComponent extends React.Component {

if (!draggingElement.id) return null;

if (draggingElement.id) {
return (
<PossibleResponse
key={draggingElement.id}
data={draggingElement}
answerChoiceTransparency={model.answerChoiceTransparency}
containerStyle={{ margin: '4px' }}
/>
);
}
// check if the response contains an image
const imgRegex = /<img[^>]+src="([^">]+)"/;
const containsImage = imgRegex.test(draggingElement.value);

return null;
return (
<PossibleResponse
key={draggingElement.id}
canDrag={false}
data={draggingElement}
onDragBegin={() => {}}
isOverlay
containerStyle={{
...(model.answerChoiceTransparency ? { opacity: '0.8' } : {}),
...(!containsImage ? { padding: '0 10px', margin: '4px 6px !important' } : {}),
}}
/>
);
};

filterPossibleAnswers = (possibleResponses, answer) =>
Expand Down
Loading