react-bootstrap
Advanced tools
Comparing version 2.0.4 to 2.1.0
import * as React from 'react'; | ||
import { SelectCallback } from '@restart/ui/types'; | ||
import { AccordionSelectCallback, AccordionEventKey } from './AccordionContext'; | ||
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers'; | ||
export interface AccordionProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'>, BsPrefixProps { | ||
activeKey?: string; | ||
defaultActiveKey?: string; | ||
onSelect?: SelectCallback; | ||
activeKey?: AccordionEventKey; | ||
defaultActiveKey?: AccordionEventKey; | ||
onSelect?: AccordionSelectCallback; | ||
flush?: boolean; | ||
alwaysOpen?: boolean; | ||
} | ||
@@ -10,0 +11,0 @@ declare const _default: BsPrefixRefForwardingComponent<"div", AccordionProps> & { |
@@ -43,2 +43,3 @@ "use strict"; | ||
flush, | ||
alwaysOpen, | ||
...controlledProps | ||
@@ -51,4 +52,5 @@ } = (0, _uncontrollable.useUncontrolled)(props, { | ||
activeEventKey: activeKey, | ||
onSelect | ||
}), [activeKey, onSelect]); | ||
onSelect, | ||
alwaysOpen | ||
}), [activeKey, onSelect, alwaysOpen]); | ||
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AccordionContext.default.Provider, { | ||
@@ -55,0 +57,0 @@ value: contextValue, |
@@ -13,3 +13,3 @@ "use strict"; | ||
var _AccordionContext = _interopRequireDefault(require("./AccordionContext")); | ||
var _AccordionContext = _interopRequireWildcard(require("./AccordionContext")); | ||
@@ -29,3 +29,4 @@ var _AccordionItemContext = _interopRequireDefault(require("./AccordionItemContext")); | ||
activeEventKey, | ||
onSelect | ||
onSelect, | ||
alwaysOpen | ||
} = (0, React.useContext)(_AccordionContext.default); | ||
@@ -37,5 +38,19 @@ return e => { | ||
*/ | ||
const eventKeyPassed = eventKey === activeEventKey ? null : eventKey; | ||
if (onSelect) onSelect(eventKeyPassed, e); | ||
if (onClick) onClick(e); | ||
let eventKeyPassed = eventKey === activeEventKey ? null : eventKey; | ||
if (alwaysOpen) { | ||
if (Array.isArray(activeEventKey)) { | ||
if (activeEventKey.includes(eventKey)) { | ||
eventKeyPassed = activeEventKey.filter(k => k !== eventKey); | ||
} else { | ||
eventKeyPassed = [...activeEventKey, eventKey]; | ||
} | ||
} else { | ||
// activeEventKey is undefined. | ||
eventKeyPassed = [eventKey]; | ||
} | ||
} | ||
onSelect == null ? void 0 : onSelect(eventKeyPassed, e); | ||
onClick == null ? void 0 : onClick(e); | ||
}; | ||
@@ -70,3 +85,3 @@ } | ||
"aria-expanded": eventKey === activeEventKey, | ||
className: (0, _classnames.default)(className, bsPrefix, eventKey !== activeEventKey && 'collapsed') | ||
className: (0, _classnames.default)(className, bsPrefix, !(0, _AccordionContext.isAccordionItemSelected)(activeEventKey, eventKey) && 'collapsed') | ||
}); | ||
@@ -73,0 +88,0 @@ }); |
@@ -16,3 +16,3 @@ "use strict"; | ||
var _AccordionContext = _interopRequireDefault(require("./AccordionContext")); | ||
var _AccordionContext = _interopRequireWildcard(require("./AccordionContext")); | ||
@@ -39,3 +39,3 @@ var _jsxRuntime = require("react/jsx-runtime"); | ||
ref: ref, | ||
in: activeEventKey === eventKey, | ||
in: (0, _AccordionContext.isAccordionItemSelected)(activeEventKey, eventKey), | ||
...props, | ||
@@ -42,0 +42,0 @@ className: (0, _classnames.default)(className, bsPrefix), |
import * as React from 'react'; | ||
import { SelectCallback } from '@restart/ui/types'; | ||
export declare type AccordionEventKey = string | string[] | null | undefined; | ||
export declare type AccordionSelectCallback = (eventKey: AccordionEventKey, e: React.SyntheticEvent<unknown>) => void; | ||
export interface AccordionContextValue { | ||
activeEventKey?: string; | ||
onSelect?: SelectCallback; | ||
activeEventKey?: AccordionEventKey; | ||
onSelect?: AccordionSelectCallback; | ||
alwaysOpen?: boolean; | ||
} | ||
export declare function isAccordionItemSelected(activeEventKey: AccordionEventKey, eventKey: string): boolean; | ||
declare const context: React.Context<AccordionContextValue>; | ||
export default context; |
@@ -5,2 +5,3 @@ "use strict"; | ||
exports.default = void 0; | ||
exports.isAccordionItemSelected = isAccordionItemSelected; | ||
@@ -13,6 +14,9 @@ var React = _interopRequireWildcard(require("react")); | ||
function isAccordionItemSelected(activeEventKey, eventKey) { | ||
return Array.isArray(activeEventKey) ? activeEventKey.includes(eventKey) : activeEventKey === eventKey; | ||
} | ||
const context = /*#__PURE__*/React.createContext({}); | ||
context.displayName = 'AccordionContext'; | ||
var _default = context; | ||
exports.default = _default; | ||
module.exports = exports.default; | ||
exports.default = _default; |
import * as React from 'react'; | ||
import { SelectCallback } from '@restart/ui/types'; | ||
import { AccordionSelectCallback, AccordionEventKey } from './AccordionContext'; | ||
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers'; | ||
export interface AccordionProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'>, BsPrefixProps { | ||
activeKey?: string; | ||
defaultActiveKey?: string; | ||
onSelect?: SelectCallback; | ||
activeKey?: AccordionEventKey; | ||
defaultActiveKey?: AccordionEventKey; | ||
onSelect?: AccordionSelectCallback; | ||
flush?: boolean; | ||
alwaysOpen?: boolean; | ||
} | ||
@@ -10,0 +11,0 @@ declare const _default: BsPrefixRefForwardingComponent<"div", AccordionProps> & { |
@@ -22,2 +22,3 @@ import classNames from 'classnames'; | ||
flush, | ||
alwaysOpen, | ||
...controlledProps | ||
@@ -30,4 +31,5 @@ } = useUncontrolled(props, { | ||
activeEventKey: activeKey, | ||
onSelect | ||
}), [activeKey, onSelect]); | ||
onSelect, | ||
alwaysOpen | ||
}), [activeKey, onSelect, alwaysOpen]); | ||
return /*#__PURE__*/_jsx(AccordionContext.Provider, { | ||
@@ -34,0 +36,0 @@ value: contextValue, |
import * as React from 'react'; | ||
import { useContext } from 'react'; | ||
import classNames from 'classnames'; | ||
import AccordionContext from './AccordionContext'; | ||
import AccordionContext, { isAccordionItemSelected } from './AccordionContext'; | ||
import AccordionItemContext from './AccordionItemContext'; | ||
@@ -11,3 +11,4 @@ import { useBootstrapPrefix } from './ThemeProvider'; | ||
activeEventKey, | ||
onSelect | ||
onSelect, | ||
alwaysOpen | ||
} = useContext(AccordionContext); | ||
@@ -19,5 +20,19 @@ return e => { | ||
*/ | ||
const eventKeyPassed = eventKey === activeEventKey ? null : eventKey; | ||
if (onSelect) onSelect(eventKeyPassed, e); | ||
if (onClick) onClick(e); | ||
let eventKeyPassed = eventKey === activeEventKey ? null : eventKey; | ||
if (alwaysOpen) { | ||
if (Array.isArray(activeEventKey)) { | ||
if (activeEventKey.includes(eventKey)) { | ||
eventKeyPassed = activeEventKey.filter(k => k !== eventKey); | ||
} else { | ||
eventKeyPassed = [...activeEventKey, eventKey]; | ||
} | ||
} else { | ||
// activeEventKey is undefined. | ||
eventKeyPassed = [eventKey]; | ||
} | ||
} | ||
onSelect == null ? void 0 : onSelect(eventKeyPassed, e); | ||
onClick == null ? void 0 : onClick(e); | ||
}; | ||
@@ -51,3 +66,3 @@ } | ||
"aria-expanded": eventKey === activeEventKey, | ||
className: classNames(className, bsPrefix, eventKey !== activeEventKey && 'collapsed') | ||
className: classNames(className, bsPrefix, !isAccordionItemSelected(activeEventKey, eventKey) && 'collapsed') | ||
}); | ||
@@ -54,0 +69,0 @@ }); |
@@ -6,3 +6,3 @@ import classNames from 'classnames'; | ||
import Collapse from './Collapse'; | ||
import AccordionContext from './AccordionContext'; | ||
import AccordionContext, { isAccordionItemSelected } from './AccordionContext'; | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
@@ -23,3 +23,3 @@ const AccordionCollapse = /*#__PURE__*/React.forwardRef(({ | ||
ref: ref, | ||
in: activeEventKey === eventKey, | ||
in: isAccordionItemSelected(activeEventKey, eventKey), | ||
...props, | ||
@@ -26,0 +26,0 @@ className: classNames(className, bsPrefix), |
import * as React from 'react'; | ||
import { SelectCallback } from '@restart/ui/types'; | ||
export declare type AccordionEventKey = string | string[] | null | undefined; | ||
export declare type AccordionSelectCallback = (eventKey: AccordionEventKey, e: React.SyntheticEvent<unknown>) => void; | ||
export interface AccordionContextValue { | ||
activeEventKey?: string; | ||
onSelect?: SelectCallback; | ||
activeEventKey?: AccordionEventKey; | ||
onSelect?: AccordionSelectCallback; | ||
alwaysOpen?: boolean; | ||
} | ||
export declare function isAccordionItemSelected(activeEventKey: AccordionEventKey, eventKey: string): boolean; | ||
declare const context: React.Context<AccordionContextValue>; | ||
export default context; |
import * as React from 'react'; | ||
export function isAccordionItemSelected(activeEventKey, eventKey) { | ||
return Array.isArray(activeEventKey) ? activeEventKey.includes(eventKey) : activeEventKey === eventKey; | ||
} | ||
const context = /*#__PURE__*/React.createContext({}); | ||
context.displayName = 'AccordionContext'; | ||
export default context; |
{ | ||
"name": "react-bootstrap", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "Bootstrap 5 components built with React", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1354787
29046