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

added tooltip to EasyPill delete action #370

Merged
merged 3 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions src/components/EasyPill/EasyPill.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
align-self: center;
margin-right: var(--rvr-space-md);
}

.tooltipText {
line-height: var(--rvr-line-height-lg);
color: var(--rvr-gray-90);
font-weight: normal;
white-space: nowrap;
}
11 changes: 11 additions & 0 deletions src/components/EasyPill/EasyPill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ describe('EasyPill', () => {
expect(wrapper.children()).toHaveLength(1);
expect(wrapper.text()).toEqual('EasyPill 1');
});

it('renders its Addon with tooltip', () => {
const tooltip = 'tooltip test';
const wrapper = mount(
<EasyPill tooltip={tooltip} onDelete={() => {}} checked>
EasyPill 2
</EasyPill>
);
const tooltipWapper = wrapper.find('Tooltip');
expect(tooltipWapper.children()).toHaveLength(1);
});
});

describe('with props.actions', () => {
Expand Down
22 changes: 21 additions & 1 deletion src/components/EasyPill/EasyPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import Pill from '../Pill';
import { PillProps } from '../Pill/Pill';
import styles from './EasyPill.module.css';
import type { MenuItem } from '../EasyDropdown/EasyDropdown';
import Tooltip from '../Tooltip';
import { TooltipDirection } from '../Tooltip/Tooltip';

interface EasyPillProps extends PillProps {
actions?: MenuItem[];
children?: React.ReactNode;
onDelete?: (...args) => void;
tooltip?: string;
tooltipDirection?: TooltipDirection;
}

interface EasyPillDropdownProps {
Expand Down Expand Up @@ -74,8 +78,24 @@ export const EasyPill: React.FC<EasyPillProps> = ({
actions,
children,
onDelete,
tooltip,
tooltipDirection = 'top-right',
...passedProps
}) => {
const renderIconWithOptionalTooltip = () => {
return tooltip ? (
<Tooltip
content={<span className={styles.tooltipText}>{tooltip}</span>}
direction={tooltipDirection}
showOnHover
>
<Icon style={{ display: 'block' }} name="clear" />
</Tooltip>
) : (
<Icon style={{ display: 'block' }} name="clear" />
);
};

return (
<Pill {...passedProps}>
{children}
Expand All @@ -92,7 +112,7 @@ export const EasyPill: React.FC<EasyPillProps> = ({
onDelete(e);
}}
>
<Icon style={{ display: 'block' }} name="clear" />
{renderIconWithOptionalTooltip()}
</Pill.Addon>
)
))}
Expand Down
11 changes: 11 additions & 0 deletions src/components/EasyPill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Easy pill actions may also have `children` props, in which case they'll render t

Easy pills come with a delete action by default. If you provide an `onDelete` function as a prop, it will show up automatically.

Easy pills show a tooltip in delete action. If you provide an `onDelete` functions as a prop and `tooltip` prop but no `actions`.

**TODO**: The easy pill's actions should be in a small dropdown with an ellipsis icon that triggers it.

## Examples
Expand Down Expand Up @@ -59,6 +61,15 @@ Easy pills come with a delete action by default. If you provide an `onDelete` fu
With onDelete but no actions
</EasyPill>

<EasyPill
checked={isChecked}
onClick={() => setIsChecked(!isChecked)}
onDelete={action('onDelete')}
tooltip="With onDelete but no actions and tooltip"
>
With onDelete but no actions and tooltip
</EasyPill>

<EasyPill
checked={isChecked}
onClick={() => setIsChecked(!isChecked)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { boolean, object } from '@storybook/addon-knobs';

import EasyPill from './';
import EasyPill from '.';
import Readme from './README.md';

storiesOf('Galaxies/EasyPill', module)
Expand Down Expand Up @@ -33,9 +33,7 @@ storiesOf('Galaxies/EasyPill', module)
actions={withActions ? actions : []}
checked={boolean('checked', false)}
onClick={action('onClick')}
onDelete={
boolean('with `onDelete`', true) ? action('onDelete') : null
}
onDelete={action('onDelete')}
>
EasyPill 1
</EasyPill>
Expand All @@ -51,7 +49,8 @@ storiesOf('Galaxies/EasyPill', module)
.add(
'Examples',
() => {
const CheckablePill = props => {
const CheckablePill = (props) => {
const { children } = props;
const [isChecked, setIsChecked] = useState(false);

return (
Expand All @@ -60,7 +59,7 @@ storiesOf('Galaxies/EasyPill', module)
checked={isChecked}
onClick={() => setIsChecked(!isChecked)}
>
{props.children}
{children}
</EasyPill>
);
};
Expand Down Expand Up @@ -105,6 +104,14 @@ storiesOf('Galaxies/EasyPill', module)
</CheckablePill>
<br />
<br />
<CheckablePill
onDelete={action('onDelete')}
tooltip="With onDelete but no actions and tooltip"
>
With onDelete but no actions and tooltip
</CheckablePill>
<br />
<br />
<CheckablePill>With neither onDelete nor actions</CheckablePill>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/sizing.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
0 5px 10px 0 rgba(0, 0, 0, 0.1);
--rvr-tooltip-base-z-index: 900;
--rvr-tooltip-border-radius: 3px;
--rvr-tooltip-offset: 20px;
--rvr-tooltip-offset: 10px;

/* Form elements */
--rvr-checkbox-size: calc(var(--rvr-baseSize) * 2.25); /* 18px */
Expand Down