Skip to content

Commit

Permalink
fix: fixed proptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Oct 20, 2023
1 parent b40c6e3 commit 0bd7c0f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/Chip/Chip.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { Close } from '../../icons';
import { STYLE_VARIANTS } from './constants';
import Chip from '.';

function TestChip(props) {
Expand Down Expand Up @@ -44,7 +45,7 @@ describe('<Chip />', () => {

describe('correct rendering', () => {
it('renders with correct class when variant is added', () => {
render(<TestChip variant="dark" />);
render(<TestChip variant={STYLE_VARIANTS[1]} />);
const chip = screen.getByRole('button');
expect(chip).toHaveClass('pgn__chip pgn__chip-dark');
});
Expand Down
6 changes: 3 additions & 3 deletions src/Chip/ChipIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ChipIcon({
onKeyPress={onClick}
iconAs={Icon}
alt={alt}
invertColors={variant === STYLE_VARIANTS[2]}
invertColors={variant === STYLE_VARIANTS[1]}
/>
);
}
Expand All @@ -36,15 +36,15 @@ function ChipIcon({

ChipIcon.propTypes = {
className: PropTypes.string.isRequired,
src: PropTypes.node.isRequired,
src: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired,
onClick: PropTypes.func,
alt: PropTypes.string.isRequired,
variant: PropTypes.string,
};

ChipIcon.defaultProps = {
onClick: undefined,
variant: STYLE_VARIANTS[1],
variant: STYLE_VARIANTS[0],
};

export default ChipIcon;
10 changes: 8 additions & 2 deletions src/Chip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ notes: |
isSelected
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
iconAfterAlt="icon-after"
>
New
</Chip>
Expand All @@ -51,17 +52,20 @@ notes: |
gap={2}
direction="horizontal"
>
<Chip iconBefore={Person}>New</Chip>
<Chip iconBefore={Person} iconBeforeAlt="icon-before">New</Chip>
<Chip
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
iconAfterAlt="icon-after"
>
New 1
</Chip>
<Chip
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
iconAfterAlt="icon-after"
iconBeforeAlt="icon-before"
disabled
>
New
Expand All @@ -77,18 +81,20 @@ notes: |
gap={2}
direction="horizontal"
>
<Chip variant="dark" iconBefore={Person}>New</Chip>
<Chip variant="dark" iconBefore={Person} iconBeforeAlt="icon-before">New</Chip>
<Chip
variant="dark"
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
iconAfterAlt="icon-after"
>
New 1
</Chip>
<Chip
variant="dark"
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
iconAfterAlt="icon-after"
disabled
>
New
Expand Down
3 changes: 1 addition & 2 deletions src/Chip/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export const STYLE_VARIANTS = ['light', 'dark'];

export const CHIP_PGN_CLASS = 'pgn__chip';
4 changes: 3 additions & 1 deletion src/Chip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import classNames from 'classnames';
// @ts-ignore
import { requiredWhen } from '../utils/propTypes';
// @ts-ignore
import { CHIP_PGN_CLASS, STYLE_VARIANTS } from './constants';
import { STYLE_VARIANTS } from './constants';
// @ts-ignore
import ChipIcon from './ChipIcon';

export const CHIP_PGN_CLASS = 'pgn__chip';

export interface IChip {
children: React.ReactNode,
className?: string,
Expand Down

0 comments on commit 0bd7c0f

Please sign in to comment.