-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-warehouse): Select color of series on a query visualization (…
…#25909) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
99c8ae7
commit 44f28c3
Showing
9 changed files
with
109 additions
and
77 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
74 changes: 74 additions & 0 deletions
74
frontend/src/queries/nodes/DataVisualization/Components/ColorPickerButton.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,74 @@ | ||
import { LemonButton, Popover } from '@posthog/lemon-ui' | ||
import { useValues } from 'kea' | ||
import { SeriesGlyph } from 'lib/components/SeriesGlyph' | ||
import { hexToRGBA, lightenDarkenColor, RGBToHex, RGBToRGBA } from 'lib/utils' | ||
import { useState } from 'react' | ||
import { ColorResult, TwitterPicker } from 'react-color' | ||
|
||
import { themeLogic } from '~/layout/navigation-3000/themeLogic' | ||
|
||
const DEFAULT_PICKER_COLORS = [ | ||
'#FFADAD', // Current default | ||
'#E8A598', | ||
'#FFD6A5', | ||
'#FFCFD2', | ||
'#FDFFB6', | ||
'#C1FBA4', | ||
'#9BF6FF', | ||
'#A0C4FF', | ||
'#BDB2FF', | ||
'#FFC6FF', | ||
] | ||
|
||
export const ColorPickerButton = ({ | ||
color, | ||
onColorSelect: propOnColorSelect, | ||
colorChoices = DEFAULT_PICKER_COLORS, | ||
}: { | ||
color: string | ||
onColorSelect?: (color: string) => void | ||
colorChoices?: string[] | ||
}): JSX.Element => { | ||
const [pickerOpen, setPickerOpen] = useState(false) | ||
const { isDarkModeOn } = useValues(themeLogic) | ||
|
||
const onColorSelect = (colorResult: ColorResult): void => { | ||
if (propOnColorSelect) { | ||
propOnColorSelect(colorResult.hex) | ||
} | ||
|
||
if (colorChoices.includes(colorResult.hex)) { | ||
setPickerOpen(false) | ||
} | ||
} | ||
|
||
const colors = isDarkModeOn ? colorChoices.map((n) => RGBToHex(lightenDarkenColor(n, -30))) : colorChoices | ||
|
||
return ( | ||
<Popover | ||
visible={pickerOpen} | ||
overlay={<TwitterPicker color={color} colors={colors} onChangeComplete={onColorSelect} />} | ||
onClickOutside={() => setPickerOpen(false)} | ||
padded={false} | ||
> | ||
<LemonButton | ||
type="secondary" | ||
onClick={() => setPickerOpen(!pickerOpen)} | ||
sideIcon={<></>} | ||
className="ConditionalFormattingTab__ColorPicker" | ||
> | ||
<SeriesGlyph | ||
style={{ | ||
borderColor: color, | ||
color: color, | ||
backgroundColor: isDarkModeOn | ||
? RGBToRGBA(lightenDarkenColor(color, -20), 0.3) | ||
: hexToRGBA(color, 0.5), | ||
}} | ||
> | ||
<></> | ||
</SeriesGlyph> | ||
</LemonButton> | ||
</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
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