-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from 1Hive/description-ellispsis
Description ellispsis
- Loading branch information
Showing
17 changed files
with
278 additions
and
122 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
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,105 @@ | ||
/* eslint-disable react/destructuring-assignment */ | ||
import { Button, IconDown, IconUp, IconCopy } from '@1hive/1hive-ui'; | ||
import { ReactNode, useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { useCopyToClipboard } from './hooks/use-copy-to-clipboard.hook'; | ||
import { GUpx } from './utils/css.util'; | ||
|
||
// #region StyledComponents | ||
|
||
const IconColumnStyled = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
margin-right: ${GUpx()}; | ||
`; | ||
|
||
const CollapseButtonStyled = styled.a` | ||
display: flex; | ||
cursor: pointer; | ||
text-decoration: none !important; | ||
user-select: none; | ||
flex-grow: 1; | ||
`; | ||
|
||
const CopyButtonStyled = styled(Button)` | ||
border-color: #2c3a584d; | ||
`; | ||
|
||
const LineStyled = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
`; | ||
|
||
const ContentWrapperStyled = styled.div` | ||
padding-top: ${GUpx()}; | ||
`; | ||
|
||
const LabelStyled = styled.span` | ||
height: 100%; | ||
`; | ||
|
||
// #endregion | ||
|
||
type Props = { | ||
children: any; | ||
label?: string; | ||
visible?: boolean; | ||
type?: 'image' | 'code' | 'default'; | ||
alt?: string; | ||
}; | ||
|
||
export function CollapsableBlock(props: Props) { | ||
const [isVisible, setVisible] = useState(props.visible); | ||
const copyCode = useCopyToClipboard(); | ||
|
||
useEffect(() => setVisible(props.visible), [props.visible]); | ||
|
||
const [content, setContent] = useState<ReactNode | undefined>(); | ||
|
||
useEffect(() => { | ||
// eslint-disable-next-line jsx-a11y/alt-text | ||
if (props.type === 'image') setContent(<img {...props} />); | ||
else | ||
setContent(props.children?.props?.children ? props.children.props.children : props.children); | ||
}, [props, props.children]); | ||
|
||
return ( | ||
<div> | ||
<pre> | ||
<LineStyled> | ||
<CollapseButtonStyled onClick={() => setVisible(!isVisible)}> | ||
<IconColumnStyled> | ||
{isVisible ? ( | ||
<> | ||
<IconDown size="tiny" /> | ||
<IconUp size="tiny" /> | ||
</> | ||
) : ( | ||
<> | ||
<IconUp size="tiny" /> | ||
<IconDown size="tiny" /> | ||
</> | ||
)} | ||
</IconColumnStyled> | ||
<LabelStyled> | ||
{isVisible ? 'Hide ' : 'Show '} | ||
{props.label} | ||
</LabelStyled> | ||
</CollapseButtonStyled> | ||
{isVisible && ( | ||
<CopyButtonStyled | ||
onClick={() => copyCode(content)} | ||
icon={<IconCopy />} | ||
size="small" | ||
label="Copy" | ||
display="icon" | ||
/> | ||
)} | ||
</LineStyled> | ||
{isVisible && content ? <ContentWrapperStyled>{content}</ContentWrapperStyled> : <></>} | ||
</pre> | ||
</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
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
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
Oops, something went wrong.
4ebd7d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: