From 397ff6893ddadca268d27bd6c2ef3ccda52b7251 Mon Sep 17 00:00:00 2001 From: Albert Yu Date: Wed, 17 Jul 2024 17:24:24 +0800 Subject: [PATCH] Add Collapsible components and hooks --- .../components/collapsible/collapsible.md | 56 +++++++++ docs/data/base/pages.ts | 1 + docs/data/base/pagesApi.js | 24 ++++ .../base-ui/api/collapsible-content.json | 19 +++ docs/pages/base-ui/api/collapsible-root.json | 20 +++ .../base-ui/api/collapsible-trigger.json | 19 +++ .../base-ui/api/use-collapsible-content.json | 8 ++ .../base-ui/api/use-collapsible-root.json | 8 ++ .../base-ui/api/use-collapsible-trigger.json | 8 ++ .../react-collapsible/[docsTab]/index.js | 96 ++++++++++++++ docs/pages/base-ui/react-collapsible/index.js | 13 ++ docs/pages/experiments/collapsible.tsx | 119 ++++++++++++++++++ .../collapsible-content.json | 10 ++ .../collapsible-root/collapsible-root.json | 14 +++ .../collapsible-trigger.json | 10 ++ .../use-collapsible-content.json | 1 + .../use-collapsible-root.json | 1 + .../use-collapsible-trigger.json | 1 + docs/translations/translations.json | 1 + .../Content/CollapsibleContent.test.tsx | 34 +++++ .../Content/CollapsibleContent.tsx | 56 +++++++++ .../Content/CollapsibleContent.types.ts | 20 +++ .../Content/useCollapsibleContent.ts | 48 +++++++ .../Collapsible/Root/CollapsibleContext.tsx | 22 ++++ .../Collapsible/Root/CollapsibleRoot.test.tsx | 100 +++++++++++++++ .../src/Collapsible/Root/CollapsibleRoot.tsx | 60 +++++++++ .../Collapsible/Root/CollapsibleRoot.types.ts | 46 +++++++ .../src/Collapsible/Root/styleHooks.ts | 8 ++ .../Collapsible/Root/useCollapsibleRoot.ts | 47 +++++++ .../Trigger/CollapsibleTrigger.test.tsx | 34 +++++ .../Trigger/CollapsibleTrigger.tsx | 56 +++++++++ .../Trigger/CollapsibleTrigger.types.ts | 23 ++++ .../Trigger/useCollapsibleTrigger.ts | 41 ++++++ .../mui-base/src/Collapsible/index.barrel.ts | 20 +++ packages/mui-base/src/Collapsible/index.ts | 26 ++++ 35 files changed, 1070 insertions(+) create mode 100644 docs/data/base/components/collapsible/collapsible.md create mode 100644 docs/pages/base-ui/api/collapsible-content.json create mode 100644 docs/pages/base-ui/api/collapsible-root.json create mode 100644 docs/pages/base-ui/api/collapsible-trigger.json create mode 100644 docs/pages/base-ui/api/use-collapsible-content.json create mode 100644 docs/pages/base-ui/api/use-collapsible-root.json create mode 100644 docs/pages/base-ui/api/use-collapsible-trigger.json create mode 100644 docs/pages/base-ui/react-collapsible/[docsTab]/index.js create mode 100644 docs/pages/base-ui/react-collapsible/index.js create mode 100644 docs/pages/experiments/collapsible.tsx create mode 100644 docs/translations/api-docs/collapsible-content/collapsible-content.json create mode 100644 docs/translations/api-docs/collapsible-root/collapsible-root.json create mode 100644 docs/translations/api-docs/collapsible-trigger/collapsible-trigger.json create mode 100644 docs/translations/api-docs/use-collapsible-content/use-collapsible-content.json create mode 100644 docs/translations/api-docs/use-collapsible-root/use-collapsible-root.json create mode 100644 docs/translations/api-docs/use-collapsible-trigger/use-collapsible-trigger.json create mode 100644 packages/mui-base/src/Collapsible/Content/CollapsibleContent.test.tsx create mode 100644 packages/mui-base/src/Collapsible/Content/CollapsibleContent.tsx create mode 100644 packages/mui-base/src/Collapsible/Content/CollapsibleContent.types.ts create mode 100644 packages/mui-base/src/Collapsible/Content/useCollapsibleContent.ts create mode 100644 packages/mui-base/src/Collapsible/Root/CollapsibleContext.tsx create mode 100644 packages/mui-base/src/Collapsible/Root/CollapsibleRoot.test.tsx create mode 100644 packages/mui-base/src/Collapsible/Root/CollapsibleRoot.tsx create mode 100644 packages/mui-base/src/Collapsible/Root/CollapsibleRoot.types.ts create mode 100644 packages/mui-base/src/Collapsible/Root/styleHooks.ts create mode 100644 packages/mui-base/src/Collapsible/Root/useCollapsibleRoot.ts create mode 100644 packages/mui-base/src/Collapsible/Trigger/CollapsibleTrigger.test.tsx create mode 100644 packages/mui-base/src/Collapsible/Trigger/CollapsibleTrigger.tsx create mode 100644 packages/mui-base/src/Collapsible/Trigger/CollapsibleTrigger.types.ts create mode 100644 packages/mui-base/src/Collapsible/Trigger/useCollapsibleTrigger.ts create mode 100644 packages/mui-base/src/Collapsible/index.barrel.ts create mode 100644 packages/mui-base/src/Collapsible/index.ts diff --git a/docs/data/base/components/collapsible/collapsible.md b/docs/data/base/components/collapsible/collapsible.md new file mode 100644 index 0000000000..806953818c --- /dev/null +++ b/docs/data/base/components/collapsible/collapsible.md @@ -0,0 +1,56 @@ +--- +productId: base-ui +title: React Collapsible components +components: CollapsibleRoot, CollapsibleTrigger, CollapsibleContent +hooks: useCollapsibleRoot, useCollapsibleTrigger, useCollapsibleContent +githubLabel: 'component: collapsible' +waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/ +packageName: '@base_ui/react' +--- + +# Collapsible + +

Collapsible is a component that shows or hides content.

+ +{{"component": "@mui/docs/ComponentLinkHeader", "design": false}} + +{{"component": "modules/components/ComponentPageTabs.js"}} + +## Installation + +Base UI components are all available as a single package. + + + +```bash npm +npm install @base_ui/react +``` + +```bash yarn +yarn add @base_ui/react +``` + +```bash pnpm +pnpm add @base_ui/react +``` + + + +Once you have the package installed, import the component. + +```ts +import * as Collapsible from '@base_ui/react/Collapsible'; +``` + +## Anatomy + +- `` is a top-level component that facilitates communication between other components. It does not render to the DOM. +- `` is the trigger element, a `