Skip to content

Commit

Permalink
feat(web/progress): progress bar in context menu's metadata (#217)
Browse files Browse the repository at this point in the history
* feature: progress bar in context menu's metadata

* undefined check `metadata.progress`
  • Loading branch information
szymczakovv authored Feb 6, 2023
1 parent be99e16 commit 4a9137a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
26 changes: 26 additions & 0 deletions web/src/features/dev/debug/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ export const debugContext = () => {
title: 'Vehicle garage',
options: [
{ title: 'Empty button' },
{
title: 'Karin Kuruma',
image: 'https://cdn.discordapp.com/attachments/1063098499027173461/1064276343585505330/screenshot.jpg',
arrow: true,
colorScheme: 'blue',
metadata: [
{
["label"]: "Body",
["value"]: "55%",
["progress"]: 55
},
{
["label"]: "Engine",
["value"]: "100%",
["progress"]: 100
},
{
["label"]: "Oil",
["progress"]: 11
},
{
["label"]: "Fuel",
["progress"]: 87
},
],
},
{
title: 'Example button',
description: 'Example button description',
Expand Down
14 changes: 10 additions & 4 deletions web/src/features/menu/context/components/ContextButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@ const ContextButton: React.FC<{
<HoverCard.Dropdown className={classes.dropdown}>
{button.image && <Image src={button.image} />}
{Array.isArray(button.metadata) ? (
button.metadata.map((metadata: string | { label: string; value: any }, index: number) => (
<Text key={`context-metadata-${index}`}>
{typeof metadata === 'string' ? `${metadata}` : `${metadata.label}: ${metadata.value}`}
</Text>
button.metadata.map((metadata: string | { label: string; value?: any; progress?: number }, index: number) => (
<>
<Text key={`context-metadata-${index}`}>
{typeof metadata === 'string' ? `${metadata}` : `${metadata.label}: ${metadata?.value ?? ""}`}
</Text>

{typeof metadata === 'object' && metadata.progress !== undefined && (
<Progress value={metadata.progress} size="sm" color={button.colorScheme || 'dark.3'} />
)}
</>
))
) : (
<>
Expand Down
2 changes: 1 addition & 1 deletion web/src/interfaces/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Option {
iconColor?: string;
progress?: number;
colorScheme?: string;
metadata?: string[] | { [key: string]: any } | { label: string; value: any }[];
metadata?: string[] | { [key: string]: any } | { label: string; value: any; progress: number; }[];
disabled?: boolean;
event?: string;
serverEvent?: string;
Expand Down

0 comments on commit 4a9137a

Please sign in to comment.