Skip to content

Commit cc0af05

Browse files
committed
refactor(many): add internal type
1 parent 03b8351 commit cc0af05

10 files changed

Lines changed: 138 additions & 76 deletions

File tree

core/src/components/action-sheet/action-sheet-interface.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ActionSheetOptions extends OverlayOptions {
1414
}
1515

1616
export interface ActionSheetButton<T = any> {
17-
text?: string | HTMLElement;
17+
text?: string;
1818
role?: LiteralUnion<'cancel' | 'destructive' | 'selected', string>;
1919
icon?: string;
2020
cssClass?: string | string[];
@@ -30,7 +30,4 @@ export interface ActionSheetButton<T = any> {
3030
* users to dismiss the action sheet.
3131
*/
3232
disabled?: boolean;
33-
startContent?: HTMLElement;
34-
endContent?: HTMLElement;
35-
description?: string;
3633
}

core/src/components/action-sheet/action-sheet.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getClassMap } from '@utils/theme';
2222
import { getIonMode, getIonTheme } from '../../global/ionic-global';
2323
import type { AnimationBuilder, CssClassMap, FrameworkDelegate, OverlayInterface } from '../../interface';
2424
import type { OverlayEventDetail } from '../../utils/overlays-interface';
25+
import type { SelectActionSheetButton } from '../select/select-interface';
2526

2627
import type { ActionSheetButton } from './action-sheet-interface';
2728
import { iosEnterAnimation } from './animations/ios.enter';
@@ -560,12 +561,19 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
560561
htmlAttrs['aria-checked'] = isActiveRadio ? 'true' : 'false';
561562
}
562563

564+
/**
565+
* Cast to `SelectActionSheetButton` to access rich content
566+
* fields (`startContent`, `endContent`, `description`)
567+
* that are passed through from `ion-select` but not
568+
* part of the public `ActionSheetButton` interface.
569+
*/
570+
const richButton = b as SelectActionSheetButton;
563571
const optionLabelOptions = {
564572
id: buttonId,
565-
label: b.text,
566-
startContent: b.startContent,
567-
endContent: b.endContent,
568-
description: b.description,
573+
label: richButton.text,
574+
startContent: richButton.startContent,
575+
endContent: richButton.endContent,
576+
description: richButton.description,
569577
};
570578

