Skip to content

Commit

Permalink
refactor code & modified tallcraftui config
Browse files Browse the repository at this point in the history
  • Loading branch information
developermithu committed Aug 10, 2024
1 parent 9651183 commit e69bc5f
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 410 deletions.
115 changes: 99 additions & 16 deletions config/tallcraftui.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,118 @@

return [
/**
*
* ==================================
* Default prefix for all components
* ==================================
*
* Note: After changing the prefix, clear the view cache
* using `php artisan view:clear`
*
* Examples:
* prefix => '' // <x-input />
* prefix => 'tc-' // <x-tc-input />
*
* prefix => '' // <x-input />
* prefix => 'tc-' // <x-tc-input />
*
*/
'prefix' => '',

/**
* Icons configuration
*
* type => Allowed: heroicons
* style => Allowed: outline, solid
*
*/
'icons' => [
/**
* ---------------------------
* Allowed icons: heroicons,
* ---------------------------
*/
'type' => 'heroicons',

/**
* --------------------
* Default icon style
* --------------------
*
* Allowed values: outline, solid
*/
'style' => 'outline',
],

/**
*
* border-radius => Allowed: rounded, rounded-sm, rounded-md, rounded-lg, rounded-xl, rounded-2xl, rounded-3xl, rounded-full, rounded-none
*
*/
'alert' => [
'border-radius' => 'rounded',
],

'badge' => [
'border-radius' => 'rounded',
],

'breadcrumb' => [
'border-radius' => 'rounded',
],

/**
*
* size => Allowed: sm, md, lg, xl, 2xl
*
*/
'button' => [
'border-radius' => 'rounded',
'size' => 'md',
],

/**
*
* size => Allowed: sm, md, lg, xl, 2xl
*
*/
'checkbox' => [
'border-radius' => 'rounded',
'size' => 'md',
],

/**
*
* position => Allowed: top, bottom, left, right
* size => Allowed: w-20, w-24, w-28, w-32, w-36, w-40, w-44, w-48, w-52, w-56, w-60, w-64, w-72, w-80, w-96, w-full
*
*/
'dropdown' => [
'border-radius' => 'rounded',
'position' => 'top',
'size' => 'w-48',
],

'input' => [
'border-radius' => 'rounded',
],

/**
*
* size => Allowed: sm, md, lg, xl, 2xl, 3xl, 4xl, 5xl, 6xl, 7xl, full
* blur => Allowed: true, false
* position => Allowed: top, bottom, left, right, center
*
*/
'modal' => [
'border-radius' => 'rounded-lg',
'size' => 'lg',
'blur' => false,
'position' => 'top',
],

/**
*
* size => Allowed: sm, md, lg, xl, 2xl
*
*/
'radio' => [
'size' => 'md',
],

'select' => [
'border-radius' => 'rounded',
],

'textarea' => [
'border-radius' => 'rounded',
],

'toggle' => [
'border-radius' => 'rounded',
],
];
24 changes: 24 additions & 0 deletions src/Helpers/BorderRadiusHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Developermithu\Tallcraftui\Helpers;

use Illuminate\View\ComponentAttributeBag;

class BorderRadiusHelper
{
public static function getRoundedClass(string $componentName, ComponentAttributeBag $attributes): string
{
return match (true) {
$attributes->get('rounded') => 'rounded',
$attributes->get('rounded-sm') => 'rounded-sm',
$attributes->get('rounded-md') => 'rounded-md',
$attributes->get('rounded-lg') => 'rounded-lg',
$attributes->get('rounded-xl') => 'rounded-xl',
$attributes->get('rounded-2xl') => 'rounded-2xl',
$attributes->get('rounded-3xl') => 'rounded-3xl',
$attributes->get('rounded-full') => 'rounded-full',
$attributes->get('rounded-none') => 'rounded-none',
default => config("tallcraftui.{$componentName}.border-radius", 'rounded'),
};
}
}
40 changes: 19 additions & 21 deletions src/TallCraftUiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@
namespace Developermithu\Tallcraftui;

