From df39602758ae8dc3765bb48e51f7a657babfa559 Mon Sep 17 00:00:00 2001
From: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com>
Date: Fri, 9 Feb 2024 10:38:30 -0500
Subject: [PATCH] feat: exposes collapsible provider with more functionality
(#5043)
---
docs/admin/hooks.mdx | 35 +++++++++++++++++--
.../components/elements/Collapsible/index.tsx | 16 +++++----
.../elements/Collapsible/provider.tsx | 33 +++++++++++++----
.../forms/field-types/Group/index.tsx | 6 ++--
.../forms/field-types/Tabs/index.tsx | 4 +--
.../src/exports/components/utilities.ts | 1 +
6 files changed, 75 insertions(+), 20 deletions(-)
diff --git a/docs/admin/hooks.mdx b/docs/admin/hooks.mdx
index 3094b90902..4da4bd7e0d 100644
--- a/docs/admin/hooks.mdx
+++ b/docs/admin/hooks.mdx
@@ -635,6 +635,37 @@ export const CustomArrayManager = () => {
]}
/>
+### useCollapsible
+
+The `useCollapsible` hook allows you to control parent collapsibles:
+
+| Property | Description |
+|---------------------------|--------------------------------------------------------------------------------------------------------------------|
+| **`collapsed`** | State of the collapsible. `true` if open, `false` if collapsed |
+| **`isVisible`** | If nested, determine if the nearest collapsible is visible. `true` if no parent is closed, `false` otherwise |
+| **`toggle`** | Toggles the state of the nearest collapsible |
+| **`withinCollapsible`** | Determine when you are within another collaspible | |
+
+**Example:**
+
+```tsx
+import React from 'react'
+
+import { useCollapsible } from 'payload/components/utilities'
+
+const CustomComponent: React.FC = () => {
+ const { collapsed, toggle } = useCollapsible()
+ return (
+
+
I am {collapsed ? 'closed' : 'open'}
+
+
+ )
+}
+```
+
### useDocumentInfo
The `useDocumentInfo` hook provides lots of information about the document currently being edited, including the following:
@@ -774,8 +805,8 @@ const MyComponent: React.FC = () => {
return (
<>
The current theme is {theme} and autoMode is {autoMode}
-