lithesome 0.12.3 → 0.13.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.
- package/dist/components/Checkbox/types.d.ts +1 -1
- package/dist/components/Combobox/ComboboxOption.svelte +2 -2
- package/dist/components/Combobox/types.d.ts +2 -2
- package/dist/components/Hovercard/types.d.ts +1 -1
- package/dist/components/Menu/types.d.ts +2 -2
- package/dist/components/Modal/Modal.svelte +1 -1
- package/dist/components/Modal/ModalContent.svelte +1 -1
- package/dist/components/Modal/types.d.ts +1 -1
- package/dist/components/Pin/types.d.ts +1 -1
- package/dist/components/Popover/PopoverContent.svelte +1 -1
- package/dist/components/Popover/types.d.ts +1 -1
- package/dist/components/Portal/Portal.svelte +1 -1
- package/dist/components/Portal/types.d.ts +1 -1
- package/dist/components/RadioGroup/types.d.ts +1 -1
- package/dist/components/Select/SelectOption.svelte +2 -2
- package/dist/components/Select/types.d.ts +6 -3
- package/dist/components/Slider/Slider.svelte +106 -0
- package/dist/components/Slider/Slider.svelte.d.ts +17 -0
- package/dist/components/Slider/SliderRange.svelte +31 -0
- package/dist/components/Slider/SliderRange.svelte.d.ts +15 -0
- package/dist/components/Slider/SliderThumb.svelte +65 -0
- package/dist/components/Slider/SliderThumb.svelte.d.ts +15 -0
- package/dist/components/Slider/SliderValue.svelte +21 -0
- package/dist/components/Slider/SliderValue.svelte.d.ts +15 -0
- package/dist/components/Slider/context.svelte.d.ts +32 -0
- package/dist/components/Slider/context.svelte.js +45 -0
- package/dist/components/Slider/index.d.ts +5 -0
- package/dist/components/Slider/index.js +4 -0
- package/dist/components/Slider/types.d.ts +35 -0
- package/dist/components/Slider/types.js +1 -0
- package/dist/components/Switch/types.d.ts +1 -1
- package/dist/components/Tabs/types.d.ts +1 -1
- package/dist/components/Toast/Toaster.svelte +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/components/FloatingContent.svelte +2 -2
- package/dist/internal/helpers/keyboard.d.ts +1 -0
- package/dist/internal/helpers/keyboard.js +1 -0
- package/dist/internal/helpers/utils.svelte.d.ts +7 -0
- package/dist/internal/helpers/utils.svelte.js +9 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Handler, PropsMaybeChildren } from '../../internal/types.js';
|
|
1
|
+
import type { Handler, PropsMaybeChildren } from '../../index.js/internal/types.js';
|
|
2
2
|
export type Checked = boolean | 'mixed';
|
|
3
3
|
interface CheckboxState {
|
|
4
4
|
/** If the checkbox is checked or not. */
|
|
@@ -12,7 +12,7 @@ let {
|
|
|
12
12
|
disabled = $bindable(false),
|
|
13
13
|
onClick,
|
|
14
14
|
onFocus,
|
|
15
|
-
|
|
15
|
+
onMouseover,
|
|
16
16
|
...props
|
|
17
17
|
} = $props();
|
|
18
18
|
let optionEl;
|
|
@@ -31,7 +31,7 @@ const handleFocus = (e) => {
|
|
|
31
31
|
onFocus?.(e);
|
|
32
32
|
};
|
|
33
33
|
const handleMouseover = (e) => {
|
|
34
|
-
|
|
34
|
+
onMouseover?.(e);
|
|
35
35
|
if (!disabled)
|
|
36
36
|
ctx.setHovered(uid());
|
|
37
37
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Props, PropsNoChildren, ContentProps, Handler, JsonValue } from '../../internal/types.js';
|
|
1
|
+
import type { Props, PropsNoChildren, ContentProps, Handler, JsonValue } from '../../index.js/internal/types.js';
|
|
2
2
|
export type ComboboxElement = HTMLAnchorElement | HTMLButtonElement;
|
|
3
3
|
interface ComboboxState {
|
|
4
4
|
/** Whether or not the content is opened or not. */
|
|
@@ -48,6 +48,6 @@ export interface ComboboxOptionProps extends Props<ComboboxElement, ComboboxOpti
|
|
|
48
48
|
label?: string;
|
|
49
49
|
onClick?: Handler<MouseEvent, ComboboxElement>;
|
|
50
50
|
onFocus?: Handler<FocusEvent, ComboboxElement>;
|
|
51
|
-
|
|
51
|
+
onMouseover?: Handler<MouseEvent, ComboboxElement>;
|
|
52
52
|
}
|
|
53
53
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Props, PropsNoChildren, ContentProps, Handler } from '../../internal/types.js';
|
|
1
|
+
import type { Props, PropsNoChildren, ContentProps, Handler } from '../../index.js/internal/types.js';
|
|
2
2
|
interface HovercardState {
|
|
3
3
|
/** Whether or not the content is opened or not. */
|
|
4
4
|
visible: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Props, PropsNoChildren, ContentProps, Handler } from '../../internal/types.js';
|
|
2
|
-
|
|
1
|
+
import type { Props, PropsNoChildren, ContentProps, Handler } from '../../index.js/internal/types.js';
|
|
2
|
+
type MenuItemElement = HTMLButtonElement | HTMLAnchorElement;
|
|
3
3
|
interface MenuState {
|
|
4
4
|
/** Whether or not the content is opened or not. */
|
|
5
5
|
visible: boolean;
|
|
@@ -4,7 +4,7 @@ export const { context, contextName } = setupContext();
|
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
6
|
<script lang="ts">import { createUID, useActions, KEYS, classProp } from "../../internal/index.js";
|
|
7
|
-
import { usePortal } from "../../index.js";
|
|
7
|
+
import { usePortal } from "../../index.js/index.js";
|
|
8
8
|
import { setContext } from "svelte";
|
|
9
9
|
let {
|
|
10
10
|
children,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">import { useActions, getTransition, classProp } from "../../internal/index.js";
|
|
2
|
-
import { useTrap } from "../../index.js";
|
|
2
|
+
import { useTrap } from "../../index.js/index.js";
|
|
3
3
|
import { context } from "./Modal.svelte";
|
|
4
4
|
let { children, class: klass, use = [], self = $bindable(), transition, ...props } = $props();
|
|
5
5
|
const ctx = context();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transition } from '../../internal/index.js';
|
|
2
|
-
import type { Props, PropsNoChildren } from '../../internal/types.js';
|
|
2
|
+
import type { Props, PropsNoChildren } from '../../index.js/internal/types.js';
|
|
3
3
|
export interface ModalProps extends Props<HTMLDivElement> {
|
|
4
4
|
/** Control the visibility of the modal. */
|
|
5
5
|
visible: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Props, PropsNoChildren, ContentProps } from '../../internal/types.js';
|
|
1
|
+
import type { Props, PropsNoChildren, ContentProps } from '../../index.js/internal/types.js';
|
|
2
2
|
interface PopoverState {
|
|
3
3
|
/** Whether or not the content is opened or not. */
|
|
4
4
|
visible: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Props, Handler, JsonValue } from '../../internal/types.js';
|
|
1
|
+
import type { Props, Handler, JsonValue } from '../../index.js/internal/types.js';
|
|
2
2
|
export interface RadioGroupProps extends Props<HTMLDivElement> {
|
|
3
3
|
/** The value of the radiogroup. */
|
|
4
4
|
value: JsonValue;
|
|
@@ -12,7 +12,7 @@ let {
|
|
|
12
12
|
disabled = $bindable(false),
|
|
13
13
|
onClick,
|
|
14
14
|
onFocus,
|
|
15
|
-
|
|
15
|
+
onMouseover,
|
|
16
16
|
...props
|
|
17
17
|
} = $props();
|
|
18
18
|
let optionEl;
|
|
@@ -31,7 +31,7 @@ const handleFocus = (e) => {
|
|
|
31
31
|
onFocus?.(e);
|
|
32
32
|
};
|
|
33
33
|
const handleMouseover = (e) => {
|
|
34
|
-
|
|
34
|
+
onMouseover?.(e);
|
|
35
35
|
if (!disabled)
|
|
36
36
|
ctx.setHovered(uid());
|
|
37
37
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Props, PropsNoChildren, ContentProps, Handler, JsonValue } from '../../internal/types.js';
|
|
1
|
+
import type { Props, PropsNoChildren, ContentProps, Handler, JsonValue } from '../../index.js/internal/types.js';
|
|
2
2
|
interface SelectState {
|
|
3
3
|
/** Whether or not the content is opened or not. */
|
|
4
4
|
visible: boolean;
|
|
@@ -31,11 +31,14 @@ export interface SelectOptionProps extends Props<HTMLButtonElement, SelectOption
|
|
|
31
31
|
label?: string;
|
|
32
32
|
onClick?: Handler<MouseEvent, HTMLButtonElement>;
|
|
33
33
|
onFocus?: Handler<FocusEvent, HTMLButtonElement>;
|
|
34
|
-
|
|
34
|
+
onMouseover?: Handler<MouseEvent, HTMLButtonElement>;
|
|
35
35
|
}
|
|
36
36
|
export interface SelectTriggerProps extends Props<HTMLDivElement, SelectState> {
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
interface SelectValueState {
|
|
39
|
+
placeholderVisible: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface SelectValueProps extends PropsNoChildren<HTMLSpanElement, SelectValueState> {
|
|
39
42
|
/** The fallback value of no option is selected. */
|
|
40
43
|
placeholder?: string;
|
|
41
44
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script lang="ts" context="module">import { clamp, setupContext } from "../../internal/index.js";
|
|
2
|
+
import { SliderContext } from "./context.svelte.js";
|
|
3
|
+
export const { context, contextName } = setupContext();
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script lang="ts">import { useActions, classProp } from "../../internal/index.js";
|
|
7
|
+
import { setContext } from "svelte";
|
|
8
|
+
let {
|
|
9
|
+
children,
|
|
10
|
+
use = [],
|
|
11
|
+
class: klass,
|
|
12
|
+
self = $bindable(),
|
|
13
|
+
min = $bindable(0),
|
|
14
|
+
max = $bindable(100),
|
|
15
|
+
step = $bindable(1),
|
|
16
|
+
value = $bindable(50),
|
|
17
|
+
orientation = $bindable("horizontal"),
|
|
18
|
+
reverse = $bindable(false),
|
|
19
|
+
disabled = $bindable(false),
|
|
20
|
+
onMousedown,
|
|
21
|
+
onClick,
|
|
22
|
+
...props
|
|
23
|
+
} = $props();
|
|
24
|
+
const ctx = new SliderContext(
|
|
25
|
+
{ min, max, step, value, orientation, reverse, disabled },
|
|
26
|
+
{
|
|
27
|
+
onChange(val) {
|
|
28
|
+
value = val;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const state = $derived({
|
|
33
|
+
value: ctx.value,
|
|
34
|
+
percentage: ctx.Percentage
|
|
35
|
+
});
|
|
36
|
+
setContext(contextName, ctx);
|
|
37
|
+
const calculateValue = (e) => {
|
|
38
|
+
if (!ctx.dragging || !ctx.trackElement)
|
|
39
|
+
return;
|
|
40
|
+
const { clientX, clientY } = e;
|
|
41
|
+
const { width, height, left, right, top, bottom } = ctx.trackElement.getBoundingClientRect();
|
|
42
|
+
const position = ctx.orientation === "horizontal" ? clientX : clientY;
|
|
43
|
+
const length = ctx.orientation === "horizontal" ? width : height;
|
|
44
|
+
const start = ctx.orientation === "horizontal" ? ctx.reverse ? right : left : ctx.reverse ? top : bottom;
|
|
45
|
+
ctx.value = clamp(
|
|
46
|
+
ctx.min,
|
|
47
|
+
Math.round(
|
|
48
|
+
(max - min) * ((position - start) / length) * (ctx.reverse ? -1 : 1) * (ctx.orientation === "vertical" ? -1 : 1) / step
|
|
49
|
+
) * step,
|
|
50
|
+
ctx.max
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
const loseFocus = (e) => {
|
|
54
|
+
const target = e.target;
|
|
55
|
+
if (target !== ctx.trackElement || ctx.thumbElement && !target.contains(ctx.thumbElement))
|
|
56
|
+
ctx.dragging = false;
|
|
57
|
+
};
|
|
58
|
+
const handleMousedown = (e) => {
|
|
59
|
+
onMousedown?.(e);
|
|
60
|
+
if (disabled)
|
|
61
|
+
return;
|
|
62
|
+
ctx.dragging = true;
|
|
63
|
+
};
|
|
64
|
+
const handleClick = (e) => {
|
|
65
|
+
onClick?.(e);
|
|
66
|
+
if (disabled)
|
|
67
|
+
return;
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
ctx.dragging = true;
|
|
70
|
+
calculateValue(e);
|
|
71
|
+
ctx.dragging = false;
|
|
72
|
+
};
|
|
73
|
+
$effect(() => {
|
|
74
|
+
ctx.trackElement = self;
|
|
75
|
+
if (disabled || !ctx.trackElement)
|
|
76
|
+
return;
|
|
77
|
+
document.addEventListener("mousemove", calculateValue);
|
|
78
|
+
document.addEventListener("mouseup", loseFocus);
|
|
79
|
+
return () => {
|
|
80
|
+
document.removeEventListener("mousemove", calculateValue);
|
|
81
|
+
document.removeEventListener("mouseup", loseFocus);
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
$effect(() => {
|
|
85
|
+
ctx.updateProps({ min, max, disabled, orientation, reverse, step, value });
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<div
|
|
90
|
+
bind:this={self}
|
|
91
|
+
use:useActions={use}
|
|
92
|
+
id={ctx.uid()}
|
|
93
|
+
class={classProp(klass, state)}
|
|
94
|
+
tabindex="-1"
|
|
95
|
+
role="none"
|
|
96
|
+
data-slider=""
|
|
97
|
+
data-value={ctx.value}
|
|
98
|
+
data-percentage={ctx.Percentage}
|
|
99
|
+
data-reversed={ctx.reverse || undefined}
|
|
100
|
+
data-orientation={ctx.orientation}
|
|
101
|
+
onmousedown={handleMousedown}
|
|
102
|
+
onclick={handleClick}
|
|
103
|
+
{...props}
|
|
104
|
+
>
|
|
105
|
+
{@render children(state)}
|
|
106
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import { SliderContext } from './context.svelte.js';
|
|
3
|
+
export declare const context: () => SliderContext, contextName: string;
|
|
4
|
+
import type { SliderProps } from './types.js';
|
|
5
|
+
declare const __propDef: {
|
|
6
|
+
props: SliderProps;
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
};
|
|
12
|
+
type SliderProps_ = typeof __propDef.props;
|
|
13
|
+
export { SliderProps_ as SliderProps };
|
|
14
|
+
export type SliderEvents = typeof __propDef.events;
|
|
15
|
+
export type SliderSlots = typeof __propDef.slots;
|
|
16
|
+
export default class Slider extends SvelteComponent<SliderProps_, SliderEvents, SliderSlots> {
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<script lang="ts">import { classProp, useActions } from "../../internal/index.js";
|
|
2
|
+
import { context } from "./Slider.svelte";
|
|
3
|
+
let { use = [], class: klass, self = $bindable(), ...props } = $props();
|
|
4
|
+
const ctx = context();
|
|
5
|
+
const styles = $derived.by(() => {
|
|
6
|
+
const perc = `${ctx.Percentage}%`;
|
|
7
|
+
let obj = {};
|
|
8
|
+
if (ctx.orientation === "horizontal") {
|
|
9
|
+
obj = ctx.reverse ? { width: perc, right: "0" } : { width: perc, left: "0" };
|
|
10
|
+
} else if (ctx.orientation === "vertical") {
|
|
11
|
+
obj = ctx.reverse ? { height: perc, top: "0" } : { height: perc, bottom: "0" };
|
|
12
|
+
}
|
|
13
|
+
return Object.entries(obj).map(([k, v]) => `${k}:${v}`).join(";");
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<div
|
|
18
|
+
bind:this={self}
|
|
19
|
+
use:useActions={use}
|
|
20
|
+
id={ctx.uid('range')}
|
|
21
|
+
class={classProp(klass, { value: ctx.value, percentage: ctx.Percentage })}
|
|
22
|
+
tabindex="-1"
|
|
23
|
+
role="none"
|
|
24
|
+
data-slider=""
|
|
25
|
+
data-value={ctx.value}
|
|
26
|
+
data-percentage={ctx.Percentage}
|
|
27
|
+
data-reversed={ctx.reverse || undefined}
|
|
28
|
+
data-orientation={ctx.orientation}
|
|
29
|
+
style="position: absolute; {styles}"
|
|
30
|
+
{...props}
|
|
31
|
+
></div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { SliderRangeProps } from './types.js';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: SliderRangeProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
type SliderRangeProps_ = typeof __propDef.props;
|
|
11
|
+
export { SliderRangeProps_ as SliderRangeProps };
|
|
12
|
+
export type SliderRangeEvents = typeof __propDef.events;
|
|
13
|
+
export type SliderRangeSlots = typeof __propDef.slots;
|
|
14
|
+
export default class SliderRange extends SvelteComponent<SliderRangeProps_, SliderRangeEvents, SliderRangeSlots> {
|
|
15
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script lang="ts">import { ALL_ARROW_KEYS, KEYS, classProp, useActions } from "../../internal/index.js";
|
|
2
|
+
import { context } from "./Slider.svelte";
|
|
3
|
+
let { use = [], class: klass, self = $bindable(), onMousedown, onKeydown, ...props } = $props();
|
|
4
|
+
const ctx = context();
|
|
5
|
+
$effect(() => {
|
|
6
|
+
ctx.thumbElement = self;
|
|
7
|
+
});
|
|
8
|
+
const handleMousedown = (e) => {
|
|
9
|
+
onMousedown?.(e);
|
|
10
|
+
if (ctx.disabled)
|
|
11
|
+
return;
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
};
|
|
14
|
+
const handleKeydown = (e) => {
|
|
15
|
+
onKeydown?.(e);
|
|
16
|
+
if (ctx.disabled)
|
|
17
|
+
return;
|
|
18
|
+
const { key } = e;
|
|
19
|
+
if (ALL_ARROW_KEYS.includes(key))
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
if (key === KEYS.arrowRight || key === KEYS.arrowUp) {
|
|
22
|
+
if (ctx.reverse)
|
|
23
|
+
ctx.stepDown();
|
|
24
|
+
else
|
|
25
|
+
ctx.stepUp();
|
|
26
|
+
}
|
|
27
|
+
if (key === KEYS.arrowLeft || key === KEYS.arrowDown) {
|
|
28
|
+
if (ctx.reverse)
|
|
29
|
+
ctx.stepUp();
|
|
30
|
+
else
|
|
31
|
+
ctx.stepDown();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const styles = $derived.by(() => {
|
|
35
|
+
const perc = `${ctx.Percentage}%`;
|
|
36
|
+
let translate = "";
|
|
37
|
+
let obj = {};
|
|
38
|
+
if (ctx.orientation === "horizontal") {
|
|
39
|
+
obj = ctx.reverse ? { right: perc } : { left: perc };
|
|
40
|
+
translate = ctx.reverse ? "50%" : "-50%";
|
|
41
|
+
} else if (ctx.orientation === "vertical") {
|
|
42
|
+
obj = ctx.reverse ? { top: perc } : { bottom: perc };
|
|
43
|
+
translate = ctx.reverse ? "0 -50%" : "0 50%";
|
|
44
|
+
}
|
|
45
|
+
obj = { ...obj, translate };
|
|
46
|
+
return Object.entries(obj).map(([k, v]) => `${k}:${v}`).join(";");
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<div
|
|
51
|
+
bind:this={self}
|
|
52
|
+
use:useActions={use}
|
|
53
|
+
id={ctx.uid('thumb')}
|
|
54
|
+
class={classProp(klass, { value: ctx.value, percentage: ctx.Percentage })}
|
|
55
|
+
role="slider"
|
|
56
|
+
tabindex="0"
|
|
57
|
+
aria-valuenow={ctx.value}
|
|
58
|
+
aria-valuemin={ctx.min}
|
|
59
|
+
aria-valuemax={ctx.max}
|
|
60
|
+
data-sliderthumb=""
|
|
61
|
+
onmousedown={handleMousedown}
|
|
62
|
+
onkeydown={handleKeydown}
|
|
63
|
+
style="position: absolute; {styles}"
|
|
64
|
+
{...props}
|
|
65
|
+
></div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { SliderThumbProps } from './types.js';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: SliderThumbProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
type SliderThumbProps_ = typeof __propDef.props;
|
|
11
|
+
export { SliderThumbProps_ as SliderThumbProps };
|
|
12
|
+
export type SliderThumbEvents = typeof __propDef.events;
|
|
13
|
+
export type SliderThumbSlots = typeof __propDef.slots;
|
|
14
|
+
export default class SliderThumb extends SvelteComponent<SliderThumbProps_, SliderThumbEvents, SliderThumbSlots> {
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts">import { classProp, useActions } from "../../internal/index.js";
|
|
2
|
+
import { context } from "./Slider.svelte";
|
|
3
|
+
let { use = [], class: klass, self = $bindable(), ...props } = $props();
|
|
4
|
+
const ctx = context();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<input
|
|
8
|
+
type="range"
|
|
9
|
+
bind:this={self}
|
|
10
|
+
use:useActions={use}
|
|
11
|
+
id={ctx.uid('value')}
|
|
12
|
+
class={classProp(klass, { value: ctx.value, percentage: ctx.Percentage })}
|
|
13
|
+
min={ctx.min}
|
|
14
|
+
max={ctx.max}
|
|
15
|
+
step={ctx.step}
|
|
16
|
+
bind:value={ctx.value}
|
|
17
|
+
aria-hidden="false"
|
|
18
|
+
data-slidervalue=""
|
|
19
|
+
style="display: none"
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { SliderValueProps } from './types.js';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: SliderValueProps;
|
|
5
|
+
events: {
|
|
6
|
+
[evt: string]: CustomEvent<any>;
|
|
7
|
+
};
|
|
8
|
+
slots: {};
|
|
9
|
+
};
|
|
10
|
+
type SliderValueProps_ = typeof __propDef.props;
|
|
11
|
+
export { SliderValueProps_ as SliderValueProps };
|
|
12
|
+
export type SliderValueEvents = typeof __propDef.events;
|
|
13
|
+
export type SliderValueSlots = typeof __propDef.slots;
|
|
14
|
+
export default class SliderValue extends SvelteComponent<SliderValueProps_, SliderValueEvents, SliderValueSlots> {
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Context } from '../../internal/index.js';
|
|
2
|
+
interface Init {
|
|
3
|
+
value: number;
|
|
4
|
+
min: number;
|
|
5
|
+
max: number;
|
|
6
|
+
step: number;
|
|
7
|
+
orientation: 'horizontal' | 'vertical';
|
|
8
|
+
reverse: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface Hooks {
|
|
12
|
+
onChange: (value: number) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare class SliderContext extends Context<Hooks> {
|
|
15
|
+
#private;
|
|
16
|
+
min: number;
|
|
17
|
+
max: number;
|
|
18
|
+
step: number;
|
|
19
|
+
value: number;
|
|
20
|
+
orientation: "horizontal" | "vertical";
|
|
21
|
+
reverse: boolean;
|
|
22
|
+
disabled: boolean;
|
|
23
|
+
dragging: boolean;
|
|
24
|
+
Percentage: number;
|
|
25
|
+
trackElement: HTMLDivElement | undefined;
|
|
26
|
+
thumbElement: HTMLDivElement | undefined;
|
|
27
|
+
constructor(init: Init, hooks: Hooks);
|
|
28
|
+
stepUp(): void;
|
|
29
|
+
stepDown(): void;
|
|
30
|
+
updateProps(props: Init): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Context, clamp, effects } from '../../internal/index.js';
|
|
2
|
+
export class SliderContext extends Context {
|
|
3
|
+
min = $state(0);
|
|
4
|
+
max = $state(100);
|
|
5
|
+
step = $state(1);
|
|
6
|
+
value = $state(0);
|
|
7
|
+
orientation = $state('horizontal');
|
|
8
|
+
reverse = $state(false);
|
|
9
|
+
disabled = $state(false);
|
|
10
|
+
dragging = $state(false);
|
|
11
|
+
Percentage = $derived(Math.round(((this.value - this.min) / (this.max - this.min)) * 100));
|
|
12
|
+
trackElement = $state(undefined);
|
|
13
|
+
thumbElement = $state(undefined);
|
|
14
|
+
constructor(init, hooks) {
|
|
15
|
+
super('slider');
|
|
16
|
+
this.hooks = hooks;
|
|
17
|
+
this.min = init.min;
|
|
18
|
+
this.value = init.value;
|
|
19
|
+
this.max = init.max;
|
|
20
|
+
this.step = init.step;
|
|
21
|
+
this.orientation = init.orientation;
|
|
22
|
+
this.reverse = init.reverse;
|
|
23
|
+
this.disabled = init.disabled;
|
|
24
|
+
}
|
|
25
|
+
stepUp() {
|
|
26
|
+
this.value = clamp(this.min, (this.value += this.step), this.max);
|
|
27
|
+
}
|
|
28
|
+
stepDown() {
|
|
29
|
+
this.value = clamp(this.min, (this.value -= this.step), this.max);
|
|
30
|
+
}
|
|
31
|
+
updateProps(props) {
|
|
32
|
+
this.min = props.min;
|
|
33
|
+
this.value = props.value;
|
|
34
|
+
this.max = props.max;
|
|
35
|
+
this.step = props.step;
|
|
36
|
+
this.orientation = props.orientation;
|
|
37
|
+
this.reverse = props.reverse;
|
|
38
|
+
this.disabled = props.disabled;
|
|
39
|
+
}
|
|
40
|
+
#effects = effects(() => {
|
|
41
|
+
$effect(() => {
|
|
42
|
+
this.hooks?.onChange(this.value);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Slider } from './Slider.svelte';
|
|
2
|
+
export { default as SliderRange } from './SliderRange.svelte';
|
|
3
|
+
export { default as SliderThumb } from './SliderThumb.svelte';
|
|
4
|
+
export { default as SliderValue } from './SliderValue.svelte';
|
|
5
|
+
export type * from './types.js';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Handler, Props, PropsNoChildren } from '../../internal/index.js';
|
|
2
|
+
interface SliderState {
|
|
3
|
+
/** The current percentage of the slider, from 0-100. */
|
|
4
|
+
percentage: number;
|
|
5
|
+
/** The current value of the slider. */
|
|
6
|
+
value: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SliderProps extends Props<HTMLDivElement, SliderState> {
|
|
9
|
+
/** The value of the slider. */
|
|
10
|
+
value?: number;
|
|
11
|
+
/** The minimum value of the slider. */
|
|
12
|
+
min?: number;
|
|
13
|
+
/** The maximum value of the slider. */
|
|
14
|
+
max?: number;
|
|
15
|
+
/** The steps between each step of the value. */
|
|
16
|
+
step?: number;
|
|
17
|
+
/** The direction of the slider. */
|
|
18
|
+
orientation?: 'horizontal' | 'vertical';
|
|
19
|
+
/** Switch the direction the slider. */
|
|
20
|
+
reverse?: boolean;
|
|
21
|
+
/** Disables the slider. */
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
onMousedown?: Handler<MouseEvent, HTMLDivElement>;
|
|
24
|
+
onClick?: Handler<MouseEvent, HTMLDivElement>;
|
|
25
|
+
}
|
|
26
|
+
export interface SliderThumbProps extends PropsNoChildren<HTMLDivElement, SliderState> {
|
|
27
|
+
onMousedown?: Handler<MouseEvent, HTMLDivElement>;
|
|
28
|
+
onKeydown?: Handler<KeyboardEvent, HTMLDivElement>;
|
|
29
|
+
}
|
|
30
|
+
export interface SliderRangeProps extends PropsNoChildren<HTMLDivElement, SliderState> {
|
|
31
|
+
}
|
|
32
|
+
export interface SliderValueProps extends PropsNoChildren<HTMLInputElement> {
|
|
33
|
+
name: string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './components/Hovercard/index.js';
|
|
|
12
12
|
export * from './components/Portal/index.js';
|
|
13
13
|
export * from './components/Switch/index.js';
|
|
14
14
|
export * from './components/Toast/index.js';
|
|
15
|
+
export * from './components/Slider/index.js';
|
|
15
16
|
export * from './actions/portal.js';
|
|
16
17
|
export * from './actions/outside.js';
|
|
17
18
|
export * from './actions/trap.js';
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from './components/Hovercard/index.js';
|
|
|
12
12
|
export * from './components/Portal/index.js';
|
|
13
13
|
export * from './components/Switch/index.js';
|
|
14
14
|
export * from './components/Toast/index.js';
|
|
15
|
+
export * from './components/Slider/index.js';
|
|
15
16
|
export * from './actions/portal.js';
|
|
16
17
|
export * from './actions/outside.js';
|
|
17
18
|
export * from './actions/trap.js';
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
useFloating,
|
|
7
7
|
getTransition
|
|
8
8
|
} from "../index.js";
|
|
9
|
-
import { useOutside } from "../../actions/outside.js";
|
|
10
|
-
import { usePortal } from "../../actions/portal.js";
|
|
9
|
+
import { useOutside } from "../../index.js/actions/outside.js";
|
|
10
|
+
import { usePortal } from "../../index.js/actions/portal.js";
|
|
11
11
|
let {
|
|
12
12
|
children,
|
|
13
13
|
class: klass,
|
|
@@ -18,6 +18,7 @@ export const KEYS = {
|
|
|
18
18
|
backspace: 'Backspace'
|
|
19
19
|
};
|
|
20
20
|
export const ALL_KEYS = Object.values(KEYS);
|
|
21
|
+
export const ALL_ARROW_KEYS = [KEYS.arrowUp, KEYS.arrowDown, KEYS.arrowLeft, KEYS.arrowRight];
|
|
21
22
|
export const PREVENT_KEYS = [
|
|
22
23
|
KEYS.arrowUp,
|
|
23
24
|
KEYS.arrowDown,
|
|
@@ -46,3 +46,10 @@ export declare const parseDelay: (delay: number | [number, number]) => {
|
|
|
46
46
|
* @param value The value to be transformed.
|
|
47
47
|
*/
|
|
48
48
|
export declare const parseDuration: (value: number | string) => number;
|
|
49
|
+
/**
|
|
50
|
+
* Restrict a number value between 2 values.
|
|
51
|
+
* @param min The minimun value of the number.
|
|
52
|
+
* @param value The value to be clamped.
|
|
53
|
+
* @param max The maximum value of the number.
|
|
54
|
+
*/
|
|
55
|
+
export declare const clamp: (min: number, value: number, max: number) => number;
|
|
@@ -103,3 +103,12 @@ export const parseDuration = (value) => {
|
|
|
103
103
|
return duration;
|
|
104
104
|
return duration * 1000;
|
|
105
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Restrict a number value between 2 values.
|
|
108
|
+
* @param min The minimun value of the number.
|
|
109
|
+
* @param value The value to be clamped.
|
|
110
|
+
* @param max The maximum value of the number.
|
|
111
|
+
*/
|
|
112
|
+
export const clamp = (min, value, max) => {
|
|
113
|
+
return Math.max(min, Math.min(value, max));
|
|
114
|
+
};
|