File size: 4,014 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
import { Card } from '@automattic/components';
import { Icon, plugins } from '@wordpress/icons';
import clsx from 'clsx';
import FormInputCheckbox from 'calypso/components/forms/form-checkbox';
import PluginCommonActions from '../plugin-common-actions';
import type { Columns, RowFormatterArgs } from '../../types';
import type { SiteDetails } from '@automattic/data-stores';
import type { ReactElement, ReactNode } from 'react';
import './style.scss';
interface Props {
item: any;
selectedSite?: SiteDetails;
rowFormatter: ( args: RowFormatterArgs ) => ReactNode;
columns: Columns;
renderActions?: ( args: any ) => ReactElement;
}
export default function PluginCommonCard( {
item,
selectedSite,
rowFormatter,
columns,
renderActions,
}: Props ) {
const columnKeys: { [ key: string ]: boolean } = columns.reduce(
( obj, cur ) => ( { ...obj, [ cur.key ]: true } ),
{}
);
const showLeftContent = columnKeys[ 'plugin' ];
return (
<Card className="plugin-common-card__card" compact>
<div className="plugin-common-card__columns">
{ showLeftContent && (
<>
<div className="plugin-common-card__left-checkbox">
{ item?.isSelectable && (
<FormInputCheckbox
className="plugin-row-formatter__checkbox"
id={ item.slug }
onClick={ item.onClick }
checked={ item.isSelected }
readOnly
/>
) }
</div>
<div className="plugin-common-card__left-content">
{ item.icon ? (
<img
className="plugin-common-card__plugin-icon"
src={ item.icon }
alt={ item.name }
/>
) : (
<Icon
size={ 32 }
icon={ plugins }
className="plugin-common-card__plugin-icon plugin-default-icon"
/>
) }
</div>
</>
) }
<div
className={ clsx( 'plugin-common-card__main-content', {
'no-padding': ! showLeftContent,
} ) }
>
{ columnKeys[ 'plugin' ] && (
<div>
{ rowFormatter( { columnKey: 'plugin', item, isSmallScreen: true } ) }
<span className="plugin-common-card__overlay"></span>
</div>
) }
{ columnKeys[ 'site-name' ] && (
<div>
{ rowFormatter( { columnKey: 'site-name', item } ) }
<span className="plugin-common-card__overlay"></span>
</div>
) }
{ columnKeys[ 'update' ] &&
rowFormatter( {
columnKey: 'update',
item,
isSmallScreen: true,
} ) }
{ columnKeys[ 'last-updated' ] && (
<div className="plugin-common-card__site-data">
{ rowFormatter( {
columnKey: 'last-updated',
item,
isSmallScreen: true,
} ) }
</div>
) }
{ ( columnKeys[ 'active' ] || columnKeys[ 'autoupdate' ] ) && (
<div className="plugin-common-card__toggle-container">
{ columnKeys[ 'activate' ] && (
<div>
{ rowFormatter( {
columnKey: 'activate',
item,
isSmallScreen: true,
selectedSite,
} ) }
</div>
) }
{ columnKeys[ 'autoupdate' ] && (
<div>
{ rowFormatter( {
columnKey: 'autoupdate',
item,
isSmallScreen: true,
selectedSite,
} ) }
</div>
) }
</div>
) }
{ columnKeys[ 'sites' ] && (
<div className="plugin-common-card__site-data plugin-common-card__installed-on">
{ rowFormatter( {
columnKey: 'sites',
item,
isSmallScreen: true,
} ) }
</div>
) }
{ columnKeys[ 'install' ] && (
<div className="plugin-common-card__install-button">
{ rowFormatter( {
columnKey: 'install',
item,
isSmallScreen: true,
} ) }
</div>
) }
</div>
{ renderActions && (
<div className="plugin-common-card__right-content">
<PluginCommonActions item={ item } renderActions={ renderActions } />
</div>
) }
</div>
</Card>
);
}
|