refactor: reorganize components

This commit is contained in:
2026-02-04 16:42:33 +05:00
parent 1996719fcb
commit 62254acdb9
11 changed files with 8 additions and 10 deletions
@@ -1,5 +1,5 @@
<script lang="ts">
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
interface Props {
backgroundImage?: string | undefined;
+1 -1
View File
@@ -4,7 +4,7 @@
import type { ImageCropResult } from "$lib/types/panel";
import { ImageService } from "$lib/services/imageService";
import { uiStore, setLoading } from "../../stores/uiStore";
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
interface Props {
imageSrc: string;
+1 -1
View File
@@ -5,7 +5,7 @@
import { ImageService } from "$lib/services/imageService";
import { handleError } from "$lib/utils/errorHandler";
import type { ImageUploadResult } from "$lib/types/panel";
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
let imageService = new ImageService();
+1 -1
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
interface Props {
onUploadNewImage?: () => void;
+1 -1
View File
@@ -3,7 +3,7 @@
import { panelStore } from "../../stores/panelStore";
import { panelStorage } from "$lib/utils/panelStorage";
import type { Panel } from "$lib/types/panel";
import { IconButton } from "$lib/components/ui";
import IconButton from "../ui/IconButton.svelte";
interface Props {
onPanelSelect: (panel: Panel) => void;
+1 -1
View File
@@ -4,7 +4,7 @@
type TextItem = Panel["texts"][0];
import { Stage, Layer, Image, Text } from "svelte-konva";
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
interface Props {
panel: Panel;
+1 -1
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import type { Panel } from "$lib/types/panel";
import PanelPreview from "./PanelPreview.svelte";
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
interface Props {
panels: Panel[];
+1 -1
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { Button } from "$lib/components/ui";
import Button from "../ui/Button.svelte";
interface Props {
onTextAdd: (text: string) => void;
+142
View File
@@ -0,0 +1,142 @@
<script lang="ts">
type ButtonVariant = "primary" | "secondary" | "danger";
type ButtonSize = "sm" | "md" | "lg";
type ButtonType = "button" | "submit" | "reset";
interface Props {
variant?: ButtonVariant;
size?: ButtonSize;
disabled?: boolean;
type?: ButtonType;
fullWidth?: boolean;
loading?: boolean;
class?: string;
children?: any;
onclick?: (event: MouseEvent) => void;
[key: string]: any;
}
let {
variant = "primary",
size = "md",
disabled = false,
type = "button",
fullWidth = false,
loading = false,
class: className = "",
children,
...restProps
}: Props = $props();
</script>
<button
{type}
{disabled}
class:btn-primary={variant === "primary"}
class:btn-secondary={variant === "secondary"}
class:btn-danger={variant === "danger"}
class:btn-sm={size === "sm"}
class:btn-md={size === "md"}
class:btn-lg={size === "lg"}
class:btn-full={fullWidth}
class:btn-loading={loading}
class={className}
{...restProps}
>
{#if loading}
<span class="btn-spinner"></span>
{/if}
{@render children?.()}
</button>
<style>
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
white-space: nowrap;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* Sizes */
.btn-sm {
padding: 0.5rem 1rem;
font-size: 0.875rem;
}
.btn-md {
padding: 0.75rem 1.5rem;
font-size: 1rem;
}
.btn-lg {
padding: 1rem 2rem;
font-size: 1.125rem;
}
.btn-full {
width: 100%;
}
/* Variants */
.btn-primary {
background: #007bff;
color: white;
}
.btn-primary:hover:not(:disabled) {
background: #0056b3;
}
.btn-secondary {
background: #6c757d;
color: white;
}
.btn-secondary:hover:not(:disabled) {
background: #545b62;
}
.btn-danger {
background: #dc3545;
color: white;
}
.btn-danger:hover:not(:disabled) {
background: #c82333;
}
/* Loading state */
.btn-loading {
position: relative;
pointer-events: none;
}
.btn-spinner {
display: inline-block;
width: 1rem;
height: 1rem;
border: 2px solid currentColor;
border-right-color: transparent;
border-radius: 50%;
animation: spin 0.6s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
</style>
+103
View File
@@ -0,0 +1,103 @@
<script lang="ts">
type IconButtonVariant = "primary" | "secondary" | "danger";
type IconButtonSize = "sm" | "md" | "lg";
interface Props {
variant?: IconButtonVariant;
size?: IconButtonSize;
disabled?: boolean;
ariaLabel?: string;
class?: string;
children?: any;
onclick?: (event: MouseEvent) => void;
[key: string]: any;
}
let {
variant = "secondary",
size = "md",
disabled = false,
ariaLabel = "",
class: className = "",
children,
...restProps
}: Props = $props();
</script>
<button
{disabled}
aria-label={ariaLabel}
class:icon-btn-primary={variant === "primary"}
class:icon-btn-secondary={variant === "secondary"}
class:icon-btn-danger={variant === "danger"}
class:icon-btn-sm={size === "sm"}
class:icon-btn-md={size === "md"}
class:icon-btn-lg={size === "lg"}
class={className}
{...restProps}
>
{@render children?.()}
</button>
<style>
.icon-btn {
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
cursor: pointer;
transition: all 0.2s ease;
background: none;
padding: 0.25rem 0.5rem;
font-size: 1.2rem;
}
.icon-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* Sizes */
.icon-btn-sm {
padding: 0.125rem 0.25rem;
font-size: 1rem;
}
.icon-btn-md {
padding: 0.25rem 0.5rem;
font-size: 1.2rem;
}
.icon-btn-lg {
padding: 0.375rem 0.75rem;
font-size: 1.5rem;
}
/* Variants */
.icon-btn-primary {
color: #007bff;
}
.icon-btn-primary:hover:not(:disabled) {
color: #0056b3;
transform: scale(1.1);
}
.icon-btn-secondary {
color: #666;
}
.icon-btn-secondary:hover:not(:disabled) {
color: #007bff;
transform: scale(1.1);
}
.icon-btn-danger {
color: #dc3545;
}
.icon-btn-danger:hover:not(:disabled) {
color: #c82333;
transform: scale(1.1);
}
</style>