Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

Commit d83ba73

Browse files
committed
feat: adds shorten text tooltip component
1 parent 2c4b44e commit d83ba73

File tree

11 files changed

+97
-25
lines changed

11 files changed

+97
-25
lines changed

dist/components/molecules/CopyTextTooltip.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { FC } from 'react';
2-
import { TooltipProps } from '@material-ui/core/Tooltip';
3-
export interface CopyTextTooltipProps extends TooltipProps {
2+
export interface CopyTextTooltipProps {
43
displayElement: React.ReactElement;
54
fullText: string;
65
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { FC } from 'react';
2+
export interface ShortenTextTooltipProps {
3+
value: string;
4+
maxLength?: number;
5+
charsShownCount?: number;
6+
}
7+
declare const ShortenTextTooltip: FC<ShortenTextTooltipProps>;
8+
export default ShortenTextTooltip;

dist/components/molecules/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import FooterColumn from './FooterColumn';
88
import LabeledCheckbox from './LabeledCheckbox';
99
import ModalDialogue from './ModalDialogue';
1010
import RangeSliderWithInputs from './RangeSliderWithInputs';
11+
import ShortenTextTooltip from './ShortenTextTooltip';
1112
import StyledTabs from './StyledTabs';
1213
import SwitchTabs from './SwitchTabs';
1314
import TooltipIconButton from './TooltipIconButton';
1415
import UnitsInput from './UnitsInput';
15-
export { Accordion, Account, AccountModal, CopyTextTooltip, FAQSection, FilterCheckboxCard, FooterColumn, LabeledCheckbox, ModalDialogue, RangeSliderWithInputs, StyledTabs, SwitchTabs, TooltipIconButton, UnitsInput, };
16+
export { Accordion, Account, AccountModal, CopyTextTooltip, FAQSection, FilterCheckboxCard, FooterColumn, LabeledCheckbox, ModalDialogue, RangeSliderWithInputs, ShortenTextTooltip, StyledTabs, SwitchTabs, TooltipIconButton, UnitsInput, };

dist/doneThumbsUp~bbkTwQsx.svg

Lines changed: 19 additions & 0 deletions
Loading

dist/index.js

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.modern.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.modern.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/molecules/CopyTextTooltip.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { FC, useState } from 'react'
2-
import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip'
2+
import Tooltip from '@material-ui/core/Tooltip'
33
import { Typography, makeStyles } from '@material-ui/core'
44
import FileCopyIcon from '@material-ui/icons/FileCopy'
55

6-
export interface CopyTextTooltipProps extends TooltipProps {
6+
export interface CopyTextTooltipProps {
77
displayElement: React.ReactElement
88
fullText: string
99
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { FC } from 'react'
2+
import Typography from '@material-ui/core/Typography'
3+
import CopyTextTooltip from './CopyTextTooltip'
4+
import { shortenString } from '../../utils'
5+
6+
export interface ShortenTextTooltipProps {
7+
value: string
8+
maxLength?: number
9+
charsShownCount?: number
10+
}
11+
12+
const ShortenTextTooltip: FC<ShortenTextTooltipProps> = ({ value, maxLength = 20, charsShownCount }) => (
13+
<React.Fragment>
14+
{
15+
value.length > maxLength
16+
&& (
17+
<CopyTextTooltip
18+
displayElement={<Typography variant="body2">{shortenString(value, maxLength, charsShownCount || maxLength - 5)}</Typography>}
19+
fullText={value}
20+
/>
21+
)
22+
}
23+
{
24+
value.length <= maxLength
25+
&& value
26+
}
27+
</React.Fragment>
28+
)
29+
30+
export default ShortenTextTooltip

0 commit comments

Comments
 (0)