Skip to content

Commit

Permalink
Render help for show advanced switch
Browse files Browse the repository at this point in the history
  • Loading branch information
holubv committed Mar 17, 2021
1 parent fedcda3 commit f2c664d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/components/HelpIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const HelpIcon = (props) => {
);

return (
<OverlayTrigger placement="right" overlay={tooltip}>
<span className={props.iconClassContainer} style={{ position: 'absolute' }}>
<OverlayTrigger placement={props.overlayPlacement} overlay={tooltip}>
<span className={props.iconClassContainer} style={{ position: props.absolutePosition ? 'absolute' : null }}>
<QuestionCircle className={props.iconClass} />
</span>
</OverlayTrigger>
Expand All @@ -22,12 +22,16 @@ const HelpIcon = (props) => {
HelpIcon.propTypes = {
text: PropTypes.string.isRequired,
iconClassContainer: PropTypes.string,
iconClass: PropTypes.string
iconClass: PropTypes.string,
overlayPlacement: PropTypes.string,
absolutePosition: PropTypes.bool,
};

HelpIcon.defaultProps = {
iconClassContainer: '',
iconClass: ''
iconClass: '',
overlayPlacement: 'right',
absolutePosition: true
};

export default HelpIcon;
40 changes: 31 additions & 9 deletions src/components/QuestionWithAdvanced.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Question from './Question';
import classNames from 'classnames';
import { ConfigurationContext } from '../contexts/ConfigurationContext';
import JsonldUtils from 'jsonld-utils';
import HelpIcon from './HelpIcon';

export default class QuestionWithAdvanced extends Question {

Expand Down Expand Up @@ -76,6 +77,23 @@ export default class QuestionWithAdvanced extends Question {
this._onChange(Constants.HAS_SUBQUESTION, index, question);
};

_renderShowAdvancedHelp() {
const { question } = this._getShowAdvancedQuestion();

if (question[Constants.HELP_DESCRIPTION]) {
return (
<HelpIcon
absolutePosition={false}
overlayPlacement="left"
text={JsonLdUtils.getLocalized(question[Constants.HELP_DESCRIPTION], this.context.options.intl)}
iconClassContainer="help-icon-section"
/>
);
}

return null;
}

render() {
const question = this.props.question;

Expand Down Expand Up @@ -116,16 +134,20 @@ export default class QuestionWithAdvanced extends Question {
{label}
</h6>

<Form.Switch
onChange={this._toggleAdvanced}
id={'--switch-' + showAdvancedQuestion['@id']}
label={advancedQuestionLabel}
checked={this.state.showAdvanced}
inline
style={{float: 'right'}}
/>

{this._renderQuestionHelp()}

<div style={{float: 'right'}}>
<Form.Switch
onChange={this._toggleAdvanced}
id={'--switch-' + showAdvancedQuestion['@id']}
label={advancedQuestionLabel}
checked={this.state.showAdvanced}
inline
/>

{this._renderShowAdvancedHelp()}
</div>

</Accordion.Toggle>
{collapsible ? <Accordion.Collapse>{cardBody}</Accordion.Collapse> : { cardBody }}

Expand Down

0 comments on commit f2c664d

Please sign in to comment.