@thomasfosterau/components 0.1.0 → 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/README.md +241 -56
- package/dist/canvas/VectorCanvas.svelte +89 -8
- package/dist/canvas/VectorCanvas.svelte.d.ts +19 -1
- package/dist/canvas/types.d.ts +1 -1
- package/dist/charts/types.d.ts +1 -1
- package/dist/citations/list-format.js +3 -1
- package/dist/data/ChatBubble.svelte +48 -0
- package/dist/data/ChatBubble.svelte.d.ts +33 -0
- package/dist/data/DescriptionList.svelte +9 -3
- package/dist/data/DescriptionList.svelte.d.ts +1 -1
- package/dist/data/DescriptionRow.svelte +6 -5
- package/dist/data/MessageThread.svelte +29 -0
- package/dist/data/MessageThread.svelte.d.ts +17 -0
- package/dist/data/Pagination.svelte +5 -5
- package/dist/data/Pagination.svelte.d.ts +8 -0
- package/dist/data/PaginationFooter.svelte +2 -1
- package/dist/data/PaginationFooter.svelte.d.ts +2 -0
- package/dist/data/Table.svelte +9 -3
- package/dist/data/description-context.d.ts +12 -6
- package/dist/data/description-context.js +6 -5
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.js +2 -0
- package/dist/data/table-types.d.ts +7 -0
- package/dist/feedback/Dialog.svelte +19 -49
- package/dist/feedback/Dialog.svelte.d.ts +0 -1
- package/dist/feedback/DialogFrame.svelte +64 -0
- package/dist/feedback/DialogFrame.svelte.d.ts +23 -0
- package/dist/feedback/Drawer.svelte +43 -0
- package/dist/feedback/Drawer.svelte.d.ts +43 -0
- package/dist/feedback/SegmentBar.svelte.d.ts +1 -0
- package/dist/feedback/StatTile.svelte.d.ts +1 -0
- package/dist/feedback/Steps.svelte +72 -0
- package/dist/feedback/Steps.svelte.d.ts +61 -0
- package/dist/feedback/Timeline.svelte.d.ts +3 -0
- package/dist/feedback/index.d.ts +3 -0
- package/dist/feedback/index.js +2 -0
- package/dist/feedback/sizes.d.ts +14 -0
- package/dist/feedback/sizes.js +28 -0
- package/dist/fields/Calendar.svelte +60 -0
- package/dist/fields/Calendar.svelte.d.ts +11 -0
- package/dist/fields/CalendarMonths.svelte +86 -0
- package/dist/fields/CalendarMonths.svelte.d.ts +30 -0
- package/dist/fields/Checkbox.svelte +1 -1
- package/dist/fields/Checkbox.svelte.d.ts +6 -0
- package/dist/fields/Combobox.svelte +61 -54
- package/dist/fields/Combobox.svelte.d.ts +38 -3
- package/dist/fields/DateField.svelte +37 -0
- package/dist/fields/DateField.svelte.d.ts +20 -0
- package/dist/fields/DateInput.svelte +1 -1
- package/dist/fields/DateInput.svelte.d.ts +6 -0
- package/dist/fields/DatePicker.svelte +47 -0
- package/dist/fields/DatePicker.svelte.d.ts +25 -0
- package/dist/fields/DateRangePicker.svelte +70 -0
- package/dist/fields/DateRangePicker.svelte.d.ts +43 -0
- package/dist/fields/Dropzone.svelte +232 -0
- package/dist/fields/Dropzone.svelte.d.ts +103 -0
- package/dist/fields/Fieldset.svelte +7 -2
- package/dist/fields/Fieldset.svelte.d.ts +3 -2
- package/dist/fields/FileInput.svelte +3 -2
- package/dist/fields/FileInput.svelte.d.ts +6 -0
- package/dist/fields/FormField.svelte +27 -3
- package/dist/fields/ImageInput.svelte.d.ts +6 -0
- package/dist/fields/MultiSelect.svelte +112 -0
- package/dist/fields/MultiSelect.svelte.d.ts +75 -0
- package/dist/fields/NumberField.svelte +190 -0
- package/dist/fields/NumberField.svelte.d.ts +76 -0
- package/dist/fields/PasswordInput.svelte +95 -0
- package/dist/fields/PasswordInput.svelte.d.ts +58 -0
- package/dist/fields/PickerPopover.svelte +47 -0
- package/dist/fields/PickerPopover.svelte.d.ts +16 -0
- package/dist/fields/PinInput.svelte +83 -0
- package/dist/fields/PinInput.svelte.d.ts +66 -0
- package/dist/fields/RadioGroup.svelte +3 -0
- package/dist/fields/RangeCalendar.svelte +51 -0
- package/dist/fields/RangeCalendar.svelte.d.ts +23 -0
- package/dist/fields/Rating.svelte +127 -0
- package/dist/fields/Rating.svelte.d.ts +86 -0
- package/dist/fields/SearchInput.svelte +2 -1
- package/dist/fields/SegmentGroup.svelte +91 -0
- package/dist/fields/SegmentGroup.svelte.d.ts +20 -0
- package/dist/fields/Select.svelte +1 -1
- package/dist/fields/Select.svelte.d.ts +6 -0
- package/dist/fields/Slider.svelte +194 -0
- package/dist/fields/Slider.svelte.d.ts +100 -0
- package/dist/fields/TagsInput.svelte +256 -0
- package/dist/fields/TagsInput.svelte.d.ts +102 -0
- package/dist/fields/TextInput.svelte +1 -1
- package/dist/fields/TextInput.svelte.d.ts +6 -0
- package/dist/fields/Textarea.svelte +1 -1
- package/dist/fields/Textarea.svelte.d.ts +6 -0
- package/dist/fields/TimeField.svelte +30 -0
- package/dist/fields/TimeField.svelte.d.ts +19 -0
- package/dist/fields/Toggle.svelte +1 -1
- package/dist/fields/Toggle.svelte.d.ts +6 -0
- package/dist/fields/VideoInput.svelte.d.ts +6 -0
- package/dist/fields/calendar-props.d.ts +119 -0
- package/dist/fields/calendar-props.js +51 -0
- package/dist/fields/dates.d.ts +28 -0
- package/dist/fields/dates.js +26 -0
- package/dist/fields/field-types.d.ts +29 -0
- package/dist/fields/field-types.js +32 -0
- package/dist/fields/file-validation.d.ts +30 -0
- package/dist/fields/file-validation.js +51 -0
- package/dist/fields/index.d.ts +9 -0
- package/dist/fields/index.js +8 -0
- package/dist/fields/latest-search.svelte.d.ts +38 -0
- package/dist/fields/latest-search.svelte.js +85 -0
- package/dist/fields/number-format.d.ts +52 -0
- package/dist/fields/number-format.js +89 -0
- package/dist/fields/segmented-field.d.ts +128 -0
- package/dist/fields/segmented-field.js +52 -0
- package/dist/fields/slider-keys.d.ts +21 -0
- package/dist/fields/slider-keys.js +37 -0
- package/dist/formatting/Countdown.svelte +110 -0
- package/dist/formatting/Countdown.svelte.d.ts +35 -0
- package/dist/formatting/Duration.svelte +18 -0
- package/dist/formatting/Duration.svelte.d.ts +20 -0
- package/dist/formatting/Highlight.svelte +4 -0
- package/dist/formatting/Highlight.svelte.d.ts +4 -0
- package/dist/formatting/duration.d.ts +44 -0
- package/dist/formatting/duration.js +125 -0
- package/dist/formatting/index.d.ts +3 -0
- package/dist/formatting/index.js +3 -0
- package/dist/forms/EntityForm.svelte +53 -45
- package/dist/forms/EntityForm.svelte.d.ts +12 -3
- package/dist/hotkeys/index.d.ts +5 -0
- package/dist/hotkeys/index.js +5 -0
- package/dist/hotkeys/match.js +12 -10
- package/dist/hotkeys/types.d.ts +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infobox/Infobox.svelte +2 -2
- package/dist/infobox/Infobox.svelte.d.ts +7 -0
- package/dist/infobox/InfoboxHeader.svelte +15 -7
- package/dist/infobox/InfoboxHeader.svelte.d.ts +7 -0
- package/dist/infobox/types.d.ts +5 -5
- package/dist/layout/AppShell.svelte +50 -0
- package/dist/layout/AppShell.svelte.d.ts +28 -0
- package/dist/layout/Cluster.svelte +28 -0
- package/dist/layout/Cluster.svelte.d.ts +27 -0
- package/dist/layout/Fits.svelte +27 -0
- package/dist/layout/Fits.svelte.d.ts +13 -0
- package/dist/layout/Flow.svelte +46 -0
- package/dist/layout/Flow.svelte.d.ts +16 -0
- package/dist/layout/Grid.svelte +23 -0
- package/dist/layout/Grid.svelte.d.ts +26 -0
- package/dist/layout/HStack.svelte +12 -0
- package/dist/layout/HStack.svelte.d.ts +34 -0
- package/dist/layout/Hero.svelte +76 -0
- package/dist/layout/Hero.svelte.d.ts +36 -0
- package/dist/layout/Navbar.svelte +2 -2
- package/dist/layout/Sidebar.svelte +1 -1
- package/dist/layout/Spacer.svelte +12 -0
- package/dist/layout/Spacer.svelte.d.ts +6 -0
- package/dist/layout/VStack.svelte +12 -0
- package/dist/layout/VStack.svelte.d.ts +29 -0
- package/dist/layout/index.d.ts +9 -0
- package/dist/layout/index.js +9 -0
- package/dist/layout/space.d.ts +44 -0
- package/dist/layout/space.js +76 -0
- package/dist/search/types.d.ts +3 -0
- package/dist/seo/og-image.d.ts +4 -3
- package/dist/seo/og-image.js +4 -3
- package/dist/tips/tip-stack.d.ts +1 -0
- package/dist/tips/tip-store.svelte.d.ts +2 -1
- package/dist/ui/Accordion.svelte +75 -0
- package/dist/ui/Accordion.svelte.d.ts +50 -0
- package/dist/ui/AccordionItem.svelte +73 -0
- package/dist/ui/AccordionItem.svelte.d.ts +18 -0
- package/dist/ui/Button.svelte +3 -2
- package/dist/ui/ButtonGroup.svelte +24 -0
- package/dist/ui/ButtonGroup.svelte.d.ts +17 -0
- package/dist/ui/ContextMenu.svelte +75 -0
- package/dist/ui/ContextMenu.svelte.d.ts +25 -0
- package/dist/ui/Disclosure.svelte +7 -0
- package/dist/ui/Disclosure.svelte.d.ts +2 -2
- package/dist/ui/Divider.svelte +47 -0
- package/dist/ui/Divider.svelte.d.ts +28 -0
- package/dist/ui/DropdownMenu.svelte +44 -0
- package/dist/ui/DropdownMenu.svelte.d.ts +30 -0
- package/dist/ui/Menu.svelte +17 -47
- package/dist/ui/Menu.svelte.d.ts +3 -24
- package/dist/ui/MenuCheckboxItem.svelte +33 -0
- package/dist/ui/MenuCheckboxItem.svelte.d.ts +20 -0
- package/dist/ui/MenuItem.svelte +29 -31
- package/dist/ui/MenuItem.svelte.d.ts +2 -2
- package/dist/ui/MenuRadioGroup.svelte +25 -0
- package/dist/ui/MenuRadioGroup.svelte.d.ts +20 -0
- package/dist/ui/MenuRadioItem.svelte +20 -0
- package/dist/ui/MenuRadioItem.svelte.d.ts +15 -0
- package/dist/ui/MenuSeparator.svelte +12 -11
- package/dist/ui/MenuSub.svelte +24 -0
- package/dist/ui/MenuSub.svelte.d.ts +15 -0
- package/dist/ui/Spinner.svelte +41 -0
- package/dist/ui/Spinner.svelte.d.ts +35 -0
- package/dist/ui/Stack.svelte +36 -0
- package/dist/ui/Stack.svelte.d.ts +48 -0
- package/dist/ui/ToggleButton.svelte +58 -0
- package/dist/ui/ToggleButton.svelte.d.ts +45 -0
- package/dist/ui/ToggleGroup.svelte +142 -0
- package/dist/ui/ToggleGroup.svelte.d.ts +86 -0
- package/dist/ui/Toolbar.svelte +40 -0
- package/dist/ui/Toolbar.svelte.d.ts +20 -0
- package/dist/ui/ToolbarButton.svelte +29 -0
- package/dist/ui/ToolbarButton.svelte.d.ts +21 -0
- package/dist/ui/ToolbarLink.svelte +21 -0
- package/dist/ui/ToolbarLink.svelte.d.ts +12 -0
- package/dist/ui/ToolbarSeparator.svelte +22 -0
- package/dist/ui/ToolbarSeparator.svelte.d.ts +12 -0
- package/dist/ui/ToolbarToggleGroup.svelte +66 -0
- package/dist/ui/ToolbarToggleGroup.svelte.d.ts +52 -0
- package/dist/ui/accordion-context.d.ts +26 -0
- package/dist/ui/accordion-context.js +23 -0
- package/dist/ui/context-menu.d.ts +13 -0
- package/dist/ui/context-menu.js +13 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +18 -0
- package/dist/ui/menu-context.d.ts +13 -15
- package/dist/ui/menu-context.js +14 -18
- package/dist/ui/menu-parts/CheckboxItemPart.svelte +26 -0
- package/dist/ui/menu-parts/CheckboxItemPart.svelte.d.ts +5 -0
- package/dist/ui/menu-parts/ItemPart.svelte +29 -0
- package/dist/ui/menu-parts/ItemPart.svelte.d.ts +5 -0
- package/dist/ui/menu-parts/RadioGroupPart.svelte +24 -0
- package/dist/ui/menu-parts/RadioGroupPart.svelte.d.ts +5 -0
- package/dist/ui/menu-parts/RadioItemPart.svelte +22 -0
- package/dist/ui/menu-parts/RadioItemPart.svelte.d.ts +5 -0
- package/dist/ui/menu-parts/SeparatorPart.svelte +16 -0
- package/dist/ui/menu-parts/SeparatorPart.svelte.d.ts +5 -0
- package/dist/ui/menu-parts/SubPart.svelte +28 -0
- package/dist/ui/menu-parts/SubPart.svelte.d.ts +5 -0
- package/dist/ui/menu-parts/menu-parts.d.ts +104 -0
- package/dist/ui/menu-parts/menu-parts.js +31 -0
- package/dist/ui/menu-parts/parts.d.ts +12 -0
- package/dist/ui/menu-parts/parts.js +27 -0
- package/dist/ui/toggle-classes.d.ts +39 -0
- package/dist/ui/toggle-classes.js +36 -0
- package/dist/ui/tones.d.ts +35 -0
- package/dist/ui/tones.js +90 -0
- package/package.json +34 -18
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ToggleGroupItem } from './toggle-classes.ts';
|
|
2
|
+
import { type ButtonVariant, type Size, type Tone } from './tones.ts';
|
|
3
|
+
declare function $$render<V extends string>(): {
|
|
4
|
+
props: {
|
|
5
|
+
items: readonly ToggleGroupItem<V>[];
|
|
6
|
+
/** Accessible name of the set ("Text style", "Alignment"). */
|
|
7
|
+
label: string;
|
|
8
|
+
/** @defaultValue `'primary'` */
|
|
9
|
+
tone?: Tone | undefined;
|
|
10
|
+
/** @defaultValue `'ghost'` */
|
|
11
|
+
variant?: ButtonVariant | undefined;
|
|
12
|
+
/** @defaultValue `'sm'` */
|
|
13
|
+
size?: Size | undefined;
|
|
14
|
+
disabled?: boolean | undefined;
|
|
15
|
+
class?: string | undefined;
|
|
16
|
+
} & ({
|
|
17
|
+
type: "single";
|
|
18
|
+
/** The selected value, `''` for none. Bindable. */
|
|
19
|
+
value?: V | "" | undefined;
|
|
20
|
+
onValueChange?: ((value: V | "") => void) | undefined;
|
|
21
|
+
/** Pressing the selected item does nothing. */
|
|
22
|
+
required?: boolean | undefined;
|
|
23
|
+
} | {
|
|
24
|
+
type: "multiple";
|
|
25
|
+
/** The selected values. Bindable. */
|
|
26
|
+
value?: readonly V[] | undefined;
|
|
27
|
+
onValueChange?: ((value: V[]) => void) | undefined;
|
|
28
|
+
required?: undefined;
|
|
29
|
+
});
|
|
30
|
+
exports: {};
|
|
31
|
+
bindings: "value";
|
|
32
|
+
slots: {};
|
|
33
|
+
events: {};
|
|
34
|
+
};
|
|
35
|
+
declare class __sveltets_Render<V extends string> {
|
|
36
|
+
props(): ReturnType<typeof $$render<V>>['props'];
|
|
37
|
+
events(): ReturnType<typeof $$render<V>>['events'];
|
|
38
|
+
slots(): ReturnType<typeof $$render<V>>['slots'];
|
|
39
|
+
bindings(): "value";
|
|
40
|
+
exports(): {};
|
|
41
|
+
}
|
|
42
|
+
interface $$IsomorphicComponent {
|
|
43
|
+
new <V extends string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V>['props']>, ReturnType<__sveltets_Render<V>['events']>, ReturnType<__sveltets_Render<V>['slots']>> & {
|
|
44
|
+
$$bindings?: ReturnType<__sveltets_Render<V>['bindings']>;
|
|
45
|
+
} & ReturnType<__sveltets_Render<V>['exports']>;
|
|
46
|
+
<V extends string>(internal: unknown, props: ReturnType<__sveltets_Render<V>['props']> & {}): ReturnType<__sveltets_Render<V>['exports']>;
|
|
47
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
48
|
+
}
|
|
49
|
+
/** A set of toggles inside a `Toolbar` (Bold / Italic, alignment), sharing the toolbar's single Tab stop. */
|
|
50
|
+
declare const ToolbarToggleGroup: $$IsomorphicComponent;
|
|
51
|
+
type ToolbarToggleGroup<V extends string> = InstanceType<typeof ToolbarToggleGroup<V>>;
|
|
52
|
+
export default ToolbarToggleGroup;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an {@link AccordionItem} learns its enclosing `Accordion`'s settings.
|
|
3
|
+
*
|
|
4
|
+
* `headingLevel`, `variant`, `joined`, `searchable` and the open state are
|
|
5
|
+
* the group's, never an item's: an item reads them from context so a stack
|
|
6
|
+
* cannot drift into mixed heading levels or markers. Getters, not values, so
|
|
7
|
+
* a change to the `Accordion`'s props reaches every item.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import type { DisclosureVariant, HeadingLevel } from './tones.ts';
|
|
12
|
+
/** What an `Accordion` lends its items. */
|
|
13
|
+
export interface AccordionContext {
|
|
14
|
+
readonly headingLevel: () => HeadingLevel;
|
|
15
|
+
readonly variant: () => DisclosureVariant;
|
|
16
|
+
readonly joined: () => boolean;
|
|
17
|
+
readonly searchable: () => boolean;
|
|
18
|
+
/** Whether the item with this value is open. */
|
|
19
|
+
readonly isOpen: (value: string) => boolean;
|
|
20
|
+
/** Whether closing this open item is refused (`type="single"` with `required`). */
|
|
21
|
+
readonly isLocked: (value: string) => boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Lend `context` to the `AccordionItem`s below. */
|
|
24
|
+
export declare function setAccordionContext(context: AccordionContext): void;
|
|
25
|
+
/** The enclosing `Accordion`'s settings; throws outside one, where an item has no group to belong to. */
|
|
26
|
+
export declare function getAccordionContext(): AccordionContext;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an {@link AccordionItem} learns its enclosing `Accordion`'s settings.
|
|
3
|
+
*
|
|
4
|
+
* `headingLevel`, `variant`, `joined`, `searchable` and the open state are
|
|
5
|
+
* the group's, never an item's: an item reads them from context so a stack
|
|
6
|
+
* cannot drift into mixed heading levels or markers. Getters, not values, so
|
|
7
|
+
* a change to the `Accordion`'s props reaches every item.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { getContext, setContext } from 'svelte';
|
|
12
|
+
const ACCORDION_KEY = Symbol.for('@thomasfosterau/components/accordion');
|
|
13
|
+
/** Lend `context` to the `AccordionItem`s below. */
|
|
14
|
+
export function setAccordionContext(context) {
|
|
15
|
+
setContext(ACCORDION_KEY, context);
|
|
16
|
+
}
|
|
17
|
+
/** The enclosing `Accordion`'s settings; throws outside one, where an item has no group to belong to. */
|
|
18
|
+
export function getAccordionContext() {
|
|
19
|
+
const context = getContext(ACCORDION_KEY);
|
|
20
|
+
if (context === undefined)
|
|
21
|
+
throw new Error('AccordionItem must be rendered inside an Accordion.');
|
|
22
|
+
return context;
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@thomasfosterau/components/context-menu` — the right-click / long-press
|
|
3
|
+
* menu, kept out of the root barrel so bits-ui's menu runtime loads only on
|
|
4
|
+
* the pages that use it.
|
|
5
|
+
*
|
|
6
|
+
* Its children (`MenuItem`, `MenuSeparator`, `MenuCheckboxItem`,
|
|
7
|
+
* `MenuRadioGroup`, `MenuRadioItem`, `MenuSub`) come from the root barrel,
|
|
8
|
+
* which carries no bits-ui menu code: `ContextMenu` lends them its parts
|
|
9
|
+
* through context.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
export { default as ContextMenu } from './ContextMenu.svelte';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@thomasfosterau/components/context-menu` — the right-click / long-press
|
|
3
|
+
* menu, kept out of the root barrel so bits-ui's menu runtime loads only on
|
|
4
|
+
* the pages that use it.
|
|
5
|
+
*
|
|
6
|
+
* Its children (`MenuItem`, `MenuSeparator`, `MenuCheckboxItem`,
|
|
7
|
+
* `MenuRadioGroup`, `MenuRadioItem`, `MenuSub`) come from the root barrel,
|
|
8
|
+
* which carries no bits-ui menu code: `ContextMenu` lends them its parts
|
|
9
|
+
* through context.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
export { default as ContextMenu } from './ContextMenu.svelte';
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -17,28 +17,47 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @module
|
|
19
19
|
*/
|
|
20
|
+
export { default as Accordion } from './Accordion.svelte';
|
|
21
|
+
export { default as AccordionItem } from './AccordionItem.svelte';
|
|
20
22
|
export { default as Alert } from './Alert.svelte';
|
|
21
23
|
export { default as Badge } from './Badge.svelte';
|
|
22
24
|
export { default as Button } from './Button.svelte';
|
|
25
|
+
export { default as ButtonGroup } from './ButtonGroup.svelte';
|
|
23
26
|
export { default as Card } from './Card.svelte';
|
|
24
27
|
export { default as Chip } from './Chip.svelte';
|
|
25
28
|
export { default as ConfirmButton } from './ConfirmButton.svelte';
|
|
26
29
|
export { default as Disclosure } from './Disclosure.svelte';
|
|
30
|
+
export { default as Divider } from './Divider.svelte';
|
|
31
|
+
export { default as DropdownMenu } from './DropdownMenu.svelte';
|
|
27
32
|
export { default as EmptyState } from './EmptyState.svelte';
|
|
28
33
|
export { default as ExternalLink } from './ExternalLink.svelte';
|
|
29
34
|
export { default as Heading } from './Heading.svelte';
|
|
30
35
|
export { default as Link } from './Link.svelte';
|
|
31
36
|
export { default as LinkButton } from './LinkButton.svelte';
|
|
32
37
|
export { default as Menu } from './Menu.svelte';
|
|
38
|
+
export { default as MenuCheckboxItem } from './MenuCheckboxItem.svelte';
|
|
33
39
|
export { default as MenuItem } from './MenuItem.svelte';
|
|
40
|
+
export { default as MenuRadioGroup } from './MenuRadioGroup.svelte';
|
|
41
|
+
export { default as MenuRadioItem } from './MenuRadioItem.svelte';
|
|
34
42
|
export { default as MenuSeparator } from './MenuSeparator.svelte';
|
|
43
|
+
export { default as MenuSub } from './MenuSub.svelte';
|
|
35
44
|
export { default as Popover } from './Popover.svelte';
|
|
36
45
|
export { default as ShareButton } from './ShareButton.svelte';
|
|
37
46
|
export { default as Skeleton } from './Skeleton.svelte';
|
|
47
|
+
export { default as Spinner } from './Spinner.svelte';
|
|
48
|
+
export { default as Stack } from './Stack.svelte';
|
|
38
49
|
export { default as ThemeToggle } from './ThemeToggle.svelte';
|
|
50
|
+
export { default as ToggleButton } from './ToggleButton.svelte';
|
|
51
|
+
export { default as ToggleGroup } from './ToggleGroup.svelte';
|
|
52
|
+
export { default as Toolbar } from './Toolbar.svelte';
|
|
53
|
+
export { default as ToolbarButton } from './ToolbarButton.svelte';
|
|
54
|
+
export { default as ToolbarLink } from './ToolbarLink.svelte';
|
|
55
|
+
export { default as ToolbarSeparator } from './ToolbarSeparator.svelte';
|
|
56
|
+
export { default as ToolbarToggleGroup } from './ToolbarToggleGroup.svelte';
|
|
39
57
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
40
58
|
export { default as VisuallyHidden } from './VisuallyHidden.svelte';
|
|
41
59
|
export * from './colour-token.ts';
|
|
42
60
|
export * from './menu-context.ts';
|
|
43
61
|
export * from './slug.ts';
|
|
44
62
|
export * from './tones.ts';
|
|
63
|
+
export type { ToggleGroupItem } from './toggle-classes.ts';
|
package/dist/ui/index.js
CHANGED
|
@@ -17,25 +17,43 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @module
|
|
19
19
|
*/
|
|
20
|
+
export { default as Accordion } from './Accordion.svelte';
|
|
21
|
+
export { default as AccordionItem } from './AccordionItem.svelte';
|
|
20
22
|
export { default as Alert } from './Alert.svelte';
|
|
21
23
|
export { default as Badge } from './Badge.svelte';
|
|
22
24
|
export { default as Button } from './Button.svelte';
|
|
25
|
+
export { default as ButtonGroup } from './ButtonGroup.svelte';
|
|
23
26
|
export { default as Card } from './Card.svelte';
|
|
24
27
|
export { default as Chip } from './Chip.svelte';
|
|
25
28
|
export { default as ConfirmButton } from './ConfirmButton.svelte';
|
|
26
29
|
export { default as Disclosure } from './Disclosure.svelte';
|
|
30
|
+
export { default as Divider } from './Divider.svelte';
|
|
31
|
+
export { default as DropdownMenu } from './DropdownMenu.svelte';
|
|
27
32
|
export { default as EmptyState } from './EmptyState.svelte';
|
|
28
33
|
export { default as ExternalLink } from './ExternalLink.svelte';
|
|
29
34
|
export { default as Heading } from './Heading.svelte';
|
|
30
35
|
export { default as Link } from './Link.svelte';
|
|
31
36
|
export { default as LinkButton } from './LinkButton.svelte';
|
|
32
37
|
export { default as Menu } from './Menu.svelte';
|
|
38
|
+
export { default as MenuCheckboxItem } from './MenuCheckboxItem.svelte';
|
|
33
39
|
export { default as MenuItem } from './MenuItem.svelte';
|
|
40
|
+
export { default as MenuRadioGroup } from './MenuRadioGroup.svelte';
|
|
41
|
+
export { default as MenuRadioItem } from './MenuRadioItem.svelte';
|
|
34
42
|
export { default as MenuSeparator } from './MenuSeparator.svelte';
|
|
43
|
+
export { default as MenuSub } from './MenuSub.svelte';
|
|
35
44
|
export { default as Popover } from './Popover.svelte';
|
|
36
45
|
export { default as ShareButton } from './ShareButton.svelte';
|
|
37
46
|
export { default as Skeleton } from './Skeleton.svelte';
|
|
47
|
+
export { default as Spinner } from './Spinner.svelte';
|
|
48
|
+
export { default as Stack } from './Stack.svelte';
|
|
38
49
|
export { default as ThemeToggle } from './ThemeToggle.svelte';
|
|
50
|
+
export { default as ToggleButton } from './ToggleButton.svelte';
|
|
51
|
+
export { default as ToggleGroup } from './ToggleGroup.svelte';
|
|
52
|
+
export { default as Toolbar } from './Toolbar.svelte';
|
|
53
|
+
export { default as ToolbarButton } from './ToolbarButton.svelte';
|
|
54
|
+
export { default as ToolbarLink } from './ToolbarLink.svelte';
|
|
55
|
+
export { default as ToolbarSeparator } from './ToolbarSeparator.svelte';
|
|
56
|
+
export { default as ToolbarToggleGroup } from './ToolbarToggleGroup.svelte';
|
|
39
57
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
40
58
|
export { default as VisuallyHidden } from './VisuallyHidden.svelte';
|
|
41
59
|
export * from "./colour-token.js";
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* How a {@link MenuItem} learns which
|
|
2
|
+
* How a {@link MenuItem} learns which kind of menu it is inside.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
7
|
-
* `<
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* A `MenuItem` renders entirely different markup in a `DropdownMenu` or a
|
|
5
|
+
* `ContextMenu` — a bits-ui menu item with roving focus and typeahead — and
|
|
6
|
+
* in a `Menu` or a hand-assembled list, where it is a plain anchor in a
|
|
7
|
+
* `<ul class="menu">` navigation list. A call site writes the same
|
|
8
|
+
* `<MenuItem>` either way. The mode is never a prop: it is which menu
|
|
9
|
+
* encloses the item, so a caller can never get the two out of step.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* `DropdownMenu` and `ContextMenu` are the only components that import
|
|
12
|
+
* bits-ui's menus, and they lend the item parts to their descendants through
|
|
13
|
+
* context, so a navigation-only `Menu` never loads the menu runtime (#129).
|
|
14
14
|
*
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
|
17
|
-
/** Which of
|
|
18
|
-
export type MenuMode = 'dropdown' | 'nav';
|
|
19
|
-
/**
|
|
20
|
-
export declare function setMenuMode(mode: () => MenuMode): void;
|
|
21
|
-
/** The enclosing `Menu`'s mode, or `nav` when there is no enclosing `Menu`. */
|
|
17
|
+
/** Which kind of menu an item is inside: a dropdown, a context menu or a navigation list. */
|
|
18
|
+
export type MenuMode = 'dropdown' | 'context' | 'nav';
|
|
19
|
+
/** The enclosing menu's mode: `dropdown` or `context` inside a bits-ui menu, otherwise `nav`. */
|
|
22
20
|
export declare function getMenuMode(): () => MenuMode;
|
package/dist/ui/menu-context.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* How a {@link MenuItem} learns which
|
|
2
|
+
* How a {@link MenuItem} learns which kind of menu it is inside.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
7
|
-
* `<
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* A `MenuItem` renders entirely different markup in a `DropdownMenu` or a
|
|
5
|
+
* `ContextMenu` — a bits-ui menu item with roving focus and typeahead — and
|
|
6
|
+
* in a `Menu` or a hand-assembled list, where it is a plain anchor in a
|
|
7
|
+
* `<ul class="menu">` navigation list. A call site writes the same
|
|
8
|
+
* `<MenuItem>` either way. The mode is never a prop: it is which menu
|
|
9
|
+
* encloses the item, so a caller can never get the two out of step.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* `DropdownMenu` and `ContextMenu` are the only components that import
|
|
12
|
+
* bits-ui's menus, and they lend the item parts to their descendants through
|
|
13
|
+
* context, so a navigation-only `Menu` never loads the menu runtime (#129).
|
|
14
14
|
*
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
/** Declare the mode every descendant `MenuItem` renders in. Called by `Menu`. */
|
|
20
|
-
export function setMenuMode(mode) {
|
|
21
|
-
setContext(MENU_MODE_KEY, mode);
|
|
22
|
-
}
|
|
23
|
-
/** The enclosing `Menu`'s mode, or `nav` when there is no enclosing `Menu`. */
|
|
17
|
+
import { getMenuParts } from "./menu-parts/menu-parts.js";
|
|
18
|
+
/** The enclosing menu's mode: `dropdown` or `context` inside a bits-ui menu, otherwise `nav`. */
|
|
24
19
|
export function getMenuMode() {
|
|
25
|
-
|
|
20
|
+
const mode = getMenuParts()?.kind ?? 'nav';
|
|
21
|
+
return () => mode;
|
|
26
22
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
Internal: the bits-ui checkbox item a `MenuCheckboxItem` renders inside a `DropdownMenu` or `ContextMenu`.
|
|
3
|
+
-->
|
|
4
|
+
<!--
|
|
5
|
+
bits-ui's shared `CheckboxItem` (`DropdownMenu.CheckboxItem` is
|
|
6
|
+
`ContextMenu.CheckboxItem`): `role="menuitemcheckbox"` with `aria-checked`,
|
|
7
|
+
toggled by Enter / Space or a click without closing the menu's focus
|
|
8
|
+
management. The check mark is drawn from bits-ui's own `checked`, so the
|
|
9
|
+
visual and the accessibility tree cannot disagree; it is `aria-hidden`
|
|
10
|
+
because `aria-checked` already says it. Lent through `menu-parts.ts`.
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts">import { Check } from "@lucide/svelte";
|
|
13
|
+
import { DropdownMenu } from "bits-ui";
|
|
14
|
+
let { checked, onCheckedChange, disabled, class: className, label } = $props();
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<li role="none" class={className}>
|
|
18
|
+
<DropdownMenu.CheckboxItem {checked} {onCheckedChange} {disabled}>
|
|
19
|
+
{#snippet children({ checked: on })}
|
|
20
|
+
<span class="grid size-4 shrink-0 place-items-center" aria-hidden="true">
|
|
21
|
+
{#if on}<Check class="size-4" />{/if}
|
|
22
|
+
</span>
|
|
23
|
+
{@render label()}
|
|
24
|
+
{/snippet}
|
|
25
|
+
</DropdownMenu.CheckboxItem>
|
|
26
|
+
</li>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CheckboxItemPartProps } from './menu-parts.ts';
|
|
2
|
+
/** Internal: the bits-ui checkbox item a `MenuCheckboxItem` renders inside a `DropdownMenu` or `ContextMenu`. */
|
|
3
|
+
declare const CheckboxItemPart: import("svelte").Component<CheckboxItemPartProps, {}, "">;
|
|
4
|
+
type CheckboxItemPart = ReturnType<typeof CheckboxItemPart>;
|
|
5
|
+
export default CheckboxItemPart;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
Internal: the bits-ui item a `MenuItem` renders inside a `DropdownMenu` or `ContextMenu`.
|
|
3
|
+
-->
|
|
4
|
+
<!--
|
|
5
|
+
Rendered through `bits-ui`'s `DropdownMenu.Item` `child` snippet, so the
|
|
6
|
+
element is still the caller's own `<a>` or `<button>` — carrying bits-ui's
|
|
7
|
+
`role="menuitem"`, its focus management and its selection handling. The
|
|
8
|
+
`<li>` is `role="none"` so it does not sit between `role="menu"` and
|
|
9
|
+
`role="menuitem"`. Lent to `MenuItem` through `menu-parts.ts`.
|
|
10
|
+
`DropdownMenu.Item` is bits-ui's shared `bits/menu` item, the same
|
|
11
|
+
component as `ContextMenu.Item`, so this part serves both menus.
|
|
12
|
+
-->
|
|
13
|
+
<script lang="ts">import { DropdownMenu } from "bits-ui";
|
|
14
|
+
let { href, current, disabled, onSelect, class: className, label } = $props();
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<li role="none" class={className}>
|
|
18
|
+
<DropdownMenu.Item {disabled} {onSelect}>
|
|
19
|
+
{#snippet child({ props })}
|
|
20
|
+
{#if href === undefined}
|
|
21
|
+
<button {...props} type="button">{@render label()}</button>
|
|
22
|
+
{:else}
|
|
23
|
+
<a {...props} {href} aria-current={current ? 'page' : undefined}>
|
|
24
|
+
{@render label()}
|
|
25
|
+
</a>
|
|
26
|
+
{/if}
|
|
27
|
+
{/snippet}
|
|
28
|
+
</DropdownMenu.Item>
|
|
29
|
+
</li>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ItemPartProps } from './menu-parts.ts';
|
|
2
|
+
/** Internal: the bits-ui item a `MenuItem` renders inside a `DropdownMenu` or `ContextMenu`. */
|
|
3
|
+
declare const ItemPart: import("svelte").Component<ItemPartProps, {}, "">;
|
|
4
|
+
type ItemPart = ReturnType<typeof ItemPart>;
|
|
5
|
+
export default ItemPart;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
Internal: the bits-ui radio group a `MenuRadioGroup` renders inside a `DropdownMenu` or `ContextMenu`.
|
|
3
|
+
-->
|
|
4
|
+
<!--
|
|
5
|
+
bits-ui's shared `RadioGroup` (`role="group"`), headed by its
|
|
6
|
+
`GroupHeading` when there is a `label`, which also names the group. The
|
|
7
|
+
`MenuRadioItem`s sit in a nested `<ul role="none">` so the markup stays a
|
|
8
|
+
valid list; daisyUI's nested-menu indent and rule are reset, since this is
|
|
9
|
+
a group, not a submenu. Lent through `menu-parts.ts`.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">import { DropdownMenu } from "bits-ui";
|
|
12
|
+
let { value, onValueChange, label, class: className, children } = $props();
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<li role="none" class={className}>
|
|
16
|
+
<DropdownMenu.RadioGroup {value} {onValueChange}>
|
|
17
|
+
{#if label !== undefined}
|
|
18
|
+
<DropdownMenu.GroupHeading class="menu-title px-2">{label}</DropdownMenu.GroupHeading>
|
|
19
|
+
{/if}
|
|
20
|
+
<ul role="none" class="ms-0 ps-0 before:hidden">
|
|
21
|
+
{@render children()}
|
|
22
|
+
</ul>
|
|
23
|
+
</DropdownMenu.RadioGroup>
|
|
24
|
+
</li>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RadioGroupPartProps } from './menu-parts.ts';
|
|
2
|
+
/** Internal: the bits-ui radio group a `MenuRadioGroup` renders inside a `DropdownMenu` or `ContextMenu`. */
|
|
3
|
+
declare const RadioGroupPart: import("svelte").Component<RadioGroupPartProps, {}, "">;
|
|
4
|
+
type RadioGroupPart = ReturnType<typeof RadioGroupPart>;
|
|
5
|
+
export default RadioGroupPart;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
Internal: the bits-ui radio item a `MenuRadioItem` renders inside a `DropdownMenu` or `ContextMenu`.
|
|
3
|
+
-->
|
|
4
|
+
<!--
|
|
5
|
+
bits-ui's shared `RadioItem`: `role="menuitemradio"` with `aria-checked`,
|
|
6
|
+
exclusive within its `MenuRadioGroup`. The dot is drawn from bits-ui's own
|
|
7
|
+
`checked` and is `aria-hidden`. Lent through `menu-parts.ts`.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">import { DropdownMenu } from "bits-ui";
|
|
10
|
+
let { value, disabled, class: className, label } = $props();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<li role="none" class={className}>
|
|
14
|
+
<DropdownMenu.RadioItem {value} {disabled}>
|
|
15
|
+
{#snippet children({ checked })}
|
|
16
|
+
<span class="grid size-4 shrink-0 place-items-center" aria-hidden="true">
|
|
17
|
+
{#if checked}<span class="bg-base-content size-2 rounded-full"></span>{/if}
|
|
18
|
+
</span>
|
|
19
|
+
{@render label()}
|
|
20
|
+
{/snippet}
|
|
21
|
+
</DropdownMenu.RadioItem>
|
|
22
|
+
</li>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RadioItemPartProps } from './menu-parts.ts';
|
|
2
|
+
/** Internal: the bits-ui radio item a `MenuRadioItem` renders inside a `DropdownMenu` or `ContextMenu`. */
|
|
3
|
+
declare const RadioItemPart: import("svelte").Component<RadioItemPartProps, {}, "">;
|
|
4
|
+
type RadioItemPart = ReturnType<typeof RadioItemPart>;
|
|
5
|
+
export default RadioItemPart;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
Internal: the bits-ui separator a `MenuSeparator` renders inside a `DropdownMenu` or `ContextMenu`.
|
|
3
|
+
-->
|
|
4
|
+
<!--
|
|
5
|
+
bits-ui's own separator carries `role="separator"` and keeps it out of the
|
|
6
|
+
menu's arrow-key navigation; the `role="none"` `<li>` keeps the
|
|
7
|
+
presentational list item out of the accessibility tree. Lent to
|
|
8
|
+
`MenuSeparator` through `menu-parts.ts`.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">import { DropdownMenu } from "bits-ui";
|
|
11
|
+
let { class: className } = $props();
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<li role="none">
|
|
15
|
+
<DropdownMenu.Separator class={['divider my-1 h-px', className]} />
|
|
16
|
+
</li>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SeparatorPartProps } from './menu-parts.ts';
|
|
2
|
+
/** Internal: the bits-ui separator a `MenuSeparator` renders inside a `DropdownMenu` or `ContextMenu`. */
|
|
3
|
+
declare const SeparatorPart: import("svelte").Component<SeparatorPartProps, {}, "">;
|
|
4
|
+
type SeparatorPart = ReturnType<typeof SeparatorPart>;
|
|
5
|
+
export default SeparatorPart;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!-- @component
|
|
2
|
+
Internal: the bits-ui submenu a `MenuSub` renders inside a `DropdownMenu` or `ContextMenu`.
|
|
3
|
+
-->
|
|
4
|
+
<!--
|
|
5
|
+
bits-ui's shared `Sub`: the `SubTrigger` is a `role="menuitem"` with
|
|
6
|
+
`aria-haspopup="menu"` that opens on → (← closes and returns to it), and
|
|
7
|
+
the `SubContent` is a `role="menu"` styled exactly as the parent menu's
|
|
8
|
+
list, with the same `role="none"` presentation layer. The chevron is
|
|
9
|
+
`aria-hidden`. Lent through `menu-parts.ts`.
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">import { ChevronRight } from "@lucide/svelte";
|
|
12
|
+
import { DropdownMenu } from "bits-ui";
|
|
13
|
+
let { label, disabled, class: className, children } = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<li role="none" class={className}>
|
|
17
|
+
<DropdownMenu.Sub>
|
|
18
|
+
<DropdownMenu.SubTrigger {disabled} class="flex justify-between">
|
|
19
|
+
<span>{label}</span>
|
|
20
|
+
<ChevronRight class="size-4" aria-hidden="true" />
|
|
21
|
+
</DropdownMenu.SubTrigger>
|
|
22
|
+
<DropdownMenu.SubContent class="z-50" sideOffset={4}>
|
|
23
|
+
<ul role="none" class="menu bg-base-100 rounded-box w-56 p-2 shadow-md">
|
|
24
|
+
{@render children()}
|
|
25
|
+
</ul>
|
|
26
|
+
</DropdownMenu.SubContent>
|
|
27
|
+
</DropdownMenu.Sub>
|
|
28
|
+
</li>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SubPartProps } from './menu-parts.ts';
|
|
2
|
+
/** Internal: the bits-ui submenu a `MenuSub` renders inside a `DropdownMenu` or `ContextMenu`. */
|
|
3
|
+
declare const SubPart: import("svelte").Component<SubPartProps, {}, "">;
|
|
4
|
+
type SubPart = ReturnType<typeof SubPart>;
|
|
5
|
+
export default SubPart;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bits-ui pieces a `DropdownMenu` or `ContextMenu` lends to the
|
|
3
|
+
* `MenuItem`, `MenuSeparator`, `MenuCheckboxItem`, `MenuRadioGroup`,
|
|
4
|
+
* `MenuRadioItem` and `MenuSub` inside it.
|
|
5
|
+
*
|
|
6
|
+
* Those children are written once for every kind of menu, but only the
|
|
7
|
+
* bits-ui menus need bits-ui's `Item` / `Separator` / `CheckboxItem` / … — and
|
|
8
|
+
* a static import of them would put the menu runtime (about 30 KB gzip) on
|
|
9
|
+
* every page that renders a plain navigation list (#129). So the parts travel
|
|
10
|
+
* down as context, set by `DropdownMenu` and `ContextMenu`, the only modules
|
|
11
|
+
* that import them. A child outside such a menu never sees them and never
|
|
12
|
+
* loads them.
|
|
13
|
+
*
|
|
14
|
+
* bits-ui's dropdown and context menus share these components (both re-export
|
|
15
|
+
* `bits/menu`'s `Item`, `Separator`, `CheckboxItem`, `RadioGroup`,
|
|
16
|
+
* `RadioItem` and `Sub*`), so one set of parts serves both (#157).
|
|
17
|
+
*
|
|
18
|
+
* Internal: not re-exported from the `ui` barrel.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { type Component, type Snippet } from 'svelte';
|
|
23
|
+
/** What `MenuItem` hands the item part. */
|
|
24
|
+
export interface ItemPartProps {
|
|
25
|
+
/** The resolved link target; `undefined` renders a button. */
|
|
26
|
+
href: string | undefined;
|
|
27
|
+
/** Whether the item is the current page. */
|
|
28
|
+
current: boolean;
|
|
29
|
+
/** Shown but not activatable. */
|
|
30
|
+
disabled: boolean;
|
|
31
|
+
/** Called when the item is chosen. */
|
|
32
|
+
onSelect: () => void;
|
|
33
|
+
/** Extra classes on the `<li>`. */
|
|
34
|
+
class: string | undefined;
|
|
35
|
+
/** The item's label, icon included. */
|
|
36
|
+
label: Snippet<[]>;
|
|
37
|
+
}
|
|
38
|
+
/** What `MenuSeparator` hands the separator part. */
|
|
39
|
+
export interface SeparatorPartProps {
|
|
40
|
+
/** Extra classes on the separator. */
|
|
41
|
+
class: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** What `MenuCheckboxItem` hands the checkbox item part. */
|
|
44
|
+
export interface CheckboxItemPartProps {
|
|
45
|
+
/** Whether the item is checked. */
|
|
46
|
+
checked: boolean;
|
|
47
|
+
/** Called with the next state when the reader toggles it. */
|
|
48
|
+
onCheckedChange: (checked: boolean) => void;
|
|
49
|
+
/** Shown but not activatable. */
|
|
50
|
+
disabled: boolean;
|
|
51
|
+
/** Extra classes on the `<li>`. */
|
|
52
|
+
class: string | undefined;
|
|
53
|
+
/** The item's label. */
|
|
54
|
+
label: Snippet<[]>;
|
|
55
|
+
}
|
|
56
|
+
/** What `MenuRadioGroup` hands the radio group part. */
|
|
57
|
+
export interface RadioGroupPartProps {
|
|
58
|
+
/** The chosen value. */
|
|
59
|
+
value: string;
|
|
60
|
+
/** Called with the chosen value. */
|
|
61
|
+
onValueChange: (value: string) => void;
|
|
62
|
+
/** Visible heading; also the group's accessible name. */
|
|
63
|
+
label: string | undefined;
|
|
64
|
+
/** Extra classes on the `<li>`. */
|
|
65
|
+
class: string | undefined;
|
|
66
|
+
/** The `MenuRadioItem`s. */
|
|
67
|
+
children: Snippet<[]>;
|
|
68
|
+
}
|
|
69
|
+
/** What `MenuRadioItem` hands the radio item part. */
|
|
70
|
+
export interface RadioItemPartProps {
|
|
71
|
+
/** The value this item chooses. */
|
|
72
|
+
value: string;
|
|
73
|
+
/** Shown but not activatable. */
|
|
74
|
+
disabled: boolean;
|
|
75
|
+
/** Extra classes on the `<li>`. */
|
|
76
|
+
class: string | undefined;
|
|
77
|
+
/** The item's label. */
|
|
78
|
+
label: Snippet<[]>;
|
|
79
|
+
}
|
|
80
|
+
/** What `MenuSub` hands the submenu part. */
|
|
81
|
+
export interface SubPartProps {
|
|
82
|
+
/** Text of the item that opens the submenu. */
|
|
83
|
+
label: string;
|
|
84
|
+
/** Shown but not activatable. */
|
|
85
|
+
disabled: boolean;
|
|
86
|
+
/** Extra classes on the `<li>`. */
|
|
87
|
+
class: string | undefined;
|
|
88
|
+
/** The submenu's items. */
|
|
89
|
+
children: Snippet<[]>;
|
|
90
|
+
}
|
|
91
|
+
/** The components a bits-ui menu lends its descendants, and which kind of menu it is. */
|
|
92
|
+
export interface MenuParts {
|
|
93
|
+
readonly kind: 'dropdown' | 'context';
|
|
94
|
+
readonly item: Component<ItemPartProps>;
|
|
95
|
+
readonly separator: Component<SeparatorPartProps>;
|
|
96
|
+
readonly checkboxItem: Component<CheckboxItemPartProps>;
|
|
97
|
+
readonly radioGroup: Component<RadioGroupPartProps>;
|
|
98
|
+
readonly radioItem: Component<RadioItemPartProps>;
|
|
99
|
+
readonly sub: Component<SubPartProps>;
|
|
100
|
+
}
|
|
101
|
+
/** Lend the menu parts to every descendant. Called by `DropdownMenu` and `ContextMenu`. */
|
|
102
|
+
export declare function setMenuParts(parts: MenuParts): void;
|
|
103
|
+
/** The enclosing bits-ui menu's parts, or `undefined` outside one. */
|
|
104
|
+
export declare function getMenuParts(): MenuParts | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bits-ui pieces a `DropdownMenu` or `ContextMenu` lends to the
|
|
3
|
+
* `MenuItem`, `MenuSeparator`, `MenuCheckboxItem`, `MenuRadioGroup`,
|
|
4
|
+
* `MenuRadioItem` and `MenuSub` inside it.
|
|
5
|
+
*
|
|
6
|
+
* Those children are written once for every kind of menu, but only the
|
|
7
|
+
* bits-ui menus need bits-ui's `Item` / `Separator` / `CheckboxItem` / … — and
|
|
8
|
+
* a static import of them would put the menu runtime (about 30 KB gzip) on
|
|
9
|
+
* every page that renders a plain navigation list (#129). So the parts travel
|
|
10
|
+
* down as context, set by `DropdownMenu` and `ContextMenu`, the only modules
|
|
11
|
+
* that import them. A child outside such a menu never sees them and never
|
|
12
|
+
* loads them.
|
|
13
|
+
*
|
|
14
|
+
* bits-ui's dropdown and context menus share these components (both re-export
|
|
15
|
+
* `bits/menu`'s `Item`, `Separator`, `CheckboxItem`, `RadioGroup`,
|
|
16
|
+
* `RadioItem` and `Sub*`), so one set of parts serves both (#157).
|
|
17
|
+
*
|
|
18
|
+
* Internal: not re-exported from the `ui` barrel.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { getContext, setContext } from 'svelte';
|
|
23
|
+
const MENU_PARTS_KEY = Symbol('@thomasfosterau/components:menu-parts');
|
|
24
|
+
/** Lend the menu parts to every descendant. Called by `DropdownMenu` and `ContextMenu`. */
|
|
25
|
+
export function setMenuParts(parts) {
|
|
26
|
+
setContext(MENU_PARTS_KEY, parts);
|
|
27
|
+
}
|
|
28
|
+
/** The enclosing bits-ui menu's parts, or `undefined` outside one. */
|
|
29
|
+
export function getMenuParts() {
|
|
30
|
+
return getContext(MENU_PARTS_KEY);
|
|
31
|
+
}
|