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): add typed trigger styling props to the DatePicker seam (#66016)

Paul D'Ambraf72d0afe8917
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index b603424818e9..80f3304d22c2 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -336,10 +336,18 @@ snapshots:
hash: v1.k794b7964.d798652b51db1c634e5e7bbbe194d5fdc6b6454581349303a02974333270240d.XWfuQdHNeBz7TfO-4mYIeDLXCp3LqxH264JiHFUgK4g
components-date-picker--past-only--light:
hash: v1.k794b7964.ffdac5431d4f98723b5e2bd51a7e8dcf13b9e4c1c0cd298018a8633419439b44.wKvYaWVSHr61dXMjL569dC82ynBF2KK3myXSvNL5Syo
+ components-date-picker--quill-custom-class--dark:
+ hash: v1.k794b7964.bf7f43ffd259cfd63d3254bb6c958615e252229f68cc00efb6f97827c2b54f9f.t99znqN6dNzpcq7l5X36J1i7LxnJVDKxNPJMlOgKpsQ
+ components-date-picker--quill-custom-class--light:
+ hash: v1.k794b7964.143ef687b56150fe70923f507cacaaa3cfe1ebb13f2dc536097a281ecf257fdc.bbAAzZZjOWlBTJACthV7HNptDVtAz6h9N5FFyYgh0JA
components-date-picker--quill-empty--dark:
hash: v1.k794b7964.44cfdb6fe956961256a9825c7d7a5cf0c596e937ecfb9994a4e133037ec8d76e.L_ZWqAvhq1iodO1C3KlnycjGH2PFxkGruf577T5Gb9Y
components-date-picker--quill-empty--light:
hash: v1.k794b7964.d40c13438b057467aa3719c70f62f7f0114635a397b394207833d764431b447a.xVNP5qzKlFD1WLEU_INK1YNK6oiuRQsrZvGNTHfXHKU
+ components-date-picker--quill-small-secondary--dark:
+ hash: v1.k794b7964.e05f37dbdce40b499cd7cdd9aa2de50f760d103439d45cae4165bfaa3e192e9e.wkOu6VlXKigWpMQ5BdHTUv0pYdWOzp0Bd7U0xSUYV_s
+ components-date-picker--quill-small-secondary--light:
+ hash: v1.k794b7964.c75138c4400c78bfb12d2609e40c5f555bd4634a4d12e2d7f9b3faec11adc7ff.56RffhN3R6HrdWzK_WXIGf5aXtAEDvXueknziKRMstY
components-date-picker--quill-with-time--dark:
hash: v1.k794b7964.296c9fae5b8898cdd66e6632e3b77bce658fd5bac4a9efef9f193cd23fe537eb.djn0ZVAivkFqN76E4bu5CobhOFU-2JwjqA1KlwgyaRo
components-date-picker--quill-with-time--light:
diff --git a/frontend/src/lib/components/DatePicker/DatePicker.stories.tsx b/frontend/src/lib/components/DatePicker/DatePicker.stories.tsx
index 2a142e14b798..d4d984b160e6 100644
--- a/frontend/src/lib/components/DatePicker/DatePicker.stories.tsx
+++ b/frontend/src/lib/components/DatePicker/DatePicker.stories.tsx
@@ -54,3 +54,13 @@ export const QuillWithTime: Story = {
render: () => <Template value={dayjs('2023-01-15T09:30')} granularity="minute" showTimeToggle />,
parameters: quillEnabled,
}
+
+export const QuillSmallSecondary: Story = {
+ render: () => <Template value={dayjs('2023-01-15')} size="small" type="secondary" fullWidth={false} />,
+ parameters: quillEnabled,
+}
+
+export const QuillCustomClass: Story = {
+ render: () => <Template value={dayjs('2023-01-15')} className="bg-accent-highlight-secondary" />,
+ parameters: quillEnabled,
+}
diff --git a/frontend/src/lib/components/DatePicker/DatePicker.test.tsx b/frontend/src/lib/components/DatePicker/DatePicker.test.tsx
index d93bbe69341f..e0e32d8939e4 100644
--- a/frontend/src/lib/components/DatePicker/DatePicker.test.tsx
+++ b/frontend/src/lib/components/DatePicker/DatePicker.test.tsx
@@ -116,6 +116,20 @@ describe('DatePicker', () => {
expect(onChange).toHaveBeenCalledWith(null)
})
+ it.each<[string, Partial<DatePickerProps>, string]>([
+ // No explicit type must keep LemonCalendarSelectInput's `secondary` trigger default rather than
+ // clobbering it with `type: undefined` (which would fall back to LemonButton's tertiary default).
+ ['no type keeps the secondary default', {}, 'LemonButton--secondary'],
+ ['type primary maps through', { type: 'primary' }, 'LemonButton--primary'],
+ ['type tertiary maps through', { type: 'tertiary' }, 'LemonButton--tertiary'],
+ ['size small maps through', { size: 'small' }, 'LemonButton--small'],
+ ['custom className forwards through', { className: 'bg-bg-light' }, 'bg-bg-light'],
+ ])('maps trigger %s onto the LemonUI button', (_name, props, expectedClass) => {
+ const { container } = renderDatePicker(dayjs('2023-01-15'), props)
+
+ expect(container.querySelector('.LemonButton')?.className).toContain(expectedClass)
+ })
+
describe('when the QUILL_DATE_PICKER flag is enabled', () => {
beforeEach(() => {
mockQuillDatePickerFlag = true
@@ -128,6 +142,23 @@ describe('DatePicker', () => {
expect(within(container).getByText('January 15, 2023')).toBeTruthy()
})
+ it.each<[string, Partial<DatePickerProps>, string]>([
+ ['size xsmall -> xs', { size: 'xsmall' }, 'quill-button--size-xs'],
+ ['size small -> sm', { size: 'small' }, 'quill-button--size-sm'],
+ ['size medium -> default', { size: 'medium' }, 'quill-button--size-default'],
+ ['size large -> lg', { size: 'large' }, 'quill-button--size-lg'],
+ ['type primary -> primary variant', { type: 'primary' }, 'quill-button--variant-primary'],
+ ['type secondary -> outline variant', { type: 'secondary' }, 'quill-button--variant-outline'],
+ ['type tertiary -> default variant', { type: 'tertiary' }, 'quill-button--variant-default'],
+ ['no type -> outline variant', {}, 'quill-button--variant-outline'],
+ ['no size -> default size', {}, 'quill-button--size-default'],
+ ['custom className', { className: 'bg-bg-light' }, 'bg-bg-light'],
+ ])('maps trigger %s onto the Quill button', (_name, props, expectedClass) => {
+ const { container } = renderDatePicker(dayjs('2023-01-15'), props)
+
+ expect(container.querySelector('[data-quill]')?.className).toContain(expectedClass)
+ })
+
it.each<[string, Partial<DatePickerProps>]>([
['hour granularity', { granularity: 'hour' }],
['12-hour time', { granularity: 'minute', use24HourFormat: false }],
diff --git a/frontend/src/lib/components/DatePicker/DatePicker.tsx b/frontend/src/lib/components/DatePicker/DatePicker.tsx
index 70903c82f7f6..57be7db5a778 100644
--- a/frontend/src/lib/components/DatePicker/DatePicker.tsx
+++ b/frontend/src/lib/components/DatePicker/DatePicker.tsx
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { IconCalendar, IconX } from '@posthog/icons'
-import { Button, DatePicker as QuillDatePicker, Popover, PopoverContent, PopoverTrigger } from '@posthog/quill'
+import { Button, cn, DatePicker as QuillDatePicker, Popover, PopoverContent, PopoverTrigger } from '@posthog/quill'
import { dayjs } from 'lib/dayjs'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
@@ -23,9 +23,10 @@ import { LemonCalendarSelectInput, LemonCalendarSelectInputProps } from 'lib/lem
* Trigger concerns (placeholder, clearable, format, ...) live here by design — Quill
* separates the trigger from the picker panel, so the wrapper owns the trigger.
*
- * The prop surface is intentionally minimal: trigger-styling props (size, type) and
- * `selectionPeriodLimit` are deliberately omitted until a real caller needs them, rather
- * than re-exposing the wrapped component's full API and losing the decoupling.
+ * Trigger-styling props (`size`, `type`, `className`) are typed and decoupled — the seam
+ * maps them onto whichever button backs the current renderer (LemonButton today, Quill
+ * Button under the flag) rather than re-exposing a raw `buttonProps` pass-through.
+ * `selectionPeriodLimit` stays omitted until a real caller needs it.
*
* Controlled visibility is a full trio: pass `visible` plus `onOpen` (fired when the
* trigger is clicked) and `onClickOutside` / `onClose` (fired when the panel dismisses) so
@@ -58,6 +59,12 @@ export interface DatePickerProps {
format?: string
/** Stretch the trigger to fill its container. Defaults to true — the seam owns this default rather than inheriting it from the wrapped trigger. */
fullWidth?: boolean
+ /** Trigger button size. Mapped to the underlying button per backing renderer. */
+ size?: 'xsmall' | 'small' | 'medium' | 'large'
+ /** Trigger button style. Mapped to the underlying button per backing renderer (secondary -> Quill outline; primary -> Quill primary; tertiary -> Quill default). When unset, the Quill trigger uses its neutral `outline`. */
+ type?: 'primary' | 'secondary' | 'tertiary'
+ /** Extra class names merged onto the trigger. */
+ className?: string
/** Disable the trigger and explain why on hover. */
disabledReason?: string
/** Externally control popover visibility. Pair with `onOpen` + `onClickOutside`/`onClose`. */
@@ -74,6 +81,18 @@ export interface DatePickerProps {
const QUILL_TRIGGER_FORMAT = 'MMMM D, YYYY'
const QUILL_TRIGGER_DATETIME_FORMAT = 'MMMM D, YYYY HH:mm'
+const QUILL_TRIGGER_VARIANT: Record<NonNullable<DatePickerProps['type']>, 'primary' | 'outline' | 'default'> = {
+ primary: 'primary',
+ secondary: 'outline',
+ tertiary: 'default',
+}
+const QUILL_TRIGGER_SIZE: Record<NonNullable<DatePickerProps['size']>, 'default' | 'xs' | 'sm' | 'lg'> = {
+ xsmall: 'xs',
+ small: 'sm',
+ medium: 'default',
+ large: 'lg',
+}
+
function quillCanRender(props: DatePickerProps): boolean {
return (
props.granularity !== 'hour' &&
@@ -105,6 +124,9 @@ function DatePickerQuill({
clearable,
format,
fullWidth = true,
+ size = 'medium',
+ type = 'secondary',
+ className,
disabledReason,
maxDate,
'data-attr': dataAttr,
@@ -130,12 +152,13 @@ function DatePickerQuill({
<PopoverTrigger
render={
<Button
- variant="outline"
+ variant={QUILL_TRIGGER_VARIANT[type]}
+ size={QUILL_TRIGGER_SIZE[size]}
data-attr={dataAttr}
data-quill
disabled={!!disabledReason}
title={disabledReason}
- className={fullWidth ? 'w-full justify-start' : 'justify-start'}
+ className={cn('justify-start', fullWidth && 'w-full', className)}
>
<IconCalendar />
{label}
@@ -157,6 +180,7 @@ function DatePickerQuill({
{clearable && value && !disabledReason && (
<Button
variant="outline"
+ size={QUILL_TRIGGER_SIZE[size]}
aria-label="Clear date"
data-attr={dataAttr ? `${dataAttr}-clear` : undefined}
onClick={() => onChange(null)}
@@ -182,6 +206,9 @@ function DatePickerLemon({
clearable,
format,
fullWidth = true,
+ size,
+ type,
+ className,
disabledReason,
visible,
onOpen,
@@ -191,9 +218,16 @@ function DatePickerLemon({
}: DatePickerProps): JSX.Element {
const buttonProps: NonNullable<LemonCalendarSelectInputProps['buttonProps']> = {
fullWidth,
+ size,
+ className,
disabledReason,
'data-attr': dataAttr,
}
+ // Only forward `type` when the caller set one — LemonCalendarSelectInput defaults the trigger to
+ // `secondary` and spreads `buttonProps` after it, so a `type: undefined` here would clobber that default.
+ if (type) {
+ buttonProps.type = type
+ }
// The wrapped trigger only flips its own uncontrolled state; a controlled caller needs the
// click to drive their `visible`, so forward `onOpen` as the trigger's onClick when given.
if (onOpen) {