-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4688]chore: added collapsible to propel #7643
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cff9e06
chore: added collapsibl to propel
vamsikrishnamathala e2d89d3
fix: export path
vamsikrishnamathala 972acdc
chore: made collapsible a compound component
vamsikrishnamathala 1d70774
Merge branch 'preview' into chore-collapsible_migration_propel
vamsikrishnamathala 1d2e06d
fix: lint and format errors
vamsikrishnamathala 4fd68ff
Merge branch 'preview' of github.com:makeplane/plane into chore-colla…
vamsikrishnamathala ab10fa1
chore: updated propel exports order and added collapsible to tsdown c…
vamsikrishnamathala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import React, { useState, useEffect, useCallback, createContext, useContext } from "react"; | ||
| import { Collapsible as BaseCollapsible } from "@base-ui-components/react/collapsible"; | ||
| import clsx from "clsx"; | ||
|
|
||
| // Types | ||
| type CollapsibleContextType = { | ||
| isOpen: boolean; | ||
| onToggle: () => void; | ||
| }; | ||
|
|
||
| type RootProps = { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| isOpen?: boolean; | ||
| onToggle?: () => void; | ||
| defaultOpen?: boolean; | ||
| }; | ||
|
|
||
| type TriggerProps = { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| buttonRef?: React.RefObject<HTMLButtonElement>; | ||
| }; | ||
|
|
||
| type ContentProps = { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| }; | ||
|
|
||
| // Context | ||
| const CollapsibleContext = createContext<CollapsibleContextType | undefined>(undefined); | ||
|
|
||
| // Hook | ||
| const useCollapsible = () => { | ||
| const context = useContext(CollapsibleContext); | ||
| if (!context) { | ||
| throw new Error("Collapsible compound components cannot be rendered outside the Collapsible component"); | ||
| } | ||
| return context; | ||
| }; | ||
|
|
||
| // Components | ||
| const Root: React.FC<RootProps> = ({ children, className, isOpen: controlledIsOpen, onToggle, defaultOpen }) => { | ||
| const [localIsOpen, setLocalIsOpen] = useState<boolean>(controlledIsOpen || defaultOpen || false); | ||
vamsikrishnamathala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| useEffect(() => { | ||
| if (controlledIsOpen !== undefined) { | ||
| setLocalIsOpen(controlledIsOpen); | ||
| } | ||
| }, [controlledIsOpen]); | ||
|
|
||
| const handleToggle = useCallback(() => { | ||
| if (controlledIsOpen !== undefined) { | ||
| onToggle?.(); | ||
| } else { | ||
| setLocalIsOpen((prev) => !prev); | ||
| } | ||
| }, [controlledIsOpen, onToggle]); | ||
|
|
||
| return ( | ||
| <CollapsibleContext.Provider value={{ isOpen: localIsOpen, onToggle: handleToggle }}> | ||
| <BaseCollapsible.Root | ||
| className={clsx(className)} | ||
| defaultOpen={defaultOpen} | ||
| open={localIsOpen} | ||
| onOpenChange={handleToggle} | ||
vamsikrishnamathala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > | ||
| {children} | ||
| </BaseCollapsible.Root> | ||
| </CollapsibleContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| const Trigger: React.FC<TriggerProps> = ({ children, className, buttonRef }) => { | ||
| const { isOpen } = useCollapsible(); | ||
|
|
||
| return ( | ||
| <BaseCollapsible.Trigger data-panel-open={isOpen} ref={buttonRef} className={className}> | ||
| {children} | ||
| </BaseCollapsible.Trigger> | ||
| ); | ||
| }; | ||
|
|
||
| const Content: React.FC<ContentProps> = ({ children, className }) => ( | ||
| <BaseCollapsible.Panel | ||
| className={clsx( | ||
| "flex h-[var(--collapsible-panel-height)] flex-col overflow-hidden text-sm transition-all ease-out data-[ending-style]:h-0 data-[starting-style]:h-0", | ||
| className | ||
| )} | ||
| > | ||
| {children} | ||
| </BaseCollapsible.Panel> | ||
| ); | ||
|
|
||
| // Compound Component | ||
| export const Collapsible = { | ||
| CollapsibleRoot: Root, | ||
| CollapsibleTrigger: Trigger, | ||
| CollapsibleContent: Content, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./collapsible"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.