-
Notifications
You must be signed in to change notification settings - Fork 44
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
TooltipButton
: Converted component to TypeScript
#2317
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hashicorp/design-system-components": minor | ||
--- | ||
|
||
`TooltipButton`: Converted component to TypeScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,29 +6,33 @@ | |
import Component from '@glimmer/component'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export const PLACEMENTS = [ | ||
'top', | ||
'top-start', | ||
'top-end', | ||
'right', | ||
'right-start', | ||
'right-end', | ||
'bottom', | ||
'bottom-start', | ||
'bottom-end', | ||
'left', | ||
'left-start', | ||
'left-end', | ||
]; | ||
import type { Props as TippyProps } from 'tippy.js'; | ||
import { HdsTooltipPlacementValues } from './types.ts'; | ||
|
||
export default class HdsTooltipIndexComponent extends Component { | ||
export const PLACEMENTS: string[] = Object.values(HdsTooltipPlacementValues); | ||
|
||
export interface HdsTooltipIndexSignature { | ||
Args: { | ||
extraTippyOptions: Omit<TippyProps, 'placement' | 'offset'>; | ||
isInline?: boolean; | ||
offset?: [number, number]; | ||
placement: HdsTooltipPlacementValues; | ||
text: string; | ||
}; | ||
Blocks: { | ||
default: []; | ||
}; | ||
Element: HTMLButtonElement; | ||
} | ||
|
||
export default class HdsTooltipIndexComponent extends Component<HdsTooltipIndexSignature> { | ||
/** | ||
* @param text | ||
* @type {string} | ||
* @description text content for tooltip | ||
*/ | ||
get text() { | ||
let { text } = this.args; | ||
get text(): string { | ||
const { text } = this.args; | ||
|
||
assert( | ||
'@text for "Hds::TooltipButton" must have a valid value', | ||
|
@@ -38,8 +42,8 @@ export default class HdsTooltipIndexComponent extends Component { | |
return text; | ||
} | ||
|
||
get options() { | ||
let { placement } = this.args; | ||
get options(): TippyProps { | ||
const { placement } = this.args; | ||
|
||
assert( | ||
'@placement for "Hds::TooltipButton" must have a valid value', | ||
|
@@ -48,10 +52,10 @@ export default class HdsTooltipIndexComponent extends Component { | |
|
||
return { | ||
...this.args.extraTippyOptions, | ||
// takes string | ||
placement: placement, | ||
// takes array of 2 numbers (skidding, distance): array(0, 0) | ||
offset: this.args.offset, | ||
showOnCreate: true, | ||
// takes array of 2 numbers (skidding, distance): array(0, 10) | ||
offset: this.args.offset ? this.args.offset : [0, 10], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: turns out the default if offset is not provided is [0,10] not [0,0] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! 👏 |
||
}; | ||
} | ||
|
||
|
@@ -61,8 +65,8 @@ export default class HdsTooltipIndexComponent extends Component { | |
* @default true | ||
* @description sets display for the button | ||
*/ | ||
get isInline() { | ||
let { isInline = true } = this.args; | ||
get isInline(): boolean { | ||
const { isInline = true } = this.args; | ||
return isInline; | ||
} | ||
|
||
|
@@ -71,8 +75,8 @@ export default class HdsTooltipIndexComponent extends Component { | |
* @method classNames | ||
* @return {string} The "class" attribute to apply to the component. | ||
*/ | ||
get classNames() { | ||
let classes = ['hds-tooltip-button']; | ||
get classNames(): string { | ||
const classes = ['hds-tooltip-button']; | ||
|
||
// add a class based on the @isInline argument | ||
if (this.isInline) { | ||
|
16 changes: 16 additions & 0 deletions
16
packages/components/src/components/hds/tooltip-button/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export enum HdsTooltipPlacementValues { | ||
Top = 'top', | ||
TopStart = 'top-start', | ||
TopEnd = 'top-end', | ||
Right = 'right', | ||
RightStart = 'right-start', | ||
RightEnd = 'right-end', | ||
Bottom = 'bottom', | ||
BottomStart = 'bottom-start', | ||
BottomEnd = 'bottom-end', | ||
Left = 'left', | ||
LeftStart = 'left-start', | ||
LeftEnd = 'left-end', | ||
} | ||
|
||
export type HdsTooltipPlacements = `${HdsTooltipPlacementValues}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: since placement and offset will always get overwritten on line 53, I figure we just omit them from the type to avoid confusion.