|
| 1 | +/** |
| 2 | + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). |
| 3 | + * |
| 4 | + * WSO2 LLC. licenses this file to you under the Apache License, |
| 5 | + * Version 2.0 (the "License"); you may not use this file except |
| 6 | + * in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, |
| 12 | + * software distributed under the License is distributed on an |
| 13 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + * KIND, either express or implied. See the License for the |
| 15 | + * specific language governing permissions and limitations |
| 16 | + * under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import MuiCollapse from '@mui/material/Collapse'; |
| 20 | +import type {CollapseProps as MuiCollapseProps} from '@mui/material/Collapse'; |
| 21 | +import type {OverridableComponent, OverridableTypeMap} from '@mui/material/OverridableComponent'; |
| 22 | +import type {TransitionProps} from '@mui/material/transitions'; |
| 23 | +import clsx from 'clsx'; |
| 24 | +import {forwardRef} from 'react'; |
| 25 | +import type {ReactElement, Ref, ElementType} from 'react'; |
| 26 | + |
| 27 | +export type CollapseProps<C extends ElementType = ElementType<TransitionProps>> = { |
| 28 | + /** |
| 29 | + * The component used for the root node. Either a string to use a HTML element or a component. |
| 30 | + */ |
| 31 | + component?: C; |
| 32 | +} & Omit<MuiCollapseProps, 'component'>; |
| 33 | + |
| 34 | +/** |
| 35 | + * A Transition component to expand from the start edge of the child element. |
| 36 | + * |
| 37 | + * Demos: |
| 38 | + * |
| 39 | + * - [Card (Oxygen UI)](https://wso2.github.io/oxygen-ui/react/?path=/docs/surfaces-card) |
| 40 | + * - [Card (MUI)](https://mui.com/material-ui/react-card/) |
| 41 | + * - [Lists (Oxygen UI)](https://wso2.github.io/oxygen-ui/react/?path=/docs/data-display-list) |
| 42 | + * - [Lists (MUI)](https://mui.com/material-ui/react-list/) |
| 43 | + * - [Collapse (Oxygen UI)](https://wso2.github.io/oxygen-ui/react/?path=/docs/utils-collapse) |
| 44 | + * - [Transitions (MUI)](https://mui.com/material-ui/transitions/) |
| 45 | + * |
| 46 | + * API: |
| 47 | + * |
| 48 | + * - [Collapse API](https://mui.com/material-ui/api/collapse/) |
| 49 | + * - inherits [Transition API](http://reactcommunity.org/react-transition-group/transition/#Transition-props) |
| 50 | + * |
| 51 | + * @remarks |
| 52 | + * - ✔️ Props of the [Transition](https://mui.com/material-ui/transitions/) component are also available. |
| 53 | + * - ✅ `component` prop is supported. |
| 54 | + * - ✅ The `ref` is forwarded to the root element. |
| 55 | + * |
| 56 | + * @template C - The type of the component. |
| 57 | + * @param props - The props for the Collapse component. |
| 58 | + * @param ref - The ref to be forwarded to the MuiCollapse component. |
| 59 | + * @returns The rendered Collapse component. |
| 60 | + */ |
| 61 | +const Collapse: OverridableComponent<OverridableTypeMap> = forwardRef( |
| 62 | + ({className, ...rest}: CollapseProps<ElementType<TransitionProps>>, ref: Ref<HTMLDivElement>): ReactElement => ( |
| 63 | + <MuiCollapse ref={ref} className={clsx('OxygenCollapse-root', className)} {...rest} /> |
| 64 | + ), |
| 65 | +) as OverridableComponent<OverridableTypeMap>; |
| 66 | + |
| 67 | +export default Collapse; |
0 commit comments