File size: 3,625 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 | import { FoldableCard, ExternalLink as ExternalLinkComponent } from '@automattic/components';
import { useBreakpoint } from '@automattic/viewport-react';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { Fragment } from 'react';
import InlineSupportLink from 'calypso/components/inline-support-link';
const PLUGIN_DETAILS_LINK_TYPES = {
NEW_TAB: 'NewTab',
HELP_CENTER: 'HelpCenter',
};
const Container = styled( FoldableCard )`
display: flex;
flex-direction: column;
align-items: flex-start;
width: 100%;
margin-bottom: 0;
box-shadow: none;
${ ( props ) => props.showAsAccordion && 'border-bottom: 1px solid #eeeeee' };
${ ( props ) => props.showAsAccordion && 'border-top: 1px solid var( --studio-gray-5)' };
${ ( props ) => props.showAsAccordion && props.first && 'border-top: 0' };
.foldable-card__content {
width: 100%;
}
.foldable-card__header {
padding-left: 0;
padding-right: 0;
${ ( props ) => ! props.showAsAccordion && 'display: none' };
}
// Increase specificity to avoid conflicts with foldable-card styles
&&.is-expanded .foldable-card__content {
${ ( props ) => props.first && 'border-top: 0' };
${ ( props ) => props.showAsAccordion && 'border: 0' };
padding: ${ ( props ) => ( props.first ? '0 0 24px' : '24px 0' ) };
${ ( props ) => props.showAsAccordion && 'padding: 0' };
}
&:last-child.is-expanded {
margin-bottom: 0;
&.is-expanded .foldable-card__content {
padding-bottom: 0;
}
}
`;
const Icon = styled.img`
margin-right: 6px;
width: 32px;
height: 24px;
${ ( props ) => ! props.showAsAccordion && 'margin-bottom: 12px;' };
`;
const Title = styled.div`
color: var( --studio-gray-100 );
font-size: 14px;
${ ( props ) => ! props.showAsAccordion && 'font-weight: 600' };
${ ( props ) => ! props.showAsAccordion && 'margin-bottom: 12px;' };
`;
const Description = styled.div`
color: var( --studio-gray-80 );
font-size: 14px;
${ ( props ) => props.showAsAccordion && 'margin-bottom: 12px;' };
`;
const linkStyles = css`
display: inline-block;
margin-top: 6px;
font-size: 14px;
`;
const ExternalLink = styled( ExternalLinkComponent )`
${ linkStyles }
`;
const Link = styled.a`
${ linkStyles }
`;
const StyledInlineSupportLink = styled( InlineSupportLink )`
${ linkStyles }
`;
const PluginDetailsSidebarUSP = ( {
id,
title,
description,
icon = undefined,
links = undefined,
first = false,
} ) => {
const isNarrow = useBreakpoint( '<960px' );
const Header = () => {
return (
<>
{ icon && (
<>
<Icon src={ icon.src } showAsAccordion={ isNarrow } />
</>
) }
<Title showAsAccordion={ isNarrow }>{ title }</Title>
</>
);
};
return (
<Container
key={ id }
header={ <Header /> }
expanded={ ! isNarrow }
showAsAccordion={ isNarrow }
first={ first }
>
{ ! isNarrow && <Header /> }
<Description showAsAccordion={ isNarrow }>{ description }</Description>
{ links &&
links.map( ( link, idx ) => {
const { openIn, label, ...linkProps } = link;
let LinkComponent;
if ( openIn === PLUGIN_DETAILS_LINK_TYPES.NEW_TAB ) {
LinkComponent = ExternalLink;
linkProps.icon = true;
} else if ( openIn === PLUGIN_DETAILS_LINK_TYPES.HELP_CENTER ) {
LinkComponent = StyledInlineSupportLink;
} else {
LinkComponent = Link;
}
return (
<Fragment key={ idx }>
<LinkComponent { ...linkProps }>{ label }</LinkComponent>
<br />
</Fragment>
);
} ) }
</Container>
);
};
export { PLUGIN_DETAILS_LINK_TYPES };
export default PluginDetailsSidebarUSP;
|