-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make company descriptions collapsible
- Loading branch information
Showing
4 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
app/components/CollapsibleDisplayContent/CollapsibleDisplayContent.css
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,55 @@ | ||
@import url('~app/styles/variables.css'); | ||
|
||
.collapse { | ||
position: relative; | ||
overflow: hidden; | ||
transition: height var(--easing-slow); | ||
} | ||
|
||
.base { | ||
word-break: break-word; | ||
|
||
div[data-type='todo'] > input { | ||
cursor: pointer; | ||
float: left; | ||
position: relative; | ||
top: 4px; | ||
left: -4px; | ||
} | ||
|
||
ul { | ||
margin-left: 15px; | ||
} | ||
|
||
ol { | ||
margin-left: 15px; | ||
} | ||
|
||
figure { | ||
text-align: center; | ||
font-size: 13px; | ||
} | ||
} | ||
|
||
.showMore { | ||
display: flex; | ||
justify-content: center; | ||
height: 50px; | ||
width: 100%; | ||
position: absolute; | ||
bottom: 0; | ||
background-image: linear-gradient( | ||
rgba(0, 0, 0, 0%), | ||
var(--lego-card-color), | ||
var(--lego-card-color) | ||
); | ||
cursor: pointer; | ||
} | ||
|
||
.showMoreIcon { | ||
padding: 3px; | ||
margin: 0; | ||
border-radius: 50%; | ||
background-color: var(--lego-card-color); | ||
box-shadow: 0 0 5px var(--lego-card-color); | ||
} |
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,86 @@ | ||
import Editor from '@webkom/lego-editor'; | ||
import '@webkom/lego-editor/dist/style.css'; | ||
import 'react-image-crop/dist/ReactCrop.css'; | ||
import { type CSSProperties, useRef, useState } from 'react'; | ||
import Icon from 'app/components/Icon'; | ||
import styles from './CollapsibleDisplayContent.css'; | ||
|
||
type Props = { | ||
content: string; | ||
id?: string; | ||
className?: string; | ||
style?: CSSProperties; | ||
placeholder?: string; | ||
collapsedHeight?: number; | ||
}; | ||
|
||
/** | ||
* Renders `content` produced by the Editor component in a collapsible read-only format. | ||
*/ | ||
function CollapsibleDisplayContent({ | ||
content, | ||
id, | ||
style, | ||
className, | ||
placeholder, | ||
collapsedHeight = 250, | ||
}: Props) { | ||
let domParser = null; | ||
|
||
if (!__CLIENT__) { | ||
const JSDOM = require('jsdom').JSDOM; | ||
|
||
domParser = (val) => new JSDOM(val).window.document; | ||
} | ||
|
||
const [isOpened, setIsOpened] = useState(false); | ||
|
||
const ref = useRef<HTMLDivElement>(null); | ||
const useCollapse = | ||
collapsedHeight < ref.current?.clientHeight || !ref.current; | ||
|
||
return ( | ||
<div | ||
className={styles.collapse} | ||
style={{ | ||
height: !useCollapse | ||
? null | ||
: isOpened | ||
? ref.current?.clientHeight + 50 | ||
: collapsedHeight + 'px' ?? collapsedHeight, | ||
}} | ||
> | ||
<div key={content} id={id} style={style} className={className} ref={ref}> | ||
<Editor | ||
onChange={() => {}} | ||
onBlur={() => {}} | ||
onFocus={() => {}} | ||
value={content} | ||
placeholder={placeholder} | ||
disabled | ||
domParser={domParser} | ||
/> | ||
</div> | ||
{useCollapse && ( | ||
<div | ||
className={styles.showMore} | ||
onClick={() => { | ||
setIsOpened(!isOpened); | ||
}} | ||
> | ||
<Icon | ||
name={ | ||
isOpened | ||
? 'chevron-up-circle-outline' | ||
: 'chevron-down-circle-outline' | ||
} | ||
className={styles.showMoreIcon} | ||
size={40} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default CollapsibleDisplayContent; |
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