Skip to content

Commit

Permalink
enh(weg-tb): configurable animation for context menus
Browse files Browse the repository at this point in the history
  • Loading branch information
luriusTM committed Dec 20, 2024
1 parent 51c2aaa commit be270fc
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 37 deletions.
16 changes: 11 additions & 5 deletions src/apps/seelen_rofi/modules/launcher/infra/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { SeelenCommand } from '@seelen-ui/lib';
import { convertFileSrc, invoke } from '@tauri-apps/api/core';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { Dropdown, Menu } from 'antd';
import { Menu } from 'antd';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { OverflowTooltip } from 'src/apps/shared/components/OverflowTooltip';

import { StartMenuApp } from '../../shared/store/domain';

import { AnimatedDropdown } from '../../../../shared/components/AnimatedWrappers';
import { OverflowTooltip } from '../../../../shared/components/OverflowTooltip';

export const Item = memo(({ item, hidden }: { item: StartMenuApp; hidden: boolean }) => {
const { label, icon, path } = item;

Expand All @@ -22,7 +23,12 @@ export const Item = memo(({ item, hidden }: { item: StartMenuApp; hidden: boolea
const shortPath = path.slice(path.indexOf('\\Programs\\') + 10);

return (
<Dropdown
<AnimatedDropdown
animationDescription={{
maxAnimationTimeMs: 500,
openAnimationName: 'launcher-item-context-menu-open',
closeAnimationName: 'launcher-item-context-menu-close',
}}
trigger={['contextMenu']}
dropdownRender={() => (
<Menu
Expand Down Expand Up @@ -54,6 +60,6 @@ export const Item = memo(({ item, hidden }: { item: StartMenuApp; hidden: boolea
<OverflowTooltip className="launcher-item-label" text={label} />
<OverflowTooltip className="launcher-item-path" text={shortPath} />
</button>
</Dropdown>
</AnimatedDropdown>
);
});
14 changes: 10 additions & 4 deletions src/apps/seelenweg/components/WithContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Dropdown, Menu } from 'antd';
import { Menu } from 'antd';
import { ItemType, MenuItemType } from 'antd/es/menu/interface';
import { PropsWithChildren, useState } from 'react';

import { BackgroundByLayersV2 } from './BackgroundByLayers/infra';

import { useWindowFocusChange } from 'src/apps/shared/hooks';
import { AnimatedDropdown } from '../../shared/components/AnimatedWrappers';
import { useWindowFocusChange } from '../../shared/hooks';

interface Props extends PropsWithChildren {
items: ItemType<MenuItemType>[];
Expand All @@ -21,7 +22,12 @@ export function WithContextMenu({ children, items, onOpenChange }: Props) {
});

return (
<Dropdown
<AnimatedDropdown
animationDescription={{
maxAnimationTimeMs: 500,
openAnimationName: 'weg-context-menu-container-open',
closeAnimationName: 'weg-context-menu-container-close',
}}
placement="topLeft"
open={openContextMenu}
onOpenChange={(isOpen) => {
Expand Down Expand Up @@ -49,6 +55,6 @@ export function WithContextMenu({ children, items, onOpenChange }: Props) {
)}
>
{children}
</Dropdown>
</AnimatedDropdown>
);
}
2 changes: 1 addition & 1 deletion src/apps/seelenweg/modules/item/infra/UserApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RootState,
} from '../../shared/store/domain';

import AnimatedPopover from '../../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../../shared/components/AnimatedWrappers';
import { cx } from '../../../../shared/styles';
import { WithContextMenu } from '../../../components/WithContextMenu';
import { getMenuForItem } from '../../bar/menu';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Dropdown, DropdownProps } from 'antd';
import { useState } from 'react';

import { CustomAnimationProps } from '../domain';

import { useTimeout } from '../../../hooks';
import { cx } from '../../../styles';

export interface AnimatedDropwonProps extends DropdownProps {
animationDescription: CustomAnimationProps;
}

export function AnimatedDropdown({ children, open, dropdownRender, animationDescription, ...dropdownProps }: AnimatedDropwonProps) {
const [delayedOpenPopover, setDelayedOpenPopover] = useState(false);

useTimeout(() => {
setDelayedOpenPopover(!!open);
}, animationDescription.maxAnimationTimeMs, [open]);

const animationObject = {};
if (animationDescription.openAnimationName) {
animationObject[animationDescription.openAnimationName] = open && !delayedOpenPopover;
}
if (animationDescription.closeAnimationName) {
animationObject[animationDescription.closeAnimationName] = delayedOpenPopover && !open;
}

return (
<Dropdown
open={open || delayedOpenPopover}
{...dropdownProps}
dropdownRender={(origin) => dropdownRender &&
<div className={cx(animationObject)}>
{dropdownRender(origin)}
</div>
}
>
{children}
</Dropdown>
);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { Popover, PopoverProps } from 'antd';
import { useState } from 'react';

import { useTimeout } from '../../hooks';
import { cx } from '../../styles';
import { CustomAnimationProps } from '../domain';

export interface PopoverAnimationProps {
maxAnimationTimeMs: number;
openAnimationName: String;
closeAnimationName: String;
}
import { useTimeout } from '../../../hooks';
import { cx } from '../../../styles';

export interface AnimatedPopoverProps extends PopoverProps {
animationDescription: PopoverAnimationProps;
animationDescription: CustomAnimationProps;
}

export default function AnimatedPopover({ children, open, content, animationDescription, ...popoverProps }: AnimatedPopoverProps) {
export function AnimatedPopover({ children, open, content, animationDescription, ...popoverProps }: AnimatedPopoverProps) {
const [delayedOpenPopover, setDelayedOpenPopover] = useState(false);

useTimeout(() => {
Expand Down
5 changes: 5 additions & 0 deletions src/apps/shared/components/AnimatedWrappers/domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CustomAnimationProps {
maxAnimationTimeMs: number;
openAnimationName: String;
closeAnimationName: String;
}
2 changes: 2 additions & 0 deletions src/apps/shared/components/AnimatedWrappers/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { AnimatedDropdown } from './AnimatedDropdown';
export { AnimatedPopover } from './AnimatedPopover';
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/Date/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BackgroundByLayersV2 } from '../../../seelenweg/components/BackgroundBy

import { useWindowFocusChange } from 'src/apps/shared/hooks';

import AnimatedPopover from '../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../shared/components/AnimatedWrappers';
import { Icon } from '../../../shared/components/Icon';
import { cx } from '../../../shared/styles';

Expand Down
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/Notifications/infra/Module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useWindowFocusChange } from 'src/apps/shared/hooks';

import { RootState } from '../../shared/store/domain';

import AnimatedPopover from '../../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../../shared/components/AnimatedWrappers';
import { ArrivalPreview } from './ArrivalPreview';
import { Notifications } from './Notifications';

Expand Down
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/Settings/infra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useWindowFocusChange } from 'src/apps/shared/hooks';

import { RootState } from '../shared/store/domain';

import AnimatedPopover from '../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../shared/components/AnimatedWrappers';
import { Icon } from '../../../shared/components/Icon';

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/Tray/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useWindowFocusChange } from 'src/apps/shared/hooks';

import { TrayInfo } from '../shared/store/domain';

import AnimatedPopover from '../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../shared/components/AnimatedWrappers';
import { OverflowTooltip } from '../../../shared/components/OverflowTooltip';

interface Props {
Expand Down
12 changes: 9 additions & 3 deletions src/apps/toolbar/modules/item/infra/infra.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GenericToolbarItem } from '@seelen-ui/lib/types';
import { Dropdown, Menu } from 'antd';
import { Menu } from 'antd';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -10,6 +10,7 @@ import { SavePlaceholderAsCustom } from '../../main/application';
import { RootActions, Selectors } from '../../shared/store/app';
import { useWindowFocusChange } from 'src/apps/shared/hooks';

import { AnimatedDropdown } from '../../../../shared/components/AnimatedWrappers';
import { Icon } from '../../../../shared/components/Icon';
import { InnerItem, InnerItemProps } from './Inner';

Expand All @@ -26,7 +27,12 @@ export function Item(props: InnerItemProps) {
});

return (
<Dropdown
<AnimatedDropdown
animationDescription={{
maxAnimationTimeMs: 500,
openAnimationName: 'ft-bar-item-context-menu-open',
closeAnimationName: 'ft-bar-item-context-menu-close',
}}
open={openContextMenu}
onOpenChange={setOpenContextMenu}
trigger={['contextMenu']}
Expand All @@ -51,7 +57,7 @@ export function Item(props: InnerItemProps) {
)}
>
<InnerItem {...props} clickable={!!props.onClick} />
</Dropdown>
</AnimatedDropdown>
);
}

Expand Down
13 changes: 9 additions & 4 deletions src/apps/toolbar/modules/main/infra.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HideMode } from '@seelen-ui/lib';
import { ToolbarModuleType as ToolbarItemType } from '@seelen-ui/lib';
import { Placeholder, Plugin, ToolbarItem } from '@seelen-ui/lib/types';
import { Dropdown } from 'antd';
import { Reorder, useForceUpdate } from 'framer-motion';
import { debounce } from 'lodash';
import { JSXElementConstructor, useCallback, useLayoutEffect, useState } from 'react';
Expand All @@ -19,8 +18,9 @@ import { SettingsModule } from '../Settings/infra';

import { RootActions, Selectors } from '../shared/store/app';
import { SavePlaceholderAsCustom } from './application';
import { useWindowFocusChange } from 'src/apps/shared/hooks';

import { AnimatedDropdown } from '../../../shared/components/AnimatedWrappers';
import { useWindowFocusChange } from '../../../shared/hooks';
import { cx } from '../../../shared/styles';
import { TrayModule } from '../Tray';
import { WorkspacesModule } from '../Workspaces';
Expand Down Expand Up @@ -140,7 +140,12 @@ export function ToolBar({ structure }: Props) {
!isAppFocused && hideMode !== HideMode.Never && (isOverlaped || hideMode === HideMode.Always);

return (
<Dropdown
<AnimatedDropdown
animationDescription={{
maxAnimationTimeMs: 500,
openAnimationName: 'ft-bar-context-menu-open',
closeAnimationName: 'ft-bar-context-menu-close',
}}
trigger={['contextMenu']}
open={openContextMenu}
onOpenChange={setOpenContextMenu}
Expand Down Expand Up @@ -175,6 +180,6 @@ export function ToolBar({ structure }: Props) {
{structure.right.map(componentByModule.bind(null, plugins))}
</div>
</Reorder.Group>
</Dropdown>
</AnimatedDropdown>
);
}
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/media/infra/MediaControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { calcLuminance } from '../application';

import { MediaChannelTransportData, MediaDevice } from '../../shared/store/domain';

import AnimatedPopover from '../../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../../shared/components/AnimatedWrappers';
import { Icon } from '../../../../shared/components/Icon';
import { OverflowTooltip } from '../../../../shared/components/OverflowTooltip';
import { useTimeout, useWindowFocusChange } from '../../../../shared/hooks';
Expand Down
2 changes: 1 addition & 1 deletion src/apps/toolbar/modules/network/infra/WlanSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useWindowFocusChange } from 'src/apps/shared/hooks';

import { WlanBssEntry } from '../domain';

import AnimatedPopover from '../../../../shared/components/AnimatedPopover';
import { AnimatedPopover } from '../../../../shared/components/AnimatedWrappers';
import { WlanSelectorEntry } from './WlanSelectorEntry';

function WlanSelector({ open }: { open: boolean }) {
Expand Down
17 changes: 17 additions & 0 deletions static/themes/default/theme.launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ body {
}
}

@keyframes PopupBaseAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}

.launcher-item-context-menu-open,
.launcher-item-context-menu-close {
animation: PopupBaseAnimation 0.2s linear forwards;
}
.launcher-item-context-menu-close {
animation-direction: reverse;
}

.launcher-body {
display: flex;
flex-direction: column;
Expand Down
6 changes: 3 additions & 3 deletions static/themes/default/theme.toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
}


.notification-open, .settings-open, .calendar-open, .tray-open, .wlan-open, .media-open,
.notification-close, .settings-close, .calendar-close, .tray-close, .wlan-close, .media-close {
.notification-open, .settings-open, .calendar-open, .tray-open, .wlan-open, .media-open, .ft-bar-item-context-menu-open, .ft-bar-context-menu-open,
.notification-close, .settings-close, .calendar-close, .tray-close, .wlan-close, .media-close, .ft-bar-item-context-menu-close, .ft-bar-context-menu-close {
animation: PopupBaseAnimation 0.2s linear forwards;
}

.notification-close, .settings-close, .calendar-close, .tray-close, .wlan-close, .media-close {
.notification-close, .settings-close, .calendar-close, .tray-close, .wlan-close, .media-close, .ft-bar-item-context-menu-close, .ft-bar-context-menu-close {
animation-direction: reverse;
}

Expand Down
5 changes: 3 additions & 2 deletions static/themes/default/theme.weg.css
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@
}


.weg-item-preview-container-open, .weg-item-preview-container-close {
.weg-item-preview-container-open, .weg-context-menu-container-open
.weg-item-preview-container-close, .weg-context-menu-container-close {
animation: PreviewContainerAnimation 0.2s linear forwards;
}

.weg-item-preview-container-close {
.weg-item-preview-container-close, .weg-context-menu-container-close {
animation-direction: reverse;
}

Expand Down

0 comments on commit be270fc

Please sign in to comment.