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

Move tooltip to next #887

Merged
merged 6 commits into from
Mar 15, 2022
Merged

Move tooltip to next #887

merged 6 commits into from
Mar 15, 2022

Conversation

jinlee93
Copy link
Contributor

@jinlee93 jinlee93 commented Mar 8, 2022

[sc-187512]

Summary:

  • moves Tooltip from v0.8.1 to next
  • remove TW use
  • use CSS custom properties
  • convert styles to BEM
  • add storybook testing libraries

Test Plan:

  • tests pass
  • manual testing
Screen.Recording.2022-03-07.at.4.27.39.PM.mov

@jinlee93 jinlee93 requested review from bradfrost and a team March 8, 2022 00:50
@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #887 (6db6e9f) into next (cf1fb18) will increase coverage by 18.08%.
The diff coverage is 90.76%.

Impacted file tree graph

@@             Coverage Diff             @@
##             next     #887       +/-   ##
===========================================
+ Coverage   61.70%   79.78%   +18.08%     
===========================================
  Files           2        4        +2     
  Lines          47       94       +47     
  Branches       21       27        +6     
===========================================
+ Hits           29       75       +46     
- Misses         17       18        +1     
  Partials        1        1               
Impacted Files Coverage Δ
src/components/Button/Button.tsx 82.75% <80.00%> (+1.27%) ⬆️
src/components/Tooltip/Tooltip.tsx 95.83% <95.23%> (ø)
src/components/Tooltip/Tooltip.stories.tsx 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf1fb18...6db6e9f. Read the comment docs.

);
};
export default Tooltip;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed the original components were not exporting default, is that something we should also do?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah, that's funny. They're always importing components like import { Button } from '../Button/Button';. I personally prefer exporting default, but I don't feel strongly about this since in the app they're going to import components like that anyway (import {Button} from "@chanzuckerberg/eds-components";).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it hurts for us to have the extra Button/index.ts file, and like the extra flexibility it gives 🙂 if that's not reflected in the plop-templates could you update them as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

@anniehu4 @dierat @jinlee93 This is all good stuff, and happy to adopt whatever ergonomic things like this help the cause. FWIW, I wrote a post that broke down the pros and cons of all these approaches: https://bradfrost.com/blog/post/this-or-that-component-names-index-js-or-component-js/

