-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathchip.tsx
More file actions
151 lines (130 loc) · 4.57 KB
/
chip.tsx
File metadata and controls
151 lines (130 loc) · 4.57 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import type { ComponentInterface } from '@stencil/core';
import { Component, Element, Host, Prop, h } from '@stencil/core';
import { printIonWarning } from '@utils/logging';
import { createColorClasses } from '@utils/theme';
import { config } from '../../global/config';
import type { Color } from '../../interface';
import type { IonChipFill, IonChipHue, IonChipSize, IonChipShape } from './chip.interfaces';
/**
* @virtualProp {"ios" | "md"} mode - The mode determines the platform behaviors of the component.
*/
@Component({
tag: 'ion-chip',
styleUrl: 'chip.scss',
shadow: true,
})
export class Chip implements ComponentInterface {
@Element() el!: HTMLElement;
/**
* 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.
*
* @deprecated - Use fill="outline" instead
*/
@Prop() outline = false;
/**
* The fill for the chip.
*
* Set to `"outline"` for a chip with a border and background.
* Set to `"solid"` for a chip with a background.
*
* Defaults to `"solid"` if both the fill property and theme config are unset.
*/
@Prop() fill?: IonChipFill;
/**
* 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.
*
* Defaults to `"subtle"` if both the hue property and theme config are unset.
*/
@Prop() hue?: IonChipHue;
/**
* 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"` if both the shape property and theme config are unset.
*/
@Prop() shape?: IonChipShape;
// TODO(FW-6266): Determine if `medium` size is needed.
/**
* Set to `"small"` for a chip with less height and padding.
*
* Defaults to `"large"` if both the size property and theme config are unset.
*/
@Prop() size?: IonChipSize;
componentDidLoad() {
if (this.outline) {
printIonWarning(
`[ion-chip] - The "outline" attribute has been deprecated in favor of the "fill" attribute. Please use the "fill" attribute with the value "outline" instead.`,
this.el
);
}
}
/**
* Gets the chip fill. Uses the `fill` property if set, otherwise
* checks the theme config. Defaults to `solid` if neither is set.
*/
get fillValue(): IonChipFill {
const fillConfig = config.getObjectValue('IonChip.fill', 'solid') as IonChipFill;
const fill = this.fill || (this.outline ? 'outline' : undefined) || fillConfig;
return fill;
}
/**
* Gets the chip hue. Uses the `hue` property if set, otherwise
* checks the theme config. Defaults to `subtle` if neither is set.
*/
get hueValue(): IonChipHue {
const hueConfig = config.getObjectValue('IonChip.hue', 'subtle') as IonChipHue;
const hue = this.hue || hueConfig;
return hue;
}
/**
* Gets the chip shape. Uses the `shape` property if set, otherwise
* checks the theme config. Defaults to `round` if neither is set.
*/
get shapeValue(): IonChipShape {
const shapeConfig = config.getObjectValue('IonChip.shape', 'round') as IonChipShape;
const shape = this.shape || shapeConfig;
return shape;
}
/**
* Gets the chip size. Uses the `size` property if set, otherwise
* checks the theme config. Defaults to `large` if neither is set.
*/
get sizeValue(): IonChipSize {
const sizeConfig = config.getObjectValue('IonChip.size', 'large') as IonChipSize;
const size = this.size || sizeConfig;
return size;
}
render() {
const { fillValue, hueValue, shapeValue, sizeValue } = this;
const useRippleEffect = config.getBoolean('rippleEffect', false);
return (
<Host
aria-disabled={this.disabled ? 'true' : null}
class={createColorClasses(this.color, {
[`chip-fill-${fillValue}`]: true,
[`chip-hue-${hueValue}`]: true,
[`chip-shape-${shapeValue}`]: true,
[`chip-size-${sizeValue}`]: true,
'chip-disabled': this.disabled,
'ion-activatable': true,
'ion-focusable': !this.disabled,
})}
>
<slot></slot>
{useRippleEffect && <ion-ripple-effect></ion-ripple-effect>}
</Host>
);
}
}