@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/menu.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { PositionOptions } from "@kirana-ui/core";
|
|
3
|
+
import { ReactElement, ReactNode } from "react";
|
|
4
|
+
import { MenuCheckboxItemProps, MenuItemOptions, MenuProps, MenuRadioGroupProps } from "@kirana-ui/core/menu";
|
|
5
|
+
export type RootProps = Omit<MenuProps, "id"> & {
|
|
6
|
+
id?: string;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
declare function Root({ children, ...props }: RootProps): ReactElement;
|
|
10
|
+
/** A menu for an area of the page, opened at the pointer. Its trigger is the area. */
|
|
11
|
+
declare function ContextRoot({ children, ...props }: RootProps): ReactElement;
|
|
12
|
+
/** The area a secondary press, or a long press on a touch screen, opens the menu in. */
|
|
13
|
+
declare const ContextTrigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
14
|
+
/** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */
|
|
15
|
+
declare function SubmenuRoot({ children, ...props }: RootProps): ReactElement;
|
|
16
|
+
declare function Portal({ children }: {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}): ReactElement | null;
|
|
19
|
+
export type PositionerProps = PartComponentProps & Partial<PositionOptions>;
|
|
20
|
+
declare function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
|
+
declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
22
|
+
declare const SubmenuTrigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
23
|
+
declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
24
|
+
declare const Arrow: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
25
|
+
declare const Separator: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
26
|
+
export type ItemProps = PartComponentProps & MenuItemOptions;
|
|
27
|
+
declare function Item({ disabled, label, closeOnClick, ...props }: ItemProps): ReactElement;
|
|
28
|
+
/** An item that is a link: `href` and the rest go to its `<a>`. */
|
|
29
|
+
declare function LinkItem({ disabled, label, closeOnClick, ...props }: ItemProps): ReactElement;
|
|
30
|
+
declare function Group({ id, ...props }: PartComponentProps & {
|
|
31
|
+
id?: string;
|
|
32
|
+
}): ReactElement;
|
|
33
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
34
|
+
declare function GroupLabel(props: PartComponentProps): ReactElement;
|
|
35
|
+
export type CheckboxItemProps = PartComponentProps & MenuCheckboxItemProps;
|
|
36
|
+
declare function CheckboxItem({ checked, defaultChecked, onCheckedChange, disabled, label, closeOnClick, ...props }: CheckboxItemProps): ReactElement;
|
|
37
|
+
export interface IndicatorProps extends PartComponentProps {
|
|
38
|
+
keepMounted?: boolean;
|
|
39
|
+
}
|
|
40
|
+
declare function CheckboxItemIndicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null;
|
|
41
|
+
export type RadioGroupProps = PartComponentProps & MenuRadioGroupProps;
|
|
42
|
+
declare function RadioGroup({ value, defaultValue, onValueChange, disabled, ...props }: RadioGroupProps): ReactElement;
|
|
43
|
+
export type RadioItemProps = PartComponentProps & MenuItemOptions & {
|
|
44
|
+
value: unknown;
|
|
45
|
+
};
|
|
46
|
+
declare function RadioItem({ value, disabled, label, closeOnClick, ...props }: RadioItemProps): import("react").JSX.Element;
|
|
47
|
+
declare function RadioItemIndicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null;
|
|
48
|
+
export declare const Menu: {
|
|
49
|
+
Root: typeof Root;
|
|
50
|
+
Trigger: typeof Trigger;
|
|
51
|
+
Portal: typeof Portal;
|
|
52
|
+
Positioner: typeof Positioner;
|
|
53
|
+
Popup: typeof Popup;
|
|
54
|
+
Arrow: typeof Arrow;
|
|
55
|
+
Item: typeof Item;
|
|
56
|
+
LinkItem: typeof LinkItem;
|
|
57
|
+
Group: typeof Group;
|
|
58
|
+
GroupLabel: typeof GroupLabel;
|
|
59
|
+
Separator: typeof Separator;
|
|
60
|
+
CheckboxItem: typeof CheckboxItem;
|
|
61
|
+
CheckboxItemIndicator: typeof CheckboxItemIndicator;
|
|
62
|
+
RadioGroup: typeof RadioGroup;
|
|
63
|
+
RadioItem: typeof RadioItem;
|
|
64
|
+
RadioItemIndicator: typeof RadioItemIndicator;
|
|
65
|
+
SubmenuRoot: typeof SubmenuRoot;
|
|
66
|
+
SubmenuTrigger: typeof SubmenuTrigger;
|
|
67
|
+
};
|
|
68
|
+
export declare const ContextMenu: {
|
|
69
|
+
Portal: typeof Portal;
|
|
70
|
+
Positioner: typeof Positioner;
|
|
71
|
+
Popup: typeof Popup;
|
|
72
|
+
Arrow: typeof Arrow;
|
|
73
|
+
Item: typeof Item;
|
|
74
|
+
LinkItem: typeof LinkItem;
|
|
75
|
+
Group: typeof Group;
|
|
76
|
+
GroupLabel: typeof GroupLabel;
|
|
77
|
+
Separator: typeof Separator;
|
|
78
|
+
CheckboxItem: typeof CheckboxItem;
|
|
79
|
+
CheckboxItemIndicator: typeof CheckboxItemIndicator;
|
|
80
|
+
RadioGroup: typeof RadioGroup;
|
|
81
|
+
RadioItem: typeof RadioItem;
|
|
82
|
+
RadioItemIndicator: typeof RadioItemIndicator;
|
|
83
|
+
SubmenuRoot: typeof SubmenuRoot;
|
|
84
|
+
SubmenuTrigger: typeof SubmenuTrigger;
|
|
85
|
+
Root: typeof ContextRoot;
|
|
86
|
+
Trigger: typeof ContextTrigger;
|
|
87
|
+
};
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=menu.d.ts.map
|
package/src/menu.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
3
|
+
import { Portal as Portal$1, useController, useOptions, usePart, useSignal } from "./runtime.js";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
|
+
import { createContext, useContext, useId, useMemo } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { createMenu } from "@kirana-ui/core/menu";
|
|
8
|
+
// src/menu.tsx
|
|
9
|
+
const Context = createContext(null);
|
|
10
|
+
const GroupContext = createContext(null);
|
|
11
|
+
const CheckboxContext = createContext(null);
|
|
12
|
+
const RadioGroupContext = createContext(null);
|
|
13
|
+
const RadioItemContext = createContext(void 0);
|
|
14
|
+
function useMenu(part) {
|
|
15
|
+
const controller = useContext(Context);
|
|
16
|
+
if (!controller) throw new Error(`<Menu.${part}> must be inside <Menu.Root>`);
|
|
17
|
+
return controller;
|
|
18
|
+
}
|
|
19
|
+
function inside(context, part, parent) {
|
|
20
|
+
const found = useContext(context);
|
|
21
|
+
if (!found) throw new Error(`<Menu.${part}> must be inside <Menu.${parent}>`);
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
function provided(controller, children) {
|
|
25
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
26
|
+
value: controller,
|
|
27
|
+
children: /* @__PURE__ */ jsx(MenubarContext.Provider, {
|
|
28
|
+
value: null,
|
|
29
|
+
children: /* @__PURE__ */ jsx(GroupContext.Provider, {
|
|
30
|
+
value: null,
|
|
31
|
+
children
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function Root({ children, ...props }) {
|
|
37
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
38
|
+
const menubar = useContext(MenubarContext) ?? void 0;
|
|
39
|
+
return provided(useController(within(createMenu, {
|
|
40
|
+
direction,
|
|
41
|
+
menubar
|
|
42
|
+
}), props), children);
|
|
43
|
+
}
|
|
44
|
+
/** A menu for an area of the page, opened at the pointer. Its trigger is the area. */
|
|
45
|
+
function ContextRoot({ children, ...props }) {
|
|
46
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
47
|
+
return provided(useController(within(createMenu, {
|
|
48
|
+
direction,
|
|
49
|
+
context: true
|
|
50
|
+
}), props), children);
|
|
51
|
+
}
|
|
52
|
+
/** The area a secondary press, or a long press on a touch screen, opens the menu in. */
|
|
53
|
+
const ContextTrigger = (props) => usePart(useMenu("Trigger").area, "div", props);
|
|
54
|
+
/** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */
|
|
55
|
+
function SubmenuRoot({ children, ...props }) {
|
|
56
|
+
const parent = useMenu("SubmenuRoot");
|
|
57
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
58
|
+
return provided(useController(within(createMenu, {
|
|
59
|
+
parent,
|
|
60
|
+
direction
|
|
61
|
+
}), props), children);
|
|
62
|
+
}
|
|
63
|
+
function Portal({ children }) {
|
|
64
|
+
return useSignal(useMenu("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
|
|
65
|
+
}
|
|
66
|
+
function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }) {
|
|
67
|
+
const controller = useMenu("Positioner");
|
|
68
|
+
controller.positioning.set(defined({
|
|
69
|
+
side,
|
|
70
|
+
align,
|
|
71
|
+
sideOffset,
|
|
72
|
+
alignOffset,
|
|
73
|
+
collisionPadding
|
|
74
|
+
}));
|
|
75
|
+
return usePart(controller.positioner, "div", props);
|
|
76
|
+
}
|
|
77
|
+
const PartElement = ({ part, tag, ...props }) => usePart(part, tag, props);
|
|
78
|
+
const Trigger = (props) => usePart(useMenu("Trigger").trigger, "button", props);
|
|
79
|
+
const SubmenuTrigger = (props) => usePart(useMenu("SubmenuTrigger").trigger, "div", props);
|
|
80
|
+
const Popup = (props) => usePart(useMenu("Popup").popup, "div", props);
|
|
81
|
+
const Arrow = (props) => usePart(useMenu("Arrow").arrow, "div", props);
|
|
82
|
+
const Separator = (props) => usePart(useMenu("Separator").separator, "div", props);
|
|
83
|
+
function Item({ disabled, label, closeOnClick, ...props }) {
|
|
84
|
+
const controller = useMenu("Item");
|
|
85
|
+
const options = useOptions({
|
|
86
|
+
disabled,
|
|
87
|
+
label,
|
|
88
|
+
closeOnClick
|
|
89
|
+
});
|
|
90
|
+
const part = useMemo(() => controller.item(() => defined(options.get())), [controller, options]);
|
|
91
|
+
return usePart(part, "div", props);
|
|
92
|
+
}
|
|
93
|
+
/** An item that is a link: `href` and the rest go to its `<a>`. */
|
|
94
|
+
function LinkItem({ disabled, label, closeOnClick, ...props }) {
|
|
95
|
+
const controller = useMenu("LinkItem");
|
|
96
|
+
const options = useOptions({
|
|
97
|
+
disabled,
|
|
98
|
+
label,
|
|
99
|
+
closeOnClick
|
|
100
|
+
});
|
|
101
|
+
const part = useMemo(() => controller.item(() => defined(options.get())), [controller, options]);
|
|
102
|
+
return usePart(part, "a", props);
|
|
103
|
+
}
|
|
104
|
+
function Group({ id, ...props }) {
|
|
105
|
+
const controller = useMenu("Group");
|
|
106
|
+
const generated = useId();
|
|
107
|
+
const group = useMemo(() => controller.group(id ?? generated), [
|
|
108
|
+
controller,
|
|
109
|
+
id,
|
|
110
|
+
generated
|
|
111
|
+
]);
|
|
112
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, {
|
|
113
|
+
value: group,
|
|
114
|
+
children: usePart(group.root, "div", props)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
118
|
+
function GroupLabel(props) {
|
|
119
|
+
const controller = useMenu("GroupLabel");
|
|
120
|
+
const group = useContext(GroupContext);
|
|
121
|
+
return usePart(group ? group.label : controller.label, "div", props);
|
|
122
|
+
}
|
|
123
|
+
function CheckboxItem({ checked, defaultChecked, onCheckedChange, disabled, label, closeOnClick, ...props }) {
|
|
124
|
+
const controller = useMenu("CheckboxItem");
|
|
125
|
+
const item = useController(controller.checkboxItem, {
|
|
126
|
+
checked,
|
|
127
|
+
defaultChecked,
|
|
128
|
+
onCheckedChange,
|
|
129
|
+
disabled,
|
|
130
|
+
label,
|
|
131
|
+
closeOnClick
|
|
132
|
+
});
|
|
133
|
+
return /* @__PURE__ */ jsx(CheckboxContext.Provider, {
|
|
134
|
+
value: item,
|
|
135
|
+
children: usePart(item.part, "div", props)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function CheckboxItemIndicator({ keepMounted, ...props }) {
|
|
139
|
+
const item = inside(CheckboxContext, "CheckboxItemIndicator", "CheckboxItem");
|
|
140
|
+
return useSignal(item.checked) || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
141
|
+
part: item.indicator,
|
|
142
|
+
tag: "span",
|
|
143
|
+
...props
|
|
144
|
+
}) : null;
|
|
145
|
+
}
|
|
146
|
+
function RadioGroup({ value, defaultValue, onValueChange, disabled, ...props }) {
|
|
147
|
+
const controller = useMenu("RadioGroup");
|
|
148
|
+
const group = useController(controller.radioGroup, {
|
|
149
|
+
value,
|
|
150
|
+
defaultValue,
|
|
151
|
+
onValueChange,
|
|
152
|
+
disabled
|
|
153
|
+
});
|
|
154
|
+
return /* @__PURE__ */ jsx(RadioGroupContext.Provider, {
|
|
155
|
+
value: group,
|
|
156
|
+
children: usePart(group.root, "div", props)
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function RadioItem({ value, disabled, label, closeOnClick, ...props }) {
|
|
160
|
+
const group = inside(RadioGroupContext, "RadioItem", "RadioGroup");
|
|
161
|
+
const options = useOptions({
|
|
162
|
+
disabled,
|
|
163
|
+
label,
|
|
164
|
+
closeOnClick
|
|
165
|
+
});
|
|
166
|
+
const part = useMemo(() => group.item(value, () => defined(options.get())), [
|
|
167
|
+
group,
|
|
168
|
+
value,
|
|
169
|
+
options
|
|
170
|
+
]);
|
|
171
|
+
return /* @__PURE__ */ jsx(RadioItemContext.Provider, {
|
|
172
|
+
value,
|
|
173
|
+
children: usePart(part, "div", props)
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function RadioItemIndicator({ keepMounted, ...props }) {
|
|
177
|
+
const group = inside(RadioGroupContext, "RadioItemIndicator", "RadioGroup");
|
|
178
|
+
const value = useContext(RadioItemContext);
|
|
179
|
+
const checked = useSignal(group.checked(value));
|
|
180
|
+
const part = useMemo(() => group.indicator(value), [group, value]);
|
|
181
|
+
return checked || keepMounted ? /* @__PURE__ */ jsx(PartElement, {
|
|
182
|
+
part,
|
|
183
|
+
tag: "span",
|
|
184
|
+
...props
|
|
185
|
+
}) : null;
|
|
186
|
+
}
|
|
187
|
+
const Menu = {
|
|
188
|
+
Root,
|
|
189
|
+
Trigger,
|
|
190
|
+
Portal,
|
|
191
|
+
Positioner,
|
|
192
|
+
Popup,
|
|
193
|
+
Arrow,
|
|
194
|
+
Item,
|
|
195
|
+
LinkItem,
|
|
196
|
+
Group,
|
|
197
|
+
GroupLabel,
|
|
198
|
+
Separator,
|
|
199
|
+
CheckboxItem,
|
|
200
|
+
CheckboxItemIndicator,
|
|
201
|
+
RadioGroup,
|
|
202
|
+
RadioItem,
|
|
203
|
+
RadioItemIndicator,
|
|
204
|
+
SubmenuRoot,
|
|
205
|
+
SubmenuTrigger
|
|
206
|
+
};
|
|
207
|
+
const ContextMenu = {
|
|
208
|
+
...Menu,
|
|
209
|
+
Root: ContextRoot,
|
|
210
|
+
Trigger: ContextTrigger
|
|
211
|
+
};
|
|
212
|
+
export { ContextMenu, Menu };
|
|
213
|
+
|
|
214
|
+
//# sourceMappingURL=menu.js.map
|
package/src/menu.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.js","names":["BodyPortal"],"sources":["../../../../packages/react/src/menu.tsx"],"sourcesContent":["import { defined, within } from \"@kirana-ui/core\"\nimport type { Part, PositionOptions } from \"@kirana-ui/core\"\nimport { createMenu } from \"@kirana-ui/core/menu\"\nimport type {\n Menu as Controller,\n MenuCheckboxItem,\n MenuCheckboxItemProps,\n MenuGroup,\n MenuItemOptions,\n MenuProps,\n MenuRadioGroup,\n MenuRadioGroupProps,\n} from \"@kirana-ui/core/menu\"\nimport { createContext, useContext, useId, useMemo } from \"react\"\nimport type { ReactElement, ReactNode } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { MenubarContext } from \"./menubar-context.ts\"\nimport { Portal as BodyPortal, useController, useOptions, usePart, useSignal } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\nconst GroupContext = createContext<MenuGroup | null>(null)\nconst CheckboxContext = createContext<MenuCheckboxItem | null>(null)\nconst RadioGroupContext = createContext<MenuRadioGroup | null>(null)\nconst RadioItemContext = createContext<unknown>(undefined)\n\nfunction useMenu(part: string): Controller {\n const controller = useContext(Context)\n if (!controller) throw new Error(`<Menu.${part}> must be inside <Menu.Root>`)\n return controller\n}\n\nfunction inside<T>(context: React.Context<T | null>, part: string, parent: string): T {\n const found = useContext(context)\n if (!found) throw new Error(`<Menu.${part}> must be inside <Menu.${parent}>`)\n return found\n}\n\nexport type RootProps = Omit<MenuProps, \"id\"> & { id?: string; children?: ReactNode }\n\nfunction provided(controller: Controller, children: ReactNode): ReactElement {\n return (\n <Context.Provider value={controller}>\n {/* A group around a submenu is not a group of the submenu's own items; nor is a menu\n written inside a bar's menu one of the bar's. */}\n <MenubarContext.Provider value={null}>\n <GroupContext.Provider value={null}>{children}</GroupContext.Provider>\n </MenubarContext.Provider>\n </Context.Provider>\n )\n}\n\nfunction Root({ children, ...props }: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const menubar = useContext(MenubarContext) ?? undefined\n return provided(useController(within(createMenu, { direction, menubar }), props), children)\n}\n\n/** A menu for an area of the page, opened at the pointer. Its trigger is the area. */\nfunction ContextRoot({ children, ...props }: RootProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n return provided(useController(within(createMenu, { direction, context: true }), props), children)\n}\n\n/** The area a secondary press, or a long press on a touch screen, opens the menu in. */\nconst ContextTrigger = (props: PartComponentProps) => usePart(useMenu(\"Trigger\").area, \"div\", props)\n\n/** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */\nfunction SubmenuRoot({ children, ...props }: RootProps): ReactElement {\n const parent = useMenu(\"SubmenuRoot\")\n const direction = useContext(DirectionContext) ?? undefined\n return provided(useController(within(createMenu, { parent, direction }), props), children)\n}\n\nfunction Portal({ children }: { children?: ReactNode }): ReactElement | null {\n const mounted = useSignal(useMenu(\"Portal\").mounted)\n return mounted ? <BodyPortal>{children}</BodyPortal> : null\n}\n\nexport type PositionerProps = PartComponentProps & Partial<PositionOptions>\n\nfunction Positioner({\n side,\n align,\n sideOffset,\n alignOffset,\n collisionPadding,\n ...props\n}: PositionerProps) {\n const controller = useMenu(\"Positioner\")\n controller.positioning.set(defined({ side, align, sideOffset, alignOffset, collisionPadding }))\n return usePart(controller.positioner, \"div\", props)\n}\n\nconst PartElement = ({ part, tag, ...props }: PartComponentProps & { part: Part; tag: string }) =>\n usePart(part, tag, props)\n\nconst Trigger = (props: PartComponentProps) => usePart(useMenu(\"Trigger\").trigger, \"button\", props)\nconst SubmenuTrigger = (props: PartComponentProps) =>\n usePart(useMenu(\"SubmenuTrigger\").trigger, \"div\", props)\nconst Popup = (props: PartComponentProps) => usePart(useMenu(\"Popup\").popup, \"div\", props)\nconst Arrow = (props: PartComponentProps) => usePart(useMenu(\"Arrow\").arrow, \"div\", props)\nconst Separator = (props: PartComponentProps) =>\n usePart(useMenu(\"Separator\").separator, \"div\", props)\n\nexport type ItemProps = PartComponentProps & MenuItemOptions\n\nfunction Item({ disabled, label, closeOnClick, ...props }: ItemProps): ReactElement {\n const controller = useMenu(\"Item\")\n const options = useOptions({ disabled, label, closeOnClick })\n const part = useMemo(() => controller.item(() => defined(options.get())), [controller, options])\n return usePart(part, \"div\", props)\n}\n\n/** An item that is a link: `href` and the rest go to its `<a>`. */\nfunction LinkItem({ disabled, label, closeOnClick, ...props }: ItemProps): ReactElement {\n const controller = useMenu(\"LinkItem\")\n const options = useOptions({ disabled, label, closeOnClick })\n const part = useMemo(() => controller.item(() => defined(options.get())), [controller, options])\n return usePart(part, \"a\", props)\n}\n\nfunction Group({ id, ...props }: PartComponentProps & { id?: string }): ReactElement {\n const controller = useMenu(\"Group\")\n const generated = useId()\n const group = useMemo(() => controller.group(id ?? generated), [controller, id, generated])\n return (\n <GroupContext.Provider value={group}>{usePart(group.root, \"div\", props)}</GroupContext.Provider>\n )\n}\n\n/** Names the group it is in. With no group around it, it is plain text. */\nfunction GroupLabel(props: PartComponentProps): ReactElement {\n const controller = useMenu(\"GroupLabel\")\n const group = useContext(GroupContext)\n return usePart(group ? group.label : controller.label, \"div\", props)\n}\n\nexport type CheckboxItemProps = PartComponentProps & MenuCheckboxItemProps\n\nfunction CheckboxItem({\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n label,\n closeOnClick,\n ...props\n}: CheckboxItemProps): ReactElement {\n const controller = useMenu(\"CheckboxItem\")\n const item = useController(controller.checkboxItem, {\n checked,\n defaultChecked,\n onCheckedChange,\n disabled,\n label,\n closeOnClick,\n })\n return (\n <CheckboxContext.Provider value={item}>\n {usePart(item.part, \"div\", props)}\n </CheckboxContext.Provider>\n )\n}\n\nexport interface IndicatorProps extends PartComponentProps {\n keepMounted?: boolean\n}\n\nfunction CheckboxItemIndicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null {\n const item = inside(CheckboxContext, \"CheckboxItemIndicator\", \"CheckboxItem\")\n const checked = useSignal(item.checked)\n return checked || keepMounted ? <PartElement part={item.indicator} tag=\"span\" {...props} /> : null\n}\n\nexport type RadioGroupProps = PartComponentProps & MenuRadioGroupProps\n\nfunction RadioGroup({\n value,\n defaultValue,\n onValueChange,\n disabled,\n ...props\n}: RadioGroupProps): ReactElement {\n const controller = useMenu(\"RadioGroup\")\n const group = useController<MenuRadioGroupProps, MenuRadioGroup>(controller.radioGroup, {\n value,\n defaultValue,\n onValueChange,\n disabled,\n })\n return (\n <RadioGroupContext.Provider value={group}>\n {usePart(group.root, \"div\", props)}\n </RadioGroupContext.Provider>\n )\n}\n\nexport type RadioItemProps = PartComponentProps & MenuItemOptions & { value: unknown }\n\nfunction RadioItem({ value, disabled, label, closeOnClick, ...props }: RadioItemProps) {\n const group = inside(RadioGroupContext, \"RadioItem\", \"RadioGroup\")\n const options = useOptions({ disabled, label, closeOnClick })\n const part = useMemo(\n () => group.item(value, () => defined(options.get())),\n [group, value, options]\n )\n return (\n <RadioItemContext.Provider value={value}>\n {usePart(part, \"div\", props)}\n </RadioItemContext.Provider>\n )\n}\n\nfunction RadioItemIndicator({ keepMounted, ...props }: IndicatorProps): ReactElement | null {\n const group = inside(RadioGroupContext, \"RadioItemIndicator\", \"RadioGroup\")\n const value = useContext(RadioItemContext)\n const checked = useSignal(group.checked(value))\n const part = useMemo(() => group.indicator(value), [group, value])\n return checked || keepMounted ? <PartElement part={part} tag=\"span\" {...props} /> : null\n}\n\nexport const Menu = {\n Root,\n Trigger,\n Portal,\n Positioner,\n Popup,\n Arrow,\n Item,\n LinkItem,\n Group,\n GroupLabel,\n Separator,\n CheckboxItem,\n CheckboxItemIndicator,\n RadioGroup,\n RadioItem,\n RadioItemIndicator,\n SubmenuRoot,\n SubmenuTrigger,\n}\n\nexport const ContextMenu = { ...Menu, Root: ContextRoot, Trigger: ContextTrigger }\n"],"mappings":";;;;;;;;AAqBA,MAAM,UAAU,cAAiC,IAAI;AACrD,MAAM,eAAe,cAAgC,IAAI;AACzD,MAAM,kBAAkB,cAAuC,IAAI;AACnE,MAAM,oBAAoB,cAAqC,IAAI;AACnE,MAAM,mBAAmB,cAAuB,KAAA,CAAS;AAEzD,SAAS,QAAQ,MAA0B;CACzC,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,SAAS,KAAK,6BAA6B;CAC5E,OAAO;AACT;AAEA,SAAS,OAAU,S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EAAE,OAAO,UAAU,OAAO,cAAc,GAAG,SAAyB;CACrF,MAAM,QAAQ,OAAO,mBAAmB,aAAa,YAAY;CACjE,MAAM,UAAU,WAAW;EAAE;EAAU;EAAO;CAAa,CAAC;CAC5D,MAAM,OAAO,cACL,MAAM,KAAK,aAAa,QAAQ,QAAQ,IAAI,CAAC,CAAC,GACpD;EAAC;EAAO;EAAO;CAAO,CACxB;CACA,OACE,oBAAC,iBAAiB,UAAlB;EAAkC;EAC/B,UAAA,QAAQ,MAAM,OAAO,KAAK;CACF,CAAA;AAE/B;AAEA,SAAS,mBAAmB,EAAE,aAAa,GAAG,SAA8C;CAC1F,MAAM,QAAQ,OAAO,mBAAmB,sBAAsB,YAAY;CAC1E,MAAM,QAAQ,WAAW,gBAAgB;CACzC,MAAM,UAAU,UAAU,MAAM,QAAQ,KAAK,CAAC;CAC9C,MAAM,OAAO,cAAc,MAAM,UAAU,KAAK,GAAG,CAAC,OAAO,KAAK,CAAC;CACjE,OAAO,WAAW,cAAc,oBAAC,aAAD;EAAmB;EAAM,KAAI;EAAO,GAAI;CAAQ,CAAA,IAAI;AACtF;AAEA,MAAa,OAAO;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,cAAc;CAAE,GAAG;CAAM,MAAM;CAAa,SAAS;AAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menubar-context.js","names":[],"sources":["../../../../packages/react/src/menubar-context.ts"],"sourcesContent":["import type { Menubar } from \"@kirana-ui/core/menubar\"\nimport { createContext } from \"react\"\n\n/** The bar a menu is one of the menus of, if it is in one. */\nexport const MenubarContext = createContext<Menubar | null>(null)\n"],"mappings":";;;AAIA,MAAa,iBAAiB,cAA8B,IAAI"}
|
package/src/menubar.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { MenubarProps as MenubarProps$1 } from "@kirana-ui/core/menubar";
|
|
4
|
+
export type MenubarProps = Omit<MenubarProps$1, "id"> & {
|
|
5
|
+
id?: string;
|
|
6
|
+
} & PartComponentProps;
|
|
7
|
+
/** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */
|
|
8
|
+
export declare function Menubar({ loop, disabled, orientation, id, ...rest }: MenubarProps): ReactElement;
|
|
9
|
+
//# sourceMappingURL=menubar.d.ts.map
|
package/src/menubar.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
3
|
+
import { useController, usePart } from "./runtime.js";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { useContext } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { createMenubar } from "@kirana-ui/core/menubar";
|
|
8
|
+
// src/menubar.tsx
|
|
9
|
+
/** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */
|
|
10
|
+
function Menubar({ loop, disabled, orientation, id, ...rest }) {
|
|
11
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
12
|
+
const controller = useController(within(createMenubar, { direction }), {
|
|
13
|
+
loop,
|
|
14
|
+
orientation,
|
|
15
|
+
disabled,
|
|
16
|
+
id
|
|
17
|
+
});
|
|
18
|
+
return /* @__PURE__ */ jsx(MenubarContext.Provider, {
|
|
19
|
+
value: controller,
|
|
20
|
+
children: usePart(controller.root, "div", rest)
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export { Menubar };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=menubar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menubar.js","names":[],"sources":["../../../../packages/react/src/menubar.tsx"],"sourcesContent":["import { within } from \"@kirana-ui/core\"\nimport { createMenubar } from \"@kirana-ui/core/menubar\"\nimport type { Menubar as Controller, MenubarProps as CoreProps } from \"@kirana-ui/core/menubar\"\nimport { useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { DirectionContext } from \"./direction-context.ts\"\nimport { MenubarContext } from \"./menubar-context.ts\"\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nexport type MenubarProps = Omit<CoreProps, \"id\"> & { id?: string } & PartComponentProps\n\n/** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */\nexport function Menubar({ loop, disabled, orientation, id, ...rest }: MenubarProps): ReactElement {\n const direction = useContext(DirectionContext) ?? undefined\n const controller = useController<CoreProps, Controller>(within(createMenubar, { direction }), {\n loop,\n orientation,\n disabled,\n id,\n })\n return (\n <MenubarContext.Provider value={controller}>\n {usePart(controller.root, \"div\", rest)}\n </MenubarContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;AAcA,SAAgB,QAAQ,EAAE,MAAM,UAAU,aAAa,IAAI,GAAG,QAAoC;CAChG,MAAM,YAAY,WAAW,gBAAgB,KAAK,KAAA;CAClD,MAAM,aAAa,cAAqC,OAAO,eAAe,EAAE,UAAU,CAAC,GAAG;EAC5F;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,eAAe,UAAhB;EAAyB,OAAO;EAC7B,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CACd,CAAA;AAE7B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
import { MessageScrollerProps } from "@kirana-ui/core/message-scroller";
|
|
4
|
+
export type RootProps = Omit<MessageScrollerProps, "id"> & {
|
|
5
|
+
id?: string;
|
|
6
|
+
} & PartComponentProps;
|
|
7
|
+
declare function Root({ initial, threshold, onAtBottomChange, id, ...rest }: RootProps): ReactElement;
|
|
8
|
+
declare const Viewport: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
9
|
+
declare const Content: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
10
|
+
declare const Button: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
11
|
+
export declare const MessageScroller: {
|
|
12
|
+
Root: typeof Root;
|
|
13
|
+
Viewport: typeof Viewport;
|
|
14
|
+
Content: typeof Content;
|
|
15
|
+
Button: typeof Button;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=message-scroller.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useController, usePart } from "./runtime.js";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createMessageScroller } from "@kirana-ui/core/message-scroller";
|
|
5
|
+
// src/message-scroller.tsx
|
|
6
|
+
const Context = createContext(null);
|
|
7
|
+
function useScroller(part) {
|
|
8
|
+
const controller = useContext(Context);
|
|
9
|
+
if (!controller) throw new Error(`<MessageScroller.${part}> must be inside <MessageScroller.Root>`);
|
|
10
|
+
return controller;
|
|
11
|
+
}
|
|
12
|
+
function Root({ initial, threshold, onAtBottomChange, id, ...rest }) {
|
|
13
|
+
const controller = useController(createMessageScroller, {
|
|
14
|
+
initial,
|
|
15
|
+
threshold,
|
|
16
|
+
onAtBottomChange,
|
|
17
|
+
id
|
|
18
|
+
});
|
|
19
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
20
|
+
value: controller,
|
|
21
|
+
children: usePart(controller.root, "div", rest)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const Viewport = (props) => usePart(useScroller("Viewport").viewport, "div", props);
|
|
25
|
+
const Content = (props) => usePart(useScroller("Content").content, "div", props);
|
|
26
|
+
const Button = (props) => usePart(useScroller("Button").button, "button", props);
|
|
27
|
+
const MessageScroller = {
|
|
28
|
+
Root,
|
|
29
|
+
Viewport,
|
|
30
|
+
Content,
|
|
31
|
+
Button
|
|
32
|
+
};
|
|
33
|
+
export { MessageScroller };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=message-scroller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-scroller.js","names":[],"sources":["../../../../packages/react/src/message-scroller.tsx"],"sourcesContent":["import { createMessageScroller } from \"@kirana-ui/core/message-scroller\"\nimport type {\n MessageScroller as Controller,\n MessageScrollerProps,\n} from \"@kirana-ui/core/message-scroller\"\nimport { createContext, useContext } from \"react\"\nimport type { ReactElement } from \"react\"\n\nimport { useController, usePart } from \"./runtime.tsx\"\nimport type { PartComponentProps } from \"./runtime.tsx\"\n\nconst Context = createContext<Controller | null>(null)\n\nfunction useScroller(part: string): Controller {\n const controller = useContext(Context)\n if (!controller)\n throw new Error(`<MessageScroller.${part}> must be inside <MessageScroller.Root>`)\n return controller\n}\n\nexport type RootProps = Omit<MessageScrollerProps, \"id\"> & { id?: string } & PartComponentProps\n\nfunction Root({ initial, threshold, onAtBottomChange, id, ...rest }: RootProps): ReactElement {\n const controller = useController<MessageScrollerProps, Controller>(createMessageScroller, {\n initial,\n threshold,\n onAtBottomChange,\n id,\n })\n return (\n <Context.Provider value={controller}>{usePart(controller.root, \"div\", rest)}</Context.Provider>\n )\n}\n\nconst Viewport = (props: PartComponentProps) =>\n usePart(useScroller(\"Viewport\").viewport, \"div\", props)\nconst Content = (props: PartComponentProps) => usePart(useScroller(\"Content\").content, \"div\", props)\nconst Button = (props: PartComponentProps) => usePart(useScroller(\"Button\").button, \"button\", props)\n\nexport const MessageScroller = { Root, Viewport, Content, Button }\n"],"mappings":";;;;;AAWA,MAAM,UAAU,cAAiC,IAAI;AAErD,SAAS,YAAY,MAA0B;CAC7C,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,oBAAoB,KAAK,wCAAwC;CACnF,OAAO;AACT;AAIA,SAAS,KAAK,EAAE,SAAS,WAAW,kBAAkB,IAAI,GAAG,QAAiC;CAC5F,MAAM,aAAa,cAAgD,uBAAuB;EACxF;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,QAAQ,UAAT;EAAkB,OAAO;EAAa,UAAA,QAAQ,WAAW,MAAM,OAAO,IAAI;CAAoB,CAAA;AAElG;AAEA,MAAM,YAAY,UAChB,QAAQ,YAAY,UAAU,CAAC,CAAC,UAAU,OAAO,KAAK;AACxD,MAAM,WAAW,UAA8B,QAAQ,YAAY,SAAS,CAAC,CAAC,SAAS,OAAO,KAAK;AACnG,MAAM,UAAU,UAA8B,QAAQ,YAAY,QAAQ,CAAC,CAAC,QAAQ,UAAU,KAAK;AAEnG,MAAa,kBAAkB;CAAE;CAAM;CAAU;CAAS;AAAO"}
|
package/src/meter.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
export declare const Meter: {
|
|
3
|
+
Root: ({ value, min, max, format, locale, getAriaValueText, id, ...rest }: Omit<import("@kirana-ui/core/meter").MeterProps, "id"> & {
|
|
4
|
+
id?: string;
|
|
5
|
+
} & PartComponentProps<undefined>) => import("react").ReactElement;
|
|
6
|
+
Track: (props: PartComponentProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
Indicator: (props: PartComponentProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
8
|
+
Value: ({ children, ...props }: Omit<PartComponentProps<undefined>, "children"> & {
|
|
9
|
+
children?: ((text: string | undefined) => import("react").ReactNode) | undefined;
|
|
10
|
+
}) => import("react").ReactElement;
|
|
11
|
+
Label: (props: PartComponentProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=meter.d.ts.map
|
package/src/meter.js
ADDED
package/src/meter.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.js","names":[],"sources":["../../../../packages/react/src/meter.tsx"],"sourcesContent":["import { createMeter } from \"@kirana-ui/core/meter\"\n\nimport { valueBar } from \"./value-bar.tsx\"\n\nexport const Meter = valueBar(\"Meter\", createMeter)\n"],"mappings":";;;AAIA,MAAa,QAAQ,SAAS,SAAS,WAAW"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PartComponentProps } from "./runtime.js";
|
|
2
|
+
import { PositionOptions } from "@kirana-ui/core";
|
|
3
|
+
import { ReactElement, ReactNode } from "react";
|
|
4
|
+
import { NavigationMenuLinkOptions, NavigationMenuProps } from "@kirana-ui/core/navigation-menu";
|
|
5
|
+
export type RootProps<Value> = Omit<NavigationMenuProps<Value>, "id"> & {
|
|
6
|
+
id?: string;
|
|
7
|
+
} & PartComponentProps;
|
|
8
|
+
declare function Root<Value>({ value, defaultValue, onValueChange, delay, closeDelay, orientation, id, ...rest }: RootProps<Value>): ReactElement;
|
|
9
|
+
declare const List: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
10
|
+
export interface ItemProps {
|
|
11
|
+
/** What tells this item from the others. Not needed for an item that is only a link. */
|
|
12
|
+
value?: unknown;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
[attribute: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
declare function Item({ value, children, ...rest }: ItemProps): ReactElement;
|
|
17
|
+
declare const Trigger: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
18
|
+
declare const Icon: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
19
|
+
/** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
|
|
20
|
+
declare function Content(props: PartComponentProps): ReactElement | null;
|
|
21
|
+
export type LinkProps = PartComponentProps & NavigationMenuLinkOptions;
|
|
22
|
+
declare function Link({ active, closeOnClick, ...props }: LinkProps): ReactElement;
|
|
23
|
+
declare function Portal({ children }: {
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
}): ReactElement | null;
|
|
26
|
+
export type PositionerProps = PartComponentProps & Partial<PositionOptions>;
|
|
27
|
+
declare function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }: PositionerProps): ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
28
|
+
declare const Popup: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
29
|
+
declare const Viewport: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
30
|
+
declare const Arrow: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
31
|
+
declare const Backdrop: (props: PartComponentProps) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
32
|
+
export declare const NavigationMenu: {
|
|
33
|
+
Root: typeof Root;
|
|
34
|
+
List: typeof List;
|
|
35
|
+
Item: typeof Item;
|
|
36
|
+
Trigger: typeof Trigger;
|
|
37
|
+
Icon: typeof Icon;
|
|
38
|
+
Content: typeof Content;
|
|
39
|
+
Link: typeof Link;
|
|
40
|
+
Portal: typeof Portal;
|
|
41
|
+
Positioner: typeof Positioner;
|
|
42
|
+
Popup: typeof Popup;
|
|
43
|
+
Viewport: typeof Viewport;
|
|
44
|
+
Arrow: typeof Arrow;
|
|
45
|
+
Backdrop: typeof Backdrop;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=navigation-menu.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { DirectionContext } from "./direction-context.js";
|
|
2
|
+
import { Portal as Portal$1, useController, useMount, useOptions, usePart, useSignal } from "./runtime.js";
|
|
3
|
+
import { defined, within } from "@kirana-ui/core";
|
|
4
|
+
import { createContext, useContext, useMemo } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { createNavigationMenu } from "@kirana-ui/core/navigation-menu";
|
|
8
|
+
// src/navigation-menu.tsx
|
|
9
|
+
const Context = createContext(null);
|
|
10
|
+
const ItemContext = createContext(null);
|
|
11
|
+
function useNavigation(part) {
|
|
12
|
+
const controller = useContext(Context);
|
|
13
|
+
if (!controller) throw new Error(`<NavigationMenu.${part}> must be inside <NavigationMenu.Root>`);
|
|
14
|
+
return controller;
|
|
15
|
+
}
|
|
16
|
+
function useItem(part) {
|
|
17
|
+
const item = useContext(ItemContext);
|
|
18
|
+
if (!item) throw new Error(`<NavigationMenu.${part}> must be inside <NavigationMenu.Item>`);
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
function Root({ value, defaultValue, onValueChange, delay, closeDelay, orientation, id, ...rest }) {
|
|
22
|
+
const direction = useContext(DirectionContext) ?? void 0;
|
|
23
|
+
const controller = useController(within(createNavigationMenu, { direction }), {
|
|
24
|
+
value,
|
|
25
|
+
defaultValue,
|
|
26
|
+
onValueChange,
|
|
27
|
+
delay,
|
|
28
|
+
closeDelay,
|
|
29
|
+
orientation,
|
|
30
|
+
id
|
|
31
|
+
});
|
|
32
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
33
|
+
value: controller,
|
|
34
|
+
children: usePart(controller.root, "nav", rest)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const PartElement = ({ part, tag, ...props }) => usePart(part, tag, props);
|
|
38
|
+
const List = (props) => usePart(useNavigation("List").list, "ul", props);
|
|
39
|
+
function Item({ value, children, ...rest }) {
|
|
40
|
+
const controller = useNavigation("Item");
|
|
41
|
+
const item = useMemo(() => value === void 0 ? null : controller.item(value), [controller, value]);
|
|
42
|
+
return /* @__PURE__ */ jsx("li", {
|
|
43
|
+
...rest,
|
|
44
|
+
children: item ? /* @__PURE__ */ jsx(Mounted, {
|
|
45
|
+
item,
|
|
46
|
+
children
|
|
47
|
+
}) : children
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function Mounted({ item, children }) {
|
|
51
|
+
useMount(item);
|
|
52
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, {
|
|
53
|
+
value: item,
|
|
54
|
+
children
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const Trigger = (props) => usePart(useItem("Trigger").trigger, "button", props);
|
|
58
|
+
const Icon = (props) => usePart(useItem("Icon").icon, "span", props);
|
|
59
|
+
/** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
|
|
60
|
+
function Content(props) {
|
|
61
|
+
const item = useItem("Content");
|
|
62
|
+
const mounted = useSignal(item.mounted);
|
|
63
|
+
const viewport = useSignal(useNavigation("Content").viewportElement);
|
|
64
|
+
if (!mounted || !viewport) return null;
|
|
65
|
+
return createPortal(/* @__PURE__ */ jsx(PartElement, {
|
|
66
|
+
part: item.content,
|
|
67
|
+
tag: "div",
|
|
68
|
+
...props
|
|
69
|
+
}), viewport);
|
|
70
|
+
}
|
|
71
|
+
function Link({ active, closeOnClick, ...props }) {
|
|
72
|
+
const controller = useNavigation("Link");
|
|
73
|
+
const options = useOptions({
|
|
74
|
+
active,
|
|
75
|
+
closeOnClick
|
|
76
|
+
});
|
|
77
|
+
const part = useMemo(() => controller.link(() => defined(options.get())), [controller, options]);
|
|
78
|
+
return usePart(part, "a", props);
|
|
79
|
+
}
|
|
80
|
+
function Portal({ children }) {
|
|
81
|
+
return useSignal(useNavigation("Portal").mounted) ? /* @__PURE__ */ jsx(Portal$1, { children }) : null;
|
|
82
|
+
}
|
|
83
|
+
function Positioner({ side, align, sideOffset, alignOffset, collisionPadding, ...props }) {
|
|
84
|
+
const controller = useNavigation("Positioner");
|
|
85
|
+
controller.positioning.set(defined({
|
|
86
|
+
side,
|
|
87
|
+
align,
|
|
88
|
+
sideOffset,
|
|
89
|
+
alignOffset,
|
|
90
|
+
collisionPadding
|
|
91
|
+
}));
|
|
92
|
+
return usePart(controller.positioner, "div", props);
|
|
93
|
+
}
|
|
94
|
+
const Popup = (props) => usePart(useNavigation("Popup").popup, "div", props);
|
|
95
|
+
const Viewport = (props) => usePart(useNavigation("Viewport").viewport, "div", props);
|
|
96
|
+
const Arrow = (props) => usePart(useNavigation("Arrow").arrow, "div", props);
|
|
97
|
+
const Backdrop = (props) => usePart(useNavigation("Backdrop").backdrop, "div", props);
|
|
98
|
+
const NavigationMenu = {
|
|
99
|
+
Root,
|
|
100
|
+
List,
|
|
101
|
+
Item,
|
|
102
|
+
Trigger,
|
|
103
|
+
Icon,
|
|
104
|
+
Content,
|
|
105
|
+
Link,
|
|
106
|
+
Portal,
|
|
107
|
+
Positioner,
|
|
108
|
+
Popup,
|
|
109
|
+
Viewport,
|
|
110
|
+
Arrow,
|
|
111
|
+
Backdrop
|
|
112
|
+
};
|
|
113
|
+
export { NavigationMenu };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=navigation-menu.js.map
|