Skip to content

Commit 73a559e

Browse files
committed
feat: migrate components to restart/ui
1 parent 8e3f3c2 commit 73a559e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+185
-234
lines changed

src/Accordion.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import classNames from 'classnames';
22
import * as React from 'react';
33
import { useMemo } from 'react';
44
import PropTypes from 'prop-types';
5+
import { SelectCallback } from '@restart/ui/types';
56
import { useUncontrolled } from 'uncontrollable';
67
import { useBootstrapPrefix } from './ThemeProvider';
78
import AccordionBody from './AccordionBody';
@@ -10,11 +11,7 @@ import AccordionCollapse from './AccordionCollapse';
1011
import AccordionContext from './AccordionContext';
1112
import AccordionHeader from './AccordionHeader';
1213
import AccordionItem from './AccordionItem';
13-
import {
14-
BsPrefixProps,
15-
BsPrefixRefForwardingComponent,
16-
SelectCallback,
17-
} from './helpers';
14+
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
1815

1916
export interface AccordionProps
2017
extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'>,

src/AccordionContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { SelectCallback } from './helpers';
2+
import { SelectCallback } from '@restart/ui/types';
33

44
export interface AccordionContextValue {
55
activeEventKey?: string;

src/Alert.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import PropTypes from 'prop-types';
44
import { elementType } from 'prop-types-extra';
55
import { useUncontrolled } from 'uncontrollable';
66
import useEventCallback from '@restart/hooks/useEventCallback';
7+
import Anchor from '@restart/ui/Anchor';
78
import { useBootstrapPrefix } from './ThemeProvider';
89
import Fade from './Fade';
910
import CloseButton, { CloseButtonVariant } from './CloseButton';
1011
import { Variant } from './types';
1112
import divWithClassName from './divWithClassName';
1213
import createWithBsPrefix from './createWithBsPrefix';
13-
import SafeAnchor from './SafeAnchor';
1414
import { TransitionType } from './helpers';
1515

1616
export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -32,7 +32,7 @@ const AlertHeading = createWithBsPrefix('alert-heading', {
3232
});
3333

3434
const AlertLink = createWithBsPrefix('alert-link', {
35-
Component: SafeAnchor,
35+
Component: Anchor,
3636
});
3737

3838
const propTypes = {

src/BreadcrumbItem.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import classNames from 'classnames';
22
import * as React from 'react';
33
import PropTypes from 'prop-types';
4-
5-
import SafeAnchor from './SafeAnchor';
4+
import Anchor from '@restart/ui/Anchor';
65
import { useBootstrapPrefix } from './ThemeProvider';
76
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
87

@@ -68,7 +67,7 @@ const BreadcrumbItem: BsPrefixRefForwardingComponent<
6867
className,
6968
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
7069
as: Component = 'li',
71-
linkAs: LinkComponent = SafeAnchor,
70+
linkAs: LinkComponent = Anchor,
7271
linkProps,
7372
href,
7473
title,

src/Button.tsx

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import classNames from 'classnames';
22
import * as React from 'react';
33
import PropTypes from 'prop-types';
4-
4+
import {
5+
useButtonProps,
6+
ButtonProps as BaseButtonProps,
7+
} from '@restart/ui/Button';
58
import { useBootstrapPrefix } from './ThemeProvider';
6-
import SafeAnchor from './SafeAnchor';
79
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
810
import { ButtonVariant } from './types';
911

10-
export type ButtonType = 'button' | 'reset' | 'submit' | string;
11-
1212
export interface ButtonProps
13-
extends React.HTMLAttributes<HTMLElement>,
14-
BsPrefixProps {
13+
extends BaseButtonProps,
14+
Omit<BsPrefixProps, 'as'> {
1515
active?: boolean;
1616
variant?: ButtonVariant;
1717
size?: 'sm' | 'lg';
18-
type?: ButtonType;
19-
href?: string;
20-
disabled?: boolean;
21-
target?: any;
2218
}
2319

2420
export type CommonButtonProps = 'href' | 'size' | 'variant' | 'disabled';
@@ -79,37 +75,30 @@ const defaultProps = {
7975

8076
const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
8177
React.forwardRef<HTMLButtonElement, ButtonProps>(
82-
(
83-
{ bsPrefix, variant, size, active, className, type, as, ...props },
84-
ref,
85-
) => {
78+
({ as, bsPrefix, variant, size, active, className, ...props }, ref) => {
8679
const prefix = useBootstrapPrefix(bsPrefix, 'btn');
87-
88-
const classes = classNames(
89-
className,
90-
prefix,
91-
active && 'active',
92-
variant && `${prefix}-${variant}`,
93-
size && `${prefix}-${size}`,
80+
const [buttonProps, { tagName }] = useButtonProps({
81+
tagName: as,
82+
...props,
83+
});
84+
85+
const Component = tagName as React.ElementType;
86+
87+
return (
88+
<Component
89+
{...props}
90+
{...buttonProps}
91+
ref={ref}
92+
className={classNames(
93+
className,
94+
prefix,
95+
active && 'active',
96+
variant && `${prefix}-${variant}`,
97+
size && `${prefix}-${size}`,
98+
props.href && props.disabled && 'disabled',
99+
)}
100+
/>
94101
);
95-
96-
if (props.href) {
97-
return (
98-
<SafeAnchor
99-
{...props}
100-
as={as}
101-
ref={ref}
102-
className={classNames(classes, props.disabled && 'disabled')}
103-
/>
104-
);
105-
}
106-
107-
if (!type && !as) {
108-
type = 'button';
109-
}
110-
111-
const Component = as || 'button';
112-
return <Component {...props} ref={ref} type={type} className={classes} />;
113102
},
114103
);
115104

src/Carousel.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import useEventCallback from '@restart/hooks/useEventCallback';
22
import useUpdateEffect from '@restart/hooks/useUpdateEffect';
33
import useCommittedRef from '@restart/hooks/useCommittedRef';
44
import useTimeout from '@restart/hooks/useTimeout';
5+
import Anchor from '@restart/ui/Anchor';
56
import classNames from 'classnames';
67
import { TransitionStatus } from 'react-transition-group/Transition';
78
import PropTypes from 'prop-types';
@@ -18,7 +19,6 @@ import { useUncontrolled } from 'uncontrollable';
1819
import CarouselCaption from './CarouselCaption';
1920
import CarouselItem from './CarouselItem';
2021
import { map, forEach } from './ElementChildren';
21-
import SafeAnchor from './SafeAnchor';
2222
import { useBootstrapPrefix, useIsRTL } from './ThemeProvider';
2323
import transitionEndListener from './transitionEndListener';
2424
import triggerBrowserReflow from './triggerBrowserReflow';
@@ -616,20 +616,20 @@ const Carousel: BsPrefixRefForwardingComponent<'div', CarouselProps> =
616616
{controls && (
617617
<>
618618
{(wrap || activeIndex !== 0) && (
619-
<SafeAnchor className={`${prefix}-control-prev`} onClick={prev}>
619+
<Anchor className={`${prefix}-control-prev`} onClick={prev}>
620620
{prevIcon}
621621
{prevLabel && (
622622
<span className="visually-hidden">{prevLabel}</span>
623623
)}
624-
</SafeAnchor>
624+
</Anchor>
625625
)}
626626
{(wrap || activeIndex !== numChildren - 1) && (
627-
<SafeAnchor className={`${prefix}-control-next`} onClick={next}>
627+
<Anchor className={`${prefix}-control-next`} onClick={next}>
628628
{nextIcon}
629629
{nextLabel && (
630630
<span className="visually-hidden">{nextLabel}</span>
631631
)}
632-
</SafeAnchor>
632+
</Anchor>
633633
)}
634634
</>
635635
)}

src/Collapse.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Transition, {
99
EXITED,
1010
EXITING,
1111
} from 'react-transition-group/Transition';
12+
import { TransitionCallbacks } from '@restart/ui/types';
1213
import transitionEndListener from './transitionEndListener';
13-
import { TransitionCallbacks } from './helpers';
1414
import createChainedFunction from './createChainedFunction';
1515
import triggerBrowserReflow from './triggerBrowserReflow';
1616
import TransitionWrapper from './TransitionWrapper';

src/Fade.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import Transition, {
77
ENTERED,
88
ENTERING,
99
} from 'react-transition-group/Transition';
10+
import { TransitionCallbacks } from '@restart/ui/types';
1011
import transitionEndListener from './transitionEndListener';
11-
import { TransitionCallbacks } from './helpers';
1212
import triggerBrowserReflow from './triggerBrowserReflow';
1313
import TransitionWrapper from './TransitionWrapper';
1414

@@ -93,9 +93,9 @@ const fadeStyles = {
9393
const Fade = React.forwardRef<Transition<any>, FadeProps>(
9494
({ className, children, ...props }, ref) => {
9595
const handleEnter = useCallback(
96-
(node) => {
96+
(node, isAppearing) => {
9797
triggerBrowserReflow(node);
98-
props.onEnter?.(node);
98+
props.onEnter?.(node, isAppearing);
9999
},
100100
[props],
101101
);

src/FormCheckInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type FormCheckInputType = 'checkbox' | 'radio';
1111
export interface FormCheckInputProps
1212
extends BsPrefixProps,
1313
React.InputHTMLAttributes<HTMLInputElement> {
14-
id?: string;
1514
type?: FormCheckInputType;
1615
isValid?: boolean;
1716
isInvalid?: boolean;

src/FormControl.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export interface FormControlProps
2121
value?: string | string[] | number;
2222
onChange?: React.ChangeEventHandler<FormControlElement>;
2323
type?: string;
24-
id?: string;
2524
isValid?: boolean;
2625
isInvalid?: boolean;
2726
}

src/ListGroup.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,17 @@ import classNames from 'classnames';
22
import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import warning from 'warning';
5-
65
import { useUncontrolled } from 'uncontrollable';
7-
6+
import BaseNav, { NavProps as BaseNavProps } from '@restart/ui/Nav';
7+
import { EventKey } from '@restart/ui/types';
88
import { useBootstrapPrefix } from './ThemeProvider';
9-
import AbstractNav from './AbstractNav';
109
import ListGroupItem from './ListGroupItem';
11-
import {
12-
BsPrefixProps,
13-
BsPrefixRefForwardingComponent,
14-
SelectCallback,
15-
} from './helpers';
16-
import { EventKey } from './types';
10+
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
1711

18-
export interface ListGroupProps
19-
extends BsPrefixProps,
20-
Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'> {
12+
export interface ListGroupProps extends BsPrefixProps, BaseNavProps {
2113
variant?: 'flush';
2214
horizontal?: boolean | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
23-
activeKey?: EventKey;
2415
defaultActiveKey?: EventKey;
25-
onSelect?: SelectCallback;
2616
}
2717

2818
const propTypes = {
@@ -81,7 +71,7 @@ const ListGroup: BsPrefixRefForwardingComponent<'div', ListGroupProps> =
8171
);
8272

8373
return (
84-
<AbstractNav
74+
<BaseNav
8575
ref={ref}
8676
{...controlledProps}
8777
as={as}

src/ListGroupItem.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ import classNames from 'classnames';
22
import * as React from 'react';
33
import { useCallback } from 'react';
44
import PropTypes from 'prop-types';
5-
6-
import AbstractNavItem from './AbstractNavItem';
5+
import BaseNavItem, {
6+
NavItemProps as BaseNavItemProps,
7+
} from '@restart/ui/NavItem';
78
import { useBootstrapPrefix } from './ThemeProvider';
89
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
9-
import { Variant, EventKey } from './types';
10+
import { Variant } from './types';
1011

1112
export interface ListGroupItemProps
12-
extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'>,
13+
extends Omit<BaseNavItemProps, 'onSelect'>,
1314
BsPrefixProps {
1415
action?: boolean;
15-
active?: boolean;
16-
disabled?: boolean;
17-
eventKey?: EventKey;
18-
href?: string;
1916
onClick?: React.MouseEventHandler;
2017
variant?: Variant;
2118
}
@@ -104,7 +101,7 @@ const ListGroupItem: BsPrefixRefForwardingComponent<'a', ListGroupItemProps> =
104101
}
105102

106103
return (
107-
<AbstractNavItem
104+
<BaseNavItem
108105
ref={ref}
109106
{...props}
110107
// eslint-disable-next-line no-nested-ternary

src/NavDropdown.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { BsPrefixRefForwardingComponent } from './helpers';
1010

1111
export interface NavDropdownProps
1212
extends Omit<DropdownProps, 'onSelect' | 'title'> {
13-
id: string;
1413
title: React.ReactNode;
1514
disabled?: boolean;
1615
active?: boolean;
@@ -23,10 +22,9 @@ export interface NavDropdownProps
2322
const propTypes = {
2423
/**
2524
* An html id attribute for the Toggle button, necessary for assistive technologies, such as screen readers.
26-
* @type {string|number}
27-
* @required
25+
* @type {string}
2826
*/
29-
id: PropTypes.any,
27+
id: PropTypes.string,
3028

3129
/** An `onClick` handler passed to the Toggle component */
3230
onClick: PropTypes.func,

src/Navbar.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import classNames from 'classnames';
22
import * as React from 'react';
33
import { useCallback, useMemo } from 'react';
44
import PropTypes from 'prop-types';
5-
5+
import SelectableContext from '@restart/ui/SelectableContext';
6+
import { SelectCallback } from '@restart/ui/types';
67
import { useUncontrolled } from 'uncontrollable';
78

89
import createWithBsPrefix from './createWithBsPrefix';
@@ -11,12 +12,7 @@ import NavbarCollapse from './NavbarCollapse';
1112
import NavbarToggle from './NavbarToggle';
1213
import { useBootstrapPrefix } from './ThemeProvider';
1314
import NavbarContext, { NavbarContextType } from './NavbarContext';
14-
import SelectableContext from './SelectableContext';
15-
import {
16-
BsPrefixProps,
17-
BsPrefixRefForwardingComponent,
18-
SelectCallback,
19-
} from './helpers';
15+
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
2016

2117
const NavbarText = createWithBsPrefix('navbar-text', {
2218
Component: 'span',

src/Offcanvas.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useCallback, useMemo, useRef } from 'react';
66
import BaseModal, {
77
ModalProps as BaseModalProps,
88
ModalHandle,
9-
} from 'react-overlays/Modal';
9+
} from '@restart/ui/Modal';
1010
import Fade from './Fade';
1111
import OffcanvasBody from './OffcanvasBody';
1212
import OffcanvasToggling from './OffcanvasToggling';
@@ -306,7 +306,6 @@ const Offcanvas: BsPrefixRefForwardingComponent<'div', OffcanvasProps> =
306306
onExiting={onExiting}
307307
onExited={handleExited}
308308
manager={getModalManager()}
309-
containerClassName={`${bsPrefix}-open`}
310309
transition={DialogTransition}
311310
backdropTransition={BackdropTransition}
312311
renderBackdrop={renderBackdrop}

src/OffcanvasToggling.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import Transition, {
77
ENTERING,
88
EXITING,
99
} from 'react-transition-group/Transition';
10+
import { TransitionCallbacks } from '@restart/ui/types';
1011
import transitionEndListener from './transitionEndListener';
11-
import { TransitionCallbacks, BsPrefixOnlyProps } from './helpers';
12+
import { BsPrefixOnlyProps } from './helpers';
1213
import TransitionWrapper from './TransitionWrapper';
1314
import { useBootstrapPrefix } from './ThemeProvider';
1415

0 commit comments

Comments
 (0)