/
tile.jsx
179 lines (167 loc) · 4.7 KB
/
tile.jsx
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
import React from 'react';
import PropTypes from 'prop-types';
import isFunction from 'lodash.isfunction';
import classNames from 'classnames';
import Truncate from '../utilities/truncate';
// ## Children
import Highlighter from '../utilities/highlighter';
import PopoverTooltip from '../popover-tooltip';
import { APP_LAUNCHER_TILE } from '../../utilities/constants';
const handleClick = (event, href, onClick) => {
event.preventDefault();
onClick(event, { href });
};
/**
* App Launcher Tiles provide information and links to a user's apps
*/
const AppLauncherTile = (props) => {
const smallTile = props.size === 'small' || false;
return (
<a
href={props.href} // eslint-disable-line no-script-url
onClick={
isFunction(props.onClick)
? (event) => handleClick(event, props.href, props.onClick)
: null
}
className={classNames(
'slds-app-launcher__tile slds-text-link--reset',
{ 'slds-app-launcher__tile--small': smallTile },
props.className
)}
>
<div
className={classNames('slds-app-launcher__tile-figure', {
'slds-app-launcher__tile-figure--small': smallTile,
})}
>
{props.iconNode || (
<span className="slds-avatar slds-avatar--large slds-align--absolute-center slds-icon-custom-27">
{props.iconText}
</span>
)}
</div>
{smallTile ? (
<div className="slds-app-launcher__tile-body slds-app-launcher__tile-body--small">
<p className="slds-truncate">
<Highlighter className="slds-text-link" search={props.search}>
{props.title}
</Highlighter>
</p>
</div>
) : (
<div className="slds-app-launcher__tile-body">
<Highlighter className="slds-text-link" search={props.search}>
{props.title}
</Highlighter>
<Truncate
line={2}
prefix={
props.descriptionHeading && props.descriptionHeading.toUpperCase()
}
suffix={props.moreLabel}
text={props.description}
textTruncateChild={
<PopoverTooltip
align="bottom"
content={
<Highlighter search={props.search}>
{props.description}
</Highlighter>
}
>
<span
className="slds-app-launcher__tile-more slds-text-link"
tabIndex="0"
>
{props.moreLabel}
</span>
</PopoverTooltip>
}
wrapper={(text, textTruncateChild) => (
<div>
{props.descriptionHeading && (
// inline style override
<span
className="slds-text-heading--label"
style={{ letterSpacing: '0.025rem' }}
>
{props.descriptionHeading}{' '}
</span>
)}
<Highlighter search={props.search}>{text}</Highlighter>
{textTruncateChild && ' '}
{textTruncateChild}
</div>
)}
/>
</div>
)}
</a>
);
};
// ### Display Name
// Always use the canonical component name as the React display name.
AppLauncherTile.displayName = APP_LAUNCHER_TILE;
AppLauncherTile.defaultProps = {
href: 'javascript:void(0);', // eslint-disable-line no-script-url
size: 'default',
moreLabel: ' More',
};
// ### Prop Types
AppLauncherTile.propTypes = {
/**
* App name for the tile's title.
*/
title: PropTypes.string.isRequired,
/**
* Size of the rendered tile.
*/
size: PropTypes.oneOf(['default', 'small']),
/**
* The description of the app. Not visible on small tiles.
*/
description: PropTypes.string,
/**
* Heading for app description
*/
descriptionHeading: PropTypes.string,
/**
* The `href` attribute of the tile. Please pass in bookmarkable URLs from your routing library. If the `onClick` callback is specified this URL will be prevented from changing the browser's location.
*/
href: PropTypes.string,
/**
* The localized text for the "More information" tooltip.
*/
moreLabel: PropTypes.string,
/**
* Class names to be added to the tile.
*/
className: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
PropTypes.string,
]),
/**
* Function that will be executed when clicking on a tile
*/
onClick: PropTypes.func,
/**
* Icon node for app tile. Takes priority over `iconText`
*/
iconNode: PropTypes.node,
/**
* Text to be used as an icon. Only renders if iconNode is undefined
*/
iconText: PropTypes.string,
/**
* Text used to highlight content in app tiles
*/
search: PropTypes.string,
// TODO: allow for passing iconBackgroundColor
// TODO: add Highlighter to Truncate text (https://github.com/ShinyChang/React-Text-Truncate/issues/32)
};
export default AppLauncherTile;