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

Voting: fix a description overflow issue #1021

Merged
merged 3 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion apps/voting/app/src/components/AutoLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import React from 'react'
import Linkify from 'react-linkify'
import { Link } from '@aragon/ui'

const InlineLink = props => (
<Link
{...props}
css={`
display: inline;
white-space: normal;
`}
/>
)

const AutoLink = ({ children }) => (
<Linkify component={Link}>{children}</Linkify>
<Linkify component={InlineLink}>{children}</Linkify>
)

export default AutoLink
21 changes: 10 additions & 11 deletions apps/voting/app/src/components/VoteCard/VoteCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ const VoteCard = ({ vote, onOpen }) => {
display: inline-flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
width: ${2.5 * GU}px;
height: ${2.5 * GU}px;
border-radius: 50%;
background: ${theme.infoSurface.alpha(0.08)};
color: ${theme.info};
Expand All @@ -92,21 +92,20 @@ const VoteCard = ({ vote, onOpen }) => {
</div>
)}
</div>
<div
<VoteText
disabled
prefix={<span css="font-weight: bold">#{voteId}: </span>}
text={description || metadata}
title={`#${voteId}: ${description || metadata}`}
css={`
overflow: hidden;
${textStyle('body1')};
/* lines per font size per line height */
/* shorter texts align to the top */
height: 84px;
height: ${27 * 3}px; // 27px = line-height with body1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a note to the comment about 3 being the number of lines we want

display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
`}
>
<span css="font-weight: bold;">#{voteId}:</span>{' '}
<VoteText disabled text={description || metadata} />
</div>
/>
<VoteOptions options={options} votingPower={votingPower} />
<div
css={`
Expand Down
37 changes: 23 additions & 14 deletions apps/voting/app/src/components/VoteText.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@ import LocalIdentityBadge from '../components/LocalIdentityBadge/LocalIdentityBa
// Render a text associated to a vote.
// Usually vote.data.metadata and vote.data.description.
const VoteText = React.memo(
({ disabled, text = '' }) => {
function VoteText({ disabled, text, prefix, ...props }) {
// If there is no text, the component doesn’t render anything.
if (!text.trim()) {
return null
}

const TextComponent = disabled ? 'span' : AutoLink

return (
<TextComponent>
<span
css={`
a {
word-break: break-all;
white-space: normal;
text-align: left;
}
`}
>
<div
{...props}
css={`
// overflow-wrap:anywhere and hyphens:auto are not supported yet by
// the latest versions of Webkit / Blink (as of October 2019), which
// is why word-break:break-word has been added here.
hyphens: auto;
overflow-wrap: anywhere;
word-break: break-word;
`}
>
{prefix}
<TextComponent>
{text.split('\n').map((line, i) => (
<React.Fragment key={i}>
{i > 0 && <br />}
{transformAddresses(line, (part, isAddress, index) =>
isAddress ? (
<span title={part} key={index}>
Expand All @@ -41,11 +46,10 @@ const VoteText = React.memo(
<span key={index}>{part}</span>
)
)}
<br />
</React.Fragment>
))}
</span>
</TextComponent>
</TextComponent>
</div>
)
},
(prevProps, nextProps) => prevProps.text === nextProps.text
Expand All @@ -54,6 +58,11 @@ const VoteText = React.memo(
VoteText.propTypes = {
disabled: PropTypes.bool,
text: PropTypes.string,
prefix: PropTypes.node,
}

VoteText.defaultProps = {
text: '',
}

export default VoteText
9 changes: 3 additions & 6 deletions apps/voting/app/src/screens/VoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,12 @@ function VoteDetail({ vote, onBack, onVote, onExecute }) {
>
Description
</h2>
<div
<VoteText
text={description || metadata || DEFAULT_DESCRIPTION}
css={`
${textStyle('body2')};
`}
>
<VoteText
text={description || metadata || DEFAULT_DESCRIPTION}
/>
</div>
/>
</div>
<div>
<h2
Expand Down