Skip to content

Commit

Permalink
Merge pull request #571 from jiru/manylinks_ux
Browse files Browse the repository at this point in the history
Enhance display of many link previews
  • Loading branch information
MrOrz authored Jul 21, 2024
2 parents b8d64a7 + ab0688a commit d107a16
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions components/Hyperlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { HyperlinkIcon } from 'components/icons';

const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexFlow: 'row',
flexWrap: 'wrap',
},
linkcard: {
padding: '12px 16px',
margin: '0 8px 8px 0',
background: theme.palette.secondary[50],
Expand All @@ -23,6 +28,20 @@ const useStyles = makeStyles(theme => ({
fontSize: 14,
},
},
multilink: {
[theme.breakpoints.down('sm')]: {
flexWrap: 'nowrap',
overflowX: 'auto',
'--gutter': `${theme.spacing(2)}px`,
marginLeft: 'calc(-1 * var(--gutter))',
marginRight: 'calc(-1 * var(--gutter))',
paddingLeft: 'var(--gutter)',
paddingRight: 'var(--gutter)',
'& article': {
maxWidth: '90%',
},
},
},
url: {
color: theme.palette.secondary[300],
display: 'flex',
Expand Down Expand Up @@ -136,7 +155,7 @@ function Hyperlink({ hyperlink, rel = '' }) {
const classes = useStyles({ topImageUrl });

return (
<article className={classes.root}>
<article className={classes.linkcard}>
<h1 title={title}>{title}</h1>
<div className={classes.preview}>
<p className="summary" title={summary}>
Expand Down Expand Up @@ -177,21 +196,19 @@ function PollingHyperlink({ pollingType, pollingId }) {
* @param {string?} props.rel - rel prop for the hyperlink (other than noopener and noreferrer)
*/
function Hyperlinks({ hyperlinks, pollingType, pollingId, rel }) {
const classes = useStyles();
if (!((pollingId && pollingType) || (!pollingId && !pollingType))) {
throw new Error('pollingType and pollingId must be specified together');
}

if (hyperlinks && hyperlinks.length === 0) return null;

let className = `${classes.root}`;
if (hyperlinks.length > 1) {
className += ` ${classes.multilink}`;
}
return (
<Box
component="section"
display="flex"
flexDirection="row"
flexWrap="wrap"
mt={2}
mb={1}
>
<Box className={className} component="section" mt={2} mb={1}>
{(hyperlinks || []).map((hyperlink, idx) => (
<Hyperlink key={idx} hyperlink={hyperlink} rel={rel} />
))}
Expand Down

0 comments on commit d107a16

Please sign in to comment.