Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Apr 12, 2024
1 parent bbf105b commit 07be7f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
value = $bindable(),
el = $bindable(),
id,
onValueChange,
...restProps
}: AccordionRootProps = $props();
const rootState = setAccordionRootState({ type, value });
const rootState = setAccordionRootState({ type, value, id, onValueChange });
$effect.pre(() => {
if (value !== undefined) {
Expand Down
17 changes: 14 additions & 3 deletions packages/bits-ui/src/lib/bits/accordion/state.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
* BASE
*/
interface AccordionBaseStateProps {
id?: string;
id?: string | null;
disabled?: boolean;
forceVisible?: boolean;
}
Expand Down Expand Up @@ -47,6 +47,7 @@ class AccordionBaseState {
interface AccordionSingleStateProps extends AccordionBaseStateProps {
value?: string;
onValueChange?: OnChangeFn<string>;
id?: string | null;
}

export class AccordionSingleState extends AccordionBaseState {
Expand Down Expand Up @@ -295,13 +296,23 @@ type AccordionState = AccordionSingleState | AccordionMultiState;
type InitAccordionProps = {
type: "single" | "multiple";
value?: string | string[];
id?: string | null;
onValueChange?: OnChangeFn<string> | OnChangeFn<string[]>;
};

export function setAccordionRootState(props: InitAccordionProps) {
const rootState =
props.type === "single"
? new AccordionSingleState({ value: props.value as string })
: new AccordionMultiState({ value: props.value as string[] });
? new AccordionSingleState({
value: props.value as string,
id: props.id,
onValueChange: props.onValueChange as OnChangeFn<string>,
})
: new AccordionMultiState({
value: props.value as string[],
id: props.id,
onValueChange: props.onValueChange as OnChangeFn<string[]>,
});
setContext(ACCORDION_ROOT_KEY, rootState);
return rootState;
}
Expand Down

0 comments on commit 07be7f5

Please sign in to comment.