fix: hover behaviour on table cells (#1557)
* edit button focus fix * cell feedback fix * using theme prop * isHovered prop drill * edit button component * refactor editable cell * import fix * index fix (merge issue)
This commit is contained in:
@ -1,9 +1,6 @@
|
|||||||
import { ReactElement, useState } from 'react';
|
import { ReactElement, useState } from 'react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { motion } from 'framer-motion';
|
|
||||||
|
|
||||||
import { FloatingIconButton } from '@/ui/button/components/FloatingIconButton';
|
|
||||||
import { IconPencil } from '@/ui/icon';
|
|
||||||
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||||
|
|
||||||
import { CellHotkeyScopeContext } from '../../contexts/CellHotkeyScopeContext';
|
import { CellHotkeyScopeContext } from '../../contexts/CellHotkeyScopeContext';
|
||||||
@ -14,14 +11,10 @@ import { useIsSoftFocusOnCurrentCell } from '../hooks/useIsSoftFocusOnCurrentCel
|
|||||||
import { useSetSoftFocusOnCurrentCell } from '../hooks/useSetSoftFocusOnCurrentCell';
|
import { useSetSoftFocusOnCurrentCell } from '../hooks/useSetSoftFocusOnCurrentCell';
|
||||||
|
|
||||||
import { EditableCellDisplayMode } from './EditableCellDisplayMode';
|
import { EditableCellDisplayMode } from './EditableCellDisplayMode';
|
||||||
|
import { EditableCellEditButton } from './EditableCellEditButton';
|
||||||
import { EditableCellEditMode } from './EditableCellEditMode';
|
import { EditableCellEditMode } from './EditableCellEditMode';
|
||||||
import { EditableCellSoftFocusMode } from './EditableCellSoftFocusMode';
|
import { EditableCellSoftFocusMode } from './EditableCellSoftFocusMode';
|
||||||
|
|
||||||
const StyledEditButtonContainer = styled(motion.div)`
|
|
||||||
position: absolute;
|
|
||||||
right: 5px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const StyledCellBaseContainer = styled.div`
|
const StyledCellBaseContainer = styled.div`
|
||||||
align-items: center;
|
align-items: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@ -102,27 +95,20 @@ export function EditableCell({
|
|||||||
{editModeContent}
|
{editModeContent}
|
||||||
</EditableCellEditMode>
|
</EditableCellEditMode>
|
||||||
) : hasSoftFocus ? (
|
) : hasSoftFocus ? (
|
||||||
<EditableCellSoftFocusMode>
|
<>
|
||||||
{nonEditModeContent}
|
{showEditButton && (
|
||||||
</EditableCellSoftFocusMode>
|
<EditableCellEditButton onClick={handlePenClick} />
|
||||||
|
)}
|
||||||
|
<EditableCellSoftFocusMode>
|
||||||
|
{nonEditModeContent}
|
||||||
|
</EditableCellSoftFocusMode>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{showEditButton && (
|
{showEditButton && (
|
||||||
<StyledEditButtonContainer
|
<EditableCellEditButton onClick={handlePenClick} />
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
transition={{ duration: 0.1 }}
|
|
||||||
whileHover={{ scale: 1.04 }}
|
|
||||||
>
|
|
||||||
<FloatingIconButton
|
|
||||||
size="small"
|
|
||||||
onClick={handlePenClick}
|
|
||||||
Icon={IconPencil}
|
|
||||||
/>
|
|
||||||
</StyledEditButtonContainer>
|
|
||||||
)}
|
)}
|
||||||
|
<EditableCellDisplayMode isHovered={isHovered}>
|
||||||
<EditableCellDisplayMode>
|
|
||||||
{nonEditModeContent}
|
{nonEditModeContent}
|
||||||
</EditableCellDisplayMode>
|
</EditableCellDisplayMode>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -5,10 +5,11 @@ export type EditableCellDisplayContainerProps = {
|
|||||||
softFocus?: boolean;
|
softFocus?: boolean;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
scrollRef?: Ref<HTMLDivElement>;
|
scrollRef?: Ref<HTMLDivElement>;
|
||||||
|
isHovered?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledEditableCellDisplayModeOuterContainer = styled.div<
|
const StyledEditableCellDisplayModeOuterContainer = styled.div<
|
||||||
Pick<EditableCellDisplayContainerProps, 'softFocus'>
|
Pick<EditableCellDisplayContainerProps, 'softFocus' | 'isHovered'>
|
||||||
>`
|
>`
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -20,7 +21,7 @@ const StyledEditableCellDisplayModeOuterContainer = styled.div<
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
${(props) =>
|
${(props) =>
|
||||||
props.softFocus
|
props.softFocus || props.isHovered
|
||||||
? `background: ${props.theme.background.transparent.secondary};
|
? `background: ${props.theme.background.transparent.secondary};
|
||||||
border-radius: ${props.theme.border.radius.sm};
|
border-radius: ${props.theme.border.radius.sm};
|
||||||
box-shadow: inset 0 0 0 1px ${props.theme.font.color.extraLight};`
|
box-shadow: inset 0 0 0 1px ${props.theme.font.color.extraLight};`
|
||||||
@ -40,6 +41,7 @@ export function EditableCellDisplayContainer({
|
|||||||
softFocus,
|
softFocus,
|
||||||
onClick,
|
onClick,
|
||||||
scrollRef,
|
scrollRef,
|
||||||
|
isHovered,
|
||||||
}: React.PropsWithChildren<EditableCellDisplayContainerProps>) {
|
}: React.PropsWithChildren<EditableCellDisplayContainerProps>) {
|
||||||
return (
|
return (
|
||||||
<StyledEditableCellDisplayModeOuterContainer
|
<StyledEditableCellDisplayModeOuterContainer
|
||||||
@ -49,6 +51,7 @@ export function EditableCellDisplayContainer({
|
|||||||
: 'editable-cell-display-mode'
|
: 'editable-cell-display-mode'
|
||||||
}
|
}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
|
isHovered={isHovered}
|
||||||
softFocus={softFocus}
|
softFocus={softFocus}
|
||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -5,7 +5,8 @@ import { EditableCellDisplayContainer } from './EditableCellDisplayContainer';
|
|||||||
|
|
||||||
export function EditableCellDisplayMode({
|
export function EditableCellDisplayMode({
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<unknown>) {
|
isHovered,
|
||||||
|
}: React.PropsWithChildren<unknown> & { isHovered?: boolean }) {
|
||||||
const setSoftFocusOnCurrentCell = useSetSoftFocusOnCurrentCell();
|
const setSoftFocusOnCurrentCell = useSetSoftFocusOnCurrentCell();
|
||||||
|
|
||||||
const { openEditableCell } = useEditableCell();
|
const { openEditableCell } = useEditableCell();
|
||||||
@ -16,7 +17,7 @@ export function EditableCellDisplayMode({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EditableCellDisplayContainer onClick={handleClick}>
|
<EditableCellDisplayContainer isHovered={isHovered} onClick={handleClick}>
|
||||||
{children}
|
{children}
|
||||||
</EditableCellDisplayContainer>
|
</EditableCellDisplayContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
import styled from '@emotion/styled';
|
||||||
|
import { motion } from 'framer-motion';
|
||||||
|
|
||||||
|
import { FloatingIconButton } from '@/ui/button/components/FloatingIconButton';
|
||||||
|
import { IconPencil } from '@/ui/icon';
|
||||||
|
|
||||||
|
const StyledEditButtonContainer = styled(motion.div)`
|
||||||
|
position: absolute;
|
||||||
|
right: 5px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
type EditableCellEditButtonProps = {
|
||||||
|
onClick?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EditableCellEditButton({
|
||||||
|
onClick,
|
||||||
|
}: EditableCellEditButtonProps) {
|
||||||
|
return (
|
||||||
|
<StyledEditButtonContainer
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
transition={{ duration: 0.1 }}
|
||||||
|
whileHover={{ scale: 1.04 }}
|
||||||
|
>
|
||||||
|
<FloatingIconButton size="small" onClick={onClick} Icon={IconPencil} />
|
||||||
|
</StyledEditButtonContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user