mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
limit description preview length
This commit is contained in:
parent
fb9a03771f
commit
54b92aa514
@ -28,6 +28,16 @@
|
|||||||
margin-bottom: calc(var(--spacer) / 12);
|
margin-bottom: calc(var(--spacer) / 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0.15rem;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.asset {
|
.asset {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 4fr;
|
grid-template-columns: 1fr 4fr;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { FormEvent, ReactElement, useState } from 'react'
|
||||||
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
|
||||||
import Markdown from '../../atoms/Markdown'
|
import Markdown from '../../atoms/Markdown'
|
||||||
import Tags from '../../atoms/Tags'
|
import Tags from '../../atoms/Tags'
|
||||||
@ -15,12 +15,42 @@ export default function Preview({
|
|||||||
}: {
|
}: {
|
||||||
values: Partial<MetadataPublishForm>
|
values: Partial<MetadataPublishForm>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
|
const [fullDescription, setFullDescription] = useState<boolean>(false)
|
||||||
|
|
||||||
|
const textLimit = 500 // string.length
|
||||||
|
const description =
|
||||||
|
fullDescription === true
|
||||||
|
? values.description
|
||||||
|
: `${values.description.substring(0, textLimit)}${
|
||||||
|
values.description.length > textLimit ? `...` : ''
|
||||||
|
}`
|
||||||
|
|
||||||
|
function handleDescriptionToggle(e: FormEvent<HTMLButtonElement>) {
|
||||||
|
e.preventDefault()
|
||||||
|
setFullDescription(!fullDescription)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.preview}>
|
<div className={styles.preview}>
|
||||||
<h2 className={styles.previewTitle}>Preview</h2>
|
<h2 className={styles.previewTitle}>Preview</h2>
|
||||||
<header>
|
<header>
|
||||||
{values.name && <h3 className={styles.title}>{values.name}</h3>}
|
{values.name && <h3 className={styles.title}>{values.name}</h3>}
|
||||||
{values.description && <Markdown text={values.description} />}
|
|
||||||
|
{values.description && (
|
||||||
|
<div className={styles.description}>
|
||||||
|
<Markdown text={description} />
|
||||||
|
{values.description.length > textLimit && (
|
||||||
|
<Button
|
||||||
|
style="text"
|
||||||
|
size="small"
|
||||||
|
onClick={handleDescriptionToggle}
|
||||||
|
className={styles.toggle}
|
||||||
|
>
|
||||||
|
{fullDescription === true ? 'Close' : 'Expand'}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className={styles.asset}>
|
<div className={styles.asset}>
|
||||||
{values.files?.length > 0 && typeof values.files !== 'string' && (
|
{values.files?.length > 0 && typeof values.files !== 'string' && (
|
||||||
|
Loading…
Reference in New Issue
Block a user