Skip to content

Commit

Permalink
feat: add ellipsis and decrease title (#108)
Browse files Browse the repository at this point in the history
* feat: first implementation for TextInput

* feat: get latest user's answer instead of first

* test: implement E2E tests of play text with multiple attempts

* feat: update PlayFillInTheBlanks to allow multiple attempts

* test: update play fillBlanks test to test multiple attempts

* feat: translate the number of attempts

* fix: update analytics and results for multiple attempts

* feat: do not display explanations of multiple choice until the end of the attempts

* feat: resize the question size and add ellipsis for TopBar question names

* feat: use const to configure max lines

* feat: increase the max number of lines

* fix: update the utilities file to remove duplicate functions

* chore: use component and variant for the Typography of the question's title
  • Loading branch information
ReidyT authored Jan 16, 2024
1 parent 526da9b commit 0df2adf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/play/textInput.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TextAppDataData } from '../../../src/components/types/types';
import { APP_SETTING_NAMES, QuestionType } from '../../../src/config/constants';
import {
PLAY_VIEW_QUESTION_TITLE_CY,
PLAY_VIEW_SUBMIT_BUTTON_CY, // PLAY_VIEW_TEXT_INPUT_CY,
PLAY_VIEW_SUBMIT_BUTTON_CY,
buildPlayViewTextInputCy,
buildQuestionStepCy,
dataCyWrapper,
Expand Down
31 changes: 31 additions & 0 deletions src/components/common/TypographyMaxLines.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ReactNode } from 'react';

import { Typography, TypographyProps } from '@mui/material';

type Props = TypographyProps & {
maxLines: number;
children?: ReactNode;
};

export const TypographyMaxLines = ({
maxLines,
children,
...typographyProps
}: Props) => {
return (
<Typography
{...typographyProps}
sx={{
...typographyProps.sx,
display: '-webkit-box',
overflow: 'hidden',
WebkitBoxOrient: 'vertical',
WebkitLineClamp: maxLines,
}}
>
{children}
</Typography>
);
};

export default TypographyMaxLines;
7 changes: 6 additions & 1 deletion src/components/create/CreateQuestionTopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import {
Stepper,
} from '@mui/material';

import { MAX_QUESTION_LINES_TOP_BAR } from '../../config/constants';
import {
QUESTION_BAR_CY,
QUESTION_BAR_NEXT_CY,
QUESTION_BAR_PREV_CY,
QUESTION_STEP_CLASSNAME,
buildQuestionStepCy,
} from '../../config/selectors';
import TypographyMaxLines from '../common/TypographyMaxLines';
import { QuizContext } from '../context/QuizContext';
import { getQuestionById } from '../context/utilities';
import PlusStep from '../navigation/PlusStep';
Expand Down Expand Up @@ -81,7 +83,9 @@ const CreateQuestionTopBar = () => {
{...provided.draggableProps}
{...props}
>
{question.data.question}
<TypographyMaxLines maxLines={MAX_QUESTION_LINES_TOP_BAR}>
{question.data.question}
</TypographyMaxLines>
</StepLabel>
);
};
Expand All @@ -107,6 +111,7 @@ const CreateQuestionTopBar = () => {
direction="row"
alignItems="flex-start"
justifyContent="center"
mb={3}
>
<Grid item>
<Button
Expand Down
1 change: 0 additions & 1 deletion src/components/create/NumberOfAttempts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const NumberOfAttempts = ({ initAttempts, onChange }: Props) => {
const { t } = useTranslation();
const MIN_ATTEMPTS = 1;
const UNSET_NUMBER = 0;

const attemptsLabel = t(QUIZ_TRANSLATIONS.CREATE_VIEW_NUMBER_OF_ATTEMPTS);
const [attempts, setAttempts] = useState<number>(MIN_ATTEMPTS);

Expand Down
6 changes: 5 additions & 1 deletion src/components/navigation/QuestionTopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { useLocalContext } from '@graasp/apps-query-client';
import { Context } from '@graasp/sdk';

import { MAX_QUESTION_LINES_TOP_BAR } from '../../config/constants';
import { hooks } from '../../config/queryClient';
import {
QUESTION_BAR_CY,
Expand All @@ -24,6 +25,7 @@ import {
QUESTION_STEP_CLASSNAME,
buildQuestionStepCy,
} from '../../config/selectors';
import TypographyMaxLines from '../common/TypographyMaxLines';
import { QuizContext } from '../context/QuizContext';
import {
computeCorrectness,
Expand Down Expand Up @@ -90,7 +92,9 @@ const QuestionTopBar = () => {
onClick={() => setCurrentIdx(index)}
{...props}
>
{question.data.question}
<TypographyMaxLines maxLines={MAX_QUESTION_LINES_TOP_BAR}>
{question.data.question}
</TypographyMaxLines>
</StepLabel>
);
};
Expand Down
8 changes: 6 additions & 2 deletions src/components/play/PlayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ const PlayView = () => {
</Grid>
<Grid item>
<Typography
variant="h4"
sx={{ pb: 2 }}
component="h1"
variant="h5"
sx={{
pb: 2,
}}
data-cy={PLAY_VIEW_QUESTION_TITLE_CY}
textAlign="center"
>
{currentQuestion.data.question}
</Typography>
Expand Down
1 change: 1 addition & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ export const FILL_BLANKS_PLACEHOLDER_TEXT =
export const AUTO_SCROLLABLE_HOVER_COLOR = '#878383';

export const CHART_SECONDARY_COLOR = '#d95557';
export const MAX_QUESTION_LINES_TOP_BAR = 3;

0 comments on commit 0df2adf

Please sign in to comment.