@behivetech/atoms.dropdown-menu 0.0.0-stage → 0.2.2
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 +24 -2
- package/dist/index.cjs +198 -0
- package/dist/index.css +78 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +184 -0
- package/docs.json +64 -0
- package/dropdown-menu.example.tsx +43 -0
- package/dropdown-menu.module.scss +109 -0
- package/dropdown-menu.tsx +75 -0
- package/index.ts +2 -0
- package/package.json +59 -3
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# DropdownMenu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TODO: Add component description.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import { DropdownMenu } from "@behivetech/atoms.dropdown-menu";
|
|
9
|
+
import { Button } from "@behivetech/atoms.button";
|
|
10
|
+
|
|
11
|
+
function Example() {
|
|
12
|
+
const items = [
|
|
13
|
+
{ id: "edit", label: "Edit" },
|
|
14
|
+
{ id: "duplicate", label: "Duplicate" },
|
|
15
|
+
{ id: "delete", label: "Delete", disabled: true },
|
|
16
|
+
];
|
|
17
|
+
return (
|
|
18
|
+
<DropdownMenu
|
|
19
|
+
trigger={<Button variant="secondary">Actions</Button>}
|
|
20
|
+
items={items}
|
|
21
|
+
onSelect={(id) => alert(id)}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
34
|
+
var require_classnames = __commonJS({
|
|
35
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
(function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
var hasOwn = {}.hasOwnProperty;
|
|
40
|
+
function classNames() {
|
|
41
|
+
var classes = "";
|
|
42
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
43
|
+
var arg = arguments[i];
|
|
44
|
+
if (arg) {
|
|
45
|
+
classes = appendClass(classes, parseValue(arg));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return classes;
|
|
49
|
+
}
|
|
50
|
+
function parseValue(arg) {
|
|
51
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
52
|
+
return arg;
|
|
53
|
+
}
|
|
54
|
+
if (typeof arg !== "object") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(arg)) {
|
|
58
|
+
return classNames.apply(null, arg);
|
|
59
|
+
}
|
|
60
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
61
|
+
return arg.toString();
|
|
62
|
+
}
|
|
63
|
+
var classes = "";
|
|
64
|
+
for (var key in arg) {
|
|
65
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
66
|
+
classes = appendClass(classes, key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return classes;
|
|
70
|
+
}
|
|
71
|
+
function appendClass(value, newClass) {
|
|
72
|
+
if (!newClass) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
if (value) {
|
|
76
|
+
return value + " " + newClass;
|
|
77
|
+
}
|
|
78
|
+
return value + newClass;
|
|
79
|
+
}
|
|
80
|
+
if (typeof module2 !== "undefined" && module2.exports) {
|
|
81
|
+
classNames.default = classNames;
|
|
82
|
+
module2.exports = classNames;
|
|
83
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
84
|
+
define("classnames", [], function() {
|
|
85
|
+
return classNames;
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
window.classNames = classNames;
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// index.ts
|
|
95
|
+
var index_exports = {};
|
|
96
|
+
__export(index_exports, {
|
|
97
|
+
DropdownMenu: () => DropdownMenu
|
|
98
|
+
});
|
|
99
|
+
module.exports = __toCommonJS(index_exports);
|
|
100
|
+
|
|
101
|
+
// dropdown-menu.tsx
|
|
102
|
+
var RadixDropdownMenu = __toESM(require("@radix-ui/react-dropdown-menu"), 1);
|
|
103
|
+
|
|
104
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
105
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
106
|
+
var getClassName = ({
|
|
107
|
+
className,
|
|
108
|
+
modifiers = {},
|
|
109
|
+
rootClass,
|
|
110
|
+
styles = {}
|
|
111
|
+
}) => {
|
|
112
|
+
function getModifiers() {
|
|
113
|
+
const updatedModifiers = {};
|
|
114
|
+
const modifierKeys = Object.keys(modifiers);
|
|
115
|
+
if (modifierKeys.length) {
|
|
116
|
+
modifierKeys.forEach((modKey) => {
|
|
117
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
118
|
+
const newClassName = styles[classKey] || classKey;
|
|
119
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return updatedModifiers;
|
|
123
|
+
}
|
|
124
|
+
function getChildClass(childClassName) {
|
|
125
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
126
|
+
return styles[classKey] || classKey;
|
|
127
|
+
}
|
|
128
|
+
function getRootStyles() {
|
|
129
|
+
return (0, import_classnames.default)(
|
|
130
|
+
className,
|
|
131
|
+
{
|
|
132
|
+
...getModifiers()
|
|
133
|
+
},
|
|
134
|
+
styles[rootClass] || rootClass
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return [getRootStyles(), getChildClass];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// dropdown-menu.module.scss
|
|
141
|
+
var dropdown_menu_module_default = {
|
|
142
|
+
"BHT__DropdownMenu__content": "BHT__DropdownMenu__content",
|
|
143
|
+
"dropdown-menu-in": "dropdown-menu-in",
|
|
144
|
+
"dropdown-menu-out": "dropdown-menu-out",
|
|
145
|
+
"BHT__DropdownMenu__item": "BHT__DropdownMenu__item"
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// dropdown-menu.tsx
|
|
149
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
150
|
+
var DropdownMenu = ({
|
|
151
|
+
trigger,
|
|
152
|
+
items,
|
|
153
|
+
onSelect,
|
|
154
|
+
open,
|
|
155
|
+
onOpenChange,
|
|
156
|
+
align = "start",
|
|
157
|
+
className
|
|
158
|
+
}) => {
|
|
159
|
+
const [, getChildClass] = getClassName({
|
|
160
|
+
className,
|
|
161
|
+
rootClass: "BHT__DropdownMenu",
|
|
162
|
+
styles: dropdown_menu_module_default
|
|
163
|
+
});
|
|
164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RadixDropdownMenu.Root, { open, onOpenChange, children: [
|
|
165
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixDropdownMenu.Trigger, { asChild: true, children: trigger }),
|
|
166
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixDropdownMenu.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
167
|
+
RadixDropdownMenu.Content,
|
|
168
|
+
{
|
|
169
|
+
className: getChildClass("content"),
|
|
170
|
+
align,
|
|
171
|
+
sideOffset: 4,
|
|
172
|
+
children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
173
|
+
RadixDropdownMenu.Item,
|
|
174
|
+
{
|
|
175
|
+
disabled: item.disabled,
|
|
176
|
+
className: getChildClass("item"),
|
|
177
|
+
onSelect: () => onSelect(item.id),
|
|
178
|
+
children: item.label
|
|
179
|
+
},
|
|
180
|
+
item.id
|
|
181
|
+
))
|
|
182
|
+
}
|
|
183
|
+
) })
|
|
184
|
+
] });
|
|
185
|
+
};
|
|
186
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
+
0 && (module.exports = {
|
|
188
|
+
DropdownMenu
|
|
189
|
+
});
|
|
190
|
+
/*! Bundled license information:
|
|
191
|
+
|
|
192
|
+
classnames/index.js:
|
|
193
|
+
(*!
|
|
194
|
+
Copyright (c) 2018 Jed Watson.
|
|
195
|
+
Licensed under the MIT License (MIT), see
|
|
196
|
+
http://jedwatson.github.io/classnames
|
|
197
|
+
*)
|
|
198
|
+
*/
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/* esbuild-sass-plugin:css-chunkdropdown-menu.module.scss */
|
|
2
|
+
.BHT__DropdownMenu__content {
|
|
3
|
+
min-width: 11.25rem;
|
|
4
|
+
background: var(--md-sys-color-surface-container, var(--color-surface-raised));
|
|
5
|
+
border-radius: var(--md-sys-shape-corner-extra-small, 4px);
|
|
6
|
+
box-shadow: var(--md-sys-elevation-2, var(--shadow-md));
|
|
7
|
+
padding: var(--spacing-1, 0.25rem);
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
z-index: var(--z-dropdown, 450);
|
|
10
|
+
}
|
|
11
|
+
.BHT__DropdownMenu__content[data-state=open] {
|
|
12
|
+
animation: dropdown-menu-in var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard-decelerate, ease-out);
|
|
13
|
+
}
|
|
14
|
+
.BHT__DropdownMenu__content[data-state=closed] {
|
|
15
|
+
animation: dropdown-menu-out var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard-accelerate, ease-in);
|
|
16
|
+
}
|
|
17
|
+
.BHT__DropdownMenu__item {
|
|
18
|
+
position: relative;
|
|
19
|
+
isolation: isolate;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
padding: var(--spacing-2, 0.5rem) var(--spacing-3, 0.75rem);
|
|
23
|
+
border-radius: var(--md-sys-shape-corner-extra-small, 4px);
|
|
24
|
+
font-family: var(--md-sys-typescale-label-large-font, var(--font-body));
|
|
25
|
+
font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
|
26
|
+
font-weight: var(--md-sys-typescale-label-large-weight, 500);
|
|
27
|
+
line-height: var(--md-sys-typescale-label-large-line-height, 1.25rem);
|
|
28
|
+
letter-spacing: var(--md-sys-typescale-label-large-tracking, 0.0071em);
|
|
29
|
+
color: var(--md-sys-color-on-surface, var(--color-on-surface));
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
user-select: none;
|
|
32
|
+
outline: none;
|
|
33
|
+
}
|
|
34
|
+
.BHT__DropdownMenu__item::after {
|
|
35
|
+
content: "";
|
|
36
|
+
position: absolute;
|
|
37
|
+
inset: 0;
|
|
38
|
+
border-radius: inherit;
|
|
39
|
+
background: currentColor;
|
|
40
|
+
opacity: 0;
|
|
41
|
+
pointer-events: none;
|
|
42
|
+
transition: opacity var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard, ease);
|
|
43
|
+
}
|
|
44
|
+
.BHT__DropdownMenu__item[data-highlighted]::after {
|
|
45
|
+
opacity: var(--md-sys-state-hover-opacity, 0.08);
|
|
46
|
+
}
|
|
47
|
+
.BHT__DropdownMenu__item:active::after {
|
|
48
|
+
opacity: var(--md-sys-state-pressed-opacity, 0.1);
|
|
49
|
+
}
|
|
50
|
+
.BHT__DropdownMenu__item:focus-visible {
|
|
51
|
+
outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
|
|
52
|
+
outline-offset: -3px;
|
|
53
|
+
}
|
|
54
|
+
.BHT__DropdownMenu__item[data-disabled] {
|
|
55
|
+
opacity: 0.4;
|
|
56
|
+
cursor: not-allowed;
|
|
57
|
+
pointer-events: none;
|
|
58
|
+
}
|
|
59
|
+
@keyframes dropdown-menu-in {
|
|
60
|
+
from {
|
|
61
|
+
opacity: 0;
|
|
62
|
+
transform: translateY(-0.25rem);
|
|
63
|
+
}
|
|
64
|
+
to {
|
|
65
|
+
opacity: 1;
|
|
66
|
+
transform: translateY(0);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
@keyframes dropdown-menu-out {
|
|
70
|
+
from {
|
|
71
|
+
opacity: 1;
|
|
72
|
+
transform: translateY(0);
|
|
73
|
+
}
|
|
74
|
+
to {
|
|
75
|
+
opacity: 0;
|
|
76
|
+
transform: translateY(-0.25rem);
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface DropdownMenuItem {
|
|
5
|
+
/** Unique identifier for this item, passed to onSelect */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Text shown for this item */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Prevents this item from being selected */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface DropdownMenuProps {
|
|
13
|
+
/** Element that opens the menu when activated — receives the trigger's props via Radix's `asChild` */
|
|
14
|
+
trigger: ReactNode;
|
|
15
|
+
/** Items rendered in the menu */
|
|
16
|
+
items: DropdownMenuItem[];
|
|
17
|
+
/** Called with the selected item's id when an item is chosen */
|
|
18
|
+
onSelect: (id: string) => void;
|
|
19
|
+
/** Controlled open state */
|
|
20
|
+
open?: boolean;
|
|
21
|
+
/** Called when the open state changes (trigger click, item select, outside click, Escape) */
|
|
22
|
+
onOpenChange?: (open: boolean) => void;
|
|
23
|
+
/** Alignment of the menu relative to the trigger; defaults to "start" */
|
|
24
|
+
align?: "start" | "center" | "end";
|
|
25
|
+
/** Additional class names to merge with the menu content element */
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A trigger element that opens a list of selectable items, built on Radix's
|
|
30
|
+
* `DropdownMenu` for focus management, keyboard navigation, and outside-click/
|
|
31
|
+
* Escape-to-close.
|
|
32
|
+
*/
|
|
33
|
+
declare const DropdownMenu: ({ trigger, items, onSelect, open, onOpenChange, align, className, }: DropdownMenuProps) => react.JSX.Element;
|
|
34
|
+
|
|
35
|
+
export { DropdownMenu, type DropdownMenuItem, type DropdownMenuProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
28
|
+
var require_classnames = __commonJS({
|
|
29
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
(function() {
|
|
32
|
+
"use strict";
|
|
33
|
+
var hasOwn = {}.hasOwnProperty;
|
|
34
|
+
function classNames() {
|
|
35
|
+
var classes = "";
|
|
36
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
37
|
+
var arg = arguments[i];
|
|
38
|
+
if (arg) {
|
|
39
|
+
classes = appendClass(classes, parseValue(arg));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return classes;
|
|
43
|
+
}
|
|
44
|
+
function parseValue(arg) {
|
|
45
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
46
|
+
return arg;
|
|
47
|
+
}
|
|
48
|
+
if (typeof arg !== "object") {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(arg)) {
|
|
52
|
+
return classNames.apply(null, arg);
|
|
53
|
+
}
|
|
54
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
55
|
+
return arg.toString();
|
|
56
|
+
}
|
|
57
|
+
var classes = "";
|
|
58
|
+
for (var key in arg) {
|
|
59
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
60
|
+
classes = appendClass(classes, key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return classes;
|
|
64
|
+
}
|
|
65
|
+
function appendClass(value, newClass) {
|
|
66
|
+
if (!newClass) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
if (value) {
|
|
70
|
+
return value + " " + newClass;
|
|
71
|
+
}
|
|
72
|
+
return value + newClass;
|
|
73
|
+
}
|
|
74
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
75
|
+
classNames.default = classNames;
|
|
76
|
+
module.exports = classNames;
|
|
77
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
78
|
+
define("classnames", [], function() {
|
|
79
|
+
return classNames;
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
window.classNames = classNames;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// dropdown-menu.tsx
|
|
89
|
+
import * as RadixDropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
90
|
+
|
|
91
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
92
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
93
|
+
var getClassName = ({
|
|
94
|
+
className,
|
|
95
|
+
modifiers = {},
|
|
96
|
+
rootClass,
|
|
97
|
+
styles = {}
|
|
98
|
+
}) => {
|
|
99
|
+
function getModifiers() {
|
|
100
|
+
const updatedModifiers = {};
|
|
101
|
+
const modifierKeys = Object.keys(modifiers);
|
|
102
|
+
if (modifierKeys.length) {
|
|
103
|
+
modifierKeys.forEach((modKey) => {
|
|
104
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
105
|
+
const newClassName = styles[classKey] || classKey;
|
|
106
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return updatedModifiers;
|
|
110
|
+
}
|
|
111
|
+
function getChildClass(childClassName) {
|
|
112
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
113
|
+
return styles[classKey] || classKey;
|
|
114
|
+
}
|
|
115
|
+
function getRootStyles() {
|
|
116
|
+
return (0, import_classnames.default)(
|
|
117
|
+
className,
|
|
118
|
+
{
|
|
119
|
+
...getModifiers()
|
|
120
|
+
},
|
|
121
|
+
styles[rootClass] || rootClass
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return [getRootStyles(), getChildClass];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// dropdown-menu.module.scss
|
|
128
|
+
var dropdown_menu_module_default = {
|
|
129
|
+
"BHT__DropdownMenu__content": "BHT__DropdownMenu__content",
|
|
130
|
+
"dropdown-menu-in": "dropdown-menu-in",
|
|
131
|
+
"dropdown-menu-out": "dropdown-menu-out",
|
|
132
|
+
"BHT__DropdownMenu__item": "BHT__DropdownMenu__item"
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// dropdown-menu.tsx
|
|
136
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
137
|
+
var DropdownMenu = ({
|
|
138
|
+
trigger,
|
|
139
|
+
items,
|
|
140
|
+
onSelect,
|
|
141
|
+
open,
|
|
142
|
+
onOpenChange,
|
|
143
|
+
align = "start",
|
|
144
|
+
className
|
|
145
|
+
}) => {
|
|
146
|
+
const [, getChildClass] = getClassName({
|
|
147
|
+
className,
|
|
148
|
+
rootClass: "BHT__DropdownMenu",
|
|
149
|
+
styles: dropdown_menu_module_default
|
|
150
|
+
});
|
|
151
|
+
return /* @__PURE__ */ jsxs(RadixDropdownMenu.Root, { open, onOpenChange, children: [
|
|
152
|
+
/* @__PURE__ */ jsx(RadixDropdownMenu.Trigger, { asChild: true, children: trigger }),
|
|
153
|
+
/* @__PURE__ */ jsx(RadixDropdownMenu.Portal, { children: /* @__PURE__ */ jsx(
|
|
154
|
+
RadixDropdownMenu.Content,
|
|
155
|
+
{
|
|
156
|
+
className: getChildClass("content"),
|
|
157
|
+
align,
|
|
158
|
+
sideOffset: 4,
|
|
159
|
+
children: items.map((item) => /* @__PURE__ */ jsx(
|
|
160
|
+
RadixDropdownMenu.Item,
|
|
161
|
+
{
|
|
162
|
+
disabled: item.disabled,
|
|
163
|
+
className: getChildClass("item"),
|
|
164
|
+
onSelect: () => onSelect(item.id),
|
|
165
|
+
children: item.label
|
|
166
|
+
},
|
|
167
|
+
item.id
|
|
168
|
+
))
|
|
169
|
+
}
|
|
170
|
+
) })
|
|
171
|
+
] });
|
|
172
|
+
};
|
|
173
|
+
export {
|
|
174
|
+
DropdownMenu
|
|
175
|
+
};
|
|
176
|
+
/*! Bundled license information:
|
|
177
|
+
|
|
178
|
+
classnames/index.js:
|
|
179
|
+
(*!
|
|
180
|
+
Copyright (c) 2018 Jed Watson.
|
|
181
|
+
Licensed under the MIT License (MIT), see
|
|
182
|
+
http://jedwatson.github.io/classnames
|
|
183
|
+
*)
|
|
184
|
+
*/
|
package/docs.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"generatedAt": "2026-10-20T05:49:31.297Z",
|
|
5
|
+
"docs": [
|
|
6
|
+
{
|
|
7
|
+
"displayName": "DropdownMenu",
|
|
8
|
+
"description": "A trigger element that opens a list of selectable items, built on Radix's\n`DropdownMenu` for focus management, keyboard navigation, and outside-click/\nEscape-to-close.",
|
|
9
|
+
"extendsNative": false,
|
|
10
|
+
"props": [
|
|
11
|
+
{
|
|
12
|
+
"name": "items",
|
|
13
|
+
"type": "DropdownMenuItem[]",
|
|
14
|
+
"required": true,
|
|
15
|
+
"defaultValue": null,
|
|
16
|
+
"description": "Items rendered in the menu"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "onSelect",
|
|
20
|
+
"type": "(id: string) => void",
|
|
21
|
+
"required": true,
|
|
22
|
+
"defaultValue": null,
|
|
23
|
+
"description": "Called with the selected item's id when an item is chosen"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "trigger",
|
|
27
|
+
"type": "ReactNode",
|
|
28
|
+
"required": true,
|
|
29
|
+
"defaultValue": null,
|
|
30
|
+
"description": "Element that opens the menu when activated — receives the trigger's props via Radix's `asChild`"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "align",
|
|
34
|
+
"type": "\"start\" | \"center\" | \"end\"",
|
|
35
|
+
"required": false,
|
|
36
|
+
"defaultValue": "start",
|
|
37
|
+
"description": "Alignment of the menu relative to the trigger; defaults to \"start\""
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "className",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"required": false,
|
|
43
|
+
"defaultValue": null,
|
|
44
|
+
"description": "Additional class names to merge with the menu content element"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "onOpenChange",
|
|
48
|
+
"type": "((open: boolean) => void)",
|
|
49
|
+
"required": false,
|
|
50
|
+
"defaultValue": null,
|
|
51
|
+
"description": "Called when the open state changes (trigger click, item select, outside click, Escape)"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "open",
|
|
55
|
+
"type": "boolean",
|
|
56
|
+
"required": false,
|
|
57
|
+
"defaultValue": null,
|
|
58
|
+
"description": "Controlled open state"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"functions": []
|
|
64
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { DropdownMenu } from "./dropdown-menu.js";
|
|
3
|
+
|
|
4
|
+
const siteItems = [
|
|
5
|
+
{ id: "site-1", label: "My Behive Site" },
|
|
6
|
+
{ id: "site-2", label: "Second Site" },
|
|
7
|
+
{ id: "site-3", label: "Archived Site", disabled: true },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
export const BasicDropdownMenu = () => {
|
|
11
|
+
const [selected, setSelected] = useState("site-1");
|
|
12
|
+
const selectedLabel = siteItems.find((item) => item.id === selected)?.label;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<DropdownMenu
|
|
16
|
+
trigger={<button type="button">{selectedLabel} ▾</button>}
|
|
17
|
+
items={siteItems}
|
|
18
|
+
onSelect={setSelected}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const ControlledDropdownMenu = () => {
|
|
24
|
+
const [open, setOpen] = useState(false);
|
|
25
|
+
const [selected, setSelected] = useState("site-1");
|
|
26
|
+
const selectedLabel = siteItems.find((item) => item.id === selected)?.label;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<p>Selected: {selectedLabel}</p>
|
|
31
|
+
<DropdownMenu
|
|
32
|
+
trigger={<button type="button">Toggle menu</button>}
|
|
33
|
+
items={siteItems}
|
|
34
|
+
open={open}
|
|
35
|
+
onOpenChange={setOpen}
|
|
36
|
+
onSelect={(id) => {
|
|
37
|
+
setSelected(id);
|
|
38
|
+
setOpen(false);
|
|
39
|
+
}}
|
|
40
|
+
/>
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Material Design 3 menu. Each color falls back to the pre-MD3 `--color-*`
|
|
2
|
+
// name, which `cms.base-styles` aliases to the matching MD3 role.
|
|
3
|
+
|
|
4
|
+
.BHT__DropdownMenu {
|
|
5
|
+
&__content {
|
|
6
|
+
min-width: 11.25rem;
|
|
7
|
+
background: var(
|
|
8
|
+
--md-sys-color-surface-container,
|
|
9
|
+
var(--color-surface-raised)
|
|
10
|
+
);
|
|
11
|
+
// No outline: MD3 menus separate from the page by tone and elevation.
|
|
12
|
+
border-radius: var(--md-sys-shape-corner-extra-small, 4px);
|
|
13
|
+
box-shadow: var(--md-sys-elevation-2, var(--shadow-md));
|
|
14
|
+
padding: var(--spacing-1, 0.25rem);
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
// Portaled to document.body — see select.module.scss; the fallback has to
|
|
17
|
+
// clear --z-modal (400) and --z-sticky (200), not sit under them.
|
|
18
|
+
z-index: var(--z-dropdown, 450);
|
|
19
|
+
|
|
20
|
+
&[data-state="open"] {
|
|
21
|
+
animation: dropdown-menu-in var(--md-sys-motion-duration-short-3, 150ms)
|
|
22
|
+
var(--md-sys-motion-easing-standard-decelerate, ease-out);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&[data-state="closed"] {
|
|
26
|
+
animation: dropdown-menu-out var(--md-sys-motion-duration-short-2, 100ms)
|
|
27
|
+
var(--md-sys-motion-easing-standard-accelerate, ease-in);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&__item {
|
|
32
|
+
position: relative;
|
|
33
|
+
isolation: isolate;
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
padding: var(--spacing-2, 0.5rem) var(--spacing-3, 0.75rem);
|
|
37
|
+
border-radius: var(--md-sys-shape-corner-extra-small, 4px);
|
|
38
|
+
font-family: var(--md-sys-typescale-label-large-font, var(--font-body));
|
|
39
|
+
font-size: var(--md-sys-typescale-label-large-size, 0.875rem);
|
|
40
|
+
font-weight: var(--md-sys-typescale-label-large-weight, 500);
|
|
41
|
+
line-height: var(--md-sys-typescale-label-large-line-height, 1.25rem);
|
|
42
|
+
letter-spacing: var(--md-sys-typescale-label-large-tracking, 0.0071em);
|
|
43
|
+
color: var(--md-sys-color-on-surface, var(--color-on-surface));
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
user-select: none;
|
|
46
|
+
outline: none;
|
|
47
|
+
|
|
48
|
+
// State layer. Radix sets `data-highlighted` for both pointer hover and
|
|
49
|
+
// keyboard navigation, so it stands in for :hover here.
|
|
50
|
+
&::after {
|
|
51
|
+
content: "";
|
|
52
|
+
position: absolute;
|
|
53
|
+
inset: 0;
|
|
54
|
+
border-radius: inherit;
|
|
55
|
+
background: currentColor;
|
|
56
|
+
opacity: 0;
|
|
57
|
+
pointer-events: none;
|
|
58
|
+
transition: opacity var(--md-sys-motion-duration-short-2, 100ms)
|
|
59
|
+
var(--md-sys-motion-easing-standard, ease);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&[data-highlighted]::after {
|
|
63
|
+
opacity: var(--md-sys-state-hover-opacity, 0.08);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&:active::after {
|
|
67
|
+
opacity: var(--md-sys-state-pressed-opacity, 0.1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The state layer alone is a faint keyboard cue, so keyboard focus also
|
|
71
|
+
// gets the ring. Inset because the content's `overflow: hidden` would clip
|
|
72
|
+
// an outer ring on the first and last items.
|
|
73
|
+
&:focus-visible {
|
|
74
|
+
outline: 3px solid
|
|
75
|
+
var(--md-sys-color-secondary, var(--color-border-focus));
|
|
76
|
+
outline-offset: -3px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&[data-disabled] {
|
|
80
|
+
opacity: 0.4;
|
|
81
|
+
cursor: not-allowed;
|
|
82
|
+
pointer-events: none;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@keyframes dropdown-menu-in {
|
|
88
|
+
from {
|
|
89
|
+
opacity: 0;
|
|
90
|
+
transform: translateY(-0.25rem);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
to {
|
|
94
|
+
opacity: 1;
|
|
95
|
+
transform: translateY(0);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@keyframes dropdown-menu-out {
|
|
100
|
+
from {
|
|
101
|
+
opacity: 1;
|
|
102
|
+
transform: translateY(0);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
to {
|
|
106
|
+
opacity: 0;
|
|
107
|
+
transform: translateY(-0.25rem);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import * as RadixDropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
3
|
+
import { getClassName } from "@bht-component-registry/class-names";
|
|
4
|
+
import styles from "./dropdown-menu.module.scss";
|
|
5
|
+
|
|
6
|
+
export interface DropdownMenuItem {
|
|
7
|
+
/** Unique identifier for this item, passed to onSelect */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Text shown for this item */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Prevents this item from being selected */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DropdownMenuProps {
|
|
16
|
+
/** Element that opens the menu when activated — receives the trigger's props via Radix's `asChild` */
|
|
17
|
+
trigger: ReactNode;
|
|
18
|
+
/** Items rendered in the menu */
|
|
19
|
+
items: DropdownMenuItem[];
|
|
20
|
+
/** Called with the selected item's id when an item is chosen */
|
|
21
|
+
onSelect: (id: string) => void;
|
|
22
|
+
/** Controlled open state */
|
|
23
|
+
open?: boolean;
|
|
24
|
+
/** Called when the open state changes (trigger click, item select, outside click, Escape) */
|
|
25
|
+
onOpenChange?: (open: boolean) => void;
|
|
26
|
+
/** Alignment of the menu relative to the trigger; defaults to "start" */
|
|
27
|
+
align?: "start" | "center" | "end";
|
|
28
|
+
/** Additional class names to merge with the menu content element */
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A trigger element that opens a list of selectable items, built on Radix's
|
|
34
|
+
* `DropdownMenu` for focus management, keyboard navigation, and outside-click/
|
|
35
|
+
* Escape-to-close.
|
|
36
|
+
*/
|
|
37
|
+
export const DropdownMenu = ({
|
|
38
|
+
trigger,
|
|
39
|
+
items,
|
|
40
|
+
onSelect,
|
|
41
|
+
open,
|
|
42
|
+
onOpenChange,
|
|
43
|
+
align = "start",
|
|
44
|
+
className,
|
|
45
|
+
}: DropdownMenuProps) => {
|
|
46
|
+
const [, getChildClass] = getClassName({
|
|
47
|
+
className,
|
|
48
|
+
rootClass: "BHT__DropdownMenu",
|
|
49
|
+
styles,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<RadixDropdownMenu.Root open={open} onOpenChange={onOpenChange}>
|
|
54
|
+
<RadixDropdownMenu.Trigger asChild>{trigger}</RadixDropdownMenu.Trigger>
|
|
55
|
+
<RadixDropdownMenu.Portal>
|
|
56
|
+
<RadixDropdownMenu.Content
|
|
57
|
+
className={getChildClass("content")}
|
|
58
|
+
align={align}
|
|
59
|
+
sideOffset={4}
|
|
60
|
+
>
|
|
61
|
+
{items.map((item) => (
|
|
62
|
+
<RadixDropdownMenu.Item
|
|
63
|
+
key={item.id}
|
|
64
|
+
disabled={item.disabled}
|
|
65
|
+
className={getChildClass("item")}
|
|
66
|
+
onSelect={() => onSelect(item.id)}
|
|
67
|
+
>
|
|
68
|
+
{item.label}
|
|
69
|
+
</RadixDropdownMenu.Item>
|
|
70
|
+
))}
|
|
71
|
+
</RadixDropdownMenu.Content>
|
|
72
|
+
</RadixDropdownMenu.Portal>
|
|
73
|
+
</RadixDropdownMenu.Root>
|
|
74
|
+
);
|
|
75
|
+
};
|
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behivetech/atoms.dropdown-menu",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./styles.css": "./dist/index.css"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"index.ts",
|
|
19
|
+
"dropdown-menu.tsx",
|
|
20
|
+
"dropdown-menu.module.scss",
|
|
21
|
+
"*.example.tsx",
|
|
22
|
+
"docs.json"
|
|
23
|
+
],
|
|
24
|
+
"registry": {
|
|
25
|
+
"status": "stable",
|
|
26
|
+
"tags": []
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@radix-ui/react-dropdown-menu": "^2.1.24"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^19.2.7",
|
|
33
|
+
"react-dom": "^19.2.7"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "19.2.17",
|
|
37
|
+
"@types/react-dom": "19.2.3",
|
|
38
|
+
"eslint": "^9.39.5",
|
|
39
|
+
"tsup": "^8.5.1",
|
|
40
|
+
"typescript": "^6.0.3",
|
|
41
|
+
"vitest": "^4.1.10",
|
|
42
|
+
"@bht-component-registry/class-names": "0.0.6",
|
|
43
|
+
"@bht-component-registry/env": "0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/behivetech/bht-galaxy.git",
|
|
48
|
+
"directory": "registry/behivetech/atoms/dropdown-menu"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"registry": "https://registry.npmjs.org",
|
|
52
|
+
"access": "public",
|
|
53
|
+
"provenance": true
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup && bht-registry-docgen",
|
|
57
|
+
"dev": "tsup --watch",
|
|
58
|
+
"lint": "eslint . --max-warnings 0",
|
|
59
|
+
"check-types": "tsc --noEmit",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
6
62
|
}
|