-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Aug 31, 2021
1 parent
ba4a9af
commit 7156603
Showing
51 changed files
with
578 additions
and
281 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MDB 5 React | ||
|
||
Version: FREE 1.0.0-beta7 | ||
Version: FREE 1.0.0 | ||
|
||
Documentation: | ||
https://mdbootstrap.com/docs/b5/react/ | ||
|
This file contains 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 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,24 @@ | ||
import clsx from 'clsx'; | ||
import React, { useState } from 'react'; | ||
import type { AccordionProps } from './types'; | ||
import { AccordionContext } from './AccordionContext'; | ||
|
||
const MDBAccordion: React.FC<AccordionProps> = React.forwardRef<HTMLAllCollection, AccordionProps>( | ||
({ alwaysOpen, className, flush, initialActive, tag: Tag, children, ...props }, ref) => { | ||
const classes = clsx('accordion', flush && 'accordion-flush', className); | ||
|
||
const [activeItem, setActiveItem] = useState(initialActive); | ||
|
||
return ( | ||
<AccordionContext.Provider value={{ activeItem, setActiveItem, alwaysOpen, initialActive }}> | ||
<Tag className={classes} ref={ref} {...props}> | ||
{children} | ||
</Tag> | ||
</AccordionContext.Provider> | ||
); | ||
} | ||
); | ||
|
||
MDBAccordion.defaultProps = { tag: 'div', initialActive: '' }; | ||
|
||
export default MDBAccordion; |
This file contains 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,17 @@ | ||
import React from 'react'; | ||
|
||
interface AccordionProps { | ||
activeItem: string | undefined; | ||
setActiveItem: React.SetStateAction<any>; | ||
alwaysOpen: boolean | undefined; | ||
initialActive: string | undefined; | ||
} | ||
|
||
const AccordionContext = React.createContext<AccordionProps>({ | ||
activeItem: '', | ||
setActiveItem: null, | ||
alwaysOpen: false, | ||
initialActive: '', | ||
}); | ||
|
||
export { AccordionContext }; |
46 changes: 46 additions & 0 deletions
46
app/src/components/Accordion/AccordionItem/AccordionItem.tsx
This file contains 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,46 @@ | ||
import clsx from 'clsx'; | ||
import React, { useContext, useState } from 'react'; | ||
import { AccordionContext } from '../AccordionContext'; | ||
import type { AccordionItemProps } from './types'; | ||
import MDBCollapse from '../../Collapse/Collapse'; | ||
|
||
const MDBAccordionItem: React.FC<AccordionItemProps> = React.forwardRef<HTMLAllCollection, AccordionItemProps>( | ||
({ className, bodyClassName, headerClassName, collapseId, headerTitle, tag: Tag, children, ...props }, ref) => { | ||
const { activeItem, setActiveItem, alwaysOpen, initialActive } = useContext(AccordionContext); | ||
|
||
const [openState, setOpenState] = useState(initialActive); | ||
|
||
const classes = clsx('accordion-item', className); | ||
const headerClasses = clsx('accordion-header', headerClassName); | ||
const bodyClasses = clsx('accordion-body', bodyClassName); | ||
const buttonClasses = clsx( | ||
'accordion-button', | ||
alwaysOpen ? collapseId !== openState && 'collapsed' : collapseId !== activeItem && 'collapsed' | ||
); | ||
|
||
const toggleAccordion = (value: string) => { | ||
if (alwaysOpen) { | ||
value !== openState ? setOpenState(value) : setOpenState(''); | ||
} else { | ||
value !== activeItem ? setActiveItem(value) : setActiveItem(''); | ||
} | ||
}; | ||
|
||
return ( | ||
<Tag className={classes} ref={ref} {...props}> | ||
<h2 className={headerClasses}> | ||
<button onClick={() => toggleAccordion(collapseId)} className={buttonClasses} type='button'> | ||
{headerTitle} | ||
</button> | ||
</h2> | ||
<MDBCollapse id={collapseId} show={alwaysOpen ? openState : activeItem}> | ||
<div className={bodyClasses}>{children}</div> | ||
</MDBCollapse> | ||
</Tag> | ||
); | ||
} | ||
); | ||
|
||
MDBAccordionItem.defaultProps = { tag: 'div' }; | ||
|
||
export default MDBAccordionItem; |
This file contains 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,13 @@ | ||
import * as React from 'react'; | ||
|
||
declare const MDBAccordionItem: React.FunctionComponent<{ | ||
className?: string; | ||
bodyClassName?: string; | ||
headerClassName?: string; | ||
collapseId: string; | ||
headerTitle?: string; | ||
tag?: React.ComponentProps<any>; | ||
[rest: string]: any; | ||
}>; | ||
|
||
export default MDBAccordionItem; |
This file contains 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,13 @@ | ||
import React from 'react'; | ||
|
||
type AccordionItemProps = { | ||
className?: string; | ||
bodyClassName?: string; | ||
headerClassName?: string; | ||
collapseId: string; | ||
headerTitle?: string; | ||
tag?: React.ComponentProps<any>; | ||
[rest: string]: any; | ||
}; | ||
|
||
export { AccordionItemProps }; |
This file contains 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,12 @@ | ||
import * as React from 'react'; | ||
|
||
declare const MDBAccordion: React.FunctionComponent<{ | ||
alwaysOpen?: boolean; | ||
className?: string; | ||
flush?: boolean; | ||
initialActive?: string; | ||
tag?: React.ComponentProps<any>; | ||
[rest: string]: any; | ||
}>; | ||
|
||
export default MDBAccordion; |
This file contains 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,12 @@ | ||
import React from 'react'; | ||
|
||
type AccordionProps = { | ||
alwaysOpen?: boolean; | ||
className?: string; | ||
flush?: boolean; | ||
initialActive?: string; | ||
tag?: React.ComponentProps<any>; | ||
[rest: string]: any; | ||
}; | ||
|
||
export { AccordionProps }; |
This file contains 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.