mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-05 14:41:26 +09:00
Mechanical wrap-the-card pass: each remaining settings tab component now spreads useSettingFocus's register(id, class) onto its identifiable cards so a palette settings result scrolls to and flashes the exact card. Covers Profile, Appearance, Sidebar, White Label, About, Users, Activity, Site, Modules, Migrations, SSO, API, AI, System, and Connections. Cards whose roots live in non-editable subcomponents (login links, invitations, provider cards) register at the nearest reachable section or fall back to landing on the tab. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
181 lines
9.5 KiB
React
181 lines
9.5 KiB
React
import { useRef } from 'react';
|
|
import { useTheme } from '../../contexts/ThemeContext';
|
|
import { Star, X, Layers, Image, Type, Upload } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import { Switch } from '@/components/ui/switch';
|
|
import useSettingFocus from '../../hooks/useSettingFocus';
|
|
|
|
const WHITELABEL_MODES = [
|
|
{ id: 'image_text', label: 'Logo + Text', icon: Layers, desc: 'Mini logo with brand name' },
|
|
{ id: 'image_full', label: 'Full-width Logo', icon: Image, desc: 'Banner image only' },
|
|
{ id: 'text_only', label: 'Text Only', icon: Type, desc: 'Just the brand name' },
|
|
];
|
|
|
|
const WhiteLabelTab = () => {
|
|
const { whiteLabel, setWhiteLabel } = useTheme();
|
|
const logoInputRef = useRef(null);
|
|
const register = useSettingFocus();
|
|
|
|
return (
|
|
<div className="settings-section">
|
|
<div className="section-header">
|
|
<h2>White Label</h2>
|
|
<p>Replace the default ServerKit branding with your own</p>
|
|
</div>
|
|
|
|
<div {...register('whitelabel-branding', 'settings-card')}>
|
|
<h3>Custom Branding</h3>
|
|
<p>Replace the sidebar logo, name, and GitHub star link</p>
|
|
|
|
<div className="settings-row">
|
|
<div className="settings-label">
|
|
<Label>Enable custom branding</Label>
|
|
<span className="settings-hint">Replaces the sidebar logo, name, and GitHub star link</span>
|
|
</div>
|
|
<div className="settings-control">
|
|
<Switch
|
|
checked={whiteLabel.enabled}
|
|
onCheckedChange={(checked) => setWhiteLabel({ enabled: checked })}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{whiteLabel.enabled && (
|
|
<>
|
|
<div className="whitelabel-modes">
|
|
{WHITELABEL_MODES.map(({ id, label, icon: Icon, desc }) => (
|
|
<button type="button"
|
|
key={id}
|
|
className={`whitelabel-mode${whiteLabel.mode === id ? ' active' : ''}`}
|
|
onClick={() => setWhiteLabel({ mode: id })}
|
|
>
|
|
<Icon size={20} />
|
|
<span className="whitelabel-mode__label">{label}</span>
|
|
<span className="whitelabel-mode__desc">{desc}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
<div className="whitelabel-fields">
|
|
{whiteLabel.mode !== 'image_full' && (
|
|
<div className="form-group">
|
|
<Label>Brand Name</Label>
|
|
<Input
|
|
type="text"
|
|
value={whiteLabel.brandName}
|
|
onChange={(e) => setWhiteLabel({ brandName: e.target.value })}
|
|
placeholder="My Brand"
|
|
maxLength={30}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
{whiteLabel.mode !== 'text_only' && (
|
|
<div className="form-group">
|
|
<Label>Logo Image</Label>
|
|
<div className="whitelabel-upload" onClick={() => logoInputRef.current?.click()}>
|
|
{whiteLabel.logoData ? (
|
|
<div className="whitelabel-logo-preview">
|
|
<img src={whiteLabel.logoData} alt="Logo preview" />
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={(e) => { e.stopPropagation(); setWhiteLabel({ logoData: '' }); }}
|
|
>
|
|
<X size={12} /> Remove
|
|
</Button>
|
|
</div>
|
|
) : (
|
|
<div className="whitelabel-upload__placeholder">
|
|
<Upload size={20} />
|
|
<span>Click to upload logo</span>
|
|
<span className="whitelabel-upload__hint">PNG, JPG, SVG — max 200KB</span>
|
|
</div>
|
|
)}
|
|
<input
|
|
ref={logoInputRef}
|
|
type="file"
|
|
accept="image/png,image/jpeg,image/svg+xml,image/webp"
|
|
style={{ display: 'none' }}
|
|
onChange={(e) => {
|
|
const file = e.target.files?.[0];
|
|
if (!file) return;
|
|
if (file.size > 200 * 1024) {
|
|
alert('Image must be under 200KB');
|
|
return;
|
|
}
|
|
const reader = new FileReader();
|
|
reader.onload = (ev) => setWhiteLabel({ logoData: ev.target.result });
|
|
reader.readAsDataURL(file);
|
|
e.target.value = '';
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="whitelabel-preview">
|
|
<span className="whitelabel-preview__label">Preview</span>
|
|
<div className="whitelabel-preview__box">
|
|
{whiteLabel.mode === 'image_full' ? (
|
|
<div className="brand-custom-banner">
|
|
{whiteLabel.logoData ? (
|
|
<img src={whiteLabel.logoData} alt="Preview" />
|
|
) : (
|
|
<Layers size={24} />
|
|
)}
|
|
</div>
|
|
) : whiteLabel.mode === 'text_only' ? (
|
|
<span className="brand-custom-text">
|
|
{whiteLabel.brandName || 'Brand'}
|
|
</span>
|
|
) : (
|
|
<>
|
|
<div className="brand-custom-logo">
|
|
{whiteLabel.logoData ? (
|
|
<img src={whiteLabel.logoData} alt="Preview" />
|
|
) : (
|
|
<Layers size={16} />
|
|
)}
|
|
</div>
|
|
<span className="brand-custom-text">
|
|
{whiteLabel.brandName || 'Brand'}
|
|
</span>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="whitelabel-star-prompt">
|
|
<div className="star-icon">
|
|
<Star size={22} />
|
|
</div>
|
|
<div className="star-content">
|
|
<h4>Support ServerKit</h4>
|
|
<p>
|
|
By using custom branding, the GitHub star link is hidden from the sidebar.
|
|
If ServerKit is useful to you, please consider starring the project — it helps the community grow!
|
|
</p>
|
|
<a
|
|
href="https://github.com/jhd3197/ServerKit"
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="btn btn-primary btn-sm"
|
|
>
|
|
<Star size={14} />
|
|
Star on GitHub
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default WhiteLabelTab;
|