From 0e96bf0613600833965a3baefd8c65afb9f16114 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Wed, 2 Oct 2024 10:51:27 +0200 Subject: [PATCH 1/6] Composite: add "With Tooltip" storybook example --- .../src/composite/stories/index.story.tsx | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/components/src/composite/stories/index.story.tsx b/packages/components/src/composite/stories/index.story.tsx index d6e4999407e993..d9cfee8b5a6826 100644 --- a/packages/components/src/composite/stories/index.story.tsx +++ b/packages/components/src/composite/stories/index.story.tsx @@ -13,6 +13,7 @@ import { useContext, useMemo } from '@wordpress/element'; */ import { createSlotFill, Provider as SlotFillProvider } from '../../slot-fill'; import { Composite } from '..'; +import { Tooltip } from '../../tooltip'; const meta: Meta< typeof Composite > = { title: 'Components/Composite', @@ -353,3 +354,50 @@ const Fill = ( { children } ) => { }, }, }; + +/** + * Combining the `Tooltip` and `Composite` component has a few caveats. + * For example, the following code won't work as expected: + * + * ```jsx + * + * + * + * ``` + * + * Take a look at this story's source code to see how to correctly compose + * these two components. + */ +export const WithTooltips: StoryObj< typeof Composite > = { + ...Default, + args: { + ...Default.args, + children: ( + <> + + }> + Item one + + + ( + + + + ) } + /> + ( + + - - ) } - /> - ( - - - * - * ``` + * + * + * + * } + * /> * - * Take a look at this story's source code to see how to correctly compose - * these two components. + * // 🟢 Good + * + * + * Item one + * + * + * ``` */ export const WithTooltips: StoryObj< typeof Composite > = { ...Default, From ad4f4f33182c1b0f0ad8983565303b1d662c235d Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Wed, 2 Oct 2024 18:25:58 +0200 Subject: [PATCH 5/6] Use third item as an example to render with a custom component --- packages/components/src/composite/stories/index.story.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/components/src/composite/stories/index.story.tsx b/packages/components/src/composite/stories/index.story.tsx index c5518375df8a6f..ecafcca7141bb6 100644 --- a/packages/components/src/composite/stories/index.story.tsx +++ b/packages/components/src/composite/stories/index.story.tsx @@ -14,6 +14,7 @@ import { useContext, useMemo } from '@wordpress/element'; import { createSlotFill, Provider as SlotFillProvider } from '../../slot-fill'; import { Composite } from '..'; import { Tooltip } from '../../tooltip'; +import Button from '../../button'; const meta: Meta< typeof Composite > = { title: 'Components/Composite', @@ -389,7 +390,9 @@ export const WithTooltips: StoryObj< typeof Composite > = { Item two - Item three + }> + Item three + ), From 50466a8fe255603705ec62f4e42b8ee4eb6398c6 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Thu, 3 Oct 2024 01:15:39 +0200 Subject: [PATCH 6/6] Do not use Button for thir composite item --- packages/components/src/composite/stories/index.story.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/components/src/composite/stories/index.story.tsx b/packages/components/src/composite/stories/index.story.tsx index ecafcca7141bb6..c5518375df8a6f 100644 --- a/packages/components/src/composite/stories/index.story.tsx +++ b/packages/components/src/composite/stories/index.story.tsx @@ -14,7 +14,6 @@ import { useContext, useMemo } from '@wordpress/element'; import { createSlotFill, Provider as SlotFillProvider } from '../../slot-fill'; import { Composite } from '..'; import { Tooltip } from '../../tooltip'; -import Button from '../../button'; const meta: Meta< typeof Composite > = { title: 'Components/Composite', @@ -390,9 +389,7 @@ export const WithTooltips: StoryObj< typeof Composite > = { Item two - }> - Item three - + Item three ),