Skip to content

Commit

Permalink
uniformize Modal CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
BulotF committed Sep 20, 2023
1 parent f232033 commit e504692
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/constants/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,11 @@ const dictionary = {
en: 'Current questionnaire',
},
CollectedVariableType: {
fr: 'Collecté',
fr: 'Collectée',
en: 'Collected',
},
CalculatedVariableType: {
fr: 'Calculé',
fr: 'Calculée',
en: 'Calculated',
},
ExternalVariableType: {
Expand Down
38 changes: 10 additions & 28 deletions src/layout/generic-input/components/generic-input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,11 @@ export const defaultProps = {

// Components

export const customModalStyles = {
content: {
display: 'absolute',
textAlign: 'center',
verticAlalign: 'middle',
top: '40%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
width: '400px',
alignItems: 'center',
transform: 'translate(-50%, -50%)',
},
};
export const customLoopModalStyles = {
content: {
display: 'absolute',
textAlign: 'center',
verticAlalign: 'middle',
verticalAlign: 'middle',
top: '25%',
left: '50%',
right: 'auto',
Expand Down Expand Up @@ -153,13 +138,13 @@ function GenericInput(props) {
isOpen
ariaHideApp={false}
shouldCloseOnOverlayClick={false}
style={customModalStyles}
className="custom-modal"
>
<p>{Dictionary.modification}</p>
<button onClick={onCancel} style={customModalbuttonStyles}>
<button onClick={onCancel} className="modal-button">
{Dictionary.no}
</button>
<button onClick={onConfirm} style={customModalbuttonStyles}>
<button onClick={onConfirm} className="modal-button">
{Dictionary.yes}
</button>
</ReactModal>
Expand Down Expand Up @@ -286,33 +271,30 @@ function GenericInput(props) {
<ReactModal
isOpen={showNewUnsavedModal}
ariaHideApp={false}
style={customModalStyles}
className="custom-modal"
>
<p>{Dictionary.notSaved}</p>
<button onClick={handleCloseModal} style={customModalbuttonStyles}>
<button onClick={handleCloseModal} className="modal-button">
{Dictionary.close}
</button>
</ReactModal>
<ReactModal
isOpen={showVisualizationErrorPopup}
ariaHideApp={false}
style={customModalStyles}
className="custom-modal"
>
<p>{Dictionary.visualizationError}</p>
<button
onClick={removeVisualizationError}
style={customModalbuttonStyles}
>
<button onClick={removeVisualizationError} className="modal-button">
{Dictionary.close}
</button>
</ReactModal>
<ReactModal
isOpen={showNewLoopModal}
ariaHideApp={false}
style={customLoopModalStyles}
className="custom-modal"
>
<p>{Dictionary.loopNotSaved}</p>
<button onClick={handleCloseModal} style={customModalbuttonStyles}>
<button onClick={handleCloseModal} className="modal-button">
{Dictionary.close}
</button>
</ReactModal>
Expand Down
32 changes: 28 additions & 4 deletions src/scss/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ a {
}
}

.custom-modal {
@extend .container;
border: 1px solid black;
position: absolute;
text-align: center;
vertical-align: middle;
padding: 10px;
top: 40%;
left: 50%;
right: auto;
bottom: auto;
margin-right: -50%;
width: 400px;
align-items: center;
transform: translate(-50%, -50%);
background-color: white;
border-radius: 4px;
}

.modal-button {
background-color: #15417a;
color: white;
box-shadow: none;
border: none;
padding: 5px 10px;
margin-right: 10px;
}

.alert-triangle {
position: relative;
background-color: red;
Expand Down Expand Up @@ -380,10 +408,6 @@ a {
margin: -50px 0px 0px -50px;
}

.customLoopModalStyles {
overflow: scroll;
}

.questionnaire-element-filter {
margin: 10px;
width: 35%;
Expand Down
3 changes: 2 additions & 1 deletion src/scss/inc/_page-questionnaire.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
flex-wrap: wrap;
justify-content: flex-end;
align-items: center;
a, button {
a,
button {
margin: 5px 5px 2px 2px;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState, useRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import classSet from 'react-classset';
import ClassSet from 'react-classset';
import { Link } from 'react-router-dom';

import Dictionary from 'utils/dictionary/dictionary';
Expand Down Expand Up @@ -37,23 +37,6 @@ function ExternalQuestionnaireDropdown({ questionnaireId, disabled, top }) {
setDropdownOpen(!dropdownOpen);
};

const classDropDown = classSet({
'btn-group': true,
dropup: top,
'flex-column': !top,
'flex-column-reverse': top,
open: dropdownOpen,
});
const classDropDownTrigger = classSet({
btn: true,
'dropdown-toggle': true,
'btn-yellow': false,
'btn-white': true,
disabled: disabled,
});
const classDropDownList = classSet({
'dropdown-menu': true,
});
const linksQuestionnaire = [
{
actionType: 'tcmRef',
Expand All @@ -72,9 +55,24 @@ function ExternalQuestionnaireDropdown({ questionnaireId, disabled, top }) {
},
];
return (
<div className={classDropDown} ref={wrapperRef}>
<div
className={ClassSet({
'btn-group': true,
dropup: top,
'flex-column': !top,
'flex-column-reverse': top,
open: dropdownOpen,
})}
ref={wrapperRef}
>
<button
className={classDropDownTrigger}
className={ClassSet({
btn: true,
'dropdown-toggle': true,
'btn-yellow': false,
'btn-white': true,
disabled: disabled,
})}
disabled={disabled}
data-toggle="dropdown"
aria-haspopup="true"
Expand All @@ -85,7 +83,7 @@ function ExternalQuestionnaireDropdown({ questionnaireId, disabled, top }) {
<span className="caret" />
</button>

<ul className={classDropDownList}>
<ul className="dropdown-menu">
{linksQuestionnaire.map(link => {
return (
<li key={link.actionLabel}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`Visualize Dropdown Component: Should disable the button 1`] = `
className="btn dropdown-toggle btn-yellow disabled"
data-toggle="dropdown"
disabled={true}
id="visualize"
onClick={[Function]}
>
Visualise
Expand Down Expand Up @@ -90,6 +91,7 @@ exports[`Visualize Dropdown Component: Should display the dropdown on top 1`] =
className="btn dropdown-toggle btn-yellow"
data-toggle="dropdown"
disabled={false}
id="visualize"
onClick={[Function]}
>
Visualise
Expand Down Expand Up @@ -170,6 +172,7 @@ exports[`Visualize Dropdown Component: Should return the right HTML 1`] = `
className="btn dropdown-toggle btn-yellow"
data-toggle="dropdown"
disabled={false}
id="visualize"
onClick={[Function]}
>
Visualise
Expand Down
61 changes: 29 additions & 32 deletions src/widgets/visualize-dropdown/components/visualize-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { Link } from 'react-router-dom';
import ReactModal from 'react-modal';
import Dictionary from 'utils/dictionary/dictionary';
import { hasDuplicateVariables } from 'utils/variables/variables-utils';
import {
customModalStyles,
/* customModalbuttonStyles, */
} from 'layout/generic-input/components/generic-input';

/**
* Component used in the actions toolbar and on each
Expand Down Expand Up @@ -81,23 +77,6 @@ function VisualizeDropdown({

const handleCloseModal = () => setAllowDuplicateVariablesModal(false);

const classDropDown = classSet({
'btn-group': true,
dropup: top,
'flex-column': !top,
'flex-column-reverse': top,
open: dropdownOpen,
});
const classDropDownTrigger = classSet({
btn: true,
'dropdown-toggle': true,
'btn-yellow': true,
'btn-white': false,
disabled: disabled,
});
const classDropDownList = classSet({
'dropdown-menu': true,
});
const links = [
{ actionType: 'html', actionLabel: Dictionary.VISUALIZE_WEB },
{
Expand All @@ -111,9 +90,25 @@ function VisualizeDropdown({
{ actionType: 'ddi', actionLabel: Dictionary.VISUALIZE_DDI },
];
return (
<div className={classDropDown} ref={wrapperRef}>
<div
className={classSet({
'btn-group': true,
dropup: top,
'flex-column': !top,
'flex-column-reverse': top,
open: dropdownOpen,
})}
ref={wrapperRef}
>
<button
className={classDropDownTrigger}
id="visualize"
className={classSet({
btn: true,
'dropdown-toggle': true,
'btn-yellow': true,
'btn-white': false,
disabled: disabled,
})}
disabled={disabled}
data-toggle="dropdown"
aria-haspopup="true"
Expand All @@ -124,7 +119,7 @@ function VisualizeDropdown({
<span className="caret" />
</button>

<ul className={classDropDownList}>
<ul className="dropdown-menu">
{links.map(link => {
return (
<li key={link.actionLabel}>
Expand All @@ -139,16 +134,18 @@ function VisualizeDropdown({
isOpen={
allowDuplicateVariablesModal && hasQuestionnaireDuplicateVariables
}
className="custom-modal"
ariaHideApp={false}
style={customModalStyles}
>
<p>{Dictionary.duplicateVariablesComment}</p>
<Link to={`/questionnaire/${questionnaire?.id}/duplicate-variables`}>
<button style={{ color: 'black' }}>
<button className="modal-button">
{Dictionary.showErrorDuplicateVariables}
</button>
</Link>
<button onClick={handleCloseModal}>{Dictionary.close}</button>
<button className="modal-button" onClick={handleCloseModal}>
{Dictionary.close}
</button>
</ReactModal>
</div>
);
Expand All @@ -172,11 +169,11 @@ VisualizeDropdown.defaultProps = {
disabled: false,
top: false,
componentId: '',
externalVariables: undefined,
calculatedVariables: undefined,
collectedVariableByQuestion: undefined,
questionnaire: undefined,
externalQuestionnairesVariables: undefined,
externalVariables: {},
calculatedVariables: {},
collectedVariableByQuestion: {},
questionnaire: {},
externalQuestionnairesVariables: {},
};

export default VisualizeDropdown;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import VisualizeDropdown from '../components/visualize-dropdown';
const mapStateToProps = state => {
return {
questionnaire: state.appState.activeQuestionnaire,
components: state.appState.activeComponentById,
calculatedVariables: state.appState.activeCalculatedVariablesById,
externalVariables: state.appState.activeExternalVariablesById,
collectedVariableByQuestion: state.appState.collectedVariableByQuestion,
Expand All @@ -15,13 +14,13 @@ const mapStateToProps = state => {
};
};

const PageQuestionnaireContainer = connect(mapStateToProps)(VisualizeDropdown);
const VisualizeDropdownContainer = connect(mapStateToProps)(VisualizeDropdown);

PageQuestionnaireContainer.propTypes = {
VisualizeDropdownContainer.propTypes = {
questionnaireId: PropTypes.string,
};
PageQuestionnaireContainer.defaultProps = {
VisualizeDropdownContainer.defaultProps = {
questionnaireId: undefined,
};

export default PageQuestionnaireContainer;
export default VisualizeDropdownContainer;
4 changes: 2 additions & 2 deletions src/widgets/visualize-dropdown/visualize-dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ describe('Visualize Dropdown Component: ', () => {
const wrapper = shallow(<VisualizeDropdown {...props} />);
expect(wrapper.find('div').hasClass('open')).toBeFalsy();
wrapper
.find('button')
.find('button[id="visualize"]')
.simulate('click', { preventDefault() {}, stopPropagation() {} });
expect(wrapper.find('div').hasClass('open')).toBeTruthy();
wrapper
.find('button')
.find('button[id="visualize"]')
.simulate('click', { preventDefault() {}, stopPropagation() {} });
expect(wrapper.find('div').hasClass('open')).toBeFalsy();
});
Expand Down

0 comments on commit e504692

Please sign in to comment.