-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add radio button component #23
Open
ashleysyg
wants to merge
7
commits into
main
Choose a base branch
from
feat-radio-btn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4aeace
feat: basic radio button test
6b19a95
fnctions to update state for radio button group
71913d5
formatted hover/focus/checked/disabled
a08c09c
abstract radio btn attributes from toy data
1521c60
refactor: change hardcoded data to prop
f976385
fix: radio button group name change
2d10ce7
remove test radio button from home
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 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,36 @@ | ||
'use client' | ||
|
||
// https://tailwindui.com/components/application-ui/forms/radio-groups | ||
|
||
import { useState } from 'react' | ||
|
||
export default function RadioButtonGroup({ options }: { options: {id: string}[] }) { | ||
|
||
const [selectedOption, setSelectedOption] = useState(options[0].id) | ||
|
||
function onValueChange(event: any){ | ||
setSelectedOption(event.target.value) | ||
} | ||
|
||
return ( | ||
<div> | ||
{options.map((option) => ( | ||
<div key={option.id} className="flex items-center"> | ||
<input | ||
type="radio" | ||
id={option.id} | ||
name="group" | ||
value={option.id} | ||
className="flex items-center relative size-4 appearance-none rounded-full form-radio text-primary-500 border border-gray-300 bg-white before:absolute before:inset-1 before:rounded-full before:bg-white checked:border-primary-500 checked:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 focus-visible:ring focus:ring-primary-500 disabled:border-gray-300 disabled:bg-gray-100 disabled:before:bg-gray-400 forced-colors:appearance-auto forced-colors:before:hidden [&:not(:checked)]:before:hidden" | ||
checked={selectedOption === option.id} | ||
onChange={onValueChange} | ||
> | ||
</input> | ||
<label htmlFor={option.id} className="ml-3 text-md/6 text-neutral-900">{option.id[0].toUpperCase() + option.id.slice(1)}</label> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
// export default RadioButtonGroup | ||
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 |
---|---|---|
|
@@ -25,7 +25,8 @@ | |
"@/*": [ | ||
"./*" | ||
] | ||
} | ||
}, | ||
"target": "ES2017" | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
|
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.
Remove comment