-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overlay option added in exercise component and new component IncludeRemoveQuestion created #86
Merged
jomcarvajal
merged 5 commits into
preview-card
from
CORE-675-include-remove-question-component
Jan 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3b30e4
overlay option added in exercise component and new component includer…
jomcarvajal dbee6c6
resolve comments
jomcarvajal a3282e5
update snapshots
jomcarvajal 9155b76
move overlay logic into Card component
jomcarvajal d7bb31c
remove focus on card when overlay is up and add autoFocus for first i…
jomcarvajal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { ExerciseToolbar, StyledToolbar } from '../ExerciseToolbar'; | |
import { breakpoints } from '../../theme'; | ||
import { ExerciseHeaderIcons } from '../ExerciseHeaderIcons'; | ||
import { TypesetMathContext } from '../../hooks/useTypesetMath'; | ||
import { exerciseStyles } from './styles'; | ||
import { exerciseStyles, StyledOverlay } from './styles'; | ||
|
||
const StyledTaskStepCard = styled(TaskStepCard)` | ||
font-size: calc(1.8rem * var(--content-text-scale)); | ||
|
@@ -61,10 +61,10 @@ const TaskStepCardWithToolbar = (props: React.PropsWithChildren<TaskStepCardProp | |
mobileToolbarEnabled: boolean; | ||
} | ||
) => <ToolbarWrapper | ||
desktopToolbarEnabled={props.desktopToolbarEnabled} | ||
mobileToolbarEnabled={props.mobileToolbarEnabled} | ||
> | ||
<ExerciseToolbar icons={props.exerciseIcons} /> | ||
desktopToolbarEnabled={props.desktopToolbarEnabled} | ||
mobileToolbarEnabled={props.mobileToolbarEnabled} | ||
> | ||
<ExerciseToolbar icons={props.exerciseIcons} /> | ||
<StyledTaskStepCard {...props} /> | ||
</ToolbarWrapper>; | ||
|
||
|
@@ -159,13 +159,20 @@ export interface ExerciseWithQuestionStatesProps extends ExerciseBaseProps { | |
onAnswerChange: (answer: Omit<Answer, 'id'> & { id: number, question_id: number }) => void; | ||
} | ||
|
||
export interface OverlayProps { | ||
enableOverlay?: boolean; | ||
overlayChildren?: React.ReactNode; | ||
} | ||
|
||
export const Exercise = styled(({ | ||
numberOfQuestions, questionNumber, step, exercise, show_all_feedback, scrollToQuestion, exerciseIcons, ...props | ||
}: { className?: string } & (ExerciseWithStepDataProps | ExerciseWithQuestionStatesProps)) => { | ||
numberOfQuestions, questionNumber, step, exercise, show_all_feedback, scrollToQuestion, exerciseIcons, enableOverlay = false, overlayChildren, ...props | ||
jomcarvajal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}: { className?: string } & (ExerciseWithStepDataProps | ExerciseWithQuestionStatesProps) & OverlayProps) => { | ||
const legacyStepRender = 'feedback_html' in step; | ||
const questionsRef = React.useRef<Array<HTMLDivElement>>([]); | ||
const container = React.useRef<HTMLDivElement>(null); | ||
|
||
const [showOverlay, setShowOverlay] = React.useState<boolean>(false); | ||
|
||
const typesetExercise = React.useCallback(() => { | ||
if (container.current) { | ||
typesetMath(container.current); | ||
|
@@ -179,6 +186,12 @@ export const Exercise = styled(({ | |
} | ||
}, [scrollToQuestion, exercise]); | ||
|
||
const handleBlur = (event: React.FocusEvent<HTMLDivElement>) => { | ||
if (container.current && !container.current.contains(event.relatedTarget as Node)) { | ||
setShowOverlay(false); | ||
} | ||
}; | ||
|
||
const desktopToolbarEnabled = Object.values(exerciseIcons || {}).some(({ location }) => location?.toolbar?.desktop); | ||
const mobileToolbarEnabled = Object.values(exerciseIcons || {}).some(({ location }) => location?.toolbar?.mobile); | ||
|
||
|
@@ -195,15 +208,23 @@ export const Exercise = styled(({ | |
{...(exerciseIcons ? { exerciseIcons: exerciseIcons } : null)} | ||
className={props.className} | ||
> | ||
<div ref={container}> | ||
<div | ||
ref={container} | ||
jomcarvajal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tabIndex={enableOverlay ? 0 : -1} // This container is focusable only if enableOverlay is true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this cause any side effects for non-overlay exercises in screenreaders? I'm wondering if we should be more conservative and not set the attribute at all for normal use. |
||
{...(enableOverlay ? { onMouseOver: () => setShowOverlay(true), onMouseLeave: () => setShowOverlay(false), onFocus: () => setShowOverlay(true), onBlur: handleBlur} : {})} | ||
jomcarvajal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
{(enableOverlay && showOverlay) && | ||
<StyledOverlay> | ||
{overlayChildren} | ||
</StyledOverlay>} | ||
<Preamble exercise={exercise} /> | ||
|
||
{exercise.questions.map((q, i) => { | ||
const state = { ...(legacyStepRender ? step : props['questionStates'][q.id]) }; | ||
return ( | ||
<ExerciseQuestion | ||
{...props} | ||
{...{...state, available_points: undefined}} | ||
{...{ ...state, available_points: undefined }} | ||
ref={(el: HTMLDivElement) => questionsRef.current[questionNumber + i] = el} | ||
exercise_uid={exercise.uid} | ||
key={q.id} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This style was causing an error for lg display
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this should be fixed in #85