-
-
Notifications
You must be signed in to change notification settings - Fork 53
Feat: Basic collapsible component added #407
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
4 commits
Select commit
Hold shift + click to select a range
5ea3642
Feat: new component added - collapsible
decipher-cs b212779
Merge branch 'rad-ui:main' into main
decipher-cs 3c86dd8
Fix: <Button/> props fixed for type safety
decipher-cs 7cf8116
Feat: Added title and external trigger to collapsible
decipher-cs 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,72 @@ | ||
| import React, {useState} from 'react'; | ||
| import {Meta} from '@storybook/react'; | ||
| import Collapsible from './Collapsible'; | ||
| import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor'; | ||
| import Button from '../Button/Button'; | ||
|
|
||
| const placeholderText= ['“One of the penalties for refusing to participate in politics is that you end up being governed by your inferiors.“ – Plato', | ||
| '“The superior man understands what is right; the inferior man understands what will sell.” – Confucius', | ||
| '“There are no secrets on the internet.” – Paul Babicki']; | ||
|
|
||
|
|
||
| const meta: Meta<typeof Collapsible> = { | ||
| component: Collapsible, | ||
| title: 'UI/Data Display/Collapsible', | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| export const Default = () => { | ||
| return (<section> | ||
| <SandboxEditor className=''> | ||
| <Collapsible> | ||
| <div className='grid gap-4 border-2 border-zinc-200 p-2'> | ||
| {placeholderText.map((text) => | ||
| <p key={text}> {text} </p>, | ||
| )} | ||
| </div> | ||
| </Collapsible> | ||
| </SandboxEditor> | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| export const WithTitle= () => { | ||
| return (<section> | ||
| <SandboxEditor className=''> | ||
| <Collapsible title='Hello World'> | ||
| <div className='grid gap-4 border-2 border-zinc-200'> | ||
| {placeholderText.map((text) => | ||
| <p key={text}> {text} </p>, | ||
| )} | ||
| </div> | ||
| </Collapsible> | ||
| </SandboxEditor> | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| export const ExternalTrigger= () => { | ||
| const [open, setOpen] =useState(true); | ||
|
|
||
| const toggleHidden=() => setOpen((p) => !p); | ||
|
|
||
| return (<section> | ||
| <SandboxEditor className=''> | ||
| <Collapsible | ||
| title='Quotes' | ||
| open={open} | ||
| trigger={<Button onClick={toggleHidden}>{open?'OPEN':'CLOSE'}</Button>} | ||
| > | ||
|
|
||
| <div className='grid gap-4 border-2 border-zinc-200'> | ||
| {placeholderText.map((text) => | ||
| <p key={text}> {text} </p>, | ||
| )} | ||
| </div> | ||
|
|
||
| </Collapsible> | ||
| </SandboxEditor> | ||
| </section> | ||
| ); | ||
| }; |
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,59 @@ | ||
| import React, {PropsWithChildren, ReactNode, useState} from 'react'; | ||
| import ButtonPrimitive from '~/core/primitives/Button'; | ||
|
|
||
| /* | ||
| * CHECKLIST | ||
| * | ||
| * Add rtl and ltr support | ||
| * Support animations | ||
| * Support basic poitioning of button | ||
| * Add title to collapsible | ||
| * | ||
| * */ | ||
|
|
||
| export type CollapsibleProps = { open?: boolean, title?: string, trigger?: ReactNode} & PropsWithChildren; | ||
|
|
||
| const ExpandIcon = () => ( | ||
| <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6"> | ||
| <path strokeLinecap="round" strokeLinejoin="round" d="M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15" /> | ||
| </svg> | ||
| ); | ||
|
|
||
| const CollapseIcon = () => ( | ||
| <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6"> | ||
| <path strokeLinecap="round" strokeLinejoin="round" d="M9 9V4.5M9 9H4.5M9 9 3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5 5.25 5.25" /> | ||
| </svg> | ||
| ); | ||
|
|
||
| const Collapsible = ({children, title, trigger, ...props}: CollapsibleProps) => { | ||
| const [open, setOpen] = useState(props.open ?? true); | ||
|
|
||
| const toggleCollapse=() => setOpen((p) => !p); | ||
|
|
||
| return ( | ||
| <article> | ||
| <span style={{display: 'flex', alignItems: 'center'}}> | ||
| {title && <p>{title}</p>} | ||
| { | ||
| trigger || | ||
| <ButtonPrimitive style={{marginInlineStart: 'auto'}} onClick={toggleCollapse}>{open?<CollapseIcon/>:<ExpandIcon/>}</ButtonPrimitive> | ||
| } | ||
| </span> | ||
|
|
||
| <div | ||
| aria-hidden={!open} | ||
| style={{ | ||
| overflow: 'hidden', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| height: (props.open ?? open)? 'auto': '0', | ||
| transition: 'all', | ||
| }}> | ||
| {children} | ||
| </div> | ||
|
|
||
| </article> | ||
| ); | ||
| }; | ||
|
|
||
| export default Collapsible; | ||
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.
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.
Consider implementing checklist features.
The checklist indicates missing features such as RTL support, animations, and positioning. Consider implementing these for a more robust component.
Would you like help implementing these features or opening a GitHub issue to track them?
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.
nah man, I'm good.
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.
@decipher-cs, understood! If you need any assistance in the future, feel free to reach out. 😊