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

#1482: Use the available height for the abstract text in a card #1524

Merged
merged 2 commits into from
Aug 8, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { forwardRef, useState } from 'react';
import React, { forwardRef, useState, useRef } from 'react';
import Message from '@mapstore/framework/components/I18N/Message';
import FaIcon from '@js/components/FaIcon';
import Button from '@js/components/Button';
Expand Down Expand Up @@ -36,6 +36,7 @@ const ResourceCard = forwardRef(({
pathname: `/detail/${res.resource_type}/${res.pk}`
})
}, ref) => {
const abstractRef = useRef();
const res = data;
const types = getTypesInfo();
const { icon } = types[res.subtype] || types[res.resource_type] || {};
Expand All @@ -54,15 +55,22 @@ const ResourceCard = forwardRef(({
function handleClick() {
onClick(data);
}
const imgClassName = layoutCardsStyle === 'list' ? 'card-img-left' : 'card-img-top';
const isCardLayoutList = layoutCardsStyle === 'list';
const imgClassName = isCardLayoutList ? 'card-img-left' : 'card-img-top';

const renderEllipsis = () => {
const isOverflowing = isCardLayoutList && abstractRef?.current?.clientHeight < abstractRef?.current?.scrollHeight;
return isOverflowing ? <span className="ellipsis">...</span> : null;
};

return (
<div
ref={ref}
onClick={handleClick}
className={`gn-resource-card${active ? ' active' : ''}${
readOnly ? ' read-only' : ''
} gn-card-type-${layoutCardsStyle} ${
layoutCardsStyle === 'list' ? 'rounded-0' : ''
isCardLayoutList ? 'rounded-0' : ''
}${className ? ` ${className}` : ''}`}
>
{!readOnly && (
Expand All @@ -74,7 +82,7 @@ const ResourceCard = forwardRef(({
{!readOnly &&
options &&
options.length > 0 &&
layoutCardsStyle === 'grid' && (
!isCardLayoutList && (
<ActionButtons
buildHrefByTemplate={buildHrefByTemplate}
resource={res}
Expand Down Expand Up @@ -130,13 +138,14 @@ const ResourceCard = forwardRef(({
<ResourceStatus resource={res} />
</div>
</div>
<p className="card-text gn-card-description">
<p ref={abstractRef} className={`card-text gn-card-description ${layoutCardsStyle}`}>
{res.raw_abstract ? res.raw_abstract : '...'}
</p>
{renderEllipsis()}
{!readOnly &&
options &&
options.length > 0 &&
layoutCardsStyle === 'list' && (
isCardLayoutList && (
<ActionButtons
buildHrefByTemplate={buildHrefByTemplate}
resource={res}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&.list {
white-space: unset;
max-height: 2.2rem;
&+.ellipsis {
position: absolute;
bottom: 0.625rem;
}
}
.gn-spinner {
margin-right: 0.4rem;
}
Expand Down