@cloudwick/astral-ui-cli 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,3 +19,4 @@ export { useOnValueChange } from "./useOnValueChange";
19
19
  export { useIsTruncated } from "./useIsTruncated";
20
20
  export { useListboxKeyboardNav } from "./useListboxKeyboardNav";
21
21
  export { useLabelPeekDismissal } from "./useLabelPeekDismissal";
22
+ export { usePartPresence, usePartRegistration } from "./usePartRegistration";
@@ -0,0 +1,27 @@
1
+ import { useCallback, useLayoutEffect, useState } from "react";
2
+
3
+ /**
4
+ * Tracks whether any instance of a compound component's part (a title, a header) is rendered. Parts
5
+ * report themselves through `usePartRegistration`, which also finds parts nested in fragments or
6
+ * wrapper components. Instances are counted, so one unmounting doesn't hide another still rendered.
7
+ */
8
+ export function usePartPresence(): [ boolean, ( mounted: boolean ) => void ] {
9
+ const [ count, setCount ] = useState( 0 );
10
+ const register = useCallback(( mounted: boolean ) => {
11
+ setCount(( current ) => current + ( mounted ? 1 : -1 ));
12
+ }, []);
13
+ return [ count > 0, register ];
14
+ }
15
+
16
+ /**
17
+ * Reports a part to the `register` callback from `usePartPresence` while it renders content.
18
+ */
19
+ export function usePartRegistration( register: (( mounted: boolean ) => void ) | undefined, hasContent: boolean ): void {
20
+ useLayoutEffect(() => {
21
+ if ( !register || !hasContent ) {
22
+ return undefined;
23
+ }
24
+ register( true );
25
+ return () => register( false );
26
+ }, [ register, hasContent ]);
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudwick/astral-ui-cli",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "CLI for installing Astral UI components in any codebase",
5
5
  "main": "dist/index.js",
6
6
  "bin": {