Skip to content

Commit

Permalink
refactor: switch SelectableText to JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
fboulnois committed Nov 13, 2023
1 parent a6ff264 commit 3f83c10
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/components/SelectableText.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useState, useEffect, useMemo } from 'react';
import { div } from 'react-hyperscript-helpers';

const defaultUnselectedStyle = {
fontSize: '1.8rem',
Expand All @@ -24,7 +24,6 @@ export default function SelectableText({label, setSelected, selectedType, styleO

const {baseStyle, tabSelected, tabUnselected, tabHover} = styleOverride;


const utilizedUnselectedStyle = useMemo(() => {
return Object.assign({}, tabUnselected || defaultUnselectedStyle, baseStyle);
}, [tabUnselected, baseStyle]);
Expand All @@ -42,22 +41,22 @@ export default function SelectableText({label, setSelected, selectedType, styleO
);
}, [label, selectedType, utilizedSelectedStyle, utilizedUnselectedStyle]);


const addHoverEffect = () => {
setStyle(utilizedHoverStyle);
};
const removeHoverEffect = () => {
setStyle(selectedType === label ? utilizedSelectedStyle : utilizedUnselectedStyle);
};


return(
div({
style,
onMouseEnter: addHoverEffect,
onMouseLeave: removeHoverEffect,
onClick: () => !isDisabled && setSelected(label),
className: `tab-selection-${label}`
}, [label])
return (
<div
style={style}
onMouseEnter={addHoverEffect}
onMouseLeave={removeHoverEffect}
onClick={() => !isDisabled && setSelected(label)}
className={`tab-selection-${label}`}
>
{label}
</div>
);
}
}

0 comments on commit 3f83c10

Please sign in to comment.