@kirana-ui/react 0.1.1 → 0.2.0
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/llms.txt +1601 -223
- package/package.json +14 -2
- package/skills/kirana-ui-primitives/SKILL.md +142 -0
- package/src/accordion.d.ts +26 -15
- package/src/accordion.js +11 -10
- package/src/accordion.js.map +1 -1
- package/src/agent.d.ts +1 -0
- package/src/agent.js +1 -0
- package/src/alert-dialog.d.ts +3 -2
- package/src/autocomplete.d.ts +3 -2
- package/src/autosize.d.ts +5 -2
- package/src/autosize.js +2 -2
- package/src/autosize.js.map +1 -1
- package/src/avatar.d.ts +12 -8
- package/src/avatar.js +18 -9
- package/src/avatar.js.map +1 -1
- package/src/button.d.ts +4 -2
- package/src/button.js +3 -3
- package/src/button.js.map +1 -1
- package/src/calendar.d.ts +49 -28
- package/src/calendar.js +7 -3
- package/src/calendar.js.map +1 -1
- package/src/carousel.d.ts +25 -15
- package/src/carousel.js +3 -3
- package/src/carousel.js.map +1 -1
- package/src/checkbox.d.ts +10 -7
- package/src/checkbox.js +18 -12
- package/src/checkbox.js.map +1 -1
- package/src/collapsible.d.ts +12 -8
- package/src/collapsible.js +8 -7
- package/src/collapsible.js.map +1 -1
- package/src/combobox.d.ts +88 -60
- package/src/combobox.js +44 -31
- package/src/combobox.js.map +1 -1
- package/src/command.d.ts +30 -21
- package/src/command.js +14 -7
- package/src/command.js.map +1 -1
- package/src/context-menu.d.ts +3 -2
- package/src/date-field.d.ts +25 -13
- package/src/date-field.js +7 -3
- package/src/date-field.js.map +1 -1
- package/src/date-picker.d.ts +31 -40
- package/src/date-picker.js +3 -3
- package/src/date-picker.js.map +1 -1
- package/src/dialog.d.ts +45 -35
- package/src/dialog.js +12 -8
- package/src/dialog.js.map +1 -1
- package/src/direction.d.ts +1 -0
- package/src/direction.js.map +1 -1
- package/src/drawer.d.ts +3 -2
- package/src/element.d.ts +12 -0
- package/src/element.js +20 -0
- package/src/element.js.map +1 -0
- package/src/field.d.ts +24 -16
- package/src/field.js +9 -7
- package/src/field.js.map +1 -1
- package/src/fieldset.d.ts +10 -5
- package/src/fieldset.js +4 -5
- package/src/fieldset.js.map +1 -1
- package/src/form.d.ts +5 -2
- package/src/form.js +6 -6
- package/src/form.js.map +1 -1
- package/src/hover-card.d.ts +16 -10
- package/src/hover-card.js +1 -1
- package/src/hover-card.js.map +1 -1
- package/src/hover-popup.d.ts +24 -14
- package/src/hover-popup.js +5 -13
- package/src/hover-popup.js.map +1 -1
- package/src/index.d.ts +13 -3
- package/src/input.d.ts +4 -2
- package/src/input.js +3 -3
- package/src/input.js.map +1 -1
- package/src/label.d.ts +4 -1
- package/src/label.js +3 -3
- package/src/label.js.map +1 -1
- package/src/listbox.d.ts +23 -15
- package/src/listbox.js +4 -5
- package/src/listbox.js.map +1 -1
- package/src/menu.d.ts +83 -65
- package/src/menu.js +10 -18
- package/src/menu.js.map +1 -1
- package/src/menubar.d.ts +5 -3
- package/src/menubar.js +3 -3
- package/src/menubar.js.map +1 -1
- package/src/message-scroller.d.ts +15 -9
- package/src/message-scroller.js +3 -3
- package/src/message-scroller.js.map +1 -1
- package/src/meter.d.ts +18 -9
- package/src/meter.js +1 -1
- package/src/meter.js.map +1 -1
- package/src/navigation-menu.d.ts +50 -40
- package/src/navigation-menu.js +15 -24
- package/src/navigation-menu.js.map +1 -1
- package/src/number-field.d.ts +19 -12
- package/src/number-field.js +6 -10
- package/src/number-field.js.map +1 -1
- package/src/otp.d.ts +24 -15
- package/src/otp.js +7 -13
- package/src/otp.js.map +1 -1
- package/src/pagination.d.ts +26 -16
- package/src/pagination.js +3 -3
- package/src/pagination.js.map +1 -1
- package/src/popover.d.ts +30 -21
- package/src/popover.js +9 -13
- package/src/popover.js.map +1 -1
- package/src/progress.d.ts +18 -9
- package/src/progress.js +1 -1
- package/src/progress.js.map +1 -1
- package/src/qr-code.d.ts +12 -7
- package/src/qr-code.js +3 -3
- package/src/qr-code.js.map +1 -1
- package/src/radio-group.d.ts +17 -11
- package/src/radio-group.js +16 -19
- package/src/radio-group.js.map +1 -1
- package/src/resizable.d.ts +13 -8
- package/src/resizable.js +3 -3
- package/src/resizable.js.map +1 -1
- package/src/runtime.d.ts +89 -15
- package/src/runtime.js +112 -19
- package/src/runtime.js.map +1 -1
- package/src/scroll-area.d.ts +26 -15
- package/src/scroll-area.js +9 -6
- package/src/scroll-area.js.map +1 -1
- package/src/select.d.ts +65 -45
- package/src/select.js +40 -35
- package/src/select.js.map +1 -1
- package/src/separator.d.ts +4 -2
- package/src/separator.js +3 -3
- package/src/separator.js.map +1 -1
- package/src/slider.d.ts +35 -20
- package/src/slider.js +17 -18
- package/src/slider.js.map +1 -1
- package/src/switch.d.ts +10 -6
- package/src/switch.js +11 -9
- package/src/switch.js.map +1 -1
- package/src/tabs.d.ts +22 -14
- package/src/tabs.js +5 -6
- package/src/tabs.js.map +1 -1
- package/src/testing.d.ts +1 -0
- package/src/testing.js +1 -0
- package/src/toast.d.ts +59 -23
- package/src/toast.js +59 -13
- package/src/toast.js.map +1 -1
- package/src/toggle-group.d.ts +5 -2
- package/src/toggle-group.js +3 -3
- package/src/toggle-group.js.map +1 -1
- package/src/toggle.d.ts +4 -2
- package/src/toggle.js +3 -3
- package/src/toggle.js.map +1 -1
- package/src/toolbar.d.ts +26 -11
- package/src/toolbar.js +23 -13
- package/src/toolbar.js.map +1 -1
- package/src/tooltip.d.ts +16 -10
- package/src/tooltip.js +1 -1
- package/src/tooltip.js.map +1 -1
- package/src/use-render.d.ts +38 -0
- package/src/use-render.js +50 -0
- package/src/use-render.js.map +1 -0
- package/src/value-bar.d.ts +19 -11
- package/src/value-bar.js +8 -5
- package/src/value-bar.js.map +1 -1
package/src/tabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","names":[],"sources":["../../../../packages/react/src/tabs.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type {
|
|
1
|
+
{"version":3,"file":"tabs.js","names":[],"sources":["../../../../packages/react/src/tabs.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createTabs } from \"@kirana-ui/core/tabs\"\nimport type { Tabs as Controller, TabsListOptions, TabsProps } from \"@kirana-ui/core/tabs\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { createContext, useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport {\n PartElement,\n parts,\n useController,\n useMount,\n useOptions,\n usePart,\n useSignal,\n} from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\ntype Parts = Vocabulary[\"tabs\"]\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useTabs(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Tabs.${part}> must be inside <Tabs.Root>`)\n return controller\n}\n\n/** `Value` is what tells a tab from the others: the type of `value`. */\nexport type RootProps<Value = unknown> = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n Omit<TabsProps<Value>, \"id\"> & { id?: string }\n>\n\nfunction Root<Value = unknown>({\n value,\n defaultValue,\n onValueChange,\n orientation,\n id,\n ...rest\n}: RootProps<Value>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const create = within(createTabs<Value>, { direction })\n const controller: Controller = useController(create, {\n value,\n defaultValue,\n onValueChange,\n orientation,\n id,\n })\n return (\n <Context.Provider value={controller}>\n <PartElement of={controller.root} tag=\"div\" {...rest} />\n </Context.Provider>\n )\n}\n\nexport type ListProps = PartComponentProps<\"div\", StateOf<Parts[\"list\"]>, TabsListOptions>\n\nfunction List({ activateOnFocus, loop, ...props }: ListProps): ReactElement {\n const controller = useTabs(\"List\")\n // Read when a key is pressed, so written while rendering: nothing re-renders for it.\n controller.listOptions.set(defined({ activateOnFocus, loop }))\n return usePart(controller.list, \"div\", props)\n}\n\nexport type TabProps = PartComponentProps<\n \"button\",\n StateOf<Parts[\"tab\"]>,\n {\n /** What the tabs' value is while this tab is the active one. */\n value: unknown\n /** Disables this tab: it cannot be chosen. */\n disabled?: boolean\n }\n>\n\nfunction Tab({ value, disabled, ...props }: TabProps): ReactElement {\n const controller = useTabs(\"Tab\")\n const options = useOptions({ disabled })\n const part = useMemo(\n () => controller.tab(value, () => defined(options.get())),\n [controller, value, options]\n )\n return usePart(part, \"button\", props)\n}\n\nexport type IndicatorProps = PartComponentProps<\"span\", StateOf<Parts[\"indicator\"]>>\n\nconst Indicator = (props: IndicatorProps) => usePart(useTabs(\"Indicator\").indicator, \"span\", props)\n\nexport type PanelProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"panel\"]>,\n {\n /** The value of the tab this is the panel of. */\n value: unknown\n /** Keeps the panel in the page, `hidden`, while its tab is not the active one. */\n keepMounted?: boolean\n }\n>\n\nfunction Panel({ value, keepMounted, ...props }: PanelProps): ReactElement | null {\n const controller = useTabs(\"Panel\")\n const panel = useMemo(() => controller.panel(value), [controller, value])\n useMount(panel)\n const mounted = useSignal(panel.mounted)\n if (!mounted && !keepMounted) return null\n return <PartElement of={panel.part} tag=\"div\" {...props} />\n}\n\nexport const Tabs = /* @__PURE__ */ parts(\"Tabs\", { Root, List, Tab, Indicator, Panel })\n"],"mappings":";;;;;;;AAsBA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,QAAQ,MAA0B;CACzC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CAC5E,OAAO;AACT;AASA,SAAS,KAAsB,EAC7B,OACA,cACA,eACA,aACA,IACA,GAAG,QAC8B;CACjC,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,SAAS,OAAO,YAAmB,EAAE,UAAU,CAAC;CACtD,MAAM,aAAyB,cAAc,QAAQ;EACnD;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACvB,UAAA,oBAAC,aAAD;GAAa,IAAI,WAAW;GAAM,KAAI;GAAM,GAAI;EAAO,CAAA;CACvC,CAAA;AAEtB;AAIA,SAAS,KAAK,EAAE,iBAAiB,MAAM,GAAG,SAAkC;CAC1E,MAAM,aAAa,QAAQ,MAAM;CAEjC,WAAW,YAAY,IAAI,QAAQ;EAAE;EAAiB;CAAK,CAAC,CAAC;CAC7D,OAAO,QAAQ,WAAW,MAAM,OAAO,KAAK;AAC9C;AAaA,SAAS,IAAI,EAAE,OAAO,UAAU,GAAG,SAAiC;CAClE,MAAM,aAAa,QAAQ,KAAK;CAChC,MAAM,UAAU,WAAW,EAAE,SAAS,CAAC;CACvC,MAAM,OAAO,cACL,WAAW,IAAI,aAAa,QAAQ,QAAQ,IAAI,CAAC,CAAC,GACxD;EAAC;EAAY;EAAO;CAAO,CAC7B;CACA,OAAO,QAAQ,MAAM,UAAU,KAAK;AACtC;AAIA,MAAM,aAAa,UAA0B,QAAQ,QAAQ,WAAW,CAAC,CAAC,WAAW,QAAQ,KAAK;AAalG,SAAS,MAAM,EAAE,OAAO,aAAa,GAAG,SAA0C;CAChF,MAAM,aAAa,QAAQ,OAAO;CAClC,MAAM,QAAQ,cAAc,WAAW,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC;CACxE,SAAS,KAAK;CAEd,IAAI,CADY,UAAU,MAAM,OACrB,KAAK,CAAC,aAAa,OAAO;CACrC,OAAO,oBAAC,aAAD;EAAa,IAAI,MAAM;EAAM,KAAI;EAAM,GAAI;CAAQ,CAAA;AAC5D;AAEA,MAAa,OAAuB,sBAAM,QAAQ;CAAE;CAAM;CAAM;CAAK;CAAW;AAAM,CAAC"}
|
package/src/testing.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kirana-ui/core/testing";
|
package/src/testing.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kirana-ui/core/testing";
|
package/src/toast.d.ts
CHANGED
|
@@ -1,32 +1,68 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement, ReactNode } from "react";
|
|
3
|
-
import
|
|
4
|
-
|
|
4
|
+
import * as Core from "@kirana-ui/core/toast";
|
|
5
|
+
import { ToasterOptions } from "@kirana-ui/core/toast";
|
|
6
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
7
|
+
/** What a toast's title, description and action's label may be here: anything React draws. */
|
|
8
|
+
export type ToastContent = ReactNode;
|
|
9
|
+
export type ToastActionOptions<Content = ReactNode> = Core.ToastActionOptions<Content>;
|
|
10
|
+
export type ToastOptions<Content = ReactNode> = Core.ToastOptions<Content>;
|
|
11
|
+
export type ToastRecord<Content = ReactNode> = Core.ToastRecord<Content>;
|
|
12
|
+
export type ToastState<Content = ReactNode> = Core.ToastState<Content>;
|
|
13
|
+
export type Toaster<Content = ReactNode> = Core.Toaster<Content>;
|
|
14
|
+
/**
|
|
15
|
+
* The toasts of a page, made once, in a module: `toaster.add({ title })` from anywhere. A
|
|
16
|
+
* title, a description and an action's label are anything React draws, unless `Content` says
|
|
17
|
+
* otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createToaster: <Content = ReactNode>(options?: Core.ToasterOptions) => Toaster<Content>;
|
|
20
|
+
type Parts = Vocabulary["toast"];
|
|
21
|
+
type ToastProps = Core.ToastProps<ReactNode>;
|
|
22
|
+
export type ViewportProps = PartComponentProps<"div", StateOf<Parts["viewport"]>, Omit<ToastProps, "id"> & {
|
|
5
23
|
id?: string;
|
|
6
|
-
}
|
|
24
|
+
}>;
|
|
7
25
|
/** Where a toaster's toasts are drawn. Always in the page: put it once, near the root. */
|
|
8
26
|
declare function Viewport({ toaster, label, hotkey, swipeDirection, id, ...rest }: ViewportProps): ReactElement;
|
|
27
|
+
export interface ListProps {
|
|
28
|
+
/** Draws one toast, once for each, the newest first: a `Toast.Root` given it as `toast`. */
|
|
29
|
+
children: (toast: ToastRecord) => ReactNode;
|
|
30
|
+
}
|
|
9
31
|
/** Draws its child once for each toast, the newest first. */
|
|
10
|
-
declare function List({ children }:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}): ReactElement;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
declare function List({ children }: ListProps): ReactElement;
|
|
33
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, {
|
|
34
|
+
/** The toast it draws: the one `Toast.List` gave its child. */
|
|
35
|
+
toast: ToastRecord;
|
|
36
|
+
}>;
|
|
37
|
+
declare function Root({ toast, ...props }: RootProps): ReactElement;
|
|
38
|
+
export type ContentProps = PartComponentProps<"div", StateOf<Parts["content"]>>;
|
|
39
|
+
export type TitleProps = PartComponentProps<"div", StateOf<Parts["title"]>>;
|
|
40
|
+
export type DescriptionProps = PartComponentProps<"div", StateOf<Parts["description"]>>;
|
|
41
|
+
export type CloseProps = PartComponentProps<"button", StateOf<Parts["close"]>>;
|
|
42
|
+
export type ActionProps = PartComponentProps<"button", StateOf<Parts["action"]>>;
|
|
43
|
+
declare const Content: (props: ContentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
44
|
+
/**
|
|
45
|
+
* The toast's title: the caller's children when it has any, what the toast was added with
|
|
46
|
+
* otherwise, and nothing in the page when there is neither.
|
|
47
|
+
*/
|
|
48
|
+
declare function Title(props: TitleProps): ReactElement | null;
|
|
49
|
+
/** The toast's description, unless it is given children of its own. */
|
|
50
|
+
declare function Description(props: DescriptionProps): ReactElement | null;
|
|
51
|
+
declare const Close: (props: CloseProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
52
|
+
/**
|
|
53
|
+
* The toast's action, its label unless it is given children of its own. A press tells the
|
|
54
|
+
* action (`onAction`), then closes the toast unless the action called `details.cancel()`.
|
|
55
|
+
*/
|
|
56
|
+
declare function Action(props: ActionProps): ReactElement | null;
|
|
21
57
|
export declare const Toast: {
|
|
22
|
-
Viewport: typeof Viewport;
|
|
23
|
-
List: typeof List;
|
|
24
|
-
Root: typeof Root;
|
|
25
|
-
Content: typeof Content;
|
|
26
|
-
Title: typeof Title;
|
|
27
|
-
Description: typeof Description;
|
|
28
|
-
Close: typeof Close;
|
|
29
|
-
Action: typeof Action;
|
|
58
|
+
readonly Viewport: typeof Viewport;
|
|
59
|
+
readonly List: typeof List;
|
|
60
|
+
readonly Root: typeof Root;
|
|
61
|
+
readonly Content: typeof Content;
|
|
62
|
+
readonly Title: typeof Title;
|
|
63
|
+
readonly Description: typeof Description;
|
|
64
|
+
readonly Close: typeof Close;
|
|
65
|
+
readonly Action: typeof Action;
|
|
30
66
|
};
|
|
31
|
-
export
|
|
67
|
+
export type { ToasterOptions };
|
|
32
68
|
//# sourceMappingURL=toast.d.ts.map
|
package/src/toast.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { useController, usePart, useSignal } from "./runtime.js";
|
|
1
|
+
import { parts, useController, usePart, useSignal } from "./runtime.js";
|
|
2
2
|
import { Fragment, createContext, useContext } from "react";
|
|
3
3
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
4
|
-
import { createToast, createToaster } from "@kirana-ui/core/toast";
|
|
4
|
+
import { createToast, createToaster as createToaster$1 } from "@kirana-ui/core/toast";
|
|
5
5
|
// src/toast.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The toasts of a page, made once, in a module: `toaster.add({ title })` from anywhere. A
|
|
8
|
+
* title, a description and an action's label are anything React draws, unless `Content` says
|
|
9
|
+
* otherwise.
|
|
10
|
+
*/
|
|
11
|
+
const createToaster = createToaster$1;
|
|
6
12
|
const Context = createContext(null);
|
|
7
13
|
const ToastContext = createContext(null);
|
|
8
14
|
function useToast(part) {
|
|
@@ -11,9 +17,9 @@ function useToast(part) {
|
|
|
11
17
|
return controller;
|
|
12
18
|
}
|
|
13
19
|
function useParts(part) {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
return
|
|
20
|
+
const made = useContext(ToastContext);
|
|
21
|
+
if (!made) throw new Error(`<Toast.${part}> must be inside <Toast.Root>`);
|
|
22
|
+
return made;
|
|
17
23
|
}
|
|
18
24
|
/** Where a toaster's toasts are drawn. Always in the page: put it once, near the root. */
|
|
19
25
|
function Viewport({ toaster, label, hotkey, swipeDirection, id, ...rest }) {
|
|
@@ -35,18 +41,58 @@ function List({ children }) {
|
|
|
35
41
|
return /* @__PURE__ */ jsx(Fragment$1, { children: toasts.map((toast) => /* @__PURE__ */ jsx(Fragment, { children: children(toast) }, toast.id)) });
|
|
36
42
|
}
|
|
37
43
|
function Root({ toast, ...props }) {
|
|
38
|
-
const
|
|
44
|
+
const made = useToast("Root").toast(toast.id);
|
|
39
45
|
return /* @__PURE__ */ jsx(ToastContext.Provider, {
|
|
40
|
-
value:
|
|
41
|
-
children: usePart(
|
|
46
|
+
value: made,
|
|
47
|
+
children: usePart(made.root, "div", props)
|
|
42
48
|
});
|
|
43
49
|
}
|
|
44
50
|
const Content = (props) => usePart(useParts("Content").content, "div", props);
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
/** A part that says something of the toast's, and what the toast was added with for it to say. */
|
|
52
|
+
function useSaid(name, part) {
|
|
53
|
+
const made = useParts(name);
|
|
54
|
+
const toast = useSignal(made.record);
|
|
55
|
+
return {
|
|
56
|
+
part: made[part],
|
|
57
|
+
said: part === "action" ? toast?.action?.label : toast?.[part]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const unlessSilent = (element, children, render) => children == null && !render ? null : element;
|
|
61
|
+
/**
|
|
62
|
+
* The toast's title: the caller's children when it has any, what the toast was added with
|
|
63
|
+
* otherwise, and nothing in the page when there is neither.
|
|
64
|
+
*/
|
|
65
|
+
function Title(props) {
|
|
66
|
+
const { part, said } = useSaid("Title", "title");
|
|
67
|
+
const children = props.children ?? said;
|
|
68
|
+
return unlessSilent(usePart(part, "div", {
|
|
69
|
+
...props,
|
|
70
|
+
children
|
|
71
|
+
}), children, props.render);
|
|
72
|
+
}
|
|
73
|
+
/** The toast's description, unless it is given children of its own. */
|
|
74
|
+
function Description(props) {
|
|
75
|
+
const { part, said } = useSaid("Description", "description");
|
|
76
|
+
const children = props.children ?? said;
|
|
77
|
+
return unlessSilent(usePart(part, "div", {
|
|
78
|
+
...props,
|
|
79
|
+
children
|
|
80
|
+
}), children, props.render);
|
|
81
|
+
}
|
|
47
82
|
const Close = (props) => usePart(useParts("Close").close, "button", props);
|
|
48
|
-
|
|
49
|
-
|
|
83
|
+
/**
|
|
84
|
+
* The toast's action, its label unless it is given children of its own. A press tells the
|
|
85
|
+
* action (`onAction`), then closes the toast unless the action called `details.cancel()`.
|
|
86
|
+
*/
|
|
87
|
+
function Action(props) {
|
|
88
|
+
const { part, said } = useSaid("Action", "action");
|
|
89
|
+
const children = props.children ?? said;
|
|
90
|
+
return unlessSilent(usePart(part, "button", {
|
|
91
|
+
...props,
|
|
92
|
+
children
|
|
93
|
+
}), children, props.render);
|
|
94
|
+
}
|
|
95
|
+
const Toast = /* @__PURE__ */ parts("Toast", {
|
|
50
96
|
Viewport,
|
|
51
97
|
List,
|
|
52
98
|
Root,
|
|
@@ -55,7 +101,7 @@ const Toast = {
|
|
|
55
101
|
Description,
|
|
56
102
|
Close,
|
|
57
103
|
Action
|
|
58
|
-
};
|
|
104
|
+
});
|
|
59
105
|
export { Toast, createToaster };
|
|
60
106
|
|
|
61
107
|
//# sourceMappingURL=toast.js.map
|
package/src/toast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toast.js","names":[],"sources":["../../../../packages/react/src/toast.tsx"],"sourcesContent":["import { createToast } from \"@kirana-ui/core/toast\"\nimport type
|
|
1
|
+
{"version":3,"file":"toast.js","names":["createCoreToaster"],"sources":["../../../../packages/react/src/toast.tsx"],"sourcesContent":["import type { Part, StateOf } from \"@kirana-ui/core\"\nimport { createToast, createToaster as createCoreToaster } from \"@kirana-ui/core/toast\"\nimport type * as Core from \"@kirana-ui/core/toast\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { Fragment, createContext, useContext } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { parts, useController, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\n/** What a toast's title, description and action's label may be here: anything React draws. */\nexport type ToastContent = ReactNode\nexport type ToastActionOptions<Content = ReactNode> = Core.ToastActionOptions<Content>\nexport type ToastOptions<Content = ReactNode> = Core.ToastOptions<Content>\nexport type ToastRecord<Content = ReactNode> = Core.ToastRecord<Content>\nexport type ToastState<Content = ReactNode> = Core.ToastState<Content>\nexport type Toaster<Content = ReactNode> = Core.Toaster<Content>\nexport type { ToasterOptions } from \"@kirana-ui/core/toast\"\n\n/**\n * The toasts of a page, made once, in a module: `toaster.add({ title })` from anywhere. A\n * title, a description and an action's label are anything React draws, unless `Content` says\n * otherwise.\n */\nexport const createToaster: <Content = ReactNode>(\n options?: Core.ToasterOptions\n) => Toaster<Content> = createCoreToaster\n\ntype Parts = Vocabulary[\"toast\"]\n\ntype Controller = Core.Toast<ReactNode>\ntype ToastParts = Core.ToastParts<ReactNode>\ntype ToastProps = Core.ToastProps<ReactNode>\n\nconst Context = createContext<Controller | null>(null)\nconst ToastContext = createContext<ToastParts | null>(null)\n\nfunction useToast(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Toast.${part}> must be inside <Toast.Viewport>`)\n return controller\n}\n\nfunction useParts(part: string): ToastParts {\n const made = useContext(ToastContext)\n if (!made) throw new Error(`<Toast.${part}> must be inside <Toast.Root>`)\n return made\n}\n\nexport type ViewportProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"viewport\"]>,\n Omit<ToastProps, \"id\"> & { id?: string }\n>\n\n/** Where a toaster's toasts are drawn. Always in the page: put it once, near the root. */\nfunction Viewport({\n toaster,\n label,\n hotkey,\n swipeDirection,\n id,\n ...rest\n}: ViewportProps): ReactElement {\n const controller = useController<ToastProps, Controller>(createToast, {\n toaster,\n label,\n hotkey,\n swipeDirection,\n id,\n })\n return (\n <Context.Provider value={controller}>\n {usePart(controller.viewport, \"div\", rest)}\n </Context.Provider>\n )\n}\n\nexport interface ListProps {\n /** Draws one toast, once for each, the newest first: a `Toast.Root` given it as `toast`. */\n children: (toast: ToastRecord) => ReactNode\n}\n\n/** Draws its child once for each toast, the newest first. */\nfunction List({ children }: ListProps): ReactElement {\n const toasts = useSignal(useToast(\"List\").toasts)\n return (\n <>\n {toasts.map((toast) => (\n <Fragment key={toast.id}>{children(toast)}</Fragment>\n ))}\n </>\n )\n}\n\nexport type RootProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"root\"]>,\n {\n /** The toast it draws: the one `Toast.List` gave its child. */\n toast: ToastRecord\n }\n>\n\nfunction Root({ toast, ...props }: RootProps): ReactElement {\n const made = useToast(\"Root\").toast(toast.id)\n return (\n <ToastContext.Provider value={made}>{usePart(made.root, \"div\", props)}</ToastContext.Provider>\n )\n}\n\nexport type ContentProps = PartComponentProps<\"div\", StateOf<Parts[\"content\"]>>\nexport type TitleProps = PartComponentProps<\"div\", StateOf<Parts[\"title\"]>>\nexport type DescriptionProps = PartComponentProps<\"div\", StateOf<Parts[\"description\"]>>\nexport type CloseProps = PartComponentProps<\"button\", StateOf<Parts[\"close\"]>>\nexport type ActionProps = PartComponentProps<\"button\", StateOf<Parts[\"action\"]>>\n\nconst Content = (props: ContentProps) => usePart(useParts(\"Content\").content, \"div\", props)\n\n/** A part that says something of the toast's, and what the toast was added with for it to say. */\nfunction useSaid(\n name: string,\n part: \"title\" | \"description\" | \"action\"\n): { part: Part; said: ReactNode } {\n const made = useParts(name)\n const toast = useSignal(made.record)\n return { part: made[part], said: part === \"action\" ? toast?.action?.label : toast?.[part] }\n}\n\n// A `render` draws what it likes; without one, an element with nothing to say is not drawn.\nconst unlessSilent = (element: ReactElement, children: ReactNode, render: unknown) =>\n children == null && !render ? null : element\n\n/**\n * The toast's title: the caller's children when it has any, what the toast was added with\n * otherwise, and nothing in the page when there is neither.\n */\nfunction Title(props: TitleProps): ReactElement | null {\n const { part, said } = useSaid(\"Title\", \"title\")\n const children = props.children ?? said\n return unlessSilent(usePart(part, \"div\", { ...props, children }), children, props.render)\n}\n\n/** The toast's description, unless it is given children of its own. */\nfunction Description(props: DescriptionProps): ReactElement | null {\n const { part, said } = useSaid(\"Description\", \"description\")\n const children = props.children ?? said\n return unlessSilent(usePart(part, \"div\", { ...props, children }), children, props.render)\n}\n\nconst Close = (props: CloseProps) => usePart(useParts(\"Close\").close, \"button\", props)\n\n/**\n * The toast's action, its label unless it is given children of its own. A press tells the\n * action (`onAction`), then closes the toast unless the action called `details.cancel()`.\n */\nfunction Action(props: ActionProps): ReactElement | null {\n const { part, said } = useSaid(\"Action\", \"action\")\n const children = props.children ?? said\n return unlessSilent(usePart(part, \"button\", { ...props, children }), children, props.render)\n}\n\nexport const Toast = /* @__PURE__ */ parts(\"Toast\", {\n Viewport,\n List,\n Root,\n Content,\n Title,\n Description,\n Close,\n Action,\n})\n"],"mappings":";;;;;;;;;;AAwBA,MAAa,gBAEWA;AAQxB,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,eAAe,cAAiC,IAAI;AAE1D,SAAS,SAAS,MAA0B;CAC1C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,UAAU,KAAK,kCAAkC;CAClF,OAAO;AACT;AAEA,SAAS,SAAS,MAA0B;CAC1C,MAAM,OAAO,WAAW,YAAY;CACpC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,UAAU,KAAK,8BAA8B;CACxE,OAAO;AACT;;AASA,SAAS,SAAS,EAChB,SACA,OACA,QACA,gBACA,IACA,GAAG,QAC2B;CAC9B,MAAM,aAAa,cAAsC,aAAa;EACpE;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EACtB,UAAA,QAAQ,WAAW,UAAU,OAAO,IAAI;CACzB,CAAA;AAEtB;;AAQA,SAAS,KAAK,EAAE,YAAqC;CACnD,MAAM,SAAS,UAAU,SAAS,MAAM,CAAC,CAAC,MAAM;CAChD,OACE,oBAAA,YAAA,EAAA,UACG,OAAO,KAAK,UACX,oBAAC,UAAD,EAAA,UAA0B,SAAS,KAAK,EAAY,GAArC,MAAM,EAA+B,CACrD,EACD,CAAA;AAEN;AAWA,SAAS,KAAK,EAAE,OAAO,GAAG,SAAkC;CAC1D,MAAM,OAAO,SAAS,MAAM,CAAC,CAAC,MAAM,MAAM,EAAE;CAC5C,OACE,oBAAC,aAAa,UAAd;EAAuB,OAAO;EAAO,UAAA,QAAQ,KAAK,MAAM,OAAO,KAAK;CAAyB,CAAA;AAEjG;AAQA,MAAM,WAAW,UAAwB,QAAQ,SAAS,SAAS,CAAC,CAAC,SAAS,OAAO,KAAK;;AAG1F,SAAS,QACP,MACA,MACiC;CACjC,MAAM,OAAO,SAAS,IAAI;CAC1B,MAAM,QAAQ,UAAU,KAAK,MAAM;CACnC,OAAO;EAAE,MAAM,KAAK;EAAO,MAAM,SAAS,WAAW,OAAO,QAAQ,QAAQ,QAAQ;CAAM;AAC5F;AAGA,MAAM,gBAAgB,SAAuB,UAAqB,WAChE,YAAY,QAAQ,CAAC,SAAS,OAAO;;;;;AAMvC,SAAS,MAAM,OAAwC;CACrD,MAAM,EAAE,MAAM,SAAS,QAAQ,SAAS,OAAO;CAC/C,MAAM,WAAW,MAAM,YAAY;CACnC,OAAO,aAAa,QAAQ,MAAM,OAAO;EAAE,GAAG;EAAO;CAAS,CAAC,GAAG,UAAU,MAAM,MAAM;AAC1F;;AAGA,SAAS,YAAY,OAA8C;CACjE,MAAM,EAAE,MAAM,SAAS,QAAQ,eAAe,aAAa;CAC3D,MAAM,WAAW,MAAM,YAAY;CACnC,OAAO,aAAa,QAAQ,MAAM,OAAO;EAAE,GAAG;EAAO;CAAS,CAAC,GAAG,UAAU,MAAM,MAAM;AAC1F;AAEA,MAAM,SAAS,UAAsB,QAAQ,SAAS,OAAO,CAAC,CAAC,OAAO,UAAU,KAAK;;;;;AAMrF,SAAS,OAAO,OAAyC;CACvD,MAAM,EAAE,MAAM,SAAS,QAAQ,UAAU,QAAQ;CACjD,MAAM,WAAW,MAAM,YAAY;CACnC,OAAO,aAAa,QAAQ,MAAM,UAAU;EAAE,GAAG;EAAO;CAAS,CAAC,GAAG,UAAU,MAAM,MAAM;AAC7F;AAEA,MAAa,QAAwB,sBAAM,SAAS;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/toggle-group.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement } from "react";
|
|
3
4
|
import { ToggleGroupProps as ToggleGroupProps$1 } from "@kirana-ui/core/toggle-group";
|
|
4
|
-
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
/** `Value` is what tells a toggle from the others: the type of `value`'s entries. */
|
|
7
|
+
export type ToggleGroupProps<Value = unknown> = PartComponentProps<"div", StateOf<Vocabulary["toggleGroup"]["root"]>, ToggleGroupProps$1<Value>>;
|
|
5
8
|
/** Toggles that are one control. Each `<Toggle value>` inside it is one of its toggles. */
|
|
6
|
-
export declare
|
|
9
|
+
export declare const ToggleGroup: <Value = unknown>({ value, defaultValue, onValueChange, multiple, disabled, orientation, loop, ...rest }: ToggleGroupProps<Value>) => ReactElement;
|
|
7
10
|
//# sourceMappingURL=toggle-group.d.ts.map
|
package/src/toggle-group.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
|
-
import { useController, usePart } from "./runtime.js";
|
|
2
|
+
import { component, useController, usePart } from "./runtime.js";
|
|
3
3
|
import { ToggleGroupContext, ToolbarContext } from "./toolbar-context.js";
|
|
4
4
|
import { within } from "@kirana-ui/core";
|
|
5
5
|
import { useContext } from "react";
|
|
@@ -7,7 +7,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
7
7
|
import { createToggleGroup } from "@kirana-ui/core/toggle-group";
|
|
8
8
|
// src/toggle-group.tsx
|
|
9
9
|
/** Toggles that are one control. Each `<Toggle value>` inside it is one of its toggles. */
|
|
10
|
-
function ToggleGroup({ value, defaultValue, onValueChange, multiple, disabled, orientation, loop, ...rest }) {
|
|
10
|
+
const ToggleGroup = /* @__PURE__ */ component("ToggleGroup", function ToggleGroup({ value, defaultValue, onValueChange, multiple, disabled, orientation, loop, ...rest }) {
|
|
11
11
|
const direction = useContext(DirectionContext) ?? void 0;
|
|
12
12
|
const toolbar = useContext(ToolbarContext) ?? void 0;
|
|
13
13
|
const controller = useController(within(createToggleGroup, {
|
|
@@ -26,7 +26,7 @@ function ToggleGroup({ value, defaultValue, onValueChange, multiple, disabled, o
|
|
|
26
26
|
value: controller,
|
|
27
27
|
children: usePart(controller.root, "div", rest)
|
|
28
28
|
});
|
|
29
|
-
}
|
|
29
|
+
});
|
|
30
30
|
export { ToggleGroup };
|
|
31
31
|
|
|
32
32
|
//# sourceMappingURL=toggle-group.js.map
|
package/src/toggle-group.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.js","names":[],"sources":["../../../../packages/react/src/toggle-group.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport { createToggleGroup } from \"@kirana-ui/core/toggle-group\"\nimport type {\n ToggleGroup as Controller,\n ToggleGroupProps as CoreProps,\n} from \"@kirana-ui/core/toggle-group\"\nimport { useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\nimport { ToggleGroupContext, ToolbarContext } from \"./toolbar-context.ts\"\n\nexport type ToggleGroupProps<Value
|
|
1
|
+
{"version":3,"file":"toggle-group.js","names":[],"sources":["../../../../packages/react/src/toggle-group.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createToggleGroup } from \"@kirana-ui/core/toggle-group\"\nimport type {\n ToggleGroup as Controller,\n ToggleGroupProps as CoreProps,\n} from \"@kirana-ui/core/toggle-group\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { component, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\nimport { ToggleGroupContext, ToolbarContext } from \"./toolbar-context.ts\"\n\n/** `Value` is what tells a toggle from the others: the type of `value`'s entries. */\nexport type ToggleGroupProps<Value = unknown> = PartComponentProps<\n \"div\",\n StateOf<Vocabulary[\"toggleGroup\"][\"root\"]>,\n CoreProps<Value>\n>\n\n/** Toggles that are one control. Each `<Toggle value>` inside it is one of its toggles. */\nexport const ToggleGroup = /* @__PURE__ */ component(\"ToggleGroup\", function ToggleGroup<\n Value = unknown,\n>({ value, defaultValue, onValueChange, multiple, disabled, orientation, loop, ...rest }: ToggleGroupProps<Value>): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const toolbar = useContext(ToolbarContext) ?? undefined\n const controller: Controller = useController<CoreProps<Value>, Controller<Value>>(\n within(createToggleGroup<Value>, { direction, toolbar }),\n { value, defaultValue, onValueChange, multiple, disabled, orientation, loop }\n )\n return (\n <ToggleGroupContext.Provider value={controller}>\n {usePart(controller.root, \"div\", rest)}\n </ToggleGroupContext.Provider>\n )\n})\n"],"mappings":";;;;;;;;;AAwBA,MAAa,cAA8B,0BAAU,eAAe,SAAS,YAE3E,EAAE,OAAO,cAAc,eAAe,UAAU,UAAU,aAAa,MAAM,GAAG,QAA+C;CAC/H,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,UAAU,WAAW,cAAc,KAAK,KAAA;CAC9C,MAAM,aAAyB,cAC7B,OAAO,mBAA0B;EAAE;EAAW;CAAQ,CAAC,GACvD;EAAE;EAAO;EAAc;EAAe;EAAU;EAAU;EAAa;CAAK,CAC9E;CACA,OACE,oBAAC,mBAAmB,UAApB;EAA6B,OAAO;EACjC,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CACV,CAAA;AAEjC,CAAC"}
|
package/src/toggle.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement } from "react";
|
|
3
4
|
import { ToggleProps as ToggleProps$1 } from "@kirana-ui/core/toggle";
|
|
4
|
-
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
export type ToggleProps = PartComponentProps<"button", StateOf<Vocabulary["toggle"]["root"]>, ToggleProps$1>;
|
|
5
7
|
/** Inside a `<ToggleGroup>`, `value` makes it one of the group's toggles. */
|
|
6
|
-
export declare
|
|
8
|
+
export declare const Toggle: ({ pressed, defaultPressed, onPressedChange, disabled, value, ...rest }: ToggleProps) => ReactElement;
|
|
7
9
|
//# sourceMappingURL=toggle.d.ts.map
|
package/src/toggle.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useController, usePart } from "./runtime.js";
|
|
1
|
+
import { component, useController, usePart } from "./runtime.js";
|
|
2
2
|
import { ToggleGroupContext, ToolbarContext } from "./toolbar-context.js";
|
|
3
3
|
import { within } from "@kirana-ui/core";
|
|
4
4
|
import { useContext } from "react";
|
|
5
5
|
import { createToggle } from "@kirana-ui/core/toggle";
|
|
6
6
|
// src/toggle.tsx
|
|
7
7
|
/** Inside a `<ToggleGroup>`, `value` makes it one of the group's toggles. */
|
|
8
|
-
function Toggle({ pressed, defaultPressed, onPressedChange, disabled, value, ...rest }) {
|
|
8
|
+
const Toggle = /* @__PURE__ */ component("Toggle", function Toggle({ pressed, defaultPressed, onPressedChange, disabled, value, ...rest }) {
|
|
9
9
|
const group = useContext(ToggleGroupContext) ?? void 0;
|
|
10
10
|
const toolbar = useContext(ToolbarContext) ?? void 0;
|
|
11
11
|
const controller = useController(within(createToggle, {
|
|
@@ -19,7 +19,7 @@ function Toggle({ pressed, defaultPressed, onPressedChange, disabled, value, ...
|
|
|
19
19
|
value
|
|
20
20
|
});
|
|
21
21
|
return usePart(controller.root, "button", rest);
|
|
22
|
-
}
|
|
22
|
+
});
|
|
23
23
|
export { Toggle };
|
|
24
24
|
|
|
25
25
|
//# sourceMappingURL=toggle.js.map
|
package/src/toggle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.js","names":[],"sources":["../../../../packages/react/src/toggle.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport { createToggle } from \"@kirana-ui/core/toggle\"\nimport type { Toggle as Controller, ToggleProps as CoreProps } from \"@kirana-ui/core/toggle\"\nimport { useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\nimport { ToggleGroupContext, ToolbarContext } from \"./toolbar-context.ts\"\n\nexport type ToggleProps =
|
|
1
|
+
{"version":3,"file":"toggle.js","names":[],"sources":["../../../../packages/react/src/toggle.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport type { StateOf } from \"@kirana-ui/core\"\nimport { createToggle } from \"@kirana-ui/core/toggle\"\nimport type { Toggle as Controller, ToggleProps as CoreProps } from \"@kirana-ui/core/toggle\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { component, useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\nimport { ToggleGroupContext, ToolbarContext } from \"./toolbar-context.ts\"\n\nexport type ToggleProps = PartComponentProps<\n \"button\",\n StateOf<Vocabulary[\"toggle\"][\"root\"]>,\n CoreProps\n>\n\n/** Inside a `<ToggleGroup>`, `value` makes it one of the group's toggles. */\nexport const Toggle = /* @__PURE__ */ component(\n \"Toggle\",\n function Toggle({\n pressed,\n defaultPressed,\n onPressedChange,\n disabled,\n value,\n ...rest\n }: ToggleProps): ReactElement {\n const group = useContext(ToggleGroupContext) ?? undefined\n const toolbar = useContext(ToolbarContext) ?? undefined\n const controller = useController<CoreProps, Controller>(\n within(createToggle, { group, toolbar }),\n {\n pressed,\n defaultPressed,\n onPressedChange,\n disabled,\n value,\n }\n )\n return usePart(controller.root, \"button\", rest)\n }\n)\n"],"mappings":";;;;;;;AAmBA,MAAa,SAAyB,0BACpC,UACA,SAAS,OAAO,EACd,SACA,gBACA,iBACA,UACA,OACA,GAAG,QACyB;CAC5B,MAAM,QAAQ,WAAW,kBAAkB,KAAK,KAAA;CAChD,MAAM,UAAU,WAAW,cAAc,KAAK,KAAA;CAC9C,MAAM,aAAa,cACjB,OAAO,cAAc;EAAE;EAAO;CAAQ,CAAC,GACvC;EACE;EACA;EACA;EACA;EACA;CACF,CACF;CACA,OAAO,QAAQ,WAAW,MAAM,UAAU,IAAI;AAChD,CACF"}
|
package/src/toolbar.d.ts
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { StateOf } from "@kirana-ui/core";
|
|
2
3
|
import { ReactElement } from "react";
|
|
3
4
|
import { ToolbarProps } from "@kirana-ui/core/toolbar";
|
|
4
|
-
|
|
5
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
6
|
+
type Parts = Vocabulary["toolbar"];
|
|
7
|
+
export type RootProps = PartComponentProps<"div", StateOf<Parts["root"]>, ToolbarProps>;
|
|
5
8
|
declare function Root({ orientation, loop, disabled, ...rest }: RootProps): ReactElement;
|
|
6
|
-
|
|
9
|
+
/** What an item of the toolbar takes of its own. */
|
|
10
|
+
export interface ItemOptions {
|
|
11
|
+
/** Disables this control. */
|
|
7
12
|
disabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
}
|
|
14
|
+
export type ButtonProps = PartComponentProps<"button", StateOf<Parts["button"]>, ItemOptions>;
|
|
15
|
+
export type InputProps = PartComponentProps<"input", StateOf<Parts["input"]>, ItemOptions>;
|
|
16
|
+
export type GroupProps = PartComponentProps<"div", StateOf<Parts["group"]>, ItemOptions>;
|
|
17
|
+
/** @deprecated The item's own: `ButtonProps`, `InputProps` or `GroupProps`. */
|
|
18
|
+
export type ItemProps = PartComponentProps<"div", StateOf<Parts["group"]>, ItemOptions>;
|
|
19
|
+
declare function Button({ disabled, ...props }: ButtonProps): ReactElement;
|
|
20
|
+
declare function Input({ disabled, ...props }: InputProps): ReactElement;
|
|
21
|
+
declare function Group({ disabled, ...props }: GroupProps): ReactElement;
|
|
22
|
+
export type LinkProps = PartComponentProps<"a", StateOf<Parts["link"]>>;
|
|
23
|
+
declare function Link(props: LinkProps): ReactElement;
|
|
24
|
+
export type SeparatorProps = PartComponentProps<"div", StateOf<Parts["separator"]>>;
|
|
25
|
+
declare const Separator: (props: SeparatorProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
11
26
|
export declare const Toolbar: {
|
|
12
|
-
Root: typeof Root;
|
|
13
|
-
Button:
|
|
14
|
-
Link: typeof Link;
|
|
15
|
-
Input:
|
|
16
|
-
Group:
|
|
17
|
-
Separator: typeof Separator;
|
|
27
|
+
readonly Root: typeof Root;
|
|
28
|
+
readonly Button: typeof Button;
|
|
29
|
+
readonly Link: typeof Link;
|
|
30
|
+
readonly Input: typeof Input;
|
|
31
|
+
readonly Group: typeof Group;
|
|
32
|
+
readonly Separator: typeof Separator;
|
|
18
33
|
};
|
|
19
34
|
export {};
|
|
20
35
|
//# sourceMappingURL=toolbar.d.ts.map
|
package/src/toolbar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DirectionContext } from "./direction-context.js";
|
|
2
|
-
import { useController, useOptions, usePart } from "./runtime.js";
|
|
2
|
+
import { parts, useController, useOptions, usePart } from "./runtime.js";
|
|
3
3
|
import { ToggleGroupContext, ToolbarContext } from "./toolbar-context.js";
|
|
4
4
|
import { defined, within } from "@kirana-ui/core";
|
|
5
5
|
import { useContext, useMemo } from "react";
|
|
@@ -26,13 +26,23 @@ function Root({ orientation, loop, disabled, ...rest }) {
|
|
|
26
26
|
})
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
function useItem(name, disabled) {
|
|
30
|
+
const controller = useToolbar(name);
|
|
31
|
+
const options = useOptions({ disabled });
|
|
32
|
+
return useMemo(() => controller[name](() => defined(options.get())), [
|
|
33
|
+
controller,
|
|
34
|
+
name,
|
|
35
|
+
options
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
function Button({ disabled, ...props }) {
|
|
39
|
+
return usePart(useItem("button", disabled), "button", props);
|
|
40
|
+
}
|
|
41
|
+
function Input({ disabled, ...props }) {
|
|
42
|
+
return usePart(useItem("input", disabled), "input", props);
|
|
43
|
+
}
|
|
44
|
+
function Group({ disabled, ...props }) {
|
|
45
|
+
return usePart(useItem("group", disabled), "div", props);
|
|
36
46
|
}
|
|
37
47
|
function Link(props) {
|
|
38
48
|
const controller = useToolbar("Link");
|
|
@@ -40,14 +50,14 @@ function Link(props) {
|
|
|
40
50
|
return usePart(part, "a", props);
|
|
41
51
|
}
|
|
42
52
|
const Separator = (props) => usePart(useToolbar("Separator").separator, "div", props);
|
|
43
|
-
const Toolbar = {
|
|
53
|
+
const Toolbar = /* @__PURE__ */ parts("Toolbar", {
|
|
44
54
|
Root,
|
|
45
|
-
Button
|
|
55
|
+
Button,
|
|
46
56
|
Link,
|
|
47
|
-
Input
|
|
48
|
-
Group
|
|
57
|
+
Input,
|
|
58
|
+
Group,
|
|
49
59
|
Separator
|
|
50
|
-
};
|
|
60
|
+
});
|
|
51
61
|
export { Toolbar };
|
|
52
62
|
|
|
53
63
|
//# sourceMappingURL=toolbar.js.map
|
package/src/toolbar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","names":[],"sources":["../../../../packages/react/src/toolbar.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport { createToolbar } from \"@kirana-ui/core/toolbar\"\nimport type { Toolbar as Controller, ToolbarProps } from \"@kirana-ui/core/toolbar\"\nimport { 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\"\nimport { ToggleGroupContext, ToolbarContext } from \"./toolbar-context.ts\"\n\nfunction useToolbar(part: string): Controller {\n const controller = useContext(ToolbarContext)\n if (!controller) throw new Error(`<Toolbar.${part}> must be inside <Toolbar.Root>`)\n return controller\n}\n\nexport type RootProps =
|
|
1
|
+
{"version":3,"file":"toolbar.js","names":[],"sources":["../../../../packages/react/src/toolbar.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { Part, StateOf } from \"@kirana-ui/core\"\nimport { createToolbar } from \"@kirana-ui/core/toolbar\"\nimport type { Toolbar as Controller, ToolbarProps } from \"@kirana-ui/core/toolbar\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\nimport { useContext, useMemo } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { parts, useController, useOptions, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\nimport { ToggleGroupContext, ToolbarContext } from \"./toolbar-context.ts\"\n\ntype Parts = Vocabulary[\"toolbar\"]\n\nfunction useToolbar(part: string): Controller {\n const controller = useContext(ToolbarContext)\n if (!controller) throw new Error(`<Toolbar.${part}> must be inside <Toolbar.Root>`)\n return controller\n}\n\nexport type RootProps = PartComponentProps<\"div\", StateOf<Parts[\"root\"]>, ToolbarProps>\n\nfunction Root({ orientation, loop, disabled, ...rest }: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<ToolbarProps, Controller>(within(createToolbar, { direction }), {\n orientation,\n loop,\n disabled,\n })\n return (\n <ToolbarContext.Provider value={controller}>\n {/* A toggle group around the toolbar is not the group of the toolbar's toggles. */}\n <ToggleGroupContext.Provider value={null}>\n {usePart(controller.root, \"div\", rest)}\n </ToggleGroupContext.Provider>\n </ToolbarContext.Provider>\n )\n}\n\n/** What an item of the toolbar takes of its own. */\nexport interface ItemOptions {\n /** Disables this control. */\n disabled?: boolean\n}\n\nexport type ButtonProps = PartComponentProps<\"button\", StateOf<Parts[\"button\"]>, ItemOptions>\nexport type InputProps = PartComponentProps<\"input\", StateOf<Parts[\"input\"]>, ItemOptions>\nexport type GroupProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, ItemOptions>\n/** @deprecated The item's own: `ButtonProps`, `InputProps` or `GroupProps`. */\nexport type ItemProps = PartComponentProps<\"div\", StateOf<Parts[\"group\"]>, ItemOptions>\n\nfunction useItem(name: \"button\" | \"input\" | \"group\", disabled: boolean | undefined): Part {\n const controller = useToolbar(name)\n const options = useOptions({ disabled })\n return useMemo(() => controller[name](() => defined(options.get())), [controller, name, options])\n}\n\nfunction Button({ disabled, ...props }: ButtonProps): ReactElement {\n return usePart(useItem(\"button\", disabled), \"button\", props)\n}\n\nfunction Input({ disabled, ...props }: InputProps): ReactElement {\n return usePart(useItem(\"input\", disabled), \"input\", props)\n}\n\nfunction Group({ disabled, ...props }: GroupProps): ReactElement {\n return usePart(useItem(\"group\", disabled), \"div\", props)\n}\n\nexport type LinkProps = PartComponentProps<\"a\", StateOf<Parts[\"link\"]>>\n\nfunction Link(props: LinkProps): ReactElement {\n const controller = useToolbar(\"Link\")\n const part = useMemo(() => controller.link(), [controller])\n return usePart(part, \"a\", props)\n}\n\nexport type SeparatorProps = PartComponentProps<\"div\", StateOf<Parts[\"separator\"]>>\n\nconst Separator = (props: SeparatorProps) =>\n usePart(useToolbar(\"Separator\").separator, \"div\", props)\n\nexport const Toolbar = /* @__PURE__ */ parts(\"Toolbar\", {\n Root,\n Button,\n Link,\n Input,\n Group,\n Separator,\n})\n"],"mappings":";;;;;;;;AAeA,SAAS,WAAW,MAA0B;CAC5C,MAAM,aAAa,WAAW,cAAc;CAC5C,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,YAAY,KAAK,gCAAgC;CAClF,OAAO;AACT;AAIA,SAAS,KAAK,EAAE,aAAa,MAAM,UAAU,GAAG,QAAiC;CAC/E,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cAAwC,OAAO,eAAe,EAAE,UAAU,CAAC,GAAG;EAC/F;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,eAAe,UAAhB;EAAyB,OAAO;EAE9B,UAAA,oBAAC,mBAAmB,UAApB;GAA6B,OAAO;GACjC,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;EACV,CAAA;CACN,CAAA;AAE7B;AAcA,SAAS,QAAQ,MAAoC,UAAqC;CACxF,MAAM,aAAa,WAAW,IAAI;CAClC,MAAM,UAAU,WAAW,EAAE,SAAS,CAAC;CACvC,OAAO,cAAc,WAAW,KAAK,OAAO,QAAQ,QAAQ,IAAI,CAAC,CAAC,GAAG;EAAC;EAAY;EAAM;CAAO,CAAC;AAClG;AAEA,SAAS,OAAO,EAAE,UAAU,GAAG,SAAoC;CACjE,OAAO,QAAQ,QAAQ,UAAU,QAAQ,GAAG,UAAU,KAAK;AAC7D;AAEA,SAAS,MAAM,EAAE,UAAU,GAAG,SAAmC;CAC/D,OAAO,QAAQ,QAAQ,SAAS,QAAQ,GAAG,SAAS,KAAK;AAC3D;AAEA,SAAS,MAAM,EAAE,UAAU,GAAG,SAAmC;CAC/D,OAAO,QAAQ,QAAQ,SAAS,QAAQ,GAAG,OAAO,KAAK;AACzD;AAIA,SAAS,KAAK,OAAgC;CAC5C,MAAM,aAAa,WAAW,MAAM;CACpC,MAAM,OAAO,cAAc,WAAW,KAAK,GAAG,CAAC,UAAU,CAAC;CAC1D,OAAO,QAAQ,MAAM,KAAK,KAAK;AACjC;AAIA,MAAM,aAAa,UACjB,QAAQ,WAAW,WAAW,CAAC,CAAC,WAAW,OAAO,KAAK;AAEzD,MAAa,UAA0B,sBAAM,WAAW;CACtD;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/src/tooltip.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PartComponentProps } from "./runtime.js";
|
|
1
|
+
import { RootProps, TriggerOptions } from "./hover-popup.js";
|
|
2
|
+
import { PartComponentProps, PortalProps, PositionerOptions } from "./runtime.js";
|
|
3
|
+
import { StateOf } from "@kirana-ui/core";
|
|
4
|
+
import { Vocabulary } from "@kirana-ui/core/vocabulary";
|
|
5
|
+
type Parts = Vocabulary["tooltip"];
|
|
6
|
+
export type TriggerProps = PartComponentProps<"button", StateOf<Parts["trigger"]>, TriggerOptions>;
|
|
7
|
+
export type PositionerProps = PartComponentProps<"div", StateOf<Parts["positioner"]>, PositionerOptions>;
|
|
8
|
+
export type PopupProps = PartComponentProps<"div", StateOf<Parts["popup"]>>;
|
|
9
|
+
export type ArrowProps = PartComponentProps<"div", StateOf<Parts["arrow"]>>;
|
|
3
10
|
export declare const Tooltip: {
|
|
4
|
-
Root: (
|
|
5
|
-
Trigger: (
|
|
6
|
-
Portal: (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Popup: (props: PartComponentProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
11
|
-
Arrow: (props: PartComponentProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
11
|
+
Root: (props: RootProps) => import("react").ReactElement;
|
|
12
|
+
Trigger: (props: TriggerProps) => import("react").ReactElement;
|
|
13
|
+
Portal: (props: PortalProps) => import("react").ReactElement | null;
|
|
14
|
+
Positioner: (props: PositionerProps) => import("react").ReactElement;
|
|
15
|
+
Popup: (props: PopupProps) => import("react").ReactElement;
|
|
16
|
+
Arrow: (props: ArrowProps) => import("react").ReactElement;
|
|
12
17
|
};
|
|
18
|
+
export type { PortalProps, RootProps };
|
|
13
19
|
//# sourceMappingURL=tooltip.d.ts.map
|
package/src/tooltip.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hoverPopup } from "./hover-popup.js";
|
|
2
2
|
import { createTooltip } from "@kirana-ui/core/tooltip";
|
|
3
3
|
// src/tooltip.tsx
|
|
4
|
-
const Tooltip = hoverPopup("Tooltip", createTooltip, "button");
|
|
4
|
+
const Tooltip = /* @__PURE__ */ hoverPopup("Tooltip", createTooltip, "button");
|
|
5
5
|
export { Tooltip };
|
|
6
6
|
|
|
7
7
|
//# sourceMappingURL=tooltip.js.map
|
package/src/tooltip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","names":[],"sources":["../../../../packages/react/src/tooltip.tsx"],"sourcesContent":["import { createTooltip } from \"@kirana-ui/core/tooltip\"\n\nimport { hoverPopup } from \"./hover-popup.tsx\"\n\nexport const Tooltip = hoverPopup(\"Tooltip\", createTooltip, \"button\")\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tooltip.js","names":[],"sources":["../../../../packages/react/src/tooltip.tsx"],"sourcesContent":["import type { StateOf } from \"@kirana-ui/core\"\nimport { createTooltip } from \"@kirana-ui/core/tooltip\"\nimport type { Vocabulary } from \"@kirana-ui/core/vocabulary\"\n\nimport { hoverPopup } from \"./hover-popup.tsx\"\nimport type { TriggerOptions } from \"./hover-popup.tsx\"\nimport type { PartComponentProps, PositionerOptions } from \"./runtime.tsx\"\n\nexport type { PortalProps, RootProps } from \"./hover-popup.tsx\"\n\ntype Parts = Vocabulary[\"tooltip\"]\n\nexport type TriggerProps = PartComponentProps<\"button\", StateOf<Parts[\"trigger\"]>, TriggerOptions>\nexport type PositionerProps = PartComponentProps<\n \"div\",\n StateOf<Parts[\"positioner\"]>,\n PositionerOptions\n>\nexport type PopupProps = PartComponentProps<\"div\", StateOf<Parts[\"popup\"]>>\nexport type ArrowProps = PartComponentProps<\"div\", StateOf<Parts[\"arrow\"]>>\n\nexport const Tooltip = /* @__PURE__ */ hoverPopup<{\n Trigger: TriggerProps\n Positioner: PositionerProps\n Popup: PopupProps\n Arrow: ArrowProps\n}>(\"Tooltip\", createTooltip, \"button\")\n"],"mappings":";;;AAqBA,MAAa,UAA0B,2BAKpC,WAAW,eAAe,QAAQ"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RenderProp } from "./runtime.js";
|
|
2
|
+
import { ReactElement, Ref } from "react";
|
|
3
|
+
/** What `useRender` takes. */
|
|
4
|
+
export interface UseRenderOptions<State extends Record<string, unknown>> {
|
|
5
|
+
/**
|
|
6
|
+
* What its caller asked the element to be drawn as: an element, whose own props lie over
|
|
7
|
+
* `props`, or a function given the props and the state.
|
|
8
|
+
*/
|
|
9
|
+
render?: RenderProp<State> | undefined;
|
|
10
|
+
/** The element drawn when there is no `render`: a `div` unless said. */
|
|
11
|
+
defaultTagName?: string | undefined;
|
|
12
|
+
/** The element's props: the component's own and its caller's, already merged (`mergeProps`). */
|
|
13
|
+
props?: Record<string, unknown> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The component's state. A function `render` is given it, and it is written on the element
|
|
16
|
+
* as `data-*` attributes, under `props`: `true` is present and empty, `false`, `null` and
|
|
17
|
+
* `undefined` are absent, anything else is its text, and `isActive` is `data-is-active`.
|
|
18
|
+
*/
|
|
19
|
+
state?: State | undefined;
|
|
20
|
+
/** A ref of the component's own, given the element beside `props.ref` and the `render` element's. */
|
|
21
|
+
ref?: Ref<HTMLElement> | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Gives a plain element of one's own (a badge, a breadcrumb's link) the `render` prop a part
|
|
25
|
+
* takes, by a part's rule: `props` lie under the `render` element's own props, classes join,
|
|
26
|
+
* styles are merged property by property, both handlers of an event run (`props`' first), the
|
|
27
|
+
* `render` element's own children are drawn when it has any, and every ref gets the element.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useRender<State extends Record<string, unknown> = Record<string, never>>({ render, defaultTagName, props, state, ref }: UseRenderOptions<State>): ReactElement;
|
|
30
|
+
/**
|
|
31
|
+
* Several sets of props as one, for a component's own props and its caller's: a later set
|
|
32
|
+
* wins an attribute it gives (one it leaves `undefined` stays), classes join, styles are
|
|
33
|
+
* merged property by property, and the handlers of an event run in order, until one calls
|
|
34
|
+
* `event.preventKiranaHandler()`, which stops those after it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function mergeProps(...props: readonly (Record<string, unknown> | undefined)[]): Record<string, unknown>;
|
|
37
|
+
export type { RenderProp };
|
|
38
|
+
//# sourceMappingURL=use-render.d.ts.map
|