-
Notifications
You must be signed in to change notification settings - Fork 17
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
16 changed files
with
926 additions
and
10 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
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,14 @@ | ||
import { popoverAnatomy } from '@chakra-ui/anatomy' | ||
import { createMultiStyleConfigHelpers } from '@chakra-ui/react' | ||
|
||
const { definePartsStyle, defineMultiStyleConfig } = | ||
createMultiStyleConfigHelpers(popoverAnatomy.keys) | ||
|
||
const baseStyle = definePartsStyle({ | ||
body: { | ||
bg: 'neutral.0', | ||
borderRadius: '8px', | ||
}, | ||
}) | ||
|
||
export const popOverTheme = defineMultiStyleConfig({ baseStyle }) |
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 @@ | ||
import { TableExtension } from '@remirror/extension-react-tables' |
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
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,167 @@ | ||
import { | ||
Box, | ||
Checkbox, | ||
HStack, | ||
Popover, | ||
PopoverArrow, | ||
PopoverBody, | ||
PopoverCloseButton, | ||
PopoverContent, | ||
PopoverTrigger, | ||
Text, | ||
useDisclosure, | ||
VStack, | ||
} from '@chakra-ui/react' | ||
import { useCommands } from '@remirror/react' | ||
import { useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { BsTable } from 'react-icons/bs' | ||
import { | ||
RiDeleteColumn, | ||
RiDeleteRow, | ||
RiInsertColumnRight, | ||
RiInsertRowBottom, | ||
} from 'react-icons/ri' | ||
|
||
import { Body2, MonoBody2 } from '../../../components/typography' | ||
import { useDebounce } from '../../../hooks' | ||
import { ToolbarCommandButton } from './ToolbarCommandButton' | ||
|
||
interface TableCommandProps { | ||
isDisabled?: boolean | ||
} | ||
|
||
const tableBoxes = [ | ||
[1, 2, 3, 4, 5, 6], | ||
[1, 2, 3, 4, 5, 6], | ||
[1, 2, 3, 4, 5, 6], | ||
[1, 2, 3, 4, 5, 6], | ||
[1, 2, 3, 4, 5, 6], | ||
] | ||
|
||
export const TableCommand = ({ isDisabled }: TableCommandProps) => { | ||
const { t } = useTranslation() | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
const [hasHeader, setHasHeader] = useState(true) | ||
|
||
const commands = useCommands() | ||
|
||
const debouncedIsOpen = useDebounce(isOpen, 200) | ||
|
||
const [currentPosition, setCurrentPosition] = useState({ i: 0, j: 0 }) | ||
|
||
const handleTableCreate = ({ i, j }: { i: number; j: number }) => { | ||
if (!commands.createTable) return | ||
commands.createTable({ | ||
rowsCount: i + 1, | ||
columnsCount: j + 1, | ||
}) | ||
onClose() | ||
} | ||
|
||
return ( | ||
<> | ||
<Popover | ||
isOpen={debouncedIsOpen} | ||
onClose={onClose} | ||
placement={'bottom'} | ||
closeOnBlur | ||
> | ||
<PopoverTrigger> | ||
<ToolbarCommandButton | ||
isDisabled={isDisabled} | ||
name="table" | ||
label="Table" | ||
onMouseOver={onOpen} | ||
onMouseLeave={onClose} | ||
> | ||
<BsTable /> | ||
</ToolbarCommandButton> | ||
</PopoverTrigger> | ||
<PopoverContent | ||
maxWidth="200px" | ||
onMouseOver={onOpen} | ||
onMouseLeave={onClose} | ||
> | ||
<PopoverArrow /> | ||
<PopoverBody> | ||
<VStack> | ||
<HStack w="full" spacing="5px"> | ||
<ToolbarCommandButton | ||
isDisabled={isDisabled} | ||
name="addTableRowAfter" | ||
label="add row below selected" | ||
onClick={commands.addTableRowAfter} | ||
> | ||
<RiInsertRowBottom /> | ||
</ToolbarCommandButton> | ||
<ToolbarCommandButton | ||
isDisabled={isDisabled} | ||
name="addTableColumnAfter" | ||
label="add column to right of selected" | ||
onClick={commands.addTableColumnAfter} | ||
> | ||
<RiInsertColumnRight /> | ||
</ToolbarCommandButton> | ||
<ToolbarCommandButton | ||
isDisabled={isDisabled} | ||
name="deleteTableRow" | ||
label="delete selected row" | ||
onClick={commands.deleteTableRow} | ||
> | ||
<RiDeleteRow /> | ||
</ToolbarCommandButton> | ||
<ToolbarCommandButton | ||
isDisabled={isDisabled} | ||
name="deleteTableColumn" | ||
label="delete selected column" | ||
onClick={commands.deleteTableColumn} | ||
> | ||
<RiDeleteColumn /> | ||
</ToolbarCommandButton> | ||
</HStack> | ||
<VStack spacing="0px" _hover={{ cursor: 'pointer' }}> | ||
{tableBoxes.map((row, i) => ( | ||
<HStack key={i} spacing="0px"> | ||
{row.map((col, j) => ( | ||
<Box | ||
key={j} | ||
padding="5px" | ||
onMouseEnter={() => setCurrentPosition({ i, j })} | ||
onClick={() => handleTableCreate({ i, j })} | ||
> | ||
<Box | ||
height="20px" | ||
width="20px" | ||
borderRadius="4px" | ||
backgroundColor={ | ||
i <= currentPosition.i && j <= currentPosition.j | ||
? 'neutral.300' | ||
: 'neutral.800' | ||
} | ||
transition="background-color 0.1s ease-in-out" | ||
/> | ||
</Box> | ||
))} | ||
</HStack> | ||
))} | ||
</VStack> | ||
<HStack w="full" justifyContent="space-between" spacing="0"> | ||
<Checkbox | ||
size="sm" | ||
isChecked={hasHeader} | ||
onChange={(e) => setHasHeader(e.target.checked)} | ||
> | ||
<MonoBody2 semiBold> {t('headers')} </MonoBody2> | ||
</Checkbox> | ||
<MonoBody2 semiBold>{`${currentPosition.i + 1}X${ | ||
currentPosition.j + 1 | ||
}`}</MonoBody2> | ||
</HStack> | ||
</VStack> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
</> | ||
) | ||
} |
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
Oops, something went wrong.