-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
189 changed files
with
1,257 additions
and
822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"bits-ui": patch | ||
--- | ||
|
||
fix: issues with tree shaking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,61 @@ | ||
import { | ||
createAccordion, | ||
type Accordion as AccordionReturn, | ||
type CreateAccordionProps | ||
} from "@melt-ui/svelte"; | ||
import { createAccordion, type CreateAccordionProps } from "@melt-ui/svelte"; | ||
import { getContext, setContext } from "svelte"; | ||
import type { ItemProps } from "./types.js"; | ||
import { createBitAttrs, getOptionUpdater, removeUndefined } from "$lib/internal/index.js"; | ||
|
||
const NAME = "accordion"; | ||
const ITEM_NAME = "accordion-item"; | ||
const PARTS = ["root", "content", "header", "item", "trigger"] as const; | ||
function getAccordionData() { | ||
const NAME = "accordion" as const; | ||
const ITEM_NAME = "accordion-item"; | ||
const PARTS = ["root", "content", "header", "item", "trigger"] as const; | ||
|
||
export const getAttrs = createBitAttrs(NAME, PARTS); | ||
|
||
type GetReturn = AccordionReturn; | ||
return { NAME, ITEM_NAME, PARTS }; | ||
} | ||
|
||
export function setCtx<Multiple extends boolean>(props: CreateAccordionProps<Multiple>) { | ||
const accordion = createAccordion(removeUndefined(props)); | ||
setContext(NAME, accordion); | ||
return { | ||
...accordion, | ||
updateOption: getOptionUpdater(accordion.options) | ||
const initAccordion = createAccordion(removeUndefined(props)); | ||
const { NAME, PARTS } = getAccordionData(); | ||
const getAttrs = createBitAttrs(NAME, PARTS); | ||
const accordion = { | ||
...initAccordion, | ||
getAttrs, | ||
updateOption: getOptionUpdater(initAccordion.options) | ||
}; | ||
|
||
setContext(NAME, accordion); | ||
return accordion; | ||
} | ||
|
||
export function getCtx() { | ||
return getContext<GetReturn>(NAME); | ||
const { NAME } = getAccordionData(); | ||
return getContext<ReturnType<typeof setCtx>>(NAME); | ||
} | ||
|
||
export function setItem(props: ItemProps) { | ||
const { ITEM_NAME } = getAccordionData(); | ||
setContext(ITEM_NAME, { ...props }); | ||
const { | ||
elements: { item } | ||
} = getCtx(); | ||
return { item, props }; | ||
const ctx = getCtx(); | ||
return { ...ctx, props }; | ||
} | ||
|
||
export function getItemProps() { | ||
const itemProps = getContext<ItemProps>(ITEM_NAME); | ||
return itemProps; | ||
const { ITEM_NAME } = getAccordionData(); | ||
return getContext<ItemProps>(ITEM_NAME); | ||
} | ||
|
||
export function getContent() { | ||
const { | ||
elements: { content }, | ||
helpers: { isSelected }, | ||
states: { value } | ||
} = getCtx(); | ||
const ctx = getCtx(); | ||
const { value: props } = getItemProps(); | ||
return { content, props, isSelected, value }; | ||
return { | ||
...ctx, | ||
props | ||
}; | ||
} | ||
|
||
export function getTrigger() { | ||
const { | ||
elements: { trigger } | ||
} = getCtx(); | ||
const ctx = getCtx(); | ||
const { value, disabled } = getItemProps(); | ||
return { props: { value, disabled }, trigger }; | ||
return { | ||
...ctx, | ||
props: { value, disabled } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.