Skip to content
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

Fix: Allow slide step prefix and suffix (fixes #173) #182

Merged
merged 7 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ guide the learner’s interaction with the component.

**\_scaleStep** (number): Defines the amount the scale should be incremented by.

**scaleStepPrefix** (string): Prefix to add to each slider step. For example, a "$" can be used as a prefix to indicate currency in dollars (ex. $100).

**scaleStepSuffix** (string): Suffix to add to each slider step. For example, a "V" can be used as a suffix to indicate voltage (ex. 4V).

**\_correctAnswer** (string): Used to set a single value on the slider scale as the correct answer. (Since the attribute expects a string, numeric values must appear in JSON within quotes.)

**\_correctRange** (object): Used to set a range of values on the slider scale as the correct answer. The range is determined by **\_bottom** and **\_top**.
Expand Down
2 changes: 2 additions & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"_scaleStart": 1,
"_scaleEnd": 10,
"_scaleStep": 1,
"scaleStepPrefix": "",
"scaleStepSuffix": "",
"_correctAnswer": "",
"_correctRange": {
"_bottom": 4,
Expand Down
20 changes: 20 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@
"validators": ["number"],
"help": "The amount the scale should increment by"
},
"scaleStepPrefix": {
"type": "string",
"required": false,
"default": "",
"title": "Prefix to add to each slider step",
"inputType": "Text",
"validators": [],
"help": "For instance, a '$' can be used as a prefix to indicate currency in dollars (ex. $100)",
"translatable": true
},
"scaleStepSuffix": {
"type": "string",
"required": false,
"default": "",
"title": "Suffix to add to each slider step",
"inputType": "Text",
"validators": [],
"help": "For instance, a 'V' can be used as a suffix to indicate voltage (ex. 4V)",
"translatable": true
},
"_correctAnswer": {
"type": "string",
"default": "",
Expand Down
20 changes: 20 additions & 0 deletions schema/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@
"description": "The amount the scale should increment by",
"default": 1
},
"scaleStepPrefix": {
"type": "string",
"title": "Prefix to add to each slider step",
"description": "For instance, a '$' can be used as a prefix to indicate currency in dollars (ex. $100)",
"default": "",
"properties": {},
"_adapt": {
"translatable": true
}
},
"scaleStepSuffix": {
"type": "string",
"title": "Suffix to add to each slider step",
"description": "For instance, a 'V' can be used as a suffix to indicate voltage (ex. 4V)",
"default": "",
"properties": {},
"_adapt": {
"translatable": true
}
},
"_correctAnswer": {
"type": "string",
"title": "Correct answer",
Expand Down
18 changes: 12 additions & 6 deletions templates/slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function Slider (props) {
_showScale,
_showNumber,
_showScaleNumbers,
_showScaleIndicator
_showScaleIndicator,
scaleStepPrefix,
scaleStepSuffix
} = props;

const sliderScaleRef = useRef(null);
Expand Down Expand Up @@ -101,7 +103,7 @@ export default function Slider (props) {
{labelStart &&
<div className="slider__label-start">
<div className="slider__label-start-inner">
<span className="aria-label">{_globals._components._slider.labelStart} {_scaleStart}</span>
<span className="aria-label">{_globals._components._slider.labelStart} {scaleStepPrefix}{_scaleStart}{scaleStepSuffix}</span>
{labelStart}
</div>
</div>
Expand All @@ -110,7 +112,7 @@ export default function Slider (props) {
{labelEnd &&
<div className="slider__label-end">
<div className="slider__label-end-inner">
<span className="aria-label">{_globals._components._slider.labelEnd} {_scaleEnd}</span>
<span className="aria-label">{_globals._components._slider.labelEnd} {scaleStepPrefix}{_scaleEnd}{scaleStepSuffix}</span>
{labelEnd}
</div>
</div>
Expand All @@ -134,7 +136,7 @@ export default function Slider (props) {
style={{ left: Math.round(normalisedPosition * sliderScaleWidth) }}
onClick={onNumberSelected}
>
{value}
{scaleStepPrefix}{value}{scaleStepSuffix}
</div>
);
})
Expand All @@ -150,7 +152,9 @@ export default function Slider (props) {
key={correctAnswer}
style={{ left: `${mapIndexToPixels(getIndexFromValue(correctAnswer))}px` }}
>
{_showNumber && correctAnswer}
{_showNumber &&
`${scaleStepPrefix}${correctAnswer}${scaleStepSuffix}`
}
</div>
);
})
Expand All @@ -166,7 +170,9 @@ export default function Slider (props) {
tabIndex="-1"
ref={sliderNumberSelectionRef}
>
{_showNumber && _selectedItem.value}
{_showNumber &&
`${scaleStepPrefix}${_selectedItem.value}${scaleStepSuffix}`
}
</div>
}
</div>
Expand Down