Skip to content

Commit a1bcc4a

Browse files
authored
IBX-10545: Change setters/getters to setX/getX methods (#18)
1 parent 7f52799 commit a1bcc4a

File tree

7 files changed

+48
-52
lines changed

7 files changed

+48
-52
lines changed

src/bundle/Resources/public/ts/components/HelperText.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export default class HelperText extends Base {
1010
error: null,
1111
};
1212

13-
private _error = false;
13+
private _hasError = false;
1414
private _message = '';
1515
private _defaultMessage: string;
1616

1717
constructor(container: HTMLElement) {
1818
super(container);
1919

20-
const iconWrapper = container.querySelector<HTMLDivElement>('.ids-helper-text__icon-wrapper');
21-
const contentWrapper = container.querySelector<HTMLDivElement>('.ids-helper-text__content-wrapper');
20+
const iconWrapper = this._container.querySelector<HTMLDivElement>('.ids-helper-text__icon-wrapper');
21+
const contentWrapper = this._container.querySelector<HTMLDivElement>('.ids-helper-text__content-wrapper');
2222

2323
if (!iconWrapper || !contentWrapper) {
2424
throw new Error('HelperText: Required elements are missing in the container.');
@@ -39,18 +39,18 @@ export default class HelperText extends Base {
3939
};
4040
}
4141

42-
set defaultMessage(value: string) {
42+
setDefaultMessage(value: string) {
4343
this._defaultMessage = value;
4444
}
4545

46-
set error(value: boolean) {
47-
if (this._error === value) {
46+
setHasError(value: boolean) {
47+
if (this._hasError === value) {
4848
return;
4949
}
5050

51-
this._error = value;
51+
this._hasError = value;
5252

53-
this.container.classList.toggle('ids-helper-text--error', value);
53+
this._container.classList.toggle('ids-helper-text--error', value);
5454

5555
const iconElement = this._iconWrapper.querySelector('.ids-helper-text__icon');
5656

@@ -67,7 +67,7 @@ export default class HelperText extends Base {
6767
iconElement.replaceWith(replacementIcon.cloneNode(true));
6868
}
6969

70-
set message(value: string) {
70+
setMessage(value: string) {
7171
if (this._message === value) {
7272
return;
7373
}
@@ -78,6 +78,6 @@ export default class HelperText extends Base {
7878
}
7979

8080
changeToDefaultMessage() {
81-
this.message = this._defaultMessage;
81+
this.setMessage(this._defaultMessage);
8282
}
8383
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Base from '../shared/Base';
22

33
export default class Label extends Base {
4-
private _error = false;
4+
private _hasError = false;
55

6-
set error(value: boolean) {
7-
this._error = value;
8-
this.container.classList.toggle('ids-label--error', value);
6+
setHasError(value: boolean) {
7+
this._hasError = value;
8+
this._container.classList.toggle('ids-label--error', value);
99
}
1010

11-
get error(): boolean {
12-
return this._error;
11+
getHasError(): boolean {
12+
return this._hasError;
1313
}
1414
}

src/bundle/Resources/public/ts/components/accordion.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import Expander, { ExpanderType } from './expander';
21
import Base from '../shared/Base';
2+
import Expander from './expander';
33

44
import { HTMLElementIDSInstance } from '../shared/types';
55

66
import { reflow } from '../helpers/dom';
77

88
export default class Accordion extends Base {
9-
private _togglerElement: HTMLElementIDSInstance<ExpanderType> | null;
10-
private _togglerInstance: ExpanderType;
9+
private _togglerElement: HTMLElementIDSInstance<Expander> | null;
10+
private _togglerInstance: Expander;
1111
private _contentElement: HTMLElement | null;
1212

1313
constructor(container: HTMLElement) {
1414
super(container);
1515

16-
this._togglerElement = container.querySelector<HTMLElementIDSInstance<ExpanderType>>('.ids-expander');
16+
this._togglerElement = this._container.querySelector<HTMLElementIDSInstance<Expander>>('.ids-expander');
1717

1818
if (!this._togglerElement) {
1919
throw new Error('No toggler element found for this container!');
@@ -26,11 +26,11 @@ export default class Accordion extends Base {
2626
}
2727

2828
isExpanded(): boolean {
29-
return this.container.classList.contains('ids-accordion--is-expanded');
29+
return this._container.classList.contains('ids-accordion--is-expanded');
3030
}
3131

3232
toggleIsExpanded(isExpanded: boolean) {
33-
const prevIsExpanded = this.container.classList.contains('ids-accordion--is-expanded');
33+
const prevIsExpanded = this._container.classList.contains('ids-accordion--is-expanded');
3434

3535
if (prevIsExpanded !== isExpanded) {
3636
this._togglerInstance.toggleIsExpanded(isExpanded);
@@ -46,12 +46,12 @@ export default class Accordion extends Base {
4646

4747
reflow(this._contentElement);
4848

49-
this.container.classList.toggle('ids-accordion--is-expanded', isExpanded);
50-
this.container.classList.toggle('ids-accordion--is-animating', true);
49+
this._container.classList.toggle('ids-accordion--is-expanded', isExpanded);
50+
this._container.classList.toggle('ids-accordion--is-animating', true);
5151
this._contentElement.addEventListener(
5252
'transitionend',
5353
() => {
54-
this.container.classList.toggle('ids-accordion--is-animating', false);
54+
this._container.classList.toggle('ids-accordion--is-animating', false);
5555

5656
if (this._contentElement) {
5757
this._contentElement.style.removeProperty('height');
@@ -81,5 +81,3 @@ export default class Accordion extends Base {
8181
super.init();
8282
}
8383
}
84-
85-
export type AccordionType = InstanceType<typeof Accordion>;

src/bundle/Resources/public/ts/components/expander.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ export default class Expander extends Base {
1212
constructor(container: HTMLElement) {
1313
super(container);
1414

15-
const labelContainer = this.container.querySelector<HTMLElement>('.ids-expander__label');
15+
const labelContainer = this._container.querySelector<HTMLElement>('.ids-expander__label');
1616

1717
if (!labelContainer) {
1818
throw new Error('No label container found for this expander!');
1919
}
2020

2121
this._labelContainer = labelContainer;
22-
this._hasLabel = this.container.classList.contains('ids-expander--has-label');
22+
this._hasLabel = this._container.classList.contains('ids-expander--has-label');
2323

2424
if (this._hasLabel) {
25-
this._collapseLabel = container.dataset.collapseLabel;
26-
this._expandLabel = container.dataset.expandLabel;
25+
this._collapseLabel = this._container.dataset.collapseLabel;
26+
this._expandLabel = this._container.dataset.expandLabel;
2727
}
2828
}
2929

@@ -32,19 +32,19 @@ export default class Expander extends Base {
3232
}
3333

3434
isExpanded(): boolean {
35-
return this.container.classList.contains('ids-expander--is-expanded');
35+
return this._container.classList.contains('ids-expander--is-expanded');
3636
}
3737

3838
toggleIsExpanded(isExpanded: boolean) {
39-
this.container.classList.toggle('ids-expander--is-expanded', isExpanded);
39+
this._container.classList.toggle('ids-expander--is-expanded', isExpanded);
4040

4141
if (this._hasLabel && this._collapseLabel && this._expandLabel) {
4242
this._labelContainer.innerHTML = isExpanded ? this._collapseLabel : this._expandLabel;
4343
}
4444
}
4545

4646
init() {
47-
this.container.addEventListener('click', () => {
47+
this._container.addEventListener('click', () => {
4848
if (typeof this._expandHandler !== 'function') {
4949
throw new Error('No expandHandler method provided!');
5050
}
@@ -55,5 +55,3 @@ export default class Expander extends Base {
5555
super.init();
5656
}
5757
}
58-
59-
export type ExpanderType = InstanceType<typeof Expander>;

src/bundle/Resources/public/ts/components/inputs/InputText.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default class InpuText extends Base {
88
constructor(container: HTMLDivElement) {
99
super(container);
1010

11-
const actionsElement = container.querySelector<HTMLDivElement>('.ids-input-text__actions');
12-
const inputElement = container.querySelector<HTMLInputElement>('.ids-input-text__source .ids-input');
11+
const actionsElement = this._container.querySelector<HTMLDivElement>('.ids-input-text__actions');
12+
const inputElement = this._container.querySelector<HTMLInputElement>('.ids-input-text__source .ids-input');
1313
const clearBtnElement = actionsElement?.querySelector<HTMLButtonElement>('.ids-clear-btn');
1414

1515
if (!actionsElement || !inputElement || !clearBtnElement) {

src/bundle/Resources/public/ts/shared/Base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default abstract class Base {
1313
setInstance(container, this);
1414
}
1515

16-
get container(): HTMLElement {
16+
getContainer(): HTMLElement {
1717
return this._container;
1818
}
1919

src/bundle/Resources/public/ts/shared/BaseFormControl.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ export default abstract class BaseFormControl<T> extends Base {
1212
protected _labelInstance: Label | null = null;
1313
protected _helperTextInstance: HelperText | null = null;
1414
protected _validatorManager: ValidatorManager<T>;
15-
protected _error = false;
15+
protected _hasError = false;
1616
protected _errorMessage = '';
1717

1818
constructor(container: HTMLDivElement) {
1919
super(container);
2020

21-
const labelContainer = container.querySelector<HTMLDivElement>('.ids-label');
21+
const labelContainer = this._container.querySelector<HTMLDivElement>('.ids-label');
2222

2323
if (labelContainer) {
2424
this._labelInstance = new Label(labelContainer);
2525
}
2626

27-
const helperTextContainer = container.querySelector<HTMLDivElement>('.ids-helper-text');
27+
const helperTextContainer = this._container.querySelector<HTMLDivElement>('.ids-helper-text');
2828

2929
if (helperTextContainer) {
3030
this._helperTextInstance = new HelperText(helperTextContainer);
@@ -33,36 +33,36 @@ export default abstract class BaseFormControl<T> extends Base {
3333
this._validatorManager = new ValidatorManager();
3434
}
3535

36-
set error(value: boolean) {
37-
if (this._error === value) {
36+
setHasError(value: boolean) {
37+
if (this._hasError === value) {
3838
return;
3939
}
4040

41-
this._error = value;
41+
this._hasError = value;
4242

4343
if (this._labelInstance) {
44-
this._labelInstance.error = value;
44+
this._labelInstance.setHasError(value);
4545
}
4646

4747
if (this._helperTextInstance) {
48-
this._helperTextInstance.error = value;
48+
this._helperTextInstance.setHasError(value);
4949
}
5050
}
5151

52-
get error(): boolean {
53-
return this._error;
52+
getHasError(): boolean {
53+
return this._hasError;
5454
}
5555

56-
set errorMessage(value: string) {
56+
setErrorMessage(value: string) {
5757
if (this._errorMessage === value) {
5858
return;
5959
}
6060

6161
this._errorMessage = value;
6262

6363
if (this._helperTextInstance) {
64-
if (this._error) {
65-
this._helperTextInstance.message = value;
64+
if (this._hasError) {
65+
this._helperTextInstance.setMessage(value);
6666
} else {
6767
this._helperTextInstance.changeToDefaultMessage();
6868
}

0 commit comments

Comments
 (0)