Skip to content

Commit 86dca51

Browse files
committed
Add Tooltip + Add optional Table/cell title (TF-125)
1 parent ec5e718 commit 86dca51

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/Icon/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ReactComponent as EyeOpen } from "../assets/icons/eye-open.svg";
2525
import { ReactComponent as File } from "../assets/icons/file.svg";
2626
import { ReactComponent as Gear } from "../assets/icons/gear.svg";
2727
import { ReactComponent as Help } from "../assets/icons/help.svg";
28+
import { ReactComponent as Info } from "../assets/icons/info.svg";
2829
import { ReactComponent as Insert } from "../assets/icons/insert.svg";
2930
import { ReactComponent as Link } from "../assets/icons/link.svg";
3031
import { ReactComponent as LogOut } from "../assets/icons/logOut.svg";
@@ -81,6 +82,7 @@ const iconMap: IconMap = {
8182
link: Link,
8283
copy: Copy,
8384
file: File,
85+
info: Info,
8486
};
8587

8688
export default function Icon({ icon, className, size, ...props }: IconProps) {

src/Icon/types/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export type IconType =
3737
| "update"
3838
| "delete"
3939
| "copy"
40-
| "file";
40+
| "file"
41+
| "info";
4142

4243
export type IconProps = React.SVGProps<SVGSVGElement> & {
4344
icon?: IconType;
@@ -88,6 +89,7 @@ const iconsArray = [
8889
"delete",
8990
"copy",
9091
"file",
92+
"info",
9193
].sort() as IconType[];
9294

9395
export { iconsArray };

src/Table/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const Row = ({ datum }: RowProps) => {
8989
// If it is an object with the 'content' property, use that as content (can be JSX or a primitive)
9090
// Another 'raw' property with a primitive value is used to sort and search
9191
const content = (datum[k] as any)?.content || datum[k];
92+
const tooltip = (datum[k] as any)?.tooltip;
9293

9394
const wrappedContent = content && typeof content === "string" ? <span>{content}</span> : content;
9495

@@ -101,7 +102,7 @@ const Row = ({ datum }: RowProps) => {
101102
const cellStyle = { width: columnWidths?.[i] || "auto", textAlign: columnAlignments?.[i] || "left" };
102103

103104
return (
104-
<Cell key={k} cellClass={cellClass} cellStyle={cellStyle}>
105+
<Cell key={k} cellClass={cellClass} cellStyle={cellStyle} tooltip={tooltip || ""}>
105106
{wrappedContent}
106107
</Cell>
107108
);
@@ -110,12 +111,13 @@ const Row = ({ datum }: RowProps) => {
110111
);
111112
};
112113

113-
const Cell = ({ children, cellClass, cellStyle }: CellProps) => {
114+
const Cell = ({ children, cellClass, cellStyle, tooltip }: CellProps) => {
114115
const { style } = useContext(TableContext);
115116
const cellProps = {
116117
className: classes([style?.td, cellClass, !children && style?.empty]),
117118
role: "cell",
118119
style: cellStyle,
120+
...(tooltip ? { title: tooltip } : {}),
119121
};
120122
return <div {...cellProps}>{children}</div>;
121123
};

src/Table/storyData.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ const storyData = [
77
},
88
{
99
id: 2,
10-
Name: "Jane Smith",
10+
Name: {
11+
raw: "Huge line",
12+
content:
13+
"Huge line with overflow. Lorem ipsum dolor sit amet. Aequam memento rebus in arduis servare mentem. Ubi fini saeculi fortunae comutatione supersunt in elipse est.",
14+
tooltip:
15+
"Huge line with overflow. Lorem ipsum dolor sit amet. Aequam memento rebus in arduis servare mentem. Ubi fini saeculi fortunae comutatione supersunt in elipse est.",
16+
},
1117
Age: 30,
1218
Email: "jane.smith@example.com",
1319
},

src/Table/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Primitive = string | number | boolean | null | undefined;
77
export type TableComposite = {
88
raw: Primitive;
99
content: Primitive | React.ReactElement;
10+
tooltip?: string;
1011
};
1112

1213
export type TableValue = Primitive | TableComposite;
@@ -40,4 +41,5 @@ export type RowProps = {
4041
export type CellProps = PropsWithChildren<{
4142
cellClass?: string;
4243
cellStyle: Style;
44+
tooltip?: string;
4345
}>;

0 commit comments

Comments
 (0)