Getting Started
UI
Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
Forms
Stack
Context Menu
Displays a menu of actions triggered by a right click.
Right click hereLong press here
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-preview',
imports: [HlmDropdownMenuImports, HlmContextMenuImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu class="w-64">
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
Back
<hlm-dropdown-menu-shortcut>⌘[</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem disabled>
Forward
<hlm-dropdown-menu-shortcut>⌘]</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem>
Reload
<hlm-dropdown-menu-shortcut>⌘R</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem [hlmDropdownMenuSubTrigger]="moreTools" align="start" side="right">
More Tools
<hlm-dropdown-menu-item-sub-indicator />
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuCheckbox checked>
Show Bookmarks Bar
<hlm-dropdown-menu-checkbox-indicator />
</button>
<button hlmDropdownMenuCheckbox>
Show full URLs
<hlm-dropdown-menu-checkbox-indicator />
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<hlm-dropdown-menu-label>People</hlm-dropdown-menu-label>
<button hlmDropdownMenuRadio checked>
<hlm-dropdown-menu-radio-indicator />
Pedro Duarte
</button>
<button hlmDropdownMenuRadio>
<hlm-dropdown-menu-radio-indicator />
Colm Tuite
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
<ng-template #moreTools>
<hlm-dropdown-menu-sub class="w-44">
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Save Page...</button>
<button hlmDropdownMenuItem>Create Shortcut...</button>
<button hlmDropdownMenuItem>Name Window...</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Developer Tools</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem variant="destructive">Delete</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu-sub>
</ng-template>
`,
})
export class ContextMenuPreview {}About
Context Menu is built with the help of Menu from Material CDK and Dropdown Menu .
Installation
ng g @spartan-ng/cli:ui context-menunx g @spartan-ng/cli:ui context-menuimport { DestroyRef, ElementRef, HostAttributeToken, Injector, PLATFORM_ID, effect, inject, makeEnvironmentProviders, runInInjectionContext, type EnvironmentProviders } from '@angular/core';
import { OVERLAY_DEFAULT_CONFIG } from '@angular/cdk/overlay';
import { clsx, type ClassValue } from 'clsx';
import { isPlatformBrowser } from '@angular/common';
import { provideSpartanHlm } from '@spartan-ng/helm/utils';
import { twMerge } from 'tailwind-merge';
export function hlm(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
// Global map to track class managers per element
const elementClassManagers = new WeakMap<HTMLElement, ElementClassManager>();
// Global mutation observer for all elements
let globalObserver: MutationObserver | null = null;
const observedElements = new Set<HTMLElement>();
interface ElementClassManager {
element: HTMLElement;
sources: Map<number, { classes: Set<string>; order: number }>;
baseClasses: Set<string>;
isUpdating: boolean;
nextOrder: number;
hasInitialized: boolean;
restoreRafId: number | null;
/** Transitions are suppressed until the first effect writes correct classes */
transitionsSuppressed: boolean;
/** Original inline transition value to restore after suppression (empty string = none was set) */
previousTransition: string;
/** Original inline transition priority to preserve !important when restoring */
previousTransitionPriority: string;
}
let sourceCounter = 0;
/**
* This function dynamically adds and removes classes for a given element without requiring
* the a class binding (e.g. `[class]="..."`) which may interfere with other class bindings.
*
* 1. This will merge the existing classes on the element with the new classes.
* 2. It will also remove any classes that were previously added by this function but are no longer present in the new classes.
* 3. Multiple calls to this function on the same element will be merged efficiently.
*/
export function classes(computed: () => ClassValue[] | string, options: ClassesOptions = {}) {
runInInjectionContext(options.injector ?? inject(Injector), () => {
const elementRef = options.elementRef ?? inject(ElementRef);
const platformId = inject(PLATFORM_ID);
const destroyRef = inject(DestroyRef);
const baseClasses = inject(new HostAttributeToken('class'), { optional: true });
const element = elementRef.nativeElement;
// Create unique identifier for this source
const sourceId = sourceCounter++;
// Get or create the class manager for this element
let manager = elementClassManagers.get(element);
if (!manager) {
// Initialize base classes from variation (host attribute 'class')
const initialBaseClasses = new Set<string>();
if (baseClasses) {
toClassList(baseClasses).forEach((cls) => initialBaseClasses.add(cls));
}
manager = {
element,
sources: new Map(),
baseClasses: initialBaseClasses,
isUpdating: false,
nextOrder: 0,
hasInitialized: false,
restoreRafId: null,
transitionsSuppressed: false,
previousTransition: '',
previousTransitionPriority: '',
};
elementClassManagers.set(element, manager);
// Setup global observer if needed and register this element
setupGlobalObserver(platformId);
observedElements.add(element);
// Suppress transitions until the first effect writes correct classes and
// the browser has painted them. This prevents CSS transition animations
// during hydration when classes change from SSR state to client state.
if (isPlatformBrowser(platformId)) {
manager.previousTransition = element.style.getPropertyValue('transition');
manager.previousTransitionPriority = element.style.getPropertyPriority('transition');
element.style.setProperty('transition', 'none', 'important');
manager.transitionsSuppressed = true;
}
}
// Assign order once at registration time
const sourceOrder = manager.nextOrder++;
function updateClasses(): void {
// Get the new classes from the computed function
const newClasses = toClassList(computed());
// Update this source's classes, keeping the original order
manager!.sources.set(sourceId, {
classes: new Set(newClasses),
order: sourceOrder,
});
// Update the element
updateElement(manager!);
// Re-enable transitions after the first effect writes correct classes.
// Deferred to next animation frame so the browser paints the class change
// with transitions disabled first, then re-enables them.
if (manager!.transitionsSuppressed) {
manager!.transitionsSuppressed = false;
manager!.restoreRafId = requestAnimationFrame(() => {
manager!.restoreRafId = null;
restoreTransitionSuppression(manager!);
});
}
}
// Register cleanup with DestroyRef
destroyRef.onDestroy(() => {
if (manager!.restoreRafId !== null) {
cancelAnimationFrame(manager!.restoreRafId);
manager!.restoreRafId = null;
}
if (manager!.transitionsSuppressed) {
manager!.transitionsSuppressed = false;
restoreTransitionSuppression(manager!);
}
// Remove this source from the manager
manager!.sources.delete(sourceId);
// If no more sources, clean up the manager
if (manager!.sources.size === 0) {
cleanupManager(element);
} else {
// Update element without this source's classes
updateElement(manager!);
}
});
/**
* We need this effect to track changes to the computed classes. Ideally, we would use
* afterRenderEffect here, but that doesn't run in SSR contexts, so we use a standard
* effect which works in both browser and SSR.
*/
effect(updateClasses);
});
}
function restoreTransitionSuppression(manager: ElementClassManager): void {
const prev = manager.previousTransition;
if (prev) {
manager.element.style.setProperty('transition', prev, manager.previousTransitionPriority || undefined);
} else {
manager.element.style.removeProperty('transition');
}
}
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
function setupGlobalObserver(platformId: Object): void {
if (isPlatformBrowser(platformId) && !globalObserver) {
// Create single global observer that watches the entire document
globalObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
const element = mutation.target as HTMLElement;
const manager = elementClassManagers.get(element);
// Only process elements we're managing
if (manager && observedElements.has(element)) {
if (manager.isUpdating) continue; // Ignore changes we're making
// Update base classes to include any externally added classes
const currentClasses = toClassList(element.className);
const allSourceClasses = new Set<string>();
// Collect all classes from all sources
for (const source of manager.sources.values()) {
for (const className of source.classes) {
allSourceClasses.add(className);
}
}
// Any classes not from sources become new base classes
manager.baseClasses.clear();
for (const className of currentClasses) {
if (!allSourceClasses.has(className)) {
manager.baseClasses.add(className);
}
}
updateElement(manager);
}
}
}
});
// Start observing the entire document for class attribute changes
globalObserver.observe(document, {
attributes: true,
attributeFilter: ['class'],
subtree: true, // Watch all descendants
});
}
}
function updateElement(manager: ElementClassManager): void {
if (manager.isUpdating) return; // Prevent recursive updates
manager.isUpdating = true;
// Handle initialization: capture base classes after first source registration
if (!manager.hasInitialized && manager.sources.size > 0) {
// Get current classes on element (may include SSR classes)
const currentClasses = toClassList(manager.element.className);
// Get all classes that will be applied by sources
const allSourceClasses = new Set<string>();
for (const source of manager.sources.values()) {
source.classes.forEach((className) => allSourceClasses.add(className));
}
// Only consider classes as "base" if they're not produced by any source
// This prevents SSR-rendered classes from being preserved as base classes
currentClasses.forEach((className) => {
if (!allSourceClasses.has(className)) {
manager.baseClasses.add(className);
}
});
manager.hasInitialized = true;
}
// Get classes from all sources, sorted by registration order (later takes precedence)
const sortedSources = Array.from(manager.sources.entries()).sort(([, a], [, b]) => a.order - b.order);
const allSourceClasses: string[] = [];
for (const [, source] of sortedSources) {
allSourceClasses.push(...source.classes);
}
// Combine base classes with all source classes, ensuring base classes take precedence
const classesToApply =
allSourceClasses.length > 0 || manager.baseClasses.size > 0
? hlm([...allSourceClasses, ...manager.baseClasses])
: '';
// Apply the classes to the element
if (manager.element.className !== classesToApply) {
manager.element.className = classesToApply;
}
manager.isUpdating = false;
}
function cleanupManager(element: HTMLElement): void {
// Remove from global tracking
observedElements.delete(element);
elementClassManagers.delete(element);
// If no more elements being tracked, cleanup global observer
if (observedElements.size === 0 && globalObserver) {
globalObserver.disconnect();
globalObserver = null;
}
}
interface ClassesOptions {
elementRef?: ElementRef<HTMLElement>;
injector?: Injector;
}
// Cache for parsed class lists to avoid repeated string operations
const classListCache = new Map<string, string[]>();
function toClassList(className: string | ClassValue[]): string[] {
// For simple string inputs, use cache to avoid repeated parsing
if (typeof className === 'string' && classListCache.has(className)) {
return classListCache.get(className)!;
}
const result = clsx(className)
.split(' ')
.filter((c) => c.length > 0);
// Cache string results, but limit cache size to prevent memory growth
if (typeof className === 'string' && classListCache.size < 1000) {
classListCache.set(className, result);
}
return result;
}
/**
* Provides default configuration for Spartan Helm components.
*
* This utility configures the Angular CDK overlay to disable the `usePopover`
* behavior introduced in Angular 21, which causes CDK overlay-based components
* (sheets, dialogs, tooltips, etc.) to render above `position: fixed` elements
* like `<hlm-toaster>`.
*
* @returns {EnvironmentProviders} Environment providers to be added to the application config.
*
* @example
* ```ts
* // app.config.ts
*
*
* export const appConfig: ApplicationConfig = {
* providers: [
* provideSpartanHlm(),
* // ... other providers
* ],
* };
* ```
*/
export function provideSpartanHlm(): EnvironmentProviders {
return makeEnvironmentProviders([
{
provide: OVERLAY_DEFAULT_CONFIG,
useValue: { usePopover: false },
},
]);
}import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive, InjectionToken, booleanAttribute, computed, effect, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { createMenuPosition, type MenuAlign, type MenuSide } from '@spartan-ng/brain/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { type BooleanInput } from '@angular/cdk/coercion';
export interface HlmContextMenuConfig {
align: MenuAlign;
side: MenuSide;
}
const defaultConfig: HlmContextMenuConfig = {
align: 'start',
side: 'bottom',
};
const HlmContextMenuConfigToken = new InjectionToken<HlmContextMenuConfig>('HlmContextMenuConfig');
export function provideHlmContextMenuConfig(config: Partial<HlmContextMenuConfig>): ValueProvider {
return { provide: HlmContextMenuConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmContextMenuConfig(): HlmContextMenuConfig {
return inject(HlmContextMenuConfigToken, { optional: true }) ?? defaultConfig;
}
@Directive({
selector: '[hlmContextMenuTrigger]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: hlmContextMenuTrigger',
'cdkContextMenuTriggerData: hlmContextMenuTriggerData',
'cdkContextMenuDisabled: disabled',
],
outputs: ['cdkContextMenuOpened: hlmContextMenuOpened', 'cdkContextMenuClosed: hlmContextMenuClosed'],
},
],
host: {
'data-slot': 'context-menu-trigger',
'[attr.data-disabled]': 'disabled() ? "" : null',
},
})
export class HlmContextMenuTrigger {
private readonly _cdkTrigger = inject(CdkContextMenuTrigger, { host: true });
private readonly _config = injectHlmContextMenuConfig();
public readonly disabled = input<boolean, BooleanInput>(this._cdkTrigger.disabled, { transform: booleanAttribute });
public readonly align = input<MenuAlign>(this._config.align);
public readonly side = input<MenuSide>(this._config.side);
private readonly _menuPosition = computed(() => createMenuPosition(this.align(), this.side()));
constructor() {
// once the trigger opens we wait until the next tick and then grab the last position
// used to position the menu. we store this in our trigger which the brnMenu directive has
// access to through DI
this._cdkTrigger.opened.pipe(takeUntilDestroyed()).subscribe(() =>
setTimeout(
() =>
// eslint-disable-next-line
((this._cdkTrigger as any)._spartanLastPosition = // eslint-disable-next-line
(this._cdkTrigger as any).overlayRef._positionStrategy._lastPosition),
),
);
effect(() => {
this._cdkTrigger.menuPosition = this._menuPosition();
});
classes(() => 'select-none');
}
}
export const HlmContextMenuImports = [HlmContextMenuTrigger] as const;import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive, InjectionToken, booleanAttribute, computed, effect, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { createMenuPosition, type MenuAlign, type MenuSide } from '@spartan-ng/brain/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { type BooleanInput } from '@angular/cdk/coercion';
export interface HlmContextMenuConfig {
align: MenuAlign;
side: MenuSide;
}
const defaultConfig: HlmContextMenuConfig = {
align: 'start',
side: 'bottom',
};
const HlmContextMenuConfigToken = new InjectionToken<HlmContextMenuConfig>('HlmContextMenuConfig');
export function provideHlmContextMenuConfig(config: Partial<HlmContextMenuConfig>): ValueProvider {
return { provide: HlmContextMenuConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmContextMenuConfig(): HlmContextMenuConfig {
return inject(HlmContextMenuConfigToken, { optional: true }) ?? defaultConfig;
}
@Directive({
selector: '[hlmContextMenuTrigger]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: hlmContextMenuTrigger',
'cdkContextMenuTriggerData: hlmContextMenuTriggerData',
'cdkContextMenuDisabled: disabled',
],
outputs: ['cdkContextMenuOpened: hlmContextMenuOpened', 'cdkContextMenuClosed: hlmContextMenuClosed'],
},
],
host: {
'data-slot': 'context-menu-trigger',
'[attr.data-disabled]': 'disabled() ? "" : null',
},
})
export class HlmContextMenuTrigger {
private readonly _cdkTrigger = inject(CdkContextMenuTrigger, { host: true });
private readonly _config = injectHlmContextMenuConfig();
public readonly disabled = input<boolean, BooleanInput>(this._cdkTrigger.disabled, { transform: booleanAttribute });
public readonly align = input<MenuAlign>(this._config.align);
public readonly side = input<MenuSide>(this._config.side);
private readonly _menuPosition = computed(() => createMenuPosition(this.align(), this.side()));
constructor() {
// once the trigger opens we wait until the next tick and then grab the last position
// used to position the menu. we store this in our trigger which the brnMenu directive has
// access to through DI
this._cdkTrigger.opened.pipe(takeUntilDestroyed()).subscribe(() =>
setTimeout(
() =>
// eslint-disable-next-line
((this._cdkTrigger as any)._spartanLastPosition = // eslint-disable-next-line
(this._cdkTrigger as any).overlayRef._positionStrategy._lastPosition),
),
);
effect(() => {
this._cdkTrigger.menuPosition = this._menuPosition();
});
classes(() => 'select-none');
}
}
export const HlmContextMenuImports = [HlmContextMenuTrigger] as const;import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive, InjectionToken, booleanAttribute, computed, effect, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { createMenuPosition, type MenuAlign, type MenuSide } from '@spartan-ng/brain/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { type BooleanInput } from '@angular/cdk/coercion';
export interface HlmContextMenuConfig {
align: MenuAlign;
side: MenuSide;
}
const defaultConfig: HlmContextMenuConfig = {
align: 'start',
side: 'bottom',
};
const HlmContextMenuConfigToken = new InjectionToken<HlmContextMenuConfig>('HlmContextMenuConfig');
export function provideHlmContextMenuConfig(config: Partial<HlmContextMenuConfig>): ValueProvider {
return { provide: HlmContextMenuConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmContextMenuConfig(): HlmContextMenuConfig {
return inject(HlmContextMenuConfigToken, { optional: true }) ?? defaultConfig;
}
@Directive({
selector: '[hlmContextMenuTrigger]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: hlmContextMenuTrigger',
'cdkContextMenuTriggerData: hlmContextMenuTriggerData',
'cdkContextMenuDisabled: disabled',
],
outputs: ['cdkContextMenuOpened: hlmContextMenuOpened', 'cdkContextMenuClosed: hlmContextMenuClosed'],
},
],
host: {
'data-slot': 'context-menu-trigger',
'[attr.data-disabled]': 'disabled() ? "" : null',
},
})
export class HlmContextMenuTrigger {
private readonly _cdkTrigger = inject(CdkContextMenuTrigger, { host: true });
private readonly _config = injectHlmContextMenuConfig();
public readonly disabled = input<boolean, BooleanInput>(this._cdkTrigger.disabled, { transform: booleanAttribute });
public readonly align = input<MenuAlign>(this._config.align);
public readonly side = input<MenuSide>(this._config.side);
private readonly _menuPosition = computed(() => createMenuPosition(this.align(), this.side()));
constructor() {
// once the trigger opens we wait until the next tick and then grab the last position
// used to position the menu. we store this in our trigger which the brnMenu directive has
// access to through DI
this._cdkTrigger.opened.pipe(takeUntilDestroyed()).subscribe(() =>
setTimeout(
() =>
// eslint-disable-next-line
((this._cdkTrigger as any)._spartanLastPosition = // eslint-disable-next-line
(this._cdkTrigger as any).overlayRef._positionStrategy._lastPosition),
),
);
effect(() => {
this._cdkTrigger.menuPosition = this._menuPosition();
});
classes(() => 'select-none');
}
}
export const HlmContextMenuImports = [HlmContextMenuTrigger] as const;import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive, InjectionToken, booleanAttribute, computed, effect, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { createMenuPosition, type MenuAlign, type MenuSide } from '@spartan-ng/brain/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { type BooleanInput } from '@angular/cdk/coercion';
export interface HlmContextMenuConfig {
align: MenuAlign;
side: MenuSide;
}
const defaultConfig: HlmContextMenuConfig = {
align: 'start',
side: 'bottom',
};
const HlmContextMenuConfigToken = new InjectionToken<HlmContextMenuConfig>('HlmContextMenuConfig');
export function provideHlmContextMenuConfig(config: Partial<HlmContextMenuConfig>): ValueProvider {
return { provide: HlmContextMenuConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmContextMenuConfig(): HlmContextMenuConfig {
return inject(HlmContextMenuConfigToken, { optional: true }) ?? defaultConfig;
}
@Directive({
selector: '[hlmContextMenuTrigger]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: hlmContextMenuTrigger',
'cdkContextMenuTriggerData: hlmContextMenuTriggerData',
'cdkContextMenuDisabled: disabled',
],
outputs: ['cdkContextMenuOpened: hlmContextMenuOpened', 'cdkContextMenuClosed: hlmContextMenuClosed'],
},
],
host: {
'data-slot': 'context-menu-trigger',
'[attr.data-disabled]': 'disabled() ? "" : null',
},
})
export class HlmContextMenuTrigger {
private readonly _cdkTrigger = inject(CdkContextMenuTrigger, { host: true });
private readonly _config = injectHlmContextMenuConfig();
public readonly disabled = input<boolean, BooleanInput>(this._cdkTrigger.disabled, { transform: booleanAttribute });
public readonly align = input<MenuAlign>(this._config.align);
public readonly side = input<MenuSide>(this._config.side);
private readonly _menuPosition = computed(() => createMenuPosition(this.align(), this.side()));
constructor() {
// once the trigger opens we wait until the next tick and then grab the last position
// used to position the menu. we store this in our trigger which the brnMenu directive has
// access to through DI
this._cdkTrigger.opened.pipe(takeUntilDestroyed()).subscribe(() =>
setTimeout(
() =>
// eslint-disable-next-line
((this._cdkTrigger as any)._spartanLastPosition = // eslint-disable-next-line
(this._cdkTrigger as any).overlayRef._positionStrategy._lastPosition),
),
);
effect(() => {
this._cdkTrigger.menuPosition = this._menuPosition();
});
classes(() => 'select-none');
}
}
export const HlmContextMenuImports = [HlmContextMenuTrigger] as const;import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive, InjectionToken, booleanAttribute, computed, effect, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { createMenuPosition, type MenuAlign, type MenuSide } from '@spartan-ng/brain/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { type BooleanInput } from '@angular/cdk/coercion';
export interface HlmContextMenuConfig {
align: MenuAlign;
side: MenuSide;
}
const defaultConfig: HlmContextMenuConfig = {
align: 'start',
side: 'bottom',
};
const HlmContextMenuConfigToken = new InjectionToken<HlmContextMenuConfig>('HlmContextMenuConfig');
export function provideHlmContextMenuConfig(config: Partial<HlmContextMenuConfig>): ValueProvider {
return { provide: HlmContextMenuConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmContextMenuConfig(): HlmContextMenuConfig {
return inject(HlmContextMenuConfigToken, { optional: true }) ?? defaultConfig;
}
@Directive({
selector: '[hlmContextMenuTrigger]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: hlmContextMenuTrigger',
'cdkContextMenuTriggerData: hlmContextMenuTriggerData',
'cdkContextMenuDisabled: disabled',
],
outputs: ['cdkContextMenuOpened: hlmContextMenuOpened', 'cdkContextMenuClosed: hlmContextMenuClosed'],
},
],
host: {
'data-slot': 'context-menu-trigger',
'[attr.data-disabled]': 'disabled() ? "" : null',
},
})
export class HlmContextMenuTrigger {
private readonly _cdkTrigger = inject(CdkContextMenuTrigger, { host: true });
private readonly _config = injectHlmContextMenuConfig();
public readonly disabled = input<boolean, BooleanInput>(this._cdkTrigger.disabled, { transform: booleanAttribute });
public readonly align = input<MenuAlign>(this._config.align);
public readonly side = input<MenuSide>(this._config.side);
private readonly _menuPosition = computed(() => createMenuPosition(this.align(), this.side()));
constructor() {
// once the trigger opens we wait until the next tick and then grab the last position
// used to position the menu. we store this in our trigger which the brnMenu directive has
// access to through DI
this._cdkTrigger.opened.pipe(takeUntilDestroyed()).subscribe(() =>
setTimeout(
() =>
// eslint-disable-next-line
((this._cdkTrigger as any)._spartanLastPosition = // eslint-disable-next-line
(this._cdkTrigger as any).overlayRef._positionStrategy._lastPosition),
),
);
effect(() => {
this._cdkTrigger.menuPosition = this._menuPosition();
});
classes(() => 'select-none');
}
}
export const HlmContextMenuImports = [HlmContextMenuTrigger] as const;import { CdkContextMenuTrigger } from '@angular/cdk/menu';
import { Directive, InjectionToken, booleanAttribute, computed, effect, inject, input, type ValueProvider } from '@angular/core';
import { classes } from '@spartan-ng/helm/utils';
import { createMenuPosition, type MenuAlign, type MenuSide } from '@spartan-ng/brain/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { type BooleanInput } from '@angular/cdk/coercion';
export interface HlmContextMenuConfig {
align: MenuAlign;
side: MenuSide;
}
const defaultConfig: HlmContextMenuConfig = {
align: 'start',
side: 'bottom',
};
const HlmContextMenuConfigToken = new InjectionToken<HlmContextMenuConfig>('HlmContextMenuConfig');
export function provideHlmContextMenuConfig(config: Partial<HlmContextMenuConfig>): ValueProvider {
return { provide: HlmContextMenuConfigToken, useValue: { ...defaultConfig, ...config } };
}
export function injectHlmContextMenuConfig(): HlmContextMenuConfig {
return inject(HlmContextMenuConfigToken, { optional: true }) ?? defaultConfig;
}
@Directive({
selector: '[hlmContextMenuTrigger]',
hostDirectives: [
{
directive: CdkContextMenuTrigger,
inputs: [
'cdkContextMenuTriggerFor: hlmContextMenuTrigger',
'cdkContextMenuTriggerData: hlmContextMenuTriggerData',
'cdkContextMenuDisabled: disabled',
],
outputs: ['cdkContextMenuOpened: hlmContextMenuOpened', 'cdkContextMenuClosed: hlmContextMenuClosed'],
},
],
host: {
'data-slot': 'context-menu-trigger',
'[attr.data-disabled]': 'disabled() ? "" : null',
},
})
export class HlmContextMenuTrigger {
private readonly _cdkTrigger = inject(CdkContextMenuTrigger, { host: true });
private readonly _config = injectHlmContextMenuConfig();
public readonly disabled = input<boolean, BooleanInput>(this._cdkTrigger.disabled, { transform: booleanAttribute });
public readonly align = input<MenuAlign>(this._config.align);
public readonly side = input<MenuSide>(this._config.side);
private readonly _menuPosition = computed(() => createMenuPosition(this.align(), this.side()));
constructor() {
// once the trigger opens we wait until the next tick and then grab the last position
// used to position the menu. we store this in our trigger which the brnMenu directive has
// access to through DI
this._cdkTrigger.opened.pipe(takeUntilDestroyed()).subscribe(() =>
setTimeout(
() =>
// eslint-disable-next-line
((this._cdkTrigger as any)._spartanLastPosition = // eslint-disable-next-line
(this._cdkTrigger as any).overlayRef._positionStrategy._lastPosition),
),
);
effect(() => {
this._cdkTrigger.menuPosition = this._menuPosition();
});
classes(() => 'select-none');
}
}
export const HlmContextMenuImports = [HlmContextMenuTrigger] as const;Usage
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';<div [hlmContextMenuTrigger]="menu">Right click here</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Profile</button>
<button hlmDropdownMenuItem>Billing</button>
<button hlmDropdownMenuItem>Team</button>
<button hlmDropdownMenuItem>Subscription</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>Examples
Basic
Right click hereLong press here
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-basic',
imports: [HlmDropdownMenuImports, HlmContextMenuImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Back</button>
<button hlmDropdownMenuItem disabled>Forward</button>
<button hlmDropdownMenuItem>Reload</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ContextMenuBasic {}Submenu
Right click hereLong press here
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-submenu',
imports: [HlmDropdownMenuImports, HlmContextMenuImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Copy</button>
<button hlmDropdownMenuItem disabled>Cut</button>
<button hlmDropdownMenuItem [hlmDropdownMenuSubTrigger]="moreTools" align="start" side="right">
More Tools
<hlm-dropdown-menu-item-sub-indicator />
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
<ng-template #moreTools>
<hlm-dropdown-menu-sub class="w-44">
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Save Page...</button>
<button hlmDropdownMenuItem>Create Shortcut...</button>
<button hlmDropdownMenuItem>Name Window...</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Developer Tools</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem variant="destructive">Delete</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu-sub>
</ng-template>
`,
})
export class ContextMenuSubmenu {}Shortcuts
Right click hereLong press here
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-shortcuts',
imports: [HlmDropdownMenuImports, HlmContextMenuImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
Back
<hlm-dropdown-menu-shortcut>⌘[</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem disabled>
Forward
<hlm-dropdown-menu-shortcut>⌘]</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem>
Reload
<hlm-dropdown-menu-shortcut>⌘R</hlm-dropdown-menu-shortcut>
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
Save
<hlm-dropdown-menu-shortcut>⌘S</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem>
Save As...
<hlm-dropdown-menu-shortcut>⇧⌘S</hlm-dropdown-menu-shortcut>
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ContextMenuShortcuts {}Icons
Right click hereLong press here
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideClipboardPaste, lucideCopy, lucideScissors, lucideTrash } from '@ng-icons/lucide';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-icons',
imports: [HlmDropdownMenuImports, HlmContextMenuImports, NgIcon],
providers: [provideIcons({ lucideCopy, lucideClipboardPaste, lucideScissors, lucideTrash })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
<ng-icon name="lucideCopy" />
Copy
</button>
<button hlmDropdownMenuItem>
<ng-icon name="lucideScissors" />
Cut
</button>
<button hlmDropdownMenuItem>
<ng-icon name="lucideClipboardPaste" />
Paste
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem variant="destructive">
<ng-icon name="lucideTrash" />
Delete
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ContextMenuIcons {}Destructive
Right click hereLong press here
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucidePencil, lucideShare, lucideTrash } from '@ng-icons/lucide';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-destructive',
imports: [HlmDropdownMenuImports, HlmContextMenuImports, NgIcon],
providers: [provideIcons({ lucidePencil, lucideShare, lucideTrash })],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
<ng-icon name="lucidePencil" />
Edit
</button>
<button hlmDropdownMenuItem>
<ng-icon name="lucideShare" />
Share
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem variant="destructive">
<ng-icon name="lucideTrash" />
Delete
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ContextMenuDestructive {}Sides
Right click (top)Long press (top)
Right click (right)Long press (right)
Right click (bottom)Long press (bottom)
Right click (left)Long press (left)
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-sides',
imports: [HlmDropdownMenuImports, HlmContextMenuImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="grid w-full max-w-sm grid-cols-2 gap-4">
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="top"
class="flex aspect-video w-full max-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click (top)</span>
<span class="hidden pointer-coarse:inline-block">Long press (top)</span>
</div>
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full max-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click (right)</span>
<span class="hidden pointer-coarse:inline-block">Long press (right)</span>
</div>
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="bottom"
class="flex aspect-video w-full max-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click (bottom)</span>
<span class="hidden pointer-coarse:inline-block">Long press (bottom)</span>
</div>
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="left"
class="flex aspect-video w-full max-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click (left)</span>
<span class="hidden pointer-coarse:inline-block">Long press (left)</span>
</div>
</div>
<ng-template #menu>
<hlm-dropdown-menu>
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>Back</button>
<button hlmDropdownMenuItem disabled>Forward</button>
<button hlmDropdownMenuItem>Reload</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ContextMenuSides {}Stateful
Right click hereLong press here
Unsaved Changes
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-with-state',
imports: [HlmDropdownMenuImports, HlmContextMenuImports],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div
align="start"
side="right"
[hlmContextMenuTriggerData]="{ $implicit: { data: 'Changes Saved' } }"
[hlmContextMenuTrigger]="menu"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">Right click here</span>
<span class="hidden pointer-coarse:inline-block">Long press here</span>
</div>
<div class="mt-2 text-center font-mono text-xs">{{ _pastedContent() }}</div>
<ng-template #menu let-ctx>
<hlm-dropdown-menu class="w-64">
<hlm-dropdown-menu-group>
<button (click)="_pastedContent.set(ctx.data)" inset hlmDropdownMenuItem>
Save
<hlm-dropdown-menu-shortcut>⌘S</hlm-dropdown-menu-shortcut>
</button>
</hlm-dropdown-menu-group>
<button (click)="_pastedContent.set('Unsaved Changes')" inset hlmDropdownMenuItem>
Back
<hlm-dropdown-menu-shortcut>⌘[</hlm-dropdown-menu-shortcut>
</button>
<button disabled inset hlmDropdownMenuItem>
Forward
<hlm-dropdown-menu-shortcut>⌘]</hlm-dropdown-menu-shortcut>
</button>
<button disabled inset hlmDropdownMenuItem>
Reload
<hlm-dropdown-menu-shortcut>⌘R</hlm-dropdown-menu-shortcut>
</button>
</hlm-dropdown-menu>
</ng-template>
`,
})
export class ContextMenuPreviewWithState {
protected readonly _pastedContent = signal('Unsaved Changes');
}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
انقر بزر الماوس الأيمن هنااضغط مطولاً هنا
import { Directionality } from '@angular/cdk/bidi';
import { ChangeDetectionStrategy, Component, computed, effect, inject, untracked } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideArrowLeft, lucideArrowRight, lucideRotateCcw } from '@ng-icons/lucide';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmContextMenuImports } from '@spartan-ng/helm/context-menu';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
@Component({
selector: 'spartan-context-menu-rtl',
imports: [HlmDropdownMenuImports, HlmContextMenuImports, NgIcon],
providers: [provideIcons({ lucideArrowLeft, lucideArrowRight, lucideRotateCcw }), Directionality],
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'[dir]': '_dir()',
},
template: `
<div
[hlmContextMenuTrigger]="menu"
align="start"
side="right"
class="flex aspect-video w-full min-w-xs items-center justify-center rounded-xl border border-dashed text-sm"
>
<span class="hidden pointer-fine:inline-block">{{ _t()['rightClick'] }}</span>
<span class="hidden pointer-coarse:inline-block">{{ _t()['longPress'] }}</span>
</div>
<ng-template #menu>
<hlm-dropdown-menu class="w-48">
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem [hlmDropdownMenuSubTrigger]="navigationMenu" side="right" align="start">
{{ _t()['navigation'] }}
<hlm-dropdown-menu-item-sub-indicator />
</button>
<button hlmDropdownMenuItem [hlmDropdownMenuSubTrigger]="moreToolsMenu" side="right" align="start">
{{ _t()['moreTools'] }}
<hlm-dropdown-menu-item-sub-indicator />
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuCheckbox checked>
{{ _t()['showBookmarks'] }}
<hlm-dropdown-menu-checkbox-indicator />
</button>
<button hlmDropdownMenuCheckbox>
{{ _t()['showFullUrls'] }}
<hlm-dropdown-menu-checkbox-indicator />
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<hlm-dropdown-menu-label>{{ _t()['people'] }}</hlm-dropdown-menu-label>
<button hlmDropdownMenuRadio checked>
{{ _t()['pedro'] }}
<hlm-dropdown-menu-radio-indicator />
</button>
<button hlmDropdownMenuRadio>
{{ _t()['colm'] }}
<hlm-dropdown-menu-radio-indicator />
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu>
</ng-template>
<ng-template #navigationMenu>
<hlm-dropdown-menu-sub class="w-44">
<button hlmDropdownMenuItem>
<ng-icon name="lucideArrowLeft" />
{{ _t()['back'] }}
<hlm-dropdown-menu-shortcut>⌘[</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem disabled>
<ng-icon name="lucideArrowRight" />
{{ _t()['forward'] }}
<hlm-dropdown-menu-shortcut>⌘]</hlm-dropdown-menu-shortcut>
</button>
<button hlmDropdownMenuItem>
<ng-icon name="lucideRotateCcw" />
{{ _t()['reload'] }}
<hlm-dropdown-menu-shortcut>⌘R</hlm-dropdown-menu-shortcut>
</button>
</hlm-dropdown-menu-sub>
</ng-template>
<ng-template #moreToolsMenu>
<hlm-dropdown-menu-sub class="w-44">
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
{{ _t()['savePage'] }}
</button>
<button hlmDropdownMenuItem>
{{ _t()['createShortcut'] }}
</button>
<button hlmDropdownMenuItem>
{{ _t()['nameWindow'] }}
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem>
{{ _t()['developerTools'] }}
</button>
</hlm-dropdown-menu-group>
<hlm-dropdown-menu-separator />
<hlm-dropdown-menu-group>
<button hlmDropdownMenuItem variant="destructive">
{{ _t()['delete'] }}
</button>
</hlm-dropdown-menu-group>
</hlm-dropdown-menu-sub>
</ng-template>
`,
})
export class ContextMenuRtl {
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {
rightClick: 'Right click here',
longPress: 'Long press here',
navigation: 'Navigation',
back: 'Back',
forward: 'Forward',
reload: 'Reload',
moreTools: 'More Tools',
savePage: 'Save Page...',
createShortcut: 'Create Shortcut...',
nameWindow: 'Name Window...',
developerTools: 'Developer Tools',
delete: 'Delete',
showBookmarks: 'Show Bookmarks',
showFullUrls: 'Show Full URLs',
people: 'People',
pedro: 'Pedro Duarte',
colm: 'Colm Tuite',
},
},
ar: {
dir: 'rtl',
values: {
rightClick: 'انقر بزر الماوس الأيمن هنا',
longPress: 'اضغط مطولاً هنا',
navigation: 'التنقل',
back: 'رجوع',
forward: 'تقدم',
reload: 'إعادة تحميل',
moreTools: 'المزيد من الأدوات',
savePage: 'حفظ الصفحة...',
createShortcut: 'إنشاء اختصار...',
nameWindow: 'تسمية النافذة...',
developerTools: 'أدوات المطور',
delete: 'حذف',
showBookmarks: 'إظهار الإشارات المرجعية',
showFullUrls: 'إظهار عناوين URL الكاملة',
people: 'الأشخاص',
pedro: 'Pedro Duarte',
colm: 'Colm Tuite',
},
},
he: {
dir: 'rtl',
values: {
rightClick: 'לחץ לחיצה ימנית כאן',
longPress: 'לחץ לחיצה ארוכה כאן',
navigation: 'ניווט',
back: 'חזור',
forward: 'קדימה',
reload: 'רענן',
moreTools: 'כלים נוספים',
savePage: 'שמור עמוד...',
createShortcut: 'צור קיצור דרך...',
nameWindow: 'שם חלון...',
developerTools: 'כלי מפתח',
delete: 'מחק',
showBookmarks: 'הצג סימניות',
showFullUrls: 'הצג כתובות URL מלאות',
people: 'אנשים',
pedro: 'Pedro Duarte',
colm: 'Colm Tuite',
},
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
private readonly _directionality = inject(Directionality);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Helm API
HlmContextMenuTrigger
Selector: [hlmContextMenuTrigger]
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | this._cdkTrigger.disabled | - |
| align | MenuAlign | this._config.align | - |
| side | MenuSide | this._config.side | - |
On This Page
Stop configuring. Start shipping.
Zerops powers spartan.ng and Angular teams worldwide.
One-command deployment. Zero infrastructure headaches.
Deploy with Zerops