Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(many): expand global config for icons #29373

Merged
merged 29 commits into from May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46da693
feat(many): expand global config for icons
thetaPC Apr 22, 2024
6ff62ab
feat(breadcrumb): add icon configs
thetaPC Apr 22, 2024
b523936
feat(datetime): add icon config
thetaPC Apr 22, 2024
72b20f9
feat(fab-button): add icon config
thetaPC Apr 22, 2024
f01b037
feat(input): add icon config
thetaPC Apr 22, 2024
034bb4e
feat(input-password-toggle): add icon config
thetaPC Apr 23, 2024
4806be1
feat(item): add icon config
thetaPC Apr 23, 2024
0dad475
fix(fab-button, datetime): use the correct icon name
thetaPC Apr 23, 2024
8248ad0
feat(reorder): use icon config
thetaPC Apr 23, 2024
3db593a
feat(searchbar): add icon config
thetaPC Apr 23, 2024
a9ebe5a
fix(breadcrumb, config): use the correct text
thetaPC Apr 23, 2024
f44ef5f
feat(select): add icon config
thetaPC Apr 23, 2024
b96cff3
feat(toggle): add icon config
thetaPC Apr 24, 2024
e82b9a0
refactor(many): cleanup
thetaPC Apr 24, 2024
8885e2f
Merge branch 'next' of github.com:ionic-team/ionic-framework into FW-…
thetaPC Apr 24, 2024
b96dba5
fix(many): remove unneeded JSDoc comment
thetaPC Apr 29, 2024
cc36dba
refactor(datetime, breadcrumb): use simplified variables
thetaPC Apr 29, 2024
d6b1224
fix(many): remove wrong comment
thetaPC Apr 29, 2024
b4b3911
refactor(many): use simplified variable instead of getters
thetaPC Apr 29, 2024
09e5d83
Merge branch 'next' into FW-6062
thetaPC May 7, 2024
3830bf8
refactor(datetime): spell out word
thetaPC May 8, 2024
e2a8046
refactor(searchbar): use backButtonIcon as default
thetaPC May 8, 2024
14cf2ed
refactor(select): combine lines
thetaPC May 8, 2024
bd008b7
refactor(toggle): rotate only the default checked icon
thetaPC May 8, 2024
8ad4e58
chore(searchbar): run lint
thetaPC May 8, 2024
67693ea
fix(toggle): remove wrong icon
thetaPC May 8, 2024
1c6b7a9
fix(searchbar): revert testing
thetaPC May 8, 2024
6bb7baa
Update core/src/components/searchbar/searchbar.tsx
thetaPC May 8, 2024
b75ede6
chore(searchbar): run lint
thetaPC May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/api.txt
Expand Up @@ -4,7 +4,7 @@ ion-accordion,prop,disabled,boolean,false,false,false
ion-accordion,prop,mode,"ios" | "md",undefined,false,false
ion-accordion,prop,readonly,boolean,false,false,false
ion-accordion,prop,theme,"ios" | "md" | "ionic",undefined,false,false
ion-accordion,prop,toggleIcon,string,chevronDown,false,false
ion-accordion,prop,toggleIcon,string | undefined,undefined,false,false
ion-accordion,prop,toggleIconSlot,"end" | "start",'end',false,false
ion-accordion,prop,value,string,`ion-accordion-${accordionIds++}`,false,false
ion-accordion,part,content
Expand Down Expand Up @@ -494,7 +494,7 @@ ion-fab,method,close,close() => Promise<void>

