Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"presets": [
["@babel/preset-env", { "modules": false } ],
["@babel/preset-react", { "useSpread": true } ],
["@babel/preset-react", { "useSpread": true, "runtime": "automatic" } ],
"@babel/preset-typescript"
],
"env": {
"test": {
"presets": [
["@babel/preset-env", {}],
["@babel/preset-react", { "useSpread": true } ],
["@babel/preset-react", { "useSpread": true, "runtime": "automatic" } ],
"@babel/preset-typescript"
]
}
Expand Down
8 changes: 5 additions & 3 deletions src/Card/BaseCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import type { ReactNode } from 'react';
// React import needed to support JSX outside functions
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

Expand Down Expand Up @@ -34,11 +36,11 @@ interface Props extends BsPropsWithAs {
borderColor?: ColorVariant;
hasBody?: boolean;
className?: string;
children: React.ReactNode;
children: ReactNode;
}
type BaseCardType = ComponentWithAsProp<'div', Props>;

const BaseCard : BaseCardType = React.forwardRef<HTMLDivElement, Props>(
const BaseCard : BaseCardType = forwardRef<HTMLDivElement, Props>(
(
{
prefix,
Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardBody.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

const CardBody = React.forwardRef(({ className, children, ...rest }, ref) => (
const CardBody = forwardRef(({ className, children, ...rest }, ref) => (
<div className={classNames('pgn__card-body', className)} ref={ref} {...rest}>
{children}
</div>
Expand Down
1 change: 0 additions & 1 deletion src/Card/CardCarousel/CardCarousel.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import PropTypes from 'prop-types';
import { OverflowScroll } from '../../OverflowScroll';
import CardCarouselProvider from './CardCarouselProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/Card/CardCarousel/CardCarouselControls.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import { useContext } from 'react';
import { useIntl } from 'react-intl';
import Stack from '../../Stack';
import IconButton from '../../IconButton';
Expand Down
2 changes: 1 addition & 1 deletion src/Card/CardCarousel/CardCarouselHeader.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, isValidElement } from 'react';
import { useContext, isValidElement } from 'react';
import PropTypes from 'prop-types';
import CardCarouselTitle from './CardCarouselTitle';
import CardCarouselSubtitle from './CardCarouselSubtitle';
Expand Down
2 changes: 1 addition & 1 deletion src/Card/CardCarousel/CardCarouselItems.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import { useContext } from 'react';
import PropTypes from 'prop-types';
import CardDeck from '../CardDeck';
import { CardCarouselContext } from './CardCarouselProvider';
Expand Down
2 changes: 1 addition & 1 deletion src/Card/CardCarousel/CardCarouselProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useContext, useMemo } from 'react';
import { createContext, useContext, useMemo } from 'react';
import PropTypes from 'prop-types';
import { OverflowScrollContext } from '../../OverflowScroll';

Expand Down
1 change: 0 additions & 1 deletion src/Card/CardCarousel/CardCarouselSubtitle.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

Expand Down
1 change: 0 additions & 1 deletion src/Card/CardCarousel/CardCarouselTitle.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

Expand Down
1 change: 0 additions & 1 deletion src/Card/CardCarousel/tests/CardCarousel.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import PropTypes from 'prop-types';
import renderer from 'react-test-renderer';
import { v4 as uuidv4 } from 'uuid';
Expand Down
1 change: 0 additions & 1 deletion src/Card/CardCarousel/tests/CardCarouselControls.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import PropTypes from 'prop-types';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand Down
1 change: 1 addition & 0 deletions src/Card/CardContext.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// React import needed to support JSX outside functions
import React, { createContext } from 'react';
import PropTypes from 'prop-types';

Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardDeck.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { Children, useMemo } from 'react';
import { forwardRef, Children, useMemo } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import { useOverflowScrollItems } from '../OverflowScroll';

const CardDeck = React.forwardRef(({
const CardDeck = forwardRef(({
className,
children,
columnSizes,
Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardDivider.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

const CardDivider = React.forwardRef(({ className, ...props }, ref) => (
const CardDivider = forwardRef(({ className, ...props }, ref) => (
<div className={classNames('pgn__card-divider', className)} ref={ref} {...props} />
));

Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardFooter.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useContext } from 'react';
import { forwardRef, useContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Skeleton from 'react-loading-skeleton';
import CardContext from './CardContext';

const IS_LOADING_HEIGHT_VALUE = 18;

const CardFooter = React.forwardRef(({
const CardFooter = forwardRef(({
children,
className,
isStacked,
Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardGrid.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import { Children, useMemo } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import Row from 'react-bootstrap/Row';
Expand All @@ -11,7 +11,7 @@ function CardGrid({
hasEqualColumnHeights,
}) {
const cards = useMemo(
() => React.Children.map(children, (card) => (
() => Children.map(children, (card) => (
<Col
{...columnSizes}
className={classNames(
Expand Down
11 changes: 7 additions & 4 deletions src/Card/CardHeader.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React, { useCallback, useContext } from 'react';
// React import needed to support JSX outside functions
import React, {
forwardRef, isValidElement, cloneElement, useCallback, useContext,
} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Skeleton from 'react-loading-skeleton';
import CardContext from './CardContext';

const SKELETON_HEIGHT_VALUE = 20;

const CardHeader = React.forwardRef(({
const CardHeader = forwardRef(({
actions,
className,
size,
Expand All @@ -18,13 +21,13 @@ const CardHeader = React.forwardRef(({
const { isLoading } = useContext(CardContext);
const cloneActions = useCallback(
(Action) => {
if (React.isValidElement(Action)) {
if (isValidElement(Action)) {
const { children } = Action.props;
const addtlActionProps = {
size,
children: Array.isArray(children) ? children.map(cloneActions) : cloneActions(children),
};
return React.cloneElement(Action, addtlActionProps);
return cloneElement(Action, addtlActionProps);
}

return Action;
Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardImageCap.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useState } from 'react';
import { forwardRef, useContext, useState } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Skeleton from 'react-loading-skeleton';
Expand All @@ -8,7 +8,7 @@ import { cardSrcFallbackImg } from './CardFallbackDefaultImage';
const SKELETON_HEIGHT_VALUE = 140;
const LOGO_SKELETON_HEIGHT_VALUE = 41;

const CardImageCap = React.forwardRef(({
const CardImageCap = forwardRef(({
src,
fallbackSrc,
srcAlt,
Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardSection.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useContext } from 'react';
import { forwardRef, useContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Skeleton from 'react-loading-skeleton';
import CardContext from './CardContext';

const SKELETON_HEIGHT_VALUE = 100;

const CardSection = React.forwardRef(({
const CardSection = forwardRef(({
className,
children,
title,
Expand Down
4 changes: 2 additions & 2 deletions src/Card/CardStatus.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useContext } from 'react';
import { forwardRef, useContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Skeleton from 'react-loading-skeleton';
import Icon from '../Icon';
import CardContext from './CardContext';

const CardStatus = React.forwardRef(({
const CardStatus = forwardRef(({
className,
children,
variant,
Expand Down
5 changes: 3 additions & 2 deletions src/Card/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
// React import needed to support JSX outside functions
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import BaseCard from './BaseCard';
Expand All @@ -14,7 +15,7 @@ import withDeprecatedProps, { DeprTypes } from '../withDeprecatedProps';

export const CARD_VARIANTS = ['light', 'dark', 'muted'];

const Card = React.forwardRef(({
const Card = forwardRef(({
orientation,
isLoading,
className,
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/BaseCard.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { render, screen } from '@testing-library/react';

import BaseCard from '../BaseCard';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardBody.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import renderer from 'react-test-renderer';
import CardBody from '../CardBody';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardContext.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import renderer from 'react-test-renderer';
import { CardContextProvider } from '../CardContext';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardDeck.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { v4 as uuidv4 } from 'uuid';
import CardDeck from '../CardDeck';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardDivider.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import CardDivider from '../CardDivider';

Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardFooter.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { render } from '@testing-library/react';
import Button from '../../Button';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardGrid.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import CardGrid from '../CardGrid';
import Card from '..';
Expand Down
11 changes: 8 additions & 3 deletions src/Card/tests/CardHeader.test.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { render } from '@testing-library/react';
import Button from '../../Button';
import CardHeader from '../CardHeader';
import CardContext from '../CardContext';

// eslint-disable-next-line react/prop-types
function CardHeaderWrapper({ isLoading }) {
function CardHeaderWrapper({ isLoading, size = 'md', actions = null }) {
return (
<CardContext.Provider value={{ isLoading }}>
<CardHeader />
<CardHeader size={size} actions={actions} />
</CardContext.Provider>
);
}
Expand Down Expand Up @@ -48,4 +47,10 @@ describe('<CardHeader />', () => {
const { container } = render(<CardHeaderWrapper isLoading />);
expect(container.querySelector('.pgn__card-header-loader')).toBeTruthy();
});

it('renders with size sm and actions', () => {
const actions = <>Actions</>;
const { getByText } = render(<CardHeaderWrapper size="sm" actions={actions} />);
expect(getByText('Actions')).toBeInTheDocument();
});
});
1 change: 0 additions & 1 deletion src/Card/tests/CardImageCap.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { render, fireEvent, screen } from '@testing-library/react';
import CardImageCap from '../CardImageCap';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardSection.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { render } from '@testing-library/react';
import Button from '../../Button';
Expand Down
1 change: 0 additions & 1 deletion src/Card/tests/CardStatus.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { render, screen } from '@testing-library/react';

Expand Down