Skip to content

Commit

Permalink
fix existing js code
Browse files Browse the repository at this point in the history
  • Loading branch information
Anne-Gaelle-S committed Nov 23, 2021
1 parent 027cfe3 commit 77ad4fb
Show file tree
Hide file tree
Showing 75 changed files with 799 additions and 683 deletions.
13 changes: 10 additions & 3 deletions addon/components/pix-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ const TYPE_COMMUNICATION = 'communication';
const TYPE_COMMUNICATION_ORGA = 'communication-orga';
const TYPE_COMMUNICATION_CERTIF = 'communication-certif';

const types = [TYPE_INFO, TYPE_ERROR, TYPE_WARNING, TYPE_COMMUNICATION, TYPE_COMMUNICATION_ORGA, TYPE_COMMUNICATION_CERTIF];
const types = [
TYPE_INFO,
TYPE_ERROR,
TYPE_WARNING,
TYPE_COMMUNICATION,
TYPE_COMMUNICATION_ORGA,
TYPE_COMMUNICATION_CERTIF,
];

const icons = {
[TYPE_INFO]: 'info-circle',
Expand All @@ -21,7 +28,7 @@ export default class PixBanner extends Component {
get type() {
return types.includes(this.args.type) ? this.args.type : TYPE_INFO;
}

get icon() {
return icons[this.type];
}
Expand All @@ -31,6 +38,6 @@ export default class PixBanner extends Component {
}

get isExternalLink() {
return this.args.actionUrl.includes('/')
return this.args.actionUrl.includes('/');
}
}
2 changes: 1 addition & 1 deletion addon/components/pix-button-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class PixButtonBase extends Component {
'pix-button',
`pix-button--shape-${this.shape}`,
`pix-button--size-${this.size}`,
`pix-button--background-${this.backgroundColor}`
`pix-button--background-${this.backgroundColor}`,
];
this.args.isBorderVisible && classNames.push('pix-button--border');
this.args.isDisabled && classNames.push('pix-button--disabled');
Expand Down
5 changes: 2 additions & 3 deletions addon/components/pix-button-link.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import PixButtonBase from './pix-button-base'
import PixButtonBase from './pix-button-base';

export default class PixButtonLink extends PixButtonBase {

defaultModel = [];
defaultParams = {};

get className() {
return super.baseClassNames.join(' ')
return super.baseClassNames.join(' ');
}
}
8 changes: 4 additions & 4 deletions addon/components/pix-button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

import PixButtonBase from './pix-button-base'
import PixButtonBase from './pix-button-base';

export default class PixButton extends PixButtonBase {
text = 'pix-button';
Expand Down Expand Up @@ -30,11 +30,11 @@ export default class PixButton extends PixButtonBase {
}

get className() {
return super.baseClassNames.join(' ')
return super.baseClassNames.join(' ');
}

get enableTriggerAction(){
return !(this.type === 'submit' && !this.args.triggerAction)
get enableTriggerAction() {
return !(this.type === 'submit' && !this.args.triggerAction);
}

@action
Expand Down
31 changes: 17 additions & 14 deletions addon/components/pix-input-code.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

const ERROR_MESSAGE = 'ERROR in PixInputCode component, you must provide an @ariaLabel and a @legend';
const NAVIGATION_EXPLANATION = "Pour se déplacer de champ en champ vous pouvez utiliser la tabulation ou bien les flèches gauche et droite de votre clavier.";
const NUMBER_INPUT_EXPLANATION = "Pour remplir un champ vous pouvez utiliser des chiffres de 1 à 9 ou bien les flèches haut et bas de votre clavier pour incrémenter de 1 la valeur du champ.";
const TEXT_INPUT_EXPLANATION = "Pour remplir un champ vous pouvez utiliser les caractères alphanumériques de votre clavier.";
const ERROR_MESSAGE =
'ERROR in PixInputCode component, you must provide an @ariaLabel and a @legend';
const NAVIGATION_EXPLANATION =
'Pour se déplacer de champ en champ vous pouvez utiliser la tabulation ou bien les flèches gauche et droite de votre clavier.';
const NUMBER_INPUT_EXPLANATION =
'Pour remplir un champ vous pouvez utiliser des chiffres de 1 à 9 ou bien les flèches haut et bas de votre clavier pour incrémenter de 1 la valeur du champ.';
const TEXT_INPUT_EXPLANATION =
'Pour remplir un champ vous pouvez utiliser les caractères alphanumériques de votre clavier.';

export default class PixInputCode extends Component {
moveFocus = true;
Expand All @@ -22,9 +26,8 @@ export default class PixInputCode extends Component {
}

get explanationOfUse() {
const defaultFillingExplanation = this.inputType === 'number'
? NUMBER_INPUT_EXPLANATION
: TEXT_INPUT_EXPLANATION;
const defaultFillingExplanation =
this.inputType === 'number' ? NUMBER_INPUT_EXPLANATION : TEXT_INPUT_EXPLANATION;
const defaultExplanationOfUseMessage = NAVIGATION_EXPLANATION + ' ' + defaultFillingExplanation;

return this.args.explanationOfUse ? this.args.explanationOfUse : defaultExplanationOfUseMessage;
Expand Down Expand Up @@ -62,7 +65,7 @@ export default class PixInputCode extends Component {
if (!this.args.onAllInputsFilled) return;

const code = [];
for(let i = 1; i <= this.numInputs; i++) {
for (let i = 1; i <= this.numInputs; i++) {
const elem = document.getElementById(`code-input-${i}`);
elem.value.length > 0 && code.push(elem.value);
}
Expand All @@ -76,11 +79,11 @@ export default class PixInputCode extends Component {
const elem = document.getElementById(`code-input-${index}`);
this.validateInput(elem);
if (elem.value.length > 0) {
elem.classList.add("filled");
elem.classList.add('filled');
this.moveFocus && this.focusElement(index + 1);
this.triggerAction();
} else {
elem.classList.remove("filled");
elem.classList.remove('filled');
}
}

Expand All @@ -89,8 +92,8 @@ export default class PixInputCode extends Component {
const eventMap = {
Backspace: index - 1,
ArrowLeft: index - 1,
ArrowRight: index + 1
}
ArrowRight: index + 1,
};
const newIndex = eventMap[event.code || event.key];
this.focusElement(newIndex);
}
Expand All @@ -110,12 +113,12 @@ export default class PixInputCode extends Component {
const pastedText = (event.clipboardData || window.clipboardData).getData('text');
const pastedTextWithOnlyValidCharacters = _extractValidCharacters(pastedText);

pastedTextWithOnlyValidCharacters.forEach(char => {
pastedTextWithOnlyValidCharacters.forEach((char) => {
const input = document.getElementById(`code-input-${index}`);
if (input) {
this.focusElement(index);
input.value = char;
input.classList.add("filled");
input.classList.add('filled');
index++;
}
});
Expand Down
9 changes: 4 additions & 5 deletions addon/components/pix-input-password.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import PixInput from './pix-input'
import PixInput from './pix-input';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

const ERROR_MESSAGE = 'ERROR in PixInputPassword component, you must provide @label or @ariaLabel params';
const ERROR_MESSAGE =
'ERROR in PixInputPassword component, you must provide @label or @ariaLabel params';

export default class PixInputPassword extends PixInput {

@tracked isPasswordVisible = false;

get label() {
Expand All @@ -29,7 +29,6 @@ export default class PixInputPassword extends PixInput {

@action
onChange() {
if(typeof this.args.onChange === 'function')
this.args.onChange();
if (typeof this.args.onChange === 'function') this.args.onChange();
}
}
3 changes: 1 addition & 2 deletions addon/components/pix-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default class PixInput extends Component {

@action
onChange() {
if(typeof this.args.onChange === 'function')
this.args.onChange();
if (typeof this.args.onChange === 'function') this.args.onChange();
}
}
6 changes: 4 additions & 2 deletions addon/components/pix-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const TYPE_ERROR = 'error';
export default class PixMessage extends Component {
get type() {
const correctTypes = [TYPE_INFO, TYPE_SUCCESS, TYPE_WARNING, TYPE_ALERT, TYPE_ERROR];
if (this.args.type === 'alert'){
console.warn('ERROR in PixMessage component, "alert" type is deprecated. Use "error" type instead.');
if (this.args.type === 'alert') {
console.warn(
'ERROR in PixMessage component, "alert" type is deprecated. Use "error" type instead.'
);
}
return correctTypes.includes(this.args.type) ? this.args.type : 'info';
}
Expand Down
35 changes: 21 additions & 14 deletions addon/components/pix-multi-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ function sortOptionsByCheckedFirst(a, b) {
}

function removeCapitalizeAndDiacritics(string) {
return string.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
return string
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
}

export default class PixMultiSelect extends Component {
@tracked isExpanded = false;
@tracked isExpanded = false;
@tracked searchData;

@tracked options = [];
@tracked isLoadingOptions = false;

constructor(...args) {
super(...args)
super(...args);
const { onLoadOptions, selected } = this.args;

if (onLoadOptions) {
this.isLoadingOptions = true;
onLoadOptions().then((options = []) => {
Expand All @@ -33,7 +36,7 @@ export default class PixMultiSelect extends Component {
this.isLoadingOptions = false;
});
} else {
this.options = [...this.args.options || []];
this.options = [...(this.args.options || [])];
this._setDisplayedOptions(selected, true);
}
}
Expand All @@ -43,7 +46,9 @@ export default class PixMultiSelect extends Component {
const idIsNotDefined = this.args.id && !this.args.id.trim();

if (labelIsDefined && idIsNotDefined) {
throw new Error('ERROR in PixMultiSelect component, @id param is necessary when giving @label');
throw new Error(
'ERROR in PixMultiSelect component, @id param is necessary when giving @label'
);
}
return this.args.label || null;
}
Expand All @@ -65,7 +70,7 @@ export default class PixMultiSelect extends Component {
const selectedOptionLabels = this.options
.filter(({ value, label }) => {
const hasOption = selected.includes(value);
return hasOption && Boolean(label)
return hasOption && Boolean(label);
})
.map(({ label }) => label)
.join(', ');
Expand All @@ -83,7 +88,7 @@ export default class PixMultiSelect extends Component {
if (shouldSort && this.args.isSearchable) {
options.sort(sortOptionsByCheckedFirst);
}

this.options = options;
}

Expand All @@ -96,13 +101,13 @@ export default class PixMultiSelect extends Component {

@action
onSelect(event) {
let selected = [...this.args.selected || []];
if(event.target.checked) {
let selected = [...(this.args.selected || [])];
if (event.target.checked) {
selected.push(event.target.value);
} else {
selected = selected.filter((value) => value !== event.target.value);
}

this._setDisplayedOptions(selected, false);

if (this.args.onSelect) {
Expand All @@ -128,7 +133,7 @@ export default class PixMultiSelect extends Component {

@action
hideDropDown(event) {
if(!this.isExpanded) return;
if (!this.isExpanded) return;

if (event) {
event.stopPropagation();
Expand All @@ -146,8 +151,10 @@ export default class PixMultiSelect extends Component {

@action
updateSearch(event) {
this.searchData = this.args.strictSearch ? event.target.value : removeCapitalizeAndDiacritics(event.target.value);
this.isExpanded = true;
this.searchData = this.args.strictSearch
? event.target.value
: removeCapitalizeAndDiacritics(event.target.value);
this.isExpanded = true;
if (!event.target.value) {
this._setDisplayedOptions(this.args.selected, true);
}
Expand Down
7 changes: 4 additions & 3 deletions addon/components/pix-progress-gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { htmlSafe } from '@ember/string';

export default class PixProgressGauge extends Component {
get progressValue() {
if(!this.args.value || this.args.value < 0) {
if (!this.args.value || this.args.value < 0) {
return 0;
}

Expand All @@ -21,8 +21,9 @@ export default class PixProgressGauge extends Component {
get progressGaugeClass() {
const availableColor = ['yellow', 'white'];

const color = this.args.color && availableColor.includes(this.args.color) ? this.args.color : `yellow`;
const color =
this.args.color && availableColor.includes(this.args.color) ? this.args.color : `yellow`;

return `progress-gauge--${color}`;
return `progress-gauge--${color}`;
}
}
2 changes: 1 addition & 1 deletion addon/components/pix-return-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class PixReturnTo extends Component {

get route() {
const routeParam = this.args.route;
if(routeParam == undefined || routeParam.trim() == '') {
if (routeParam == undefined || routeParam.trim() == '') {
throw new Error('ERROR in PixReturnTo component, @route param is not provided');
}
return routeParam;
Expand Down
4 changes: 2 additions & 2 deletions addon/components/pix-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class PixSelect extends Component {

get label() {
const labelIsDefined = this.args.label?.trim();
const idIsNotDefined = !(this.args.id?.trim());
const idIsNotDefined = !this.args.id?.trim();

if (labelIsDefined && idIsNotDefined) {
throw new Error('ERROR in PixSelect component, @id param is necessary when giving @label');
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class PixSelect extends Component {
if (this.args.isValidationActive) {
this.isValueAValidOption = _checkIfValueIsAValidOption({
value: event.target.value,
options: this.args.options
options: this.args.options,
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions addon/components/pix-stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const STAR_UNACQUIRED = 'unacquired';

export default class PixStars extends Component {
get pixStarsClass() {
if (!this.args.color) return "pix-stars";
if (!this.args.color) return 'pix-stars';
return `pix-stars pix-stars--${this.args.color}`;
}

get stars() {
const { count = 0, total = 0 } = this.args;

const starsTotal = total || count;

const stars = [];
for (let index = 0; index < starsTotal; index++) {
if (index < count) {
Expand Down
7 changes: 2 additions & 5 deletions addon/components/pix-textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import Component from '@glimmer/component';

export default class PixTextarea extends Component {
get textLengthIndicator() {
return this.args.value
? this.args.value.length
: 0;
return this.args.value ? this.args.value.length : 0;
}

get label() {
const labelIsDefined = this.args.label?.trim();
const idIsNotDefined = !(this.args.id?.trim());
const idIsNotDefined = !this.args.id?.trim();

if (labelIsDefined && idIsNotDefined) {
throw new Error('ERROR in PixTextarea component, @id param is necessary when giving @label');
}
return this.args.label || null;
}

}
Loading

0 comments on commit 77ad4fb

Please sign in to comment.