@loykin/cron-input 0.0.1-dev.4 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,40 @@ validateCronExpression('99 99 * * *')
51
51
  // → false
52
52
  ```
53
53
 
54
+ ## UI Adapter
55
+
56
+ By default `CronInput` renders with its own built-in `@base-ui/react`-backed
57
+ Button/Popover/Tabs. If your app already has real shadcn/ui components, pass
58
+ `uiAdapter` to render with those instead — same behavior, native look:
59
+
60
+ ```tsx
61
+ import { CronInput } from '@loykin/cron-input'
62
+ import { createShadcnAdapter } from '@loykin/cron-input/adapters/shadcn'
63
+ import { Button } from '@/components/ui/button'
64
+ import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'
65
+ import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'
66
+
67
+ // Build once at module scope — uiAdapter must be referentially stable, or the
68
+ // adapted subtree remounts on every render.
69
+ const shadcnAdapter = createShadcnAdapter({
70
+ Button, Popover, PopoverTrigger, PopoverContent,
71
+ Tabs, TabsList, TabsTrigger, TabsContent,
72
+ })
73
+
74
+ <CronInput value={value} onChange={onChange} uiAdapter={shadcnAdapter} />
75
+ ```
76
+
77
+ Only `createShadcnAdapter` ships today. For anything else, build a
78
+ `CronInputUIAdapter` by hand — `Button`, `Popover`, `PopoverTrigger`,
79
+ `PopoverContent`, `Tabs`, `TabsList`, `TabsTrigger`, `TabsContent` are all
80
+ optional; unset fields fall back to the built-in ones. Wrap a subtree in
81
+ `CronInputProvider` to apply one adapter to every `CronInput` inside it
82
+ without passing `uiAdapter` on each.
83
+
84
+ NumberStepper/DayChips/TimePicker and the Custom-tab expression input stay
85
+ built-in either way — they're cron-input's own domain widgets, not generic UI
86
+ primitives, so there's nothing to swap them for.
87
+
54
88
  ## Headless
55
89
 
56
90
  Use `useCronInput` if you want full control over the UI:
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+ import { Button as Button$1 } from '@base-ui/react/button';
4
+ import { Popover as Popover$1 } from '@base-ui/react/popover';
5
+ import { Tabs as Tabs$1 } from '@base-ui/react/tabs';
6
+
7
+ type ButtonVariant = 'default' | 'outline' | 'ghost';
8
+ type ButtonSize = 'default' | 'sm';
9
+ declare function Button({ className, variant, size, type, ...props }: Button$1.Props & {
10
+ variant?: ButtonVariant;
11
+ size?: ButtonSize;
12
+ }): React.JSX.Element;
13
+
14
+ declare function Popover({ ...props }: Popover$1.Root.Props): React.JSX.Element;
15
+ declare function PopoverTrigger({ ...props }: Popover$1.Trigger.Props): React.JSX.Element;
16
+ declare function PopoverContent({ className, align, side, sideOffset, container, ...props }: Popover$1.Popup.Props & Pick<Popover$1.Positioner.Props, 'align' | 'side' | 'sideOffset'> & {
17
+ container?: Popover$1.Portal.Props['container'];
18
+ }): React.JSX.Element;
19
+
20
+ declare function Tabs({ className, ...props }: Tabs$1.Root.Props): React.JSX.Element;
21
+ declare function TabsList({ className, ...props }: Tabs$1.List.Props): React.JSX.Element;
22
+ declare function TabsTrigger({ className, ...props }: Tabs$1.Tab.Props): React.JSX.Element;
23
+ declare function TabsContent({ className, ...props }: Tabs$1.Panel.Props): React.JSX.Element;
24
+
25
+ type ButtonProps = React__default.ComponentProps<typeof Button>;
26
+ type PopoverProps = React__default.ComponentProps<typeof Popover>;
27
+ type PopoverTriggerProps = React__default.ComponentProps<typeof PopoverTrigger>;
28
+ type PopoverContentProps = React__default.ComponentProps<typeof PopoverContent>;
29
+ type TabsProps = React__default.ComponentProps<typeof Tabs>;
30
+ type TabsListProps = React__default.ComponentProps<typeof TabsList>;
31
+ type TabsTriggerProps = React__default.ComponentProps<typeof TabsTrigger>;
32
+ type TabsContentProps = React__default.ComponentProps<typeof TabsContent>;
33
+ /**
34
+ * Component-implementation slots CronInput renders through. Every field is optional —
35
+ * an adapter only needs to supply the slots it wants to replace; anything omitted falls
36
+ * back to the built-in implementation.
37
+ */
38
+ interface CronInputUIAdapter {
39
+ Button?: React__default.ComponentType<ButtonProps>;
40
+ Popover?: React__default.ComponentType<PopoverProps>;
41
+ PopoverTrigger?: React__default.ComponentType<PopoverTriggerProps>;
42
+ PopoverContent?: React__default.ComponentType<PopoverContentProps>;
43
+ Tabs?: React__default.ComponentType<TabsProps>;
44
+ TabsList?: React__default.ComponentType<TabsListProps>;
45
+ TabsTrigger?: React__default.ComponentType<TabsTriggerProps>;
46
+ TabsContent?: React__default.ComponentType<TabsContentProps>;
47
+ }
48
+ type ResolvedCronInputUIAdapter = Required<CronInputUIAdapter>;
49
+ interface CronInputProviderProps {
50
+ adapter?: CronInputUIAdapter;
51
+ children: React__default.ReactNode;
52
+ }
53
+ /** Makes a `uiAdapter` ambient for every CronInput instance nested below it. */
54
+ declare function CronInputProvider({ adapter, children }: CronInputProviderProps): React__default.JSX.Element;
55
+ declare function useCronInputUI(): ResolvedCronInputUIAdapter;
56
+
57
+ export { type CronInputUIAdapter as C, CronInputProvider as a, useCronInputUI as u };
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+ import { Button as Button$1 } from '@base-ui/react/button';
4
+ import { Popover as Popover$1 } from '@base-ui/react/popover';
5
+ import { Tabs as Tabs$1 } from '@base-ui/react/tabs';
6
+
7
+ type ButtonVariant = 'default' | 'outline' | 'ghost';
8
+ type ButtonSize = 'default' | 'sm';
9
+ declare function Button({ className, variant, size, type, ...props }: Button$1.Props & {
10
+ variant?: ButtonVariant;
11
+ size?: ButtonSize;
12
+ }): React.JSX.Element;
13
+
14
+ declare function Popover({ ...props }: Popover$1.Root.Props): React.JSX.Element;
15
+ declare function PopoverTrigger({ ...props }: Popover$1.Trigger.Props): React.JSX.Element;
16
+ declare function PopoverContent({ className, align, side, sideOffset, container, ...props }: Popover$1.Popup.Props & Pick<Popover$1.Positioner.Props, 'align' | 'side' | 'sideOffset'> & {
17
+ container?: Popover$1.Portal.Props['container'];
18
+ }): React.JSX.Element;
19
+
20
+ declare function Tabs({ className, ...props }: Tabs$1.Root.Props): React.JSX.Element;
21
+ declare function TabsList({ className, ...props }: Tabs$1.List.Props): React.JSX.Element;
22
+ declare function TabsTrigger({ className, ...props }: Tabs$1.Tab.Props): React.JSX.Element;
23
+ declare function TabsContent({ className, ...props }: Tabs$1.Panel.Props): React.JSX.Element;
24
+
25
+ type ButtonProps = React__default.ComponentProps<typeof Button>;
26
+ type PopoverProps = React__default.ComponentProps<typeof Popover>;
27
+ type PopoverTriggerProps = React__default.ComponentProps<typeof PopoverTrigger>;
28
+ type PopoverContentProps = React__default.ComponentProps<typeof PopoverContent>;
29
+ type TabsProps = React__default.ComponentProps<typeof Tabs>;
30
+ type TabsListProps = React__default.ComponentProps<typeof TabsList>;
31
+ type TabsTriggerProps = React__default.ComponentProps<typeof TabsTrigger>;
32
+ type TabsContentProps = React__default.ComponentProps<typeof TabsContent>;
33
+ /**
34
+ * Component-implementation slots CronInput renders through. Every field is optional —
35
+ * an adapter only needs to supply the slots it wants to replace; anything omitted falls
36
+ * back to the built-in implementation.
37
+ */
38
+ interface CronInputUIAdapter {
39
+ Button?: React__default.ComponentType<ButtonProps>;
40
+ Popover?: React__default.ComponentType<PopoverProps>;
41
+ PopoverTrigger?: React__default.ComponentType<PopoverTriggerProps>;
42
+ PopoverContent?: React__default.ComponentType<PopoverContentProps>;
43
+ Tabs?: React__default.ComponentType<TabsProps>;
44
+ TabsList?: React__default.ComponentType<TabsListProps>;
45
+ TabsTrigger?: React__default.ComponentType<TabsTriggerProps>;
46
+ TabsContent?: React__default.ComponentType<TabsContentProps>;
47
+ }
48
+ type ResolvedCronInputUIAdapter = Required<CronInputUIAdapter>;
49
+ interface CronInputProviderProps {
50
+ adapter?: CronInputUIAdapter;
51
+ children: React__default.ReactNode;
52
+ }
53
+ /** Makes a `uiAdapter` ambient for every CronInput instance nested below it. */
54
+ declare function CronInputProvider({ adapter, children }: CronInputProviderProps): React__default.JSX.Element;
55
+ declare function useCronInputUI(): ResolvedCronInputUIAdapter;
56
+
57
+ export { type CronInputUIAdapter as C, CronInputProvider as a, useCronInputUI as u };
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+
5
+ // src/adapters/shadcn.tsx
6
+ function resolveContainer(container) {
7
+ if (container && typeof container === "object" && "current" in container) {
8
+ return container.current;
9
+ }
10
+ return container;
11
+ }
12
+ function createShadcnAdapter(components) {
13
+ const {
14
+ Button: ShadcnButton,
15
+ Popover: ShadcnPopover,
16
+ PopoverTrigger: ShadcnPopoverTrigger,
17
+ PopoverContent: ShadcnPopoverContent,
18
+ Tabs: ShadcnTabs,
19
+ TabsList: ShadcnTabsList,
20
+ TabsTrigger: ShadcnTabsTrigger,
21
+ TabsContent: ShadcnTabsContent
22
+ } = components;
23
+ function Button({ type = "button", ...props }) {
24
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnButton, { type, ...props });
25
+ }
26
+ function Popover(props) {
27
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnPopover, { ...props });
28
+ }
29
+ function PopoverTrigger({ render, disabled }) {
30
+ const placeholderTriggerProps = { type: "button" };
31
+ const rendered = typeof render === "function" ? render(placeholderTriggerProps, { disabled: !!disabled, open: false }) : render;
32
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnPopoverTrigger, { asChild: true, disabled, children: rendered });
33
+ }
34
+ function PopoverContent({ container, className, ...props }) {
35
+ const sized = className ? `w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale ${className}` : "w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale";
36
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnPopoverContent, { ...props, className: sized, container: resolveContainer(container) });
37
+ }
38
+ function Tabs({ className, ...props }) {
39
+ const grown = className ? `flex-1 p-4 ${className}` : "flex-1 p-4";
40
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnTabs, { ...props, className: grown });
41
+ }
42
+ function TabsList({ className, ...props }) {
43
+ const widened = className ? `w-full ${className}` : "w-full";
44
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnTabsList, { ...props, className: widened });
45
+ }
46
+ function TabsTrigger(props) {
47
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnTabsTrigger, { ...props });
48
+ }
49
+ function TabsContent({ className, ...props }) {
50
+ const centered = className ? `flex flex-col justify-center ${className}` : "flex flex-col justify-center";
51
+ return /* @__PURE__ */ jsxRuntime.jsx(ShadcnTabsContent, { ...props, className: centered });
52
+ }
53
+ return {
54
+ Button,
55
+ Popover,
56
+ PopoverTrigger,
57
+ PopoverContent,
58
+ Tabs,
59
+ TabsList,
60
+ TabsTrigger,
61
+ TabsContent
62
+ };
63
+ }
64
+
65
+ exports.createShadcnAdapter = createShadcnAdapter;
66
+ //# sourceMappingURL=shadcn.cjs.map
67
+ //# sourceMappingURL=shadcn.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/shadcn.tsx"],"names":["jsx"],"mappings":";;;;;AA0BA,SAAS,iBAAiB,SAAA,EAA4F;AACpH,EAAA,IAAI,SAAA,IAAa,OAAO,SAAA,KAAc,QAAA,IAAY,aAAa,SAAA,EAAW;AACxE,IAAA,OAAO,SAAA,CAAU,OAAA;AAAA,EACnB;AACA,EAAA,OAAO,SAAA;AACT;AAOO,SAAS,oBAAoB,UAAA,EAAyD;AAC3F,EAAA,MAAM;AAAA,IACJ,MAAA,EAAQ,YAAA;AAAA,IACR,OAAA,EAAS,aAAA;AAAA,IACT,cAAA,EAAgB,oBAAA;AAAA,IAChB,cAAA,EAAgB,oBAAA;AAAA,IAChB,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU,cAAA;AAAA,IACV,WAAA,EAAa,iBAAA;AAAA,IACb,WAAA,EAAa;AAAA,GACf,GAAI,UAAA;AAWJ,EAAA,SAAS,OAAO,EAAE,IAAA,GAAO,QAAA,EAAU,GAAG,OAAM,EAAgB;AAC1D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AAS,QAAA,CAAS,EAAE,SAAA,EAAW,GAAG,OAAM,EAAkB;AAKxD,IAAA,MAAM,OAAA,GAAU,SAAA,GAAY,CAAA,OAAA,EAAU,SAAS,CAAA,CAAA,GAAK,QAAA;AACpD,IAAA,uBAAOA,cAAA,CAAC,cAAA,EAAA,EAAgB,GAAG,KAAA,EAAO,WAAW,OAAA,EAAS,CAAA;AAAA,EACxD;AAEA,EAAA,SAAS,YAAY,KAAA,EAAyB;AAC5C,IAAA,uBAAOA,cAAA,CAAC,iBAAA,EAAA,EAAmB,GAAG,KAAA,EAAO,CAAA;AAAA,EACvC;AAEA,EAAA,SAAS,WAAA,CAAY,EAAE,SAAA,EAAW,GAAG,OAAM,EAAqB;AAO9D,IAAA,MAAM,QAAA,GAAW,SAAA,GAAY,CAAA,6BAAA,EAAgC,SAAS,CAAA,CAAA,GAAK,8BAAA;AAC3E,IAAA,uBAAOA,cAAA,CAAC,iBAAA,EAAA,EAAmB,GAAG,KAAA,EAAO,WAAW,QAAA,EAAU,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AACF","file":"shadcn.cjs","sourcesContent":["import type { ElementType } from 'react';\nimport type {\n CronInputUIAdapter,\n ButtonProps,\n PopoverProps,\n PopoverTriggerProps,\n PopoverContentProps,\n TabsProps,\n TabsListProps,\n TabsTriggerProps,\n TabsContentProps,\n} from '../core/UIAdapterContext';\n\nexport interface ShadcnAdapterComponents {\n Button: ElementType;\n Popover: ElementType;\n PopoverTrigger: ElementType;\n PopoverContent: ElementType;\n Tabs: ElementType;\n TabsList: ElementType;\n TabsTrigger: ElementType;\n TabsContent: ElementType;\n}\n\n// base-ui's `container` prop accepts a ref OR an element; Radix's Portal only accepts an\n// element. Unwrap so `portalContainer` (e.g. for a scoped custom theme) works either way.\nfunction resolveContainer(container: PopoverContentProps['container']): Element | DocumentFragment | null | undefined {\n if (container && typeof container === 'object' && 'current' in container) {\n return container.current as Element | null;\n }\n return container as Element | DocumentFragment | null | undefined;\n}\n\n/**\n * Bridges the consumer's own real shadcn/ui components (imported from their app, e.g.\n * `@/components/ui/button`) into a `CronInputUIAdapter` so `<CronInput uiAdapter={...} />`\n * renders with them instead of the built-in @base-ui/react-backed components.\n */\nexport function createShadcnAdapter(components: ShadcnAdapterComponents): CronInputUIAdapter {\n const {\n Button: ShadcnButton,\n Popover: ShadcnPopover,\n PopoverTrigger: ShadcnPopoverTrigger,\n PopoverContent: ShadcnPopoverContent,\n Tabs: ShadcnTabs,\n TabsList: ShadcnTabsList,\n TabsTrigger: ShadcnTabsTrigger,\n TabsContent: ShadcnTabsContent,\n } = components;\n\n // cron-input's own 'default' | 'outline' | 'ghost' variants and 'default' | 'sm' sizes\n // are already a subset of shadcn's standard Button API, so no size/variant map is needed\n // here (unlike datetime-range's wider size union).\n //\n // type=\"button\" default: a plain <button>/shadcn Button with no explicit `type` is\n // type=\"submit\" per the HTML spec — inside a real <form> (a schedule field almost always\n // is one), clicking it submits the form instead of just doing its own thing. Stock\n // shadcn/ui Button templates don't default this themselves, so without it here every\n // Button in this package would silently submit an enclosing form when adapted.\n function Button({ type = 'button', ...props }: ButtonProps) {\n return <ShadcnButton type={type} {...props} />;\n }\n\n function Popover(props: PopoverProps) {\n return <ShadcnPopover {...props} />;\n }\n\n function PopoverTrigger({ render, disabled }: PopoverTriggerProps) {\n // base-ui's render-prop contract: `render(props, state) => ReactElement`, or a bare\n // element. Radix's `asChild` clones whatever element we hand it and injects its own\n // onClick/aria/ref regardless of the placeholder props/state below.\n //\n // { type: 'button' } (not {}): the real base-ui Popover.Trigger always includes\n // type: 'button' in the props it hands to a render function, precisely so a bare\n // <button {...triggerProps}> defaults safely. An empty object here silently drops\n // that — the trigger falls back to the browser's type=\"submit\" default and submits\n // any enclosing <form> on click instead of opening the popover. base-ui's own render\n // prop type doesn't declare `type` on its generic HTML props bag even though its\n // runtime always includes it, so the final cast to Parameters<typeof render>[0] is\n // unavoidable — but typing the literal itself first still gets excess-property\n // checking on it, so a future typo'd key or wrong value here doesn't silently pass.\n const placeholderTriggerProps: { type: 'button' } = { type: 'button' };\n // The `state` (2nd) argument's `open: false` is a placeholder too, but a harmless one:\n // CronInput.tsx's own `render={(triggerProps) => ...}` callback only ever destructures\n // the first argument, and the real `open` state it exposes to a consumer's own\n // `renderTrigger` prop is computed separately from CronInput's own React state, not\n // from this placeholder — so no consumer-facing code path ever observes this `false`.\n const rendered = typeof render === 'function' ? render(placeholderTriggerProps as Parameters<typeof render>[0], { disabled: !!disabled, open: false }) : render;\n\n return (\n <ShadcnPopoverTrigger asChild disabled={disabled}>\n {rendered}\n </ShadcnPopoverTrigger>\n );\n }\n\n function PopoverContent({ container, className, ...props }: PopoverContentProps) {\n // The consumer's shadcn PopoverContent typically defaults to a generic short-menu\n // width (e.g. w-72/288px), sized for the kind of content shadcn/ui ships by default.\n // That's narrower than cron-input's 5-tab bar needs at the consumer's own (non-cramped)\n // type scale. Fixed (not auto) on purpose: the tab bar's 5 triggers are always all\n // mounted, so its width is constant regardless of which tab is active — but the tab\n // *body* below it isn't (only the active one is mounted), so `w-auto` would resize the\n // card on every tab switch as the widest mounted child changes. w-96 comfortably fits\n // the tab bar with room to spare and stays put across tabs.\n //\n // Same reasoning for height: only one tab body is ever mounted at a time, and they're\n // not all the same height (Custom's expression breakdown is the tallest), so an\n // auto-height card would grow/shrink on every tab switch too. min-h pins it to the\n // tallest tab's height so the card holds still regardless of which tab is active.\n //\n // flex-col here (paired with the Tabs wrapper below getting flex-1) is what actually\n // pins the footer to the bottom edge instead of just leaving it floating above a gap:\n // without it, min-h padded the *card*, but the footer — a plain sibling after Tabs —\n // stayed at its natural document-flow position right after whatever short tab body was\n // showing, i.e. it visibly moved between tabs even though the card itself didn't.\n //\n // p-0 + overflow-hidden: the built-in footer (.cron-input-footer) is designed edge-to-\n // edge — its own gray background and top border are meant to span the full width of an\n // unpadded container. The consumer's shadcn PopoverContent defaults to p-4 on every\n // side, which insets the footer into a floating gray box instead. Padding moves onto\n // the Tabs wrapper below so only the tab area is inset; the footer stays flush, and\n // overflow-hidden clips it to the card's own rounded corners.\n //\n // cron-input-shadcn-scale: NumberStepper/DayChips/TimePicker/the Custom-tab input\n // aren't part of the uiAdapter surface, so they still render at the built-in's\n // 11-14px/~28px scale — visibly undersized next to this card's real shadcn (~14px/\n // ~36px) typography. This marker class (see styles/index.css) bumps them to match.\n const sized = className\n ? `w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale ${className}`\n : 'w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale';\n return <ShadcnPopoverContent {...props} className={sized} container={resolveContainer(container)} />;\n }\n\n function Tabs({ className, ...props }: TabsProps) {\n // flex-1 makes the tab-list+body block absorb the leftover vertical space (from the\n // card's fixed min-h), so the footer — its sibling in PopoverContent's flex column —\n // gets pushed flush to the bottom instead of trailing right after a short tab body.\n // p-4 replaces the padding PopoverContent no longer applies (moved here so the footer,\n // Tabs' sibling, can stay unpadded/edge-to-edge — see PopoverContent above).\n const grown = className ? `flex-1 p-4 ${className}` : 'flex-1 p-4';\n return <ShadcnTabs {...props} className={grown} />;\n }\n\n function TabsList({ className, ...props }: TabsListProps) {\n // The built-in tab bar forces 5 equal-width columns (CSS grid); shadcn's default\n // TabsList sizes to its content instead, so each trigger ends up exactly as wide as\n // its own label — \"Daily\" narrower than \"Monthly\". w-full (combined with each\n // trigger's own flex-1) restores the even, grid-like column split.\n const widened = className ? `w-full ${className}` : 'w-full';\n return <ShadcnTabsList {...props} className={widened} />;\n }\n\n function TabsTrigger(props: TabsTriggerProps) {\n return <ShadcnTabsTrigger {...props} />;\n }\n\n function TabsContent({ className, ...props }: TabsContentProps) {\n // TabsContent already gets flex-1 from the consumer's own shadcn styles, so it fills\n // whatever leftover height the fixed-height card has for the (single, short) mounted\n // tab body — but that only sizes the *box*; the body inside it (.cron-input-tab-body,\n // a plain flex column) still stacks at the top of that box by default. flex+justify-\n // center here centers the body vertically within the available space instead of\n // leaving it pinned to the top with dead air below it before the footer.\n const centered = className ? `flex flex-col justify-center ${className}` : 'flex flex-col justify-center';\n return <ShadcnTabsContent {...props} className={centered} />;\n }\n\n return {\n Button,\n Popover,\n PopoverTrigger,\n PopoverContent,\n Tabs,\n TabsList,\n TabsTrigger,\n TabsContent,\n };\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { ElementType } from 'react';
2
+ import { C as CronInputUIAdapter } from '../UIAdapterContext-2S2m9TWH.cjs';
3
+ import '@base-ui/react/button';
4
+ import '@base-ui/react/popover';
5
+ import '@base-ui/react/tabs';
6
+
7
+ interface ShadcnAdapterComponents {
8
+ Button: ElementType;
9
+ Popover: ElementType;
10
+ PopoverTrigger: ElementType;
11
+ PopoverContent: ElementType;
12
+ Tabs: ElementType;
13
+ TabsList: ElementType;
14
+ TabsTrigger: ElementType;
15
+ TabsContent: ElementType;
16
+ }
17
+ /**
18
+ * Bridges the consumer's own real shadcn/ui components (imported from their app, e.g.
19
+ * `@/components/ui/button`) into a `CronInputUIAdapter` so `<CronInput uiAdapter={...} />`
20
+ * renders with them instead of the built-in @base-ui/react-backed components.
21
+ */
22
+ declare function createShadcnAdapter(components: ShadcnAdapterComponents): CronInputUIAdapter;
23
+
24
+ export { type ShadcnAdapterComponents, createShadcnAdapter };
@@ -0,0 +1,24 @@
1
+ import { ElementType } from 'react';
2
+ import { C as CronInputUIAdapter } from '../UIAdapterContext-2S2m9TWH.js';
3
+ import '@base-ui/react/button';
4
+ import '@base-ui/react/popover';
5
+ import '@base-ui/react/tabs';
6
+
7
+ interface ShadcnAdapterComponents {
8
+ Button: ElementType;
9
+ Popover: ElementType;
10
+ PopoverTrigger: ElementType;
11
+ PopoverContent: ElementType;
12
+ Tabs: ElementType;
13
+ TabsList: ElementType;
14
+ TabsTrigger: ElementType;
15
+ TabsContent: ElementType;
16
+ }
17
+ /**
18
+ * Bridges the consumer's own real shadcn/ui components (imported from their app, e.g.
19
+ * `@/components/ui/button`) into a `CronInputUIAdapter` so `<CronInput uiAdapter={...} />`
20
+ * renders with them instead of the built-in @base-ui/react-backed components.
21
+ */
22
+ declare function createShadcnAdapter(components: ShadcnAdapterComponents): CronInputUIAdapter;
23
+
24
+ export { type ShadcnAdapterComponents, createShadcnAdapter };
@@ -0,0 +1,65 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ // src/adapters/shadcn.tsx
4
+ function resolveContainer(container) {
5
+ if (container && typeof container === "object" && "current" in container) {
6
+ return container.current;
7
+ }
8
+ return container;
9
+ }
10
+ function createShadcnAdapter(components) {
11
+ const {
12
+ Button: ShadcnButton,
13
+ Popover: ShadcnPopover,
14
+ PopoverTrigger: ShadcnPopoverTrigger,
15
+ PopoverContent: ShadcnPopoverContent,
16
+ Tabs: ShadcnTabs,
17
+ TabsList: ShadcnTabsList,
18
+ TabsTrigger: ShadcnTabsTrigger,
19
+ TabsContent: ShadcnTabsContent
20
+ } = components;
21
+ function Button({ type = "button", ...props }) {
22
+ return /* @__PURE__ */ jsx(ShadcnButton, { type, ...props });
23
+ }
24
+ function Popover(props) {
25
+ return /* @__PURE__ */ jsx(ShadcnPopover, { ...props });
26
+ }
27
+ function PopoverTrigger({ render, disabled }) {
28
+ const placeholderTriggerProps = { type: "button" };
29
+ const rendered = typeof render === "function" ? render(placeholderTriggerProps, { disabled: !!disabled, open: false }) : render;
30
+ return /* @__PURE__ */ jsx(ShadcnPopoverTrigger, { asChild: true, disabled, children: rendered });
31
+ }
32
+ function PopoverContent({ container, className, ...props }) {
33
+ const sized = className ? `w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale ${className}` : "w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale";
34
+ return /* @__PURE__ */ jsx(ShadcnPopoverContent, { ...props, className: sized, container: resolveContainer(container) });
35
+ }
36
+ function Tabs({ className, ...props }) {
37
+ const grown = className ? `flex-1 p-4 ${className}` : "flex-1 p-4";
38
+ return /* @__PURE__ */ jsx(ShadcnTabs, { ...props, className: grown });
39
+ }
40
+ function TabsList({ className, ...props }) {
41
+ const widened = className ? `w-full ${className}` : "w-full";
42
+ return /* @__PURE__ */ jsx(ShadcnTabsList, { ...props, className: widened });
43
+ }
44
+ function TabsTrigger(props) {
45
+ return /* @__PURE__ */ jsx(ShadcnTabsTrigger, { ...props });
46
+ }
47
+ function TabsContent({ className, ...props }) {
48
+ const centered = className ? `flex flex-col justify-center ${className}` : "flex flex-col justify-center";
49
+ return /* @__PURE__ */ jsx(ShadcnTabsContent, { ...props, className: centered });
50
+ }
51
+ return {
52
+ Button,
53
+ Popover,
54
+ PopoverTrigger,
55
+ PopoverContent,
56
+ Tabs,
57
+ TabsList,
58
+ TabsTrigger,
59
+ TabsContent
60
+ };
61
+ }
62
+
63
+ export { createShadcnAdapter };
64
+ //# sourceMappingURL=shadcn.js.map
65
+ //# sourceMappingURL=shadcn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/adapters/shadcn.tsx"],"names":[],"mappings":";;;AA0BA,SAAS,iBAAiB,SAAA,EAA4F;AACpH,EAAA,IAAI,SAAA,IAAa,OAAO,SAAA,KAAc,QAAA,IAAY,aAAa,SAAA,EAAW;AACxE,IAAA,OAAO,SAAA,CAAU,OAAA;AAAA,EACnB;AACA,EAAA,OAAO,SAAA;AACT;AAOO,SAAS,oBAAoB,UAAA,EAAyD;AAC3F,EAAA,MAAM;AAAA,IACJ,MAAA,EAAQ,YAAA;AAAA,IACR,OAAA,EAAS,aAAA;AAAA,IACT,cAAA,EAAgB,oBAAA;AAAA,IAChB,cAAA,EAAgB,oBAAA;AAAA,IAChB,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU,cAAA;AAAA,IACV,WAAA,EAAa,iBAAA;AAAA,IACb,WAAA,EAAa;AAAA,GACf,G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UAAA,EAAA,EAAY,GAAG,KAAA,EAAO,WAAW,KAAA,EAAO,CAAA;AAAA,EAClD;AAEA,EAAA,SAAS,QAAA,CAAS,EAAE,SAAA,EAAW,GAAG,OAAM,EAAkB;AAKxD,IAAA,MAAM,OAAA,GAAU,SAAA,GAAY,CAAA,OAAA,EAAU,SAAS,CAAA,CAAA,GAAK,QAAA;AACpD,IAAA,uBAAO,GAAA,CAAC,cAAA,EAAA,EAAgB,GAAG,KAAA,EAAO,WAAW,OAAA,EAAS,CAAA;AAAA,EACxD;AAEA,EAAA,SAAS,YAAY,KAAA,EAAyB;AAC5C,IAAA,uBAAO,GAAA,CAAC,iBAAA,EAAA,EAAmB,GAAG,KAAA,EAAO,CAAA;AAAA,EACvC;AAEA,EAAA,SAAS,WAAA,CAAY,EAAE,SAAA,EAAW,GAAG,OAAM,EAAqB;AAO9D,IAAA,MAAM,QAAA,GAAW,SAAA,GAAY,CAAA,6BAAA,EAAgC,SAAS,CAAA,CAAA,GAAK,8BAAA;AAC3E,IAAA,uBAAO,GAAA,CAAC,iBAAA,EAAA,EAAmB,GAAG,KAAA,EAAO,WAAW,QAAA,EAAU,CAAA;AAAA,EAC5D;AAEA,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AACF","file":"shadcn.js","sourcesContent":["import type { ElementType } from 'react';\nimport type {\n CronInputUIAdapter,\n ButtonProps,\n PopoverProps,\n PopoverTriggerProps,\n PopoverContentProps,\n TabsProps,\n TabsListProps,\n TabsTriggerProps,\n TabsContentProps,\n} from '../core/UIAdapterContext';\n\nexport interface ShadcnAdapterComponents {\n Button: ElementType;\n Popover: ElementType;\n PopoverTrigger: ElementType;\n PopoverContent: ElementType;\n Tabs: ElementType;\n TabsList: ElementType;\n TabsTrigger: ElementType;\n TabsContent: ElementType;\n}\n\n// base-ui's `container` prop accepts a ref OR an element; Radix's Portal only accepts an\n// element. Unwrap so `portalContainer` (e.g. for a scoped custom theme) works either way.\nfunction resolveContainer(container: PopoverContentProps['container']): Element | DocumentFragment | null | undefined {\n if (container && typeof container === 'object' && 'current' in container) {\n return container.current as Element | null;\n }\n return container as Element | DocumentFragment | null | undefined;\n}\n\n/**\n * Bridges the consumer's own real shadcn/ui components (imported from their app, e.g.\n * `@/components/ui/button`) into a `CronInputUIAdapter` so `<CronInput uiAdapter={...} />`\n * renders with them instead of the built-in @base-ui/react-backed components.\n */\nexport function createShadcnAdapter(components: ShadcnAdapterComponents): CronInputUIAdapter {\n const {\n Button: ShadcnButton,\n Popover: ShadcnPopover,\n PopoverTrigger: ShadcnPopoverTrigger,\n PopoverContent: ShadcnPopoverContent,\n Tabs: ShadcnTabs,\n TabsList: ShadcnTabsList,\n TabsTrigger: ShadcnTabsTrigger,\n TabsContent: ShadcnTabsContent,\n } = components;\n\n // cron-input's own 'default' | 'outline' | 'ghost' variants and 'default' | 'sm' sizes\n // are already a subset of shadcn's standard Button API, so no size/variant map is needed\n // here (unlike datetime-range's wider size union).\n //\n // type=\"button\" default: a plain <button>/shadcn Button with no explicit `type` is\n // type=\"submit\" per the HTML spec — inside a real <form> (a schedule field almost always\n // is one), clicking it submits the form instead of just doing its own thing. Stock\n // shadcn/ui Button templates don't default this themselves, so without it here every\n // Button in this package would silently submit an enclosing form when adapted.\n function Button({ type = 'button', ...props }: ButtonProps) {\n return <ShadcnButton type={type} {...props} />;\n }\n\n function Popover(props: PopoverProps) {\n return <ShadcnPopover {...props} />;\n }\n\n function PopoverTrigger({ render, disabled }: PopoverTriggerProps) {\n // base-ui's render-prop contract: `render(props, state) => ReactElement`, or a bare\n // element. Radix's `asChild` clones whatever element we hand it and injects its own\n // onClick/aria/ref regardless of the placeholder props/state below.\n //\n // { type: 'button' } (not {}): the real base-ui Popover.Trigger always includes\n // type: 'button' in the props it hands to a render function, precisely so a bare\n // <button {...triggerProps}> defaults safely. An empty object here silently drops\n // that — the trigger falls back to the browser's type=\"submit\" default and submits\n // any enclosing <form> on click instead of opening the popover. base-ui's own render\n // prop type doesn't declare `type` on its generic HTML props bag even though its\n // runtime always includes it, so the final cast to Parameters<typeof render>[0] is\n // unavoidable — but typing the literal itself first still gets excess-property\n // checking on it, so a future typo'd key or wrong value here doesn't silently pass.\n const placeholderTriggerProps: { type: 'button' } = { type: 'button' };\n // The `state` (2nd) argument's `open: false` is a placeholder too, but a harmless one:\n // CronInput.tsx's own `render={(triggerProps) => ...}` callback only ever destructures\n // the first argument, and the real `open` state it exposes to a consumer's own\n // `renderTrigger` prop is computed separately from CronInput's own React state, not\n // from this placeholder — so no consumer-facing code path ever observes this `false`.\n const rendered = typeof render === 'function' ? render(placeholderTriggerProps as Parameters<typeof render>[0], { disabled: !!disabled, open: false }) : render;\n\n return (\n <ShadcnPopoverTrigger asChild disabled={disabled}>\n {rendered}\n </ShadcnPopoverTrigger>\n );\n }\n\n function PopoverContent({ container, className, ...props }: PopoverContentProps) {\n // The consumer's shadcn PopoverContent typically defaults to a generic short-menu\n // width (e.g. w-72/288px), sized for the kind of content shadcn/ui ships by default.\n // That's narrower than cron-input's 5-tab bar needs at the consumer's own (non-cramped)\n // type scale. Fixed (not auto) on purpose: the tab bar's 5 triggers are always all\n // mounted, so its width is constant regardless of which tab is active — but the tab\n // *body* below it isn't (only the active one is mounted), so `w-auto` would resize the\n // card on every tab switch as the widest mounted child changes. w-96 comfortably fits\n // the tab bar with room to spare and stays put across tabs.\n //\n // Same reasoning for height: only one tab body is ever mounted at a time, and they're\n // not all the same height (Custom's expression breakdown is the tallest), so an\n // auto-height card would grow/shrink on every tab switch too. min-h pins it to the\n // tallest tab's height so the card holds still regardless of which tab is active.\n //\n // flex-col here (paired with the Tabs wrapper below getting flex-1) is what actually\n // pins the footer to the bottom edge instead of just leaving it floating above a gap:\n // without it, min-h padded the *card*, but the footer — a plain sibling after Tabs —\n // stayed at its natural document-flow position right after whatever short tab body was\n // showing, i.e. it visibly moved between tabs even though the card itself didn't.\n //\n // p-0 + overflow-hidden: the built-in footer (.cron-input-footer) is designed edge-to-\n // edge — its own gray background and top border are meant to span the full width of an\n // unpadded container. The consumer's shadcn PopoverContent defaults to p-4 on every\n // side, which insets the footer into a floating gray box instead. Padding moves onto\n // the Tabs wrapper below so only the tab area is inset; the footer stays flush, and\n // overflow-hidden clips it to the card's own rounded corners.\n //\n // cron-input-shadcn-scale: NumberStepper/DayChips/TimePicker/the Custom-tab input\n // aren't part of the uiAdapter surface, so they still render at the built-in's\n // 11-14px/~28px scale — visibly undersized next to this card's real shadcn (~14px/\n // ~36px) typography. This marker class (see styles/index.css) bumps them to match.\n const sized = className\n ? `w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale ${className}`\n : 'w-96 min-h-[17rem] flex flex-col p-0 overflow-hidden cron-input-shadcn-scale';\n return <ShadcnPopoverContent {...props} className={sized} container={resolveContainer(container)} />;\n }\n\n function Tabs({ className, ...props }: TabsProps) {\n // flex-1 makes the tab-list+body block absorb the leftover vertical space (from the\n // card's fixed min-h), so the footer — its sibling in PopoverContent's flex column —\n // gets pushed flush to the bottom instead of trailing right after a short tab body.\n // p-4 replaces the padding PopoverContent no longer applies (moved here so the footer,\n // Tabs' sibling, can stay unpadded/edge-to-edge — see PopoverContent above).\n const grown = className ? `flex-1 p-4 ${className}` : 'flex-1 p-4';\n return <ShadcnTabs {...props} className={grown} />;\n }\n\n function TabsList({ className, ...props }: TabsListProps) {\n // The built-in tab bar forces 5 equal-width columns (CSS grid); shadcn's default\n // TabsList sizes to its content instead, so each trigger ends up exactly as wide as\n // its own label — \"Daily\" narrower than \"Monthly\". w-full (combined with each\n // trigger's own flex-1) restores the even, grid-like column split.\n const widened = className ? `w-full ${className}` : 'w-full';\n return <ShadcnTabsList {...props} className={widened} />;\n }\n\n function TabsTrigger(props: TabsTriggerProps) {\n return <ShadcnTabsTrigger {...props} />;\n }\n\n function TabsContent({ className, ...props }: TabsContentProps) {\n // TabsContent already gets flex-1 from the consumer's own shadcn styles, so it fills\n // whatever leftover height the fixed-height card has for the (single, short) mounted\n // tab body — but that only sizes the *box*; the body inside it (.cron-input-tab-body,\n // a plain flex column) still stacks at the top of that box by default. flex+justify-\n // center here centers the body vertically within the available space instead of\n // leaving it pinned to the top with dead air below it before the footer.\n const centered = className ? `flex flex-col justify-center ${className}` : 'flex flex-col justify-center';\n return <ShadcnTabsContent {...props} className={centered} />;\n }\n\n return {\n Button,\n Popover,\n PopoverTrigger,\n PopoverContent,\n Tabs,\n TabsList,\n TabsTrigger,\n TabsContent,\n };\n}\n"]}