Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit 7bc6f79

Browse files
committed
feat(view): hide overflow in boxed components
1 parent 214d059 commit 7bc6f79

File tree

3 files changed

+141
-26
lines changed

3 files changed

+141
-26
lines changed

lib/components/view.jsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const semver = require('semver')
22
const byteSize = require('byte-size')
33
const relativeDate = require('tiny-relative-date')
44
const columns = require('cli-columns')
5+
const sliceAnsi = require('slice-ansi')
56

67
const {
78
h, // eslint-disable-line
@@ -45,6 +46,11 @@ class Columns extends Component {
4546
sort: false
4647
})
4748
}
49+
50+
const Line = ({ width, children }) => {
51+
const string = children.map(renderToString).join('')
52+
const sliced = sliceAnsi(string, 0, width)
53+
return string === sliced ? string : sliceAnsi(string, 0, width - 3) + '...'
4854
}
4955

5056
const packageValueObjectItems = function ({ field, value, props, maxItems }) {
@@ -285,6 +291,7 @@ module.exports.PackageFields = PackageFields
285291

286292
class PackageSummary extends Component {
287293
render () {
294+
const width = process.env.COLUMNS - 2
288295
let { packument, spec } = this.props
289296
let [data] = getData(packument, spec)
290297
let views = data.map((pkg) => {
@@ -309,8 +316,12 @@ class PackageSummary extends Component {
309316
</span>
310317
</div>
311318

312-
<div>{pkg.description}</div>
313-
<span><PackageValue {...getProps('homepage')} /> - <PackageValue {...getProps('keywords')} /></span>
319+
<div><Line width={width}>{pkg.description}</Line></div>
320+
<span>
321+
<Line width={width}>
322+
<PackageValue {...getProps('homepage')} /> - <PackageValue {...getProps('keywords')} />
323+
</Line>
324+
</span>
314325
</Box>
315326
})
316327

@@ -324,6 +335,7 @@ module.exports.PackageSummary = PackageSummary
324335

325336
class PackageSearchResult extends Component {
326337
render () {
338+
const width = process.env.COLUMNS - 2
327339
const { result: { package: pkg } } = this.props
328340
return <Box>
329341
<div>
@@ -337,8 +349,12 @@ class PackageSearchResult extends Component {
337349
</span>
338350
</div>
339351

340-
<div>{pkg.description}</div>
341-
<span><PackageValue field='homepage' value={pkg.links.homepage} /> - <PackageValue field='keywords' value={pkg.keywords} /></span>
352+
<div><Line width={width}>{pkg.description}</Line></div>
353+
<span>
354+
<Line width={width}>
355+
<PackageValue field='homepage' value={pkg.links.homepage} /> - <PackageValue field='keywords' value={pkg.keywords} />
356+
</Line>
357+
</span>
342358
</Box>
343359
}
344360
}

package-lock.json

Lines changed: 120 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"read": "^1.0.7",
110110
"rimraf": "^2.6.3",
111111
"semver": "^5.6.0",
112+
"slice-ansi": "^2.0.0",
112113
"spawn-wrap": "^1.4.2",
113114
"ssri": "^6.0.1",
114115
"stringify-package": "^1.0.0",

0 commit comments

Comments
 (0)