Skip to content

Commit

Permalink
Merge pull request #637 from nordnet/feat/table-add-tooltip-to-expand…
Browse files Browse the repository at this point in the history
…-item

Feat/table add tooltip to expand item
  • Loading branch information
smithsamyan authored Jul 16, 2020
2 parents 17c109b + 5754b9c commit 5c735e6
Show file tree
Hide file tree
Showing 7 changed files with 6,071 additions and 3,313 deletions.
12 changes: 9 additions & 3 deletions src/Molecules/FlexTable/FlexTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,12 @@ export const TableWithDifferentSizeProps = () => {

const expandedItemsGenerator = (renderComponent = false) =>
[...Array(20)].reduce((acc, _, itemIndex) => {
// Make the first item really long
if (itemIndex === 0) {
const label = 'This is a reaaaallllyyy loooong label demonstrating truncation';
const value = 'This valuues is super long to also demonstrate truncation';
return [...acc, { label, value }];
}
const keyName = `${itemIndex + 1}`;
const labelText = `Label ${keyName}`;
const label = renderComponent
Expand Down Expand Up @@ -1177,7 +1183,7 @@ export const ExpandableTableWithDifferentScenarios = () => {
</FlexTable.Row>
);

const ControlledExpandableTableWithOwnCellExample = () => {
const ControlledExpandableTableWithCustomRowExample = () => {
const [expandedRows, setExpandedRows] = useState<string[]>(['row3']);
const toggleExpand = (rowId: string) => {
const isAlreadyExpanded = expandedRows.includes(rowId);
Expand Down Expand Up @@ -1274,8 +1280,8 @@ export const ExpandableTableWithDifferentScenarios = () => {
<OnlyExpandableOnMobileTable />
<Typography type="title3">Controlled Expandable Table</Typography>
<ControlledExpandedTableExample />
<Typography type="title3">Controlled Expandable Table With Own Cell</Typography>
<ControlledExpandableTableWithOwnCellExample />
<Typography type="title3">Controlled Expandable Table With Custom Row</Typography>
<ControlledExpandableTableWithCustomRowExample />
<Typography type="title3">Different Font Size For Expand Item On Mobile</Typography>
<ExpandedTableDifferentFontSizeOnMobile />
</StyledDiv>
Expand Down
16 changes: 11 additions & 5 deletions src/Molecules/FlexTable/Row/components/ExpandItems/ExpandItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import { isElement, isFunction } from '../../../../../common/utils';
import { Flexbox, LabeledValue } from '../../../../..';
import { ExpandItemComponent, ExpandItemProps, RenderFunc } from './ExpandItems.types';
import { Props as FlexBoxProps } from '../../../../../Atoms/Flexbox/Flexbox.types';
import { TextWrapperLabel, TextWrapperValue } from './TextWrapper';
import { TextWrapperLabel } from './TextWrapperLabel';
import { TextWrapperValue } from './TextWrapperValue';
import { FontSize } from '../../../shared/shared.types';
import { useFlexTable } from '../../../shared/FlexTableProvider';
import { RenderForSizes } from '../../../shared';

const StyledOverflowItem = styled(Flexbox)<{ textAlign?: string }>`
overflow: hidden;
text-align: ${({ textAlign = 'left' }) => textAlign};
`;

const StyledFlexboxItem = styled(Flexbox)<FlexBoxProps>`
max-width: ${p => p.theme.spacing.unit(75)}px;
padding-bottom: ${p => p.theme.spacing.unit(5)}px;
Expand Down Expand Up @@ -36,14 +42,14 @@ const MobileItem: React.FC<{ item: ExpandItemProps; fontSize: FontSize }> = ({
fontSize,
}) => (
<Flexbox container justifyContent="space-between" as="li">
<Flexbox item>
<StyledOverflowItem item flex="0 0 50%">
<ExpandRenderer fontSize={fontSize} isLabel>
{item.label}
</ExpandRenderer>
</Flexbox>
<Flexbox item>
</StyledOverflowItem>
<StyledOverflowItem item flex="0 0 50%" textAlign="right">
<ExpandRenderer fontSize={fontSize}>{item.value}</ExpandRenderer>
</Flexbox>
</StyledOverflowItem>
</Flexbox>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ type Items = {
export type ExpandItemComponent = React.FC<{ item: ExpandItemProps }> & Items;

export type ExpandItemsComponent = React.FC<{ items: ExpandItems }>;

export type TextWrapperComponent = React.FC<{ fontSize: FontSize; truncate?: boolean }>;
23 changes: 0 additions & 23 deletions src/Molecules/FlexTable/Row/components/ExpandItems/TextWrapper.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { FontSize } from '../../../shared/shared.types';
import { getFontSizeTypographyType } from '../../../shared/textUtils';
import { Typography, TruncateWithTooltip } from '../../../../..';
import { TextWrapperComponent } from './ExpandItems.types';

const Text: React.FC<{ fontSize: FontSize }> = ({ fontSize, children }) => (
<Typography type={getFontSizeTypographyType(fontSize)} color={t => t.color.label}>
{children}
</Typography>
);

export const TextWrapperLabel: TextWrapperComponent = ({ fontSize, children, truncate = true }) => {
if (!truncate) {
return <Text fontSize={fontSize}>{children}</Text>;
}
return (
<TruncateWithTooltip label={children}>
<Text fontSize={fontSize}>{children}</Text>
</TruncateWithTooltip>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { Typography, TruncateWithTooltip } from '../../../../..';
import { FontSize } from '../../../shared/shared.types';
import { getFontSizeTypographyType } from '../../../shared/textUtils';
import { TextWrapperComponent } from './ExpandItems.types';

const Text: React.FC<{ fontSize: FontSize }> = ({ fontSize, children }) => (
<Typography type={getFontSizeTypographyType(fontSize)}>{children}</Typography>
);

export const TextWrapperValue: TextWrapperComponent = ({ fontSize, children, truncate = true }) => {
if (!truncate) {
return <Text fontSize={fontSize}>{children}</Text>;
}
return (
<TruncateWithTooltip label={children}>
<Text fontSize={fontSize}>{children}</Text>
</TruncateWithTooltip>
);
};
Loading

0 comments on commit 5c735e6

Please sign in to comment.