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

feat(tooltip): composable tooltips - phase 1 #1725

Merged
merged 42 commits into from
Jul 22, 2022

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Jun 23, 2022

Summary

Redesigns tooltip styles and adds composable tooltip components for users to develop custom tooltip configurations. Adds the option for header and tooltip on the default tooltip that provides the tooltip items for contextual headers and footers.

Screen Recording 2022-07-06 at 07 36 05 PM

BREAKING CHANGES: Settings.tooltip is deprecated in favor of the new Tooltip spec. Type changes related to TooltipProps, TooltipSettings and others see #1725. Changes to tooltip styles from dark to light theme. The Annotation tooltip class .echAnnotation used to target the icon, but now refers to the tooltip itself similar to .echTooltip and now .echAnnotation__marker refers to the icon itself.

 const tooltipProps = {...};
 <Chart>
-  <Settings tooltip={tooltipProps} />
+  <Tooltip {...tooltipProps} />
 </Chart>

Details

Demo the tooltip in storybook here.

This pr decouples the existing tooltip components into exported atomic elements to make it easier to compose a tooltip as a list or table while maintaining styles. Cleans-up and simplifies tooltip logic and styles to reuse the same composable components.

New Tooltip Spec

The Settings.tooltip option is now deprecated in favor of the new Tooltip spec. All options are the same such that Settings.tooltip can be spread over the Tooltip option, such as...

 const tooltipProps = {...};
 <Chart>
-  <Settings tooltip={tooltipProps} />
+  <Tooltip {...tooltipProps} />
 </Chart>

New components

Tooltip components

  • TooltipWrapper - Used as wrapper around content (i.e. .echTooltip)
  • TooltipHeader
  • TooltipMetricRow
  • TooltipFooter

Tabular Tooltip components

  • TooltipTable
  • TooltipTableHeader
  • TooltipTableBody
  • TooltipTableFooter
  • TooltipTableRow
  • TooltipTableCell
  • TooltipTableColorCell

Tooltip portal ref changes

These changes improve and simplify the internal ref logic related to the tooltip and portals. The main api change is that now the anchor prop on the TooltipPortal allows for passing a ref (i.e. PortalAnchorRef) being an actual dom element ref or passing an indirect ref and position (i.e. PositionedPortalAnchorRef) which will be used to create an pseudo-ref to place tooltip.

 <TooltipPortal
   scope="MainTooltip"
-  anchor={{
-    position,
-    ref: chartRef.current,
-  }}
+  anchor={
+    anchorRef ?? {
+      position,
+      appendRef: chartRef,
+    }
+  }
 />

Type changes

Added types

The PropsOrChildrenWithProps type allows for simple type to defined a union between rendering props which includes children (i.e. PropsWithChildren) or render props that exclude children (i.e. PropsWithoutChildren). This enables a flexible component that can be used in either case and split the props respective of the usage.

type TooltipTableProps = PropsOrChildrenWithProps<
  { // properties only when children is not defined
    columns: TooltipTableColumn[];
    items: TooltipValue[];
  },
  { // properties only when children is defined
    dir: string;
  },
  { // shared properties
    maxHeight?: CSSProperties['maxHeight'];
  }
>;

<TooltipTable columns={columns} items={items} />
// or
<TooltipTable dir="lrt">Some children</TooltipTable>

Note: When children is passed columns and items are not permitted, only dir and vise versa. Then maxHeight is shared and permitted for either case.

Adds TooltipTableColumn to define the columns for generating a tabular tooltip.

Changed types

  • TooltipSettings - Used to unionize the string tooltip type and the TooltipProps object. This is no longer needed and is deprecated to be removed soon.
  • TooltipValue - Now accepts Datum and SeriesIdentifier generics to narrow type for different chart types.
  • TooltipProps - To maintain naming conventions for all spec props to be exported as <Spec>Props name. The old TooltipProps type was used to define all tooltip settings. The new TooltipProps type defines to props of the new Tooltip spec which overlaps all previous values, so should be minimal impact.
  • XYChartSeriesIdentifier - Adds xAccessor string

Issues

related to #615

