Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(package): support icon urls in radial menu #487

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions web/src/features/dev/debug/radial.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { debugData } from '../../../utils/debugData';
import type { MenuItem } from '../../../typings';
import type { RadialMenuItem } from '../../../typings';

export const debugRadial = () => {
debugData<{ items: MenuItem[]; sub?: boolean }>([
debugData<{ items: RadialMenuItem[]; sub?: boolean }>([
{
action: 'openRadialMenu',
data: {
items: [
{ icon: 'palette', label: 'Paint' },
{ iconWidth: 35, iconHeight: 35, icon: 'https://icon-library.com/images/white-icon-png/white-icon-png-18.jpg', label: 'External icon'},
{ icon: 'warehouse', label: 'Garage' },
{ icon: 'palette', label: 'Quite long \ntext' },
{ icon: 'palette', label: 'Paint' },
Expand Down
17 changes: 16 additions & 1 deletion web/src/features/menu/radial/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Box, createStyles } from '@mantine/core';
import { useEffect, useState } from 'react';
import { IconProp } from '@fortawesome/fontawesome-svg-core';
import { useNuiEvent } from '../../../hooks/useNuiEvent';
import { fetchNui } from '../../../utils/fetchNui';
import { isIconUrl } from '../../../utils/isIconUrl';
import ScaleFade from '../../../transitions/ScaleFade';
import type { RadialMenuItem } from '../../../typings';
import { useLocales } from '../../../providers/LocaleProvider';
Expand Down Expand Up @@ -132,6 +134,9 @@ const RadialMenu: React.FC = () => {
const cosAngle = Math.cos(angle);
const iconX = 175 + sinAngle * radius;
const iconY = 175 + cosAngle * radius;
const iconWidth = item.iconWidth || 50;
const iconHeight = item.iconHeight || 50;


return (
<>
Expand All @@ -153,7 +158,17 @@ const RadialMenu: React.FC = () => {
}, ${175 + (175 - gap) * Math.sin(-degToRad(pieAngle))} z`}
/>
<g transform={`rotate(${index * pieAngle - 90} ${iconX} ${iconY})`} pointerEvents="none">
<LibIcon x={iconX - 12.5} y={iconY - 17.5} icon={item.icon} width={25} height={25} fixedWidth />
{typeof item.icon === 'string' && isIconUrl(item.icon) ? (
<image
href={item.icon}
width={iconWidth}
height={iconHeight}
x={iconX - iconWidth / 2}
y={iconY - iconHeight / 2 - iconHeight / 4}
/>
) : (
<LibIcon x={iconX - 12.5} y={iconY - 17.5} icon={item.icon as IconProp} width={25} height={25} fixedWidth/>
)}
<text
x={iconX}
y={iconY + (item.label.includes(' \n') ? 7 : 25)}
Expand Down
4 changes: 3 additions & 1 deletion web/src/typings/radial.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { IconProp } from '@fortawesome/fontawesome-svg-core';

export interface RadialMenuItem {
icon: IconProp;
icon: string | IconProp;
label: string;
isMore?: boolean;
menu?: string;
iconWidth?: number;
iconHeight?: number;
}