Skip to content

Commit

Permalink
chore: typing cleanups for <Chip> code
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Jun 17, 2024
1 parent 1b642a6 commit 4cd7029
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
12 changes: 5 additions & 7 deletions src/Chip/Chip.test.jsx → src/Chip/Chip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Close } from '../../icons';
import { STYLE_VARIANTS } from './constants';
import Chip from '.';

function TestChip(props) {
function TestChip(props: Omit<React.ComponentProps<typeof Chip>, 'children'>) {
return (
<Chip {...props}>
Test
Expand Down Expand Up @@ -42,15 +42,13 @@ describe('<Chip />', () => {
iconBeforeAlt="close icon"
iconAfter={Close}
iconAfterAlt="close icon"
>
Chip
</TestChip>
/>
)).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders div with "button" role when onClick is provided', () => {
const tree = renderer.create((
<TestChip onClick={jest.fn}>Chip</TestChip>
<TestChip onClick={jest.fn} />
)).toJSON();
expect(tree).toMatchSnapshot();
});
Expand Down Expand Up @@ -104,7 +102,7 @@ describe('<Chip />', () => {
/>,
);
const iconAfter = screen.getByLabelText('icon-after');
await userEvent.click(iconAfter, '{enter}', { skipClick: true });
await userEvent.click(iconAfter);
expect(func).toHaveBeenCalledTimes(1);
});
it('onIconBeforeClick is triggered', async () => {
Expand All @@ -130,7 +128,7 @@ describe('<Chip />', () => {
/>,
);
const iconBefore = screen.getByLabelText('icon-before');
await userEvent.click(iconBefore, '{enter}', { skipClick: true });
await userEvent.click(iconBefore);
expect(func).toHaveBeenCalledTimes(1);
});
it('checks the absence of the `selected` class in the chip', async () => {
Expand Down
12 changes: 6 additions & 6 deletions src/Chip/ChipIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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 interface ChipIconProps {
export type ChipIconProps = {
className: string,
src: React.ComponentType,
onClick?: KeyboardEventHandler & MouseEventHandler,
alt: string,
variant: string,
disabled?: boolean,
}
} & (
// Either _both_ onClick and alt are provided, or neither is:
| { onClick: KeyboardEventHandler & MouseEventHandler, alt: string }
| { onClick?: undefined, alt?: undefined }
);

function ChipIcon({
className, src, onClick, alt, variant, disabled,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Chip/constants.js → src/Chip/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
export const STYLE_VARIANTS = {
DARK: 'dark',
LIGHT: 'light',
};
} as const;
2 changes: 0 additions & 2 deletions src/Chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import PropTypes, { type Requireable } from 'prop-types';
import classNames from 'classnames';
// @ts-ignore
import { requiredWhen } from '../utils/propTypes';
// @ts-ignore
import { STYLE_VARIANTS } from './constants';
// @ts-ignore
import ChipIcon from './ChipIcon';

export const CHIP_PGN_CLASS = 'pgn__chip';
Expand Down
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

0 comments on commit 4cd7029

Please sign in to comment.