File size: 1,241 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import { createBitAttrs, getOptionUpdater } from "../../internal/index.js";
import { createRadioGroup } from "@melt-ui/svelte";
import { getContext, setContext } from "svelte";
import { removeUndefined } from "../../internal/index.js";
function getRadioGroupData() {
const NAME = "radio-group";
const ITEM_NAME = "radio-group-item";
const PARTS = ["root", "item", "input", "item-indicator"];
return {
NAME,
ITEM_NAME,
PARTS,
};
}
export function setCtx(props) {
const { NAME, PARTS } = getRadioGroupData();
const getAttrs = createBitAttrs(NAME, PARTS);
const radioGroup = { ...createRadioGroup(removeUndefined(props)), getAttrs };
setContext(NAME, radioGroup);
return {
...radioGroup,
updateOption: getOptionUpdater(radioGroup.options),
};
}
export function getCtx() {
const { NAME } = getRadioGroupData();
return getContext(NAME);
}
export function setItemCtx(value) {
const { ITEM_NAME } = getRadioGroupData();
const radioGroup = { ...getCtx(), value };
setContext(ITEM_NAME, radioGroup);
return radioGroup;
}
export function getRadioIndicator() {
const { ITEM_NAME } = getRadioGroupData();
return getContext(ITEM_NAME);
}
|