@immich/ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,127 @@
1
+ <script lang="ts">
2
+ import type { Color, Shape, Size } from '../types.js';
3
+ import { cleanClass } from '../utils.js';
4
+ import { Button as ButtonPrimitive } from 'bits-ui';
5
+ import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
6
+ import { tv } from 'tailwind-variants';
7
+
8
+ type ButtonVariant = 'filled' | 'outline' | 'ghost' | 'hero';
9
+ type ButtonProps = {
10
+ class?: string;
11
+ color?: Color;
12
+ size?: Size;
13
+ shape?: Shape;
14
+ variant?: ButtonVariant;
15
+ fullWidth?: boolean;
16
+ } & (({ href?: never } & HTMLButtonAttributes) | ({ href: string } & HTMLAnchorAttributes));
17
+
18
+ const asOverride = (variant: ButtonVariant, colors: Record<Color, string>) =>
19
+ (Object.keys(colors) as Color[]).map((color) => ({ variant, color, class: colors[color] }));
20
+
21
+ const colorPlaceholder = {
22
+ primary: '',
23
+ secondary: '',
24
+ success: '',
25
+ danger: '',
26
+ warning: '',
27
+ info: '',
28
+ };
29
+
30
+ const variantPlaceholder = {
31
+ outline: '',
32
+ filled: '',
33
+ ghost: '',
34
+ hero: '',
35
+ };
36
+
37
+ const buttonVariants = tv({
38
+ base: 'ring-offset-background focus-visible:ring-ring flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
39
+ variants: {
40
+ shape: {
41
+ rectangle: 'rounded-none',
42
+ 'semi-round': 'rounded-lg',
43
+ round: 'rounded-full',
44
+ },
45
+ size: {
46
+ tiny: 'px-2 py-1 text-xs',
47
+ small: 'px-2 py-1 text-sm',
48
+ medium: 'px-4 py-2 text-md',
49
+ large: 'px-4 py-2 text-lg',
50
+ giant: 'px-8 py-4 text-xl',
51
+ },
52
+ fullWidth: {
53
+ true: 'w-full',
54
+ },
55
+ color: colorPlaceholder,
56
+ variant: variantPlaceholder,
57
+ },
58
+ compoundVariants: [
59
+ ...asOverride('filled', {
60
+ primary: 'bg-primary text-light hover:bg-primary/80',
61
+ secondary: 'bg-dark text-light hover:bg-dark/80',
62
+ success: 'bg-success text-light hover:bg-success/80',
63
+ danger: 'bg-danger text-light hover:bg-danger/80',
64
+ warning: 'bg-warning text-light hover:bg-warning/80',
65
+ info: 'bg-info text-light hover:bg-info/80',
66
+ }),
67
+
68
+ ...asOverride('outline', {
69
+ primary: 'bg-primary/10 text-primary border border-primary hover:bg-primary/20',
70
+ secondary: 'bg-dark/10 text-dark border border-dark hover:bg-dark/20',
71
+ success: 'bg-success/10 text-success border border-success hover:bg-success/20',
72
+ danger: 'bg-danger/10 text-danger border border-danger hover:bg-danger/20',
73
+ warning: 'bg-warning/10 text-warning border border-warning hover:bg-warning/20',
74
+ info: 'bg-info/10 text-info border border-info hover:bg-info/20',
75
+ }),
76
+
77
+ ...asOverride('ghost', {
78
+ primary: 'text-primary hover:bg-primary/10',
79
+ secondary: 'text-dark hover:bg-dark/10',
80
+ success: 'text-success hover:bg-success/10',
81
+ danger: 'text-danger hover:bg-danger/10',
82
+ warning: 'text-warning hover:bg-warning/10',
83
+ info: 'text-info hover:bg-info/10',
84
+ }),
85
+
86
+ ...asOverride('hero', {
87
+ primary: 'bg-gradient-to-tr from-primary to-primary/60 text-light hover:bg-primary',
88
+ secondary: 'bg-gradient-to-tr from-dark to-dark/60 text-light hover:bg-dark',
89
+ success: 'bg-gradient-to-tr from-success to-success/60 text-light hover:bg-success',
90
+ danger: 'bg-gradient-to-tr from-danger to-danger/60 text-light hover:bg-danger',
91
+ warning: 'bg-gradient-to-tr from-warning to-warning/60 text-light hover:bg-warning',
92
+ info: 'bg-gradient-to-tr from-info to-info/60 text-light hover:bg-info',
93
+ }),
94
+ ],
95
+ });
96
+
97
+ const {
98
+ type = 'button',
99
+ href,
100
+ variant = 'filled',
101
+ color = 'primary',
102
+ shape = 'semi-round',
103
+ size = 'medium',
104
+ fullWidth = false,
105
+ class: className = '',
106
+ children,
107
+ ...restProps
108
+ }: ButtonProps = $props();
109
+
110
+ const classList = $derived(
111
+ cleanClass(buttonVariants({ variant, color, shape, size, fullWidth }), className),
112
+ );
113
+ </script>
114
+
115
+ {#if href}
116
+ <a {href} class={classList} {...restProps as HTMLAnchorAttributes}>
117
+ {@render children?.()}
118
+ </a>
119
+ {:else}
120
+ <ButtonPrimitive.Root
121
+ class={classList}
122
+ type={type as HTMLButtonAttributes['type']}
123
+ {...restProps as HTMLButtonAttributes}
124
+ >
125
+ {@render children?.()}
126
+ </ButtonPrimitive.Root>
127
+ {/if}
@@ -0,0 +1,15 @@
1
+ import type { Color, Shape, Size } from '../types.js';
2
+ import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';
3
+ declare const Button: import("svelte").Component<{
4
+ class?: string;
5
+ color?: Color;
6
+ size?: Size;
7
+ shape?: Shape;
8
+ variant?: "filled" | "outline" | "ghost" | "hero";
9
+ fullWidth?: boolean;
10
+ } & (({
11
+ href?: never;
12
+ } & HTMLButtonAttributes) | ({
13
+ href: string;
14
+ } & HTMLAnchorAttributes)), {}, "">;
15
+ export default Button;
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { cleanClass } from '../utils.js';
3
+ import type { WithElementRef } from 'bits-ui';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+
6
+ type Props = WithElementRef<HTMLAttributes<HTMLDivElement>>;
7
+
8
+ let { ref = $bindable(null), class: className, children, ...restProps }: Props = $props();
9
+ </script>
10
+
11
+ <div
12
+ bind:this={ref}
13
+ class={cleanClass('rounded-lg border bg-light text-dark shadow-lg', className)}
14
+ {...restProps}
15
+ >
16
+ {@render children?.()}
17
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { WithElementRef } from 'bits-ui';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ declare const Card: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLDivElement>>, {}, "ref">;
4
+ export default Card;
@@ -0,0 +1,16 @@
1
+ <script lang="ts">
2
+ import { cleanClass } from '../utils.js';
3
+ import type { WithElementRef } from 'bits-ui';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+
6
+ let {
7
+ ref = $bindable(null),
8
+ class: className,
9
+ children,
10
+ ...restProps
11
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
12
+ </script>
13
+
14
+ <div bind:this={ref} class={cleanClass('p-6', className)} {...restProps}>
15
+ {@render children?.()}
16
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { WithElementRef } from 'bits-ui';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ declare const CardBody: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLDivElement>>, {}, "ref">;
4
+ export default CardBody;
@@ -0,0 +1,16 @@
1
+ <script lang="ts">
2
+ import type { WithElementRef } from 'bits-ui';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { cleanClass } from '../utils.js';
5
+
6
+ let {
7
+ ref = $bindable(null),
8
+ class: className,
9
+ children,
10
+ ...restProps
11
+ }: WithElementRef<HTMLAttributes<HTMLParagraphElement>> = $props();
12
+ </script>
13
+
14
+ <p bind:this={ref} class={cleanClass('text-muted-foreground text-sm', className)} {...restProps}>
15
+ {@render children?.()}
16
+ </p>
@@ -0,0 +1,4 @@
1
+ import type { WithElementRef } from 'bits-ui';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ declare const CardDescription: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLParagraphElement>>, {}, "ref">;
4
+ export default CardDescription;
@@ -0,0 +1,16 @@
1
+ <script lang="ts">
2
+ import { cleanClass } from '../utils.js';
3
+ import type { WithElementRef } from 'bits-ui';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+
6
+ let {
7
+ ref = $bindable(null),
8
+ class: className,
9
+ children,
10
+ ...restProps
11
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
12
+ </script>
13
+
14
+ <div bind:this={ref} class={cleanClass('flex items-center p-6 pt-0', className)} {...restProps}>
15
+ {@render children?.()}
16
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { WithElementRef } from 'bits-ui';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ declare const CardFooter: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLDivElement>>, {}, "ref">;
4
+ export default CardFooter;
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { cleanClass } from '../utils.js';
3
+ import type { WithElementRef } from 'bits-ui';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+
6
+ type Props = WithElementRef<HTMLAttributes<HTMLDivElement>>;
7
+
8
+ let { ref = $bindable(null), class: className, children, ...restProps }: Props = $props();
9
+ </script>
10
+
11
+ <div
12
+ bind:this={ref}
13
+ class={cleanClass('flex flex-col space-y-1.5 rounded-t-lg p-6 pb-0', className)}
14
+ {...restProps}
15
+ >
16
+ {@render children?.()}
17
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { WithElementRef } from 'bits-ui';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ declare const CardHeader: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLDivElement>>, {}, "ref">;
4
+ export default CardHeader;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import type { WithElementRef } from 'bits-ui';
3
+ import type { HTMLAttributes } from 'svelte/elements';
4
+ import { cleanClass } from '../utils.js';
5
+
6
+ let {
7
+ ref = $bindable(null),
8
+ class: className,
9
+ level = 3,
10
+ children,
11
+ ...restProps
12
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
13
+ level?: 1 | 2 | 3 | 4 | 5 | 6;
14
+ } = $props();
15
+ </script>
16
+
17
+ <div
18
+ role="heading"
19
+ aria-level={level}
20
+ bind:this={ref}
21
+ class={cleanClass('text-lg font-semibold leading-none tracking-tight', className)}
22
+ {...restProps}
23
+ >
24
+ {@render children?.()}
25
+ </div>
@@ -0,0 +1,7 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ declare const CardTitle: import("svelte").Component<HTMLAttributes<HTMLDivElement> & {
3
+ ref?: HTMLElement | null | undefined;
4
+ } & {
5
+ level?: 1 | 2 | 3 | 4 | 5 | 6;
6
+ }, {}, "ref">;
7
+ export default CardTitle;
@@ -0,0 +1,103 @@
1
+ <script lang="ts">
2
+ import { Checkbox as CheckboxPrimitive, type WithoutChildrenOrChild } from 'bits-ui';
3
+ import { mdiCheck, mdiMinus } from '@mdi/js';
4
+ import Icon from './Icon.svelte';
5
+ import { tv } from 'tailwind-variants';
6
+ import type { Color, Shape, Size } from '../types.js';
7
+ import { cleanClass } from '../utils.js';
8
+
9
+ type CheckboxProps = WithoutChildrenOrChild<CheckboxPrimitive.RootProps> & {
10
+ color?: Color;
11
+ shape?: Shape;
12
+ size?: Size;
13
+ };
14
+
15
+ let {
16
+ ref = $bindable(null),
17
+ checked = $bindable(false),
18
+ class: className,
19
+ color = 'primary',
20
+ shape = 'semi-round',
21
+ size = 'small',
22
+ ...restProps
23
+ }: CheckboxProps = $props();
24
+
25
+ const container = tv({
26
+ base: 'ring-offset-background focus-visible:ring-ring peer box-content border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[disabled=true]:cursor-not-allowed data-[state=checked]:bg-primary data-[disabled=true]:opacity-50 overflow-hidden',
27
+ variants: {
28
+ shape: {
29
+ rectangle: 'rounded-none',
30
+ 'semi-round': 'rounded-lg',
31
+ round: 'rounded-full',
32
+ },
33
+ color: {
34
+ primary: 'border-primary',
35
+ secondary: 'border-secondary',
36
+ success: 'border-success',
37
+ danger: 'border-danger',
38
+ warning: 'border-warning',
39
+ info: 'border-info',
40
+ },
41
+ size: {
42
+ tiny: 'size-4',
43
+ small: 'size-6',
44
+ medium: 'size-8',
45
+ large: 'size-16',
46
+ giant: 'size-32',
47
+ },
48
+ },
49
+ compoundVariants: [
50
+ //
51
+ { size: 'tiny', shape: 'semi-round', class: 'rounded' },
52
+ { size: 'small', shape: 'semi-round', class: 'rounded-md' },
53
+ { size: 'large', shape: 'semi-round', class: 'rounded-xl' },
54
+ { size: 'giant', shape: 'semi-round', class: 'rounded-2xl' },
55
+ ],
56
+ });
57
+
58
+ const parent = tv({
59
+ base: 'flex items-center justify-center text-current',
60
+ variants: {
61
+ size: {
62
+ tiny: 'size-4',
63
+ small: 'size-6',
64
+ medium: 'size-8',
65
+ large: 'size-16',
66
+ giant: 'size-32',
67
+ },
68
+ },
69
+ });
70
+
71
+ const icon = tv({
72
+ variants: {
73
+ fullWidth: {
74
+ true: 'w-full',
75
+ },
76
+ color: {
77
+ primary: 'bg-primary text-light hover:bg-primary/80',
78
+ secondary: 'bg-dark text-light hover:bg-dark/80',
79
+ success: 'bg-success text-light hover:bg-success/80',
80
+ danger: 'bg-danger text-light hover:bg-danger/80',
81
+ warning: 'bg-warning text-light hover:bg-warning/80',
82
+ info: 'bg-info text-light hover:bg-info/80',
83
+ },
84
+ },
85
+ });
86
+ </script>
87
+
88
+ <CheckboxPrimitive.Root
89
+ bind:ref
90
+ class={cleanClass(container({ size, color, shape }), className)}
91
+ bind:checked
92
+ {...restProps}
93
+ >
94
+ {#snippet children({ checked })}
95
+ <div class={parent({ size })}>
96
+ {#if checked === true}
97
+ <Icon path={mdiCheck} size="100%" class={cleanClass(icon({ color }))} />
98
+ {:else if checked === 'indeterminate'}
99
+ <Icon path={mdiMinus} size="100%" class={cleanClass(icon({ color }))} />
100
+ {/if}
101
+ </div>
102
+ {/snippet}
103
+ </CheckboxPrimitive.Root>
@@ -0,0 +1,8 @@
1
+ import { Checkbox as CheckboxPrimitive } from 'bits-ui';
2
+ import type { Color, Shape, Size } from '../types.js';
3
+ declare const Checkbox: import("svelte").Component<Omit<Omit<CheckboxPrimitive.RootProps, "child">, "children"> & {
4
+ color?: Color;
5
+ shape?: Shape;
6
+ size?: Size;
7
+ }, {}, "ref" | "checked">;
8
+ export default Checkbox;
@@ -0,0 +1,62 @@
1
+ <script lang="ts">
2
+ import type { Color } from '../types.js';
3
+ import { cleanClass } from '../utils.js';
4
+ import type { AriaRole } from 'svelte/elements';
5
+
6
+ type IconProps = {
7
+ path: string;
8
+ size?: string;
9
+ color?: Color | 'currentColor' | string;
10
+ flipped?: boolean;
11
+ class?: string;
12
+ viewBox?: string;
13
+ role?: AriaRole;
14
+ title?: string;
15
+ description?: string;
16
+ ariaHidden?: boolean;
17
+ ariaLabel?: string;
18
+ ariaLabelledby?: string;
19
+ strokeWidth?: number;
20
+ strokeColor?: string;
21
+ spin?: false;
22
+ };
23
+
24
+ const {
25
+ size = '1em',
26
+ viewBox = '0 0 24 24',
27
+ class: className = '',
28
+ flipped = false,
29
+ spin = false,
30
+ role = 'img',
31
+ ariaLabelledby,
32
+ strokeColor = 'currentColor',
33
+ strokeWidth = 2,
34
+ ariaLabel = '',
35
+ ariaHidden = false,
36
+ title,
37
+ path,
38
+ color = 'currentColor',
39
+ description,
40
+ }: IconProps = $props();
41
+ </script>
42
+
43
+ <svg
44
+ width={size}
45
+ height={size}
46
+ {viewBox}
47
+ class={cleanClass(className, flipped && '-scale-x-100', spin && 'animate-spin')}
48
+ {role}
49
+ stroke={strokeColor}
50
+ stroke-width={strokeWidth}
51
+ aria-label={ariaLabel}
52
+ aria-hidden={ariaHidden}
53
+ aria-labelledby={ariaLabelledby}
54
+ >
55
+ {#if title}
56
+ <title>{title}</title>
57
+ {/if}
58
+ {#if description}
59
+ <desc>{description}</desc>
60
+ {/if}
61
+ <path d={path} fill={color} />
62
+ </svg>
@@ -0,0 +1,20 @@
1
+ import type { Color } from '../types.js';
2
+ import type { AriaRole } from 'svelte/elements';
3
+ declare const Icon: import("svelte").Component<{
4
+ path: string;
5
+ size?: string;
6
+ color?: Color | "currentColor" | string;
7
+ flipped?: boolean;
8
+ class?: string;
9
+ viewBox?: string;
10
+ role?: AriaRole;
11
+ title?: string;
12
+ description?: string;
13
+ ariaHidden?: boolean;
14
+ ariaLabel?: string;
15
+ ariaLabelledby?: string;
16
+ strokeWidth?: number;
17
+ strokeColor?: string;
18
+ spin?: false;
19
+ }, {}, "">;
20
+ export default Icon;
@@ -0,0 +1,22 @@
1
+ <script lang="ts">
2
+ import type { HTMLInputAttributes } from 'svelte/elements';
3
+ import type { WithElementRef } from 'bits-ui';
4
+ import { cleanClass } from '../utils.js';
5
+
6
+ let {
7
+ ref = $bindable(null),
8
+ value = $bindable(),
9
+ class: className,
10
+ ...restProps
11
+ }: WithElementRef<HTMLInputAttributes> = $props();
12
+ </script>
13
+
14
+ <input
15
+ bind:this={ref}
16
+ class={cleanClass(
17
+ 'border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
18
+ className,
19
+ )}
20
+ bind:value
21
+ {...restProps}
22
+ />
@@ -0,0 +1,4 @@
1
+ import type { HTMLInputAttributes } from 'svelte/elements';
2
+ import type { WithElementRef } from 'bits-ui';
3
+ declare const Input: import("svelte").Component<WithElementRef<HTMLInputAttributes>, {}, "value" | "ref">;
4
+ export default Input;
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ import { cleanClass } from '../utils.js';
3
+ import { Label as LabelPrimitive } from 'bits-ui';
4
+
5
+ let {
6
+ ref = $bindable(null),
7
+ class: className,
8
+ ...restProps
9
+ }: LabelPrimitive.RootProps = $props();
10
+ </script>
11
+
12
+ <LabelPrimitive.Root
13
+ bind:ref
14
+ class={cleanClass(
15
+ 'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
16
+ className,
17
+ )}
18
+ {...restProps}
19
+ />
@@ -0,0 +1,3 @@
1
+ import { Label as LabelPrimitive } from 'bits-ui';
2
+ declare const Label: import("svelte").Component<LabelPrimitive.RootProps, {}, "ref">;
3
+ export default Label;
@@ -0,0 +1,11 @@
1
+ export { default as Button } from './Button.svelte';
2
+ export { default as Card } from './Card.svelte';
3
+ export { default as CardBody } from './CardBody.svelte';
4
+ export { default as CardDescription } from './CardDescription.svelte';
5
+ export { default as CardFooter } from './CardFooter.svelte';
6
+ export { default as CardHeader } from './CardHeader.svelte';
7
+ export { default as CardTitle } from './CardTitle.svelte';
8
+ export { default as Checkbox } from './Checkbox.svelte';
9
+ export { default as Icon } from './Icon.svelte';
10
+ export { default as Input } from './Input.svelte';
11
+ export { default as Label } from './Label.svelte';
@@ -0,0 +1,11 @@
1
+ export { default as Button } from './Button.svelte';
2
+ export { default as Card } from './Card.svelte';
3
+ export { default as CardBody } from './CardBody.svelte';
4
+ export { default as CardDescription } from './CardDescription.svelte';
5
+ export { default as CardFooter } from './CardFooter.svelte';
6
+ export { default as CardHeader } from './CardHeader.svelte';
7
+ export { default as CardTitle } from './CardTitle.svelte';
8
+ export { default as Checkbox } from './Checkbox.svelte';
9
+ export { default as Icon } from './Icon.svelte';
10
+ export { default as Input } from './Input.svelte';
11
+ export { default as Label } from './Label.svelte';
@@ -0,0 +1 @@
1
+ export * from './components/index.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components/index.js';
@@ -0,0 +1,3 @@
1
+ export type Color = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info';
2
+ export type Size = 'tiny' | 'small' | 'medium' | 'large' | 'giant';
3
+ export type Shape = 'rectangle' | 'semi-round' | 'round';
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const cleanClass: (...classNames: unknown[]) => string;
package/dist/utils.js ADDED
@@ -0,0 +1,10 @@
1
+ export const cleanClass = (...classNames) => {
2
+ return classNames
3
+ .filter((className) => {
4
+ if (!className || typeof className === 'boolean') {
5
+ return false;
6
+ }
7
+ return typeof className === 'string';
8
+ })
9
+ .join(' ');
10
+ };