Skip to content
Snippets Groups Projects
Unverified Commit 72006ef6 authored by George Sumpster's avatar George Sumpster Committed by GitHub
Browse files

Add 'View on Hover' to Category Notes for #563 (#579)


* add hover state to NotesButton

* switch NotesButton editability to a ternary

* fix new lines, adjust padding on textarea

* add workBreak to text styling

* Update packages/loot-design/src/components/NotesButton.js

Co-authored-by: default avatarJed Fox <git@jedfox.com>

* change wordBreak to overflowWrap

---------

Co-authored-by: default avatarJed Fox <git@jedfox.com>
parent 384fc68e
No related branches found
No related tags found
No related merge requests found
...@@ -9,9 +9,10 @@ import { send } from 'loot-core/src/platform/client/fetch'; ...@@ -9,9 +9,10 @@ import { send } from 'loot-core/src/platform/client/fetch';
import { colors } from '../style'; import { colors } from '../style';
import CustomNotesPaper from '../svg/v2/CustomNotesPaper'; import CustomNotesPaper from '../svg/v2/CustomNotesPaper';
import { View, Button, Tooltip, useTooltip } from './common'; import { View, Button, Tooltip, useTooltip, Text } from './common';
export function NotesTooltip({ export function NotesTooltip({
editable,
defaultNotes, defaultNotes,
position = 'bottom-left', position = 'bottom-left',
onClose onClose
...@@ -20,22 +21,39 @@ export function NotesTooltip({ ...@@ -20,22 +21,39 @@ export function NotesTooltip({
let inputRef = React.createRef(); let inputRef = React.createRef();
useEffect(() => { useEffect(() => {
inputRef.current.focus(); if (editable) {
}, []); inputRef.current.focus();
}
}, [inputRef, editable]);
return ( return (
<Tooltip position={position} onClose={() => onClose(notes)}> <Tooltip position={position} onClose={() => onClose(notes)}>
<textarea {editable ? (
ref={inputRef} <textarea
{...css({ ref={inputRef}
border: '1px solid ' + colors.border, {...css({
minWidth: 300, border: '1px solid ' + colors.border,
minHeight: 120, padding: 7,
outline: 'none' minWidth: 300,
})} minHeight: 120,
value={notes || ''} outline: 'none'
onChange={e => setNotes(e.target.value)} })}
></textarea> value={notes || ''}
onChange={e => setNotes(e.target.value)}
></textarea>
) : (
<Text
{...css({
display: 'block',
maxWidth: 225,
padding: 8,
whiteSpace: 'pre-wrap',
overflowWrap: 'break-word'
})}
>
{notes}
</Text>
)}
</Tooltip> </Tooltip>
); );
} }
...@@ -48,6 +66,7 @@ export default function NotesButton({ ...@@ -48,6 +66,7 @@ export default function NotesButton({
tooltipPosition, tooltipPosition,
style style
}) { }) {
let [hover, setHover] = useState(false);
let tooltip = useTooltip(); let tooltip = useTooltip();
let { data } = useLiveQuery( let { data } = useLiveQuery(
useMemo(() => q('notes').filter({ id }).select('*'), [id]) useMemo(() => q('notes').filter({ id }).select('*'), [id])
...@@ -60,11 +79,14 @@ export default function NotesButton({ ...@@ -60,11 +79,14 @@ export default function NotesButton({
tooltip.close(); tooltip.close();
} }
// This account for both the tooltip hover, and editing tooltip
const tooltipOpen = tooltip.isOpen || (hasNotes && hover);
return ( return (
<View <View
style={[ style={[
{ flexShrink: 0 }, { flexShrink: 0 },
tooltip.isOpen && { tooltipOpen && {
'& button, & .hover-visible': { '& button, & .hover-visible': {
display: 'flex', display: 'flex',
opacity: 1, opacity: 1,
...@@ -75,6 +97,8 @@ export default function NotesButton({ ...@@ -75,6 +97,8 @@ export default function NotesButton({
'& button, & .hover-visible': { display: 'flex', opacity: 1 } '& button, & .hover-visible': { display: 'flex', opacity: 1 }
} }
]} ]}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
> >
<Button <Button
bare bare
...@@ -84,8 +108,9 @@ export default function NotesButton({ ...@@ -84,8 +108,9 @@ export default function NotesButton({
> >
<CustomNotesPaper style={{ width, height, color: 'currentColor' }} /> <CustomNotesPaper style={{ width, height, color: 'currentColor' }} />
</Button> </Button>
{tooltip.isOpen && ( {tooltipOpen && (
<NotesTooltip <NotesTooltip
editable={tooltip.isOpen}
defaultNotes={note} defaultNotes={note}
position={tooltipPosition} position={tooltipPosition}
onClose={onClose} onClose={onClose}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment