This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { ProgressRootProps } from "../types.js";
|
||||
import { ProgressRootState } from "../progress.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
child,
|
||||
children,
|
||||
value = 0,
|
||||
max = 100,
|
||||
min = 0,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
...restProps
|
||||
}: ProgressRootProps = $props();
|
||||
|
||||
const rootState = ProgressRootState.create({
|
||||
value: boxWith(() => value),
|
||||
max: boxWith(() => max),
|
||||
min: boxWith(() => min),
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { ProgressRootProps } from "../types.js";
|
||||
declare const Progress: import("svelte").Component<ProgressRootProps, {}, "ref">;
|
||||
type Progress = ReturnType<typeof Progress>;
|
||||
export default Progress;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { default as Root } from "./components/progress.svelte";
|
||||
export type { ProgressRootProps as RootProps } from "./types.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { default as Root } from "./components/progress.svelte";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * as Progress from "./exports.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * as Progress from "./exports.js";
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { type ReadableBoxedValues } from "svelte-toolbelt";
|
||||
import type { RefAttachment, WithRefOpts } from "../../internal/types.js";
|
||||
interface ProgressRootStateOpts extends WithRefOpts, ReadableBoxedValues<{
|
||||
value: number | null;
|
||||
max: number;
|
||||
min: number;
|
||||
}> {
|
||||
}
|
||||
export declare class ProgressRootState {
|
||||
static create(opts: ProgressRootStateOpts): ProgressRootState;
|
||||
readonly opts: ProgressRootStateOpts;
|
||||
readonly attachment: RefAttachment;
|
||||
constructor(opts: ProgressRootStateOpts);
|
||||
readonly props: {
|
||||
readonly role: "progressbar";
|
||||
readonly value: number | null;
|
||||
readonly "aria-valuemin": number;
|
||||
readonly "aria-valuemax": number;
|
||||
readonly "aria-valuenow": number | undefined;
|
||||
readonly "data-value": number | undefined;
|
||||
readonly "data-state": "indeterminate" | "loading" | "loaded";
|
||||
readonly "data-max": number;
|
||||
readonly "data-min": number;
|
||||
readonly "data-indeterminate": "" | undefined;
|
||||
};
|
||||
}
|
||||
export {};
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import { attachRef } from "svelte-toolbelt";
|
||||
import { createBitsAttrs } from "../../internal/attrs.js";
|
||||
const progressAttrs = createBitsAttrs({
|
||||
component: "progress",
|
||||
parts: ["root"],
|
||||
});
|
||||
export class ProgressRootState {
|
||||
static create(opts) {
|
||||
return new ProgressRootState(opts);
|
||||
}
|
||||
opts;
|
||||
attachment;
|
||||
constructor(opts) {
|
||||
this.opts = opts;
|
||||
this.attachment = attachRef(this.opts.ref);
|
||||
}
|
||||
props = $derived.by(() => ({
|
||||
role: "progressbar",
|
||||
value: this.opts.value.current,
|
||||
"aria-valuemin": this.opts.min.current,
|
||||
"aria-valuemax": this.opts.max.current,
|
||||
"aria-valuenow": this.opts.value.current === null ? undefined : this.opts.value.current,
|
||||
"data-value": this.opts.value.current === null ? undefined : this.opts.value.current,
|
||||
"data-state": getProgressDataState(this.opts.value.current, this.opts.max.current),
|
||||
"data-max": this.opts.max.current,
|
||||
"data-min": this.opts.min.current,
|
||||
"data-indeterminate": this.opts.value.current === null ? "" : undefined,
|
||||
[progressAttrs.root]: "",
|
||||
...this.attachment,
|
||||
}));
|
||||
}
|
||||
function getProgressDataState(value, max) {
|
||||
if (value === null)
|
||||
return "indeterminate";
|
||||
return value === max ? "loaded" : "loading";
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import type { WithChild, Without } from "../../internal/types.js";
|
||||
import type { BitsPrimitiveDivAttributes } from "../../shared/attributes.js";
|
||||
export type ProgressRootPropsWithoutHTML = WithChild<{
|
||||
/**
|
||||
* The current value of the progress bar.
|
||||
* If `null`, the progress bar will be in an indeterminate state.
|
||||
*
|
||||
* @default 0
|
||||
*/
|
||||
value?: number | null;
|
||||
/**
|
||||
* The maximum value of the progress bar.
|
||||
*
|
||||
* @default 100
|
||||
*/
|
||||
max?: number;
|
||||
/**
|
||||
* The minimum value of the progress bar.
|
||||
*
|
||||
* @default 0
|
||||
*/
|
||||
min?: number;
|
||||
}>;
|
||||
export type ProgressRootProps = ProgressRootPropsWithoutHTML & Without<BitsPrimitiveDivAttributes, ProgressRootPropsWithoutHTML>;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user