Skip to content

Commit

Permalink
refactor radio group
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Aug 3, 2023
1 parent caa517e commit 8a5cba7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<RadioGroup.Item value="compact" id="r3" />
<Label for="r3">Compact</Label>
</div>
<RadioGroup.Input name="spacing" />
</RadioGroup>
10 changes: 10 additions & 0 deletions apps/www/src/lib/components/ui/radio-group/RadioGroupInput.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import type { HTMLInputAttributes } from "svelte/elements";
import { ctx, melt } from ".";
const input = ctx.getInput();
type $$Props = HTMLInputAttributes;
</script>

<input use:melt={$input} hidden {...$$restProps} />
5 changes: 3 additions & 2 deletions apps/www/src/lib/components/ui/radio-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Item from "./RadioGroupItem.svelte";
import Input from "./RadioGroupInput.svelte";

type ObjectVariation<T> = T extends object ? T : never;
export type RadioGroupItemProps = ObjectVariation<ItemProps>;
const NAME = "radiogroup";

export const ctx = {
set,
get,
getItem
getItem,
getInput: () => get().elements.itemInput
};

function set(props: RadioGroupProps) {
Expand All @@ -42,6 +42,7 @@ function getItem() {
}

export { melt, RadioGroupProps };
export type RadioGroupItemProps = ObjectVariation<ItemProps>;
export const RadioGroup = Object.assign(Root, {
Item,
Input
Expand Down

0 comments on commit 8a5cba7

Please sign in to comment.