Skip to content

Commit d0a8a56

Browse files
committed
feat(select): add HTML to options
1 parent 9918f4a commit d0a8a56

35 files changed

Lines changed: 731 additions & 257 deletions

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

Lines changed: 4 additions & 1 deletion
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;
17+
text?: string | HTMLElement;
1818
role?: LiteralUnion<'cancel' | 'destructive' | 'selected', string>;
1919
icon?: string;
2020
cssClass?: string | string[];
@@ -30,4 +30,7 @@ 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;
3336
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@use "../../themes/ionic/ionic.globals.scss" as globals;
2+
@use "./action-sheet";
3+
@use "./action-sheet.md" as action-sheet-md;
4+
5+
// Ionic Action Sheet
6+
// --------------------------------------------------
7+
8+
// Action Sheet: Select Option
9+
// --------------------------------------------------
10+
11+
.action-sheet-button-label {
12+
gap: globals.$ion-space-300;
13+
}
14+
15+
.select-option-description {
16+
@include globals.typography(globals.$ion-body-md-regular);
17+
@include globals.padding(0);
18+
19+
color: globals.$ion-text-subtle;
20+
21+
font-size: globals.$ion-font-size-350;
22+
}

core/src/components/action-sheet/action-sheet.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./action-sheet";
1+
@import "./action-sheet.native";
22
@import "./action-sheet.ios.vars";
33

44
// iOS Action Sheet

core/src/components/action-sheet/action-sheet.md.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./action-sheet";
1+
@import "./action-sheet.native";
22
@import "./action-sheet.md.vars";
33

44
// Material Design Action Sheet Title
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@use "../../themes/native/native.theme.default" as native;
2+
@use "../../themes/mixins" as mixins;
3+
@use "../../themes/functions.font" as font;
4+
@use "./action-sheet";
5+
6+
// Action Sheet: Native
7+
// --------------------------------------------------
8+
9+
.action-sheet-button-label {
10+
gap: 12px;
11+
}
12+
13+
.select-option-description {
14+
@include mixins.padding(5px, 0, 0, 0);
15+
16+
color: native.$text-color-step-300;
17+
18+
font-size: font.dynamic-font(12px);
19+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,20 @@
233233
}
234234
}
235235
}
236+
237+
// Action Sheet: Select Option
238+
// --------------------------------------------------
239+
240+
.action-sheet-button-label {
241+
display: flex;
242+
243+
align-items: center;
244+
}
245+
246+
.select-option-content {
247+
flex: 1;
248+
}
249+
250+
.select-option-description {
251+
display: block;
252+
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Watch, Component, Element, Event, Host, Listen, Method, Prop, State, h, readTask } from '@stencil/core';
3-
import { ENABLE_HTML_CONTENT_DEFAULT } from '@utils/config';
43
import type { Gesture } from '@utils/gesture';
54
import { createButtonActiveGesture } from '@utils/gesture/button-active';
65
import { raf } from '@utils/helpers';
@@ -17,10 +16,9 @@ import {
1716
safeCall,
1817
setOverlayId,
1918
} from '@utils/overlays';
20-
import { sanitizeDOMString } from '@utils/sanitization';
19+
import { renderOptionLabel } from '@utils/select-option-render';
2120
import { getClassMap } from '@utils/theme';
2221

23-
import { config } from '../../global/config';
2422
import { getIonMode, getIonTheme } from '../../global/ionic-global';
2523
import type { AnimationBuilder, CssClassMap, FrameworkDelegate, OverlayInterface } from '../../interface';
2624
import type { OverlayEventDetail } from '../../utils/overlays-interface';
@@ -40,7 +38,7 @@ import { mdLeaveAnimation } from './animations/md.leave';
4038
styleUrls: {
4139
ios: 'action-sheet.ios.scss',
4240
md: 'action-sheet.md.scss',
43-
ionic: 'action-sheet.md.scss',
41+
ionic: 'action-sheet.ionic.scss',
4442
},
4543
scoped: true,
4644
})
@@ -52,7 +50,6 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
5250
private groupEl?: HTMLElement;
5351
private gesture?: Gesture;
5452
private hasRadioButtons = false;
55-
private customHTMLEnabled = config.get('innerHTMLTemplatesEnabled', ENABLE_HTML_CONTENT_DEFAULT);
5653

5754
presented = false;
5855
lastFocus?: HTMLElement;
@@ -563,6 +560,14 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
563560
htmlAttrs['aria-checked'] = isActiveRadio ? 'true' : 'false';
564561
}
565562

563+
const optionLabelOptions = {
564+
id: buttonId,
565+
label: b.text,
566+
startContent: b.startContent,
567+
endContent: b.endContent,
568+
description: b.description,
569+
};
570+
566571
return (
567572
<button
568573
{...htmlAttrs}
@@ -584,7 +589,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
584589
>
585590
<span class="action-sheet-button-inner">
586591
{b.icon && <ion-icon icon={b.icon} aria-hidden="true" lazy={false} class="action-sheet-icon" />}
587-
{this.customHTMLEnabled ? <span innerHTML={sanitizeDOMString(b.text)}></span> : b.text}
592+
{renderOptionLabel(optionLabelOptions, 'action-sheet-button-label')}
588593
</span>
589594
{theme === 'md' && <ion-ripple-effect></ion-ripple-effect>}
590595
</button>

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

Lines changed: 4 additions & 1 deletion
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;
28+
label?: string | HTMLElement;
2929
checked?: boolean;
3030
disabled?: boolean;
3131
id?: string;
@@ -35,6 +35,9 @@ export interface AlertInput {
3535
cssClass?: string | string[];
3636
attributes?: { [key: string]: any };
3737
tabindex?: number;
38+
startContent?: HTMLElement;
39+
endContent?: HTMLElement;
40+
description?: string;
3841
}
3942

4043
type AlertButtonOverlayHandler = boolean | void | { [key: string]: any };
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@use "../../themes/ionic/ionic.globals.scss" as globals;
2+
@use "./alert";
3+
@use "./alert.md" as alert-md;
4+
5+
// Ionic Alert
6+
// --------------------------------------------------
7+
8+
// Alert: Select Option
9+
// --------------------------------------------------
10+
11+
.alert-radio-label,
12+
.alert-checkbox-label {
13+
gap: globals.$ion-space-300;
14+
}
15+
16+
.select-option-description {
17+
@include globals.typography(globals.$ion-body-md-regular);
18+
@include globals.padding(0);
19+
20+
color: globals.$ion-text-subtle;
21+
22+
font-size: globals.$ion-font-size-350;
23+
}

core/src/components/alert/alert.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./alert";
1+
@import "./alert.native";
22
@import "./alert.ios.vars";
33

44
// iOS Alert

0 commit comments

Comments
 (0)