Skip to content

Commit

Permalink
feat: add tooltip on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Dec 1, 2023
1 parent deb3deb commit 1269d80
Showing 1 changed file with 54 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import * as React from 'react';
import { Chip, Tooltip } from '@dhis2/ui';
import { withStyles } from '@material-ui/core/';
import { TemplateSelectorChipContent } from './TemplateSelectorChipContent.component';
import type { WorkingListTemplate } from './workingListsBase.types';

Expand All @@ -13,10 +14,35 @@ type Props = {
template: WorkingListTemplate,
currentTemplateId: string,
onSelectTemplate: Function,
...CssClasses,
};

export const TemplateSelectorChip = (props: Props) => {
const { template, currentTemplateId, onSelectTemplate, ...passOnProps } = props;
const styles = {
// button style reset
button: {
border: 'none',
backgroundColor: 'transparent',
borderRadius: '16px',
padding: 0,
margin: 0,
minWidth: 0,
minHeight: 0,
'&:hover': {
backgroundColor: 'transparent',
},
},
// Override default chip margin
chip: {
marginTop: '0 !important',
marginBottom: '0 !important',
marginRight: '0 !important',
marginLeft: '0 !important',
backgroundColor: 'red',
},
};

export const TemplateSelectorChipPlain = (props: Props) => {
const { template, currentTemplateId, onSelectTemplate, classes, ...passOnProps } = props;
const { name, id } = template;

const selectTemplateHandler = React.useCallback(() => {
Expand All @@ -32,18 +58,32 @@ export const TemplateSelectorChip = (props: Props) => {
placement={'top'}
openDelay={800}
>
<Chip
dataTest="workinglist-template-selector-chip"
tabIndex="0"
selected={id === currentTemplateId}
onClick={selectTemplateHandler}
>
<TemplateSelectorChipContent
{...passOnProps}
text={name}
isSelectedTemplate={id === currentTemplateId}
/>
</Chip>
{({ ref, onMouseOver, onMouseOut }) => (
<button
ref={ref}
onClick={selectTemplateHandler}
className={classes.button}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
onFocus={onMouseOver}
onBlur={onMouseOut}
>
<Chip
dataTest="workinglist-template-selector-chip"
tabIndex="0"
className={classes.chip}
selected={id === currentTemplateId}
>
<TemplateSelectorChipContent
{...passOnProps}
text={name}
isSelectedTemplate={id === currentTemplateId}
/>
</Chip>
</button>
)}
</Tooltip>
);
};

export const TemplateSelectorChip = withStyles(styles)(TemplateSelectorChipPlain);

0 comments on commit 1269d80

Please sign in to comment.