-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
2,092 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"StyledTheme": { | ||
"prefix": "theme-interpolation", | ||
"body": [ | ||
"${p => p.theme.${1:colors}.$2};" | ||
], | ||
"description": "Insert Theme interpolation in styled-component" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import * as RadixScrollArea from '@radix-ui/react-scroll-area'; | ||
import styled from 'styled-components'; | ||
import { transparentize } from 'polished'; | ||
|
||
const SIZE = '0.8rem'; | ||
|
||
export interface ScrollAreaProps { | ||
className?: string; | ||
} | ||
|
||
export const ScrollArea = React.forwardRef< | ||
HTMLDivElement, | ||
React.PropsWithChildren<ScrollAreaProps> | ||
>(({ children, className }, ref): JSX.Element => { | ||
return ( | ||
<RadixScrollArea.Root type='scroll'> | ||
<RadixScrollArea.Viewport className={className} ref={ref}> | ||
{children} | ||
</RadixScrollArea.Viewport> | ||
<ScrollBar orientation='horizontal'> | ||
<Thumb /> | ||
</ScrollBar> | ||
<ScrollBar orientation='vertical'> | ||
<Thumb /> | ||
</ScrollBar> | ||
<RadixScrollArea.Corner /> | ||
</RadixScrollArea.Root> | ||
); | ||
}); | ||
|
||
ScrollArea.displayName = 'ScrollArea'; | ||
|
||
const ScrollBar = styled(RadixScrollArea.Scrollbar)` | ||
display: flex; | ||
/* ensures no selection */ | ||
user-select: none; | ||
/* disable browser handling of all panning and zooming gestures on touch devices */ | ||
touch-action: none; | ||
padding: 2px; | ||
background-color: transparent; | ||
transition: background-color ${p => p.theme.animation.duration} ease-out; | ||
&[data-orientation='horizontal'] { | ||
flex-direction: column; | ||
height: ${() => SIZE}; | ||
} | ||
`; | ||
|
||
const Thumb = styled(RadixScrollArea.Thumb)` | ||
position: relative; | ||
bottom: 1px; | ||
flex: 1; | ||
background-color: ${p => transparentize(0.25, p.theme.colors.bg2)}; | ||
border-radius: ${() => SIZE}; | ||
backdrop-filter: blur(10px); | ||
z-index: 2; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
data-browser/src/components/TableEditor/ActiveCellIndicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { transparentize } from 'polished'; | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { CursorMode, useTableEditorContext } from './TableEditorContext'; | ||
|
||
export interface ActiveCellIndicatorProps { | ||
sizeStr: string; | ||
scrollerRef: React.RefObject<HTMLDivElement>; | ||
setOnScroll: (onScroll: () => void) => void; | ||
} | ||
|
||
export function ActiveCellIndicator({ | ||
sizeStr, | ||
scrollerRef, | ||
setOnScroll, | ||
}: ActiveCellIndicatorProps): JSX.Element | null { | ||
const [visible, setVisible] = useState(false); | ||
const [scrolling, setScrolling] = useState(false); | ||
|
||
const [{ top, left, width }, setSize] = useState({ | ||
top: '0px', | ||
left: '0px', | ||
width: '0px', | ||
}); | ||
|
||
const { selectedColumn, selectedRow, activeCellRef, isDragging, cursorMode } = | ||
useTableEditorContext(); | ||
|
||
const updatePosition = useCallback(() => { | ||
if (!activeCellRef.current || !scrollerRef.current) { | ||
setVisible(false); | ||
|
||
return; | ||
} | ||
|
||
const rect = activeCellRef.current!.getBoundingClientRect(); | ||
const tableRect = scrollerRef.current!.getBoundingClientRect(); | ||
|
||
if (rect.top === 0 && rect.left === 0) { | ||
return; | ||
} | ||
|
||
setSize({ | ||
top: `${rect.top - tableRect.top - 1}px`, | ||
left: `${ | ||
rect.left - tableRect.left + scrollerRef.current!.scrollLeft! - 1 | ||
}px`, | ||
width: | ||
selectedColumn === 0 | ||
? 'calc(var(--table-content-width) + 1px)' | ||
: `${rect.width + 1}px`, | ||
}); | ||
}, [selectedColumn, selectedRow, sizeStr]); | ||
|
||
useEffect(() => { | ||
setOnScroll(() => (_, __, requested: boolean) => { | ||
if (requested) { | ||
return; | ||
} | ||
|
||
setScrolling(true); | ||
updatePosition(); | ||
}); | ||
}, [updatePosition]); | ||
|
||
useEffect(() => { | ||
if (!activeCellRef.current || !scrollerRef.current) { | ||
setVisible(false); | ||
|
||
return; | ||
} | ||
|
||
setVisible(true); | ||
setScrolling(false); | ||
|
||
updatePosition(); | ||
}, [selectedColumn, selectedRow, sizeStr]); | ||
|
||
if (!visible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Indicator | ||
top={top} | ||
left={left} | ||
width={width} | ||
noTransition={isDragging || scrolling} | ||
cursorMode={cursorMode} | ||
/> | ||
); | ||
} | ||
|
||
interface IndicatorProps { | ||
top: string; | ||
left: string; | ||
width: string; | ||
noTransition: boolean; | ||
cursorMode: CursorMode; | ||
} | ||
|
||
const Indicator = styled.div.attrs<IndicatorProps>(p => ({ | ||
style: { | ||
transform: `translate(${p.left}, ${p.top})`, | ||
width: p.width, | ||
}, | ||
}))<IndicatorProps>` | ||
--speed: ${p => (p.noTransition ? 0 : 80)}ms; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: calc(var(--table-row-height) + 1px); | ||
border: 2px solid ${p => p.theme.colors.main}; | ||
pointer-events: none; | ||
will-change: transform, width; | ||
transition: transform var(--speed) ease-out, width var(--speed) ease-out; | ||
z-index: 1; | ||
background-color: ${p => | ||
p.cursorMode === CursorMode.Visual | ||
? transparentize(0.85, p.theme.colors.main) | ||
: 'none'}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import React, { useCallback, useEffect, useRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import { | ||
CursorMode, | ||
TableEvent, | ||
useTableEditorContext, | ||
} from './TableEditorContext'; | ||
|
||
export enum CellAlign { | ||
Start = 'flex-start', | ||
End = 'flex-end', | ||
Center = 'center', | ||
} | ||
|
||
export interface CellProps { | ||
rowIndex: number; | ||
columnIndex: number; | ||
className?: string; | ||
align?: CellAlign; | ||
onClearCell?: () => void; | ||
onEnterEditModeWithCharacter?: (key: string) => void; | ||
} | ||
|
||
export function Cell({ | ||
rowIndex, | ||
columnIndex, | ||
className, | ||
children, | ||
align, | ||
onClearCell, | ||
onEnterEditModeWithCharacter, | ||
}: React.PropsWithChildren<CellProps>): JSX.Element { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
const { | ||
selectedRow, | ||
selectedColumn, | ||
setActiveCell, | ||
activeCellRef, | ||
setCursorMode, | ||
registerEventListener, | ||
} = useTableEditorContext(); | ||
|
||
const isActive = rowIndex === selectedRow && columnIndex === selectedColumn; | ||
|
||
const handleClick = useCallback( | ||
(e: React.MouseEvent<HTMLDivElement>) => { | ||
if (isActive) { | ||
// @ts-ignore | ||
if (e.target.tagName === 'INPUT') { | ||
// If the user clicked on an input don't enter edit mode. (Necessary for normal checkbox behavior) | ||
return; | ||
} | ||
|
||
return setCursorMode(CursorMode.Edit); | ||
} | ||
|
||
setActiveCell(rowIndex, columnIndex); | ||
}, | ||
[setActiveCell, isActive], | ||
); | ||
|
||
useEffect(() => { | ||
if (!ref.current) { | ||
return; | ||
} | ||
|
||
if (isActive) { | ||
ref.current.focus(); | ||
activeCellRef.current = ref.current; | ||
|
||
const listeners = [ | ||
registerEventListener( | ||
TableEvent.ClearCell, | ||
onClearCell ?? (() => undefined), | ||
), | ||
registerEventListener( | ||
TableEvent.EnterEditModeWithCharacter, | ||
onEnterEditModeWithCharacter ?? (() => undefined), | ||
), | ||
]; | ||
|
||
return () => { | ||
listeners.forEach(unregister => unregister()); | ||
}; | ||
} | ||
}, [isActive, onClearCell, onEnterEditModeWithCharacter]); | ||
|
||
return ( | ||
<CellWrapper | ||
ref={ref} | ||
className={className} | ||
onClick={handleClick} | ||
align={align} | ||
> | ||
{children} | ||
</CellWrapper> | ||
); | ||
} | ||
|
||
export const IndexCell = styled(Cell)` | ||
justify-content: flex-end !important; | ||
color: ${p => p.theme.colors.textLight}; | ||
`; | ||
|
||
export interface CellWrapperProps { | ||
align?: CellAlign; | ||
} | ||
|
||
export const CellWrapper = styled.div<CellWrapperProps>` | ||
background: ${p => p.theme.colors.bg}; | ||
display: flex; | ||
width: 100%; | ||
justify-content: ${p => p.align ?? 'flex-start'}; | ||
align-items: center; | ||
padding-inline: var(--table-inner-padding); | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
position: relative; | ||
`; |
Oops, something went wrong.