Skip to content

Commit

Permalink
slider stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 12, 2024
1 parent 493ce02 commit f2c1273
Show file tree
Hide file tree
Showing 21 changed files with 1,203 additions and 394 deletions.
25 changes: 25 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Bits UI
=================
The following is a list of sources from which code was used/modified in this codebase.

-------------------------------------------------------------------------------
This codebase contains a modified portion of code from Adobe which can be obtained at:
* SOURCE:
* https://www.npmjs.com/package/@react-aria/utils
* LICENSE:
* https://unpkg.com/@react-aria/utils@3.24.1/LICENSE

* SOURCE:
* https://www.npmjs.com/package/react-stately
* LICENSE:
* https://unpkg.com/react-stately@3.31.1/LICENSE

-------------------------------------------------------------------------------

This codebase contains a modified portion of code from Melt UI which can be obtained at:
* SOURCE:
* https://www.npmjs.com/package/@melt-ui/svelte
* LICENSE:
* https://unpkg.com/@melt-ui/svelte@0.76.2/LICENSE

-------------------------------------------------------------------------------
93 changes: 41 additions & 52 deletions packages/bits-ui/src/lib/bits/accordion/accordion.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type Box,
type ReadableBoxedValues,
type WithRefProps,
type WritableBoxedValues,
afterTick,
getAriaDisabled,
Expand All @@ -25,15 +26,13 @@ const ACCORDION_HEADER_ATTR = "data-accordion-header";
// BASE
//

type AccordionBaseStateProps = ReadableBoxedValues<{
id: string;
disabled: boolean;
orientation: Orientation;
loop: boolean;
}> &
WritableBoxedValues<{
ref: HTMLElement | null;
}>;
type AccordionBaseStateProps = WithRefProps<
ReadableBoxedValues<{
disabled: boolean;
orientation: Orientation;
loop: boolean;
}>
>;

