Skip to content

Commit 1aa7c35

Browse files
committed
feat(themes): add support for modular themes and custom themes (#30651)
Issue number: internal --------- ## What is the new behavior? - Moves `openURL` out of the `theme` utils because it makes more sense in `helpers` - Adds support for the default `default.tokens.ts` design tokens file - Adds support for custom theme set globally and on a component ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Requires additional changes in order to test. --------- Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
1 parent fea1e64 commit 1aa7c35

File tree

15 files changed

+657
-32
lines changed

15 files changed

+657
-32
lines changed

core/src/components/back-button/back-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { ComponentInterface } from '@stencil/core';
33
import { Component, Element, Host, Prop, h } from '@stencil/core';
44
import type { ButtonInterface } from '@utils/element-interface';
55
import type { Attributes } from '@utils/helpers';
6-
import { inheritAriaAttributes } from '@utils/helpers';
7-
import { createColorClasses, hostContext, openURL } from '@utils/theme';
6+
import { inheritAriaAttributes, openURL } from '@utils/helpers';
7+
import { createColorClasses, hostContext } from '@utils/theme';
88
import { arrowBackSharp, chevronBack } from 'ionicons/icons';
99

1010
import { config } from '../../global/config';

core/src/components/breadcrumb/breadcrumb.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import dotsThreeRegular from '@phosphor-icons/core/assets/regular/dots-three.svg
33
import type { ComponentInterface, EventEmitter } from '@stencil/core';
44
import { Component, Element, Event, Host, Prop, h } from '@stencil/core';
55
import type { Attributes } from '@utils/helpers';
6-
import { inheritAriaAttributes } from '@utils/helpers';
7-
import { createColorClasses, hostContext, openURL } from '@utils/theme';
6+
import { inheritAriaAttributes, openURL } from '@utils/helpers';
7+
import { createColorClasses, hostContext } from '@utils/theme';
88
import { chevronForwardOutline, ellipsisHorizontal } from 'ionicons/icons';
99

1010
import { config } from '../../global/config';

core/src/components/button/button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Prop, Watch, State, forceUpdate, h } from '@stencil/core';
33
import type { AnchorInterface, ButtonInterface } from '@utils/element-interface';
44
import type { Attributes } from '@utils/helpers';
5-
import { inheritAriaAttributes, hasShadowDom } from '@utils/helpers';
5+
import { inheritAriaAttributes, hasShadowDom, openURL } from '@utils/helpers';
66
import { printIonWarning } from '@utils/logging';
7-
import { createColorClasses, hostContext, openURL } from '@utils/theme';
7+
import { createColorClasses, hostContext } from '@utils/theme';
88

99
import { getIonTheme, getIonMode } from '../../global/ionic-global';
1010
import type { AnimationBuilder, Color } from '../../interface';

core/src/components/card/card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { ComponentInterface } from '@stencil/core';
22
import { Element, Component, Host, Prop, h } from '@stencil/core';
33
import type { AnchorInterface, ButtonInterface } from '@utils/element-interface';
44
import type { Attributes } from '@utils/helpers';
5-
import { inheritAttributes } from '@utils/helpers';
6-
import { createColorClasses, openURL } from '@utils/theme';
5+
import { inheritAttributes, openURL } from '@utils/helpers';
6+
import { createColorClasses } from '@utils/theme';
77

88
import { getIonTheme } from '../../global/ionic-global';
99
import type { AnimationBuilder, Color, Theme } from '../../interface';

core/src/components/fab-button/fab-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import xRegular from '@phosphor-icons/core/assets/regular/x.svg';
22
import type { ComponentInterface, EventEmitter } from '@stencil/core';
33
import { Component, Element, Event, Host, Prop, h } from '@stencil/core';
44
import type { AnchorInterface, ButtonInterface } from '@utils/element-interface';
5-
import { inheritAriaAttributes } from '@utils/helpers';
5+
import { inheritAriaAttributes, openURL } from '@utils/helpers';
66
import type { Attributes } from '@utils/helpers';
7-
import { createColorClasses, hostContext, openURL } from '@utils/theme';
7+
import { createColorClasses, hostContext } from '@utils/theme';
88
import { close } from 'ionicons/icons';
99

