Skip to content

Commit 717ea52

Browse files
committed
refactor: Minor code style changes and a CHANGELOG entry
1 parent 7c027ff commit 717ea52

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88
### Added
9-
- New File Input Component(`igc-file-input`)
9+
- File Input component
1010
- Exposed more public API type aliases for component property types like `ButtonVariant`, `PickerMode`, `StepperOrientation`, `HorizontalTransitionAnimation` (carousel and horizontal stepper) and more.
11+
- Tooltip component
1112

1213
### Deprecated
1314
- Some event argument types have been renamed for consistency:

src/components/tooltip/controller.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class TooltipController implements ReactiveController {
165165
break;
166166
case 'pointerleave':
167167
await this._options.onHide.call(this._host);
168+
break;
169+
default:
170+
return;
168171
}
169172
}
170173

@@ -256,9 +259,28 @@ class TooltipController implements ReactiveController {
256259
}
257260

258261
function parseTriggers(string: string): Set<string> {
259-
return new Set((string ?? '').split(/[,\s]+/).filter((s) => s.trim()));
262+
return new Set(
263+
(string ?? '').split(TooltipRegexes.triggers).filter((s) => s.trim())
264+
);
260265
}
261266

267+
export const TooltipRegexes = Object.freeze({
268+
/** Used for parsing the strings passed in the tooltip `show/hide-trigger` properties. */
269+
triggers: /[,\s]+/,
270+
271+
/** Matches horizontal `PopoverPlacement` start positions. */
272+
horizontalStart: /^(left|right)-start$/,
273+
274+
/** Matches horizontal `PopoverPlacement` end positions. */
275+
horizontalEnd: /^(left|right)-end$/,
276+
277+
/** Matches vertical `PopoverPlacement` start positions. */
278+
start: /start$/,
279+
280+
/** Matches vertical `PopoverPlacement` end positions. */
281+
end: /end$/,
282+
});
283+
262284
export function addTooltipController(
263285
host: IgcTooltipComponent,
264286
options: TooltipCallbacks

src/components/tooltip/tooltip.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import IgcIconComponent from '../icon/icon.js';
1515
import IgcPopoverComponent, {
1616
type PopoverPlacement,
1717
} from '../popover/popover.js';
18-
import { addTooltipController } from './controller.js';
18+
import { TooltipRegexes, addTooltipController } from './controller.js';
1919
import { styles as shared } from './themes/shared/tooltip.common.css';
2020
import { all } from './themes/themes.js';
2121
import { styles } from './themes/tooltip.base.css.js';
@@ -91,24 +91,24 @@ export default class IgcTooltipComponent extends EventEmitterMixin<
9191
private _arrowElement!: HTMLElement;
9292

9393
private get _arrowOffset() {
94-
if (/-/.test(this.placement)) {
94+
if (this.placement.includes('-')) {
9595
// Horizontal start | end placement
9696

97-
if (/^(left|right)-start$/.test(this.placement)) {
97+
if (TooltipRegexes.horizontalStart.test(this.placement)) {
9898
return -8;
9999
}
100100

101-
if (/^(left|right)-end$/.test(this.placement)) {
101+
if (TooltipRegexes.horizontalEnd.test(this.placement)) {
102102
return 8;
103103
}
104104

105105
// Vertical start | end placement
106106

107-
if (/start$/.test(this.placement)) {
107+
if (TooltipRegexes.start.test(this.placement)) {
108108
return isLTR(this) ? -8 : 8;
109109
}
110110

111-
if (/end$/.test(this.placement)) {
111+
if (TooltipRegexes.end.test(this.placement)) {
112112
return isLTR(this) ? 8 : -8;
113113
}
114114
}
@@ -350,17 +350,17 @@ export default class IgcTooltipComponent extends EventEmitterMixin<
350350
this._controller.setAnchor(target, true);
351351
}
352352

353-
return this._applyTooltipState({ show: true });
353+
return await this._applyTooltipState({ show: true });
354354
}
355355

356356
/** Hides the tooltip if not already hidden. */
357357
public async hide(): Promise<boolean> {
358-
return this._applyTooltipState({ show: false });
358+
return await this._applyTooltipState({ show: false });
359359
}
360360

361361
/** Toggles the tooltip between shown/hidden state */
362362
public async toggle(): Promise<boolean> {
363-
return this.open ? this.hide() : this.show();
363+
return await (this.open ? this.hide() : this.show());
364364
}
365365

366366
protected _showWithEvent(): Promise<boolean> {
@@ -393,7 +393,7 @@ export default class IgcTooltipComponent extends EventEmitterMixin<
393393
this._stopTimeoutAndAnimation();
394394

395395
this._timeoutId = setTimeout(
396-
() => this._hideWithEvent(),
396+
this._hideWithEvent.bind(this),
397397
this._autoHideDelay
398398
);
399399
}

0 commit comments

Comments
 (0)