Update Accordion CSS
This commit is contained in:
parent
f6c5ac4893
commit
20ebf6f400
|
@ -1,7 +1,8 @@
|
|||
import React, { useState, useRef } from 'react';
|
||||
import { RichBody } from '../components/RichBody';
|
||||
import classNames from 'classnames';
|
||||
import TriangleSVG from '../assets/svgs/triangle.svg';
|
||||
import TriangleOutlinedSVG from '../assets/svgs/triangle-outlined.svg';
|
||||
import { useHoverDirty } from 'react-use';
|
||||
|
||||
export function Accordion(props) {
|
||||
const { question, answer } = props;
|
||||
|
@ -9,6 +10,10 @@ export function Accordion(props) {
|
|||
const [height, setHeight] = useState('0px');
|
||||
|
||||
const content = useRef(null);
|
||||
const button = useRef(null);
|
||||
const isHovering = useHoverDirty(button);
|
||||
const isExcited = isActive || isHovering;
|
||||
|
||||
function toggleAccordion() {
|
||||
setActiveState(!isActive);
|
||||
setHeight(isActive ? '0px' : `${content.current.scrollHeight}px`);
|
||||
|
@ -17,17 +22,19 @@ export function Accordion(props) {
|
|||
return (
|
||||
<div className="mb-1 border border-current rounded-sm">
|
||||
<button
|
||||
ref={button}
|
||||
className={classNames(
|
||||
'flex accordion text-xl tablet:text-2xl w-full text-left justify-between items-center hover:bg-secondary cursor-pointer py-3 px-6',
|
||||
'flex accordion text-xl tablet:text-2xl w-full text-left justify-between items-center hover:bg-secondary duration-300 cursor-pointer py-3 px-6',
|
||||
isActive ? 'bg-secondary' : '',
|
||||
)}
|
||||
onClick={toggleAccordion}
|
||||
>
|
||||
<div style={{ maxWidth: '90%' }}>{question}</div>
|
||||
<TriangleSVG
|
||||
<TriangleOutlinedSVG
|
||||
className={classNames(
|
||||
'h-3 fill-current text-primary transform outline-none cursor-pointer duration-200',
|
||||
'h-3 fill-current transform outline-none cursor-pointer duration-300 text-transparent',
|
||||
isActive ? 'rotate-90' : '',
|
||||
isExcited ? 'text-primary' : '',
|
||||
)}
|
||||
/>{' '}
|
||||
</button>
|
||||
|
|
Loading…
Reference in New Issue