tipowerup/ti-theme-toolkit
Shared PHP + frontend toolkit for TastyIgniter themes. Build a custom theme with minimal PHP via AbstractThemeServiceProvider, plus palettes, field schema, widgets, Livewire auth/contact/newsletter components, dark mode, and Tailwind/Vite/Alpine presets.
## Getting Started
### Minimal Setup for Daily Use
1. **Extend `AbstractThemeServiceProvider`** (5 lines):
```php
use TiPowerUp\ThemeToolkit\AbstractThemeServiceProvider;
class MyThemeServiceProvider extends AbstractThemeServiceProvider {
protected function themeCode(): string { return 'my-theme'; }
// Other overrides as needed
}
Key: Register this in config/app.php under providers.
Configure fields.php (3 lines):
use TiPowerUp\ThemeToolkit\Fields\BaseSchema;
return BaseSchema::merge(['tabs' => BaseSchema::tabs()]);
Daily use: This auto-generates the theme customizer UI in TastyIgniter admin.
Add Tailwind/Vite presets (1 line each):
// tailwind.config.js
import toolkit from '@tipowerup/ti-theme-toolkit/tailwind-preset';
export default { presets: [toolkit] };
// vite.config.js
import { toolkitPreset } from '@tipowerup/ti-theme-toolkit/vite-preset';
export default toolkitPreset({ input: ['resources/src/js/app.js'] });
Daily use: Handles dark mode, color tokens, and build optimizations.
Import CSS/JS (2 lines):
/* resources/src/css/app.css */
@import '@tipowerup/ti-theme-toolkit/css/theme.css';
@tailwind base;
// resources/src/js/app.js
import '@tipowerup/ti-theme-toolkit/js/dark-mode';
Daily use: Activates dark mode toggle and CSS variables.
fields.php to override defaults:
return BaseSchema::merge([
'tabs' => [
'colors' => [
'fields' => [
'color[primary]' => ['default' => '#3b82f6'], // Tailwind blue-500
],
],
],
]);
npm run build and php artisan igniter:theme-vendor-publish.bg-primary work.Design Phase:
BaseSchema in fields.php to define customizer options.themeCode(), viewsPath(), etc., in ServiceProvider.BaseSchema::merge() to inherit defaults while customizing.Frontend Integration:
darkmode store:
const darkMode = DarkModeStore();
darkMode.toggle(); // Toggles html.dark class
.header { background: rgb(var(--color-primary)); }
text-primary-500) map to these vars via the preset.Livewire Components:
Login, Contact) by dropping blade views in resources/views/livewire/.Livewire/ with the same relative path.// MyTheme/Livewire/NewsletterSubscribeForm.php
class NewsletterSubscribeForm extends \TiPowerUp\ThemeToolkit\Livewire\NewsletterSubscribeForm {
public function render() {
return view('my-theme.livewire.newsletter-subscribe-form');
}
}
Error Handling:
resources/views/errors/404.blade.php.Asset Management:
igniter:theme-vendor-publish to sync assets to public/vendor/my-theme.registerAutoVendorPublish() listener runs this on theme activation.TastyIgniter Admin:
ThemePayloadResolver::resolve() in custom admin controllers to access theme data.Blade Components:
BladeComponentServiceProvider:
$this->loadBladeComponentsFrom(__DIR__.'/View/Components');
Dark Mode Persistence:
localStorage. Extend with:
darkMode.on('changed', (isDark) => {
// Custom logic (e.g., analytics)
});
TypeScript:
tsconfig.json:
{
"compilerOptions": {
"strict": true
}
}
.d.ts files for full IntelliSense (e.g., DarkModeStore).CSS Variable Conflicts:
--color-* vars.!important sparingly; prefer Tailwind classes (bg-[var(--color-primary)]).Livewire Component Overrides:
NewsletterSubscribeForm may break if the toolkit’s class isn’t properly namespaced.use TiPowerUp\ThemeToolkit\Livewire\NewsletterSubscribeForm;
Dark Mode Class Strategy:
html.dark.dark-mode.js as a base and extend:
document.documentElement.classList.add('dark');
Tailwind Safelist:
bg-[var(--color-primary)]) may be purged.tailwind.config.js:
safelist: [
'bg-[var(--color-primary)]',
'text-[var(--color-primary)]',
],
Theme Activation:
registerAutoVendorPublish() listener (enabled by default).PHP Namespace Reflection:
phpNamespace() defaults to the class’s namespace, but may fail for anonymous classes or complex inheritance.protected function phpNamespace(): string { return 'MyVendor\\MyTheme'; }
Theme Data:
{{ dd(\TiPowerUp\ThemeToolkit\Support\ThemePayloadResolver::resolve()) }}
Livewire Registration:
\Livewire::getComponentClasses(); // Debug in Tinker
Dark Mode:
console.log(DarkModeStore().data);
CSS Variables:
:root { --color-primary: #ff0000; }
Custom Form Widgets:
BannerManager or create new widgets by implementing FormWidgetInterface.Color Palette Logic:
ColorHelper::derivePrimaryPalette() to customize shade generation.Tailwind Preset:
tailwind.config.js:
export default {
presets: [toolkit],
theme: {
extend: {
colors: {
'custom': 'rgb(var(--color-custom))',
},
},
},
};
Dark Mode Events:
darkmode:changed in your JS:
window.addEventListener('darkmode:changed', (e) => {
console.log('Dark mode is now:', e.detail);
});
View Composer:
$themeBrandStyle and $themeNeutralStyle:
<html style="{{ $themeBrandStyle }}">
Vite Auto-Detection:
app.ts over app.js. To force JS, rename your entry file.Tailwind Content Paths:
content in tailwind.config.js includes:
content: [
'./resources/**/*.blade.php',
'./resources/src/**/*.{js,ts}',
],
Livewire Namespace:
How can I help you explore Laravel packages today?