Checklist

  • The proper chart type label has been added (e.g. :xy, :partition)
  • The proper feature labels have been added (e.g. :interactions, :axis)
  • The :theme label has been added and the @elastic/eui-design team has been pinged when there are Theme API changes
  • All related issues have been linked (i.e. closes #123, fixes #123)
  • New public API exports have been added to packages/charts/src/index.ts
  • Unit tests have been added or updated to match the most common scenarios
  • The proper documentation and/or storybook story has been added or updated
  • The code has been checked for cross-browser compatibility (Chrome, Firefox, Safari, Edge)
  • Visual changes have been tested with all available themes including dark, light, eui-dark & eui-light

@nickofthyme nickofthyme added :styling Styling related issue :tooltip Related to hover tooltip :all Applies to all chart types design labels Jun 23, 2022
@github-actions github-actions bot temporarily deployed to PR #1725 June 23, 2022 16:01 Inactive
@nickofthyme nickofthyme added ci:skip Skip all build checks and removed ci:skip Skip all build checks labels Jun 30, 2022
- Use tooltip provider for internal style pass through
- Add column definitions to control table renderings
- Improve color strip styles to render nicely in all cases
- Add empty column/row states and logic to hide empties
- Add rtl support
- Add styles overrides for tooltip table components
- Add highlighted row styles
- Remove obsolete list styles
@nickofthyme nickofthyme removed the ci:skip Skip all build checks label Jul 7, 2022
- Create new Tooltip spec for applying tooltip options
- Merge deprecated legacy tooltip options from settings
- Dry up all getSpecs repeated usages
- Remove over simplified tooltip setting selectors
- Remove unused tooltip default constants
@nickofthyme
Copy link
Collaborator Author

buildkite update vrt

elastic-datavis bot and others added 6 commits July 20, 2022 04:28
- remove hideColor option and provider sync logic
- add color, text, number and custom tooltip table column types
- implement pass-through of generic types through all new types
- fix missing generic type when using ComponentProps helper type
- cleanup tooltip component api and render logic
@nickofthyme
Copy link
Collaborator Author

@markov00 I updated the things we talked about this morning, namely:

  • Remove hideColor global option
  • Add tooltip table column types which include color, text, number and custom.
  • Improved the generic typings to pass-through all the goodness!

Additionally, I added the option for a header and/or footer on the default tooltip in . This would enable something like...

<Tooltip header={(items) => items.find(({ isHighlighted }) => isHighlighted)?.label ?? null} />

Screen Recording 2022-07-20 at 06 00 48 PM


I still want to look at renaming some of the properties in the column types (i.e. renderCell). Will look at this tomorrow but feel free to add your ideas! 👍🏼

@nickofthyme
Copy link
Collaborator Author

buildkite update vrt

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

It looks great, I've left a few minor comments, but code-wise looks perfect.

@nickofthyme nickofthyme enabled auto-merge (squash) July 21, 2022 19:52
@nickofthyme nickofthyme merged this pull request into elastic:master Jul 22, 2022
@nickofthyme nickofthyme deleted the composible-tooltip branch July 22, 2022 09:24
nickofthyme added a commit that referenced this pull request Jul 22, 2022
Redesigned tooltip styles and adds composable tooltip components for users to develop custom tooltip configurations. Adds the option for `header` and `tooltip` on the default tooltip that provides the tooltip items for contextual headers and footers.

BREAKING CHANGE: `Settings.tooltip` is deprecated in favor of the new `Tooltip` spec. Type changes related to `TooltipProps`, `TooltipSettings` and others see #1725. Changes to tooltip styles from dark to light theme. The Annotation tooltip class `.echAnnotation` used to target the icon, but now refers to the tooltip itself similar to `.echTooltip` and now `.echAnnotation__marker` refers to the icon itself.

```diff
 const tooltipProps = {...};
 <Chart>
-  <Settings tooltip={tooltipProps} />
+  <Tooltip {...tooltipProps} />
 </Chart>
```
nickofthyme pushed a commit that referenced this pull request Jul 22, 2022
# [47.0.0](v46.13.0...v47.0.0) (2022-07-22)

### Bug Fixes

* **deps:** update dependency @elastic/eui to ^60.3.0 ([#1755](#1755)) ([623b19f](623b19f))

### Features

* **tooltip:** composable tooltips - phase 1 ([#1725](#1725)) ([e79fa20](e79fa20))

### BREAKING CHANGES

* **tooltip:** `Settings.tooltip` is deprecated in favor of the new `Tooltip` spec. Type changes related to `TooltipProps`, `TooltipSettings` and others see #1725. Changes to tooltip styles from dark to light theme. The Annotation tooltip class `.echAnnotation` used to target the icon, but now refers to the tooltip itself similar to `.echTooltip` and now `.echAnnotation__marker` refers to the icon itself.

```diff
 const tooltipProps = {...};
 <Chart>
-  <Settings tooltip={tooltipProps} />
+  <Tooltip {...tooltipProps} />
 </Chart>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:all Applies to all chart types breaking change design :styling Styling related issue :tooltip Related to hover tooltip
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants