react-bootstrap 2.0.2 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,12 @@
1
1
  import * as React from 'react';
2
- import { SelectCallback } from '@restart/ui/types';
2
+ import { AccordionSelectCallback, AccordionEventKey } from './AccordionContext';
3
3
  import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
4
4
  export interface AccordionProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'>, BsPrefixProps {
5
- activeKey?: string;
6
- defaultActiveKey?: string;
7
- onSelect?: SelectCallback;
5
+ activeKey?: AccordionEventKey;
6
+ defaultActiveKey?: AccordionEventKey;
7
+ onSelect?: AccordionSelectCallback;
8
8
  flush?: boolean;
9
+ alwaysOpen?: boolean;
9
10
  }
10
11
  declare const _default: BsPrefixRefForwardingComponent<"div", AccordionProps> & {
11
12
  Button: BsPrefixRefForwardingComponent<"div", import("./AccordionButton").AccordionButtonProps>;
package/esm/Accordion.js CHANGED
@@ -19,6 +19,7 @@ const Accordion = /*#__PURE__*/React.forwardRef((props, ref) => {
19
19
  className,
20
20
  onSelect,
21
21
  flush,
22
+ alwaysOpen,
22
23
  ...controlledProps
23
24
  } = useUncontrolled(props, {
24
25
  activeKey: 'onSelect'
@@ -26,8 +27,9 @@ const Accordion = /*#__PURE__*/React.forwardRef((props, ref) => {
26
27
  const prefix = useBootstrapPrefix(bsPrefix, 'accordion');
27
28
  const contextValue = useMemo(() => ({
28
29
  activeEventKey: activeKey,
29
- onSelect
30
- }), [activeKey, onSelect]);
30
+ onSelect,
31
+ alwaysOpen
32
+ }), [activeKey, onSelect, alwaysOpen]);
31
33
  return /*#__PURE__*/_jsx(AccordionContext.Provider, {
32
34
  value: contextValue,
33
35
  children: /*#__PURE__*/_jsx(Component, {
@@ -1,23 +1,38 @@
1
1
  import * as React from 'react';
2
2
  import { useContext } from 'react';
3
3
  import classNames from 'classnames';
4
- import AccordionContext from './AccordionContext';
4
+ import AccordionContext, { isAccordionItemSelected } from './AccordionContext';
5
5
  import AccordionItemContext from './AccordionItemContext';
6
6
  import { useBootstrapPrefix } from './ThemeProvider';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  export function useAccordionButton(eventKey, onClick) {
9
9
  const {
10
10
  activeEventKey,
11
- onSelect
11
+ onSelect,
12
+ alwaysOpen
12
13
  } = useContext(AccordionContext);
13
14
  return e => {
14
15
  /*
15
16
  Compare the event key in context with the given event key.
16
17
  If they are the same, then collapse the component.
17
18
  */
18
- const eventKeyPassed = eventKey === activeEventKey ? null : eventKey;
19
- if (onSelect) onSelect(eventKeyPassed, e);
20
- if (onClick) onClick(e);
19
+ let eventKeyPassed = eventKey === activeEventKey ? null : eventKey;
20
+
21
+ if (alwaysOpen) {
22
+ if (Array.isArray(activeEventKey)) {
23
+ if (activeEventKey.includes(eventKey)) {
24
+ eventKeyPassed = activeEventKey.filter(k => k !== eventKey);
25
+ } else {
26
+ eventKeyPassed = [...activeEventKey, eventKey];
27
+ }
28
+ } else {
29
+ // activeEventKey is undefined.
30
+ eventKeyPassed = [eventKey];
31
+ }
32
+ }
33
+
34
+ onSelect == null ? void 0 : onSelect(eventKeyPassed, e);
35
+ onClick == null ? void 0 : onClick(e);
21
36
  };
22
37
  }
23
38
  const AccordionButton = /*#__PURE__*/React.forwardRef(({
@@ -46,7 +61,7 @@ const AccordionButton = /*#__PURE__*/React.forwardRef(({
46
61
  onClick: accordionOnClick,
47
62
  ...props,
48
63
  "aria-expanded": eventKey === activeEventKey,
49
- className: classNames(className, bsPrefix, eventKey !== activeEventKey && 'collapsed')
64
+ className: classNames(className, bsPrefix, !isAccordionItemSelected(activeEventKey, eventKey) && 'collapsed')
50
65
  });
51
66
  });
52
67
  AccordionButton.displayName = 'AccordionButton';
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { useContext } from 'react';
4
4
  import { useBootstrapPrefix } from './ThemeProvider';
5
5
  import Collapse from './Collapse';
6
- import AccordionContext from './AccordionContext';
6
+ import AccordionContext, { isAccordionItemSelected } from './AccordionContext';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  const AccordionCollapse = /*#__PURE__*/React.forwardRef(({
9
9
  as: Component = 'div',
@@ -19,7 +19,7 @@ const AccordionCollapse = /*#__PURE__*/React.forwardRef(({
19
19
  bsPrefix = useBootstrapPrefix(bsPrefix, 'accordion-collapse');
20
20
  return /*#__PURE__*/_jsx(Collapse, {
21
21
  ref: ref,
22
- in: activeEventKey === eventKey,
22
+ in: isAccordionItemSelected(activeEventKey, eventKey),
23
23
  ...props,
24
24
  className: classNames(className, bsPrefix),
25
25
  children: /*#__PURE__*/_jsx(Component, {
@@ -1,8 +1,11 @@
1
1
  import * as React from 'react';
2
- import { SelectCallback } from '@restart/ui/types';
2
+ export declare type AccordionEventKey = string | string[] | null | undefined;
3
+ export declare type AccordionSelectCallback = (eventKey: AccordionEventKey, e: React.SyntheticEvent<unknown>) => void;
3
4
  export interface AccordionContextValue {
4
- activeEventKey?: string;
5
- onSelect?: SelectCallback;
5
+ activeEventKey?: AccordionEventKey;
6
+ onSelect?: AccordionSelectCallback;
7
+ alwaysOpen?: boolean;
6
8
  }
9
+ export declare function isAccordionItemSelected(activeEventKey: AccordionEventKey, eventKey: string): boolean;
7
10
  declare const context: React.Context<AccordionContextValue>;
8
11
  export default context;
@@ -1,4 +1,7 @@
1
1
  import * as React from 'react';
2
+ export function isAccordionItemSelected(activeEventKey, eventKey) {
3
+ return Array.isArray(activeEventKey) ? activeEventKey.includes(eventKey) : activeEventKey === eventKey;
4
+ }
2
5
  const context = /*#__PURE__*/React.createContext({});
3
6
  context.displayName = 'AccordionContext';
4
7
  export default context;
@@ -15,4 +15,9 @@ declare function map<P = any>(children: any, func: (el: React.ReactElement<P>, i
15
15
  * leaf child with the index reflecting the position relative to "valid components".
16
16
  */
17
17
  declare function forEach<P = any>(children: any, func: (el: React.ReactElement<P>, index: number) => void): void;
18
- export { map, forEach };
18
+ /**
19
+ * Finds whether a component's `children` prop includes a React element of the
20
+ * specified type.
21
+ */
22
+ declare function hasChildOfType<P = any>(children: React.ReactNode, type: string | React.JSXElementConstructor<P>): boolean;
23
+ export { map, forEach, hasChildOfType };
@@ -26,5 +26,14 @@ function forEach(children, func) {
26
26
  if ( /*#__PURE__*/React.isValidElement(child)) func(child, index++);
27
27
  });
28
28
  }
29
+ /**
30
+ * Finds whether a component's `children` prop includes a React element of the
31
+ * specified type.
32
+ */
33
+
34
+
35
+ function hasChildOfType(children, type) {
36
+ return React.Children.toArray(children).some(child => /*#__PURE__*/React.isValidElement(child) && child.type === type);
37
+ }
29
38
 
30
- export { map, forEach };
39
+ export { map, forEach, hasChildOfType };
package/esm/FormCheck.js CHANGED
@@ -6,6 +6,7 @@ import FormCheckInput from './FormCheckInput';
6
6
  import FormCheckLabel from './FormCheckLabel';
7
7
  import FormContext from './FormContext';
8
8
  import { useBootstrapPrefix } from './ThemeProvider';
9
+ import { hasChildOfType } from './ElementChildren';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
11
  import { Fragment as _Fragment } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -38,7 +39,7 @@ const FormCheck = /*#__PURE__*/React.forwardRef(({
38
39
  const innerFormContext = useMemo(() => ({
39
40
  controlId: id || controlId
40
41
  }), [controlId, id]);
41
- const hasLabel = label != null && label !== false && !children;
42
+ const hasLabel = !children && label != null && label !== false || hasChildOfType(children, FormCheckLabel);
42
43
 
43
44
  const input = /*#__PURE__*/_jsx(FormCheckInput, { ...props,
44
45
  type: type === 'switch' ? 'checkbox' : type,
@@ -53,7 +54,7 @@ const FormCheck = /*#__PURE__*/React.forwardRef(({
53
54
  value: innerFormContext,
54
55
  children: /*#__PURE__*/_jsx("div", {
55
56
  style: style,
56
- className: classNames(className, label && bsPrefix, inline && `${bsPrefix}-inline`, type === 'switch' && bsSwitchPrefix),
57
+ className: classNames(className, hasLabel && bsPrefix, inline && `${bsPrefix}-inline`, type === 'switch' && bsSwitchPrefix),
57
58
  children: children || /*#__PURE__*/_jsxs(_Fragment, {
58
59
  children: [input, hasLabel && /*#__PURE__*/_jsx(FormCheckLabel, {
59
60
  title: title,
package/esm/Modal.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ModalProps as BaseModalProps } from '@restart/ui/Modal';
2
+ import { BaseModalProps } from '@restart/ui/Modal';
3
3
  import { BsPrefixRefForwardingComponent } from './helpers';
4
4
  export interface ModalProps extends Omit<BaseModalProps, 'role' | 'renderBackdrop' | 'renderDialog' | 'transition' | 'backdropTransition' | 'children'> {
5
5
  size?: 'sm' | 'lg' | 'xl';
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { DropdownProps } from './Dropdown';
3
3
  import { DropdownMenuVariant } from './DropdownMenu';
4
4
  import { BsPrefixRefForwardingComponent } from './helpers';
5
- export interface NavDropdownProps extends Omit<DropdownProps, 'onSelect' | 'title'> {
5
+ export interface NavDropdownProps extends Omit<DropdownProps, 'title'> {
6
6
  title: React.ReactNode;
7
7
  disabled?: boolean;
8
8
  active?: boolean;
package/esm/Overlay.js CHANGED
@@ -45,21 +45,22 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
45
45
  transition: actualTransition,
46
46
  children: (overlayProps, {
47
47
  arrowProps,
48
- placement,
49
48
  popper: popperObj,
50
49
  show
51
50
  }) => {
52
51
  var _popperObj$state, _popperObj$state$modi;
53
52
 
54
- wrapRefs(overlayProps, arrowProps);
53
+ wrapRefs(overlayProps, arrowProps); // Need to get placement from popper object, handling case when overlay is flipped using 'flip' prop
54
+
55
+ const updatedPlacement = popperObj == null ? void 0 : popperObj.placement;
55
56
  const popper = Object.assign(popperRef.current, {
56
57
  state: popperObj == null ? void 0 : popperObj.state,
57
58
  scheduleUpdate: popperObj == null ? void 0 : popperObj.update,
58
- placement,
59
+ placement: updatedPlacement,
59
60
  outOfBoundaries: (popperObj == null ? void 0 : (_popperObj$state = popperObj.state) == null ? void 0 : (_popperObj$state$modi = _popperObj$state.modifiersData.hide) == null ? void 0 : _popperObj$state$modi.isReferenceHidden) || false
60
61
  });
61
62
  if (typeof overlay === 'function') return overlay({ ...overlayProps,
62
- placement,
63
+ placement: updatedPlacement,
63
64
  show,
64
65
  ...(!transition && show && {
65
66
  className: 'show'
@@ -68,7 +69,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
68
69
  arrowProps
69
70
  });
70
71
  return /*#__PURE__*/React.cloneElement(overlay, { ...overlayProps,
71
- placement,
72
+ placement: updatedPlacement,
72
73
  arrowProps,
73
74
  popper,
74
75
  className: classNames(overlay.props.className, !transition && show && 'show'),
@@ -4,7 +4,7 @@ export interface ThemeContextValue {
4
4
  dir?: string;
5
5
  }
6
6
  export interface ThemeProviderProps extends Partial<ThemeContextValue> {
7
- children: React.ElementType;
7
+ children: React.ReactNode;
8
8
  }
9
9
  declare const Consumer: React.Consumer<ThemeContextValue>;
10
10
  declare function ThemeProvider({ prefixes, dir, children }: ThemeProviderProps): JSX.Element;
@@ -13,6 +13,8 @@ declare namespace ThemeProvider {
13
13
  }
14
14
  export declare function useBootstrapPrefix(prefix: string | undefined, defaultPrefix: string): string;
15
15
  export declare function useIsRTL(): boolean;
16
- declare function createBootstrapComponent(Component: any, opts: any): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
16
+ declare function createBootstrapComponent(Component: any, opts: any): React.ForwardRefExoticComponent<{
17
+ bsPrefix?: string | undefined;
18
+ } & React.RefAttributes<any>>;
17
19
  export { createBootstrapComponent, Consumer as ThemeConsumer };
18
20
  export default ThemeProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-bootstrap",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "Bootstrap 5 components built with React",
5
5
  "keywords": [
6
6
  "react",
@@ -34,9 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@babel/runtime": "^7.14.0",
37
- "@restart/context": "^2.1.4",
38
- "@restart/hooks": "^0.3.26",
39
- "@restart/ui": "^0.2.3",
37
+ "@restart/hooks": "^0.4.5",
38
+ "@restart/ui": "^0.2.5",
40
39
  "@types/invariant": "^2.2.33",
41
40
  "@types/prop-types": "^15.7.3",
42
41
  "@types/react": ">=16.14.8",