Skip to content

Commit 70aeec3

Browse files
authored
Merge pull request #2317 from hashicorp/hds-2718/ts-tooltip
`TooltipButton`: Converted component to TypeScript
2 parents eeafbba + 9e98051 commit 70aeec3

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

.changeset/strange-schools-flash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hashicorp/design-system-components": minor
3+
---
4+
5+
`TooltipButton`: Converted component to TypeScript

packages/components/src/components.ts

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import HdsTextBody from './components/hds/text/body.ts';
103103
import HdsTextCode from './components/hds/text/code.ts';
104104
import HdsTextDisplay from './components/hds/text/display.ts';
105105
import HdsToast from './components/hds/toast/index.ts';
106+
import HdsTooltipButton from './components/hds/tooltip-button/index.ts';
106107

107108
export {
108109
HdsAccordion,
@@ -204,4 +205,5 @@ export {
204205
HdsTextCode,
205206
HdsTextDisplay,
206207
HdsToast,
208+
HdsTooltipButton,
207209
};

packages/components/src/components/hds/tooltip-button/index.js renamed to packages/components/src/components/hds/tooltip-button/index.ts

+29-26
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@
66
import Component from '@glimmer/component';
77
import { assert } from '@ember/debug';
88

9-
export const PLACEMENTS = [
10-
'top',
11-
'top-start',
12-
'top-end',
13-
'right',
14-
'right-start',
15-
'right-end',
16-
'bottom',
17-
'bottom-start',
18-
'bottom-end',
19-
'left',
20-
'left-start',
21-
'left-end',
22-
];
9+
import type { Props as TippyProps } from 'tippy.js';
10+
import { HdsTooltipPlacementValues } from './types.ts';
2311

24-
export default class HdsTooltipIndexComponent extends Component {
12+
export const PLACEMENTS: string[] = Object.values(HdsTooltipPlacementValues);
13+
14+
export interface HdsTooltipSignature {
15+
Args: {
16+
extraTippyOptions: Omit<TippyProps, 'placement' | 'offset'>;
17+
isInline?: boolean;
18+
offset?: [number, number];
19+
placement: HdsTooltipPlacementValues;
20+
text: string;
21+
};
22+
Blocks: {
23+
default: [];
24+
};
25+
Element: HTMLButtonElement;
26+
}
27+
28+
export default class HdsTooltipIndexComponent extends Component<HdsTooltipSignature> {
2529
/**
2630
* @param text
2731
* @type {string}
2832
* @description text content for tooltip
2933
*/
30-
get text() {
31-
let { text } = this.args;
34+
get text(): string {
35+
const { text } = this.args;
3236

3337
assert(
3438
'@text for "Hds::TooltipButton" must have a valid value',
@@ -38,8 +42,8 @@ export default class HdsTooltipIndexComponent extends Component {
3842
return text;
3943
}
4044

41-
get options() {
42-
let { placement } = this.args;
45+
get options(): TippyProps {
46+
const { placement } = this.args;
4347

4448
assert(
4549
'@placement for "Hds::TooltipButton" must have a valid value',
@@ -48,10 +52,9 @@ export default class HdsTooltipIndexComponent extends Component {
4852

4953
return {
5054
...this.args.extraTippyOptions,
51-
// takes string
5255
placement: placement,
53-
// takes array of 2 numbers (skidding, distance): array(0, 0)
54-
offset: this.args.offset,
56+
// takes array of 2 numbers (skidding, distance): array(0, 10)
57+
offset: this.args.offset ? this.args.offset : [0, 10],
5558
};
5659
}
5760

@@ -61,8 +64,8 @@ export default class HdsTooltipIndexComponent extends Component {
6164
* @default true
6265
* @description sets display for the button
6366
*/
64-
get isInline() {
65-
let { isInline = true } = this.args;
67+
get isInline(): boolean {
68+
const { isInline = true } = this.args;
6669
return isInline;
6770
}
6871

@@ -71,8 +74,8 @@ export default class HdsTooltipIndexComponent extends Component {
7174
* @method classNames
7275
* @return {string} The "class" attribute to apply to the component.
7376
*/
74-
get classNames() {
75-
let classes = ['hds-tooltip-button'];
77+
get classNames(): string {
78+
const classes = ['hds-tooltip-button'];
7679

7780
// add a class based on the @isInline argument
7881
if (this.isInline) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
export enum HdsTooltipPlacementValues {
7+
Top = 'top',
8+
TopStart = 'top-start',
9+
TopEnd = 'top-end',
10+
Right = 'right',
11+
RightStart = 'right-start',
12+
RightEnd = 'right-end',
13+
Bottom = 'bottom',
14+
BottomStart = 'bottom-start',
15+
BottomEnd = 'bottom-end',
16+
Left = 'left',
17+
LeftStart = 'left-start',
18+
LeftEnd = 'left-end',
19+
}
20+
21+
export type HdsTooltipPlacements = `${HdsTooltipPlacementValues}`;

packages/components/src/template-registry.ts

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ import type HdsTextComponent from './components/hds/text';
150150
import type HdsTextBodyComponent from './components/hds/text/body';
151151
import type HdsTextDisplayComponent from './components/hds/text/display';
152152
import type HdsTagComponent from './components/hds/tag';
153+
import type HdsTooltipButtonComponent from './components/hds/tooltip-button';
153154
import type HdsToastComponent from './components/hds/toast';
154155
import type HdsTextCodeComponent from './components/hds/text/code';
155156
import type HdsYieldComponent from './components/hds/yield';
@@ -700,6 +701,10 @@ export default interface HdsComponentsRegistry {
700701
'Hds::Tag': typeof HdsTagComponent;
701702
'hds/tag': typeof HdsTagComponent;
702703

704+
// TooltipButton
705+
'Hds::TooltipButton': typeof HdsTooltipButtonComponent;
706+
'hds/tooltip-button': typeof HdsTooltipButtonComponent;
707+
703708
// Toast
704709
'Hds::Toast': typeof HdsToastComponent;
705710
'hds/toast': typeof HdsToastComponent;

0 commit comments

Comments
 (0)