Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-15783] Tooltip on long working list names #3474

Merged
merged 7 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// @flow
import React from 'react';
import { Tooltip } from '@dhis2/ui';
import { withStyles } from '@material-ui/core/';

type Props = {
enabled: boolean,
onClick: Function,
children: any,
...CssClasses,
};

const styles = {
// button style reset
button: {
border: 'none',
backgroundColor: 'transparent',
borderRadius: '16px',
padding: 0,
margin: 0,
minWidth: 0,
minHeight: 0,
'&:hover': {
backgroundColor: 'transparent',
},
},
};
const ConditionalTooltipForChipPlain = (props: Props) => {
const { enabled, children, classes, onClick, ...passOnProps } = props;

return enabled ?
(
<Tooltip
{...passOnProps}
>
{({ ref, onMouseOver, onMouseOut }) => (
<button
ref={ref}
onClick={onClick}
className={classes.button}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
onFocus={onMouseOver}
onBlur={onMouseOut}
>
{children}
</button>
)}
</Tooltip>
) : (
<button
onClick={onClick}
className={classes.button}
>
{children}
</button>
);
};

export const ConditionalTooltipForChip = withStyles(styles)(ConditionalTooltipForChipPlain);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
export { ConditionalTooltipForChip } from './ConditionalTooltipForChip.component';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const getStyles = () => ({
padding: 0,
gap: '4px',
marginBottom: spacers.dp8,
overflow: 'hidden',
},
chipContainer: {
padding: 0,
Expand Down Expand Up @@ -80,7 +79,10 @@ const TemplateSelectorPlain = (props: Props) => {
const { id } = customTemplate;
return (
<div className={classes.chipContainer} key={id}>
<TemplateSelectorChip template={customTemplate} onSelectTemplate={onSelectTemplate} />
<TemplateSelectorChip
template={customTemplate}
onSelectTemplate={onSelectTemplate}
/>
</div>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { useCallback } from 'react';
import { Chip } from '@dhis2/ui';
import type { WorkingListTemplate } from './workingListsBase.types';
import { ConditionalTooltipForChip } from '../ConditionalTooltipForChip';

type Props = {
template: WorkingListTemplate,
Expand All @@ -19,8 +20,23 @@ export const TemplateSelectorChip = (props: Props) => {
const text = displayName.length > 30 ? `${displayName.substring(0, 27)}...` : displayName;

return (
<Chip marginTop="0" marginBottom="0" marginLeft="0" marginRight="0" dataTest="workinglist-template-selector-chip" onClick={selectTemplateHandler}>
{text}
</Chip>
<ConditionalTooltipForChip
content={displayName}
placement={'top'}
openDelay={800}
enabled={displayName.length > 30}
onClick={selectTemplateHandler}
>
<Chip
marginTop="0"
marginBottom="0"
marginLeft="0"
marginRight="0"
dataTest="workinglist-template-selector-chip"
>
{text}
</Chip>
</ConditionalTooltipForChip>

);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import { Chip } from '@dhis2/ui';
import { TemplateSelectorChipContent } from './TemplateSelectorChipContent.component';
import type { WorkingListTemplate } from './workingListsBase.types';
import { ConditionalTooltipForChip } from '../../ConditionalTooltipForChip';

type PassOnProps = {
currentListIsModified: boolean,
Expand All @@ -27,16 +28,28 @@ export const TemplateSelectorChip = (props: Props) => {
]);

return (
<Chip
dataTest="workinglist-template-selector-chip"
selected={id === currentTemplateId}
<ConditionalTooltipForChip
content={name}
placement={'top'}
openDelay={800}
enabled={name.length > 30}
onClick={selectTemplateHandler}
>
<TemplateSelectorChipContent
{...passOnProps}
text={name}
isSelectedTemplate={id === currentTemplateId}
/>
</Chip>
<Chip
marginTop="0"
marginBottom="0"
marginLeft="0"
marginRight="0"
dataTest="workinglist-template-selector-chip"
selected={id === currentTemplateId}
>
<TemplateSelectorChipContent
{...passOnProps}
text={name}
isSelectedTemplate={id === currentTemplateId}
/>
superskip marked this conversation as resolved.
Show resolved Hide resolved
</Chip>
</ConditionalTooltipForChip>
);
};

Loading