Skip to content

Commit

Permalink
Add Icon enum and update Field class
Browse files Browse the repository at this point in the history
  • Loading branch information
tdwesten committed Feb 11, 2024
1 parent 4d90583 commit f985fb1
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 4 deletions.
126 changes: 126 additions & 0 deletions src/Enums/Icon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace Tdwesten\StatamicBuilder\Enums;

enum Icon: string
{
case AddCircle = 'add-circle';
case Add = 'add';
case Addons = 'addons';
case AngleBracketsDots = 'angle-brackets-dots';
case AngleBrackets = 'angle-brackets';
case ArrangeLetter = 'arrange-letter';
case ArrangeNumber = 'arrange-number';
case Array = 'array';
case ArrowRightThin = 'arrow-right-thin';
case Assets = 'assets';
case Bard = 'bard';
case Blueprint = 'blueprint';
case Blueprints = 'blueprints';
case BookOpen = 'book-open';
case BookPages = 'book-pages';
case BrowserCom = 'browser-com';
case Burger = 'burger';
case ButtonGroup = 'button_group';
case Cache = 'cache';
case Calendar = 'calendar';
case Charts = 'charts';
case Check = 'check';
case Checkboxes = 'checkboxes';
case Close = 'close';
case Code = 'code';
case Cog = 'cog';
case Collection = 'collection';
case Collections = 'collections';
case Color = 'color';
case ContentWriting = 'content-writing';
case Crane = 'crane';
case Date = 'date';
case Download = 'download';
case DragDots = 'drag-dots';
case DrawerFile = 'drawer-file';
case DuplicateIds = 'duplicate-ids';
case Duplicate = 'duplicate';
case Earth = 'earth';
case EmailUtility = 'email-utility';
case Entries = 'entries';
case ExpandDiagonal = 'expand-diagonal';
case ExpandVertical = 'expand-vertical';
case ExternalLink = 'external-link';
case Fieldsets = 'fieldsets';
case Fieldtype = 'fieldtype';
case FileCode = 'file-code';
case FileText = 'file-text';
case FilterLines = 'filter-lines';
case Filter = 'filter';
case Flag = 'flag';
case Float = 'float';
case Form = 'form';
case GenericField = 'generic-field';
case Git = 'git';
case Grid = 'grid';
case Group = 'group';
case HammerWrench = 'hammer-wrench';
case Hidden = 'hidden';
case HierarchyFiles = 'hierarchy-files';
case History = 'history';
case Html = 'html';
case HyperlinkBroken = 'hyperlink-broken';
case Hyperlink = 'hyperlink';
case IconPicker = 'icon_picker';
case Integer = 'integer';
case Licensing = 'licensing';
case Link = 'link';
case ListBullets = 'list-bullets';
case List = 'list';
case LoadingBar = 'loading-bar';
case Lock = 'lock';
case MagnifyingGlass = 'magnifying-glass';
case Markdown = 'markdown';
case NavPreferences = 'nav-preferences';
case Partial = 'partial';
case Php = 'php';
case Picker = 'picker';
case Pin = 'pin';
case Playground = 'playground';
case ProRibbon = 'pro-ribbon';
case PullDown = 'pull-down';
case Radio = 'radio';
case Range = 'range';
case Replicator = 'replicator';
case Revealer = 'revealer';
case SearchUtility = 'search-utility';
case Search = 'search';
case Section = 'section';
case Select = 'select';
case SeoSearchGraph = 'seo-search-graph';
case SettingsHorizontal = 'settings-horizontal';
case SettingsSlider = 'settings-slider';
case ShieldKey = 'shield-key';
case Shrink = 'shrink';
case Sites = 'sites';
case Slug = 'slug';
case Structures = 'structures';
case Synchronize = 'synchronize';
case Table = 'table';
case Tags = 'tags';
case Taxonomies = 'taxonomies';
case Taxonomy = 'taxonomy';
case Template = 'template';
case Text = 'text';
case Textarea = 'textarea';
case Time = 'time';
case Title = 'title';
case Toggle = 'toggle';
case UserGroups = 'user_groups';
case UserRoles = 'user_roles';
case UserEdit = 'user-edit';
case User = 'user';
case UsersBox = 'users-box';
case UsersMultiple = 'users-multiple';
case Users = 'users';
case Video = 'video';
case Width = 'width';
case Wireframe = 'wireframe';
case Yaml = 'yaml';
}
17 changes: 15 additions & 2 deletions src/FieldTypes/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Field implements Renderable

protected $hideDisplay = false;

protected $icon;
protected Icon $icon;

protected $width;

Expand All @@ -57,6 +57,8 @@ class Field implements Renderable

public function __construct($handle)
{
$this->validateHandle($handle);

$this->handle = $handle;
$this->type = $this->getType();
$this->validate = new Collection([]);
Expand Down Expand Up @@ -254,7 +256,7 @@ public function hideDisplay(bool $hideDisplay)
return $this;
}

public function icon($icon)
public function icon(Icon $icon)
{
$this->icon = $icon;

Expand Down Expand Up @@ -290,4 +292,15 @@ public function fieldsToArray()
return $field->toArray();
})->all();
}

public function validateHandle($handle)
{
if (! is_string($handle)) {
throw new \InvalidArgumentException('[ '.get_called_class().' ] Field handle must be a string');
}

if (empty($handle)) {
throw new \InvalidArgumentException('[ '.get_called_class().'] Field handle cannot be empty');
}
}
}
8 changes: 8 additions & 0 deletions src/FieldTypes/SetGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public function setsToArray(): array

return $sets;
}

public function displayName($displayName)
{
$this->displayName = $displayName;

return $this;

}
}
4 changes: 2 additions & 2 deletions src/FieldTypes/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function sectionsToArray(): ?array
return ! ($field instanceof Section);
});

if ($fields->isNotEmpty()) {
throw new BlueprintRenderException('Only sections are allowed in tabs');
if ($fields->count() > 0) {
throw new BlueprintRenderException('['.get_called_class().'] > Only sections are allowed in tabs');
}

return $this->sections->map(function (Section $section) {
Expand Down

0 comments on commit f985fb1

Please sign in to comment.