Add length constraints to tooltip label

pull/4136/head
Thibaud Colas 2018-01-15 17:13:40 +02:00
rodzic ded04cf6b0
commit bc2a4c3560
3 zmienionych plików z 15 dodań i 8 usunięć

Wyświetl plik

@ -8,11 +8,13 @@ import TooltipEntity from '../decorators/TooltipEntity';
const Document = props => {
const { entityKey, contentState } = props;
const { url } = contentState.getEntity(entityKey).getData();
const filename = url.split('/')[3];
return (
<TooltipEntity
{...props}
icon={<Icon name="doc-full" />}
label={url}
label={filename}
url={url}
/>
);

Wyświetl plik

@ -13,19 +13,15 @@ const Link = props => {
const data = contentState.getEntity(entityKey).getData();
let icon;
let label;
let tooltipURL;
if (data.id) {
icon = 'link';
tooltipURL = data.url;
label = data.url;
} else if (data.url.startsWith('mailto:')) {
icon = 'mail';
tooltipURL = getEmailAddress(data.url);
label = data.url;
label = getEmailAddress(data.url);
} else {
icon = 'link';
tooltipURL = data.url;
label = getDomainName(data.url);
}
@ -34,7 +30,7 @@ const Link = props => {
{...props}
icon={<Icon name={icon} />}
label={label}
url={tooltipURL}
url={data.url}
/>
);
};

Wyświetl plik

@ -5,6 +5,15 @@ import { Icon } from 'draftail';
import Tooltip from '../Tooltip/Tooltip';
import Portal from '../../Portal/Portal';
const shortenLabel = (label) => {
let shortened = label;
if (shortened.length > 25) {
shortened = `${shortened.slice(0, 20)}`;
}
return shortened;
};
class TooltipEntity extends Component {
constructor(props) {
super(props);
@ -59,7 +68,7 @@ class TooltipEntity extends Component {
rel="noopener noreferrer"
className="Tooltip__link"
>
{label}
{shortenLabel(label)}
</a>
<button