@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
81 lines (79 loc) • 2.64 kB
JavaScript
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { triggerOpenStateMapping } from '../../utils/collapsibleOpenStateMapping.js';
import { useComponentRenderer } from '../../utils/useComponentRenderer.js';
import { useCollapsibleRootContext } from '../root/CollapsibleRootContext.js';
import { useCollapsibleTrigger } from './useCollapsibleTrigger.js';
/**
* A button that opens and closes the collapsible panel.
* Renders a `<button>` element.
*
* Documentation: [Base UI Collapsible](https://base-ui.com/react/components/collapsible)
*/
const CollapsibleTrigger = /*#__PURE__*/React.forwardRef(function CollapsibleTrigger(props, forwardedRef) {
const {
className,
disabled = false,
id,
render,
...otherProps
} = props;
const {
panelId,
open,
setOpen,
state
} = useCollapsibleRootContext();
const {
getRootProps
} = useCollapsibleTrigger({
disabled,
panelId,
open,
setOpen,
rootRef: forwardedRef
});
const {
renderElement
} = useComponentRenderer({
propGetter: getRootProps,
render: render ?? 'button',
state,
className,
extraProps: otherProps,
customStyleHookMapping: triggerOpenStateMapping
});
return renderElement();
});
export { CollapsibleTrigger };
process.env.NODE_ENV !== "production" ? CollapsibleTrigger.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* @ignore
*/
disabled: PropTypes.bool,
/**
* @ignore
*/
id: PropTypes.string,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func])
} : void 0;