use Developermithu\Tallcraftui\Console\Commands\InstallTallcraftuiCommand;
use Developermithu\Tallcraftui\View\Components\{
Alert,
Badge,
Breadcrumb,
BreadcrumbItem,
Button,
Checkbox,
Dropdown,
DropdownItem,
Hint,
Icon,
Input,
Label,
Modal,
Radio,
Select,
Textarea,
Toggle
};
use Developermithu\Tallcraftui\View\Components\Alert;
use Developermithu\Tallcraftui\View\Components\Badge;
use Developermithu\Tallcraftui\View\Components\Breadcrumb;
use Developermithu\Tallcraftui\View\Components\BreadcrumbItem;
use Developermithu\Tallcraftui\View\Components\Button;
use Developermithu\Tallcraftui\View\Components\Checkbox;
use Developermithu\Tallcraftui\View\Components\Dropdown;
use Developermithu\Tallcraftui\View\Components\DropdownItem;
use Developermithu\Tallcraftui\View\Components\Hint;
use Developermithu\Tallcraftui\View\Components\Icon;
use Developermithu\Tallcraftui\View\Components\Input;
use Developermithu\Tallcraftui\View\Components\Label;
use Developermithu\Tallcraftui\View\Components\Modal;
use Developermithu\Tallcraftui\View\Components\Radio;
use Developermithu\Tallcraftui\View\Components\Select;
use Developermithu\Tallcraftui\View\Components\Textarea;
use Developermithu\Tallcraftui\View\Components\Toggle;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

Expand All @@ -34,7 +32,7 @@ public function boot(): void
$this->registerComponents();

$this->publishes([
__DIR__ . '/../config/tallcraftui.php' => config_path('tallcraftui.php'),
__DIR__.'/../config/tallcraftui.php' => config_path('tallcraftui.php'),
], 'tallcraftui-config');

// Register the application's commands.
Expand Down Expand Up @@ -68,7 +66,7 @@ private function registerComponents(): void
];

foreach ($components as $name => $class) {
Blade::component($prefix . $name, $class);
Blade::component($prefix.$name, $class);
}

// TallCraftUI internal components
Expand Down
67 changes: 67 additions & 0 deletions src/Traits/HasCheckboxColors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Developermithu\Tallcraftui\Traits;

trait HasCheckboxColors
{
public array $colorAttributes = [
'primary',
'secondary',
'black',
'white',
'slate',
'gray',
'zinc',
'neutral',
'stone',
'red',
'orange',
'amber',
'yellow',
'lime',
'green',
'emerald',
'teal',
'cyan',
'sky',
'blue',
'indigo',
'violet',
'purple',
'fuchsia',
'pink',
'rose',
];

public function colorClasses(): string
{
return match (true) {
$this->attributes->has('secondary') => 'text-secondary/90 focus:ring-secondary/90',
$this->attributes->has('black') => 'text-black focus:ring-black',
$this->attributes->has('white') => 'text-white focus:ring-white !border-gray-200',
$this->attributes->has('slate') => 'text-slate-600 focus:ring-slate-600',
$this->attributes->has('gray') => 'text-gray-600 focus:ring-gray-600',
$this->attributes->has('zinc') => 'text-zinc-600 focus:ring-zinc-600',
$this->attributes->has('neutral') => 'text-neutral-600 focus:ring-neutral-600',
$this->attributes->has('stone') => 'text-stone-600 focus:ring-stone-600',
$this->attributes->has('red') => 'text-red-600 focus:ring-red-600',
$this->attributes->has('orange') => 'text-orange-600 focus:ring-orange-600',
$this->attributes->has('amber') => 'text-amber-600 focus:ring-amber-600',
$this->attributes->has('yellow') => 'text-yellow-600 focus:ring-yellow-600',
$this->attributes->has('lime') => 'text-lime-600 focus:ring-lime-600',
$this->attributes->has('green') => 'text-green-600 focus:ring-green-600',
$this->attributes->has('emerald') => 'text-emerald-600 focus:ring-emerald-600',
$this->attributes->has('teal') => 'text-teal-600 focus:ring-teal-600',
$this->attributes->has('cyan') => 'text-cyan-600 focus:ring-cyan-600',
$this->attributes->has('sky') => 'text-sky-600 focus:ring-sky-600',
$this->attributes->has('blue') => 'text-blue-600 focus:ring-blue-600',
$this->attributes->has('indigo') => 'text-indigo-600 focus:ring-indigo-600',
$this->attributes->has('violet') => 'text-violet-600 focus:ring-violet-600',
$this->attributes->has('purple') => 'text-purple-600 focus:ring-purple-600',
$this->attributes->has('fuchsia') => 'text-fuchsia-600 focus:ring-fuchsia-600',
$this->attributes->has('pink') => 'text-pink-600 focus:ring-pink-600',
$this->attributes->has('rose') => 'text-rose-600 focus:ring-rose-600',
default => 'text-primary/90 focus:ring-primary/90', // primary
};
}
}
17 changes: 4 additions & 13 deletions src/View/Components/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Developermithu\Tallcraftui\View\Components;