class AccordionBaseState {
#id: AccordionBaseStateProps["id"];
Expand Down Expand Up @@ -130,15 +129,14 @@ export class AccordionMultiState extends AccordionBaseState {
// ITEM
//

type AccordionItemStateProps = ReadableBoxedValues<{
value: string;
disabled: boolean;
id: string;
}> & {
rootState: AccordionState;
} & WritableBoxedValues<{
ref: HTMLElement | null;
}>;
type AccordionItemStateProps = WithRefProps<
ReadableBoxedValues<{
value: string;
disabled: boolean;
}> & {
rootState: AccordionState;
}
>;

export class AccordionItemState {
#id: AccordionItemStateProps["id"];
Expand Down Expand Up @@ -190,13 +188,11 @@ export class AccordionItemState {
// TRIGGER
//

type AccordionTriggerStateProps = ReadableBoxedValues<{
disabled: boolean;
id: string;
}> &
WritableBoxedValues<{
ref: HTMLElement | null;
}>;
type AccordionTriggerStateProps = WithRefProps<
ReadableBoxedValues<{
disabled: boolean;
}>
>;

class AccordionTriggerState {
#ref: AccordionTriggerStateProps["ref"];
Expand Down Expand Up @@ -259,14 +255,11 @@ class AccordionTriggerState {
// CONTENT
//

type AccordionContentStateProps = ReadableBoxedValues<{
forceMount: boolean;
id: string;
}> &
WritableBoxedValues<{
ref: HTMLElement | null;
}>;

type AccordionContentStateProps = WithRefProps<
ReadableBoxedValues<{
forceMount: boolean;
}>
>;
class AccordionContentState {
item: AccordionItemState;
#ref: AccordionContentStateProps["ref"];
Expand Down Expand Up @@ -348,13 +341,11 @@ class AccordionContentState {
);
}

type AccordionHeaderStateProps = ReadableBoxedValues<{
level: 1 | 2 | 3 | 4 | 5 | 6;
id: string;
}> &
WritableBoxedValues<{
ref: HTMLElement | null;
}>;
type AccordionHeaderStateProps = WithRefProps<
ReadableBoxedValues<{
level: 1 | 2 | 3 | 4 | 5 | 6;
}>
>;

class AccordionHeaderState {
#id: AccordionHeaderStateProps["id"];
Expand Down Expand Up @@ -394,18 +385,16 @@ class AccordionHeaderState {

type AccordionState = AccordionSingleState | AccordionMultiState;

type InitAccordionProps = {
type: "single" | "multiple";
value: Box<string> | Box<string[]>;
} & ReadableBoxedValues<{
id: string;
disabled: boolean;
orientation: Orientation;
loop: boolean;
}> &
WritableBoxedValues<{
ref: HTMLElement | null;
}>;
type InitAccordionProps = WithRefProps<
{
type: "single" | "multiple";
value: Box<string> | Box<string[]>;
} & ReadableBoxedValues<{
disabled: boolean;
orientation: Orientation;
loop: boolean;
}>
>;

const [setAccordionRootContext, getAccordionRootContext] =
createContext<AccordionState>("Accordion.Root");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { box } from "svelte-toolbelt";
import type { CancelProps } from "../index.js";
import { useAlertDialogCancel } from "$lib/bits/date-range-picker/dialog/dialog.svelte.js";
import { useAlertDialogCancel } from "$lib/bits/dialog/dialog.svelte.js";
import { useId } from "$lib/internal/useId.svelte.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { useId } from "$lib/internal/useId.svelte.js";
import { noop } from "$lib/internal/callbacks.js";
import ScrollLock from "$lib/bits/utilities/scroll-lock/scroll-lock.svelte";
import { useDialogContent } from "$lib/bits/date-range-picker/dialog/dialog.svelte.js";
import { useDialogContent } from "$lib/bits/dialog/dialog.svelte.js";
let {
id = useId(),
Expand Down

This file was deleted.

42 changes: 24 additions & 18 deletions packages/bits-ui/src/lib/bits/slider/components/slider-range.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
import { getCtx } from "../ctx.js";
import { box } from "svelte-toolbelt";
import type { RangeProps } from "../index.js";
import { useSliderRange } from "../slider.svelte.js";
import { useId } from "$lib/internal/useId.svelte.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
type $$Props = RangeProps;
let {
children,
child,
ref = $bindable(null),
id = useId(),
...restProps
}: RangeProps = $props();
export let asChild: $$Props["asChild"] = false;
export let el: $$Props["el"] = undefined;
const {
elements: { range },
getAttrs,
} = getCtx();
const attrs = getAttrs("range");
$: builder = $range;
$: Object.assign(builder, attrs);
const rangeState = useSliderRange({
id: box.with(() => id),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, rangeState.props));
</script>

{#if asChild}
<slot {builder} />
{#if child}
{@render child?.({ props: mergedProps })}
{:else}
<span bind:this={ref} use:melt={builder} {...$$restProps} />
<span {...mergedProps}>
{@render children?.()}
</span>
{/if}
48 changes: 29 additions & 19 deletions packages/bits-ui/src/lib/bits/slider/components/slider-thumb.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
import { getCtx } from "../ctx.js";
import type { ThumbEvents, ThumbProps } from "../index.js";
import { createDispatcher } from "$lib/internal/events.js";
import { box } from "svelte-toolbelt";
import type { ThumbProps } from "../index.js";
import { useSliderThumb } from "../slider.svelte.js";
import { useId } from "$lib/internal/useId.svelte.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
type $$Props = ThumbProps;
type $$Events = ThumbEvents;
let {
children,
child,
ref = $bindable(null),
id = useId(),
index,
disabled = false,
...restProps
}: ThumbProps = $props();
export let asChild: $$Props["asChild"] = false;
export let el: $$Props["el"] = undefined;
export let thumb: $$Props["thumb"];
const thumbState = useSliderThumb({
id: box.with(() => id),
ref: box.with(
() => ref,
(v) => (ref = v)
),
index: box.with(() => index),
disabled: box.with(() => disabled),
});
const { getAttrs } = getCtx();
const dispatch = createDispatcher();
const attrs = getAttrs("thumb");
$: builder = thumb;
$: Object.assign(builder, attrs);
const mergedProps = $derived(mergeProps(restProps, thumbState.props));
</script>

{#if asChild}
<slot {builder} />
{#if child}
{@render child?.({ props: mergedProps })}
{:else}
<span bind:this={ref} use:melt={builder} {...$$restProps} on:m-keydown={dispatch} />
<span {...mergedProps}>
{@render children?.()}
</span>
{/if}
39 changes: 24 additions & 15 deletions packages/bits-ui/src/lib/bits/slider/components/slider-tick.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
import { getCtx } from "../ctx.js";
import { box } from "svelte-toolbelt";
import type { TickProps } from "../index.js";
import { useSliderTick } from "../slider.svelte.js";
import { useId } from "$lib/internal/useId.svelte.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
type $$Props = TickProps;
let {
children,
child,
ref = $bindable(null),
id = useId(),
index,
...restProps
}: TickProps = $props();
export let asChild: $$Props["asChild"] = false;
export let el: $$Props["el"] = undefined;
export let tick: $$Props["tick"];
const tickState = useSliderTick({
id: box.with(() => id),
ref: box.with(
() => ref,
(v) => (ref = v)
),
index: box.with(() => index),
});
const { getAttrs } = getCtx();
const attrs = getAttrs("tick");
$: builder = tick;
$: Object.assign(builder, attrs);
const mergedProps = $derived(mergeProps(restProps, tickState.props));
</script>

{#if asChild}
<slot {builder} />
{#if child}
{@render child?.({ props: mergedProps })}
{:else}
<span bind:this={ref} use:melt={builder} {...$$restProps} />
<span {...mergedProps}>{@render children?.()}</span>
{/if}
Loading

0 comments on commit f2c1273

Please sign in to comment.