Skip to content

Commit

Permalink
Merge pull request #2348 from pie-framework/PD-3844
Browse files Browse the repository at this point in the history
feat(multiple-choice): add background color for selected choices PD-3844
  • Loading branch information
CarlaCostea authored Dec 20, 2024
2 parents 1bf85f1 + 2488fe1 commit bf2631f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ exports[`Main snapshot renders with choicePrefix="letters" as default 1`] = `
"rationale": "",
"rationaleEnabled": true,
"scoringType": "auto",
"selectedAnswerBackgroundColor": "initial",
"studentInstructionsEnabled": true,
"teacherInstructions": "",
"teacherInstructionsEnabled": true,
Expand Down Expand Up @@ -142,6 +143,7 @@ exports[`Main snapshot renders with choicePrefix="numbers" 1`] = `
"rationale": "",
"rationaleEnabled": true,
"scoringType": "auto",
"selectedAnswerBackgroundColor": "initial",
"studentInstructionsEnabled": true,
"teacherInstructions": "",
"teacherInstructionsEnabled": true,
Expand Down
1 change: 1 addition & 0 deletions packages/multiple-choice/configure/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
teacherInstructions: '',
teacherInstructionsEnabled: true,
toolbarEditorPosition: 'bottom',
selectedAnswerBackgroundColor: 'initial',
},
configuration: {
baseInputConfiguration: {
Expand Down
1 change: 1 addition & 0 deletions packages/multiple-choice/controller/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default {
teacherInstructions: '',
teacherInstructionsEnabled: true,
toolbarEditorPosition: 'bottom',
selectedAnswerBackgroundColor: 'initial',
};
1 change: 1 addition & 0 deletions packages/multiple-choice/controller/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export async function model(question, session, env, updateSession) {
extraCSSRules: normalizedQuestion.extraCSSRules,
fontSizeFactor: normalizedQuestion.fontSizeFactor,
isSelectionButtonBelow: normalizedQuestion.isSelectionButtonBelow,
selectedAnswerBackgroundColor: normalizedQuestion.selectedAnswerBackgroundColor || 'initial',
minSelections: normalizedQuestion.minSelections,
maxSelections: normalizedQuestion.maxSelections,
};
Expand Down
10 changes: 8 additions & 2 deletions packages/multiple-choice/src/choice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Choice extends React.Component {
choicesLayout,
gridColumns,
isSelectionButtonBelow,
selectedAnswerBackgroundColor
} = this.props;
const choiceClass = 'choice' + (index === choicesLength - 1 ? ' last' : '');

Expand All @@ -58,8 +59,10 @@ export class Choice extends React.Component {
[classes.horizontalLayout]: choicesLayout === 'horizontal',
});

const choiceBackground = selectedAnswerBackgroundColor && checked ? selectedAnswerBackgroundColor : 'initial';

return (
<div className={choiceClass} key={index}>
<div className={choiceClass} key={index} style={{ backgroundColor: choiceBackground }}>
<ChoiceInput {...choiceProps} className={names} />
</div>
);
Expand All @@ -81,13 +84,16 @@ Choice.propTypes = {
displayKey: PropTypes.string,
choicesLayout: PropTypes.oneOf(['vertical', 'grid', 'horizontal']),
gridColumns: PropTypes.string,
isSelectionButtonBelow: PropTypes.bool,
selectedAnswerBackgroundColor: PropTypes.string,
isSelectionButtonBelow: PropTypes.bool
};

export default withStyles((theme) => ({
choice: {
paddingTop: theme.spacing.unit * 2.5,
paddingBottom: theme.spacing.unit + 2,
paddingLeft: theme.spacing.unit + 2,
paddingRight: theme.spacing.unit + 2,
borderBottom: `1px solid ${theme.palette.grey[300]}`,
},
noBorder: {
Expand Down
2 changes: 2 additions & 0 deletions packages/multiple-choice/src/multiple-choice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class MultipleChoice extends React.Component {
alwaysShowCorrect: PropTypes.bool,
animationsDisabled: PropTypes.bool,
language: PropTypes.string,
selectedAnswerBackgroundColor: PropTypes.string,
onShowCorrectToggle: PropTypes.func,
isSelectionButtonBelow: PropTypes.bool,
minSelections: PropTypes.number,
Expand Down Expand Up @@ -308,6 +309,7 @@ export class MultipleChoice extends React.Component {
{choices.map((choice, index) => (
<StyledChoice
choicesLayout={this.props.choicesLayout}
selectedAnswerBackgroundColor={this.props.selectedAnswerBackgroundColor}
gridColumns={gridColumns}
key={`choice-${index}`}
choice={choice}
Expand Down
5 changes: 5 additions & 0 deletions packages/pie-models/src/pie/multiple-choice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export interface MultipleChoicePie extends PieModel {
*/
toolbarEditorPosition?: 'bottom' | 'top';

/** Indicates the background color for selected choices
* @default: 'initial'
*/
selectedAnswerBackgroundColor?: string;

/**
* Indicates the order of choices presented to user
* if true, answer choices will be presented in the order they are defined in the model
Expand Down

0 comments on commit bf2631f

Please sign in to comment.