Skip to content

Commit 3cfd930

Browse files
committed
refactor(utils): move openUrl to helpers
1 parent fbb5149 commit 3cfd930

File tree

10 files changed

+38
-37
lines changed

10 files changed

+38
-37
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/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,

core/src/utils/helpers.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { focusElements } from '@utils/focus-visible';
33
import { printIonError } from '@utils/logging';
44

55
import type { Side } from '../components/menu/menu-interface';
6+
import type { RouterDirection } from '../components/router/utils/interface';
67
import { config } from '../global/config';
8+
import type { AnimationBuilder } from '../interface';
79

810
// TODO(FW-2832): types
911

@@ -434,3 +436,23 @@ export const shallowEqualStringMap = (
434436
export const isSafeNumber = (input: unknown): input is number => {
435437
return typeof input === 'number' && !isNaN(input) && isFinite(input);
436438
};
439+
440+
const SCHEME = /^[a-z][a-z0-9+\-.]*:/;
441+
442+
export const openURL = async (
443+
url: string | undefined | null,
444+
ev: Event | undefined | null,
445+
direction: RouterDirection,
446+
animation?: AnimationBuilder
447+
): Promise<boolean> => {
448+
if (url != null && url[0] !== '#' && !SCHEME.test(url)) {
449+
const router = document.querySelector('ion-router');
450+
if (router) {
451+
if (ev != null) {
452+
ev.preventDefault();
453+
}
454+
return router.push(url, direction, animation);
455+
}
456+
}
457+
return false;
458+
};

core/src/utils/theme.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { RouterDirection } from '../components/router/utils/interface';
2-
import type { AnimationBuilder, Color, CssClassMap } from '../interface';
1+
import type { Color, CssClassMap } from '../interface';
32

43
export const hostContext = (selector: string, el: HTMLElement): boolean => {
54
return el.closest(selector) !== null;
@@ -34,23 +33,3 @@ export const getClassMap = (classes: string | string[] | undefined): CssClassMap
3433
getClassList(classes).forEach((c) => (map[c] = true));
3534
return map;
3635
};
37-
38-
const SCHEME = /^[a-z][a-z0-9+\-.]*:/;
39-
40-
export const openURL = async (
41-
url: string | undefined | null,
42-
ev: Event | undefined | null,
43-
direction: RouterDirection,
44-
animation?: AnimationBuilder
45-
): Promise<boolean> => {
46-
if (url != null && url[0] !== '#' && !SCHEME.test(url)) {
47-
const router = document.querySelector('ion-router');
48-
if (router) {
49-
if (ev != null) {
50-
ev.preventDefault();
51-
}
52-
return router.push(url, direction, animation);
53-
}
54-
}
55-
return false;
56-
};

0 commit comments

Comments
 (0)