-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathIonIcon.tsx
More file actions
70 lines (58 loc) · 1.62 KB
/
IonIcon.tsx
File metadata and controls
70 lines (58 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import { NavContext } from '../contexts/NavContext';
import type { IonicReactProps } from './IonicReactProps';
import { IonIconInner } from './inner-proxies';
import { createForwardRef, getConfig } from './utils';
interface IonIconProps {
color?: string;
flipRtl?: boolean;
icon?: string;
ios?: string;
lazy?: boolean;
md?: string;
mode?: 'ios' | 'md';
name?: string;
size?: string;
src?: string;
}
type InternalProps = IonIconProps & {
forwardedRef?: React.ForwardedRef<HTMLIonIconElement>;
children: React.ReactNode;
};
class IonIconContainer extends React.PureComponent<InternalProps> {
constructor(props: InternalProps) {
super(props);
if (this.props.name) {
console.warn(
'In Ionic React, you import icons from "ionicons/icons" and set the icon you imported to the "icon" property. Setting the "name" property has no effect.'
);
}
}
render() {
const { icon, ios, md, mode, ...rest } = this.props;
let iconToUse: typeof icon;
const config = getConfig();
const iconMode = mode || config?.get('mode');
if (ios || md) {
if (iconMode === 'ios') {
iconToUse = ios ?? md ?? icon;
} else {
iconToUse = md ?? ios ?? icon;
}
} else {
iconToUse = icon;
}
return (
<IonIconInner ref={this.props.forwardedRef} icon={iconToUse} {...rest}>
{this.props.children}
</IonIconInner>
);
}
static get contextType() {
return NavContext;
}
}
export const IonIcon = createForwardRef<IonIconProps & IonicReactProps, HTMLIonIconElement>(
IonIconContainer,
'IonIcon'
);