Skip to content

Commit

Permalink
feat(Grid): adds headCellTooltip prop
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-kumawat committed Aug 17, 2020
1 parent 58171e6 commit b13ba22
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
44 changes: 29 additions & 15 deletions core/components/organisms/grid/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import { RowData, ColumnSchema } from './Grid';
import { Dropdown, Grid, Placeholder, PlaceholderParagraph, Heading, Icon, Button } from '@/index';
import { Dropdown, Grid, Placeholder, PlaceholderParagraph, Text, Icon, Button, Tooltip } from '@/index';
import { resizeCol, getInit } from './utility';
import { GridCell } from './GridCell';
import { DropdownProps } from '@/components/atoms/dropdown';
Expand Down Expand Up @@ -41,7 +41,8 @@ const HeaderCell = (props: HeaderCellProps) => {
loading,
showMenu,
sortingList,
filterList
filterList,
headCellTooltip
} = _this.props;

const {
Expand Down Expand Up @@ -95,6 +96,24 @@ const HeaderCell = (props: HeaderCellProps) => {
}))
: [];

const renderLabel = () => (
<>
<Text weight="strong" className="ellipsis--noWrap">{schema.displayName}</Text>
{sorting && (
<div className="Grid-sortingIcons">
{sorted ? sorted === 'asc' ? (
<Icon name="arrow_downward" />
) : (
<Icon name="arrow_upward" />
) : (
<Icon name="unfold_more" />
)
}
</div>
)}
</>
);

return (
<div
key={name}
Expand All @@ -117,19 +136,14 @@ const HeaderCell = (props: HeaderCellProps) => {
</Placeholder>
) : (
<>
<Heading size="s" className="ellipsis--noWrap">{schema.displayName}</Heading>
{sorting && (
<div className="Grid-sortingIcons">
{sorted ? sorted === 'asc' ? (
<Icon name="arrow_downward" />
) : (
<Icon name="arrow_upward" />
) : (
<Icon name="unfold_more" />
)
}
</div>
)}
{headCellTooltip ? (
<Tooltip position="top-start" triggerClass="w-100 overflow-hidden" tooltip={schema.displayName}>
{renderLabel()}
</Tooltip>
) : (
renderLabel()
)
}
</>
)
}
Expand Down
4 changes: 4 additions & 0 deletions core/components/organisms/grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ export interface GridProps extends BaseProps {
checked: boolean,
indeterminate: boolean
};
/**
* Shows tooltip on Head Cell hover
*/
headCellTooltip?: boolean;
}

export class Grid extends React.Component<GridProps> {
Expand Down
1 change: 1 addition & 0 deletions core/components/organisms/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface SharedListProps extends BaseProps {
onRowClick?: GridProps['onRowClick'];
onSelect?: TableProps['onSelect'];
onPageChange?: GridProps['onPageChange'];
headCellTooltip?: boolean;
}

type SyncListProps = SyncProps & SharedListProps;
Expand Down
6 changes: 6 additions & 0 deletions core/components/organisms/list/__stories__/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export const all = () => {
false
);

const headCellTooltip = boolean(
'headCellTooltip',
false
);

let dataAttr = {};
if (async) {
dataAttr = {
Expand Down Expand Up @@ -117,6 +122,7 @@ export const all = () => {
withCheckbox={withCheckbox}
type={type}
size={size}
headCellTooltip={headCellTooltip}
withPagination={withPagination}
paginationType={paginationType}
pageSize={pageSize}
Expand Down
6 changes: 6 additions & 0 deletions core/components/organisms/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ interface SharedTableProps extends BaseProps {
* Callback to be called on page change in case of withPagination: true
*/
onPageChange?: GridProps['onPageChange'];
/**
* Shows tooltip on Head Cell hover
*/
headCellTooltip?: boolean;
}

const defaultProps = {
Expand Down Expand Up @@ -558,6 +562,7 @@ export class Table extends React.Component<TableProps, TableState> {
showHead,
type,
size,
headCellTooltip,
draggable,
nestedRows,
nestedRowRenderer,
Expand Down Expand Up @@ -625,6 +630,7 @@ export class Table extends React.Component<TableProps, TableState> {
showHead={showHead}
type={type}
size={size}
headCellTooltip={headCellTooltip}
draggable={draggable}
nestedRows={nestedRows}
nestedRowRenderer={nestedRowRenderer}
Expand Down
6 changes: 6 additions & 0 deletions core/components/organisms/table/__stories__/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export const all = () => {
false
);

const headCellTooltip = boolean(
'headCellTooltip',
false
);

let dataAttr = {};
if (async) {
dataAttr = {
Expand Down Expand Up @@ -141,6 +146,7 @@ export const all = () => {
showMenu={showMenu}
type={type}
size={size}
headCellTooltip={headCellTooltip}
draggable={draggable}
nestedRows={nestedRows}
nestedRowRenderer={nestedRowRenderer}
Expand Down

0 comments on commit b13ba22

Please sign in to comment.