Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@theme={{@theme}}
@square={{@square}}
@countDown={{@countDown}}
@suffixIcon={{if this.displayContextMenuPanel "fa-chevron-up" "fa-chevron-down"}}
@suffixIcon={{unless @hideArrow (if this.displayContextMenuPanel "fa-chevron-up" "fa-chevron-down")}}
{{did-insert this.registerMenuTrigger}}
{{on "click" this.toggleContextMenuPanel}}
...attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Template = (args) => ({
@loadingOptions={{this.loadingOptions}}
@iconUrl={{this.iconUrl}}
@size={{this.size}}
@hideArrow={{this.hideArrow}}
disabled={{this.disabled}}
@closeOnMouseLeave={{this.closeOnMouseLeave}}
@onMenuOpened={{this.onMenuOpened}}
Expand All @@ -33,6 +34,19 @@ const items = [
{
title: 'Item 3',
action: () => console.log('Item 3 selected')
},
{
title: 'Disabled item',
disabled: true,
tooltip: { title: 'This action is not available yet', placement: 'right' },
action: () => console.log('Disabled item selected')
},
{
title: 'Delete',
groupKey: 'danger',
skin: 'danger',
prefixIcon: { icon: 'fa-trash' },
action: () => console.log('Delete selected')
}
];

Expand All @@ -44,6 +58,7 @@ const defaultArgs = {
icon: 'far fa-envelope-open',
theme: 'light',
size: 'md',
hideArrow: false,
square: false,
countDown: undefined,
loadingOptions: undefined,
Expand Down Expand Up @@ -81,3 +96,12 @@ export default {
};

export const BasicUsage = {};

export const IconTriggerWithoutArrow = {
args: {
label: undefined,
icon: 'far fa-ellipsis-h',
square: true,
hideArrow: true
}
};
9 changes: 9 additions & 0 deletions packages/oss-components/src/components/o-s-s/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

import type { OSSButtonArgs } from './button';
import type { OSSInfiniteSelectOptionSkin, OSSInfiniteSelectOptionTooltip } from './infinite-select/option';

export type ContextMenuItem = {
items?: ContextMenuItem[];
groupKey?: string;
rowRenderer?: ReturnType<typeof ensureSafeComponent>;
disabled?: boolean;
tooltip?: OSSInfiniteSelectOptionTooltip;
skin?: OSSInfiniteSelectOptionSkin;
action: (event?: MouseEvent) => void | boolean;
[key: string]: unknown;
};

export interface OSSContextMenuArgs extends Omit<OSSButtonArgs, 'suffixIcon'> {
/** An array of context menu items to be displayed in the panel */
items: ContextMenuItem[];
/**
* Hides the chevron of the button, for example for a "…" icon trigger
* @default false
*/
hideArrow?: boolean;
/**
* If true, the menu will close when the mouse leaves the panel
* @default false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{{#if this.isInitialized}}
{{#in-element this.portalTarget insertBefore=null}}
<OSS::ScrollablePanel
@plain={{true}}
id={{this.portalId}}
class="context-menu-panel__scrollable-container"
{{did-insert this.registerPanel}}
Expand All @@ -12,9 +13,8 @@
<OSS::InfiniteSelect
@items={{@items}}
@searchEnabled={{false}}
@onSelect={{this.noop}}
@onSelect={{this.selectItem}}
@onClose={{this.closeDropdown}}
@enableKeyboard={{false}}
class="margin-top-px-0 context-menu-panel__dropdown"
{{on-click-outside this.onClickOutside}}
>
Expand All @@ -34,18 +34,16 @@
@selectionType={{item.selectionType}}
@selected={{item.selected}}
@disabled={{item.disabled}}
@tooltip={{item.tooltip}}
@skin={{item.skin}}
@onSelect={{item.action}}
{{did-insert this.registerMouseEnterOnParent (fn this.openSubMenu item.items index)}}
{{on "click" (fn this.openSubMenu item.items index)}}
class="infinit-select-option-panel-container {{if (eq index this.subReferenceIndex) 'active' ''}}"
data-control-name={{item.dataControlName}}
/>
{{else if item.rowRenderer}}
<item.rowRenderer
@item={{item}}
{{did-insert this.registerMouseEnterOnParent this.closeSubMenu}}
{{on "click" (fn this.callAction item.action)}}
/>
<item.rowRenderer @item={{item}} {{did-insert this.registerMouseEnterOnParent this.closeSubMenu}} />
{{else}}
<OSS::InfiniteSelect::Option
@prefixAvatar={{item.prefixAvatar}}
Expand All @@ -61,6 +59,8 @@
@selectionType={{item.selectionType}}
@selected={{item.selected}}
@disabled={{item.disabled}}
@tooltip={{item.tooltip}}
@skin={{item.skin}}
@onSelect={{fn this.callAction item.action}}
{{did-insert this.registerMouseEnterOnParent this.closeSubMenu}}
class="infinit-select-option-panel-container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ export default class OSSContextMenuPanelComponent extends Component<OSSContextMe
}

@action
noop(): void {}
selectItem(item?: ContextMenuItem): void {
if (!item || item.disabled || item.items) return;
this.callAction(item.action);
}

@action
closeDropdown(): void {
this.args.onClose?.();
}

@action
onClickOutside(_: HTMLElement, event: MouseEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class="upf-infinite-select__items-container
{{if (eq this.items.length 0) 'upf-infinite-select__items-container--empty'}}"
{{on-bottom-reached this.onBottomReached}}
{{scroll-shadow}}
{{scroll-shadow followScroll=true}}
{{on "keydown" this.handleKeyEvent}}
>
{{#if (and @loading (not @loadingMore))}}
Expand Down
13 changes: 8 additions & 5 deletions packages/oss-components/src/components/o-s-s/infinite-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ export default class OSSInfiniteSelect extends Component<InfiniteSelectSignature
}

findItemIndex = helper((_, { item }: { item: InfinityItem }): number => {
return Object.values(this.groups)
.flat()
.findIndex((element) => element === item);
return this.itemsInDisplayOrder.findIndex((element) => element === item);
});

get itemsInDisplayOrder(): InfinityItem[] {
return Object.values(this.groups).flat();
}

get groups(): InfinityItemByGroup {
return (this.args.items ?? []).reduce<InfinityItemByGroup>((groups, item) => {
const groupKey = item.groupKey ?? '_ungrouped_';
Expand Down Expand Up @@ -232,7 +234,7 @@ export default class OSSInfiniteSelect extends Component<InfiniteSelectSignature

@action
handleKeyEvent(e: KeyboardEvent): void {
if (!this.searchEnabled && this.enableKeyboard) {
if (this.enableKeyboard) {
this.focusStylesDisabled = false;
}

Expand Down Expand Up @@ -308,7 +310,7 @@ export default class OSSInfiniteSelect extends Component<InfiniteSelectSignature
}

private handleEnter(self: any, e: KeyboardEvent): void {
self.didSelectItem(self.items[self._focusElement]);
self.didSelectItem(self.itemsInDisplayOrder[self._focusElement]);
e.preventDefault();
}

Expand All @@ -321,6 +323,7 @@ export default class OSSInfiniteSelect extends Component<InfiniteSelectSignature
}

private focusFirstItem(self: any, e: KeyboardEvent): void {
self.focusStylesDisabled = false;
self._focusElementAt(self._focusElement);
e.preventDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
role="button"
tabindex="0"
{{on "click" (fn this.onSelect (not this.selected))}}
{{enable-tooltip title=@tooltip.title placement=@tooltip.placement}}
...attributes
>
<div class="oss-infinite-select-option__container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const Template = (args) => ({
@selectionType={{this.selectionType}}
@selected={{this.selected}}
@disabled={{this.disabled}}
@tooltip={{this.tooltip}}
@skin={{this.skin}}
@prefixAvatar={{this.prefixAvatar}}
@prefixBadge={{this.prefixBadge}}
@prefixIcon={{this.prefixIcon}}
Expand All @@ -33,6 +35,8 @@ const defaultArgs = {
selectionType: 'single',
selected: false,
disabled: false,
tooltip: undefined,
skin: 'default',
prefixAvatar: undefined,
prefixBadge: undefined,
prefixIcon: undefined,
Expand Down Expand Up @@ -186,6 +190,27 @@ export const Disabled = {
}
};

export const DisabledWithTooltip = {
args: {
title: 'Disabled Option',
disabled: true,
tooltip: {
title: 'Select at least one creator to use this action',
placement: 'right'
}
}
};

export const Danger = {
args: {
title: 'Remove from list',
skin: 'danger',
prefixIcon: {
icon: 'fa-trash'
}
}
};

export const ComplexExample = {
args: {
title: 'Complex Option',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import type { OSSBadgeArgs } from '../badge';
import type { OSSIconArgs } from '../icon';
import type { OSSTagArgs } from '../tag';

export type OSSInfiniteSelectOptionTooltip = { title: ReturnType<IntlService['t']>; placement?: string };

type IconSpec = OSSIconArgs & {
tooltip?: { title: ReturnType<IntlService['t']>; placement?: string };
tooltip?: OSSInfiniteSelectOptionTooltip;
};

export type OSSInfiniteSelectOptionSkin = 'default' | 'danger';

interface OSSInfiniteSelectOptionComponentSignature {
Args: {
/** Optional avatar displayed before the title. Object with properties: image, initials, size, loading */
Expand Down Expand Up @@ -59,6 +63,16 @@ interface OSSInfiniteSelectOptionComponentSignature {
* @default false
*/
disabled?: boolean;
/**
* Optional tooltip shown when hovering the whole option, including when it is disabled. Object with properties:
* title, placement
*/
tooltip?: OSSInfiniteSelectOptionTooltip;
/**
* The visual variant of the option. Use "danger" for destructive actions
* @default 'default'
*/
skin?: OSSInfiniteSelectOptionSkin;
/** Callback function called when the option is selected/deselected */
onSelect(value: boolean, event?: PointerEvent): void;
};
Expand Down Expand Up @@ -100,6 +114,9 @@ export default class OSSInfiniteSelectOptionComponent extends Component<OSSInfin
if (this.args.disabled) {
classes.push('oss-infinite-select-option--disabled');
}
if (this.args.skin === 'danger') {
classes.push('oss-infinite-select-option--danger');
}
return classes.join(' ');
}

Expand Down
Loading
Loading