Skip to content

Commit 3ff530f

Browse files
authored
Merge pull request #623 from code16/command-icon
Command icon
2 parents 04c0bf3 + 7dba860 commit 3ff530f

11 files changed

Lines changed: 93 additions & 6 deletions

File tree

demo/app/Sharp/Authors/Commands/VisitFacebookProfileCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function label(): string
1414

1515
public function buildCommandConfig(): void
1616
{
17-
$this->configureDescription('You will leave Sharp');
17+
$this->configureDescription('You will leave Sharp')
18+
->configureIcon('lucide-facebook');
1819
}
1920

2021
public function execute(mixed $instanceId, array $data = []): array

demo/app/Sharp/Posts/Commands/BulkPublishPostsCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function label(): ?string
1515
public function buildCommandConfig(): void
1616
{
1717
$this->configureDescription('Bulk command to publish posts')
18+
->configureIcon('lucide-check-check')
1819
->configureInstanceSelectionRequired();
1920
}
2021

demo/app/Sharp/Posts/Commands/ComposeEmailWithPostsWizardCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function label(): ?string
2121

2222
public function buildCommandConfig(): void
2323
{
24-
$this->configureDescription('Use this wizard command to compose a message choosing posts links in a list');
24+
$this->configureDescription('Use this wizard command to compose a message choosing posts links in a list')
25+
->configureIcon('lucide-mail');
2526
}
2627

2728
public function buildFormFieldsForFirstStep(FieldsContainer $formFields): void

ide.json

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,56 @@
1616
]
1717
}
1818
]
19+
},
20+
{
21+
"complete": "bladeIcon",
22+
"condition": [
23+
{
24+
"classFqn": [
25+
"Code16\\Sharp\\Utils\\Menu\\HasSharpMenuItems"
26+
],
27+
"methodNames": [
28+
"addEntityLink"
29+
],
30+
"parameters": [
31+
3
32+
]
33+
},
34+
{
35+
"classFqn": [
36+
"Code16\\Sharp\\Form\\Fields\\Embeds\\SharpFormEditorEmbed"
37+
],
38+
"methodNames": [
39+
"configureIcon"
40+
],
41+
"parameters": [
42+
1
43+
]
44+
},
45+
{
46+
"classFqn": [
47+
"Code16\\Sharp\\EntityList\\Commands\\Command"
48+
],
49+
"methodNames": [
50+
"configureIcon"
51+
],
52+
"parameters": [
53+
1
54+
]
55+
},
56+
{
57+
"place": "parameter",
58+
"classFqn": [
59+
"Code16\\Sharp\\EntityList\\EntityListEntities"
60+
],
61+
"methodNames": [
62+
"addEntity"
63+
],
64+
"parameters": [
65+
3
66+
]
67+
}
68+
]
1969
}
2070
],
2171
"view": {
@@ -285,4 +335,4 @@
285335
]
286336
}
287337
]
288-
}
338+
}

resources/js/commands/components/CommandDropdownItems.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
77
import { useBreakpoints } from "@/composables/useBreakpoints";
88
import { showAlert } from "@/utils/dialogs";
9+
import Icon from "@/components/ui/Icon.vue";
910
1011
const props = defineProps<{
1112
commands: CommandData[][],
@@ -38,6 +39,9 @@
3839
@click="$emit('select', command)"
3940
:disabled="requiresSelection(command)"
4041
>
42+
<template v-if="command.icon">
43+
<Icon :icon="command.icon" class="size-4" />
44+
</template>
4145
<div>
4246
{{ command.label }}
4347
<template v-if="command.description">

resources/js/types/generated.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type CommandData = {
4444
buttonLabel: string | null;
4545
} | null;
4646
hasForm: boolean;
47+
icon: IconData | null;
4748
authorization: Array<string | number> | boolean;
4849
instanceSelection: InstanceSelectionMode | null;
4950
primary: boolean | null;

src/Data/Commands/CommandData.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Code16\Sharp\Data\Commands;
44

55
use Code16\Sharp\Data\Data;
6+
use Code16\Sharp\Data\IconData;
67
use Code16\Sharp\Enums\CommandType;
78
use Code16\Sharp\Enums\InstanceSelectionMode;
89
use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType;
@@ -20,6 +21,7 @@ public function __construct(
2021
#[LiteralTypeScriptType('{ text: string, title: string | null, buttonLabel: string | null } | null')]
2122
public ?array $confirmation,
2223
public bool $hasForm,
24+
public ?IconData $icon,
2325
/** @var array<string|int>|bool */
2426
public array|bool $authorization,
2527
public ?InstanceSelectionMode $instanceSelection = null,
@@ -34,6 +36,7 @@ public static function from(array $command): self
3436
'instanceSelection' => isset($command['instanceSelection'])
3537
? InstanceSelectionMode::from($command['instanceSelection'])
3638
: null,
39+
'icon' => IconData::optional($command['icon'] ?? null),
3740
];
3841

3942
return new self(...$command);

src/EntityList/Commands/Command.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ abstract class Command
3333
private ?string $confirmationTitle = null;
3434
private ?string $confirmationButtonLabel = null;
3535
private ?string $description = null;
36+
private ?string $icon = null;
3637

3738
protected function info(string $message, bool $reload = false): array
3839
{
@@ -146,6 +147,13 @@ final protected function configureConfirmationText(string $confirmationText, ?st
146147
return $this;
147148
}
148149

150+
final protected function configureIcon(string $icon): self
151+
{
152+
$this->icon = $icon;
153+
154+
return $this;
155+
}
156+
149157
/**
150158
* Check if the current user is allowed to use this Command.
151159
*/
@@ -179,6 +187,11 @@ final public function getDescription(): ?string
179187
return $this->description;
180188
}
181189

190+
final public function getIcon(): ?string
191+
{
192+
return $this->icon;
193+
}
194+
182195
final public function getFormModalTitle(?array $formData): ?string
183196
{
184197
return ($callback = $this->formModalTitle) instanceof Closure

src/EntityList/Traits/Utils/CommonCommandUtils.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Code16\Sharp\EntityList\Commands\Command;
66
use Code16\Sharp\EntityList\Commands\EntityCommand;
7+
use Code16\Sharp\Utils\Icons\IconManager;
78
use Illuminate\Support\Collection;
89

910
trait CommonCommandUtils
@@ -30,6 +31,7 @@ protected function appendCommandsToConfig(Collection $commandHandlers, array &$c
3031
'authorization' => $instanceId
3132
? $handler->authorizeFor($instanceId)
3233
: $handler->getGlobalAuthorization(),
34+
'icon' => app(IconManager::class)->iconToArray($handler->getIcon()),
3335
...$handler instanceof EntityCommand ? [
3436
'instanceSelection' => $handler->getInstanceSelectionMode(),
3537
] : [],

tests/Unit/Dashboard/DashboardCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function execute(array $data = []): array {}
3434
'description' => null,
3535
'confirmation' => null,
3636
'hasForm' => false,
37+
'icon' => null,
3738
]);
3839
});
3940

@@ -113,6 +114,7 @@ public function execute(array $data = []): array {}
113114
'authorization' => true,
114115
'confirmation' => null,
115116
'description' => null,
117+
'icon' => null,
116118
],
117119
],
118120
],

0 commit comments

Comments
 (0)