Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(lemon-ui): support unsetting color in LemonColorPicker (#59081)

Thomas Obermüllerb6ee0c06177b
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 06d2ea7e7684..ae16f4d0a81f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2536,6 +2536,10 @@ snapshots:
hash: v1.k794b7964.2a5d49e70e0d284a65ff0ec671063ba0bf2e60eeb6bbc63715ff2bf7bcbc29d7.XUTByC9kY8ePrW29fgJNIKnHCWvn_Z2ZC07pk5EIsOA
lemon-ui-lemon-color-lemon-color-picker--show-custom-color--light:
hash: v1.k794b7964.9156f2765f1efeea15d870e08faf5d4c90a64f1138ac36296a2f283bf1078b24.WndYB_kQVe68ZUhu048I4qn9K7M1vfxgFC4JP2wM42s
+ lemon-ui-lemon-color-lemon-color-picker--with-unset--dark:
+ hash: v1.k794b7964.71d425cea0efcec828c973cd33af99174d5b1de4acb16c8ccac3916da87002e2.2P3jzrJ9U2uC7hKK-OogeVGTjiGvBLzxgbw4CXo-b1w
+ lemon-ui-lemon-color-lemon-color-picker--with-unset--light:
+ hash: v1.k794b7964.05fe8e67d2e2102d19b76a95e9e93846eaa39d19425da3272b3a55518e3de83d.fVnP2i2tlppUK0L8or8QisVFOL532YPnix6ryKDVcZE
lemon-ui-lemon-dialog--customised--dark:
hash: v1.k794b7964.63943fdae27bc82471ffa286bcb2c8c41cadb3308fea7b729d1c8bf4872c18a4.c_i4Ols6JKKQmRg8dSxxFpDiSnKcr1TUKk1CzZVIq7k
lemon-ui-lemon-dialog--customised--light:
diff --git a/frontend/src/lib/lemon-ui/LemonColor/LemonColorList.tsx b/frontend/src/lib/lemon-ui/LemonColor/LemonColorList.tsx
index 9e9244f60a4c..efb092b20ae4 100644
--- a/frontend/src/lib/lemon-ui/LemonColor/LemonColorList.tsx
+++ b/frontend/src/lib/lemon-ui/LemonColor/LemonColorList.tsx
@@ -6,9 +6,11 @@ type LemonColorListColorProps = {
colors: string[]
selectedColor?: string | null
onSelectColor?: (color: string) => void
+ onClearColor?: () => void
colorTokens?: never
selectedColorToken?: never
onSelectColorToken?: never
+ onClearColorToken?: never
themeId?: never
}
@@ -16,10 +18,12 @@ type LemonColorListTokenProps = {
colorTokens: DataColorToken[]
selectedColorToken?: DataColorToken | null
onSelectColorToken?: (colorToken: DataColorToken) => void
+ onClearColorToken?: () => void
themeId?: number | null
colors?: never
selectedColor?: never
onSelectColor?: never
+ onClearColor?: never
}
export type LemonColorListProps = LemonColorListColorProps | LemonColorListTokenProps
@@ -31,11 +35,26 @@ export function LemonColorList({
selectedColorToken,
onSelectColor,
onSelectColorToken,
+ onClearColor,
+ onClearColorToken,
themeId,
}: LemonColorListProps): JSX.Element | null {
if (colorTokens?.length) {
return (
<div className="flex flex-wrap gap-1">
+ {onClearColorToken && (
+ <LemonColorButton
+ color={null}
+ type={selectedColorToken === null ? 'secondary' : 'tertiary'}
+ tooltip="No color"
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+
+ onClearColorToken()
+ }}
+ />
+ )}
{colorTokens.map((colorToken) => (
<LemonColorButton
key={colorToken}
@@ -57,6 +76,19 @@ export function LemonColorList({
if (colors?.length) {
return (
<div className="flex flex-wrap gap-1">
+ {onClearColor && (
+ <LemonColorButton
+ color={null}
+ type={selectedColor === null ? 'secondary' : 'tertiary'}
+ tooltip="No color"
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+
+ onClearColor()
+ }}
+ />
+ )}
{colors.map((color) => (
<LemonColorButton
key={color}
diff --git a/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.stories.tsx b/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.stories.tsx
index 06aeaa7d80ea..48c12e3b2e89 100644
--- a/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.stories.tsx
+++ b/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.stories.tsx
@@ -68,3 +68,18 @@ export const CustomButton: Story = {
)
},
}
+
+export const WithUnset: Story = {
+ render: () => {
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ const [color, setColor] = useState<string | null>('#ff0000')
+ return (
+ <LemonColorPicker
+ colors={colors}
+ selectedColor={color}
+ onSelectColor={setColor}
+ onClearColor={() => setColor(null)}
+ />
+ )
+ },
+}
diff --git a/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.tsx b/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.tsx
index 763a50e1c8b6..2825b2fbe965 100644
--- a/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.tsx
+++ b/frontend/src/lib/lemon-ui/LemonColor/LemonColorPicker.tsx
@@ -21,9 +21,11 @@ type LemonColorPickerColorProps = LemonColorPickerBaseProps & {
colors: string[]
selectedColor?: string | null
onSelectColor: (color: string) => void
+ onClearColor?: () => void
colorTokens?: never
selectedColorToken?: never
onSelectColorToken?: never
+ onClearColorToken?: never
themeId?: never
}
@@ -31,10 +33,12 @@ type LemonColorPickerTokenProps = LemonColorPickerBaseProps & {
colorTokens?: DataColorToken[]
selectedColorToken?: DataColorToken | null
onSelectColorToken: (colorToken: DataColorToken) => void
+ onClearColorToken?: () => void
themeId?: number | null
colors?: never
selectedColor?: never
onSelectColor?: never
+ onClearColor?: never
}
export type LemonColorPickerProps = LemonColorPickerColorProps | LemonColorPickerTokenProps
@@ -49,6 +53,8 @@ export const LemonColorPickerOverlay = ({
selectedColorToken,
onSelectColor,
onSelectColorToken,
+ onClearColor,
+ onClearColorToken,
showCustomColor = false,
preventPopoverClose = false,
customColorValue,
@@ -82,13 +88,19 @@ export const LemonColorPickerOverlay = ({
>
<LemonLabel className="mt-1 mb-0.5">Preset colors</LemonLabel>
{colors ? (
- <LemonColorList colors={colors} selectedColor={selectedColor} onSelectColor={onSelectColor} />
+ <LemonColorList
+ colors={colors}
+ selectedColor={selectedColor}
+ onSelectColor={onSelectColor}
+ onClearColor={onClearColor}
+ />
) : (
<LemonColorList
themeId={themeId}
colorTokens={colorTokens || getAvailableColorTokens(themeId) || []}
selectedColorToken={selectedColorToken}
onSelectColorToken={onSelectColorToken}
+ onClearColorToken={onClearColorToken}
/>
)}
{showCustomColor && (