use Closure;
use Developermithu\Tallcraftui\Helpers\BorderRadiusHelper;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

Expand Down Expand Up @@ -120,19 +121,9 @@ public function descriptionClasses(): string
};
}

public function roundClasses()
public function roundedClass(): string
{
return match (true) {
$this->attributes->get('rounded-none') => 'rounded-none',
$this->attributes->get('rounded-sm') => 'rounded-sm',
$this->attributes->get('rounded-md') => 'rounded-md',
$this->attributes->get('rounded-lg') => 'rounded-lg',
$this->attributes->get('rounded-xl') => 'rounded-xl',
$this->attributes->get('rounded-2xl') => 'rounded-2xl',
$this->attributes->get('rounded-3xl') => 'rounded-3xl',
$this->attributes->get('rounded-full') => 'rounded-full',
default => 'rounded',
};
return BorderRadiusHelper::getRoundedClass('alert', $this->attributes);
}

public function actionColors(): string
Expand Down Expand Up @@ -182,7 +173,7 @@ public function render(): View|Closure|string
{{ $attributes->withoutTwMergeClasses()->twMerge([
"p-4 text-sm transition duration-300 border",
$alertClasses(),
$roundClasses()
$roundedClass()
])
}}
>
Expand Down
18 changes: 4 additions & 14 deletions src/View/Components/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Developermithu\Tallcraftui\View\Components;

use Closure;
use Developermithu\Tallcraftui\Helpers\BorderRadiusHelper;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

Expand Down Expand Up @@ -168,20 +169,9 @@ public function iconSize(): string
};
}

public function roundClasses()
public function roundedClass(): string
{
return match (true) {
$this->attributes->get('rounded-none') => 'rounded-none',
$this->attributes->get('rounded') => 'rounded',
$this->attributes->get('rounded-sm') => 'rounded-sm',
$this->attributes->get('rounded-md') => 'rounded-md',
$this->attributes->get('rounded-lg') => 'rounded-lg',
$this->attributes->get('rounded-xl') => 'rounded-xl',
$this->attributes->get('rounded-2xl') => 'rounded-2xl',
$this->attributes->get('rounded-3xl') => 'rounded-3xl',
$this->attributes->get('rounded-full') => 'rounded-full',
default => 'rounded',
};
return BorderRadiusHelper::getRoundedClass('badge', $this->attributes);
}

public function render(): View|Closure|string
Expand All @@ -192,7 +182,7 @@ public function render(): View|Closure|string
$badgeSize(),
$colorClasses(),
$outlineClasses(),
$roundClasses(),
$roundedClass(),
])
}}
>
Expand Down
Loading

0 comments on commit e69bc5f

Please sign in to comment.