buttonText,
...other
}) => {
variant?: 'light' | 'dark';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be inverted?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure 🤔 inverted is when the color scheme is inverted so it will have enough contrast on a dark background, but both of these variants work on light and dark backgrounds. Actually, this might be a good time to bring up whether we really need both of them, and, if we do, what are the guidelines around when to use which?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah that's a great point @dierat

Copy link
Contributor

Choose a reason for hiding this comment

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

Flagged this conundrum with the team over here and we're hopefully helping make some calls here: https://bigmedium.slack.com/archives/C0310HJ9WEN/p1646949365214339

border-style: solid;
border-width: var(--eds-border-width-sm);
border-radius: var(--eds-border-radius-lg);
box-shadow: var(--eds-theme-box-shadow);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this shadow is thinner than the original shadow, but using what is available for consistency
original on the left, this pr on the right:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we need a ticket for updating the tokens 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I think all tokens are subject to change while design is doing discovery right now; so we can feel free to replace the values with our existing ones

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, to clarify, are you saying to add a token to shadows.json, or not using a token for now and assigning a value to box-shadow?

Copy link
Contributor

@anniehu4 anniehu4 Mar 8, 2022

Choose a reason for hiding this comment

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

either add a token to shadows.json or update one of the base tokens to match ours 🙂 we should always be using a tier 2 token, but the values are owned by us, and will probably evolve over the next few weeks. so not sure it's worth to update all of them up front, but if we notice discrepancies we can default to the values we were already using for the component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks for the explanation, will update shadow token md,

Copy link
Contributor

Choose a reason for hiding this comment

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

@anniehu4 @jinlee93 @dierat yep the token work is firming up, and I'm going to take the lead on an initial import of what they've put in place in Figma. Hoping to get that in there by the end of the day.

@@ -0,0 +1,20 @@
.trigger--spacing {
margin: 9rem;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weird number but it's appropriate required for the tooltip to place where alignment is indicated, otherwise Tippy places somewhere else due to lack of space

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe leave that in a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, added comment

Copy link
Contributor

Choose a reason for hiding this comment

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

let's also do the footnote commenting thing brad had, i.e.:

Suggested change
margin: 9rem;
margin: 9rem; /* 1 */

to note that this specific line is connected to the 1) comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

Comment on lines 9 to 13
/* TODO: replace ForwardRefButton with EDS button since it's already using forwardRef */
const ForwardRefButton = React.forwardRef((props: Props, ref) => (
<Button {...props} buttonRef={ref} />
));
ForwardRefButton.displayName = 'ForwardRefButton';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required for for Tippy. Button that will be imported from EDS already uses forwardRef

@@ -88,7 +88,7 @@ Here's another example:

### CSS Nesting

EDS uses [PostCSS Nested](https://github.com/postcss/postcss-nested) to provide some developer ergononics. As a general principle, nesting should be used sparingly and is only used in the following situations:
EDS uses [PostCSS Nested](https://github.com/postcss/postcss-nested) to provide some developer ergonomics. As a general principle, nesting should be used sparingly and is only used in the following situations:
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow thanks for all the spelling updates! ❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

I somehow feel like this was some sort of test and you passed.

@@ -20,6 +21,19 @@ Default.args = {
plusButtonText: 'Add by 1',
};

/* TODO: replace <ForwardRefButton> with EDS button since it's already using forwardRef */
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

could we quickly add forwardRef to the existing button now? not sure how long EDS button conversion will take & it's nicer not having to hunt down TODOs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep we can, and will do

*/
children?: ReactNode;
content?: React.ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be text based on the prop guidelines Big Medium uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to text, thanks

Comment on lines 22 to 24
* The visually-hidden button text for the tooltip trigger button
* The trigger element the tooltip appears next to.
*
* Use this instead of `children` if the trigger element is being
* stored in a ref. Most cases will use `children` and not
* `reference`.
*/
buttonText?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't figure out what this prop was 🤔 Do you understand the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhh not sure what the comment means but the b/m tooltip also exported the trigger button, and buttonText is for the text inside the trigger button
image
Screen Shot 2022-03-08 at 11 06 04 AM


useEffect(() => {
if (isActive) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that their version of the component is focusable. I wonder why.

Copy link
Contributor Author

@jinlee93 jinlee93 Mar 8, 2022

Choose a reason for hiding this comment

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

Hmmm in my understanding, tooltip does not receive focus

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe they were trying to handle tooltips w/ interactive content 🤔 we don't want that tho

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #187512: Move Tooltip to new architecture.

Comment on lines +113 to +114
variant === 'light' && styles['tooltip--light'],
variant === 'dark' && styles['tooltip--dark'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if we've cleared with BM if we're using ampersands or object literals for these subjective classes? The code guidelines still has it using the object literals, but I think we want to keep using the ampersands. https://github.com/chanzuckerberg/edu-design-system/blob/next/docs/CODE_GUIDELINES.md#define-componentclassname

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh good q, I do like ampersands b/c I feel like it's easier to read

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they wanted to see an example in code first. So here it is! @bradfrost @ifrost1 @csnizik any concerns with this syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Via offline eng sync, committing to this style of syntax

@dierat
Copy link
Contributor

dierat commented Mar 8, 2022

Very nice!

So the open questions I still have about our process based on seeing this change are:

  • Do we need a ticket to update the tokens (ex: shadows)?
  • Should inverted be used in a case like this where there are two light/dark colors schemes but it's not related to dark backgrounds or dark mode?
  • Do we still need 2 colors schemes for tooltips?
  • Should we export a default?
  • Are we using objects literals or ampersands for subjective classes (ex: size === 'lg' && styles['my-component--lg' vs {[styles['my-component--lg']]: size === 'lg'}? (If using ampersands, we should update the code guidelines.)

Does that sound right?

@jinlee93
Copy link
Contributor Author

jinlee93 commented Mar 8, 2022

Does that sound right?

Yup that sounds right, thanks for surfacing these questions

<Tippy
{...rest}
className={clsx(
styles.tooltip,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really small thing but I wonder if we want to use the brackets and quotation syntax for class names all the time for consistency or not (I see they used styles['tooltip'] in their version of the component).

Copy link
Contributor

Choose a reason for hiding this comment

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

let's be consistent with the brackets + quotes


export interface Props {
// Full list of Tippy props: https://atomiks.github.io/tippyjs/v6/all-props/
type TooltipProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed that they use Prop and we use component name + Props. We often have several sub components in a file, so it may make sense to just keep using component name + Props for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will change to Prop and also export it

@@ -20,6 +21,19 @@ Default.args = {
plusButtonText: 'Add by 1',
};

/* TODO: replace <ForwardRefButton> with EDS button since it's already using forwardRef */
Copy link
Contributor

Choose a reason for hiding this comment

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

could we quickly add forwardRef to the existing button now? not sure how long EDS button conversion will take & it's nicer not having to hunt down TODOs

@@ -1,72 +1,126 @@
@import '../../design-tokens/mixins.css';
/* stylelint-disable selector-pseudo-class-no-unknown */
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add to stylelintrc

border-style: solid;
border-width: var(--eds-border-width-sm);
border-radius: var(--eds-border-radius-lg);
box-shadow: var(--eds-theme-box-shadow);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think all tokens are subject to change while design is doing discovery right now; so we can feel free to replace the values with our existing ones

@@ -0,0 +1,20 @@
.trigger--spacing {
margin: 9rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

let's also do the footnote commenting thing brad had, i.e.:

Suggested change
margin: 9rem;
margin: 9rem; /* 1 */

to note that this specific line is connected to the 1) comment above

*/
align?: 'right' | 'below' | 'left';
children?: React.ReactElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we keep the props alphabetized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Alphabetizing

buttonText,
...other
}) => {
variant?: 'light' | 'dark';
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah that's a great point @dierat


useEffect(() => {
if (isActive) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe they were trying to handle tooltips w/ interactive content 🤔 we don't want that tho

<Tippy
{...rest}
className={clsx(
styles.tooltip,
Copy link
Contributor

Choose a reason for hiding this comment

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

let's be consistent with the brackets + quotes

);
};
export default Tooltip;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it hurts for us to have the extra Button/index.ts file, and like the extra flexibility it gives 🙂 if that's not reflected in the plop-templates could you update them as well?

Comment on lines +113 to +114
variant === 'light' && styles['tooltip--light'],
variant === 'dark' && styles['tooltip--dark'],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think they wanted to see an example in code first. So here it is! @bradfrost @ifrost1 @csnizik any concerns with this syntax?

@jinlee93 jinlee93 requested a review from csnizik March 9, 2022 00:05
Comment on lines 39 to 40
aria-label="Hover this button to trigger the tooltip"
text="Hover this button to trigger the tooltip"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - I don't think you need both the text and aria-label here since they're the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

Copy link
Contributor

@dierat dierat left a comment

Choose a reason for hiding this comment

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

I saw go ahead without deprecating the dark variant; we can do that separately.

@jinlee93
Copy link
Contributor Author

I saw go ahead without deprecating the dark variant; we can do that separately.

Sounds good to me

@jinlee93
Copy link
Contributor Author

jinlee93 commented Mar 15, 2022

Will go ahead and merge as comments have been addressed. Deprecating the dark variant can be done in a separate PR after clearer deprecation guidelines have been established, and deprecation badge for storybook has been merged

@jinlee93 jinlee93 merged commit 1a3968f into next Mar 15, 2022
@jinlee93 jinlee93 deleted the jlee/moveTooltip branch March 15, 2022 20:27
anniehu4 pushed a commit that referenced this pull request Apr 20, 2022
* chore: move Tooltip to next

* chore: update counter story since it uses tooltip

* chore: add tooltip styling comments

* chore: update prop and comments

* chore: respond to comments

* chore: nit: remove redundant prop in story
anniehu4 pushed a commit that referenced this pull request Apr 20, 2022
* chore: move Tooltip to next

* chore: update counter story since it uses tooltip

* chore: add tooltip styling comments

* chore: update prop and comments

* chore: respond to comments

* chore: nit: remove redundant prop in story
anniehu4 pushed a commit that referenced this pull request May 12, 2022
anniehu4 pushed a commit that referenced this pull request May 13, 2022
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.

4 participants