571579
return (

core/src/components/alert/alert-interface.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface AlertInput {
2525
/**
2626
* The label text to display next to the input, if the input type is `radio` or `checkbox`.
2727
*/
28-
label?: string | HTMLElement;
28+
label?: string;
2929
checked?: boolean;
3030
disabled?: boolean;
3131
id?: string;
@@ -35,9 +35,6 @@ export interface AlertInput {
3535
cssClass?: string | string[];
3636
attributes?: { [key: string]: any };
3737
tabindex?: number;
38-
startContent?: HTMLElement;
39-
endContent?: HTMLElement;
40-
description?: string;
4138
}
4239

4340
type AlertButtonOverlayHandler = boolean | void | { [key: string]: any };

core/src/components/alert/alert.tsx

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { getIonMode, getIonTheme } from '../../global/ionic-global';
2727
import type { AnimationBuilder, CssClassMap, OverlayInterface, FrameworkDelegate } from '../../interface';
2828
import type { OverlayEventDetail } from '../../utils/overlays-interface';
2929
import type { IonicSafeString } from '../../utils/sanitization';
30+
import type { SelectAlertInput } from '../select/select-interface';
3031

3132
import type { AlertButton, AlertInput } from './alert-interface';
3233
import { iosEnterAnimation } from './animations/ios.enter';
@@ -330,28 +331,20 @@ export class Alert implements ComponentInterface, OverlayInterface {
330331
}
331332

332333
this.inputType = inputTypes.values().next().value;
333-
this.processedInputs = inputs.map(
334-
(i, index) =>
335-
({
336-
type: i.type || 'text',
337-
name: i.name || `${index}`,
338-
placeholder: i.placeholder || '',
339-
value: i.value,
340-
label: i.label,
341-
checked: !!i.checked,
342-
disabled: !!i.disabled,
343-
id: i.id || `alert-input-${this.overlayIndex}-${index}`,
344-
handler: i.handler,
345-
min: i.min,
346-
max: i.max,
347-
cssClass: i.cssClass ?? '',
348-
attributes: i.attributes || {},
349-
tabindex: i.type === 'radio' && i !== focusable ? -1 : 0,
350-
startContent: i.startContent,
351-
endContent: i.endContent,
352-
description: i.description,
353-
} as AlertInput)
354-
);
334+
this.processedInputs = inputs.map((i, index) => {
335+
return {
336+
...i,
337+
type: i.type || 'text',
338+
name: i.name || `${index}`,
339+
placeholder: i.placeholder || '',
340+
checked: !!i.checked,
341+
disabled: !!i.disabled,
342+
id: i.id || `alert-input-${this.overlayIndex}-${index}`,
343+
cssClass: i.cssClass ?? '',
344+
attributes: i.attributes || {},
345+
tabindex: i.type === 'radio' && i !== focusable ? -1 : 0,
346+
} as AlertInput;
347+
});
355348
}
356349

357350
connectedCallback() {
@@ -574,12 +567,19 @@ export class Alert implements ComponentInterface, OverlayInterface {
574567
return (
575568
<div class="alert-checkbox-group">
576569
{inputs.map((i) => {
570+
/**
571+
* Cast to `SelectAlertInput` to access rich content
572+
* fields (`startContent`, `endContent`, `description`)
573+
* that are passed through from `ion-select` but not
574+
* part of the public `AlertInput` interface.
575+
*/
576+
const richInput = i as SelectAlertInput;
577577
const optionLabelOptions = {
578-
id: i.id!,
579-
label: i.label,
580-
startContent: i.startContent,
581-
endContent: i.endContent,
582-
description: i.description,
578+
id: richInput.id!,
579+
label: richInput.label,
580+
startContent: richInput.startContent,
581+
endContent: richInput.endContent,
582+
description: richInput.description,
583583
};
584584

585585
return (
@@ -624,12 +624,19 @@ export class Alert implements ComponentInterface, OverlayInterface {
624624
return (
625625
<div class="alert-radio-group" role="radiogroup" aria-activedescendant={this.activeId}>
626626
{inputs.map((i) => {
627+
/**
628+
* Cast to `SelectAlertInput` to access rich content
629+
* fields (`startContent`, `endContent`, `description`)
630+
* that are passed through from `ion-select` but not
631+
* part of the public `AlertInput` interface.
632+
*/
633+
const richInput = i as SelectAlertInput;
627634
const optionLabelOptions = {
628-
id: i.id!,
629-
label: i.label,
630-
startContent: i.startContent,
631-
endContent: i.endContent,
632-
description: i.description,
635+
id: richInput.id!,
636+
label: richInput.label,
637+
startContent: richInput.startContent,
638+
endContent: richInput.endContent,
639+
description: richInput.description,
633640
};
634641

635642
return (
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
export interface SelectModalOption {
2-
text: string | HTMLElement;
2+
text: string;
33
value: string;
44
disabled: boolean;
55
checked: boolean;
66
cssClass?: string | string[];
77
handler?: (value: any) => boolean | void | { [key: string]: any };
8-
startContent?: HTMLElement;
9-
endContent?: HTMLElement;
10-
description?: string;
118
}

core/src/components/select-modal/select-modal.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getClassMap, hostContext } from '@utils/theme';
77

88
import type { CheckboxCustomEvent } from '../checkbox/checkbox-interface';
99
import type { RadioGroupCustomEvent } from '../radio-group/radio-group-interface';
10+
import type { SelectOverlayOption } from '../select/select-interface';
1011

1112
import type { SelectModalOption } from './select-modal-interface';
1213

@@ -94,12 +95,19 @@ export class SelectModal implements ComponentInterface {
9495
return (
9596
<ion-radio-group value={checked} onIonChange={(ev) => this.callOptionHandler(ev)}>
9697
{this.options.map((option, index) => {
98+
/**
99+
* Cast to `SelectOverlayOption` to access rich content
100+
* fields (`startContent`, `endContent`, `description`)
101+
* that are passed through from `ion-select` but not
102+
* part of the public `SelectModalOption` interface.
103+
*/
104+
const richOption = option as SelectOverlayOption;
97105
const optionLabelOptions = {
98106
id: `modal-option-${index}`,
99-
label: option.text,
100-
startContent: option.startContent,
101-
endContent: option.endContent,
102-
description: option.description,
107+
label: richOption.text,
108+
startContent: richOption.startContent,
109+
endContent: richOption.endContent,
110+
description: richOption.description,
103111
};
104112

105113
return (
@@ -139,12 +147,19 @@ export class SelectModal implements ComponentInterface {
139147

140148
private renderCheckboxOptions() {
141149
return this.options.map((option, index) => {
150+
/**
151+
* Cast to `SelectOverlayOption` to access rich content
152+
* fields (`startContent`, `endContent`, `description`)
153+
* that are passed through from `ion-select` but not
154+
* part of the public `SelectModalOption` interface.
155+
*/
156+
const richOption = option as SelectOverlayOption;
142157
const optionLabelOptions = {
143158
id: `modal-option-${index}`,
144-
label: option.text,
145-
startContent: option.startContent,
146-
endContent: option.endContent,
147-
description: option.description,
159+
label: richOption.text,
160+
startContent: richOption.startContent,
161+
endContent: richOption.endContent,
162+
description: richOption.description,
148163
};
149164

150165
return (
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
export interface SelectPopoverOption {
2-
text: string | HTMLElement;
2+
text: string;
33
value: string;
44
disabled: boolean;
55
checked: boolean;
66
cssClass?: string | string[];
77
handler?: (value: any) => boolean | void | { [key: string]: any };
8-
startContent?: HTMLElement;
9-
endContent?: HTMLElement;
10-
description?: string;
118
}

core/src/components/select-popover/select-popover.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getClassMap } from '@utils/theme';
77
import { getIonTheme } from '../../global/ionic-global';
88
import type { CheckboxCustomEvent } from '../checkbox/checkbox-interface';
99
import type { RadioGroupCustomEvent } from '../radio-group/radio-group-interface';
10+
import type { SelectOverlayOption } from '../select/select-interface';
1011

1112
import type { SelectPopoverOption } from './select-popover-interface';
1213

@@ -121,12 +122,19 @@ export class SelectPopover implements ComponentInterface {
121122

122123
renderCheckboxOptions(options: SelectPopoverOption[]) {
123124
return options.map((option, index) => {
125+
/**
126+
* Cast to `SelectOverlayOption` to access rich content
127+
* fields (`startContent`, `endContent`, `description`)
128+
* that are passed through from `ion-select` but not
129+
* part of the public `SelectPopoverOption` interface.
130+
*/
131+
const richOption = option as SelectOverlayOption;
124132
const optionLabelOptions = {
125133
id: `popover-option-${index}`,
126-
label: option.text,
127-
startContent: option.startContent,
128-
endContent: option.endContent,
129-
description: option.description,
134+
label: richOption.text,
135+
startContent: richOption.startContent,
136+
endContent: richOption.endContent,
137+
description: richOption.description,
130138
};
131139

132140
return (
@@ -163,12 +171,19 @@ export class SelectPopover implements ComponentInterface {
163171
return (
164172
<ion-radio-group value={checked} onIonChange={(ev) => this.callOptionHandler(ev)}>
165173
{options.map((option, index) => {
174+
/**
175+
* Cast to `SelectOverlayOption` to access rich content
176+
* fields (`startContent`, `endContent`, `description`)
177+
* that are passed through from `ion-select` but not
178+
* part of the public `SelectPopoverOption` interface.
179+
*/
180+
const richOption = option as SelectOverlayOption;
166181
const optionLabelOptions = {
167182
id: `popover-option-${index}`,
168-
label: option.text,
169-
startContent: option.startContent,
170-
endContent: option.endContent,
171-
description: option.description,
183+
label: richOption.text,
184+
startContent: richOption.startContent,
185+
endContent: richOption.endContent,
186+
description: richOption.description,
172187
};
173188

174189
return (

core/src/components/select/select-interface.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import type { ActionSheetButton } from '../action-sheet/action-sheet-interface';
2+
import type { AlertInput } from '../alert/alert-interface';
3+
import type { SelectPopoverOption } from '../select-popover/select-popover-interface';
4+
15
export type SelectInterface = 'action-sheet' | 'popover' | 'alert' | 'modal';
26

37
export type SelectCompareFn = (currentValue: any, compareValue: any) => boolean;
@@ -10,3 +14,24 @@ export interface SelectCustomEvent<T = any> extends CustomEvent {
1014
detail: SelectChangeEventDetail<T>;
1115
target: HTMLIonSelectElement;
1216
}
17+
18+
export interface SelectActionSheetButton extends Omit<ActionSheetButton, 'text'> {
19+
text?: string | HTMLElement;
20+
startContent?: HTMLElement;
21+
endContent?: HTMLElement;
22+
description?: string;
23+
}
24+
25+
export interface SelectAlertInput extends Omit<AlertInput, 'label'> {
26+
label?: string | HTMLElement;
27+
startContent?: HTMLElement;
28+
endContent?: HTMLElement;
29+
description?: string;
30+
}
31+
32+
export interface SelectOverlayOption extends Omit<SelectPopoverOption, 'text'> {
33+
text?: string | HTMLElement;
34+
startContent?: HTMLElement;
35+
endContent?: HTMLElement;
36+
description?: string;
37+
}

core/src/components/select/select.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ import type {
2626
StyleEventDetail,
2727
ModalOptions,
2828
} from '../../interface';
29-
import type { ActionSheetButton } from '../action-sheet/action-sheet-interface';
30-
import type { AlertInput } from '../alert/alert-interface';
31-
import type { SelectPopoverOption } from '../select-popover/select-popover-interface';
3229

33-
import type { SelectChangeEventDetail, SelectInterface, SelectCompareFn } from './select-interface';
30+
import type {
31+
SelectChangeEventDetail,
32+
SelectInterface,
33+
SelectCompareFn,
34+
SelectActionSheetButton,
35+
SelectAlertInput,
36+
SelectOverlayOption,
37+
} from './select-interface';
3438

3539
// TODO(FW-2832): types
3640

@@ -568,7 +572,7 @@ export class Select implements ComponentInterface {
568572
}
569573
}
570574

571-
private createActionSheetButtons(data: HTMLIonSelectOptionElement[], selectValue: any): ActionSheetButton[] {
575+
private createActionSheetButtons(data: HTMLIonSelectOptionElement[], selectValue: any): SelectActionSheetButton[] {
572576
const actionSheetButtons = data.map((option) => {
573577
const value = getOptionValue(option);
574578

@@ -598,7 +602,7 @@ export class Select implements ComponentInterface {
598602
startContent: startContent ?? undefined,
599603
endContent: endContent ?? undefined,
600604
description: option.description,
601-
} as ActionSheetButton;
605+
} as SelectActionSheetButton;
602606
});
603607

604608
// Add "cancel" button
@@ -617,7 +621,7 @@ export class Select implements ComponentInterface {
617621
data: HTMLIonSelectOptionElement[],
618622
inputType: 'checkbox' | 'radio',
619623
selectValue: any
620-
): AlertInput[] {
624+
): SelectAlertInput[] {
621625
const alertInputs = data.map((option) => {
622626
const value = getOptionValue(option);
623627

@@ -648,7 +652,7 @@ export class Select implements ComponentInterface {
648652
return alertInputs;
649653
}
650654

651-
private createOverlaySelectOptions(data: HTMLIonSelectOptionElement[], selectValue: any): SelectPopoverOption[] {
655+
private createOverlaySelectOptions(data: HTMLIonSelectOptionElement[], selectValue: any): SelectOverlayOption[] {
652656
const popoverOptions = data.map((option) => {
653657
const value = getOptionValue(option);
654658

0 commit comments

Comments
 (0)