@dxos/react-list 0.10.0 → 0.11.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/dist/lib/index.mjs +97 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/types/src/List.d.ts +3 -35
- package/dist/types/src/List.d.ts.map +1 -1
- package/dist/types/src/ListContext.d.ts +40 -0
- package/dist/types/src/ListContext.d.ts.map +1 -0
- package/dist/types/src/ListItem.d.ts +7 -38
- package/dist/types/src/ListItem.d.ts.map +1 -1
- package/dist/types/src/ListItemContext.d.ts +41 -0
- package/dist/types/src/ListItemContext.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -4
- package/src/List.stories.tsx +1 -1
- package/src/List.tsx +3 -40
- package/src/ListContext.ts +46 -0
- package/src/ListItem.tsx +14 -68
- package/src/ListItemContext.ts +54 -0
- package/src/index.ts +16 -0
- package/dist/lib/browser/index.mjs +0 -105
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -107
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-list",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "List primitive components for React.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
".": {
|
|
17
17
|
"source": "./src/index.ts",
|
|
18
18
|
"types": "./dist/types/src/index.d.ts",
|
|
19
|
-
"
|
|
20
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
19
|
+
"import": "./dist/lib/index.mjs"
|
|
21
20
|
}
|
|
22
21
|
},
|
|
23
22
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
"@radix-ui/react-primitive": "2.0.2",
|
|
32
31
|
"@radix-ui/react-slot": "1.1.2",
|
|
33
32
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
34
|
-
"@dxos/react-hooks": "0.
|
|
33
|
+
"@dxos/react-hooks": "0.11.0"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
36
|
"@radix-ui/react-checkbox": "1.1.4",
|
package/src/List.stories.tsx
CHANGED
|
@@ -110,7 +110,7 @@ const MultiSelectStory = () => {
|
|
|
110
110
|
//
|
|
111
111
|
|
|
112
112
|
const CollapsibleStory = () => (
|
|
113
|
-
<List variant='unordered' className='dx-container border border-separator divide-y divide-separator'>
|
|
113
|
+
<List variant='unordered' className='dx-container border border-separator divide-y divide-subdued-separator'>
|
|
114
114
|
{items.slice(0, 3).map((item) => (
|
|
115
115
|
<ListItem key={item.id} collapsible defaultOpen={item.id === items[0].id}>
|
|
116
116
|
<ListItemOpenTrigger asChild>
|
package/src/List.tsx
CHANGED
|
@@ -30,45 +30,10 @@
|
|
|
30
30
|
// - `packages/ui/react-ui-list/AUDIT.md` for why this layering exists.
|
|
31
31
|
// - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role
|
|
32
32
|
|
|
33
|
-
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
34
33
|
import { Primitive } from '@radix-ui/react-primitive';
|
|
35
|
-
import React, {
|
|
34
|
+
import React, { forwardRef } from 'react';
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
type ListScopedProps<P> = P & { __listScope?: Scope };
|
|
40
|
-
|
|
41
|
-
type ListVariant = 'ordered' | 'unordered';
|
|
42
|
-
|
|
43
|
-
type ListItemSizes = 'one' | 'many';
|
|
44
|
-
|
|
45
|
-
type ListProps = ComponentPropsWithRef<typeof Primitive.ol> & {
|
|
46
|
-
/**
|
|
47
|
-
* If true, render as `role="listbox"` and let `ListItem` children become
|
|
48
|
-
* `role="option"` + `aria-selected`. If false (default) the list is a
|
|
49
|
-
* plain `<ol>` / `<ul>` with no selection semantics — pick this for
|
|
50
|
-
* static lists.
|
|
51
|
-
*/
|
|
52
|
-
selectable?: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* If true, the listbox advertises multi-select via
|
|
55
|
-
* `aria-multiselectable="true"`. Defaults to false (single-select).
|
|
56
|
-
* Has no effect unless `selectable` is also true.
|
|
57
|
-
*/
|
|
58
|
-
multiSelectable?: boolean;
|
|
59
|
-
variant?: ListVariant;
|
|
60
|
-
itemSizes?: ListItemSizes;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
64
|
-
|
|
65
|
-
type ListContextValue = {
|
|
66
|
-
selectable: Exclude<ListProps['selectable'], undefined>;
|
|
67
|
-
variant: Exclude<ListProps['variant'], undefined>;
|
|
68
|
-
itemSizes?: ListItemSizes;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);
|
|
36
|
+
import { LIST_NAME, type ListProps, ListProvider, type ListScopedProps } from './ListContext';
|
|
72
37
|
|
|
73
38
|
const List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {
|
|
74
39
|
const {
|
|
@@ -109,6 +74,4 @@ const List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<Lis
|
|
|
109
74
|
|
|
110
75
|
List.displayName = LIST_NAME;
|
|
111
76
|
|
|
112
|
-
export { List
|
|
113
|
-
|
|
114
|
-
export type { ListProps, ListScopedProps, ListVariant };
|
|
77
|
+
export { List };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
6
|
+
import { type Primitive } from '@radix-ui/react-primitive';
|
|
7
|
+
import { type ComponentPropsWithRef } from 'react';
|
|
8
|
+
|
|
9
|
+
// Kept out of `List.tsx`: react-refresh only fast-refreshes a module whose exports are all
|
|
10
|
+
// components, so a context and its hook exported beside them force a full page reload on every edit.
|
|
11
|
+
|
|
12
|
+
export const LIST_NAME = 'List';
|
|
13
|
+
|
|
14
|
+
export type ListScopedProps<P> = P & { __listScope?: Scope };
|
|
15
|
+
|
|
16
|
+
export type ListVariant = 'ordered' | 'unordered';
|
|
17
|
+
|
|
18
|
+
export type ListItemSizes = 'one' | 'many';
|
|
19
|
+
|
|
20
|
+
export type ListProps = ComponentPropsWithRef<typeof Primitive.ol> & {
|
|
21
|
+
/**
|
|
22
|
+
* If true, render as `role="listbox"` and let `ListItem` children become
|
|
23
|
+
* `role="option"` + `aria-selected`. If false (default) the list is a
|
|
24
|
+
* plain `<ol>` / `<ul>` with no selection semantics — pick this for
|
|
25
|
+
* static lists.
|
|
26
|
+
*/
|
|
27
|
+
selectable?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* If true, the listbox advertises multi-select via
|
|
30
|
+
* `aria-multiselectable="true"`. Defaults to false (single-select).
|
|
31
|
+
* Has no effect unless `selectable` is also true.
|
|
32
|
+
*/
|
|
33
|
+
multiSelectable?: boolean;
|
|
34
|
+
variant?: ListVariant;
|
|
35
|
+
itemSizes?: ListItemSizes;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
39
|
+
|
|
40
|
+
export type ListContextValue = {
|
|
41
|
+
selectable: Exclude<ListProps['selectable'], undefined>;
|
|
42
|
+
variant: Exclude<ListProps['variant'], undefined>;
|
|
43
|
+
itemSizes?: ListItemSizes;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);
|
package/src/ListItem.tsx
CHANGED
|
@@ -2,65 +2,25 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { CheckboxProps } from '@radix-ui/react-checkbox';
|
|
6
5
|
import { type CollapsibleContentProps, type CollapsibleTriggerProps } from '@radix-ui/react-collapsible';
|
|
7
6
|
import * as Collapsible from '@radix-ui/react-collapsible';
|
|
8
|
-
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
9
7
|
import { Primitive } from '@radix-ui/react-primitive';
|
|
10
8
|
import { Slot } from '@radix-ui/react-slot';
|
|
11
9
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
12
|
-
import React, {
|
|
13
|
-
type ComponentProps,
|
|
14
|
-
type ComponentPropsWithoutRef,
|
|
15
|
-
type ComponentRef,
|
|
16
|
-
type Dispatch,
|
|
17
|
-
type ForwardRefExoticComponent,
|
|
18
|
-
type RefAttributes,
|
|
19
|
-
type SetStateAction,
|
|
20
|
-
forwardRef,
|
|
21
|
-
} from 'react';
|
|
10
|
+
import React, { type ComponentProps, type ForwardRefExoticComponent, forwardRef } from 'react';
|
|
22
11
|
|
|
23
12
|
import { useId } from '@dxos/react-hooks';
|
|
24
13
|
|
|
25
|
-
import { LIST_NAME, type ListScopedProps, useListContext } from './
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
type
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
open?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & RefAttributes<HTMLLIElement> &
|
|
39
|
-
ComponentPropsWithoutRef<'li'> & {
|
|
40
|
-
defaultOpen?: boolean;
|
|
41
|
-
onOpenChange?: (nextOpen: boolean) => void;
|
|
42
|
-
} & {
|
|
43
|
-
onSelectedChange?: CheckboxProps['onCheckedChange'];
|
|
44
|
-
defaultSelected?: CheckboxProps['defaultChecked'];
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type ListItemElement = ComponentRef<'li'>;
|
|
48
|
-
|
|
49
|
-
const [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);
|
|
50
|
-
|
|
51
|
-
type ListItemContextValue = {
|
|
52
|
-
headingId: string;
|
|
53
|
-
open: boolean;
|
|
54
|
-
selected: CheckboxProps['checked'];
|
|
55
|
-
setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);
|
|
59
|
-
|
|
60
|
-
type ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithoutRef<'p'>, 'id'>> &
|
|
61
|
-
RefAttributes<HTMLParagraphElement> & {
|
|
62
|
-
asChild?: boolean;
|
|
63
|
-
};
|
|
14
|
+
import { LIST_NAME, type ListScopedProps, useListContext } from './ListContext';
|
|
15
|
+
import {
|
|
16
|
+
LIST_ITEM_NAME,
|
|
17
|
+
type ListItemElement,
|
|
18
|
+
type ListItemHeadingProps,
|
|
19
|
+
type ListItemProps,
|
|
20
|
+
ListItemProvider,
|
|
21
|
+
type ListItemScopedProps,
|
|
22
|
+
useListItemContext,
|
|
23
|
+
} from './ListItemContext';
|
|
64
24
|
|
|
65
25
|
const ListItemHeading = forwardRef<HTMLDivElement, ListItemHeadingProps>(
|
|
66
26
|
({ children, asChild, __listItemScope, ...props }, forwardedRef) => {
|
|
@@ -151,20 +111,6 @@ const ListItem = forwardRef<ListItemElement, ListItemProps>(
|
|
|
151
111
|
|
|
152
112
|
ListItem.displayName = LIST_ITEM_NAME;
|
|
153
113
|
|
|
154
|
-
export {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
ListItemCollapsibleContent,
|
|
158
|
-
ListItemHeading,
|
|
159
|
-
ListItemOpenTrigger,
|
|
160
|
-
createListItemScope,
|
|
161
|
-
useListItemContext,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export type {
|
|
165
|
-
ListItemCollapsibleContentProps,
|
|
166
|
-
ListItemHeadingProps,
|
|
167
|
-
ListItemOpenTriggerProps,
|
|
168
|
-
ListItemProps,
|
|
169
|
-
ListItemScopedProps,
|
|
170
|
-
};
|
|
114
|
+
export { ListItem, ListItemCollapsibleContent, ListItemHeading, ListItemOpenTrigger };
|
|
115
|
+
|
|
116
|
+
export type { ListItemCollapsibleContentProps, ListItemOpenTriggerProps };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type CheckboxProps } from '@radix-ui/react-checkbox';
|
|
6
|
+
import { type Scope, createContextScope } from '@radix-ui/react-context';
|
|
7
|
+
import {
|
|
8
|
+
type ComponentPropsWithoutRef,
|
|
9
|
+
type ComponentRef,
|
|
10
|
+
type Dispatch,
|
|
11
|
+
type RefAttributes,
|
|
12
|
+
type SetStateAction,
|
|
13
|
+
} from 'react';
|
|
14
|
+
|
|
15
|
+
// Kept out of `ListItem.tsx`: react-refresh only fast-refreshes a module whose exports are all
|
|
16
|
+
// components, so a context and its hook exported beside them force a full page reload on every edit.
|
|
17
|
+
|
|
18
|
+
export const LIST_ITEM_NAME = 'ListItem';
|
|
19
|
+
|
|
20
|
+
export type ListItemScopedProps<P> = P & { __listItemScope?: Scope };
|
|
21
|
+
|
|
22
|
+
export interface ListItemData {
|
|
23
|
+
id: string;
|
|
24
|
+
labelId?: string;
|
|
25
|
+
selected?: CheckboxProps['checked'];
|
|
26
|
+
open?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & RefAttributes<HTMLLIElement> &
|
|
30
|
+
ComponentPropsWithoutRef<'li'> & {
|
|
31
|
+
defaultOpen?: boolean;
|
|
32
|
+
onOpenChange?: (nextOpen: boolean) => void;
|
|
33
|
+
} & {
|
|
34
|
+
onSelectedChange?: CheckboxProps['onCheckedChange'];
|
|
35
|
+
defaultSelected?: CheckboxProps['defaultChecked'];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type ListItemElement = ComponentRef<'li'>;
|
|
39
|
+
|
|
40
|
+
export const [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);
|
|
41
|
+
|
|
42
|
+
export type ListItemContextValue = {
|
|
43
|
+
headingId: string;
|
|
44
|
+
open: boolean;
|
|
45
|
+
selected: CheckboxProps['checked'];
|
|
46
|
+
setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);
|
|
50
|
+
|
|
51
|
+
export type ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithoutRef<'p'>, 'id'>> &
|
|
52
|
+
RefAttributes<HTMLParagraphElement> & {
|
|
53
|
+
asChild?: boolean;
|
|
54
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,21 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
export {
|
|
6
|
+
LIST_NAME,
|
|
7
|
+
type ListProps,
|
|
8
|
+
type ListScopedProps,
|
|
9
|
+
type ListVariant,
|
|
10
|
+
createListScope,
|
|
11
|
+
useListContext,
|
|
12
|
+
} from './ListContext';
|
|
5
13
|
export * from './List';
|
|
14
|
+
export {
|
|
15
|
+
LIST_ITEM_NAME,
|
|
16
|
+
type ListItemHeadingProps,
|
|
17
|
+
type ListItemProps,
|
|
18
|
+
type ListItemScopedProps,
|
|
19
|
+
createListItemScope,
|
|
20
|
+
useListItemContext,
|
|
21
|
+
} from './ListItemContext';
|
|
6
22
|
export * from './ListItem';
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// src/List.tsx
|
|
2
|
-
import { createContextScope } from "@radix-ui/react-context";
|
|
3
|
-
import { Primitive } from "@radix-ui/react-primitive";
|
|
4
|
-
import React, { forwardRef } from "react";
|
|
5
|
-
var LIST_NAME = "List";
|
|
6
|
-
var [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
7
|
-
var [ListProvider, useListContext] = createListContext(LIST_NAME);
|
|
8
|
-
var List = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
9
|
-
const { __listScope, variant = "ordered", selectable = false, multiSelectable = false, itemSizes, children, ...rootProps } = props;
|
|
10
|
-
const ListRoot = variant === "ordered" ? Primitive.ol : Primitive.ul;
|
|
11
|
-
return /* @__PURE__ */ React.createElement(ListRoot, {
|
|
12
|
-
...selectable && {
|
|
13
|
-
role: "listbox",
|
|
14
|
-
...multiSelectable && {
|
|
15
|
-
"aria-multiselectable": true
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
...rootProps,
|
|
19
|
-
ref: forwardedRef
|
|
20
|
-
}, /* @__PURE__ */ React.createElement(ListProvider, {
|
|
21
|
-
scope: __listScope,
|
|
22
|
-
variant,
|
|
23
|
-
selectable,
|
|
24
|
-
itemSizes
|
|
25
|
-
}, children));
|
|
26
|
-
});
|
|
27
|
-
List.displayName = LIST_NAME;
|
|
28
|
-
|
|
29
|
-
// src/ListItem.tsx
|
|
30
|
-
import * as Collapsible from "@radix-ui/react-collapsible";
|
|
31
|
-
import { createContextScope as createContextScope2 } from "@radix-ui/react-context";
|
|
32
|
-
import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
|
|
33
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
34
|
-
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
35
|
-
import React2, { forwardRef as forwardRef2 } from "react";
|
|
36
|
-
import { useId } from "@dxos/react-hooks";
|
|
37
|
-
var LIST_ITEM_NAME = "ListItem";
|
|
38
|
-
var [createListItemContext, createListItemScope] = createContextScope2(LIST_ITEM_NAME, []);
|
|
39
|
-
var [ListItemProvider, useListItemContext] = createListItemContext(LIST_ITEM_NAME);
|
|
40
|
-
var ListItemHeading = /* @__PURE__ */ forwardRef2(({ children, asChild, __listItemScope, ...props }, forwardedRef) => {
|
|
41
|
-
const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);
|
|
42
|
-
const Comp = asChild ? Slot : Primitive2.div;
|
|
43
|
-
return /* @__PURE__ */ React2.createElement(Comp, {
|
|
44
|
-
...props,
|
|
45
|
-
id: headingId,
|
|
46
|
-
ref: forwardedRef
|
|
47
|
-
}, children);
|
|
48
|
-
});
|
|
49
|
-
var ListItemOpenTrigger = Collapsible.Trigger;
|
|
50
|
-
var ListItemCollapsibleContent = Collapsible.Content;
|
|
51
|
-
var ListItem = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
52
|
-
const id = useId("listItem", props.id);
|
|
53
|
-
const { __listScope, __listItemScope, children, selected: propsSelected, defaultSelected, onSelectedChange, open: propsOpen, defaultOpen, onOpenChange, collapsible, labelId, ...listItemProps } = props;
|
|
54
|
-
const { selectable } = useListContext(LIST_NAME, __listScope);
|
|
55
|
-
const [selected = false, setSelected] = useControllableState({
|
|
56
|
-
prop: propsSelected,
|
|
57
|
-
defaultProp: defaultSelected,
|
|
58
|
-
onChange: onSelectedChange
|
|
59
|
-
});
|
|
60
|
-
const [open = false, setOpen] = useControllableState({
|
|
61
|
-
prop: propsOpen,
|
|
62
|
-
defaultProp: defaultOpen,
|
|
63
|
-
onChange: onOpenChange
|
|
64
|
-
});
|
|
65
|
-
const headingId = useId("listItem__heading", labelId);
|
|
66
|
-
const listItem = /* @__PURE__ */ React2.createElement(Primitive2.li, {
|
|
67
|
-
...listItemProps,
|
|
68
|
-
id,
|
|
69
|
-
ref: forwardedRef,
|
|
70
|
-
"aria-labelledby": headingId,
|
|
71
|
-
...selectable && {
|
|
72
|
-
"role": "option",
|
|
73
|
-
"aria-selected": !!selected
|
|
74
|
-
},
|
|
75
|
-
...open && {
|
|
76
|
-
"aria-expanded": true
|
|
77
|
-
}
|
|
78
|
-
}, children);
|
|
79
|
-
return /* @__PURE__ */ React2.createElement(ListItemProvider, {
|
|
80
|
-
scope: __listItemScope,
|
|
81
|
-
headingId,
|
|
82
|
-
open,
|
|
83
|
-
selected,
|
|
84
|
-
setSelected
|
|
85
|
-
}, collapsible ? /* @__PURE__ */ React2.createElement(Collapsible.Root, {
|
|
86
|
-
asChild: true,
|
|
87
|
-
open,
|
|
88
|
-
onOpenChange: setOpen
|
|
89
|
-
}, listItem) : listItem);
|
|
90
|
-
});
|
|
91
|
-
ListItem.displayName = LIST_ITEM_NAME;
|
|
92
|
-
export {
|
|
93
|
-
LIST_ITEM_NAME,
|
|
94
|
-
LIST_NAME,
|
|
95
|
-
List,
|
|
96
|
-
ListItem,
|
|
97
|
-
ListItemCollapsibleContent,
|
|
98
|
-
ListItemHeading,
|
|
99
|
-
ListItemOpenTrigger,
|
|
100
|
-
createListItemScope,
|
|
101
|
-
createListScope,
|
|
102
|
-
useListContext,
|
|
103
|
-
useListItemContext
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/List.tsx", "../../../src/ListItem.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\n// Elemental list / listbox primitive.\n//\n// This is the ARIA-only foundation of the DXOS list stack. It renders a\n// semantically-correct `<ol>` / `<ul>` (or, when `selectable={true}`, a\n// `role=\"listbox\"` element with `role=\"option\"` children carrying\n// `aria-selected`). It applies no styling, no keyboard navigation, and\n// no `dx-*` utility classes — those are layered above in\n// `@dxos/react-ui-list`.\n//\n// Layering:\n// - `@dxos/react-list` — this package; ARIA + structure only.\n// - `@dxos/react-ui-list` — adds `dx-*` styling, keyboard nav, and\n// opinionated containers (Listbox, OrderedList,\n// Tree, Accordion, Combobox, Picker) plus the\n// reusable navigation/selection/disclosure aspects.\n// - `@dxos/react-ui-mosaic` — virtualized / draggable / card-board\n// layouts; composes the above where useful.\n//\n// Most app code should reach for `@dxos/react-ui-list`. Use this primitive\n// directly only when building a *new* selectable surface that needs full\n// control over styling and keyboard handling (e.g. a custom Combobox).\n//\n// See:\n// - `packages/ui/ui-theme/src/css/components/state.md` for the\n// `aria-selected` ↔ `dx-selected` pairing rules.\n// - `packages/ui/react-ui-list/AUDIT.md` for why this layering exists.\n// - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\n\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, forwardRef } from 'react';\n\nconst LIST_NAME = 'List';\n\ntype ListScopedProps<P> = P & { __listScope?: Scope };\n\ntype ListVariant = 'ordered' | 'unordered';\n\ntype ListItemSizes = 'one' | 'many';\n\ntype ListProps = ComponentPropsWithRef<typeof Primitive.ol> & {\n /**\n * If true, render as `role=\"listbox\"` and let `ListItem` children become\n * `role=\"option\"` + `aria-selected`. If false (default) the list is a\n * plain `<ol>` / `<ul>` with no selection semantics — pick this for\n * static lists.\n */\n selectable?: boolean;\n /**\n * If true, the listbox advertises multi-select via\n * `aria-multiselectable=\"true\"`. Defaults to false (single-select).\n * Has no effect unless `selectable` is also true.\n */\n multiSelectable?: boolean;\n variant?: ListVariant;\n itemSizes?: ListItemSizes;\n};\n\nconst [createListContext, createListScope] = createContextScope(LIST_NAME, []);\n\ntype ListContextValue = {\n selectable: Exclude<ListProps['selectable'], undefined>;\n variant: Exclude<ListProps['variant'], undefined>;\n itemSizes?: ListItemSizes;\n};\n\nconst [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);\n\nconst List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {\n const {\n __listScope,\n variant = 'ordered',\n selectable = false,\n multiSelectable = false,\n itemSizes,\n children,\n ...rootProps\n } = props;\n const ListRoot = variant === 'ordered' ? Primitive.ol : Primitive.ul;\n return (\n <ListRoot\n // `aria-multiselectable` is only meaningful on `role=\"listbox\"`,\n // and even there is omitted in the single-select default to keep\n // assistive tech announcements concise.\n {...(selectable && {\n role: 'listbox',\n ...(multiSelectable && { 'aria-multiselectable': true as const }),\n })}\n {...rootProps}\n ref={forwardedRef}\n >\n <ListProvider\n {...{\n scope: __listScope,\n variant,\n selectable,\n itemSizes,\n }}\n >\n {children}\n </ListProvider>\n </ListRoot>\n );\n});\n\nList.displayName = LIST_NAME;\n\nexport { List, LIST_NAME, createListScope, useListContext };\n\nexport type { ListProps, ListScopedProps, ListVariant };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { type CollapsibleContentProps, type CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n type ComponentProps,\n type ComponentPropsWithoutRef,\n type ComponentRef,\n type Dispatch,\n type ForwardRefExoticComponent,\n type RefAttributes,\n type SetStateAction,\n forwardRef,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, type ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n labelId?: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & RefAttributes<HTMLLIElement> &\n ComponentPropsWithoutRef<'li'> & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = ComponentRef<'li'>;\n\nconst [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);\n\ntype ListItemContextValue = {\n headingId: string;\n open: boolean;\n selected: CheckboxProps['checked'];\n setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;\n};\n\nconst [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);\n\ntype ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithoutRef<'p'>, 'id'>> &\n RefAttributes<HTMLParagraphElement> & {\n asChild?: boolean;\n };\n\nconst ListItemHeading = forwardRef<HTMLDivElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Comp = asChild ? Slot : Primitive.div;\n return (\n <Comp {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Comp>\n );\n },\n);\n\ntype ListItemOpenTriggerProps = ListItemScopedProps<CollapsibleTriggerProps>;\n\nconst ListItemOpenTrigger = Collapsible.Trigger;\n\ntype ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content>;\n\nconst ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;\n\nconst ListItem = forwardRef<ListItemElement, ListItemProps>(\n (props: ListItemScopedProps<ListScopedProps<ListItemProps>>, forwardedRef) => {\n const id = useId('listItem', props.id);\n\n const {\n __listScope,\n __listItemScope,\n children,\n selected: propsSelected,\n defaultSelected,\n onSelectedChange,\n open: propsOpen,\n defaultOpen,\n onOpenChange,\n collapsible,\n labelId,\n ...listItemProps\n } = props;\n const { selectable } = useListContext(LIST_NAME, __listScope);\n\n const [selected = false, setSelected] = useControllableState({\n prop: propsSelected,\n defaultProp: defaultSelected,\n onChange: onSelectedChange,\n });\n\n const [open = false, setOpen] = useControllableState({\n prop: propsOpen,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const headingId = useId('listItem__heading', labelId);\n\n const listItem = (\n <Primitive.li\n {...listItemProps}\n id={id}\n ref={forwardedRef}\n aria-labelledby={headingId}\n {...(selectable && { 'role': 'option', 'aria-selected': !!selected })}\n {...(open && { 'aria-expanded': true })}\n >\n {children}\n </Primitive.li>\n );\n\n return (\n <ListItemProvider\n scope={__listItemScope}\n headingId={headingId}\n open={open}\n selected={selected}\n setSelected={setSelected}\n >\n {collapsible ? (\n <Collapsible.Root asChild open={open} onOpenChange={setOpen}>\n {listItem}\n </Collapsible.Root>\n ) : (\n listItem\n )}\n </ListItemProvider>\n );\n },\n);\n\nListItem.displayName = LIST_ITEM_NAME;\n\nexport {\n LIST_ITEM_NAME,\n ListItem,\n ListItemCollapsibleContent,\n ListItemHeading,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n};\n\nexport type {\n ListItemCollapsibleContentProps,\n ListItemHeadingProps,\n ListItemOpenTriggerProps,\n ListItemProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["createContextScope", "Primitive", "React", "forwardRef", "LIST_NAME", "createListContext", "createListScope", "ListProvider", "useListContext", "List", "props", "forwardedRef", "__listScope", "variant", "selectable", "multiSelectable", "itemSizes", "children", "rootProps", "ListRoot", "ol", "ul", "role", "ref", "scope", "displayName", "Collapsible", "createContextScope", "Primitive", "Slot", "useControllableState", "React", "forwardRef", "useId", "LIST_ITEM_NAME", "createListItemContext", "createListItemScope", "createContextScope", "ListItemProvider", "useListItemContext", "ListItemHeading", "forwardRef", "children", "asChild", "__listItemScope", "props", "forwardedRef", "headingId", "Comp", "Slot", "Primitive", "div", "React", "id", "ref", "ListItemOpenTrigger", "Trigger", "ListItemCollapsibleContent", "Content", "ListItem", "useId", "__listScope", "selected", "propsSelected", "defaultSelected", "onSelectedChange", "open", "propsOpen", "defaultOpen", "onOpenChange", "collapsible", "labelId", "listItemProps", "selectable", "useListContext", "LIST_NAME", "setSelected", "useControllableState", "prop", "defaultProp", "onChange", "setOpen", "listItem", "li", "aria-labelledby", "scope", "Root", "displayName"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"inputs":{"src/List.tsx":{"bytes":10080,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/ListItem.tsx":{"bytes":12912,"imports":[{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"src/List.tsx","kind":"import-statement","original":"./List"}],"format":"esm"},"src/index.ts":{"bytes":456,"imports":[{"path":"src/List.tsx","kind":"import-statement","original":"./List"},{"path":"src/ListItem.tsx","kind":"import-statement","original":"./ListItem"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12457},"dist/lib/browser/index.mjs":{"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true}],"exports":["LIST_ITEM_NAME","LIST_NAME","List","ListItem","ListItemCollapsibleContent","ListItemHeading","ListItemOpenTrigger","createListItemScope","createListScope","useListContext","useListItemContext"],"entryPoint":"src/index.ts","inputs":{"src/List.tsx":{"bytesInOutput":1000},"src/index.ts":{"bytesInOutput":0},"src/ListItem.tsx":{"bytesInOutput":2530}},"bytes":3818}}}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// src/List.tsx
|
|
4
|
-
import { createContextScope } from "@radix-ui/react-context";
|
|
5
|
-
import { Primitive } from "@radix-ui/react-primitive";
|
|
6
|
-
import React, { forwardRef } from "react";
|
|
7
|
-
var LIST_NAME = "List";
|
|
8
|
-
var [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
9
|
-
var [ListProvider, useListContext] = createListContext(LIST_NAME);
|
|
10
|
-
var List = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
11
|
-
const { __listScope, variant = "ordered", selectable = false, multiSelectable = false, itemSizes, children, ...rootProps } = props;
|
|
12
|
-
const ListRoot = variant === "ordered" ? Primitive.ol : Primitive.ul;
|
|
13
|
-
return /* @__PURE__ */ React.createElement(ListRoot, {
|
|
14
|
-
...selectable && {
|
|
15
|
-
role: "listbox",
|
|
16
|
-
...multiSelectable && {
|
|
17
|
-
"aria-multiselectable": true
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
...rootProps,
|
|
21
|
-
ref: forwardedRef
|
|
22
|
-
}, /* @__PURE__ */ React.createElement(ListProvider, {
|
|
23
|
-
scope: __listScope,
|
|
24
|
-
variant,
|
|
25
|
-
selectable,
|
|
26
|
-
itemSizes
|
|
27
|
-
}, children));
|
|
28
|
-
});
|
|
29
|
-
List.displayName = LIST_NAME;
|
|
30
|
-
|
|
31
|
-
// src/ListItem.tsx
|
|
32
|
-
import * as Collapsible from "@radix-ui/react-collapsible";
|
|
33
|
-
import { createContextScope as createContextScope2 } from "@radix-ui/react-context";
|
|
34
|
-
import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
|
|
35
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
36
|
-
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
37
|
-
import React2, { forwardRef as forwardRef2 } from "react";
|
|
38
|
-
import { useId } from "@dxos/react-hooks";
|
|
39
|
-
var LIST_ITEM_NAME = "ListItem";
|
|
40
|
-
var [createListItemContext, createListItemScope] = createContextScope2(LIST_ITEM_NAME, []);
|
|
41
|
-
var [ListItemProvider, useListItemContext] = createListItemContext(LIST_ITEM_NAME);
|
|
42
|
-
var ListItemHeading = /* @__PURE__ */ forwardRef2(({ children, asChild, __listItemScope, ...props }, forwardedRef) => {
|
|
43
|
-
const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);
|
|
44
|
-
const Comp = asChild ? Slot : Primitive2.div;
|
|
45
|
-
return /* @__PURE__ */ React2.createElement(Comp, {
|
|
46
|
-
...props,
|
|
47
|
-
id: headingId,
|
|
48
|
-
ref: forwardedRef
|
|
49
|
-
}, children);
|
|
50
|
-
});
|
|
51
|
-
var ListItemOpenTrigger = Collapsible.Trigger;
|
|
52
|
-
var ListItemCollapsibleContent = Collapsible.Content;
|
|
53
|
-
var ListItem = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
54
|
-
const id = useId("listItem", props.id);
|
|
55
|
-
const { __listScope, __listItemScope, children, selected: propsSelected, defaultSelected, onSelectedChange, open: propsOpen, defaultOpen, onOpenChange, collapsible, labelId, ...listItemProps } = props;
|
|
56
|
-
const { selectable } = useListContext(LIST_NAME, __listScope);
|
|
57
|
-
const [selected = false, setSelected] = useControllableState({
|
|
58
|
-
prop: propsSelected,
|
|
59
|
-
defaultProp: defaultSelected,
|
|
60
|
-
onChange: onSelectedChange
|
|
61
|
-
});
|
|
62
|
-
const [open = false, setOpen] = useControllableState({
|
|
63
|
-
prop: propsOpen,
|
|
64
|
-
defaultProp: defaultOpen,
|
|
65
|
-
onChange: onOpenChange
|
|
66
|
-
});
|
|
67
|
-
const headingId = useId("listItem__heading", labelId);
|
|
68
|
-
const listItem = /* @__PURE__ */ React2.createElement(Primitive2.li, {
|
|
69
|
-
...listItemProps,
|
|
70
|
-
id,
|
|
71
|
-
ref: forwardedRef,
|
|
72
|
-
"aria-labelledby": headingId,
|
|
73
|
-
...selectable && {
|
|
74
|
-
"role": "option",
|
|
75
|
-
"aria-selected": !!selected
|
|
76
|
-
},
|
|
77
|
-
...open && {
|
|
78
|
-
"aria-expanded": true
|
|
79
|
-
}
|
|
80
|
-
}, children);
|
|
81
|
-
return /* @__PURE__ */ React2.createElement(ListItemProvider, {
|
|
82
|
-
scope: __listItemScope,
|
|
83
|
-
headingId,
|
|
84
|
-
open,
|
|
85
|
-
selected,
|
|
86
|
-
setSelected
|
|
87
|
-
}, collapsible ? /* @__PURE__ */ React2.createElement(Collapsible.Root, {
|
|
88
|
-
asChild: true,
|
|
89
|
-
open,
|
|
90
|
-
onOpenChange: setOpen
|
|
91
|
-
}, listItem) : listItem);
|
|
92
|
-
});
|
|
93
|
-
ListItem.displayName = LIST_ITEM_NAME;
|
|
94
|
-
export {
|
|
95
|
-
LIST_ITEM_NAME,
|
|
96
|
-
LIST_NAME,
|
|
97
|
-
List,
|
|
98
|
-
ListItem,
|
|
99
|
-
ListItemCollapsibleContent,
|
|
100
|
-
ListItemHeading,
|
|
101
|
-
ListItemOpenTrigger,
|
|
102
|
-
createListItemScope,
|
|
103
|
-
createListScope,
|
|
104
|
-
useListContext,
|
|
105
|
-
useListItemContext
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/List.tsx", "../../../src/ListItem.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\n// Elemental list / listbox primitive.\n//\n// This is the ARIA-only foundation of the DXOS list stack. It renders a\n// semantically-correct `<ol>` / `<ul>` (or, when `selectable={true}`, a\n// `role=\"listbox\"` element with `role=\"option\"` children carrying\n// `aria-selected`). It applies no styling, no keyboard navigation, and\n// no `dx-*` utility classes — those are layered above in\n// `@dxos/react-ui-list`.\n//\n// Layering:\n// - `@dxos/react-list` — this package; ARIA + structure only.\n// - `@dxos/react-ui-list` — adds `dx-*` styling, keyboard nav, and\n// opinionated containers (Listbox, OrderedList,\n// Tree, Accordion, Combobox, Picker) plus the\n// reusable navigation/selection/disclosure aspects.\n// - `@dxos/react-ui-mosaic` — virtualized / draggable / card-board\n// layouts; composes the above where useful.\n//\n// Most app code should reach for `@dxos/react-ui-list`. Use this primitive\n// directly only when building a *new* selectable surface that needs full\n// control over styling and keyboard handling (e.g. a custom Combobox).\n//\n// See:\n// - `packages/ui/ui-theme/src/css/components/state.md` for the\n// `aria-selected` ↔ `dx-selected` pairing rules.\n// - `packages/ui/react-ui-list/AUDIT.md` for why this layering exists.\n// - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\n\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport React, { type ComponentPropsWithRef, forwardRef } from 'react';\n\nconst LIST_NAME = 'List';\n\ntype ListScopedProps<P> = P & { __listScope?: Scope };\n\ntype ListVariant = 'ordered' | 'unordered';\n\ntype ListItemSizes = 'one' | 'many';\n\ntype ListProps = ComponentPropsWithRef<typeof Primitive.ol> & {\n /**\n * If true, render as `role=\"listbox\"` and let `ListItem` children become\n * `role=\"option\"` + `aria-selected`. If false (default) the list is a\n * plain `<ol>` / `<ul>` with no selection semantics — pick this for\n * static lists.\n */\n selectable?: boolean;\n /**\n * If true, the listbox advertises multi-select via\n * `aria-multiselectable=\"true\"`. Defaults to false (single-select).\n * Has no effect unless `selectable` is also true.\n */\n multiSelectable?: boolean;\n variant?: ListVariant;\n itemSizes?: ListItemSizes;\n};\n\nconst [createListContext, createListScope] = createContextScope(LIST_NAME, []);\n\ntype ListContextValue = {\n selectable: Exclude<ListProps['selectable'], undefined>;\n variant: Exclude<ListProps['variant'], undefined>;\n itemSizes?: ListItemSizes;\n};\n\nconst [ListProvider, useListContext] = createListContext<ListContextValue>(LIST_NAME);\n\nconst List = forwardRef<HTMLOListElement, ListProps>((props: ListScopedProps<ListProps>, forwardedRef) => {\n const {\n __listScope,\n variant = 'ordered',\n selectable = false,\n multiSelectable = false,\n itemSizes,\n children,\n ...rootProps\n } = props;\n const ListRoot = variant === 'ordered' ? Primitive.ol : Primitive.ul;\n return (\n <ListRoot\n // `aria-multiselectable` is only meaningful on `role=\"listbox\"`,\n // and even there is omitted in the single-select default to keep\n // assistive tech announcements concise.\n {...(selectable && {\n role: 'listbox',\n ...(multiSelectable && { 'aria-multiselectable': true as const }),\n })}\n {...rootProps}\n ref={forwardedRef}\n >\n <ListProvider\n {...{\n scope: __listScope,\n variant,\n selectable,\n itemSizes,\n }}\n >\n {children}\n </ListProvider>\n </ListRoot>\n );\n});\n\nList.displayName = LIST_NAME;\n\nexport { List, LIST_NAME, createListScope, useListContext };\n\nexport type { ListProps, ListScopedProps, ListVariant };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { type CollapsibleContentProps, type CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n type ComponentProps,\n type ComponentPropsWithoutRef,\n type ComponentRef,\n type Dispatch,\n type ForwardRefExoticComponent,\n type RefAttributes,\n type SetStateAction,\n forwardRef,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, type ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n labelId?: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & RefAttributes<HTMLLIElement> &\n ComponentPropsWithoutRef<'li'> & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = ComponentRef<'li'>;\n\nconst [createListItemContext, createListItemScope] = createContextScope(LIST_ITEM_NAME, []);\n\ntype ListItemContextValue = {\n headingId: string;\n open: boolean;\n selected: CheckboxProps['checked'];\n setSelected: Dispatch<SetStateAction<CheckboxProps['checked']>>;\n};\n\nconst [ListItemProvider, useListItemContext] = createListItemContext<ListItemContextValue>(LIST_ITEM_NAME);\n\ntype ListItemHeadingProps = ListItemScopedProps<Omit<ComponentPropsWithoutRef<'p'>, 'id'>> &\n RefAttributes<HTMLParagraphElement> & {\n asChild?: boolean;\n };\n\nconst ListItemHeading = forwardRef<HTMLDivElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Comp = asChild ? Slot : Primitive.div;\n return (\n <Comp {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Comp>\n );\n },\n);\n\ntype ListItemOpenTriggerProps = ListItemScopedProps<CollapsibleTriggerProps>;\n\nconst ListItemOpenTrigger = Collapsible.Trigger;\n\ntype ListItemCollapsibleContentProps = ComponentProps<typeof Collapsible.Content>;\n\nconst ListItemCollapsibleContent: ForwardRefExoticComponent<CollapsibleContentProps> = Collapsible.Content;\n\nconst ListItem = forwardRef<ListItemElement, ListItemProps>(\n (props: ListItemScopedProps<ListScopedProps<ListItemProps>>, forwardedRef) => {\n const id = useId('listItem', props.id);\n\n const {\n __listScope,\n __listItemScope,\n children,\n selected: propsSelected,\n defaultSelected,\n onSelectedChange,\n open: propsOpen,\n defaultOpen,\n onOpenChange,\n collapsible,\n labelId,\n ...listItemProps\n } = props;\n const { selectable } = useListContext(LIST_NAME, __listScope);\n\n const [selected = false, setSelected] = useControllableState({\n prop: propsSelected,\n defaultProp: defaultSelected,\n onChange: onSelectedChange,\n });\n\n const [open = false, setOpen] = useControllableState({\n prop: propsOpen,\n defaultProp: defaultOpen,\n onChange: onOpenChange,\n });\n\n const headingId = useId('listItem__heading', labelId);\n\n const listItem = (\n <Primitive.li\n {...listItemProps}\n id={id}\n ref={forwardedRef}\n aria-labelledby={headingId}\n {...(selectable && { 'role': 'option', 'aria-selected': !!selected })}\n {...(open && { 'aria-expanded': true })}\n >\n {children}\n </Primitive.li>\n );\n\n return (\n <ListItemProvider\n scope={__listItemScope}\n headingId={headingId}\n open={open}\n selected={selected}\n setSelected={setSelected}\n >\n {collapsible ? (\n <Collapsible.Root asChild open={open} onOpenChange={setOpen}>\n {listItem}\n </Collapsible.Root>\n ) : (\n listItem\n )}\n </ListItemProvider>\n );\n },\n);\n\nListItem.displayName = LIST_ITEM_NAME;\n\nexport {\n LIST_ITEM_NAME,\n ListItem,\n ListItemCollapsibleContent,\n ListItemHeading,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n};\n\nexport type {\n ListItemCollapsibleContentProps,\n ListItemHeadingProps,\n ListItemOpenTriggerProps,\n ListItemProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["createContextScope", "Primitive", "React", "forwardRef", "LIST_NAME", "createListContext", "createListScope", "ListProvider", "useListContext", "List", "props", "forwardedRef", "__listScope", "variant", "selectable", "multiSelectable", "itemSizes", "children", "rootProps", "ListRoot", "ol", "ul", "role", "ref", "scope", "displayName", "Collapsible", "createContextScope", "Primitive", "Slot", "useControllableState", "React", "forwardRef", "useId", "LIST_ITEM_NAME", "createListItemContext", "createListItemScope", "createContextScope", "ListItemProvider", "useListItemContext", "ListItemHeading", "forwardRef", "children", "asChild", "__listItemScope", "props", "forwardedRef", "headingId", "Comp", "Slot", "Primitive", "div", "React", "id", "ref", "ListItemOpenTrigger", "Trigger", "ListItemCollapsibleContent", "Content", "ListItem", "useId", "__listScope", "selected", "propsSelected", "defaultSelected", "onSelectedChange", "open", "propsOpen", "defaultOpen", "onOpenChange", "collapsible", "labelId", "listItemProps", "selectable", "useListContext", "LIST_NAME", "setSelected", "useControllableState", "prop", "defaultProp", "onChange", "setOpen", "listItem", "li", "aria-labelledby", "scope", "Root", "displayName"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"inputs":{"src/List.tsx":{"bytes":10080,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"src/ListItem.tsx":{"bytes":12912,"imports":[{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true},{"path":"src/List.tsx","kind":"import-statement","original":"./List"}],"format":"esm"},"src/index.ts":{"bytes":456,"imports":[{"path":"src/List.tsx","kind":"import-statement","original":"./List"},{"path":"src/ListItem.tsx","kind":"import-statement","original":"./ListItem"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12459},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@radix-ui/react-collapsible","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-primitive","kind":"import-statement","external":true},{"path":"@radix-ui/react-slot","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-hooks","kind":"import-statement","external":true}],"exports":["LIST_ITEM_NAME","LIST_NAME","List","ListItem","ListItemCollapsibleContent","ListItemHeading","ListItemOpenTrigger","createListItemScope","createListScope","useListContext","useListItemContext"],"entryPoint":"src/index.ts","inputs":{"src/List.tsx":{"bytesInOutput":1000},"src/index.ts":{"bytesInOutput":0},"src/ListItem.tsx":{"bytesInOutput":2530}},"bytes":3911}}}
|