-
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.
#25 Add select, number and checkbox columns
- Loading branch information
Showing
41 changed files
with
1,355 additions
and
180 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
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,99 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import Picker from '@emoji-mart/react'; | ||
import styled from 'styled-components'; | ||
import * as RadixPopover from '@radix-ui/react-popover'; | ||
import { transition } from '../../helpers/transition'; | ||
import { Popover } from '../../components/Popover'; | ||
|
||
interface EmojiInputProps { | ||
initialValue?: string; | ||
onChange: (value: string | undefined) => void; | ||
} | ||
|
||
const EMOJI_DATA_URL = 'https://cdn.jsdelivr.net/npm/@emoji-mart/data'; | ||
|
||
let data: Promise<unknown>; | ||
|
||
const fetchAndCacheData = async () => { | ||
if (data) { | ||
return data; | ||
} | ||
|
||
const response = await fetch(EMOJI_DATA_URL); | ||
data = response.json(); | ||
|
||
return data; | ||
}; | ||
|
||
export default function EmojiInput({ | ||
initialValue, | ||
onChange, | ||
}: EmojiInputProps): JSX.Element { | ||
const [showPicker, setShowPicker] = useState(false); | ||
const [emoji, setEmoji] = useState<string | undefined>(initialValue); | ||
|
||
const handleEmojiSelect = useCallback((e: any) => { | ||
setEmoji(e.native); | ||
setShowPicker(false); | ||
onChange(e.native); | ||
}, []); | ||
|
||
return ( | ||
<PickerPopover | ||
noArrow | ||
open={showPicker} | ||
onOpenChange={setShowPicker} | ||
Trigger={ | ||
<PickerButton onClick={() => setShowPicker(true)}> | ||
{emoji ? <Preview>{emoji}</Preview> : <Placeholder>😎</Placeholder>} | ||
</PickerButton> | ||
} | ||
> | ||
<PickerWrapper> | ||
<Picker | ||
autoFocus | ||
data={fetchAndCacheData} | ||
onEmojiSelect={handleEmojiSelect} | ||
maxFrequentRows={2} | ||
dynamicWidth={true} | ||
/> | ||
</PickerWrapper> | ||
</PickerPopover> | ||
); | ||
} | ||
|
||
const Preview = styled.span` | ||
transition: ${transition('font-size')}; | ||
`; | ||
|
||
const Placeholder = styled(Preview)` | ||
opacity: 0.5; | ||
`; | ||
|
||
const PickerButton = styled(RadixPopover.Trigger)` | ||
border: none; | ||
border-radius: ${({ theme }) => theme.radius}; | ||
width: 2rem; | ||
background: transparent; | ||
padding: 0; | ||
cursor: pointer; | ||
user-select: none; | ||
&:hover > ${Preview} { | ||
font-size: 1.3rem; | ||
} | ||
`; | ||
|
||
const PickerPopover = styled(Popover)` | ||
top: 200px; | ||
`; | ||
|
||
const PickerWrapper = styled.div` | ||
display: contents; | ||
& em-emoji-picker { | ||
height: 400px; | ||
width: min(90vw, 20rem); | ||
} | ||
`; |
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
import React, { createContext, useMemo, useState } from 'react'; | ||
|
||
export const DialogPortalContext = createContext< | ||
React.RefObject<HTMLDivElement> | ||
>(null!); | ||
|
||
interface DialogTreeContext { | ||
inDialog: boolean; | ||
hasOpenInnerPopup: boolean; | ||
setHasOpenInnerPopup: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
export const DialogTreeContext = createContext<DialogTreeContext>({ | ||
inDialog: false, | ||
hasOpenInnerPopup: false, | ||
setHasOpenInnerPopup: () => undefined, | ||
}); | ||
|
||
export const DialogTreeContextProvider: React.FC<React.PropsWithChildren> = ({ | ||
children, | ||
}) => { | ||
const [hasOpenInnerPopup, setHasOpenInnerPopup] = useState<boolean>(false); | ||
|
||
const context = useMemo( | ||
() => ({ | ||
inDialog: true, | ||
hasOpenInnerPopup, | ||
setHasOpenInnerPopup, | ||
}), | ||
[hasOpenInnerPopup], | ||
); | ||
|
||
return ( | ||
<DialogTreeContext.Provider value={context}> | ||
{children} | ||
</DialogTreeContext.Provider> | ||
); | ||
}; | ||
|
||
export function useDialogTreeContext() { | ||
return React.useContext(DialogTreeContext); | ||
} |
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,49 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { transition } from '../helpers/transition'; | ||
import { Row } from './Row'; | ||
|
||
interface PalettePickerProps { | ||
palette: string[]; | ||
onChange: (color: string) => void; | ||
} | ||
|
||
export function PalettePicker({ | ||
palette, | ||
onChange, | ||
}: PalettePickerProps): JSX.Element { | ||
const createHandleClick = (color: string) => () => onChange(color); | ||
|
||
return ( | ||
<Row wrapItems> | ||
{palette.map(color => ( | ||
<PaletteButton | ||
key={color} | ||
color={color} | ||
onClick={createHandleClick(color)} | ||
></PaletteButton> | ||
))} | ||
</Row> | ||
); | ||
} | ||
|
||
interface PaletteButtonProps { | ||
color: string; | ||
} | ||
|
||
const PaletteButton = styled.button<PaletteButtonProps>` | ||
background-color: ${({ color }) => color}; | ||
border: none; | ||
height: 1.5rem; | ||
aspect-ratio: 1/1; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
transform-origin: center; | ||
transition: ${transition('transform')}; | ||
&:hover, | ||
&:focus { | ||
outline: none; | ||
transform: scale(1.3); | ||
} | ||
`; |
Oops, something went wrong.