@dxos/react-list 0.1.53 → 0.1.54-main.1661511
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.
|
@@ -2,37 +2,25 @@
|
|
|
2
2
|
import { createContextScope } from "@radix-ui/react-context";
|
|
3
3
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
4
4
|
import React, { forwardRef } from "react";
|
|
5
|
-
function _extends() {
|
|
6
|
-
_extends = Object.assign || function(target) {
|
|
7
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
8
|
-
var source = arguments[i];
|
|
9
|
-
for (var key in source) {
|
|
10
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
11
|
-
target[key] = source[key];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return target;
|
|
16
|
-
};
|
|
17
|
-
return _extends.apply(this, arguments);
|
|
18
|
-
}
|
|
19
5
|
var LIST_NAME = "List";
|
|
20
6
|
var [createListContext, createListScope] = createContextScope(LIST_NAME, []);
|
|
21
7
|
var [ListProvider, useListContext] = createListContext(LIST_NAME);
|
|
22
8
|
var List = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
23
9
|
const { __listScope, variant = "ordered", selectable = false, itemSizes, children, ...rootProps } = props;
|
|
24
10
|
const ListRoot = variant === "ordered" ? Primitive.ol : Primitive.ul;
|
|
25
|
-
return /* @__PURE__ */ React.createElement(ListRoot,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
11
|
+
return /* @__PURE__ */ React.createElement(ListRoot, {
|
|
12
|
+
...selectable && {
|
|
13
|
+
role: "listbox",
|
|
14
|
+
"aria-multiselectable": true
|
|
15
|
+
},
|
|
16
|
+
...rootProps,
|
|
29
17
|
ref: forwardedRef
|
|
30
|
-
}
|
|
18
|
+
}, /* @__PURE__ */ React.createElement(ListProvider, {
|
|
31
19
|
scope: __listScope,
|
|
32
20
|
variant,
|
|
33
21
|
selectable,
|
|
34
22
|
itemSizes
|
|
35
|
-
}
|
|
23
|
+
}, children));
|
|
36
24
|
});
|
|
37
25
|
List.displayName = LIST_NAME;
|
|
38
26
|
|
|
@@ -44,30 +32,17 @@ import { Slot } from "@radix-ui/react-slot";
|
|
|
44
32
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
45
33
|
import React2, { forwardRef as forwardRef2 } from "react";
|
|
46
34
|
import { useId } from "@dxos/react-hooks";
|
|
47
|
-
function _extends2() {
|
|
48
|
-
_extends2 = Object.assign || function(target) {
|
|
49
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
50
|
-
var source = arguments[i];
|
|
51
|
-
for (var key in source) {
|
|
52
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
53
|
-
target[key] = source[key];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return target;
|
|
58
|
-
};
|
|
59
|
-
return _extends2.apply(this, arguments);
|
|
60
|
-
}
|
|
61
35
|
var LIST_ITEM_NAME = "ListItem";
|
|
62
36
|
var [createListItemContext, createListItemScope] = createContextScope2(LIST_ITEM_NAME, []);
|
|
63
37
|
var [ListItemProvider, useListItemContext] = createListItemContext(LIST_ITEM_NAME);
|
|
64
38
|
var ListItemHeading = /* @__PURE__ */ forwardRef2(({ children, asChild, __listItemScope, ...props }, forwardedRef) => {
|
|
65
39
|
const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);
|
|
66
40
|
const Root2 = asChild ? Slot : Primitive2.p;
|
|
67
|
-
return /* @__PURE__ */ React2.createElement(Root2,
|
|
41
|
+
return /* @__PURE__ */ React2.createElement(Root2, {
|
|
42
|
+
...props,
|
|
68
43
|
id: headingId,
|
|
69
44
|
ref: forwardedRef
|
|
70
|
-
}
|
|
45
|
+
}, children);
|
|
71
46
|
});
|
|
72
47
|
var ListItemOpenTrigger = Collapsible.Trigger;
|
|
73
48
|
var ListItemCollapsibleContent = Collapsible.Content;
|
|
@@ -86,14 +61,16 @@ var ListItem = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
|
|
|
86
61
|
onChange: onOpenChange
|
|
87
62
|
});
|
|
88
63
|
const headingId = useId("listItem__heading");
|
|
89
|
-
const listItem = /* @__PURE__ */ React2.createElement(Primitive2.li,
|
|
64
|
+
const listItem = /* @__PURE__ */ React2.createElement(Primitive2.li, {
|
|
65
|
+
...listItemProps,
|
|
90
66
|
id,
|
|
91
67
|
ref: forwardedRef,
|
|
92
|
-
"aria-labelledby": headingId
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
68
|
+
"aria-labelledby": headingId,
|
|
69
|
+
...selectable && {
|
|
70
|
+
role: "option",
|
|
71
|
+
"aria-selected": !!selected
|
|
72
|
+
}
|
|
73
|
+
}, children);
|
|
97
74
|
return /* @__PURE__ */ React2.createElement(ListItemProvider, {
|
|
98
75
|
scope: __listItemScope,
|
|
99
76
|
headingId,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/List.tsx", "../../../src/ListItem.tsx"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport React, { ComponentPropsWithRef, forwardRef } from 'react';\n\n// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\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 selectable?: boolean;\n variant?: ListVariant;\n itemSizes?: ListItemSizes;\n};\n\n// LIST\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 { __listScope, variant = 'ordered', selectable = false, itemSizes, children, ...rootProps } = props;\n const ListRoot = variant === 'ordered' ? Primitive.ol : Primitive.ul;\n return (\n <ListRoot {...(selectable && { role: 'listbox', 'aria-multiselectable': true })} {...rootProps} ref={forwardedRef}>\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, createListScope, useListContext, LIST_NAME };\n\nexport type { ListProps, ListVariant, ListScopedProps };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { CollapsibleContentProps, CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { createContextScope, Scope } 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 ComponentProps,\n ComponentPropsWithRef,\n Dispatch,\n forwardRef,\n ForwardRefExoticComponent,\n SetStateAction,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & ComponentPropsWithRef<\n typeof Primitive.li\n > & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = React.ElementRef<typeof Primitive.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<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {\n asChild?: boolean;\n};\n\nconst ListItemHeading = forwardRef<HTMLParagraphElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Root = asChild ? Slot : Primitive.p;\n return (\n <Root {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Root>\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 ...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');\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 >\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 ListItem,\n ListItemHeading,\n ListItemCollapsibleContent,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n LIST_ITEM_NAME,\n};\n\nexport type {\n ListItemProps,\n ListItemHeadingProps,\n ListItemCollapsibleContentProps,\n ListItemOpenTriggerProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,0BAAiC;AAC1C,SAASC,iBAAiB;AAC1B,OAAOC,SAAgCC,kBAAkB;
|
|
6
|
-
"names": ["createContextScope", "Primitive", "React", "forwardRef", "LIST_NAME", "createListContext", "createListScope", "ListProvider", "useListContext", "List", "props", "forwardedRef", "__listScope", "variant", "selectable", "itemSizes", "children", "rootProps", "ListRoot", "ol", "ul", "role", "ref", "scope", "displayName", "Collapsible", "createContextScope", "Primitive", "Slot", "useControllableState", "React", "forwardRef", "useId", "
|
|
5
|
+
"mappings": ";AAIA,SAASA,0BAAiC;AAC1C,SAASC,iBAAiB;AAC1B,OAAOC,SAAgCC,kBAAkB;AAIzD,IAAMC,YAAY;AAgBlB,IAAM,CAACC,mBAAmBC,eAAAA,IAAmBC,mBAAmBH,WAAW,CAAA,CAAE;AAQ7E,IAAM,CAACI,cAAcC,cAAAA,IAAkBJ,kBAAoCD,SAAAA;AAE3E,IAAMM,OAAOC,2BAAwC,CAACC,OAAmCC,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ACAoB,UAAUC,eACVC,iBACAC,kBACAC,MAAMC,WACNC,aACAC,cACAC,aACA,GAAGC,cAAAA,IACD1B;AACJ,QAAM,EAAE2B,WAAU,IAAKC,eAAeC,WAAWb,WAAAA;AAEjD,QAAM,CAACC,WAAW,OAAOa,WAAAA,IAAeC,qBAAqB;IAC3DC,MAAMd;IACNe,aAAad;IACbe,UAAUd;EACZ,CAAA;AAEA,QAAM,CAACC,OAAO,OAAOc,OAAAA,IAAWJ,qBAAqB;IACnDC,MAAMV;IACNW,aAAaV;IACbW,UAAUV;EACZ,CAAA;AAEA,QAAMtB,YAAYa,MAAM,mBAAA;AAExB,QAAMqB,WACJ,gBAAA7B,OAAA,cAACF,WAAUgC,IAAE;IACV,GAAGX;IACJlB;IACAC,KAAKR;IACLqC,mBAAiBpC;IAChB,GAAIyB,cAAc;MAAEY,MAAM;MAAU,iBAAiB,CAAC,CAACtB;IAAS;KAEhEpB,QAAAA;AAIL,SACE,gBAAAU,OAAA,cAACd,kBAAAA;IACC+C,OAAOzC;IACPG;IACAmB;IACAJ;IACAa;KAECL,cACC,gBAAAlB,OAAA,cAAaJ,kBAAI;IAACL,SAAAA;IAAQuB;IAAYG,cAAcW;KACjDC,QAAAA,IAGHA,QAAAA;AAIR,CAAA;AAGFtB,SAAS2B,cAAcpD;",
|
|
6
|
+
"names": ["createContextScope", "Primitive", "React", "forwardRef", "LIST_NAME", "createListContext", "createListScope", "createContextScope", "ListProvider", "useListContext", "List", "forwardRef", "props", "forwardedRef", "__listScope", "variant", "selectable", "itemSizes", "children", "rootProps", "ListRoot", "Primitive", "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", "Root", "Slot", "Primitive", "p", "React", "id", "ref", "ListItemOpenTrigger", "Trigger", "ListItemCollapsibleContent", "Content", "ListItem", "useId", "__listScope", "selected", "propsSelected", "defaultSelected", "onSelectedChange", "open", "propsOpen", "defaultOpen", "onOpenChange", "collapsible", "listItemProps", "selectable", "useListContext", "LIST_NAME", "setSelected", "useControllableState", "prop", "defaultProp", "onChange", "setOpen", "listItem", "li", "aria-labelledby", "role", "scope", "displayName"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":5412,"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}]},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytes":12549,"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":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"}]},"packages/ui/primitives/react-list/src/index.ts":{"bytes":553,"imports":[{"path":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"},{"path":"packages/ui/primitives/react-list/src/ListItem.tsx","kind":"import-statement","original":"./ListItem"}]}},"outputs":{"packages/ui/primitives/react-list/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10003},"packages/ui/primitives/react-list/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":"packages/ui/primitives/react-list/src/index.ts","inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytesInOutput":935},"packages/ui/primitives/react-list/src/index.ts":{"bytesInOutput":0},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytesInOutput":2458}},"bytes":3749}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -48,37 +48,25 @@ module.exports = __toCommonJS(src_exports);
|
|
|
48
48
|
var import_react_context = require("@radix-ui/react-context");
|
|
49
49
|
var import_react_primitive = require("@radix-ui/react-primitive");
|
|
50
50
|
var import_react = __toESM(require("react"));
|
|
51
|
-
function _extends() {
|
|
52
|
-
_extends = Object.assign || function(target) {
|
|
53
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
54
|
-
var source = arguments[i];
|
|
55
|
-
for (var key in source) {
|
|
56
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
57
|
-
target[key] = source[key];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return target;
|
|
62
|
-
};
|
|
63
|
-
return _extends.apply(this, arguments);
|
|
64
|
-
}
|
|
65
51
|
var LIST_NAME = "List";
|
|
66
52
|
var [createListContext, createListScope] = (0, import_react_context.createContextScope)(LIST_NAME, []);
|
|
67
53
|
var [ListProvider, useListContext] = createListContext(LIST_NAME);
|
|
68
54
|
var List = /* @__PURE__ */ (0, import_react.forwardRef)((props, forwardedRef) => {
|
|
69
55
|
const { __listScope, variant = "ordered", selectable = false, itemSizes, children, ...rootProps } = props;
|
|
70
56
|
const ListRoot = variant === "ordered" ? import_react_primitive.Primitive.ol : import_react_primitive.Primitive.ul;
|
|
71
|
-
return /* @__PURE__ */ import_react.default.createElement(ListRoot,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
return /* @__PURE__ */ import_react.default.createElement(ListRoot, {
|
|
58
|
+
...selectable && {
|
|
59
|
+
role: "listbox",
|
|
60
|
+
"aria-multiselectable": true
|
|
61
|
+
},
|
|
62
|
+
...rootProps,
|
|
75
63
|
ref: forwardedRef
|
|
76
|
-
}
|
|
64
|
+
}, /* @__PURE__ */ import_react.default.createElement(ListProvider, {
|
|
77
65
|
scope: __listScope,
|
|
78
66
|
variant,
|
|
79
67
|
selectable,
|
|
80
68
|
itemSizes
|
|
81
|
-
}
|
|
69
|
+
}, children));
|
|
82
70
|
});
|
|
83
71
|
List.displayName = LIST_NAME;
|
|
84
72
|
|
|
@@ -90,30 +78,17 @@ var import_react_slot = require("@radix-ui/react-slot");
|
|
|
90
78
|
var import_react_use_controllable_state = require("@radix-ui/react-use-controllable-state");
|
|
91
79
|
var import_react2 = __toESM(require("react"));
|
|
92
80
|
var import_react_hooks = require("@dxos/react-hooks");
|
|
93
|
-
function _extends2() {
|
|
94
|
-
_extends2 = Object.assign || function(target) {
|
|
95
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
96
|
-
var source = arguments[i];
|
|
97
|
-
for (var key in source) {
|
|
98
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
99
|
-
target[key] = source[key];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return target;
|
|
104
|
-
};
|
|
105
|
-
return _extends2.apply(this, arguments);
|
|
106
|
-
}
|
|
107
81
|
var LIST_ITEM_NAME = "ListItem";
|
|
108
82
|
var [createListItemContext, createListItemScope] = (0, import_react_context2.createContextScope)(LIST_ITEM_NAME, []);
|
|
109
83
|
var [ListItemProvider, useListItemContext] = createListItemContext(LIST_ITEM_NAME);
|
|
110
84
|
var ListItemHeading = /* @__PURE__ */ (0, import_react2.forwardRef)(({ children, asChild, __listItemScope, ...props }, forwardedRef) => {
|
|
111
85
|
const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);
|
|
112
86
|
const Root2 = asChild ? import_react_slot.Slot : import_react_primitive2.Primitive.p;
|
|
113
|
-
return /* @__PURE__ */ import_react2.default.createElement(Root2,
|
|
87
|
+
return /* @__PURE__ */ import_react2.default.createElement(Root2, {
|
|
88
|
+
...props,
|
|
114
89
|
id: headingId,
|
|
115
90
|
ref: forwardedRef
|
|
116
|
-
}
|
|
91
|
+
}, children);
|
|
117
92
|
});
|
|
118
93
|
var ListItemOpenTrigger = Collapsible.Trigger;
|
|
119
94
|
var ListItemCollapsibleContent = Collapsible.Content;
|
|
@@ -132,14 +107,16 @@ var ListItem = /* @__PURE__ */ (0, import_react2.forwardRef)((props, forwardedRe
|
|
|
132
107
|
onChange: onOpenChange
|
|
133
108
|
});
|
|
134
109
|
const headingId = (0, import_react_hooks.useId)("listItem__heading");
|
|
135
|
-
const listItem = /* @__PURE__ */ import_react2.default.createElement(import_react_primitive2.Primitive.li,
|
|
110
|
+
const listItem = /* @__PURE__ */ import_react2.default.createElement(import_react_primitive2.Primitive.li, {
|
|
111
|
+
...listItemProps,
|
|
136
112
|
id,
|
|
137
113
|
ref: forwardedRef,
|
|
138
|
-
"aria-labelledby": headingId
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
114
|
+
"aria-labelledby": headingId,
|
|
115
|
+
...selectable && {
|
|
116
|
+
role: "option",
|
|
117
|
+
"aria-selected": !!selected
|
|
118
|
+
}
|
|
119
|
+
}, children);
|
|
143
120
|
return /* @__PURE__ */ import_react2.default.createElement(ListItemProvider, {
|
|
144
121
|
scope: __listItemScope,
|
|
145
122
|
headingId,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/List.tsx", "../../../src/ListItem.tsx"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nexport * from './List';\nexport * from './ListItem';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContextScope, Scope } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport React, { ComponentPropsWithRef, forwardRef } from 'react';\n\n// TODO(thure): A lot of the accessible affordances for this kind of thing need to be implemented per https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role\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 selectable?: boolean;\n variant?: ListVariant;\n itemSizes?: ListItemSizes;\n};\n\n// LIST\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 { __listScope, variant = 'ordered', selectable = false, itemSizes, children, ...rootProps } = props;\n const ListRoot = variant === 'ordered' ? Primitive.ol : Primitive.ul;\n return (\n <ListRoot {...(selectable && { role: 'listbox', 'aria-multiselectable': true })} {...rootProps} ref={forwardedRef}>\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, createListScope, useListContext, LIST_NAME };\n\nexport type { ListProps, ListVariant, ListScopedProps };\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport type { CheckboxProps } from '@radix-ui/react-checkbox';\nimport { CollapsibleContentProps, CollapsibleTriggerProps } from '@radix-ui/react-collapsible';\nimport * as Collapsible from '@radix-ui/react-collapsible';\nimport { createContextScope, Scope } 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 ComponentProps,\n ComponentPropsWithRef,\n Dispatch,\n forwardRef,\n ForwardRefExoticComponent,\n SetStateAction,\n} from 'react';\n\nimport { useId } from '@dxos/react-hooks';\n\nimport { LIST_NAME, ListScopedProps, useListContext } from './List';\n\nconst LIST_ITEM_NAME = 'ListItem';\n\ntype ListItemScopedProps<P> = P & { __listItemScope?: Scope };\n\ninterface ListItemData {\n id: string;\n selected?: CheckboxProps['checked'];\n open?: boolean;\n}\n\ntype ListItemProps = Omit<ListItemData, 'id'> & { collapsible?: boolean } & ComponentPropsWithRef<\n typeof Primitive.li\n > & {\n defaultOpen?: boolean;\n onOpenChange?: (nextOpen: boolean) => void;\n } & {\n onSelectedChange?: CheckboxProps['onCheckedChange'];\n defaultSelected?: CheckboxProps['defaultChecked'];\n };\n\ntype ListItemElement = React.ElementRef<typeof Primitive.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<ComponentPropsWithRef<typeof Primitive.p>, 'id'>> & {\n asChild?: boolean;\n};\n\nconst ListItemHeading = forwardRef<HTMLParagraphElement, ListItemHeadingProps>(\n ({ children, asChild, __listItemScope, ...props }, forwardedRef) => {\n const { headingId } = useListItemContext(LIST_ITEM_NAME, __listItemScope);\n const Root = asChild ? Slot : Primitive.p;\n return (\n <Root {...props} id={headingId} ref={forwardedRef}>\n {children}\n </Root>\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 ...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');\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 >\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 ListItem,\n ListItemHeading,\n ListItemCollapsibleContent,\n ListItemOpenTrigger,\n createListItemScope,\n useListItemContext,\n LIST_ITEM_NAME,\n};\n\nexport type {\n ListItemProps,\n ListItemHeadingProps,\n ListItemCollapsibleContentProps,\n ListItemOpenTriggerProps,\n ListItemScopedProps,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;ACIA,2BAA0C;AAC1C,6BAA0B;AAC1B,mBAAyD;
|
|
6
|
-
"names": ["LIST_NAME", "createListContext", "createListScope", "createContextScope", "ListProvider", "useListContext", "List", "forwardRef", "props", "forwardedRef", "__listScope", "variant", "selectable", "itemSizes", "children", "rootProps", "ListRoot", "Primitive", "ol", "ul", "React", "role", "ref", "scope", "displayName", "import_react_context", "import_react_primitive", "import_react", "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;ACIA,2BAA0C;AAC1C,6BAA0B;AAC1B,mBAAyD;AAIzD,IAAMA,YAAY;AAgBlB,IAAM,CAACC,mBAAmBC,eAAAA,QAAmBC,yCAAmBH,WAAW,CAAA,CAAE;AAQ7E,IAAM,CAACI,cAAcC,cAAAA,IAAkBJ,kBAAoCD,SAAAA;AAE3E,IAAMM,OAAOC,6CAAwC,CAACC,OAAmCC,iBAAAA;AACvF,QAAM,EAAEC,aAAaC,UAAU,WAAWC,aAAa,OAAOC,WAAWC,UAAU,GAAGC,UAAAA,IAAcP;AACpG,QAAMQ,WAAWL,YAAY,YAAYM,iCAAUC,KAAKD,iCAAUE;AAClE,SACE,6BAAAC,QAAA,cAACJ,UAAAA;IAAU,GAAIJ,cAAc;MAAES,MAAM;MAAW,wBAAwB;IAAK;IAAK,GAAGN;IAAWO,KAAKb;KACnG,6BAAAW,QAAA,cAAChB,cACK;IACFmB,OAAOb;IACPC;IACAC;IACAC;EACF,GAECC,QAAAA,CAAAA;AAIT,CAAA;AAEAR,KAAKkB,cAAcxB;;;ACjDnB,kBAA6B;AAC7B,IAAAyB,wBAA0C;AAC1C,IAAAC,0BAA0B;AAC1B,wBAAqB;AACrB,0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M;MAAU,iBAAiB,CAAC,CAACtB;IAAS;KAEhEpB,QAAAA;AAIL,SACE,8BAAAU,QAAA,cAACd,kBAAAA;IACC+C,OAAOzC;IACPG;IACAmB;IACAJ;IACAa;KAECL,cACC,8BAAAlB,QAAA,cAAaJ,kBAAI;IAACL,SAAAA;IAAQuB;IAAYG,cAAcW;KACjDC,QAAAA,IAGHA,QAAAA;AAIR,CAAA;AAGFtB,SAAS2B,cAAcpD;",
|
|
6
|
+
"names": ["LIST_NAME", "createListContext", "createListScope", "createContextScope", "ListProvider", "useListContext", "List", "forwardRef", "props", "forwardedRef", "__listScope", "variant", "selectable", "itemSizes", "children", "rootProps", "ListRoot", "Primitive", "ol", "ul", "React", "role", "ref", "scope", "displayName", "import_react_context", "import_react_primitive", "import_react", "LIST_ITEM_NAME", "createListItemContext", "createListItemScope", "createContextScope", "ListItemProvider", "useListItemContext", "ListItemHeading", "forwardRef", "children", "asChild", "__listItemScope", "props", "forwardedRef", "headingId", "Root", "Slot", "Primitive", "p", "React", "id", "ref", "ListItemOpenTrigger", "Trigger", "ListItemCollapsibleContent", "Content", "ListItem", "useId", "__listScope", "selected", "propsSelected", "defaultSelected", "onSelectedChange", "open", "propsOpen", "defaultOpen", "onOpenChange", "collapsible", "listItemProps", "selectable", "useListContext", "LIST_NAME", "setSelected", "useControllableState", "prop", "defaultProp", "onChange", "setOpen", "listItem", "li", "aria-labelledby", "role", "scope", "displayName"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"packages/ui/primitives/react-list/src/List.tsx":{"bytes":5412,"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}]},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytes":12549,"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":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"}]},"packages/ui/primitives/react-list/src/index.ts":{"bytes":553,"imports":[{"path":"packages/ui/primitives/react-list/src/List.tsx","kind":"import-statement","original":"./List"},{"path":"packages/ui/primitives/react-list/src/ListItem.tsx","kind":"import-statement","original":"./ListItem"}]}},"outputs":{"packages/ui/primitives/react-list/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10016},"packages/ui/primitives/react-list/dist/lib/node/index.cjs":{"imports":[{"path":"@radix-ui/react-context","kind":"require-call","external":true},{"path":"@radix-ui/react-primitive","kind":"require-call","external":true},{"path":"react","kind":"require-call","external":true},{"path":"@radix-ui/react-collapsible","kind":"require-call","external":true},{"path":"@radix-ui/react-context","kind":"require-call","external":true},{"path":"@radix-ui/react-primitive","kind":"require-call","external":true},{"path":"@radix-ui/react-slot","kind":"require-call","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"require-call","external":true},{"path":"react","kind":"require-call","external":true},{"path":"@dxos/react-hooks","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/ui/primitives/react-list/src/index.ts","inputs":{"packages/ui/primitives/react-list/src/index.ts":{"bytesInOutput":547},"packages/ui/primitives/react-list/src/List.tsx":{"bytesInOutput":1071},"packages/ui/primitives/react-list/src/ListItem.tsx":{"bytesInOutput":2785}},"bytes":6286}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-list",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.54-main.1661511",
|
|
4
4
|
"description": "List primitive components for React.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@radix-ui/react-slot": "^1.0.1",
|
|
23
23
|
"@radix-ui/react-use-controllable-state": "^1.0.0",
|
|
24
24
|
"lodash.omit": "^4.5.0",
|
|
25
|
-
"@dxos/react-hooks": "0.1.
|
|
25
|
+
"@dxos/react-hooks": "0.1.54-main.1661511"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@radix-ui/react-checkbox": "^1.0.3",
|