Skip to content

Commit

Permalink
feat: Add TypeScript types for <Overlay>, <OverlayTrigger>, <Tooltip>…
Browse files Browse the repository at this point in the history
…, <IconButton> (#3100)

* feat: add typings for <Overlay> and <OverlayTrigger>

* feat: add typings for <Tooltip>

* feat: add typings for <IconButton>

* chore: typing cleanups for <Chip> code

* feat: slightly more detailed types for <Chip/ChipIcon> - per review
  • Loading branch information
bradenmacdonald authored and PKulkoRaccoonGang committed Aug 5, 2024
1 parent d1a91a0 commit 6c05506
Show file tree
Hide file tree
Showing 10 changed files with 787 additions and 201 deletions.
918 changes: 768 additions & 150 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/Chip/ChipIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { KeyboardEventHandler, MouseEventHandler } from 'react';
import PropTypes from 'prop-types';
import Icon from '../Icon';
// @ts-ignore
import IconButton from '../IconButton';
// @ts-ignore
import { STYLE_VARIANTS } from './constants';

export type ChipIconProps = {
Expand Down
5 changes: 0 additions & 5 deletions src/Chip/constants.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/ChipCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { useIntl } from 'react-intl';
import classNames from 'classnames';
// @ts-ignore
import { OverflowScroll, OverflowScrollContext } from '../OverflowScroll';
// @ts-ignore
import IconButton from '../IconButton';
// @ts-ignore
import Icon from '../Icon';
// @ts-ignore
import { ArrowForward, ArrowBack } from '../../icons';
Expand Down
32 changes: 5 additions & 27 deletions src/IconButton/__snapshots__/IconButton.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,11 @@ exports[`<IconButton /> renders with deprecated props 1`] = `
<span
className="btn-icon__icon-container"
>
<svg
aria-hidden="true"
className="svg-inline--fa fa-InfoOutlineIcon btn-icon__icon"
data-icon="InfoOutlineIcon"
data-prefix="pgn"
focusable="false"
role="img"
style={{}}
viewBox="0 0 function SvgInfoOutline(props) {
return /*#__PURE__*/React.createElement("svg", _extends({
width: 24,
height: 24,
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg"
}, props), /*#__PURE__*/React.createElement("path", {
d: "M11 7h2v2h-2V7Zm0 4h2v6h-2v-6Zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2Zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8Z",
fill: "currentColor"
}));
} undefined"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill="currentColor"
style={{}}
/>
</svg>
<span
aria-hidden={true}
className="btn-icon__icon"
id="Icon1"
/>
</span>
</button>
`;
Expand Down
14 changes: 8 additions & 6 deletions src/IconButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { OverlayTrigger } from '../Overlay';
import Tooltip from '../Tooltip';

interface Props extends React.HTMLAttributes<HTMLButtonElement> {
iconAs?: typeof Icon | typeof FontAwesomeIcon,
iconAs?: React.ComponentType<any>,
/** Additional CSS class[es] to apply to this button */
className?: string;
/** Alt text for your icon. For best practice, avoid using alt text to describe
Expand Down Expand Up @@ -75,11 +75,13 @@ const IconButton = React.forwardRef<HTMLButtonElement, Props>(({
{...attrs}
>
<span className="btn-icon__icon-container">
<IconComponent
className={classNames('btn-icon__icon', iconClassNames)}
icon={icon as any}
src={src}
/>
{IconComponent && (
<IconComponent
className={classNames('btn-icon__icon', iconClassNames)}
icon={icon as any}
src={src}
/>
)}
</span>
</button>
);
Expand Down
5 changes: 3 additions & 2 deletions src/Overlay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import BaseOverlay, { type OverlayProps, type Placement } from 'react-bootstrap/Overlay';
import BaseOverlayTrigger, { type OverlayTriggerProps, type OverlayTriggerType } from 'react-bootstrap/OverlayTrigger';
import Fade from 'react-bootstrap/Fade';
import PropTypes from 'prop-types';

// Note: The only thing this file adds to the base component is propTypes validation.
Expand Down Expand Up @@ -92,7 +93,7 @@ Overlay.propTypes = {
* Animate the entering and exiting of the Overlay. `true` will use the `<Fade>` transition,
* or a custom react-transition-group `<Transition>` component can be provided.
*/
transition: PropTypes.oneOfType([PropTypes.bool, PropTypes.elementType]),
transition: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
};

OverlayTrigger.propTypes = {
Expand Down Expand Up @@ -148,7 +149,7 @@ Overlay.defaultProps = {
rootCloseEvent: undefined,
show: false,
target: undefined,
transition: true,
transition: Fade,
};

OverlayTrigger.defaultProps = {
Expand Down
4 changes: 0 additions & 4 deletions src/setupTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ class ResizeObserver {
}

window.ResizeObserver = ResizeObserver;

(window as any).crypto = {
getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
};
2 changes: 1 addition & 1 deletion www/src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const {

export type CollapsibleLiveEditorTypes = {
children: React.ReactNode;
clickToCopy: (arg: string) => void;
clickToCopy: () => void;
handleCodeChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
};

Expand Down
4 changes: 2 additions & 2 deletions www/src/components/css-utilities-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { colorCSSDeclaration } from './utils';

function CSSUtilitiesTable({ selectors }: CSSUtilities) {
const [showPopover, setShowPopover] = useState<boolean>(false);
const [popoverTarget, setPopoverTarget] = useState<EventTarget | undefined>(undefined);
const [popoverTarget, setPopoverTarget] = useState<HTMLElement | undefined>(undefined);
const [computedStyle, setComputedStyle] = useState<string>('');

useEffect(() => {
Expand All @@ -21,7 +21,7 @@ function CSSUtilitiesTable({ selectors }: CSSUtilities) {
}, []);

const handleCSSVariableMouseEnter = (e: React.MouseEvent, declaration: string) => {
setPopoverTarget(e.target);
setPopoverTarget(e.target as HTMLElement);
setShowPopover(true);

const propertyName = declaration.split(':')[0];
Expand Down

0 comments on commit 6c05506

Please sign in to comment.