-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MIM-1962:Startet on Expansion Box * MIM-1962: Lagt til effekt ved åpne og lukk * MIM-1962: Starten på SneakPeek og Icon * Litt mer fiksing på sneakPeek * Ryddet i css * Added test and readme * MIM-1962: refaktorering av koden * MIM-1962:Lagt til mobil styling * Fixed sass warning nested rules * Lagt til ExpansionBox til index.js * Added information about deprecated component FaxtBox * converted from jsx to tsx * MIM-1962:Refactoring after QA Teknisk * More refactoring css * Added setMaxHeigh to improve open and close content * Updated bundle.css and bumped version to 2.2.0
- Loading branch information
Showing
25 changed files
with
872 additions
and
91 deletions.
There are no files selected for viewing
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,51 @@ | ||
import React, { useEffect, useRef, useState, ReactNode } from 'react' | ||
import { ChevronDown, ChevronUp } from 'react-feather' | ||
|
||
export interface ExpansionBoxProps { | ||
className?: string | ||
header: string | ||
icon?: ReactNode | ||
openByDefault?: boolean | ||
sneakPeek?: boolean | ||
text: string | ReactNode | ||
} | ||
const ExpansionBox: React.FC<ExpansionBoxProps> = ({ | ||
className = '', | ||
header = '', | ||
icon, | ||
openByDefault = false, | ||
sneakPeek, | ||
text = '', | ||
}) => { | ||
const [isOpen, toggleOpen] = useState(openByDefault) | ||
const [maxHeight, setMaxHeight] = useState('') | ||
const contentRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
if (contentRef.current) { | ||
const contentHeight = contentRef.current.scrollHeight | ||
const maxHeightValue = contentHeight <= 1000 ? contentHeight : 1000 | ||
setMaxHeight(isOpen ? `${maxHeightValue}px` : '') | ||
} | ||
}, [isOpen]) | ||
|
||
return ( | ||
<div | ||
className={`ssb-expansion-box${className ? ` ${className}` : ''}${isOpen ? ' open' : ''}${sneakPeek ? ` sneak-peek` : ''}`} | ||
> | ||
<button className='header' aria-expanded={isOpen ? 'true' : 'false'} onClick={() => toggleOpen(!isOpen)}> | ||
{icon && <div className='icon'>{icon}</div>} | ||
<span className='header-text'>{header}</span> | ||
<div className='icon-wrapper'> | ||
{!isOpen && <ChevronDown className='expand-icon' size={24} />} | ||
{isOpen && <ChevronUp className='expand-icon' size={24} />} | ||
</div> | ||
</button> | ||
<div className={`content ${!isOpen ? 'closed' : ''}`} ref={contentRef} style={{ maxHeight }}> | ||
{text} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default ExpansionBox |
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,59 @@ | ||
# ExpansionBox | ||
|
||
> Wrapper for expansionBox | ||
### Usage | ||
|
||
#### HTML | ||
|
||
```html Default | ||
<div class='ssb-expansion-box'> | ||
<button aria-expanded='false' class='header'> | ||
<span class='header-text'>This is a ExpansionBox title</span> | ||
<div class='icon-wrapper'> | ||
<i class="expand-icon">{feather.chevronDown 20px}</i> | ||
</div> | ||
</button> | ||
<div class='content closed'>This is paragraph text</div> | ||
</div> | ||
``` | ||
|
||
```html SneakPeek and icon | ||
<div class="ssb-expansion-box sneak-peek"> | ||
<button class="header" aria-expanded="false"> | ||
<div class="icon"> | ||
<i>{feather.sun 32px}</i> | ||
</div> | ||
<span class="header-text">ExpansionBox with icon and sneakpeek content</span> | ||
<div class="icon-wrapper"> | ||
<i class="expand-icon">{feather.chevronDown 20px}</i> | ||
</div> | ||
</button> | ||
<div class="content closed"> | ||
{content} | ||
</div> | ||
</div> | ||
``` | ||
|
||
#### React | ||
|
||
```jsx harmony | ||
<ExpansionBox header='Default expansionBox' text='This is paragraph text which explains the expansionBox' /> | ||
|
||
<ExpansionBox header='ExpansionBox open by default' text='This is paragraph text which explains the expansionBox' openByDefault /> | ||
|
||
<ExpansionBox header='ExpansionBox with icon and sneakpeek text' text='This is paragraph text which explains the expansionBox' icon={<Sun size={32} />} sneakPeek /> | ||
``` | ||
|
||
Available props: | ||
|
||
| Name | Type | Description | | ||
| ------------- | ----------------- | ------------------------------------- | | ||
| className | string | Optional container class | | ||
| header | string | Header text | | ||
| icon | node | Renders an icon to the left of header | | ||
| sneakPeek | bool | Show a sneakpeek of the text | | ||
| openByDefault | bool | Open when rendered. Defaults to false | | ||
| text | string or element | Content in expansionBox | | ||
|
||
|
45 changes: 45 additions & 0 deletions
45
src/components/ExpansionBox/__snapshots__/expansionBox.test.jsx.snap
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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ExpansionBox component Matches the snapshot 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="ssb-expansion-box" | ||
> | ||
<button | ||
aria-expanded="false" | ||
class="header" | ||
> | ||
<span | ||
class="header-text" | ||
> | ||
This is a ExpansionBox title | ||
</span> | ||
<div | ||
class="icon-wrapper" | ||
> | ||
<svg | ||
class="expand-icon" | ||
fill="none" | ||
height="24" | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<polyline | ||
points="6 9 12 15 18 9" | ||
/> | ||
</svg> | ||
</div> | ||
</button> | ||
<div | ||
class="content closed" | ||
> | ||
This is paragraph text | ||
</div> | ||
</div> | ||
</DocumentFragment> | ||
`; |
Oops, something went wrong.