-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Composite: stabilize new ariakit implementation #63564
Conversation
@@ -14,7 +14,7 @@ import type { Icon } from '@wordpress/icons'; | |||
import type { ButtonAsButtonProps } from '../button/types'; | |||
import type { DropdownProps } from '../dropdown/types'; | |||
import type { WordPressComponentProps } from '../context'; | |||
import type { CompositeStore } from '../composite/v2'; | |||
import type { Store as CompositeStore } from '../composite'; |
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.
Same as above for types — I went for Store
as I expect consumers to consume this API as Composite.Store
(or by aliasing the import like in this case)
packages/components/src/composite/current/stories/index.story.tsx
Outdated
Show resolved
Hide resolved
@@ -15,7 +15,8 @@ import { | |||
import { UseCompositeStatePlaceholder, transform } from './utils'; | |||
|
|||
const meta: Meta< typeof UseCompositeStatePlaceholder > = { | |||
title: 'Components/Composite', | |||
// TODO: should we keep this story around? If so, how should we call it? | |||
title: 'Components/Composite/Legacy', |
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.
Probably @mirka is best-suited for the above TODO question. Also, see other comment on the current implementation's Storybook title
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.
Maybe we should keep it like we keep other deprecated component stories (like Navigation
)?
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.
Yes, I think we should keep it as long as it's available in the package. As for how, my recommendation would be like this:
diff --git a/packages/components/src/composite/legacy/stories/index.story.tsx b/packages/components/src/composite/legacy/stories/index.story.tsx
index 08eebc65ed..d3d3205afe 100644
--- a/packages/components/src/composite/legacy/stories/index.story.tsx
+++ b/packages/components/src/composite/legacy/stories/index.story.tsx
@@ -15,8 +15,8 @@ import {
import { UseCompositeStatePlaceholder, transform } from './utils';
const meta: Meta< typeof UseCompositeStatePlaceholder > = {
- // TODO: should we keep this story around? If so, how should we call it?
- title: 'Components/Composite/Legacy',
+ title: 'Components (Deprecated)/Composite (Unstable)',
+ id: 'components-composite-unstable',
component: UseCompositeStatePlaceholder,
subcomponents: {
// @ts-expect-error Storybook doesn't like overloaded exports as subcomponents
diff --git a/packages/components/src/composite/legacy/stories/utils.tsx b/packages/components/src/composite/legacy/stories/utils.tsx
index 06edd34863..2fb51c845f 100644
--- a/packages/components/src/composite/legacy/stories/utils.tsx
+++ b/packages/components/src/composite/legacy/stories/utils.tsx
@@ -8,6 +8,25 @@ import type { StoryContext } from '@storybook/react';
*/
import type { LegacyStateOptions } from '..';
+/**
+ * Renders a composite widget.
+ *
+ * This unstable component is deprecated. Use `Composite` instead.
+ *
+ * ```jsx
+ * import {
+ * __unstableUseCompositeState as useCompositeState,
+ * __unstableComposite as Composite,
+ * __unstableCompositeItem as CompositeItem,
+ * } from '@wordpress/components';
+ *
+ * const state = useCompositeState();
+ * <Composite state={ state }>
+ * <CompositeItem>Item 1</CompositeItem>
+ * <CompositeItem>Item 2</CompositeItem>
+ * </Composite>;
+ * ```
+ */
export function UseCompositeStatePlaceholder( props: LegacyStateOptions ) {
return (
<dl>
The important points being:
- It needs to be clear that we're referring to the
__unstable
version, and that it's deprecated. - Usually we want to ensure that we don't break permalinks, but in this specific case I think we would cause the less damage if we just made a clean break and changed the URLs so it reflects the new situation.
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.
Sounds good, done in b3e58bc
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thanks for working on this one @ciampo! Excited about stabilizing the Ariakit version of Composite
!
This looks and works great overall!
Left some comments and questions, some might be naive, so take them with a grain of salt 😉
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.
This LGTM, and tests well 👍
I acknowledge that there are a bunch of follow-ups after merging this one, and that's more than fine. Smaller changes always win!
🚀
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.
Waiting for an agreement on #63714, but just to add a concrete example to what I'm suggesting in #63714 (comment), I think Composite is a case where we don't need a .Root
. The basic, default API should always start with MyComponent
, and only when we need to provide a more low-level API in parallel, do we need a MyComponent.Root
. Most consumers should never have to deal with a .Root
. It's almost like the escape hatch for us as a component library. What do you think?
Just pointing out that I agree with that and brought a similar point up previously in my review here. |
760fbb8
to
fde527a
Compare
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.
With a bunch of follow-ups to come as discussed earlier, this looks good to me! 🚀
Excited to see it stable!
@@ -15,7 +15,8 @@ import { | |||
import { UseCompositeStatePlaceholder, transform } from './utils'; | |||
|
|||
const meta: Meta< typeof UseCompositeStatePlaceholder > = { | |||
title: 'Components/Composite', | |||
// TODO: should we keep this story around? If so, how should we call it? | |||
title: 'Components/Composite/Legacy', |
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.
Maybe we should keep it like we keep other deprecated component stories (like Navigation
)?
…ect results in Storybook
Composite.Item should pick up the store from context without explicit prop
e9e14e5
to
c41ff65
Compare
Thank you for the final round of review. I've updated the README and marked the I'll merge as soon as CI checks pass 🟢 |
Flaky tests detected in c41ff65. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10317162077
|
* Point legacy exports directly to the source (instead of folder root) * Swap default folder export to new version * Apply compound component naming * Export new version from the package * Update (fix) private APIs exports * Update composite implementation to use new compound naming * Update references to Composite inside components package * Update Storybook entry points for both legacy and current * Fix Storybook generated docs * Add todo * Remove unncecessary code * CHANGELOG * README * Add JSDocs to Composite exports * Move current implementation out of `current` folder * Fix import in the legacy implementation * Update docs manifest * Fix type in Storybook example * Add JSDocs for Storybook docs * Apply Overloaded naming convention * Update README * Fix typo * Update legacy storybook title/id, make sure JSDocs refer to unstable version * Derive types instead of importing them directly from ariakit * Add JSDoc snippet for stable component * Remove unnecessary JSDoc code * Remove unnecessary display name * Assign display names via Object.assign to comply with TS and get correct results in Storybook * Update subcomponent TS ignore comment to align with other components * Remove unnecessary store prop in circular option picker Composite.Item should pick up the store from context without explicit prop * Add first-party types, rewrite components with one unique forwardRef call * Use the newly added types instead of using the Parameters<> util * Fix Storybook story type * Remove unnecessary ts-expect-error * Use `CompositeStore` type directly * Manual Storybook args table * Tweak display name fallback * README * Mark `store` prop on `Composite` as required --- Co-authored-by: ciampo <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: mirka <[email protected]>
What?
Extracted from #63364
Part of #58850
Export the new
ariakit
-basedComposite
component from the@wordpress/components
package.Why?
The component has been available via private APIs for a while without causing issues. It's time to stabilize it!
How?
@wordpress/components
packageNote: from the point of view of a consumer of
@wordpress/components
, this PR only adds new APIs and shouldn't require any code changes.Follow-ups
Testing Instructions
No changes were made to how the component works, only to how it's exported / imported.
Smoke test that usages of the component both in Storybook and in the editor work as on trunk.
Reviewing commit-by-commit may help.