-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renterd): alerts collapse large errors
- Loading branch information
1 parent
19b7257
commit 62bb9cf
Showing
6 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'renterd': minor | ||
--- | ||
|
||
Alerts with large errors are now collapsed by default and have a control to expand and collapse the full contents. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@siafoundation/design-system': minor | ||
--- | ||
|
||
Added ExpandableText. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Button } from './Button' | ||
import { Text } from './Text' | ||
import { useState, useRef, useEffect } from 'react' | ||
import { cx } from 'class-variance-authority' | ||
|
||
type Props = { | ||
text: string | ||
maxHeight?: number | ||
size?: '10' | '12' | '14' | '16' | '18' | '20' | ||
color?: 'subtle' | 'contrast' | 'green' | 'amber' | 'red' | ||
} | ||
|
||
export function ExpandableText({ | ||
text, | ||
maxHeight = 96, | ||
size = '12', | ||
color = 'subtle', | ||
}: Props) { | ||
const [isExpanded, setIsExpanded] = useState(false) | ||
const [canExpand, setCanExpand] = useState(false) | ||
const contentRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (contentRef.current) { | ||
setCanExpand(contentRef.current.scrollHeight > maxHeight) | ||
} | ||
}, [maxHeight, text]) | ||
|
||
return ( | ||
<div className="flex flex-col gap-1"> | ||
<div className="relative"> | ||
<div | ||
ref={contentRef} | ||
className="overflow-hidden transition-[max-height] duration-300" | ||
style={{ maxHeight: !isExpanded ? maxHeight : undefined }} | ||
> | ||
<Text size={size} color={color}> | ||
{text} | ||
</Text> | ||
</div> | ||
{!isExpanded && canExpand && ( | ||
<div | ||
className={cx( | ||
'absolute bottom-0 left-0 right-0 h-[48px]', | ||
'bg-gradient-to-b from-transparent', | ||
'dark:via-graydark-50/80 dark:to-graydark-50', | ||
'via-gray-50/80 to-gray-50' | ||
)} | ||
/> | ||
)} | ||
</div> | ||
{canExpand && ( | ||
<div | ||
className={cx( | ||
'flex justify-center', | ||
isExpanded && 'sticky bottom-2 z-10' | ||
)} | ||
> | ||
<Button | ||
variant="gray" | ||
size="small" | ||
onClick={() => setIsExpanded(!isExpanded)} | ||
className={cx( | ||
isExpanded && 'bg-gray-50 dark:bg-graydark-50', | ||
isExpanded && 'shadow-md' | ||
)} | ||
> | ||
{isExpanded ? 'Show less' : 'Show more'} | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters