Skip to content

Commit

Permalink
Add 'View on Hover' to Category Notes for #563 (#579)
Browse files Browse the repository at this point in the history
* 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: Jed Fox <[email protected]>

* change wordBreak to overflowWrap

---------

Co-authored-by: Jed Fox <[email protected]>
  • Loading branch information
gsumpster and j-f1 authored Jan 27, 2023
1 parent 384fc68 commit 72006ef
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions packages/loot-design/src/components/NotesButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { send } from 'loot-core/src/platform/client/fetch';
import { colors } from '../style';
import CustomNotesPaper from '../svg/v2/CustomNotesPaper';

import { View, Button, Tooltip, useTooltip } from './common';
import { View, Button, Tooltip, useTooltip, Text } from './common';

export function NotesTooltip({
editable,
defaultNotes,
position = 'bottom-left',
onClose
Expand All @@ -20,22 +21,39 @@ export function NotesTooltip({
let inputRef = React.createRef();

useEffect(() => {
inputRef.current.focus();
}, []);
if (editable) {
inputRef.current.focus();
}
}, [inputRef, editable]);

return (
<Tooltip position={position} onClose={() => onClose(notes)}>
<textarea
ref={inputRef}
{...css({
border: '1px solid ' + colors.border,
minWidth: 300,
minHeight: 120,
outline: 'none'
})}
value={notes || ''}
onChange={e => setNotes(e.target.value)}
></textarea>
{editable ? (
<textarea
ref={inputRef}
{...css({
border: '1px solid ' + colors.border,
padding: 7,
minWidth: 300,
minHeight: 120,
outline: 'none'
})}
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>
);
}
Expand All @@ -48,6 +66,7 @@ export default function NotesButton({
tooltipPosition,
style
}) {
let [hover, setHover] = useState(false);
let tooltip = useTooltip();
let { data } = useLiveQuery(
useMemo(() => q('notes').filter({ id }).select('*'), [id])
Expand All @@ -60,11 +79,14 @@ export default function NotesButton({
tooltip.close();
}

// This account for both the tooltip hover, and editing tooltip
const tooltipOpen = tooltip.isOpen || (hasNotes && hover);

return (
<View
style={[
{ flexShrink: 0 },
tooltip.isOpen && {
tooltipOpen && {
'& button, & .hover-visible': {
display: 'flex',
opacity: 1,
Expand All @@ -75,6 +97,8 @@ export default function NotesButton({
'& button, & .hover-visible': { display: 'flex', opacity: 1 }
}
]}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<Button
bare
Expand All @@ -84,8 +108,9 @@ export default function NotesButton({
>
<CustomNotesPaper style={{ width, height, color: 'currentColor' }} />
</Button>
{tooltip.isOpen && (
{tooltipOpen && (
<NotesTooltip
editable={tooltip.isOpen}
defaultNotes={note}
position={tooltipPosition}
onClose={onClose}
Expand Down

0 comments on commit 72006ef

Please sign in to comment.