Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ExpressiveCard): implement typescript types #4960

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,128 @@
// LICENSE file in the root directory of this source tree.
//

import React, { forwardRef } from 'react';
import React, { PropsWithChildren, ReactNode, forwardRef } from 'react';
import PropTypes from 'prop-types';
import { Card } from '../Card';

import { getDevtoolsProps } from '../../global/js/utils/devtools';
import { prepareProps } from '../../global/js/utils/props-helper';
import { pkg } from '../../settings';

type ActionIcon = {
id?: string;
icon?: () => void | object;
onKeydown?: () => void;
onClick?: () => void;
iconDescription?: string;
href?: string;
};

interface ExpressiveCardProps extends PropsWithChildren {
/**
* Icons that are displayed on card. Refer to design documentation for implementation guidelines. Note- href will supersede onClick
*/
actionIcons?: ActionIcon[];
/**
* Content that shows in the body of the card
*/
// children: PropTypes.node,
/**
* Optional user provided class
*/
className?: string;
/**
* Optional header description
*/
description?: string | object | ReactNode;
/**
* Optional label for the top of the card
*/
label?: string | object | ReactNode;
/**
* Optional media content like an image to be placed in the card
*/
media?: ReactNode;
/**
* Establishes the position of the media in the card
*/
mediaPosition?: 'top' | 'left';
/**
* Provides the callback for a clickable card
*/
onClick?: () => void;
/**
* Function that's called from the primary button or action icon
*/
onPrimaryButtonClick?: () => void;
/**
* Function that's called from the secondary button
*/
onSecondaryButtonClick?: () => void;
/**
* Provides the icon that's displayed at the top of the card
*/
pictogram?: () => void | object;
/**
* Optionally specify an href for your Button to become an <a> element
*/
primaryButtonHref?: string;
/**
* Optional prop to allow overriding the icon rendering. Can be a React component class
*/
primaryButtonIcon?: () => void | object;
/**
* Establishes the kind of button displayed for the primary button
*/
primaryButtonKind?: 'primary' | 'ghost';
/**
* The text that's displayed in the primary button
*/
primaryButtonText?: string;
/**
* Optionally specify an href for your Button to become an <a> element
*/
secondaryButtonHref?: string;
/**
* Optional prop to allow overriding the icon rendering. Can be a React component class
*/
secondaryButtonIcon?: () => void | object;
/**
* Establishes the kind of button displayed for the secondary button
*/
secondaryButtonKind?: 'secondary' | 'ghost';
/**
* The text that's displayed in the secondary button
*/
secondaryButtonText?: string;
/**
* **Experimental:** For all cases a `Slug` component can be provided.
* Clickable tiles only accept a boolean value of true and display a hollow slug.
*/
slug?: ReactNode | boolean;

/**
* Title that's displayed at the top of the card
*/
title?: string | object | ReactNode;
}

const componentName = 'ExpressiveCard';

export let ExpressiveCard = forwardRef((props, ref) => {
const validProps = prepareProps(props, [
'actionIconsPosition',
'overflowActions',
'productive',
'titleSize',
]);
export let ExpressiveCard = forwardRef(
(props: ExpressiveCardProps, ref: React.Ref<HTMLDivElement>) => {
const validProps = prepareProps(props, [
'actionIconsPosition',
'overflowActions',
'productive',
'titleSize',
]);

return (
<Card ref={ref} {...validProps} {...getDevtoolsProps(componentName)} />
);
});
return (
<Card ref={ref} {...validProps} {...getDevtoolsProps(componentName)} />
);
}
);

// Return a placeholder if not released and not enabled by feature flag
ExpressiveCard = pkg.checkComponentEnabled(ExpressiveCard, componentName);
Expand All @@ -35,6 +135,7 @@ ExpressiveCard.propTypes = {
/**
* Icons that are displayed on card. Refer to design documentation for implementation guidelines. Note- href will supersede onClick
*/
/**@ts-ignore */
actionIcons: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
Expand Down Expand Up @@ -92,6 +193,7 @@ ExpressiveCard.propTypes = {
/**
* Provides the icon that's displayed at the top of the card
*/
/**@ts-ignore */
pictogram: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Optionally specify an href for your Button to become an <a> element
Expand All @@ -100,6 +202,7 @@ ExpressiveCard.propTypes = {
/**
* Optional prop to allow overriding the icon rendering. Can be a React component class
*/
/**@ts-ignore */
primaryButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Establishes the kind of button displayed for the primary button
Expand All @@ -116,6 +219,7 @@ ExpressiveCard.propTypes = {
/**
* Optional prop to allow overriding the icon rendering. Can be a React component class
*/
/**@ts-ignore */
secondaryButtonIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**
* Establishes the kind of button displayed for the secondary button
Expand Down
Loading