@kirana-ui/react 0.0.0 → 0.1.1
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/LICENSE +1 -1
- package/llms.txt +1838 -0
- package/package.json +231 -6
- package/src/accordion.d.ts +28 -0
- package/src/accordion.js +81 -0
- package/src/accordion.js.map +1 -0
- package/src/alert-dialog.d.ts +2 -0
- package/src/alert-dialog.js +1 -0
- package/src/autocomplete.d.ts +2 -0
- package/src/autocomplete.js +1 -0
- package/src/autosize.d.ts +9 -0
- package/src/autosize.js +12 -0
- package/src/autosize.js.map +1 -0
- package/src/avatar.d.ts +16 -0
- package/src/avatar.js +42 -0
- package/src/avatar.js.map +1 -0
- package/src/button.d.ts +7 -0
- package/src/button.js +15 -0
- package/src/button.js.map +1 -0
- package/src/calendar.d.ts +44 -0
- package/src/calendar.js +85 -0
- package/src/calendar.js.map +1 -0
- package/src/carousel.d.ts +26 -0
- package/src/carousel.js +52 -0
- package/src/carousel.js.map +1 -0
- package/src/checkbox.d.ts +18 -0
- package/src/checkbox.js +51 -0
- package/src/checkbox.js.map +1 -0
- package/src/collapsible.d.ts +20 -0
- package/src/collapsible.js +43 -0
- package/src/collapsible.js.map +1 -0
- package/src/combobox.d.ts +91 -0
- package/src/combobox.js +164 -0
- package/src/combobox.js.map +1 -0
- package/src/command.d.ts +44 -0
- package/src/command.js +88 -0
- package/src/command.js.map +1 -0
- package/src/context-menu.d.ts +2 -0
- package/src/context-menu.js +1 -0
- package/src/date-field.d.ts +25 -0
- package/src/date-field.js +60 -0
- package/src/date-field.js.map +1 -0
- package/src/date-picker.d.ts +53 -0
- package/src/date-picker.js +62 -0
- package/src/date-picker.js.map +1 -0
- package/src/dialog.d.ts +63 -0
- package/src/dialog.js +66 -0
- package/src/dialog.js.map +1 -0
- package/src/direction-context.d.ts +4 -0
- package/src/direction-context.js +7 -0
- package/src/direction-context.js.map +1 -0
- package/src/direction.d.ts +15 -0
- package/src/direction.js +27 -0
- package/src/direction.js.map +1 -0
- package/src/drawer.d.ts +2 -0
- package/src/drawer.js +1 -0
- package/src/field-context.d.ts +4 -0
- package/src/field-context.js +7 -0
- package/src/field-context.js.map +1 -0
- package/src/field.d.ts +31 -0
- package/src/field.js +71 -0
- package/src/field.js.map +1 -0
- package/src/fieldset.d.ts +15 -0
- package/src/fieldset.js +31 -0
- package/src/fieldset.js.map +1 -0
- package/src/form.d.ts +8 -0
- package/src/form.js +27 -0
- package/src/form.js.map +1 -0
- package/src/hover-card.d.ts +13 -0
- package/src/hover-card.js +7 -0
- package/src/hover-card.js.map +1 -0
- package/src/hover-popup.d.ts +25 -0
- package/src/hover-popup.js +57 -0
- package/src/hover-popup.js.map +1 -0
- package/src/index.d.ts +48 -0
- package/src/index.js +47 -0
- package/src/input.d.ts +10 -0
- package/src/input.js +21 -0
- package/src/input.js.map +1 -0
- package/src/label.d.ts +5 -0
- package/src/label.js +14 -0
- package/src/label.js.map +1 -0
- package/src/listbox.d.ts +28 -0
- package/src/listbox.js +89 -0
- package/src/listbox.js.map +1 -0
- package/src/menu.d.ts +89 -0
- package/src/menu.js +214 -0
- package/src/menu.js.map +1 -0
- package/src/menubar-context.d.ts +4 -0
- package/src/menubar-context.js +7 -0
- package/src/menubar-context.js.map +1 -0
- package/src/menubar.d.ts +9 -0
- package/src/menubar.js +25 -0
- package/src/menubar.js.map +1 -0
- package/src/message-scroller.d.ts +18 -0
- package/src/message-scroller.js +35 -0
- package/src/message-scroller.js.map +1 -0
- package/src/meter.d.ts +13 -0
- package/src/meter.js +7 -0
- package/src/meter.js.map +1 -0
- package/src/navigation-menu.d.ts +48 -0
- package/src/navigation-menu.js +115 -0
- package/src/navigation-menu.js.map +1 -0
- package/src/number-field.d.ts +21 -0
- package/src/number-field.js +62 -0
- package/src/number-field.js.map +1 -0
- package/src/otp.d.ts +26 -0
- package/src/otp.js +70 -0
- package/src/otp.js.map +1 -0
- package/src/pagination.d.ts +27 -0
- package/src/pagination.js +50 -0
- package/src/pagination.js.map +1 -0
- package/src/popover.d.ts +32 -0
- package/src/popover.js +51 -0
- package/src/popover.js.map +1 -0
- package/src/progress.d.ts +13 -0
- package/src/progress.js +7 -0
- package/src/progress.js.map +1 -0
- package/src/qr-code.d.ts +16 -0
- package/src/qr-code.js +32 -0
- package/src/qr-code.js.map +1 -0
- package/src/radio-group.d.ts +24 -0
- package/src/radio-group.js +87 -0
- package/src/radio-group.js.map +1 -0
- package/src/resizable.d.ts +19 -0
- package/src/resizable.js +51 -0
- package/src/resizable.js.map +1 -0
- package/src/runtime.d.ts +61 -0
- package/src/runtime.js +208 -0
- package/src/runtime.js.map +1 -0
- package/src/scroll-area.d.ts +25 -0
- package/src/scroll-area.js +61 -0
- package/src/scroll-area.js.map +1 -0
- package/src/select.d.ts +74 -0
- package/src/select.js +149 -0
- package/src/select.js.map +1 -0
- package/src/separator.d.ts +6 -0
- package/src/separator.js +10 -0
- package/src/separator.js.map +1 -0
- package/src/slider.d.ts +29 -0
- package/src/slider.js +84 -0
- package/src/slider.js.map +1 -0
- package/src/switch.d.ts +14 -0
- package/src/switch.js +46 -0
- package/src/switch.js.map +1 -0
- package/src/tabs.d.ts +30 -0
- package/src/tabs.js +73 -0
- package/src/tabs.js.map +1 -0
- package/src/toast.d.ts +32 -0
- package/src/toast.js +61 -0
- package/src/toast.js.map +1 -0
- package/src/toggle-group.d.ts +7 -0
- package/src/toggle-group.js +32 -0
- package/src/toggle-group.js.map +1 -0
- package/src/toggle.d.ts +7 -0
- package/src/toggle.js +25 -0
- package/src/toggle.js.map +1 -0
- package/src/toolbar-context.d.ts +7 -0
- package/src/toolbar-context.js +9 -0
- package/src/toolbar-context.js.map +1 -0
- package/src/toolbar.d.ts +20 -0
- package/src/toolbar.js +53 -0
- package/src/toolbar.js.map +1 -0
- package/src/tooltip.d.ts +13 -0
- package/src/tooltip.js +7 -0
- package/src/tooltip.js.map +1 -0
- package/src/value-bar.d.ts +17 -0
- package/src/value-bar.js +51 -0
- package/src/value-bar.js.map +1 -0
- package/README.md +0 -7
- package/index.js +0 -5
package/src/resizable.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { useController, useOptions, usePart } from "./runtime.js";
|
|
3
|
+
import { defined, within } from "@kirana-ui/core";
|
|
4
|
+
import { createContext, useContext, useMemo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createResizable } from "@kirana-ui/core/resizable";
|
|
7
|
+
// src/resizable.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
function useResizable(part) {
|
|
10
|
+
const controller = useContext(Context);
|
|
11
|
+
if (!controller) throw new Error(`<Resizable.${part}> must be inside <Resizable.Group>`);
|
|
12
|
+
return controller;
|
|
13
|
+
}
|
|
14
|
+
function Group({ orientation, onSizesChange, keyboardStep, disabled, id, ...rest }) {
|
|
15
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
16
|
+
const controller = useController(within(createResizable, { direction }), {
|
|
17
|
+
orientation,
|
|
18
|
+
onSizesChange,
|
|
19
|
+
keyboardStep,
|
|
20
|
+
disabled,
|
|
21
|
+
id
|
|
22
|
+
});
|
|
23
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
24
|
+
value: controller,
|
|
25
|
+
children: usePart(controller.group, "div", rest)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function Panel({ defaultSize, minSize, maxSize, ...props }) {
|
|
29
|
+
const controller = useResizable("Panel");
|
|
30
|
+
const options = useOptions({
|
|
31
|
+
defaultSize,
|
|
32
|
+
minSize,
|
|
33
|
+
maxSize
|
|
34
|
+
});
|
|
35
|
+
const part = useMemo(() => controller.panel(() => defined(options.get())), [controller, options]);
|
|
36
|
+
return usePart(part, "div", props);
|
|
37
|
+
}
|
|
38
|
+
function Handle({ disabled, ...props }) {
|
|
39
|
+
const controller = useResizable("Handle");
|
|
40
|
+
const options = useOptions({ disabled });
|
|
41
|
+
const part = useMemo(() => controller.handle(() => defined(options.get())), [controller, options]);
|
|
42
|
+
return usePart(part, "div", props);
|
|
43
|
+
}
|
|
44
|
+
const Resizable = {
|
|
45
|
+
Group,
|
|
46
|
+
Panel,
|
|
47
|
+
Handle
|
|
48
|
+
};
|
|
49
|
+
export { Resizable };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=resizable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resizable.js","names":[],"sources":["../../../../packages/react/src/resizable.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport { createResizable } from \"@kirana-ui/core/resizable\"\nimport type {\n Resizable as Controller,\n ResizablePanelOptions,\n ResizableProps,\n} from \"@kirana-ui/core/resizable\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, useOptions, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useResizable(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Resizable.${part}> must be inside <Resizable.Group>`)\n return controller\n}\n\nexport type GroupProps = Omit<ResizableProps, \"id\"> & { id?: string } & PartComponentProps\n\nfunction Group({\n orientation,\n onSizesChange,\n keyboardStep,\n disabled,\n id,\n ...rest\n}: GroupProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<ResizableProps, Controller>(\n within(createResizable, { direction }),\n { orientation, onSizesChange, keyboardStep, disabled, id }\n )\n return (\n <Context.Provider value={controller}>{usePart(controller.group, \"div\", rest)}</Context.Provider>\n )\n}\n\nexport type PanelProps = PartComponentProps & ResizablePanelOptions\n\nfunction Panel({ defaultSize, minSize, maxSize, ...props }: PanelProps): ReactElement {\n const controller = useResizable(\"Panel\")\n const options = useOptions({ defaultSize, minSize, maxSize })\n const part = useMemo(() => controller.panel(() => defined(options.get())), [controller, options])\n return usePart(part, \"div\", props)\n}\n\nfunction Handle({ disabled, ...props }: PartComponentProps & { disabled?: boolean }) {\n const controller = useResizable(\"Handle\")\n const options = useOptions({ disabled })\n const part = useMemo(() => controller.handle(() => defined(options.get())), [controller, options])\n return usePart(part, \"div\", props)\n}\n\nexport const Resizable = { Group, Panel, Handle }\n"],"mappings":";;;;;;;AAcA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,aAAa,MAA0B;CAC9C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,cAAc,KAAK,mCAAmC;CACvF,OAAO;AACT;AAIA,SAAS,MAAM,EACb,aACA,eACA,cACA,UACA,IACA,GAAG,QACwB;CAC3B,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cACjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,GACrC;EAAE;EAAa;EAAe;EAAc;EAAU;CAAG,CAC3D;CACA,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,OAAO,OAAO,IAAI;CAAoB,CAAA;AAEnG;AAIA,SAAS,MAAM,EAAE,aAAa,SAAS,SAAS,GAAG,SAAmC;CACpF,MAAM,aAAa,aAAa,OAAO;CACvC,MAAM,UAAU,WAAW;EAAE;EAAa;EAAS;CAAQ,CAAC;CAC5D,MAAM,OAAO,cAAc,WAAW,YAAY,QAAQ,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC;CAChG,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAEA,SAAS,OAAO,EAAE,UAAU,GAAG,SAAsD;CACnF,MAAM,aAAa,aAAa,QAAQ;CACxC,MAAM,UAAU,WAAW,EAAE,SAAS,CAAC;CACvC,MAAM,OAAO,cAAc,WAAW,aAAa,QAAQ,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC;CACjG,OAAO,QAAQ,MAAM,OAAO,KAAK;AACnC;AAEA,MAAa,YAAY;CAAE;CAAO;CAAO;AAAO"}
|
package/src/runtime.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Part, ReadonlySignal } from "@kirana-ui/core";
|
|
2
|
+
import { ReactElement, ReactNode, Ref, useLayoutEffect } from "react";
|
|
3
|
+
/** A layout effect in the browser, an effect (which never runs) on a server. */
|
|
4
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
5
|
+
/** A core signal's value, re-rendering when it changes. */
|
|
6
|
+
export declare function useSignal<T>(source: ReadonlySignal<T>): T;
|
|
7
|
+
/**
|
|
8
|
+
* A component's controller, made once, following the props of each render. The props reach the
|
|
9
|
+
* core after the render commits (a layout effect), never during it: another part that reads the
|
|
10
|
+
* controller is another component, and React forbids updating it mid-render.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useController<P extends object, C extends {
|
|
13
|
+
mount(): () => void;
|
|
14
|
+
}>(create: (props: ReadonlySignal<P>) => C, props: Omit<P, "id"> & {
|
|
15
|
+
id?: string | undefined;
|
|
16
|
+
}): C;
|
|
17
|
+
/**
|
|
18
|
+
* Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an
|
|
19
|
+
* effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:
|
|
20
|
+
* a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in
|
|
21
|
+
* the meantime keeps what is running.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useMount(mounted: {
|
|
24
|
+
mount(): () => void;
|
|
25
|
+
}): void;
|
|
26
|
+
/** A part's own options as a core signal that follows each render, after it commits. */
|
|
27
|
+
export declare function useOptions<T extends Record<string, unknown>>(options: T): ReadonlySignal<T>;
|
|
28
|
+
export type RenderProp<State = undefined> = ReactElement<Record<string, unknown>> | ((props: Record<string, unknown>, state: State) => ReactElement);
|
|
29
|
+
export interface PartComponentProps<State = undefined> {
|
|
30
|
+
/** Renders the part as another element or component. The part's attributes still win. */
|
|
31
|
+
render?: RenderProp<State> | undefined;
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
34
|
+
[attribute: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Renders a part: its element (or the caller's `render`), with the caller's props merged under
|
|
38
|
+
* the part's, and the part's DOM work attached to the element.
|
|
39
|
+
*/
|
|
40
|
+
export declare function usePart<State = undefined>(part: Part, tag: string, { render, ref, ...caller }: PartComponentProps<State>, state?: State): ReactElement;
|
|
41
|
+
/**
|
|
42
|
+
* A text input whose text is the core's own (a combobox's, a number field's): its `value` is
|
|
43
|
+
* given to React as the input's default. To React a `value` with no `onChange` is an input
|
|
44
|
+
* that cannot be typed in; the core writes the text itself, as it changes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useOwnText(part: Part): Part;
|
|
47
|
+
export interface PortalProviderProps {
|
|
48
|
+
/** Where the popups inside are drawn; the end of `<body>` while it is not given. */
|
|
49
|
+
container?: HTMLElement | null | undefined;
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Says where every popup inside it is drawn, the popups those open included: an element of
|
|
54
|
+
* the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function PortalProvider({ container, children }: PortalProviderProps): ReactElement;
|
|
57
|
+
/** Its children in a container at the end of the page, once the page has hydrated. */
|
|
58
|
+
export declare function Portal({ children }: {
|
|
59
|
+
children?: ReactNode;
|
|
60
|
+
}): ReactElement | null;
|
|
61
|
+
//# sourceMappingURL=runtime.d.ts.map
|
package/src/runtime.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { computed, mergeProps, sameProps, signal } from "@kirana-ui/core";
|
|
2
|
+
import { cloneElement, createContext, createElement, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/runtime.tsx
|
|
6
|
+
/** A layout effect in the browser, an effect (which never runs) on a server. */
|
|
7
|
+
const useIsomorphicLayoutEffect = typeof document === "undefined" ? useEffect : useLayoutEffect;
|
|
8
|
+
/** A core signal's value, re-rendering when it changes. */
|
|
9
|
+
function useSignal(source) {
|
|
10
|
+
const subscribe = useCallback((listener) => source.subscribe(listener), [source]);
|
|
11
|
+
const read = useCallback(() => source.peek(), [source]);
|
|
12
|
+
return useSyncExternalStore(subscribe, read, read);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A component's controller, made once, following the props of each render. The props reach the
|
|
16
|
+
* core after the render commits (a layout effect), never during it: another part that reads the
|
|
17
|
+
* controller is another component, and React forbids updating it mid-render.
|
|
18
|
+
*/
|
|
19
|
+
function useController(create, props) {
|
|
20
|
+
const generated = useId();
|
|
21
|
+
const next = {
|
|
22
|
+
...props,
|
|
23
|
+
id: props.id ?? generated
|
|
24
|
+
};
|
|
25
|
+
const latest = useRef(next);
|
|
26
|
+
latest.current = next;
|
|
27
|
+
const [state] = useState(() => {
|
|
28
|
+
const stable = {};
|
|
29
|
+
for (const key in next) stable[key] = typeof next[key] === "function" ? (...args) => latest.current[key]?.(...args) : next[key];
|
|
30
|
+
const source = signal(stable, sameProps);
|
|
31
|
+
return {
|
|
32
|
+
source,
|
|
33
|
+
controller: create(source)
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
useIsomorphicLayoutEffect(() => {
|
|
37
|
+
const stable = { ...state.source.peek() };
|
|
38
|
+
for (const key in next) if (typeof next[key] !== "function") stable[key] = next[key];
|
|
39
|
+
state.source.set(stable);
|
|
40
|
+
});
|
|
41
|
+
useMount(state.controller);
|
|
42
|
+
return state.controller;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an
|
|
46
|
+
* effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:
|
|
47
|
+
* a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in
|
|
48
|
+
* the meantime keeps what is running.
|
|
49
|
+
*/
|
|
50
|
+
function useMount(mounted) {
|
|
51
|
+
const [state] = useState(() => ({
|
|
52
|
+
of: mounted,
|
|
53
|
+
unmount: void 0,
|
|
54
|
+
leaving: false
|
|
55
|
+
}));
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (state.of !== mounted) {
|
|
58
|
+
state.unmount?.();
|
|
59
|
+
state.unmount = void 0;
|
|
60
|
+
state.of = mounted;
|
|
61
|
+
}
|
|
62
|
+
state.leaving = false;
|
|
63
|
+
state.unmount ??= mounted.mount();
|
|
64
|
+
return () => {
|
|
65
|
+
state.leaving = true;
|
|
66
|
+
queueMicrotask(() => {
|
|
67
|
+
if (!state.leaving) return;
|
|
68
|
+
state.unmount?.();
|
|
69
|
+
state.unmount = void 0;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
}, [state, mounted]);
|
|
73
|
+
}
|
|
74
|
+
/** A part's own options as a core signal that follows each render, after it commits. */
|
|
75
|
+
function useOptions(options) {
|
|
76
|
+
const [source] = useState(() => signal(options, sameProps));
|
|
77
|
+
useIsomorphicLayoutEffect(() => source.set(options));
|
|
78
|
+
return source;
|
|
79
|
+
}
|
|
80
|
+
const BOOLEAN = /* @__PURE__ */ new Set([
|
|
81
|
+
"hidden",
|
|
82
|
+
"disabled",
|
|
83
|
+
"inert",
|
|
84
|
+
"required",
|
|
85
|
+
"readonly",
|
|
86
|
+
"multiple",
|
|
87
|
+
"checked",
|
|
88
|
+
"novalidate"
|
|
89
|
+
]);
|
|
90
|
+
const RENAMED = {
|
|
91
|
+
tabindex: "tabIndex",
|
|
92
|
+
for: "htmlFor",
|
|
93
|
+
readonly: "readOnly",
|
|
94
|
+
novalidate: "noValidate",
|
|
95
|
+
autocomplete: "autoComplete",
|
|
96
|
+
inputmode: "inputMode",
|
|
97
|
+
maxlength: "maxLength",
|
|
98
|
+
contenteditable: "contentEditable",
|
|
99
|
+
spellcheck: "spellCheck",
|
|
100
|
+
autocapitalize: "autoCapitalize",
|
|
101
|
+
enterkeyhint: "enterKeyHint"
|
|
102
|
+
};
|
|
103
|
+
/** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */
|
|
104
|
+
function reactStyle(style) {
|
|
105
|
+
const out = {};
|
|
106
|
+
for (const name in style) {
|
|
107
|
+
const key = name.startsWith("--") ? name : name.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
|
|
108
|
+
out[key] = style[name];
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
function toReact(props) {
|
|
113
|
+
const out = {};
|
|
114
|
+
for (const key in props) {
|
|
115
|
+
const value = props[key];
|
|
116
|
+
if (BOOLEAN.has(key)) out[RENAMED[key] ?? key] = value === "" || value === true;
|
|
117
|
+
else if (key === "style" && value) out.style = reactStyle(value);
|
|
118
|
+
else if (value !== void 0) out[RENAMED[key] ?? key] = value;
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Renders a part: its element (or the caller's `render`), with the caller's props merged under
|
|
124
|
+
* the part's, and the part's DOM work attached to the element.
|
|
125
|
+
*/
|
|
126
|
+
function usePart(part, tag, { render, ref, ...caller }, state) {
|
|
127
|
+
const own = useSignal(part.props);
|
|
128
|
+
const held = useRef(void 0);
|
|
129
|
+
const attach = useCallback((element) => {
|
|
130
|
+
const now = held.current;
|
|
131
|
+
if (!element) {
|
|
132
|
+
if (now) {
|
|
133
|
+
now.leaving = true;
|
|
134
|
+
queueMicrotask(() => {
|
|
135
|
+
if (!now.leaving) return;
|
|
136
|
+
now.detach();
|
|
137
|
+
if (held.current === now) held.current = void 0;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
} else if (now && now.element === element && now.part === part) now.leaving = false;
|
|
141
|
+
else {
|
|
142
|
+
if (now) {
|
|
143
|
+
now.leaving = false;
|
|
144
|
+
now.detach();
|
|
145
|
+
}
|
|
146
|
+
held.current = {
|
|
147
|
+
element,
|
|
148
|
+
part,
|
|
149
|
+
detach: part.attach(element),
|
|
150
|
+
leaving: false
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (typeof ref === "function") ref(element);
|
|
154
|
+
else if (ref) ref.current = element;
|
|
155
|
+
}, [part, ref]);
|
|
156
|
+
const props = {
|
|
157
|
+
...toReact(mergeProps(caller, own)),
|
|
158
|
+
ref: attach
|
|
159
|
+
};
|
|
160
|
+
if (typeof render === "function") return render(props, state);
|
|
161
|
+
if (isValidElement(render)) return cloneElement(render, {
|
|
162
|
+
...toReact(mergeProps(render.props, props)),
|
|
163
|
+
ref: attach
|
|
164
|
+
});
|
|
165
|
+
return createElement(tag, props);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* A text input whose text is the core's own (a combobox's, a number field's): its `value` is
|
|
169
|
+
* given to React as the input's default. To React a `value` with no `onChange` is an input
|
|
170
|
+
* that cannot be typed in; the core writes the text itself, as it changes.
|
|
171
|
+
*/
|
|
172
|
+
function useOwnText(part) {
|
|
173
|
+
return useMemo(() => ({
|
|
174
|
+
props: computed(() => {
|
|
175
|
+
const { value, ...rest } = part.props.get();
|
|
176
|
+
return {
|
|
177
|
+
...rest,
|
|
178
|
+
defaultValue: value
|
|
179
|
+
};
|
|
180
|
+
}),
|
|
181
|
+
attach: (element) => part.attach(element)
|
|
182
|
+
}), [part]);
|
|
183
|
+
}
|
|
184
|
+
const PortalContainer = createContext(void 0);
|
|
185
|
+
/**
|
|
186
|
+
* Says where every popup inside it is drawn, the popups those open included: an element of
|
|
187
|
+
* the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.
|
|
188
|
+
*/
|
|
189
|
+
function PortalProvider({ container, children }) {
|
|
190
|
+
return /* @__PURE__ */ jsx(PortalContainer.Provider, {
|
|
191
|
+
value: container,
|
|
192
|
+
children
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/** Its children in a container at the end of the page, once the page has hydrated. */
|
|
196
|
+
function Portal({ children }) {
|
|
197
|
+
const container = useContext(PortalContainer);
|
|
198
|
+
const [ready, setReady] = useState(false);
|
|
199
|
+
useIsomorphicLayoutEffect(() => setReady(true), []);
|
|
200
|
+
if (!ready) return null;
|
|
201
|
+
return createPortal(/* @__PURE__ */ jsx("div", {
|
|
202
|
+
"data-kirana-portal": "",
|
|
203
|
+
children
|
|
204
|
+
}), container ?? document.body);
|
|
205
|
+
}
|
|
206
|
+
export { Portal, PortalProvider, useController, useIsomorphicLayoutEffect, useMount, useOptions, useOwnText, usePart, useSignal };
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../../../packages/react/src/runtime.tsx"],"sourcesContent":["import { computed, mergeProps, sameProps, signal } from \"@kirana-ui/core\"\nimport type { Part, PartProps, ReadonlySignal, Signal } from \"@kirana-ui/core\"\nimport {\n cloneElement,\n createContext,\n createElement,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from \"react\"\nimport type { ReactElement, ReactNode, Ref } from \"react\"\nimport { createPortal } from \"react-dom\"\n\n/** A layout effect in the browser, an effect (which never runs) on a server. */\nexport const useIsomorphicLayoutEffect =\n typeof document === \"undefined\" ? useEffect : useLayoutEffect\n\n/** A core signal's value, re-rendering when it changes. */\nexport function useSignal<T>(source: ReadonlySignal<T>): T {\n const subscribe = useCallback((listener: () => void) => source.subscribe(listener), [source])\n const read = useCallback(() => source.peek(), [source])\n return useSyncExternalStore(subscribe, read, read)\n}\n\n/**\n * A component's controller, made once, following the props of each render. The props reach the\n * core after the render commits (a layout effect), never during it: another part that reads the\n * controller is another component, and React forbids updating it mid-render.\n */\nexport function useController<P extends object, C extends { mount(): () => void }>(\n create: (props: ReadonlySignal<P>) => C,\n props: Omit<P, \"id\"> & { id?: string | undefined }\n): C {\n const generated = useId()\n const next = { ...props, id: props.id ?? generated } as P\n const latest = useRef(next)\n latest.current = next\n const [state] = useState(() => {\n // The callbacks the core holds always call the latest render's.\n const stable = {} as Record<string, unknown>\n for (const key in next) {\n stable[key] =\n typeof next[key] === \"function\"\n ? (...args: unknown[]) =>\n (latest.current[key] as ((...args: unknown[]) => unknown) | undefined)?.(...args)\n : next[key]\n }\n const source: Signal<P> = signal(stable as P, sameProps as (a: P, b: P) => boolean)\n return { source, controller: create(source) }\n })\n useIsomorphicLayoutEffect(() => {\n const stable = { ...state.source.peek() } as Record<string, unknown>\n for (const key in next) {\n if (typeof next[key] !== \"function\") stable[key] = next[key]\n }\n state.source.set(stable as P)\n })\n useMount(state.controller)\n return state.controller\n}\n\n/**\n * Starts what a controller (or an item of one) runs while it is in the page. StrictMode runs an\n * effect, undoes it and runs it again in one commit, to find effects that cannot be run twice:\n * a mount is not undone for that. The cleanup waits a moment, and a mount that comes back in\n * the meantime keeps what is running.\n */\nexport function useMount(mounted: { mount(): () => void }): void {\n const [state] = useState(() => ({\n of: mounted,\n unmount: undefined as (() => void) | undefined,\n leaving: false,\n }))\n useEffect(() => {\n if (state.of !== mounted) {\n state.unmount?.()\n state.unmount = undefined\n state.of = mounted\n }\n state.leaving = false\n state.unmount ??= mounted.mount()\n return () => {\n state.leaving = true\n queueMicrotask(() => {\n if (!state.leaving) return\n state.unmount?.()\n state.unmount = undefined\n })\n }\n }, [state, mounted])\n}\n\n/** A part's own options as a core signal that follows each render, after it commits. */\nexport function useOptions<T extends Record<string, unknown>>(options: T): ReadonlySignal<T> {\n const [source] = useState(() => signal(options, sameProps as (a: T, b: T) => boolean))\n useIsomorphicLayoutEffect(() => source.set(options))\n return source\n}\n\n// HTML's boolean attributes, which React takes as booleans: a part's `\"\"` means \"present\".\nconst BOOLEAN = new Set([\n \"hidden\",\n \"disabled\",\n \"inert\",\n \"required\",\n \"readonly\",\n \"multiple\",\n \"checked\",\n \"novalidate\",\n])\nconst RENAMED: Record<string, string> = {\n tabindex: \"tabIndex\",\n for: \"htmlFor\",\n readonly: \"readOnly\",\n novalidate: \"noValidate\",\n autocomplete: \"autoComplete\",\n inputmode: \"inputMode\",\n maxlength: \"maxLength\",\n contenteditable: \"contentEditable\",\n spellcheck: \"spellCheck\",\n autocapitalize: \"autoCapitalize\",\n enterkeyhint: \"enterKeyHint\",\n}\n\n/** A style as React takes it: `inset-inline-start` is `insetInlineStart`, `--x` stays as it is. */\nfunction reactStyle(style: Record<string, string>): Record<string, string> {\n const out: Record<string, string> = {}\n for (const name in style) {\n const key = name.startsWith(\"--\")\n ? name\n : name.replace(/-([a-z])/g, (_match, letter: string) => letter.toUpperCase())\n out[key] = style[name]!\n }\n return out\n}\n\nfunction toReact(props: PartProps): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n for (const key in props) {\n const value = props[key]\n // Always a boolean, never left out: an input whose `checked` comes and goes is, to React,\n // one that changes from controlled to not.\n if (BOOLEAN.has(key)) out[RENAMED[key] ?? key] = value === \"\" || value === true\n else if (key === \"style\" && value) out.style = reactStyle(value as Record<string, string>)\n else if (value !== undefined) out[RENAMED[key] ?? key] = value\n }\n return out\n}\n\nexport type RenderProp<State = undefined> =\n | ReactElement<Record<string, unknown>>\n | ((props: Record<string, unknown>, state: State) => ReactElement)\n\nexport interface PartComponentProps<State = undefined> {\n /** Renders the part as another element or component. The part's attributes still win. */\n render?: RenderProp<State> | undefined\n children?: ReactNode\n ref?: Ref<HTMLElement> | undefined\n [attribute: string]: unknown\n}\n\n/** A part's DOM work on the element it is on. */\ninterface Attached {\n element: HTMLElement\n part: Part\n detach(): void\n leaving: boolean\n}\n\n/**\n * Renders a part: its element (or the caller's `render`), with the caller's props merged under\n * the part's, and the part's DOM work attached to the element.\n */\nexport function usePart<State = undefined>(\n part: Part,\n tag: string,\n { render, ref, ...caller }: PartComponentProps<State>,\n state?: State\n): ReactElement {\n const own = useSignal(part.props)\n const held = useRef<Attached | undefined>(undefined)\n const attach = useCallback(\n (element: HTMLElement | null) => {\n const now = held.current\n if (!element) {\n // React takes a ref away and hands it straight back when the caller's `ref` is a new\n // function, and in StrictMode when the element is first drawn. The part's DOM work is\n // not undone for that (a popup would close its layer and give focus back): it is\n // undone a moment later, if the element has not come back.\n if (now) {\n now.leaving = true\n queueMicrotask(() => {\n if (!now.leaving) return\n now.detach()\n if (held.current === now) held.current = undefined\n })\n }\n } else if (now && now.element === element && now.part === part) {\n now.leaving = false\n } else {\n if (now) {\n now.leaving = false\n now.detach()\n }\n held.current = { element, part, detach: part.attach(element), leaving: false }\n }\n if (typeof ref === \"function\") ref(element)\n else if (ref) (ref as { current: HTMLElement | null }).current = element\n },\n [part, ref]\n )\n const props = { ...toReact(mergeProps(caller, own)), ref: attach }\n if (typeof render === \"function\") return render(props, state as State)\n if (isValidElement(render)) {\n return cloneElement(render, { ...toReact(mergeProps(render.props, props)), ref: attach })\n }\n return createElement(tag, props)\n}\n\n/**\n * A text input whose text is the core's own (a combobox's, a number field's): its `value` is\n * given to React as the input's default. To React a `value` with no `onChange` is an input\n * that cannot be typed in; the core writes the text itself, as it changes.\n */\nexport function useOwnText(part: Part): Part {\n return useMemo(\n () => ({\n props: computed(() => {\n const { value, ...rest } = part.props.get()\n return { ...rest, defaultValue: value }\n }),\n attach: (element) => part.attach(element),\n }),\n [part]\n )\n}\n\nconst PortalContainer = createContext<HTMLElement | null | undefined>(undefined)\n\nexport interface PortalProviderProps {\n /** Where the popups inside are drawn; the end of `<body>` while it is not given. */\n container?: HTMLElement | null | undefined\n children?: ReactNode\n}\n\n/**\n * Says where every popup inside it is drawn, the popups those open included: an element of\n * the page (a shadow root's host, a full-screen element, a frame) in place of `<body>`.\n */\nexport function PortalProvider({ container, children }: PortalProviderProps): ReactElement {\n return <PortalContainer.Provider value={container}>{children}</PortalContainer.Provider>\n}\n\n/** Its children in a container at the end of the page, once the page has hydrated. */\nexport function Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const container = useContext(PortalContainer)\n const [ready, setReady] = useState(false)\n useIsomorphicLayoutEffect(() => setReady(true), [])\n if (!ready) return null\n return createPortal(<div data-kirana-portal=\"\">{children}</div>, container ?? document.body)\n}\n"],"mappings":";;;;;;AAqBA,MAAa,4BACX,OAAO,aAAa,cAAc,YAAY;;AAGhD,SAAgB,UAAa,QAA8B;CACzD,MAAM,YAAY,aAAa,aAAyB,OAAO,UAAU,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC5F,MAAM,OAAO,kBAAkB,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC;CACtD,OAAO,qBAAqB,WAAW,MAAM,IAAI;AACnD;;;;;;AAOA,SAAgB,cACd,QACA,OACG;CACH,MAAM,YAAY,MAAM;CACxB,MAAM,OAAO;EAAE,GAAG;EAAO,IAAI,MAAM,MAAM;CAAU;CACnD,MAAM,SAAS,OAAO,IAAI;CAC1B,OAAO,UAAU;CACjB,MAAM,CAAC,SAAS,eAAe;EAE7B,MAAM,SAAS,CAAC;EAChB,KAAK,MAAM,OAAO,MAChB,OAAO,OACL,OAAO,KAAK,SAAS,cAChB,GAAG,SACD,OAAO,QAAQ,IAAI,GAAqD,GAAG,IAAI,IAClF,KAAK;EAEb,MAAM,SAAoB,OAAO,QAAa,SAAoC;EAClF,OAAO;GAAE;GAAQ,YAAY,OAAO,MAAM;EAAE;CAC9C,CAAC;CACD,gCAAgC;EAC9B,MAAM,SAAS,EAAE,GAAG,MAAM,OAAO,KAAK,EAAE;EACxC,KAAK,MAAM,OAAO,MAChB,IAAI,OAAO,KAAK,SAAS,YAAY,OAAO,OAAO,KAAK;EAE1D,MAAM,OAAO,IAAI,MAAW;CAC9B,CAAC;CACD,SAAS,MAAM,UAAU;CACzB,OAAO,MAAM;AACf;;;;;;;AAQA,SAAgB,SAAS,SAAwC;CAC/D,MAAM,CAAC,SAAS,gBAAgB;EAC9B,IAAI;EACJ,SAAS,KAA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S,YAAY,KAAK,OAAO,OAAO;CAC1C,IACA,CAAC,IAAI,CACP;AACF;AAEA,MAAM,kBAAkB,cAA8C,KAAA,CAAS;;;;;AAY/E,SAAgB,eAAe,EAAE,WAAW,YAA+C;CACzF,OAAO,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAAY;CAAmC,CAAA;AACzF;;AAGA,SAAgB,OAAO,EAAE,YAA2D;CAClF,MAAM,YAAY,WAAW,eAAe;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,gCAAgC,SAAS,IAAI,GAAG,CAAC,CAAC;CAClD,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,aAAa,oBAAC,OAAD;EAAK,sBAAmB;EAAI;CAAc,CAAA,GAAG,aAAa,SAAS,IAAI;AAC7F"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { Orientation } from "@kirana-ui/core";
|
|
3
|
+
import { ReactElement } from "react";
|
|
4
|
+
declare function Root(props: PartComponentProps): ReactElement;
|
|
5
|
+
declare const Viewport: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
6
|
+
declare const Content: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export interface ScrollbarProps extends PartComponentProps {
|
|
8
|
+
/** Which way it scrolls. Default: `vertical`. */
|
|
9
|
+
orientation?: Orientation;
|
|
10
|
+
/** In the page even while there is nothing to scroll its way. */
|
|
11
|
+
keepMounted?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare function Scrollbar({ orientation, keepMounted, ...props }: ScrollbarProps): import("react").JSX.Element | null;
|
|
14
|
+
declare function Thumb(props: PartComponentProps): ReactElement;
|
|
15
|
+
declare function Corner(props: PartComponentProps): ReactElement | null;
|
|
16
|
+
export declare const ScrollArea: {
|
|
17
|
+
Root: typeof Root;
|
|
18
|
+
Viewport: typeof Viewport;
|
|
19
|
+
Content: typeof Content;
|
|
20
|
+
Scrollbar: typeof Scrollbar;
|
|
21
|
+
Thumb: typeof Thumb;
|
|
22
|
+
Corner: typeof Corner;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=scroll-area.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { useController, usePart, useSignal } from "./runtime.js";
|
|
3
|
+
import { within } from "@kirana-ui/core";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { createScrollArea } from "@kirana-ui/core/scroll-area";
|
|
7
|
+
// src/scroll-area.tsx
|
|
8
|
+
const Context = createContext(null);
|
|
9
|
+
const ScrollbarContext = createContext(null);
|
|
10
|
+
function useScrollArea(part) {
|
|
11
|
+
const controller = useContext(Context);
|
|
12
|
+
if (!controller) throw new Error(`<ScrollArea.${part}> must be inside <ScrollArea.Root>`);
|
|
13
|
+
return controller;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
17
|
+
const controller = useController(within(createScrollArea, { direction }), {});
|
|
18
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
19
|
+
value: controller,
|
|
20
|
+
children: usePart(controller.root, "div", props)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const PartElement = ({ part, tag, ...props }) => usePart(part, tag, props);
|
|
24
|
+
const Viewport = (props) => usePart(useScrollArea("Viewport").viewport, "div", props);
|
|
25
|
+
const Content = (props) => usePart(useScrollArea("Content").content, "div", props);
|
|
26
|
+
function Scrollbar({ orientation = "vertical", keepMounted, ...props }) {
|
|
27
|
+
const bar = useScrollArea("Scrollbar").scrollbar(orientation);
|
|
28
|
+
if (!useSignal(bar.shown) && !keepMounted) return null;
|
|
29
|
+
return /* @__PURE__ */ jsx(ScrollbarContext.Provider, {
|
|
30
|
+
value: bar,
|
|
31
|
+
children: /* @__PURE__ */ jsx(PartElement, {
|
|
32
|
+
part: bar.part,
|
|
33
|
+
tag: "div",
|
|
34
|
+
...props
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function Thumb(props) {
|
|
39
|
+
const bar = useContext(ScrollbarContext);
|
|
40
|
+
if (!bar) throw new Error("<ScrollArea.Thumb> must be inside <ScrollArea.Scrollbar>");
|
|
41
|
+
return usePart(bar.thumb, "div", props);
|
|
42
|
+
}
|
|
43
|
+
function Corner(props) {
|
|
44
|
+
const { corner } = useScrollArea("Corner");
|
|
45
|
+
return useSignal(corner.shown) ? /* @__PURE__ */ jsx(PartElement, {
|
|
46
|
+
part: corner.part,
|
|
47
|
+
tag: "div",
|
|
48
|
+
...props
|
|
49
|
+
}) : null;
|
|
50
|
+
}
|
|
51
|
+
const ScrollArea = {
|
|
52
|
+
Root,
|
|
53
|
+
Viewport,
|
|
54
|
+
Content,
|
|
55
|
+
Scrollbar,
|
|
56
|
+
Thumb,
|
|
57
|
+
Corner
|
|
58
|
+
};
|
|
59
|
+
export { ScrollArea };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=scroll-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-area.js","names":[],"sources":["../../../../packages/react/src/scroll-area.tsx"],"sourcesContent":["import type { Orientation, Part } from \"@kirana-ui/core\"\nimport { within } from \"@kirana-ui/core\"\nimport { createScrollArea } from \"@kirana-ui/core/scroll-area\"\nimport type { ScrollArea as Controller, ScrollAreaScrollbar } from \"@kirana-ui/core/scroll-area\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\nconst ScrollbarContext = createContext<ScrollAreaScrollbar | null>(null)\n\nfunction useScrollArea(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<ScrollArea.${part}> must be inside <ScrollArea.Root>`)\n return controller\n}\n\nfunction Root(props: PartComponentProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController(within(createScrollArea, { direction }), {})\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", props)}</Context.Provider>\n )\n}\n\nconst PartElement = ({ part, tag, ...props }: PartComponentProps & { part: Part; tag: string }) =>\n usePart(part, tag, props)\n\nconst Viewport = (props: PartComponentProps) =>\n usePart(useScrollArea(\"Viewport\").viewport, \"div\", props)\nconst Content = (props: PartComponentProps) =>\n usePart(useScrollArea(\"Content\").content, \"div\", props)\n\nexport interface ScrollbarProps extends PartComponentProps {\n /** Which way it scrolls. Default: `vertical`. */\n orientation?: Orientation\n /** In the page even while there is nothing to scroll its way. */\n keepMounted?: boolean\n}\n\nfunction Scrollbar({ orientation = \"vertical\", keepMounted, ...props }: ScrollbarProps) {\n const bar = useScrollArea(\"Scrollbar\").scrollbar(orientation)\n const shown = useSignal(bar.shown)\n if (!shown && !keepMounted) return null\n return (\n <ScrollbarContext.Provider value={bar}>\n <PartElement part={bar.part} tag=\"div\" {...props} />\n </ScrollbarContext.Provider>\n )\n}\n\nfunction Thumb(props: PartComponentProps): ReactElement {\n const bar = useContext(ScrollbarContext)\n if (!bar) throw new Error(\"<ScrollArea.Thumb> must be inside <ScrollArea.Scrollbar>\")\n return usePart(bar.thumb, \"div\", props)\n}\n\nfunction Corner(props: PartComponentProps): ReactElement | null {\n const { corner } = useScrollArea(\"Corner\")\n const shown = useSignal(corner.shown)\n return shown ? <PartElement part={corner.part} tag=\"div\" {...props} /> : null\n}\n\nexport const ScrollArea = { Root, Viewport, Content, Scrollbar, Thumb, Corner }\n"],"mappings":";;;;;;;AAWA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,mBAAmB,cAA0C,IAAI;AAEvE,SAAS,cAAc,MAA0B;CAC/C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C3E;AAEA,MAAa,aAAa;CAAE;CAAM;CAAU;CAAS;CAAW;CAAO;AAAO"}
|
package/src/select.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { PositionOptions } from "@kirana-ui/core";
|
|
3
|
+
import { ReactElement, ReactNode } from "react";
|
|
4
|
+
import { SelectProps } from "@kirana-ui/core/select";
|
|
5
|
+
export type RootProps<Value> = Omit<SelectProps<Value>, "id"> & {
|
|
6
|
+
id?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
declare function Root<Value>({ children, ...props }: RootProps<Value>): ReactElement;
|
|
10
|
+
declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
11
|
+
export interface ValueProps extends PartComponentProps {
|
|
12
|
+
/** Shown while nothing is chosen. */
|
|
13
|
+
placeholder?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare function Value({ placeholder, children, ...props }: ValueProps): ReactElement;
|
|
16
|
+
declare function Portal({ children }: {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}): ReactElement | null;
|
|
19
|
+
export type PositionerProps = PartComponentProps & Partial<PositionOptions> & {
|
|
20
|
+
/**
|
|
21
|
+
* The list opens over its trigger, the chosen item's text on the trigger's own, where
|
|
22
|
+
* there is room and unless a finger opened it.
|
|
23
|
+
*/
|
|
24
|
+
alignItemWithTrigger?: boolean;
|
|
25
|
+
};
|
|
26
|
+
declare function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, alignItemWithTrigger, ...props }: PositionerProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
27
|
+
declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
28
|
+
/** Items that belong together, named by their `<Select.GroupLabel>`. */
|
|
29
|
+
declare function Group({ id, ...props }: PartComponentProps & {
|
|
30
|
+
id?: string;
|
|
31
|
+
}): ReactElement;
|
|
32
|
+
/** A group's name. Outside a group it is plain text, and names nothing. */
|
|
33
|
+
declare function GroupLabel(props: PartComponentProps): ReactElement;
|
|
34
|
+
/** A line between groups. */
|
|
35
|
+
declare const Separator: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
36
|
+
/** The items' own box inside the popup, when the popup also holds scroll arrows. */
|
|
37
|
+
declare const List: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
38
|
+
/** In the page while there is more of the list above: it scrolls it while the pointer moves over it. */
|
|
39
|
+
declare function ScrollUpArrow(props: PartComponentProps): ReactElement;
|
|
40
|
+
/** In the page while there is more of the list below. */
|
|
41
|
+
declare function ScrollDownArrow(props: PartComponentProps): ReactElement;
|
|
42
|
+
export interface ItemProps extends PartComponentProps {
|
|
43
|
+
value: unknown;
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
/** What typeahead matches and the trigger shows; the item's text when left out. */
|
|
46
|
+
label?: string;
|
|
47
|
+
/** Its place among all the rows, in a virtualized list. */
|
|
48
|
+
index?: number;
|
|
49
|
+
}
|
|
50
|
+
declare function Item({ value, disabled, label, index, ...props }: ItemProps): ReactElement;
|
|
51
|
+
declare function ItemText(props: PartComponentProps): ReactElement;
|
|
52
|
+
export interface ItemIndicatorProps extends PartComponentProps {
|
|
53
|
+
keepMounted?: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare function ItemIndicator({ keepMounted, render: _render, ref: _ref, ...rest }: ItemIndicatorProps): import("react").JSX.Element | null;
|
|
56
|
+
export declare const Select: {
|
|
57
|
+
Root: typeof Root;
|
|
58
|
+
Trigger: typeof Trigger;
|
|
59
|
+
Value: typeof Value;
|
|
60
|
+
Portal: typeof Portal;
|
|
61
|
+
Positioner: typeof Positioner;
|
|
62
|
+
Popup: typeof Popup;
|
|
63
|
+
List: typeof List;
|
|
64
|
+
ScrollUpArrow: typeof ScrollUpArrow;
|
|
65
|
+
ScrollDownArrow: typeof ScrollDownArrow;
|
|
66
|
+
Group: typeof Group;
|
|
67
|
+
GroupLabel: typeof GroupLabel;
|
|
68
|
+
Separator: typeof Separator;
|
|
69
|
+
Item: typeof Item;
|
|
70
|
+
ItemText: typeof ItemText;
|
|
71
|
+
ItemIndicator: typeof ItemIndicator;
|
|
72
|
+
};
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=select.d.ts.map
|