-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
Copy pathchip.tsx
116 lines (101 loc) · 3.33 KB
/
chip.tsx
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import type { ComponentInterface } from '@stencil/core';
import { Component, Host, Prop, h } from '@stencil/core';
import { printIonWarning } from '@utils/logging';
import { createColorClasses } from '@utils/theme';
import { getIonTheme } from '../../global/ionic-global';
import type { Color } from '../../interface';
/**
* @virtualProp {"ios" | "md"} mode - The mode determines the platform behaviors of the component.
* @virtualProp {"ios" | "md" | "ionic"} theme - The theme determines the visual appearance of the component.
*/
@Component({
tag: 'ion-chip',
styleUrls: {
ios: 'chip.ios.scss',
md: 'chip.md.scss',
ionic: 'chip.ionic.scss',
},
shadow: true,
})
export class Chip implements ComponentInterface {
/**
* 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).
*/
@Prop({ reflect: true }) color?: Color;
/**
* Display an outline style button.
*/
@Prop() outline = false;
/**
* If `true`, the user cannot interact with the chip.
*/
@Prop() disabled = false;
/**
* Set to `"bold"` for a chip with vibrant, bold colors or to `"subtle"` for
* a chip with muted, subtle colors.
*
* Only applies to the `ionic` theme.
*/
@Prop() hue?: 'bold' | 'subtle' = 'subtle';
/**
* Set to `"soft"` for a chip with slightly rounded corners, `"round"` for a chip with fully
* rounded corners, or `"rectangular"` for a chip without rounded corners.
* Defaults to `"round"` for the `"ionic"` theme and `"soft"` for all other themes.
*/
@Prop() shape?: 'soft' | 'round' | 'rectangular';
/**
* Set the shape based on the theme
*/
private getShape(): string {
const theme = getIonTheme(this);
const { shape } = this;
if (shape === undefined) {
return theme === 'ionic' ? 'round' : 'soft';
}
return shape;
}
/**
* Set to `"small"` for a chip with less height and padding.
*
* Defaults to `"large"` for the ionic theme, and undefined for all other themes.
*/
@Prop() size?: 'small' | 'large';
private getSize() {
const theme = getIonTheme(this);
const { size } = this;
if (theme === 'ionic') {
return size !== undefined ? size : 'large';
// TODO(ROU-10695): remove the size !== undefined when we add support for
// the `ios` and `md` themes.
} else if (size !== undefined) {
printIonWarning(`The "${size}" size is not supported in the ${theme} theme.`);
}
return undefined;
}
render() {
const { hue } = this;
const theme = getIonTheme(this);
const size = this.getSize();
const shape = this.getShape();
return (
<Host
aria-disabled={this.disabled ? 'true' : null}
class={createColorClasses(this.color, {
[theme]: true,
[`chip-${shape}`]: true,
'chip-outline': this.outline,
'chip-disabled': this.disabled,
'ion-activatable': true,
'ion-focusable': !this.disabled,
[`chip-${size}`]: size !== undefined,
[`chip-${hue}`]: hue !== undefined,
})}
>
<slot></slot>
{theme === 'md' && <ion-ripple-effect></ion-ripple-effect>}
</Host>
);
}
}