-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/radio input #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/radio input #176
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
250dba1
feat: added a radio button custom
Sahil2004 f8720aa
docs: added name option in docs.
Sahil2004 dcdd7d4
fix: merge conflict.
Sahil2004 4249ed2
chore: cleaned the unnecessary classes and variables for input type r…
Sahil2004 504be58
fix: moved input radio to its own component.
Sahil2004 eb442b6
fix: keydown events added.
Sahil2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,54 +1,62 @@ | ||
import { Input } from '..'; | ||
import { Input } from ".."; | ||
|
||
export default { | ||
title: 'UI/Input', | ||
component: Input, | ||
tags: ['autodocs'], | ||
render: (args: { type: string; placeholder: string }) => ({ | ||
Component: Input, | ||
props: args | ||
}) | ||
title: "UI/Input", | ||
component: Input, | ||
tags: ["autodocs"], | ||
render: (args: { type: string; placeholder: string }) => ({ | ||
Component: Input, | ||
props: args, | ||
}), | ||
}; | ||
|
||
export const Text = { | ||
args: { | ||
type: 'text', | ||
placeholder: 'Joe Biden' | ||
} | ||
args: { | ||
type: "text", | ||
placeholder: "Joe Biden", | ||
}, | ||
}; | ||
|
||
export const Tel = { | ||
args: { | ||
type: 'tel', | ||
placeholder: '987654321' | ||
} | ||
args: { | ||
type: "tel", | ||
placeholder: "987654321", | ||
}, | ||
}; | ||
|
||
export const NumberInput = { | ||
args: { | ||
type: 'number', | ||
placeholder: 'Enter something' | ||
} | ||
args: { | ||
type: "number", | ||
placeholder: "Enter something", | ||
}, | ||
}; | ||
|
||
export const Email = { | ||
args: { | ||
type: 'email', | ||
placeholder: '[email protected]' | ||
} | ||
args: { | ||
type: "email", | ||
placeholder: "[email protected]", | ||
}, | ||
}; | ||
|
||
export const Invalid = { | ||
args: { | ||
type: 'email', | ||
placeholder: 'Invalid email', | ||
value: 'not-an-email' | ||
} | ||
args: { | ||
type: "email", | ||
placeholder: "Invalid email", | ||
value: "not-an-email", | ||
}, | ||
}; | ||
|
||
export const Password = { | ||
args: { | ||
type: 'password', | ||
placeholder: 'Please enter password' | ||
} | ||
args: { | ||
type: "password", | ||
placeholder: "Please enter password", | ||
}, | ||
}; | ||
|
||
export const Radio = { | ||
args: { | ||
type: "radio", | ||
value: "option1", | ||
name: "option-1", | ||
}, | ||
}; |
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
platforms/metagram/src/lib/ui/InputRadio/InputRadio.stories.ts
This file contains hidden or 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,19 @@ | ||
import { InputRadio } from ".."; | ||
|
||
export default { | ||
title: "UI/InputRadio", | ||
component: InputRadio, | ||
tags: ["autodocs"], | ||
render: (args: { type: string; placeholder: string }) => ({ | ||
Component: InputRadio, | ||
props: args, | ||
}), | ||
}; | ||
|
||
export const Radio = { | ||
args: { | ||
type: "radio", | ||
value: "option1", | ||
name: "option-1", | ||
}, | ||
}; |
53 changes: 53 additions & 0 deletions
53
platforms/metagram/src/lib/ui/InputRadio/InputRadio.svelte
This file contains hidden or 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,53 @@ | ||
<script lang="ts"> | ||
import { cn } from '$lib/utils'; | ||
import type { HTMLAttributes } from 'svelte/elements'; | ||
|
||
interface IInputRadioProps extends HTMLAttributes<HTMLElement> { | ||
selected?: string; | ||
name?: string; | ||
value: string; | ||
} | ||
|
||
let { | ||
value = '', | ||
selected = $bindable(''), | ||
name = '', | ||
...restProps | ||
}: IInputRadioProps = $props(); | ||
|
||
let radioElement: HTMLInputElement | null = $state(null); | ||
|
||
const cbase = | ||
"before:h-4.5 before:w-4.5 before:border-brand-burnt-orange before:-left-0.75 before:-bottom-0.25 relative before:absolute before:rounded-full before:border-2 before:bg-white before:content-['']"; | ||
</script> | ||
|
||
<input | ||
{...restProps} | ||
type="radio" | ||
{value} | ||
bind:group={selected} | ||
bind:this={radioElement} | ||
{name} | ||
checked={selected === value} | ||
class={cn(['hidden', restProps.class].join(' '))} | ||
/> | ||
|
||
<span | ||
{...restProps} | ||
class={cn([cbase, restProps.class].join(' '))} | ||
role="radio" | ||
tabindex="0" | ||
aria-checked={selected === value} | ||
onclick={() => radioElement?.click()} | ||
onkeydown={(e) => { | ||
if (e.key === ' ' || e.key === 'Enter') { | ||
e.preventDefault(); | ||
radioElement?.click(); | ||
} | ||
}} | ||
> | ||
{#if selected === value} | ||
<span class="bg-brand-burnt-orange bottom-0.75 left-0.25 absolute h-2.5 w-2.5 rounded-full" | ||
></span> | ||
{/if} | ||
</span> |
This file contains hidden or 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,7 +1,8 @@ | ||
export { default as Button } from './Button/Button.svelte'; | ||
export { default as Avatar } from './Avatar/Avatar.svelte'; | ||
export { default as Input } from './Input/Input.svelte'; | ||
export { default as Select } from './Select/Select.svelte'; | ||
export { default as Label } from './Label/Label.svelte'; | ||
export { default as Toggle } from './Toggle/Toggle.svelte'; | ||
export { default as Helper } from './Helper/Helper.svelte'; | ||
export { default as Button } from "./Button/Button.svelte"; | ||
export { default as Avatar } from "./Avatar/Avatar.svelte"; | ||
export { default as Input } from "./Input/Input.svelte"; | ||
export { default as Select } from "./Select/Select.svelte"; | ||
export { default as Label } from "./Label/Label.svelte"; | ||
export { default as Toggle } from "./Toggle/Toggle.svelte"; | ||
export { default as Helper } from "./Helper/Helper.svelte"; | ||
export { default as InputRadio } from "./InputRadio/InputRadio.svelte"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve interface type specificity.
The interface extends
HTMLAttributes<HTMLElement>
but the component renders bothinput
andspan
elements with different attribute requirements. This could lead to type safety issues.Consider creating a more specific interface:
📝 Committable suggestion
🤖 Prompt for AI Agents