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
-142
View File
@@ -1,142 +0,0 @@
<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
@@ -1,103 +0,0 @@
<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>
-2
View File
@@ -1,2 +0,0 @@
export { default as Button } from "./Button.svelte";
export { default as IconButton } from "./IconButton.svelte";