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

WP-96: Tooltip Web Component #78

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

harshdeep-gill
Copy link
Contributor

@harshdeep-gill harshdeep-gill commented Sep 24, 2024

Hi @junaidbhura , please take a look at this PR, I am raising this to seek your insights whether I am heading in the right direction.

Here, I have used popover API as you suggested.

Features:

  • We can wrap any element with tp-tooltip-trigger ( it can be a icon, div, cell, or anchor tag, etc. ) and on hovering that particular element the popup will be shown.
  • The arrow position of the tooltip will always remain at the centre of the trigger.
  • Tooltip will adjust itself vertically. If there is not enough space at the top it will shift towards downward otherwise it will be at the top.
  • The popover element will also adjust it horizontally, if there is not enough space at the left it will align itself according to the left edge of the parent container of to-tooltip, and similarly for the right side (here it will align with the right edge of the parent container.)
  • Everything is customizable, popover styles, trigger styles, etc.

Please ignore any hard coded values in the code, I am still working on as making this more customizable.

I would suggest you to please run it locally to have a better look at functionality.

Thank you.


<link rel="stylesheet" href="../../dist/tooltip/style.css" media="all">
<script type="module" src="../../dist/tooltip/index.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's make this file bare-bones and only contain code and styles that are absolutely required (won't work without it)

<main >
<tp-tooltip>
<tp-tooltip-trigger>
<div class="my-btn">Hover Me</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's use a button tag so the user has full control over the markup

</head>
<body style="padding: 0; margin: 0">
<main >
<tp-tooltip>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's remove this component, and allow the user to be define their own ID

}

tp-tooltip-popover {
--arrow-top-positioning: 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's rename to --tp-tooltip-popover-arrow-top-position


tp-tooltip-popover {
--arrow-top-positioning: 0;
--arrow-left-positioning: 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's rename to --tp-tooltip-popover-arrow-left-position

@@ -0,0 +1,29 @@
tp-tooltip-trigger > button {
background-color: transparent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's remove all styles that are not essential

&::backdrop {
width: 0;
height: 0;
border-width: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's make all these styles as bare-bones as possible

<i>i</i>
</div>
</tp-tooltip-trigger>
<tp-tooltip-popover style="width: 265px;">Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia molestiae distinctio tempore nobis rem provident libero voluptatum excepturi optio pariatur, accusantium minus ex, doloremque a, repellendus iure quae eaque consectetur!</tp-tooltip-popover>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harshdeep-gill Let's add <tp-tooltip-arrow></tp-tooltip-arrow> here so that the user can have full control over the arrow's styles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants