@yahoo/uds 3.46.1 → 3.47.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/cli/commands/editor-rules.ts +159 -0
- package/cli/rules/config.ts +73 -0
- package/cli/rules/cursor/uds/components.mdc +25 -0
- package/cli/rules/cursor/uds/icons.mdc +8 -0
- package/cli/rules/cursor/uds/tailwind.mdc +9 -0
- package/cli/utils/types.ts +9 -0
- package/dist/client/Menu.cjs +1 -2
- package/dist/client/Menu.js +2 -2
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/cli/FlattenButtonVariant.mock.tsx +0 -17
@@ -0,0 +1,159 @@
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
2
|
+
import { join } from 'node:path';
|
3
|
+
|
4
|
+
import type { Props } from 'bluebun';
|
5
|
+
import { blue, green, print, red, yellow } from 'bluebun';
|
6
|
+
|
7
|
+
import type { EditorConfig } from '../rules/config';
|
8
|
+
import { getAvailableEditors, getEditorConfig, getRuleContent } from '../rules/config';
|
9
|
+
import { trackEvent } from '../utils/analytics';
|
10
|
+
import type { EditorRulesOptions } from '../utils/types';
|
11
|
+
|
12
|
+
interface EditorRulesProps extends Props {
|
13
|
+
options: EditorRulesOptions;
|
14
|
+
}
|
15
|
+
|
16
|
+
export default {
|
17
|
+
name: 'editor-rules',
|
18
|
+
description: '🎯 Generate editor rules for various code editors and AI tools',
|
19
|
+
alias: ['rules', 'editor'],
|
20
|
+
options: {
|
21
|
+
force: {
|
22
|
+
type: 'boolean',
|
23
|
+
description: 'Force overwrite existing rules directory',
|
24
|
+
alias: 'f',
|
25
|
+
},
|
26
|
+
output: {
|
27
|
+
type: 'string',
|
28
|
+
description: 'Output directory (defaults to workspace root)',
|
29
|
+
alias: 'o',
|
30
|
+
},
|
31
|
+
editor: {
|
32
|
+
type: 'string',
|
33
|
+
description: 'Specific editor or AI tool to generate rules for',
|
34
|
+
alias: 'e',
|
35
|
+
},
|
36
|
+
},
|
37
|
+
run: async ({ options }: EditorRulesProps) => {
|
38
|
+
// Check for help flag manually since bluebun help handling seems to have issues
|
39
|
+
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
40
|
+
print(blue('🎯 UDS Editor Rules Command'));
|
41
|
+
print('');
|
42
|
+
print(green('Description: Generate editor rules for various code editors and AI tools'));
|
43
|
+
print('');
|
44
|
+
print(yellow('Options:'));
|
45
|
+
print(' --force, -f Force overwrite existing rules directory');
|
46
|
+
print(' --output, -o Output directory (defaults to workspace root)');
|
47
|
+
print(' --editor, -e Specific editor/tool (defaults to all)');
|
48
|
+
print('');
|
49
|
+
print(blue('Available editors/tools:'));
|
50
|
+
const editors = getAvailableEditors();
|
51
|
+
for (const editor of editors) {
|
52
|
+
const config = getEditorConfig(editor);
|
53
|
+
if (config) {
|
54
|
+
print(` • ${editor}: ${config.description}`);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
print('');
|
58
|
+
print(blue('Examples:'));
|
59
|
+
print(' uds editor-rules # Generate all rules in current directory');
|
60
|
+
print(' uds editor-rules --editor cursor # Generate only Cursor rules');
|
61
|
+
print(' uds editor-rules --output /path # Generate rules in specific directory');
|
62
|
+
print(' uds editor-rules --force # Force overwrite existing rules');
|
63
|
+
print('');
|
64
|
+
print(green('What it generates:'));
|
65
|
+
print(' • Cursor Rules (.cursor/uds/)');
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
try {
|
70
|
+
const outputDir = options.output || process.cwd();
|
71
|
+
const selectedEditor = options.editor?.toLowerCase();
|
72
|
+
|
73
|
+
print(blue(`📁 Generating editor rules in: ${outputDir}`));
|
74
|
+
|
75
|
+
if (selectedEditor) {
|
76
|
+
// Generate rules for specific editor
|
77
|
+
const editorConfig = getEditorConfig(selectedEditor);
|
78
|
+
if (!editorConfig) {
|
79
|
+
print(red(`❌ Unknown editor: ${selectedEditor}`));
|
80
|
+
print(yellow('Available editors:'));
|
81
|
+
const editors = getAvailableEditors();
|
82
|
+
for (const editor of editors) {
|
83
|
+
const config = getEditorConfig(editor);
|
84
|
+
if (config) {
|
85
|
+
print(` • ${editor}: ${config.description}`);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
await generateEditorRules(outputDir, selectedEditor, editorConfig, options.force);
|
92
|
+
} else {
|
93
|
+
// Generate rules for all editors
|
94
|
+
const editors = getAvailableEditors();
|
95
|
+
for (const editor of editors) {
|
96
|
+
const editorConfig = getEditorConfig(editor);
|
97
|
+
if (editorConfig) {
|
98
|
+
await generateEditorRules(outputDir, editor, editorConfig, options.force);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
print(green('🎉 Editor rules generated successfully!'));
|
104
|
+
print(blue('📝 Rules are now available for your development environment'));
|
105
|
+
|
106
|
+
await trackEvent('editor_rules_generated', {
|
107
|
+
output_dir: outputDir,
|
108
|
+
force: options.force || false,
|
109
|
+
editor: selectedEditor || 'all',
|
110
|
+
});
|
111
|
+
} catch (error) {
|
112
|
+
print(red(`❌ Error generating editor rules: ${error}`));
|
113
|
+
process.exitCode = 1;
|
114
|
+
}
|
115
|
+
},
|
116
|
+
};
|
117
|
+
|
118
|
+
async function generateEditorRules(
|
119
|
+
outputDir: string,
|
120
|
+
editorName: string,
|
121
|
+
editorConfig: EditorConfig,
|
122
|
+
force: boolean = false,
|
123
|
+
) {
|
124
|
+
print(blue(`\n🔧 Generating ${editorConfig.name} rules...`));
|
125
|
+
|
126
|
+
for (const rule of editorConfig.rules) {
|
127
|
+
print(yellow(` 📝 ${rule.name}: ${rule.description}`));
|
128
|
+
|
129
|
+
for (const file of rule.files) {
|
130
|
+
const targetPath = join(outputDir, file.target);
|
131
|
+
const targetDir = join(targetPath, '..');
|
132
|
+
|
133
|
+
// Create target directory if it doesn't exist
|
134
|
+
if (!existsSync(targetDir)) {
|
135
|
+
mkdirSync(targetDir, { recursive: true });
|
136
|
+
}
|
137
|
+
|
138
|
+
// Check if file exists and handle force flag
|
139
|
+
if (existsSync(targetPath)) {
|
140
|
+
if (force) {
|
141
|
+
print(yellow(` 🗑️ Overwriting: ${file.target}`));
|
142
|
+
} else {
|
143
|
+
print(red(` ❌ File already exists: ${file.target}`));
|
144
|
+
print(yellow(' Use --force to overwrite existing files'));
|
145
|
+
continue;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
try {
|
150
|
+
// Read and write the rule file
|
151
|
+
const content = getRuleContent(file.source);
|
152
|
+
writeFileSync(targetPath, content);
|
153
|
+
print(green(` ✅ Created: ${file.target}`));
|
154
|
+
} catch (error) {
|
155
|
+
print(red(` ❌ Error creating ${file.target}: ${error}`));
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
2
|
+
import { join } from 'node:path';
|
3
|
+
|
4
|
+
export interface RuleConfig {
|
5
|
+
name: string;
|
6
|
+
description: string;
|
7
|
+
files: Array<{
|
8
|
+
source: string;
|
9
|
+
target: string;
|
10
|
+
type: 'file' | 'directory';
|
11
|
+
}>;
|
12
|
+
}
|
13
|
+
|
14
|
+
export interface EditorConfig {
|
15
|
+
name: string;
|
16
|
+
description: string;
|
17
|
+
rules: RuleConfig[];
|
18
|
+
}
|
19
|
+
|
20
|
+
export const EDITOR_CONFIGS: Record<string, EditorConfig> = {
|
21
|
+
cursor: {
|
22
|
+
name: 'Cursor',
|
23
|
+
description: 'AI-powered coding assistant rules for UDS development',
|
24
|
+
rules: [
|
25
|
+
{
|
26
|
+
name: 'UDS Components',
|
27
|
+
description: 'Component development guidelines and patterns',
|
28
|
+
files: [
|
29
|
+
{
|
30
|
+
source: 'cursor/uds/components.mdc',
|
31
|
+
target: '.cursor/rules/uds/components.mdc',
|
32
|
+
type: 'file',
|
33
|
+
},
|
34
|
+
],
|
35
|
+
},
|
36
|
+
{
|
37
|
+
name: 'UDS Tailwind',
|
38
|
+
description: 'Tailwind CSS configuration and setup guidelines',
|
39
|
+
files: [
|
40
|
+
{
|
41
|
+
source: 'cursor/uds/tailwind.mdc',
|
42
|
+
target: '.cursor/rules/uds/tailwind.mdc',
|
43
|
+
type: 'file',
|
44
|
+
},
|
45
|
+
],
|
46
|
+
},
|
47
|
+
{
|
48
|
+
name: 'UDS Icons',
|
49
|
+
description: 'Icon usage and documentation guidelines',
|
50
|
+
files: [
|
51
|
+
{
|
52
|
+
source: 'cursor/uds/icons.mdc',
|
53
|
+
target: '.cursor/rules/uds/icons.mdc',
|
54
|
+
type: 'file',
|
55
|
+
},
|
56
|
+
],
|
57
|
+
},
|
58
|
+
],
|
59
|
+
},
|
60
|
+
};
|
61
|
+
|
62
|
+
export function getAvailableEditors(): string[] {
|
63
|
+
return Object.keys(EDITOR_CONFIGS);
|
64
|
+
}
|
65
|
+
|
66
|
+
export function getEditorConfig(editor: string): EditorConfig | undefined {
|
67
|
+
return EDITOR_CONFIGS[editor];
|
68
|
+
}
|
69
|
+
|
70
|
+
export function getRuleContent(rulePath: string): string {
|
71
|
+
const fullPath = join(__dirname, rulePath);
|
72
|
+
return readFileSync(fullPath, 'utf-8');
|
73
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
description: UDS components
|
3
|
+
globs:
|
4
|
+
alwaysApply: true
|
5
|
+
---
|
6
|
+
|
7
|
+
- Always fetch components type definition using the UDS mcp server
|
8
|
+
- Always fetch the possible components from uds using the UDS mcp server
|
9
|
+
- Anytime you are about to use a component, fetch the type definition
|
10
|
+
- Anytime you are about to use a component, fetch the component documentation examples
|
11
|
+
- Anytime you have to create a component, make sure you are using UDS components
|
12
|
+
- Never create already existing UDS components from scratch
|
13
|
+
- Make sure there are no type errors when you create new components
|
14
|
+
- Always use UDS UI library components instead of raw HTML tags.
|
15
|
+
- Only create custom components when UDS doesn't provide the needed functionality
|
16
|
+
- `<Box>` has `display = 'flex'` by default - use `<VStack>` for vertical stacking, `<HStack>` for horizontal, or `<div>` for simple containers
|
17
|
+
- Use `<Text>` instead of `<p>`, `<span>`, `<h1>`-`<h6>`
|
18
|
+
- Use `<Button>` instead of `<button>`
|
19
|
+
- Use `<Input>` instead of `<input>`
|
20
|
+
- Use `<Checkbox>` instead of `<input type="checkbox">`
|
21
|
+
- Use `<Radio>` instead of `<input type="radio">`
|
22
|
+
- Use `<Switch>` instead of custom toggle components
|
23
|
+
- Use `<Link>` instead of `<a>`
|
24
|
+
- Use `<Icon>` instead of SVG elements
|
25
|
+
- Fix all lint errors before completing the task
|
@@ -0,0 +1,8 @@
|
|
1
|
+
---
|
2
|
+
description: UDS Icons
|
3
|
+
globs:
|
4
|
+
alwaysApply: true
|
5
|
+
---
|
6
|
+
|
7
|
+
- Anytime you have to use an icon in a UDS component or use UDS icons outside UDS components, fetch Icon documentation for more context from the MCP server
|
8
|
+
- Always check what icons are available in UDS through the MCP server
|
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
description: UDS config
|
3
|
+
globs:
|
4
|
+
alwaysApply: true
|
5
|
+
---
|
6
|
+
|
7
|
+
- Never create a UDS config manually
|
8
|
+
- If `uds.config.ts` or `uds.config.js` is not present at the root of the project, ask the user to create it using UDS CLI sync command
|
9
|
+
- Make sure that tailwind configuration has the UDS tailwind plugin
|
package/cli/utils/types.ts
CHANGED
@@ -19,3 +19,12 @@ export type SyncOptions = {
|
|
19
19
|
/** The version of the CLI */
|
20
20
|
version: string;
|
21
21
|
};
|
22
|
+
|
23
|
+
export type EditorRulesOptions = {
|
24
|
+
/** Force overwrite existing rules directory */
|
25
|
+
force?: boolean;
|
26
|
+
/** Output directory (defaults to workspace root) */
|
27
|
+
output?: string;
|
28
|
+
/** Specific editor or AI tool to generate rules for */
|
29
|
+
editor?: string;
|
30
|
+
};
|
package/dist/client/Menu.cjs
CHANGED
@@ -1,3 +1,2 @@
|
|
1
1
|
"use client";
|
2
|
-
"use strict";var e=require("../chunk-GMQZWDKV.cjs"),r=require("../chunk-H5RFGJT6.cjs"),t=require("../chunk-IWTF6VT4.cjs"),a=require("../chunk-TWH2EAVG.cjs"),d=require("../chunk-3VUEFW4X.cjs"),s=require("../chunk-QLXJH36U.cjs"),n=require("@ariakit/react/menu"),i=require("react"),c=require("use-sync-external-store/shim/index.js"),o=require("@yahoo/uds/fixtures"),u=require("motion/react"),l=require("react/jsx-runtime"),x=require("@ariakit/react");function m(e){return e&&e.__esModule?e:{default:e}}function p(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,Object.freeze(r)}var f=p(i),b=m(c);function h(e){return e}function _(e,r){const t=e.__unstableInternals;return function(e,r){if(!e)throw new Error(r)}(t,"Invalid store"),t[r]}var{useSyncExternalStore:v}=b.default;function g(e,r=h){const t=f.useCallback(r=>e?function(e,...r){if(e)return _(e,"subscribe")(...r)}(e,null,r):()=>{},[e]),a=()=>{const t="string"==typeof r?r:null,a="function"==typeof r?r:null,d=null==e?void 0:e.getState();if(a)return a(d);/*! © 2025 Yahoo, Inc. UDS v0.0.0-development */
|
3
|
-
var s,n;if(d&&(t&&(s=d,n=t,"function"==typeof Object.hasOwn?Object.hasOwn(s,n):Object.prototype.hasOwnProperty.call(s,n))))return d[t]};return v(t,a,a)}var I=u.m.create(t.VStack),y=5,S=.97,w={top:{x:0,y:y},bottom:{x:0,y:-5},left:{x:y,y:0},right:{x:-5,y:0}},C=e=>i.useMemo(()=>((e="bottom")=>{const[r="top"]=e?.split("-");return{closed:{...w[r],opacity:0,scale:S},open:{y:0,x:0,opacity:1,scale:1}}})(e),[e]),j=i.forwardRef(function({gap:e,spacing:r,spacingBottom:t,spacingEnd:a,spacingStart:s,spacingTop:c,gutter:x="1",backgroundColor:m="primary",borderRadius:p="md",borderColor:f,borderWidth:b="thin",overflow:h,dropShadow:_="lg",className:v,sameWidth:y,focusable:S,children:w,portalElement:j,portal:k=!0,disableAutoBorderRadius:N,...M},V){const E=n.useMenuContext(),R=g(E,"open"),O=g(E,"mounted"),P=g(E,"currentPlacement"),T=g(E,"placement"),[q,z]=i.useState(P),[A,D]=i.useState(P);i.useEffect(()=>{T!==A&&D(T)},[T]),i.useEffect(()=>{P!==A&&D(P)},[P]),i.useEffect(()=>{O&&A!==q&&z(A)},[O,A,q]);const H=i.useMemo(()=>R&&O?"open":"closed",[R,O]),B=i.useMemo(()=>R?_:"none",[R,_]),W=C(A),F=(({borderRadius:e,spacing:r})=>{if(void 0===r||"0"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))]";case"sm":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))]";case"md":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))]";case"lg":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))]"}if("px"===r||"0.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_2px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))]"}if("1"===r||"1.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_4px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_4px)]"}if("2"===r||"2.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_8px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_8px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_8px)]"}if("3"===r||"3.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))]";case"md":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-md)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-md)_-_6px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))] [&>*:last-child]:rounded-b-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))]"}if("4"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_16px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_16px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))]"}switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))] [&>*:last-child]:rounded-b-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))]"}})({borderRadius:p,spacing:r}),G=i.useMemo(()=>o.spacingMap[x],[x]);return l.jsx(u.AnimatePresence,{initial:!1,children:l.jsx(n.Menu,{gutter:G,sameWidth:y,focusable:S,store:E,ref:V,portalElement:j,portal:k,...M,render:l.jsx(I,{backgroundColor:m,gap:e,spacing:r,spacingBottom:t,spacingEnd:a,spacingStart:s,spacingTop:c,borderRadius:p,borderColor:f,borderWidth:b,overflow:h,animate:H,variants:W,dropShadow:B,className:d.cx("uds-menu-content","transition-shadow","duration-200","ease-in-out","min-w-60","max-w-lg","max-h-96","overflow-auto","uds-ring","z-10","group",!N&&F,v),children:w})})})}),k=i.forwardRef(function({role:r="separator",contentPosition:t="start",gap:a="4",children:s,spacingVertical:n=(s?"2":"0"),spacingHorizontal:i=(s?"4":"0"),className:c,...o},u){const x={root:d.getStyles({menuDividerVariantRoot:"default",className:c}),text:d.getStyles({menuDividerVariantText:"default"}),line:d.getStyles({menuDividerVariantLine:"default"})};return l.jsx(e.DividerInternal,{ref:u,role:r,variant:"inherit",contentPosition:t,gap:a,spacingVertical:n,spacingHorizontal:i,className:x.root,layerClassNames:x,...o,children:s})});k.displayName="MenuDivider";var N={};s.__export(N,{Content:()=>j,Divider:()=>k,Item:()=>R,ItemCheckbox:()=>O,Provider:()=>q,Trigger:()=>z,useMenuContext:()=>n.useMenuContext,useMenuStore:()=>n.useMenuStore,useStoreState:()=>x.useStoreState});var M="uds-menu-item",V={visible:{scale:1,opacity:1},hidden:{scale:.7,opacity:0}},E=i.forwardRef(function({spacing:e="0",spacingBottom:a,spacingEnd:s,spacingHorizontal:n="4",spacingStart:c,spacingTop:o,spacingVertical:x="3.5",columnGap:m="2",className:p,children:f,endIcon:b,startIcon:h,hideEndIcon:_,active:v,disabled:g,as:I,name:y,alignItems:S="center",justifyContent:w="space-between",layerClassNames:C,slots:j,rootProps:k,...N},E){const R=i.Children.count(f)>1,O=(({active:e,disabled:r,className:t})=>d.cx(M,"flex","focus-visible:text-brand","focus-visible:bg-brand-secondary","focus-visible:z-10","uds-ring","!-outline-offset-2",e&&["[&:not([aria-checked])]:cursor-default"],r&&"opacity-25 cursor-not-allowed","duration-20 transition-[font-variation-settings] ease-in-out","z-0",t))({active:v,disabled:g,className:p}),P=d.getStyles({className:d.cx(`${M}-content truncate`,C?.text),textAlign:"start",...R&&{columnGap:m,display:"flex",alignItems:"center",width:"full",justifyContent:"space-between"}}),T=i.useMemo(()=>({root:d.getStyles({menuSizeRoot:"default",flexDirection:"row",spacing:e,spacingBottom:a,spacingEnd:s,spacingHorizontal:n,spacingStart:c,spacingTop:o,spacingVertical:x,columnGap:m,alignItems:S,justifyContent:w,className:d.cx(O,C?.root)}),startIcon:d.getStyles({menuSizeStartIcon:"default",className:C?.startIcon}),endIcon:d.getStyles({menuSizeEndIcon:"default",className:C?.endIcon})}),[S,m,w,C?.endIcon,C?.root,C?.startIcon,O,e,a,s,n,c,o,x]),q=j?.root??(e=>l.jsx(r.Pressable,{...e,...N}));return l.jsxs(I,{ref:E,name:y??"",...k,render:q,disabled:g,className:T.root,children:[l.jsxs(t.HStack,{gap:m,alignItems:"center",width:"full",children:[l.jsx(u.AnimatePresence,{initial:!1,children:h&&l.jsx(u.m.span,{variants:V,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-start-icon",children:l.jsx(d.IconSlot,{icon:h,className:T.startIcon,iconProps:{size:"sm",variant:v?"fill":"outline",color:"current"}})})}),l.jsx("span",{className:P,children:f})]}),l.jsx(u.AnimatePresence,{initial:!1,mode:"popLayout",children:!_&&b&&l.jsx(u.m.span,{variants:V,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-end-icon",children:l.jsx(d.IconSlot,{icon:b,className:T.endIcon,iconProps:{size:"sm",variant:v?"fill":"outline",color:"current"}})})})]})});E.displayName="MenuItemBase";var R=i.forwardRef(function({active:e,hideOnClick:r,...t},a){const s={root:d.getStyles({menuItemVariantRoot:"default",menuItemVariantActiveRoot:e?"on":"off"}),text:d.getStyles({menuItemVariantText:"default",menuItemVariantActiveText:e?"on":"off"}),startIcon:d.getStyles({menuItemVariantIcon:"default",menuItemVariantActiveIcon:e?"on":"off"})};return l.jsx(E,{ref:a,as:n.MenuItem,active:e,layerClassNames:s,rootProps:{hideOnClick:r},...t})});R.displayName="MenuItem";var O=i.forwardRef(function({name:e,endIcon:t=r.e,checked:a,defaultChecked:s,hideOnClick:c,className:o,...u},m){const p=e,f=i.useRef(!1),b=n.useMenuContext(),h=x.useStoreState(b);i.useEffect(()=>{!f.current&&void 0!==s&&b&&(b.setValues(e=>({...e,[p]:s})),f.current=!0)},[b,s,p]);const _=i.useMemo(()=>{if(void 0!==a)return a;if(h?.items?.length){const e=h?.items.find(e=>e.element?.name===p);if(e?.element)return e.element.checked}const e=h?.values[p];return"boolean"==typeof e?e:s??!1},[h?.items,h?.values,p,a,s]),v=i.useCallback(e=>{void 0===a&&b?.setValues(r=>({...r,[p]:e.target.checked}))},[p,b,a]),g={root:d.getStyles({menuItemCheckboxVariantRoot:"default",menuItemCheckboxVariantActiveRoot:_?"on":"off"}),text:d.getStyles({menuItemCheckboxVariantText:"default",menuItemCheckboxVariantActiveText:_?"on":"off"}),startIcon:d.getStyles({menuItemCheckboxVariantStartIcon:"default",menuItemCheckboxVariantActiveStartIcon:_?"on":"off"}),endIcon:d.getStyles({menuItemCheckboxVariantEndIcon:"default",menuItemCheckboxVariantActiveEndIcon:_?"on":"off"})};return l.jsx(E,{ref:m,as:n.MenuItemCheckbox,hideEndIcon:!_,endIcon:t,active:_,className:d.cx("uds-menu-item-checkbox",o),layerClassNames:g,name:e,rootProps:{onChange:v,defaultChecked:s,checked:void 0!==a?a:void 0,hideOnClick:c},...u})});O.displayName="MenuItemCheckbox";var P=()=>{if("undefined"==typeof document)return!1;return"rtl"===getComputedStyle(document.documentElement).direction},T=e=>{const[r,t]=i.useState(P);return i.useEffect(()=>{if(e?.explicit)return void t(e.explicit);const r=(e=>{const r=new MutationObserver(r=>{r.some(e=>"attributes"===e.type&&"dir"===e.attributeName)&&e()});return r.observe(document.documentElement,{attributes:!0,attributeFilter:["dir"]}),r})(()=>{t(P())});return()=>r.disconnect()},[e?.explicit]),r},q=function({placement:e="bottom",rtl:r,...t}){const d=T({explicit:r}),s=((e,r)=>{const t=r?.rtl;if("start"===e)return t?"right":"left";if("end"===e)return t?"left":"right";if(e?.includes("-")){const[r,a]=e.split("-");if(!("start"!==r&&"end"!==r||"top"!==a&&"bottom"!==a))return`${"start"===r?t?"right":"left":t?"left":"right"}-${"bottom"===a?"end":"start"}`;if("top"===r||"bottom"===r)return`${r}-${"start"===a?t?"end":"start":t?"start":"end"}`}return e})(e,{rtl:d});return l.jsx(a.SpringMotionConfig,{children:l.jsx(n.MenuProvider,{placement:s,rtl:d,...t})})},z=i.forwardRef(function({asChild:e,children:r,className:t,...a},s){const c=i.useRef(null),o=e?{render:l.jsx(d.Box,{asChild:!0,ref:c,className:"uds-ring h-fit w-fit",children:r})}:{children:r},u=i.useCallback(()=>{const e=c.current?.firstChild;e instanceof HTMLElement&&"function"==typeof e.focus&&e.focus()},[c]);return l.jsx(n.MenuButton,{onFocus:u,onFocusVisible:u,ref:s,className:d.cx("uds-menu-trigger",t),...o,...a})});exports.Menu=N;
|
2
|
+
"use strict";var e=require("../chunk-GMQZWDKV.cjs"),r=require("../chunk-H5RFGJT6.cjs"),t=require("../chunk-IWTF6VT4.cjs"),a=require("../chunk-TWH2EAVG.cjs"),d=require("../chunk-3VUEFW4X.cjs"),s=require("../chunk-QLXJH36U.cjs"),n=require("@ariakit/react/menu"),i=require("react"),c=require("use-sync-external-store/shim/index.js"),o=require("@yahoo/uds/fixtures"),u=require("motion/react"),l=require("react/jsx-runtime"),x=require("@ariakit/react");function m(e){return e&&e.__esModule?e:{default:e}}function p(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,Object.freeze(r)}var f=p(i),b=m(c),h={};function _(e){return e}function v(e,r){const t=e.__unstableInternals;return function(e,r){if(!e)throw new Error(r)}(t,"Invalid store"),t[r]}s.__export(h,{Content:()=>k,Divider:()=>N,Item:()=>R,ItemCheckbox:()=>O,Provider:()=>q,Trigger:()=>z,useMenuContext:()=>n.useMenuContext,useMenuStore:()=>n.useMenuStore,useStoreState:()=>x.useStoreState});var{useSyncExternalStore:g}=b.default;function I(e,r=_){const t=f.useCallback(r=>e?function(e,...r){if(e)return v(e,"subscribe")(...r)}(e,null,r):()=>{},[e]),a=()=>{const t="string"==typeof r?r:null,a="function"==typeof r?r:null,d=null==e?void 0:e.getState();if(a)return a(d);var s,n;if(d&&(t&&(s=d,n=t,"function"==typeof Object.hasOwn?Object.hasOwn(s,n):Object.prototype.hasOwnProperty.call(s,n))))return d[t]};return g(t,a,a)}var y=u.m.create(t.VStack),S=5,w=.97,C={top:{x:0,y:S},bottom:{x:0,y:-5},left:{x:S,y:0},right:{x:-5,y:0}},j=e=>i.useMemo(()=>((e="bottom")=>{const[r="top"]=e?.split("-");return{closed:{...C[r],opacity:0,scale:w},open:{y:0,x:0,opacity:1,scale:1}}})(e),[e]),k=i.forwardRef(function({gap:e,spacing:r,spacingBottom:t,spacingEnd:a,spacingStart:s,spacingTop:c,gutter:x="1",backgroundColor:m="primary",borderRadius:p="md",borderColor:f,borderWidth:b="thin",overflow:h,dropShadow:_="lg",className:v,sameWidth:g,focusable:S,children:w,portalElement:C,portal:k=!0,disableAutoBorderRadius:N,...M},V){const E=n.useMenuContext(),R=I(E,"open"),O=I(E,"mounted"),P=I(E,"currentPlacement"),T=I(E,"placement"),[q,z]=i.useState(P),[A,D]=i.useState(P);i.useEffect(()=>{T!==A&&D(T)},[T]),i.useEffect(()=>{P!==A&&D(P)},[P]),i.useEffect(()=>{O&&A!==q&&z(A)},[O,A,q]);const H=i.useMemo(()=>R&&O?"open":"closed",[R,O]),B=i.useMemo(()=>R?_:"none",[R,_]),W=j(A),F=(({borderRadius:e,spacing:r})=>{if(void 0===r||"0"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))]";case"sm":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))]";case"md":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))]";case"lg":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))]"}if("px"===r||"0.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_2px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))]"}if("1"===r||"1.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_4px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_4px)]"}if("2"===r||"2.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_8px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_8px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_8px)]"}if("3"===r||"3.5"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))]";case"md":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-md)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-md)_-_6px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))] [&>*:last-child]:rounded-b-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))]"}if("4"===r)switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_16px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_16px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))]"}switch(e){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))] [&>*:last-child]:rounded-b-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))]"}})({borderRadius:p,spacing:r}),G=i.useMemo(()=>o.spacingMap[x],[x]);return l.jsx(u.AnimatePresence,{initial:!1,children:l.jsx(n.Menu,{gutter:G,sameWidth:g,focusable:S,store:E,ref:V,portalElement:C,portal:k,...M,render:l.jsx(y,{backgroundColor:m,gap:e,spacing:r,spacingBottom:t,spacingEnd:a,spacingStart:s,spacingTop:c,borderRadius:p,borderColor:f,borderWidth:b,overflow:h,animate:H,variants:W,dropShadow:B,className:d.cx("uds-menu-content","transition-shadow","duration-200","ease-in-out","min-w-60","max-w-lg","max-h-96","overflow-auto","uds-ring","z-10","group",!N&&F,v),children:w})})})}),N=i.forwardRef(function({role:r="separator",contentPosition:t="start",gap:a="4",children:s,spacingVertical:n=(s?"2":"0"),spacingHorizontal:i=(s?"4":"0"),className:c,...o},u){const x={root:d.getStyles({menuDividerVariantRoot:"default",className:c}),text:d.getStyles({menuDividerVariantText:"default"}),line:d.getStyles({menuDividerVariantLine:"default"})};return l.jsx(e.DividerInternal,{ref:u,role:r,variant:"inherit",contentPosition:t,gap:a,spacingVertical:n,spacingHorizontal:i,className:x.root,layerClassNames:x,...o,children:s})});N.displayName="MenuDivider";var M="uds-menu-item",V={visible:{scale:1,opacity:1},hidden:{scale:.7,opacity:0}},E=i.forwardRef(function({spacing:e="0",spacingBottom:a,spacingEnd:s,spacingHorizontal:n="4",spacingStart:c,spacingTop:o,spacingVertical:x="3.5",columnGap:m="2",className:p,children:f,endIcon:b,startIcon:h,hideEndIcon:_,active:v,disabled:g,as:I,name:y,alignItems:S="center",justifyContent:w="space-between",layerClassNames:C,slots:j,rootProps:k,...N},E){const R=i.Children.count(f)>1,O=(({active:e,disabled:r,className:t})=>d.cx(M,"flex","focus-visible:text-brand","focus-visible:bg-brand-secondary","focus-visible:z-10","uds-ring","!-outline-offset-2",e&&["[&:not([aria-checked])]:cursor-default"],r&&"opacity-25 cursor-not-allowed","duration-20 transition-[font-variation-settings] ease-in-out","z-0",t))({active:v,disabled:g,className:p}),P=d.getStyles({className:d.cx(`${M}-content truncate`,C?.text),textAlign:"start",...R&&{columnGap:m,display:"flex",alignItems:"center",width:"full",justifyContent:"space-between"}}),T=i.useMemo(()=>({root:d.getStyles({menuSizeRoot:"default",flexDirection:"row",spacing:e,spacingBottom:a,spacingEnd:s,spacingHorizontal:n,spacingStart:c,spacingTop:o,spacingVertical:x,columnGap:m,alignItems:S,justifyContent:w,className:d.cx(O,C?.root)}),startIcon:d.getStyles({menuSizeStartIcon:"default",className:C?.startIcon}),endIcon:d.getStyles({menuSizeEndIcon:"default",className:C?.endIcon})}),[S,m,w,C?.endIcon,C?.root,C?.startIcon,O,e,a,s,n,c,o,x]),q=j?.root??(e=>l.jsx(r.Pressable,{...e,...N}));return l.jsxs(I,{ref:E,name:y??"",...k,render:q,disabled:g,className:T.root,children:[l.jsxs(t.HStack,{gap:m,alignItems:"center",width:"full",children:[l.jsx(u.AnimatePresence,{initial:!1,children:h&&l.jsx(u.m.span,{variants:V,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-start-icon",children:l.jsx(d.IconSlot,{icon:h,className:T.startIcon,iconProps:{size:"sm",variant:v?"fill":"outline",color:"current"}})})}),l.jsx("span",{className:P,children:f})]}),l.jsx(u.AnimatePresence,{initial:!1,mode:"popLayout",children:!_&&b&&l.jsx(u.m.span,{variants:V,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-end-icon",children:l.jsx(d.IconSlot,{icon:b,className:T.endIcon,iconProps:{size:"sm",variant:v?"fill":"outline",color:"current"}})})})]})});E.displayName="MenuItemBase";var R=i.forwardRef(function({active:e,hideOnClick:r,...t},a){const s={root:d.getStyles({menuItemVariantRoot:"default",menuItemVariantActiveRoot:e?"on":"off"}),text:d.getStyles({menuItemVariantText:"default",menuItemVariantActiveText:e?"on":"off"}),startIcon:d.getStyles({menuItemVariantIcon:"default",menuItemVariantActiveIcon:e?"on":"off"})};return l.jsx(E,{ref:a,as:n.MenuItem,active:e,layerClassNames:s,rootProps:{hideOnClick:r},...t})});R.displayName="MenuItem";var O=i.forwardRef(function({name:e,endIcon:t=r.e,checked:a,defaultChecked:s,hideOnClick:c,className:o,...u},m){const p=e,f=i.useRef(!1),b=n.useMenuContext(),h=x.useStoreState(b);i.useEffect(()=>{!f.current&&void 0!==s&&b&&(b.setValues(e=>({...e,[p]:s})),f.current=!0)},[b,s,p]);const _=i.useMemo(()=>{if(void 0!==a)return a;if(h?.items?.length){const e=h?.items.find(e=>e.element?.name===p);if(e?.element)return e.element.checked}const e=h?.values[p];return"boolean"==typeof e?e:s??!1},[h?.items,h?.values,p,a,s]),v=i.useCallback(e=>{void 0===a&&b?.setValues(r=>({...r,[p]:e.target.checked}))},[p,b,a]),g={root:d.getStyles({menuItemCheckboxVariantRoot:"default",menuItemCheckboxVariantActiveRoot:_?"on":"off"}),text:d.getStyles({menuItemCheckboxVariantText:"default",menuItemCheckboxVariantActiveText:_?"on":"off"}),startIcon:d.getStyles({menuItemCheckboxVariantStartIcon:"default",menuItemCheckboxVariantActiveStartIcon:_?"on":"off"}),endIcon:d.getStyles({menuItemCheckboxVariantEndIcon:"default",menuItemCheckboxVariantActiveEndIcon:_?"on":"off"})};return l.jsx(E,{ref:m,as:n.MenuItemCheckbox,hideEndIcon:!_,endIcon:t,active:_,className:d.cx("uds-menu-item-checkbox",o),layerClassNames:g,name:e,rootProps:{onChange:v,defaultChecked:s,checked:void 0!==a?a:void 0,hideOnClick:c},...u})});O.displayName="MenuItemCheckbox";var P=()=>{if("undefined"==typeof document)return!1;return"rtl"===getComputedStyle(document.documentElement).direction},T=e=>{const[r,t]=i.useState(P);return i.useEffect(()=>{if(e?.explicit)return void t(e.explicit);const r=(e=>{const r=new MutationObserver(r=>{r.some(e=>"attributes"===e.type&&"dir"===e.attributeName)&&e()});return r.observe(document.documentElement,{attributes:!0,attributeFilter:["dir"]}),r})(()=>{t(P())});return()=>r.disconnect()},[e?.explicit]),r},q=function({placement:e="bottom",rtl:r,...t}){const d=T({explicit:r}),s=((e,r)=>{const t=r?.rtl;if("start"===e)return t?"right":"left";if("end"===e)return t?"left":"right";if(e?.includes("-")){const[r,a]=e.split("-");if(!("start"!==r&&"end"!==r||"top"!==a&&"bottom"!==a))return`${"start"===r?t?"right":"left":t?"left":"right"}-${"bottom"===a?"end":"start"}`;if("top"===r||"bottom"===r)return`${r}-${"start"===a?t?"end":"start":t?"start":"end"}`}return e})(e,{rtl:d});return l.jsx(a.SpringMotionConfig,{children:l.jsx(n.MenuProvider,{placement:s,rtl:d,...t})})},z=i.forwardRef(function({asChild:e,children:r,className:t,...a},s){const c=i.useRef(null),o=e?{render:l.jsx(d.Box,{asChild:!0,ref:c,className:"uds-ring h-fit w-fit",children:r})}:{children:r},u=i.useCallback(()=>{const e=c.current?.firstChild;e instanceof HTMLElement&&"function"==typeof e.focus&&e.focus()},[c]);return l.jsx(n.MenuButton,{onFocus:u,onFocusVisible:u,ref:s,className:d.cx("uds-menu-trigger",t),...o,...a})});exports.Menu=h;
|
package/dist/client/Menu.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
"use client";
|
2
|
-
import{DividerInternal as r}from"../chunk-5VROETXJ.js";import{e,Pressable as a}from"../chunk-GGW73ECI.js";import{VStack as d,HStack as t}from"../chunk-WFWWC766.js";import{SpringMotionConfig as s}from"../chunk-EFOWTGKI.js";import{cx as i,getStyles as n,IconSlot as c,Box as o}from"../chunk-PMXAH4FA.js";import{__export as u}from"../chunk-GF4A6TFM.js";import{
|
3
|
-
var s,i;if(t&&(a&&(s=t,i=a,"function"==typeof Object.hasOwn?Object.hasOwn(s,i):Object.prototype.hasOwnProperty.call(s,i))))return t[a]};return A(a,d,d)}var R=S.create(d),W=5,F=.97,G={top:{x:0,y:W},bottom:{x:0,y:-5},left:{x:W,y:0},right:{x:-5,y:0}},B=r=>w(()=>((r="bottom")=>{const[e="top"]=r?.split("-");return{closed:{...G[e],opacity:0,scale:F},open:{y:0,x:0,opacity:1,scale:1}}})(r),[r]),D=v(function({gap:r,spacing:e,spacingBottom:a,spacingEnd:d,spacingStart:t,spacingTop:s,gutter:n="1",backgroundColor:c="primary",borderRadius:o="md",borderColor:u,borderWidth:x="thin",overflow:p,dropShadow:h="lg",className:b,sameWidth:f,focusable:_,children:v,portalElement:y,portal:C=!0,disableAutoBorderRadius:k,...N},S){const M=l(),T=P(M,"open"),O=P(M,"mounted"),z=P(M,"currentPlacement"),A=P(M,"placement"),[W,F]=g(z),[G,D]=g(z);I(()=>{A!==G&&D(A)},[A]),I(()=>{z!==G&&D(z)},[z]),I(()=>{O&&G!==W&&F(G)},[O,G,W]);const H=w(()=>T&&O?"open":"closed",[T,O]),$=w(()=>T?h:"none",[T,h]),L=B(G),X=(({borderRadius:r,spacing:e})=>{if(void 0===e||"0"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))]";case"sm":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))]";case"md":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))]";case"lg":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))]"}if("px"===e||"0.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_2px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))]"}if("1"===e||"1.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_4px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_4px)]"}if("2"===e||"2.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_8px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_8px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_8px)]"}if("3"===e||"3.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))]";case"md":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-md)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-md)_-_6px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))] [&>*:last-child]:rounded-b-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))]"}if("4"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_16px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_16px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))]"}switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))] [&>*:last-child]:rounded-b-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))]"}})({borderRadius:o,spacing:e}),J=w(()=>V[n],[n]);return j(E,{initial:!1,children:j(m,{gutter:J,sameWidth:f,focusable:_,store:M,ref:S,portalElement:y,portal:C,...N,render:j(R,{backgroundColor:c,gap:r,spacing:e,spacingBottom:a,spacingEnd:d,spacingStart:t,spacingTop:s,borderRadius:o,borderColor:u,borderWidth:x,overflow:p,animate:H,variants:L,dropShadow:$,className:i("uds-menu-content","transition-shadow","duration-200","ease-in-out","min-w-60","max-w-lg","max-h-96","overflow-auto","uds-ring","z-10","group",!k&&X,b),children:v})})})}),H=v(function({role:e="separator",contentPosition:a="start",gap:d="4",children:t,spacingVertical:s=(t?"2":"0"),spacingHorizontal:i=(t?"4":"0"),className:c,...o},u){const l={root:n({menuDividerVariantRoot:"default",className:c}),text:n({menuDividerVariantText:"default"}),line:n({menuDividerVariantLine:"default"})};return j(r,{ref:u,role:e,variant:"inherit",contentPosition:a,gap:d,spacingVertical:s,spacingHorizontal:i,className:l.root,layerClassNames:l,...o,children:t})});H.displayName="MenuDivider";var $={};u($,{Content:()=>D,Divider:()=>H,Item:()=>K,ItemCheckbox:()=>q,Provider:()=>Y,Trigger:()=>Z,useMenuContext:()=>l,useMenuStore:()=>x,useStoreState:()=>T});var L="uds-menu-item",X={visible:{scale:1,opacity:1},hidden:{scale:.7,opacity:0}},J=v(function({spacing:r="0",spacingBottom:e,spacingEnd:d,spacingHorizontal:s="4",spacingStart:o,spacingTop:u,spacingVertical:l="3.5",columnGap:m="2",className:x,children:p,endIcon:h,startIcon:b,hideEndIcon:f,active:_,disabled:v,as:g,name:I,alignItems:C="center",justifyContent:k="space-between",layerClassNames:N,slots:V,rootProps:T,...O},z){const A=y.count(p)>1,P=(({active:r,disabled:e,className:a})=>i(L,"flex","focus-visible:text-brand","focus-visible:bg-brand-secondary","focus-visible:z-10","uds-ring","!-outline-offset-2",r&&["[&:not([aria-checked])]:cursor-default"],e&&"opacity-25 cursor-not-allowed","duration-20 transition-[font-variation-settings] ease-in-out","z-0",a))({active:_,disabled:v,className:x}),R=n({className:i(`${L}-content truncate`,N?.text),textAlign:"start",...A&&{columnGap:m,display:"flex",alignItems:"center",width:"full",justifyContent:"space-between"}}),W=w(()=>({root:n({menuSizeRoot:"default",flexDirection:"row",spacing:r,spacingBottom:e,spacingEnd:d,spacingHorizontal:s,spacingStart:o,spacingTop:u,spacingVertical:l,columnGap:m,alignItems:C,justifyContent:k,className:i(P,N?.root)}),startIcon:n({menuSizeStartIcon:"default",className:N?.startIcon}),endIcon:n({menuSizeEndIcon:"default",className:N?.endIcon})}),[C,m,k,N?.endIcon,N?.root,N?.startIcon,P,r,e,d,s,o,u,l]);return M(g,{ref:z,name:I??"",...T,render:V?.root??(r=>j(a,{...r,...O})),disabled:v,className:W.root,children:[M(t,{gap:m,alignItems:"center",width:"full",children:[j(E,{initial:!1,children:b&&j(S.span,{variants:X,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-start-icon",children:j(c,{icon:b,className:W.startIcon,iconProps:{size:"sm",variant:_?"fill":"outline",color:"current"}})})}),j("span",{className:R,children:p})]}),j(E,{initial:!1,mode:"popLayout",children:!f&&h&&j(S.span,{variants:X,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-end-icon",children:j(c,{icon:h,className:W.endIcon,iconProps:{size:"sm",variant:_?"fill":"outline",color:"current"}})})})]})});J.displayName="MenuItemBase";var K=v(function({active:r,hideOnClick:e,...a},d){const t={root:n({menuItemVariantRoot:"default",menuItemVariantActiveRoot:r?"on":"off"}),text:n({menuItemVariantText:"default",menuItemVariantActiveText:r?"on":"off"}),startIcon:n({menuItemVariantIcon:"default",menuItemVariantActiveIcon:r?"on":"off"})};return j(J,{ref:d,as:p,active:r,layerClassNames:t,rootProps:{hideOnClick:e},...a})});K.displayName="MenuItem";var q=v(function({name:r,endIcon:a=e,checked:d,defaultChecked:t,hideOnClick:s,className:c,...o},u){const m=r,x=C(!1),p=l(),b=T(p);I(()=>{!x.current&&void 0!==t&&p&&(p.setValues(r=>({...r,[m]:t})),x.current=!0)},[p,t,m]);const f=w(()=>{if(void 0!==d)return d;if(b?.items?.length){const r=b?.items.find(r=>r.element?.name===m);if(r?.element)return r.element.checked}const r=b?.values[m];return"boolean"==typeof r?r:t??!1},[b?.items,b?.values,m,d,t]),_=k(r=>{void 0===d&&p?.setValues(e=>({...e,[m]:r.target.checked}))},[m,p,d]),v={root:n({menuItemCheckboxVariantRoot:"default",menuItemCheckboxVariantActiveRoot:f?"on":"off"}),text:n({menuItemCheckboxVariantText:"default",menuItemCheckboxVariantActiveText:f?"on":"off"}),startIcon:n({menuItemCheckboxVariantStartIcon:"default",menuItemCheckboxVariantActiveStartIcon:f?"on":"off"}),endIcon:n({menuItemCheckboxVariantEndIcon:"default",menuItemCheckboxVariantActiveEndIcon:f?"on":"off"})};return j(J,{ref:u,as:h,hideEndIcon:!f,endIcon:a,active:f,className:i("uds-menu-item-checkbox",c),layerClassNames:v,name:r,rootProps:{onChange:_,defaultChecked:t,checked:void 0!==d?d:void 0,hideOnClick:s},...o})});q.displayName="MenuItemCheckbox";var Q=()=>{if("undefined"==typeof document)return!1;return"rtl"===getComputedStyle(document.documentElement).direction},U=r=>{const[e,a]=g(Q);return I(()=>{if(r?.explicit)return void a(r.explicit);const e=(r=>{const e=new MutationObserver(e=>{e.some(r=>"attributes"===r.type&&"dir"===r.attributeName)&&r()});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["dir"]}),e})(()=>{a(Q())});return()=>e.disconnect()},[r?.explicit]),e},Y=function({placement:r="bottom",rtl:e,...a}){const d=U({explicit:e}),t=((r,e)=>{const a=e?.rtl;if("start"===r)return a?"right":"left";if("end"===r)return a?"left":"right";if(r?.includes("-")){const[e,d]=r.split("-");if(!("start"!==e&&"end"!==e||"top"!==d&&"bottom"!==d))return`${"start"===e?a?"right":"left":a?"left":"right"}-${"bottom"===d?"end":"start"}`;if("top"===e||"bottom"===e)return`${e}-${"start"===d?a?"end":"start":a?"start":"end"}`}return r})(r,{rtl:d});return j(s,{children:j(b,{placement:t,rtl:d,...a})})},Z=v(function({asChild:r,children:e,className:a,...d},t){const s=C(null),n=r?{render:j(o,{asChild:!0,ref:s,className:"uds-ring h-fit w-fit",children:e})}:{children:e},c=k(()=>{const r=s.current?.firstChild;r instanceof HTMLElement&&"function"==typeof r.focus&&r.focus()},[s]);return j(f,{onFocus:c,onFocusVisible:c,ref:t,className:i("uds-menu-trigger",a),...n,...d})});export{$ as Menu};
|
2
|
+
import{DividerInternal as r}from"../chunk-5VROETXJ.js";import{e,Pressable as a}from"../chunk-GGW73ECI.js";import{VStack as d,HStack as t}from"../chunk-WFWWC766.js";import{SpringMotionConfig as s}from"../chunk-EFOWTGKI.js";import{cx as i,getStyles as n,IconSlot as c,Box as o}from"../chunk-PMXAH4FA.js";import{__export as u}from"../chunk-GF4A6TFM.js";import{useMenuStore as l,useMenuContext as m,Menu as x,MenuItem as p,MenuItemCheckbox as h,MenuProvider as b,MenuButton as f}from"@ariakit/react/menu";import*as _ from"react";import{forwardRef as v,useState as g,useEffect as I,useMemo as w,Children as y,useRef as C,useCallback as k}from"react";import N from"use-sync-external-store/shim/index.js";import{spacingMap as V}from"@yahoo/uds/fixtures";import{m as S,AnimatePresence as E}from"motion/react";import{jsx as j,jsxs as M}from"react/jsx-runtime";import{useStoreState as T}from"@ariakit/react";/*! © 2025 Yahoo, Inc. UDS v0.0.0-development */
|
3
|
+
var O={};function z(r){return r}function A(r,e){const a=r.__unstableInternals;return function(r,e){if(!r)throw new Error(e)}(a,"Invalid store"),a[e]}u(O,{Content:()=>H,Divider:()=>$,Item:()=>K,ItemCheckbox:()=>q,Provider:()=>Y,Trigger:()=>Z,useMenuContext:()=>m,useMenuStore:()=>l,useStoreState:()=>T});var{useSyncExternalStore:P}=N;function R(r,e=z){const a=_.useCallback(e=>r?function(r,...e){if(r)return A(r,"subscribe")(...e)}(r,null,e):()=>{},[r]),d=()=>{const a="string"==typeof e?e:null,d="function"==typeof e?e:null,t=null==r?void 0:r.getState();if(d)return d(t);var s,i;if(t&&(a&&(s=t,i=a,"function"==typeof Object.hasOwn?Object.hasOwn(s,i):Object.prototype.hasOwnProperty.call(s,i))))return t[a]};return P(a,d,d)}var W=S.create(d),F=5,G=.97,B={top:{x:0,y:F},bottom:{x:0,y:-5},left:{x:F,y:0},right:{x:-5,y:0}},D=r=>w(()=>((r="bottom")=>{const[e="top"]=r?.split("-");return{closed:{...B[e],opacity:0,scale:G},open:{y:0,x:0,opacity:1,scale:1}}})(r),[r]),H=v(function({gap:r,spacing:e,spacingBottom:a,spacingEnd:d,spacingStart:t,spacingTop:s,gutter:n="1",backgroundColor:c="primary",borderRadius:o="md",borderColor:u,borderWidth:l="thin",overflow:p,dropShadow:h="lg",className:b,sameWidth:f,focusable:_,children:v,portalElement:y,portal:C=!0,disableAutoBorderRadius:k,...N},S){const M=m(),T=R(M,"open"),O=R(M,"mounted"),z=R(M,"currentPlacement"),A=R(M,"placement"),[P,F]=g(z),[G,B]=g(z);I(()=>{A!==G&&B(A)},[A]),I(()=>{z!==G&&B(z)},[z]),I(()=>{O&&G!==P&&F(G)},[O,G,P]);const H=w(()=>T&&O?"open":"closed",[T,O]),$=w(()=>T?h:"none",[T,h]),L=D(G),X=(({borderRadius:r,spacing:e})=>{if(void 0===e||"0"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))]";case"sm":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))]";case"md":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))]";case"lg":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))]"}if("px"===e||"0.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_2px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))]"}if("1"===e||"1.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_4px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_4px)]"}if("2"===e||"2.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_8px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))]";case"xl":return"[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_8px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_8px)]"}if("3"===e||"3.5"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))]";case"md":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-md)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-md)_-_6px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))] [&>*:last-child]:rounded-b-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))]"}if("4"===e)switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))]";case"md":return"[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_16px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_16px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))]";case"xl":return"[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))]"}switch(r){case"xs":return"[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]";case"sm":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]";case"md":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]";case"lg":return"[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]";case"xl":return"[&>*:first-child]:rounded-t-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))] [&>*:last-child]:rounded-b-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))]"}})({borderRadius:o,spacing:e}),J=w(()=>V[n],[n]);return j(E,{initial:!1,children:j(x,{gutter:J,sameWidth:f,focusable:_,store:M,ref:S,portalElement:y,portal:C,...N,render:j(W,{backgroundColor:c,gap:r,spacing:e,spacingBottom:a,spacingEnd:d,spacingStart:t,spacingTop:s,borderRadius:o,borderColor:u,borderWidth:l,overflow:p,animate:H,variants:L,dropShadow:$,className:i("uds-menu-content","transition-shadow","duration-200","ease-in-out","min-w-60","max-w-lg","max-h-96","overflow-auto","uds-ring","z-10","group",!k&&X,b),children:v})})})}),$=v(function({role:e="separator",contentPosition:a="start",gap:d="4",children:t,spacingVertical:s=(t?"2":"0"),spacingHorizontal:i=(t?"4":"0"),className:c,...o},u){const l={root:n({menuDividerVariantRoot:"default",className:c}),text:n({menuDividerVariantText:"default"}),line:n({menuDividerVariantLine:"default"})};return j(r,{ref:u,role:e,variant:"inherit",contentPosition:a,gap:d,spacingVertical:s,spacingHorizontal:i,className:l.root,layerClassNames:l,...o,children:t})});$.displayName="MenuDivider";var L="uds-menu-item",X={visible:{scale:1,opacity:1},hidden:{scale:.7,opacity:0}},J=v(function({spacing:r="0",spacingBottom:e,spacingEnd:d,spacingHorizontal:s="4",spacingStart:o,spacingTop:u,spacingVertical:l="3.5",columnGap:m="2",className:x,children:p,endIcon:h,startIcon:b,hideEndIcon:f,active:_,disabled:v,as:g,name:I,alignItems:C="center",justifyContent:k="space-between",layerClassNames:N,slots:V,rootProps:T,...O},z){const A=y.count(p)>1,P=(({active:r,disabled:e,className:a})=>i(L,"flex","focus-visible:text-brand","focus-visible:bg-brand-secondary","focus-visible:z-10","uds-ring","!-outline-offset-2",r&&["[&:not([aria-checked])]:cursor-default"],e&&"opacity-25 cursor-not-allowed","duration-20 transition-[font-variation-settings] ease-in-out","z-0",a))({active:_,disabled:v,className:x}),R=n({className:i(`${L}-content truncate`,N?.text),textAlign:"start",...A&&{columnGap:m,display:"flex",alignItems:"center",width:"full",justifyContent:"space-between"}}),W=w(()=>({root:n({menuSizeRoot:"default",flexDirection:"row",spacing:r,spacingBottom:e,spacingEnd:d,spacingHorizontal:s,spacingStart:o,spacingTop:u,spacingVertical:l,columnGap:m,alignItems:C,justifyContent:k,className:i(P,N?.root)}),startIcon:n({menuSizeStartIcon:"default",className:N?.startIcon}),endIcon:n({menuSizeEndIcon:"default",className:N?.endIcon})}),[C,m,k,N?.endIcon,N?.root,N?.startIcon,P,r,e,d,s,o,u,l]);return M(g,{ref:z,name:I??"",...T,render:V?.root??(r=>j(a,{...r,...O})),disabled:v,className:W.root,children:[M(t,{gap:m,alignItems:"center",width:"full",children:[j(E,{initial:!1,children:b&&j(S.span,{variants:X,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-start-icon",children:j(c,{icon:b,className:W.startIcon,iconProps:{size:"sm",variant:_?"fill":"outline",color:"current"}})})}),j("span",{className:R,children:p})]}),j(E,{initial:!1,mode:"popLayout",children:!f&&h&&j(S.span,{variants:X,initial:"hidden",animate:"visible",exit:"hidden",className:"uds-end-icon",children:j(c,{icon:h,className:W.endIcon,iconProps:{size:"sm",variant:_?"fill":"outline",color:"current"}})})})]})});J.displayName="MenuItemBase";var K=v(function({active:r,hideOnClick:e,...a},d){const t={root:n({menuItemVariantRoot:"default",menuItemVariantActiveRoot:r?"on":"off"}),text:n({menuItemVariantText:"default",menuItemVariantActiveText:r?"on":"off"}),startIcon:n({menuItemVariantIcon:"default",menuItemVariantActiveIcon:r?"on":"off"})};return j(J,{ref:d,as:p,active:r,layerClassNames:t,rootProps:{hideOnClick:e},...a})});K.displayName="MenuItem";var q=v(function({name:r,endIcon:a=e,checked:d,defaultChecked:t,hideOnClick:s,className:c,...o},u){const l=r,x=C(!1),p=m(),b=T(p);I(()=>{!x.current&&void 0!==t&&p&&(p.setValues(r=>({...r,[l]:t})),x.current=!0)},[p,t,l]);const f=w(()=>{if(void 0!==d)return d;if(b?.items?.length){const r=b?.items.find(r=>r.element?.name===l);if(r?.element)return r.element.checked}const r=b?.values[l];return"boolean"==typeof r?r:t??!1},[b?.items,b?.values,l,d,t]),_=k(r=>{void 0===d&&p?.setValues(e=>({...e,[l]:r.target.checked}))},[l,p,d]),v={root:n({menuItemCheckboxVariantRoot:"default",menuItemCheckboxVariantActiveRoot:f?"on":"off"}),text:n({menuItemCheckboxVariantText:"default",menuItemCheckboxVariantActiveText:f?"on":"off"}),startIcon:n({menuItemCheckboxVariantStartIcon:"default",menuItemCheckboxVariantActiveStartIcon:f?"on":"off"}),endIcon:n({menuItemCheckboxVariantEndIcon:"default",menuItemCheckboxVariantActiveEndIcon:f?"on":"off"})};return j(J,{ref:u,as:h,hideEndIcon:!f,endIcon:a,active:f,className:i("uds-menu-item-checkbox",c),layerClassNames:v,name:r,rootProps:{onChange:_,defaultChecked:t,checked:void 0!==d?d:void 0,hideOnClick:s},...o})});q.displayName="MenuItemCheckbox";var Q=()=>{if("undefined"==typeof document)return!1;return"rtl"===getComputedStyle(document.documentElement).direction},U=r=>{const[e,a]=g(Q);return I(()=>{if(r?.explicit)return void a(r.explicit);const e=(r=>{const e=new MutationObserver(e=>{e.some(r=>"attributes"===r.type&&"dir"===r.attributeName)&&r()});return e.observe(document.documentElement,{attributes:!0,attributeFilter:["dir"]}),e})(()=>{a(Q())});return()=>e.disconnect()},[r?.explicit]),e},Y=function({placement:r="bottom",rtl:e,...a}){const d=U({explicit:e}),t=((r,e)=>{const a=e?.rtl;if("start"===r)return a?"right":"left";if("end"===r)return a?"left":"right";if(r?.includes("-")){const[e,d]=r.split("-");if(!("start"!==e&&"end"!==e||"top"!==d&&"bottom"!==d))return`${"start"===e?a?"right":"left":a?"left":"right"}-${"bottom"===d?"end":"start"}`;if("top"===e||"bottom"===e)return`${e}-${"start"===d?a?"end":"start":a?"start":"end"}`}return r})(r,{rtl:d});return j(s,{children:j(b,{placement:t,rtl:d,...a})})},Z=v(function({asChild:r,children:e,className:a,...d},t){const s=C(null),n=r?{render:j(o,{asChild:!0,ref:s,className:"uds-ring h-fit w-fit",children:e})}:{children:e},c=k(()=>{const r=s.current?.firstChild;r instanceof HTMLElement&&"function"==typeof r.focus&&r.focus()},[s]);return j(f,{onFocus:c,onFocusVisible:c,ref:t,className:i("uds-menu-trigger",a),...n,...d})});export{O as Menu};
|