-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathchip.jsx
More file actions
113 lines (100 loc) · 2.41 KB
/
chip.jsx
File metadata and controls
113 lines (100 loc) · 2.41 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
import React, { useRef } from 'react';
import { classNames, getExtraAttrs, getSlots, emit } from '../shared/utils.js';
import { colorClasses } from '../shared/mixins.js';
import { useTooltip } from '../shared/use-tooltip.js';
import { useIcon } from '../shared/use-icon.js';
import { setRef } from '../shared/set-ref.js';
/* dts-props
id: string | number;
className: string;
style: React.CSSProperties;
media? : string
text? : string | number
deleteable? : boolean
mediaBgColor? : string
mediaTextColor? : string
outline? : boolean
tooltip? : string
tooltipTrigger? : string
onClick? : (event?: any) => void
onDelete? : (event?: any) => void
ref?: React.MutableRefObject<{el: HTMLElement | null}>;
children?: React.ReactNode;
COLOR_PROPS
ICON_PROPS
*/
const Chip = (props) => {
const {
className,
id,
style,
media,
text,
deleteable,
mediaTextColor,
mediaBgColor,
outline,
ref,
} = props;
const extraAttrs = getExtraAttrs(props);
const onClick = (event) => {
emit(props, 'click', event);
};
const onDeleteClick = (event) => {
event.stopPropagation();
emit(props, 'delete', event);
};
const elRef = useRef(null);
useTooltip(elRef, props);
const slots = getSlots(props);
const iconEl = useIcon(props);
let mediaEl;
let labelEl;
let deleteEl;
if (media || iconEl || (slots && slots.media)) {
const mediaClasses = classNames(
'chip-media',
mediaTextColor && `text-color-${mediaTextColor}`,
mediaBgColor && `bg-color-${mediaBgColor}`,
);
mediaEl = (
<div className={mediaClasses}>
{iconEl}
{media}
{slots.media}
</div>
);
}
if (text || (slots && (slots.text || (slots.default && slots.default.length)))) {
labelEl = (
<div className="chip-label">
{text}
{slots.text}
{slots.default}
</div>
);
}
if (deleteable) {
deleteEl = <a className="chip-delete" onClick={onDeleteClick} />;
}
const classes = classNames(className, 'chip', { 'chip-outline': outline }, colorClasses(props));
return (
<div
id={id}
style={style}
className={classes}
ref={(el) => {
elRef.current = el;
setRef(ref, el);
}}
{...extraAttrs}
onClick={onClick}
>
{mediaEl}
{labelEl}
{deleteEl}
</div>
);
};
Chip.displayName = 'f7-chip';
export default Chip;