1010
import { config } from '../../global/config';

core/src/components/item/item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { ComponentInterface } from '@stencil/core';
33
import { Component, Element, Host, Listen, Prop, State, Watch, forceUpdate, h } from '@stencil/core';
44
import type { AnchorInterface, ButtonInterface } from '@utils/element-interface';
55
import type { Attributes } from '@utils/helpers';
6-
import { inheritAttributes, raf } from '@utils/helpers';
7-
import { createColorClasses, hostContext, openURL } from '@utils/theme';
6+
import { inheritAttributes, raf, openURL } from '@utils/helpers';
7+
import { createColorClasses, hostContext } from '@utils/theme';
88
import { chevronForward } from 'ionicons/icons';
99

1010
import { config } from '../../global/config';

core/src/components/router-link/router-link.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ComponentInterface } from '@stencil/core';
22
import { Component, Host, Prop, h } from '@stencil/core';
3-
import { createColorClasses, openURL } from '@utils/theme';
3+
import { openURL } from '@utils/helpers';
4+
import { createColorClasses } from '@utils/theme';
45

56
import { getIonTheme } from '../../global/ionic-global';
67
import type { AnimationBuilder, Color } from '../../interface';

core/src/global/ionic-global.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Build, getMode, setMode, getElement } from '@stencil/core';
22
import { printIonWarning } from '@utils/logging';
3+
import { applyGlobalTheme } from '@utils/theme';
34

45
import type { IonicConfig, Mode, Theme } from '../interface';
6+
import { defaultTheme as baseTheme } from '../themes/base/default.tokens';
7+
import type { Theme as BaseTheme } from '../themes/base/default.tokens';
58
import { shouldUseCloseWatcher } from '../utils/hardware-back-button';
69
import { isPlatform, setupPlatforms } from '../utils/platform';
710

@@ -225,6 +228,16 @@ export const initialize = (userConfig: IonicConfig = {}) => {
225228
doc.documentElement.setAttribute('theme', defaultTheme);
226229
doc.documentElement.classList.add(defaultTheme);
227230

231+
const customTheme: BaseTheme | undefined = configObj.customTheme;
232+
233+
// Apply base theme, or combine with custom theme if provided
234+
if (customTheme) {
235+
const combinedTheme = applyGlobalTheme(baseTheme, customTheme);
236+
config.set('customTheme', combinedTheme);
237+
} else {
238+
applyGlobalTheme(baseTheme);
239+
}
240+
228241
if (config.getBoolean('_testing')) {
229242
config.set('animated', false);
230243
}

core/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ export { mdTransitionAnimation } from './utils/transition/md.transition';
77
export { getTimeGivenProgression } from './utils/animation/cubic-bezier';
88
export { createGesture } from './utils/gesture';
99
export { initialize } from './global/ionic-global';
10-
export { componentOnReady } from './utils/helpers';
10+
export { componentOnReady, openURL } from './utils/helpers';
1111
export { LogLevel } from './utils/logging';
1212
export { isPlatform, Platforms, PlatformConfig, getPlatforms } from './utils/platform';
1313
export { IonicSafeString } from './utils/sanitization';
1414
export { IonicConfig, getMode, setupConfig } from './utils/config';
15-
export { openURL } from './utils/theme';
1615
export {
1716
LIFECYCLE_WILL_ENTER,
1817
LIFECYCLE_DID_ENTER,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const defaultTheme = {
2+
palette: {
3+
light: {},
4+
dark: {
5+
enabled: 'system',
6+
},
7+
},
8+
};
9+
10+
export type Theme = typeof defaultTheme;

0 commit comments

Comments
 (0)