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(toggletip): add option for alternate icon #11694

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ import '@carbon/web-components/es/components/button/index.js';

Note: For `boolean` attributes, `true` means simply setting the attribute (e.g.
`<cds-toggletip open>`) and `false` means not setting the attribute (e.g.
`<cds-toggletip>` without `open` attribute).
`<cds-toggletip>` without `open` attribute).<br/>
Use `hasCustomIcon` for including custom icons.

```html
<cds-toggletip hasCustomIcon>
Toggletip label
<span slot="icon"> ${Information16({ id: 'trigger' })} </span>
<p slot="body-text">
Lorem ipsum dolor sit amet, di os consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut fsil labore et dolore magna aliqua.
</p>
<cds-link slot="actions">Test</cds-link>
<cds-button slot="actions">Button</cds-button>
</cds-toggletip>
```

<ArgsTable of="cds-toggletip" />
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import './toggletip';
import '../button';
import { POPOVER_ALIGNMENT } from '../popover/defs';
import storyDocs from './toggletip-story.mdx';
import Information16 from '@carbon/icons/lib/information/16';
import View16 from '@carbon/icons/lib/view/16';
import Video16 from '@carbon/icons/lib/video/16';
import User16 from '@carbon/icons/lib/user/16';

const tooltipAlignments = {
[`top`]: POPOVER_ALIGNMENT.TOP,
Expand All @@ -31,13 +35,35 @@ const tooltipAlignments = {
[`right-bottom`]: POPOVER_ALIGNMENT.RIGHT_BOTTOM,
[`right-top`]: POPOVER_ALIGNMENT.RIGHT_TOP,
};

const iconList = {
[`information`]: `Information16`,
[`view`]: `View16`,
[`user`]: `User16`,
[`video`]: `Video16`,
};
export const Default = (args) => {
const { alignment, bodyText } = args?.[`${prefix}-toggletip`] ?? {};
const { alignment, icon, bodyText } = args?.[`${prefix}-toggletip`] ?? {};
let iconVal;
switch (icon) {
case 'Information16':
iconVal = Information16;
break;
case 'View16':
iconVal = View16;
break;
case 'Video16':
iconVal = Video16;
break;
case 'User16':
iconVal = User16;
break;
default:
iconVal = Information16;
}
return html`
<cds-toggletip alignment="${ifDefined(alignment)}">
<cds-toggletip alignment="${ifDefined(alignment)}" hasCustomIcon>
Toggletip label

<span slot="icon"> ${iconVal({ id: 'trigger' })} </span>
<p slot="body-text">${bodyText}</p>
<cds-link slot="actions">Test</cds-link>
<cds-button slot="actions">Button</cds-button>
Expand All @@ -53,6 +79,7 @@ Default.parameters = {
tooltipAlignments,
POPOVER_ALIGNMENT.BOTTOM
),
icon: select('Toggletip icon', iconList, Information16),
bodyText: textNullable(
'Toggletip content (bodyText)',
`Lorem ipsum dolor sit amet, di os consectetur adipiscing elit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
justify-content: center;

outline: none;

.#{$prefix}--popover-caret {
background-color: $background-inverse;
}
Expand All @@ -44,3 +43,11 @@
@include declaration('popover-text-color', $text-inverse);
}
}

:host(#{$prefix}-toggletip) {
slot[name='icon'] {
color: var(--cds-icon-secondary, #525252);
display: inline-block;
height: 16px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class CDSToggletip extends HostListenerMixin(FocusMixin(LitElement)) {
*/
@property({ type: Boolean, reflect: true })
open = false;
/**
* Set whether toggletip is open
*/
@property({ type: Boolean })
hasCustomIcon = false;

/**
* Handles `slotchange` event.
Expand Down Expand Up @@ -96,12 +101,15 @@ class CDSToggletip extends HostListenerMixin(FocusMixin(LitElement)) {
};

protected _renderTooltipButton = () => {
const { hasCustomIcon } = this;
return html`
<button
aria-controls="${this.id}"
class="${prefix}--toggletip-button"
@click=${this._handleClick}>
${Information16({ id: 'trigger' })}
${hasCustomIcon
? html` <slot name="icon"></slot> `
: html`${Information16({ id: 'trigger' })}`}
</button>
`;
};
Expand Down Expand Up @@ -143,6 +151,11 @@ class CDSToggletip extends HostListenerMixin(FocusMixin(LitElement)) {
${this._renderTooltipButton()} ${this._renderTooltipContent()}
`;
};
firstUpdated() {
if (this.hasAttribute('hasCustomIcon')) {
this.hasCustomIcon = true;
}
}

updated() {
if (this.autoalign && this.open) {
Expand Down
Loading