Skip to content

Commit

Permalink
enh(launcher): dropdown style & stylability
Browse files Browse the repository at this point in the history
  • Loading branch information
luriusTM committed Dec 20, 2024
1 parent be270fc commit 0b05b28
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/apps/seelen_rofi/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function App() {
theme={{
token: {
colorPrimary: isDarkMode ? colors.accent_light : colors.accent_dark,
motion: false,
},
algorithm: isDarkMode ? theme.darkAlgorithm : theme.defaultAlgorithm,
}}
Expand Down
43 changes: 27 additions & 16 deletions src/apps/seelen_rofi/modules/launcher/infra/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Menu } from 'antd';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

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

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

import { AnimatedDropdown } from '../../../../shared/components/AnimatedWrappers';
Expand All @@ -31,24 +33,33 @@ export const Item = memo(({ item, hidden }: { item: StartMenuApp; hidden: boolea
}}
trigger={['contextMenu']}
dropdownRender={() => (
<Menu
items={[
{
label: t('item.pin'),
key: 'pin',
onClick() {
invoke(SeelenCommand.WegPinItem, { path });
<BackgroundByLayersV2
className="launcher-item-context-menu"
prefix="menu"
onContextMenu={(e) => {
e.stopPropagation();
e.preventDefault();
}}
>
<Menu
items={[
{
label: t('item.pin'),
key: 'pin',
onClick() {
invoke(SeelenCommand.WegPinItem, { path });
},
},
},
{
label: t('item.open_location'),
key: 'open',
onClick() {
invoke(SeelenCommand.SelectFileOnExplorer, { path });
{
label: t('item.open_location'),
key: 'open',
onClick() {
invoke(SeelenCommand.SelectFileOnExplorer, { path });
},
},
},
]}
/>
]}
/>
</BackgroundByLayersV2>
)}
>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ export interface AnimatedDropwonProps extends DropdownProps {
animationDescription: CustomAnimationProps;
}

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

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

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

return (
<Dropdown
open={open || delayedOpenPopover}
open={open || openReplacement || delayedOpenPopover}
onOpenChange={(open, info) => {
if (onOpenChange) {
onOpenChange(open, info);
} else {
setOpenReplacement(open);
}
}}
{...dropdownProps}
dropdownRender={(origin) => dropdownRender &&
<div className={cx(animationObject)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ export interface AnimatedPopoverProps extends PopoverProps {
animationDescription: CustomAnimationProps;
}

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

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

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

return (
<Popover
open={open || delayedOpenPopover}
onOpenChange={(open, info) => {
if (onOpenChange) {
onOpenChange(open, info);
} else {
setOpenReplacement(open);
}
}}
{...popoverProps}
content={content &&
<div className={cx(animationObject)}>
Expand Down
6 changes: 6 additions & 0 deletions static/themes/default/theme.launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ body {
}
}

.launcher-item-context-menu {
border-radius: 8px;
background-color: var(--color-gray-50);
box-shadow: 0 4px 10px 4px #0001;
}

@keyframes PopupBaseAnimation {
0% {
opacity: 0;
Expand Down

0 comments on commit 0b05b28

Please sign in to comment.