ion-fab-button,shadow
ion-fab-button,prop,activated,boolean,false,false,false
ion-fab-button,prop,closeIcon,string,close,false,false
ion-fab-button,prop,closeIcon,string | undefined,undefined,false,false
ion-fab-button,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-fab-button,prop,disabled,boolean,false,false,false
ion-fab-button,prop,download,string | undefined,undefined,false,false
Expand Down Expand Up @@ -669,7 +669,7 @@ ion-item,shadow
ion-item,prop,button,boolean,false,false,false
ion-item,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
ion-item,prop,detail,boolean | undefined,undefined,false,false
ion-item,prop,detailIcon,string,chevronForward,false,false
ion-item,prop,detailIcon,string | undefined,undefined,false,false
ion-item,prop,disabled,boolean,false,false,false
ion-item,prop,download,string | undefined,undefined,false,false
ion-item,prop,href,string | undefined,undefined,false,false
Expand Down Expand Up @@ -1282,7 +1282,7 @@ ion-searchbar,prop,animated,boolean,false,false,false
ion-searchbar,prop,autocapitalize,string,'off',false,false
ion-searchbar,prop,autocomplete,"name" | "email" | "tel" | "url" | "on" | "off" | "honorific-prefix" | "given-name" | "additional-name" | "family-name" | "honorific-suffix" | "nickname" | "username" | "new-password" | "current-password" | "one-time-code" | "organization-title" | "organization" | "street-address" | "address-line1" | "address-line2" | "address-line3" | "address-level4" | "address-level3" | "address-level2" | "address-level1" | "country" | "country-name" | "postal-code" | "cc-name" | "cc-given-name" | "cc-additional-name" | "cc-family-name" | "cc-number" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-csc" | "cc-type" | "transaction-currency" | "transaction-amount" | "language" | "bday" | "bday-day" | "bday-month" | "bday-year" | "sex" | "tel-country-code" | "tel-national" | "tel-area-code" | "tel-local" | "tel-extension" | "impp" | "photo",'off',false,false
ion-searchbar,prop,autocorrect,"off" | "on",'off',false,false
ion-searchbar,prop,cancelButtonIcon,string,config.get('backButtonIcon', arrowBackSharp) as string,false,false
ion-searchbar,prop,cancelButtonIcon,string | undefined,undefined,false,false
ion-searchbar,prop,cancelButtonText,string,'Cancel',false,false
ion-searchbar,prop,clearIcon,string | undefined,undefined,false,false
ion-searchbar,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
Expand Down
8 changes: 4 additions & 4 deletions core/src/components.d.ts
Expand Up @@ -96,7 +96,7 @@ export namespace Components {
/**
* The toggle icon to use. This icon will be rotated when the accordion is expanded or collapsed.
*/
"toggleIcon": string;
"toggleIcon"?: string;
/**
* The slot inside of `ion-item` to place the toggle icon. Defaults to `"end"`.
*/
Expand Down Expand Up @@ -1153,7 +1153,7 @@ export namespace Components {
/**
* The icon name to use for the close icon. This will appear when the fab button is pressed. Only applies if it is the main button inside of a fab containing a fab list.
*/
"closeIcon": string;
"closeIcon"?: string;
/**
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
*/
Expand Down Expand Up @@ -1530,7 +1530,7 @@ export namespace Components {
/**
* The icon to use when `detail` is set to `true`.
*/
"detailIcon": string;
"detailIcon"?: string;
/**
* If `true`, the user cannot interact with the item.
*/
Expand Down Expand Up @@ -2989,7 +2989,7 @@ export namespace Components {
/**
* Set the cancel button icon. Only available when the theme is `"md"`. Defaults to `"arrow-back-sharp"`.
*/
"cancelButtonIcon": string;
"cancelButtonIcon"?: string;
/**
* Set the the cancel button text. Only available when the theme is `"ios"`.
*/
Expand Down
7 changes: 4 additions & 3 deletions core/src/components/accordion/accordion.tsx
Expand Up @@ -79,7 +79,7 @@ export class Accordion implements ComponentInterface {
* rotated when the accordion is expanded
* or collapsed.
*/
@Prop() toggleIcon = chevronDown;
@Prop() toggleIcon?: string;

/**
* The slot inside of `ion-item` to
Expand Down Expand Up @@ -193,7 +193,8 @@ export class Accordion implements ComponentInterface {
return;
}

const { toggleIconSlot, toggleIcon } = this;
const { toggleIconSlot } = this;
const accordionToggleIcon = this.toggleIcon ?? config.get('accordionToggleIcon', chevronDown);

/**
* Check if there already is a toggle icon.
Expand All @@ -208,7 +209,7 @@ export class Accordion implements ComponentInterface {
iconEl.slot = toggleIconSlot;
iconEl.lazy = false;
iconEl.classList.add('ion-accordion-toggle-icon');
iconEl.icon = toggleIcon;
iconEl.icon = accordionToggleIcon;
iconEl.setAttribute('aria-hidden', 'true');

ionItem.appendChild(iconEl);
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/back-button/back-button.tsx
Expand Up @@ -82,7 +82,7 @@ export class BackButton implements ComponentInterface, ButtonInterface {
get backButtonIcon() {
const icon = this.icon;
if (icon != null) {
// icon is set on the component or by the config
// Icon is set on the component or by the config.
return icon;
}

Expand Down
8 changes: 6 additions & 2 deletions core/src/components/breadcrumb/breadcrumb.tsx
Expand Up @@ -5,6 +5,7 @@ import { inheritAriaAttributes } from '@utils/helpers';
import { createColorClasses, hostContext, openURL } from '@utils/theme';
import { chevronForwardOutline, ellipsisHorizontal } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonTheme } from '../../global/ionic-global';
import type { AnimationBuilder, Color } from '../../interface';
import type { RouterDirection } from '../router/utils/interface';
Expand Down Expand Up @@ -167,6 +168,9 @@ export class Breadcrumb implements ComponentInterface {
const clickable = this.isClickable();
const TagType = this.href === undefined ? 'span' : ('a' as any);

const breadcrumbSeparatorIcon = config.get('breadcrumbSeparatorIcon', chevronForwardOutline);
const breadcrumbCollapsedIcon = config.get('breadcrumbCollapsedIcon', ellipsisHorizontal);

// Links can still be tabbed to when set to disabled if they have an href
// in order to truly disable them we can keep it as an anchor but remove the href
const href = disabled ? undefined : this.href;
Expand Down Expand Up @@ -224,7 +228,7 @@ export class Breadcrumb implements ComponentInterface {
'breadcrumbs-collapsed-indicator': true,
}}
>
<ion-icon aria-hidden="true" icon={ellipsisHorizontal} lazy={false}></ion-icon>
<ion-icon aria-hidden="true" icon={breadcrumbCollapsedIcon} lazy={false}></ion-icon>
</button>
)}
{showSeparator && (
Expand All @@ -236,7 +240,7 @@ export class Breadcrumb implements ComponentInterface {
<span class="breadcrumb-separator" part="separator" aria-hidden="true">
<slot name="separator">
{theme === 'ios' ? (
<ion-icon icon={chevronForwardOutline} lazy={false} flip-rtl></ion-icon>
<ion-icon icon={breadcrumbSeparatorIcon} lazy={false} flip-rtl></ion-icon>
) : (
<span>/</span>
)}
Expand Down
42 changes: 36 additions & 6 deletions core/src/components/datetime/datetime.tsx
Expand Up @@ -7,6 +7,7 @@ import { isRTL } from '@utils/rtl';
import { createColorClasses } from '@utils/theme';
import { caretDownSharp, caretUpSharp, chevronBack, chevronDown, chevronForward } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonMode, getIonTheme } from '../../global/ionic-global';
import type { Color, StyleEventDetail, Theme } from '../../interface';

Expand Down Expand Up @@ -2115,9 +2116,10 @@ export class Datetime implements ComponentInterface {
*/

private renderCalendarHeader(theme: Theme) {
const { disabled } = this;
const expandedIcon = theme === 'ios' ? chevronDown : caretUpSharp;
const collapsedIcon = theme === 'ios' ? chevronForward : caretDownSharp;
const { disabled, datetimeShowMonthYearIcon, datetimeHideMonthYearIcon } = this;

const datetimeNextIcon = config.get('datetimeNextIcon', chevronForward);
const datetimePrevIcon = config.get('datetimePreviousIcon', chevronBack);

const prevMonthDisabled = disabled || isPrevMonthDisabled(this.workingParts, this.minParts, this.maxParts);
const nextMonthDisabled = disabled || isNextMonthDisabled(this.workingParts, this.maxParts);
Expand All @@ -2144,7 +2146,7 @@ export class Datetime implements ComponentInterface {
{getMonthAndYear(this.locale, this.workingParts)}
<ion-icon
aria-hidden="true"
icon={this.showMonthAndYear ? expandedIcon : collapsedIcon}
icon={this.showMonthAndYear ? datetimeShowMonthYearIcon : datetimeHideMonthYearIcon}
lazy={false}
flipRtl={true}
></ion-icon>
Expand All @@ -2160,7 +2162,7 @@ export class Datetime implements ComponentInterface {
dir={hostDir}
aria-hidden="true"
slot="icon-only"
icon={chevronBack}
icon={datetimePrevIcon}
lazy={false}
flipRtl
></ion-icon>
Expand All @@ -2170,7 +2172,7 @@ export class Datetime implements ComponentInterface {
dir={hostDir}
aria-hidden="true"
slot="icon-only"
icon={chevronForward}
icon={datetimeNextIcon}
lazy={false}
flipRtl
></ion-icon>
Expand Down Expand Up @@ -2593,6 +2595,34 @@ export class Datetime implements ComponentInterface {
}
}

/**
* Get the icon to use for the show month and year icon.
* Otherwise, use the icon set in the config.
* If no icon is set in the config, use the default icon.
*
* @returns {string} The icon to use for the show month and year icon.
*/
get datetimeShowMonthYearIcon(): string {
const theme = getIonTheme(this);
const expandedIcon = theme === 'ios' ? chevronDown : caretUpSharp;

return config.get('datetimeShowMonthYearIcon', expandedIcon);
}

/**
* Get the icon to use for the hide month and year icon.
* Otherwise, use the icon set in the config.
* If no icon is set in the config, use the default icon.
*
* @returns {string} The icon to use for the hide month and year icon.
*/
get datetimeHideMonthYearIcon(): string {
const theme = getIonTheme(this);
const collapsedIcon = theme === 'ios' ? chevronForward : caretDownSharp;

return config.get('datetimeHideMonthYearIcon', collapsedIcon);
}

render() {
const {
name,
Expand Down
6 changes: 4 additions & 2 deletions core/src/components/fab-button/fab-button.tsx
Expand Up @@ -6,6 +6,7 @@ import type { Attributes } from '@utils/helpers';
import { createColorClasses, hostContext, openURL } from '@utils/theme';
import { close } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonTheme } from '../../global/ionic-global';
import type { AnimationBuilder, Color } from '../../interface';
import type { RouterDirection } from '../router/utils/interface';
Expand Down Expand Up @@ -115,7 +116,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
* is pressed. Only applies if it is the main button inside of a fab containing a
* fab list.
*/
@Prop() closeIcon = close;
@Prop() closeIcon?: string;

/**
* Emitted when the button has focus.
Expand Down Expand Up @@ -166,6 +167,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
rel: this.rel,
target: this.target,
};
const fabButtonCloseIcon = this.closeIcon ?? config.get('fabButtonCloseIcon', close);

return (
<Host
Expand Down Expand Up @@ -196,7 +198,7 @@ export class FabButton implements ComponentInterface, AnchorInterface, ButtonInt
>
<ion-icon
aria-hidden="true"
icon={this.closeIcon}
icon={fabButtonCloseIcon}
part="close-icon"
class="close-icon"
lazy={false}
Expand Down
Expand Up @@ -4,6 +4,7 @@ import { printIonWarning } from '@utils/logging';
import { createColorClasses } from '@utils/theme';
import { eyeOff, eye } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
import type { Color, TextFieldTypes } from '../../interface';

Expand Down Expand Up @@ -110,10 +111,9 @@ export class InputPasswordToggle implements ComponentInterface {

const mode = getIonMode(this);

const showPasswordIcon = this.showIcon ?? eye;
const hidePasswordIcon = this.hideIcon ?? eyeOff;

const isPasswordVisible = type === 'text';
const inputPasswordShowIcon = this.showIcon ?? config.get('inputPasswordShowIcon', eye);
const inputPasswordHideIcon = this.hideIcon ?? config.get('inputPasswordHideIcon', eyeOff);

return (
<Host
Expand Down Expand Up @@ -143,7 +143,7 @@ export class InputPasswordToggle implements ComponentInterface {
<ion-icon
slot="icon-only"
aria-hidden="true"
icon={isPasswordVisible ? hidePasswordIcon : showPasswordIcon}
icon={isPasswordVisible ? inputPasswordHideIcon : inputPasswordShowIcon}
></ion-icon>
</ion-button>
</Host>
Expand Down
30 changes: 25 additions & 5 deletions core/src/components/input/input.tsx
Expand Up @@ -9,6 +9,7 @@ import type { SlotMutationController } from '@utils/slot-mutation-controller';
import { createColorClasses, hostContext } from '@utils/theme';
import { closeCircle, closeSharp } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonTheme } from '../../global/ionic-global';
import type { AutocompleteTypes, Color, TextFieldTypes } from '../../interface';

Expand Down Expand Up @@ -690,16 +691,35 @@ export class Input implements ComponentInterface {
return this.renderLabel();
}

/**
* Get the icon to use for the clear icon.
* If an icon is set on the component, use that.
* Otherwise, use the icon set in the config.
* If no icon is set in the config, use the default icon.
*
* @internal
* @returns {string} The icon to use for the clear icon.
*/
get inputClearIcon(): string {
const theme = getIonTheme(this);
const defaultClearIcon = theme === 'ios' ? closeCircle : closeSharp;
const icon = this.clearInputIcon;

if (icon !== undefined) {
// Icon is set on the component.
return icon;
}

return config.get('inputClearIcon', defaultClearIcon);
}

render() {
const { disabled, fill, readonly, shape, inputId, labelPlacement, el, hasFocus, clearInputIcon } = this;
const { disabled, fill, readonly, shape, inputId, labelPlacement, el, hasFocus, inputClearIcon } = this;
const theme = getIonTheme(this);
const value = this.getValue();
const inItem = hostContext('ion-item', this.el);
const shouldRenderHighlight = theme === 'md' && fill !== 'outline' && !inItem;

const defaultClearIcon = theme === 'ios' ? closeCircle : closeSharp;
const clearIconData = clearInputIcon ?? defaultClearIcon;

const hasValue = this.hasValue();
const hasStartEndSlots = el.querySelector('[slot="start"], [slot="end"]') !== null;

Expand Down Expand Up @@ -806,7 +826,7 @@ export class Input implements ComponentInterface {
}}
onClick={this.clearTextInput}
>
<ion-icon aria-hidden="true" icon={clearIconData}></ion-icon>
<ion-icon aria-hidden="true" icon={inputClearIcon}></ion-icon>
</button>
)}
<slot name="end"></slot>
Expand Down
9 changes: 5 additions & 4 deletions core/src/components/item/item.tsx
Expand Up @@ -6,6 +6,7 @@ import { inheritAttributes, raf } from '@utils/helpers';
import { createColorClasses, hostContext, openURL } from '@utils/theme';
import { chevronForward } from 'ionicons/icons';

import { config } from '../../global/config';
import { getIonTheme } from '../../global/ionic-global';
import type { AnimationBuilder, Color, CssClassMap, StyleEventDetail } from '../../interface';
import type { RouterDirection } from '../router/utils/interface';
Expand Down Expand Up @@ -61,7 +62,7 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
/**
* The icon to use when `detail` is set to `true`.
*/
@Prop() detailIcon = chevronForward;
@Prop() detailIcon?: string;

/**
* If `true`, the user cannot interact with the item.
Expand Down Expand Up @@ -244,7 +245,6 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
render() {
const {
detail,
detailIcon,
download,
labelColorStyles,
lines,
Expand All @@ -262,6 +262,7 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
const clickable = this.isClickable();
const canActivate = this.canActivate();
const TagType = clickable ? (href === undefined ? 'button' : 'a') : ('div' as any);
const itemDetailIcon = this.detailIcon ?? config.get('itemDetailIcon', chevronForward);

const attrs =
TagType === 'button'
Expand Down Expand Up @@ -368,12 +369,12 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
<slot name="end"></slot>
{showDetail && (
<ion-icon
icon={detailIcon}
icon={itemDetailIcon}
lazy={false}
class="item-detail-icon"
part="detail-icon"
aria-hidden="true"
flip-rtl={detailIcon === chevronForward}
flip-rtl={itemDetailIcon === chevronForward}
></ion-icon>
)}
</div>
Expand Down