Files
classroomio/apps/dashboard/src/lib/features/widget/panels/design-panel.svelte
T

121 lines
4.2 KiB
Svelte
Raw Normal View History

2026-04-27 11:40:38 +01:00
<script lang="ts">
import * as Field from '@cio/ui/base/field';
import * as Select from '@cio/ui/base/select';
import { Switch } from '@cio/ui/base/switch';
import { InputField } from '@cio/ui/custom/input-field';
import { TextareaField } from '@cio/ui/custom/textarea-field';
import { t } from '$lib/utils/functions/translations';
import type { WidgetDetail } from '../utils/types';
import type { WidgetConfig } from '../utils/types';
interface Props {
draftConfig: WidgetConfig;
availableThemes: WidgetDetail['planGatedFields']['availableThemes'];
canUseCustomColors: boolean;
canUseCustomCss: boolean;
isBrandingForced: boolean;
/** Zod-keyed validation errors from the last save attempt (e.g. `config.colors.primaryColor`). */
errors?: Record<string, string>;
2026-04-27 11:40:38 +01:00
}
let {
draftConfig = $bindable(),
availableThemes,
canUseCustomColors,
canUseCustomCss,
isBrandingForced,
errors = {}
2026-04-27 11:40:38 +01:00
}: Props = $props();
const errFor = (path: string) => errors[path] ?? '';
2026-04-27 11:40:38 +01:00
</script>
<div class="space-y-6">
<Field.Group>
<Field.Set>
<Field.Legend>{$t('widgets.editor.design')}</Field.Legend>
<Field.Field>
<Field.Label>{$t('widgets.form.theme_preset')}</Field.Label>
<Select.Root type="single" bind:value={draftConfig.themePreset}>
<Select.Trigger>{draftConfig.themePreset}</Select.Trigger>
<Select.Content>
{#each availableThemes as theme (theme)}
<Select.Item value={theme}>{theme}</Select.Item>
{/each}
</Select.Content>
</Select.Root>
</Field.Field>
<InputField
label={$t('widgets.form.primary_color')}
bind:value={draftConfig.colors.primaryColor}
maxLength={64}
errorMessage={errFor('config.colors.primaryColor')}
/>
2026-04-27 11:40:38 +01:00
<InputField
label={$t('widgets.form.background_color')}
bind:value={draftConfig.colors.backgroundColor}
isDisabled={!canUseCustomColors}
maxLength={64}
errorMessage={errFor('config.colors.backgroundColor')}
2026-04-27 11:40:38 +01:00
/>
<InputField
label={$t('widgets.form.text_color')}
bind:value={draftConfig.colors.textColor}
isDisabled={!canUseCustomColors}
maxLength={64}
errorMessage={errFor('config.colors.textColor')}
2026-04-27 11:40:38 +01:00
/>
<InputField
label={$t('widgets.form.border_color')}
bind:value={draftConfig.colors.borderColor}
isDisabled={!canUseCustomColors}
maxLength={64}
errorMessage={errFor('config.colors.borderColor')}
2026-04-27 11:40:38 +01:00
/>
<InputField
type="number"
label={$t('widgets.form.border_radius')}
bind:value={draftConfig.content.borderRadius}
min={0}
max={32}
step={1}
helperMessage={errFor('config.content.borderRadius') ? '' : $t('widgets.form.border_radius_hint')}
errorMessage={errFor('config.content.borderRadius')}
/>
<InputField
label={$t('widgets.form.font_family')}
bind:value={draftConfig.typography.fontFamily}
maxLength={120}
errorMessage={errFor('config.typography.fontFamily')}
2026-04-27 11:40:38 +01:00
/>
<InputField
type="number"
label={$t('widgets.form.font_scale')}
bind:value={draftConfig.typography.fontSizeScale}
min={0.8}
max={1.4}
step={0.1}
helperMessage={errFor('config.typography.fontSizeScale') ? '' : $t('widgets.form.font_scale_hint')}
errorMessage={errFor('config.typography.fontSizeScale')}
2026-04-27 11:40:38 +01:00
/>
<Field.Field orientation="horizontal">
<Switch bind:checked={draftConfig.branding.showPoweredBy} disabled={isBrandingForced} />
<Field.Label>{$t('widgets.form.show_powered_by')}</Field.Label>
</Field.Field>
<TextareaField
label={$t('widgets.form.custom_css')}
bind:value={draftConfig.advanced.customCss}
rows={6}
maxlength={5000}
2026-04-27 11:40:38 +01:00
disabled={!canUseCustomCss}
helperMessage={!canUseCustomCss
? $t('widgets.form.custom_css_locked')
: errFor('config.advanced.customCss')
? ''
: $t('widgets.form.custom_css_hint')}
errorMessage={errFor('config.advanced.customCss')}
2026-04-27 11:40:38 +01:00
/>
</Field.Set>
</Field.Group>
</div>