generated from github/codespaces-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggle switch and toggle button options components
* **ToggleSwitch.module.css**: Add styles for the toggle switch component * **ToggleSwitch.tsx**: Add a new toggle switch component and use the styles from `ToggleSwitch.module.css` * **ToggleButtonOptions.module.css**: Add styles for the toggle button options component * **ToggleButtonOptions.tsx**: Add a new toggle button options component and use the styles from `ToggleButtonOptions.module.css` * **index.tsx**: Import and use the new toggle switch and toggle button options components
- Loading branch information
1 parent
3d0a8fd
commit 0a2d189
Showing
5 changed files
with
147 additions
and
0 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,15 @@ | ||
.toggleButtonOptions { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} | ||
|
||
.toggleButton { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
} | ||
|
||
.toggleButton input { | ||
margin-right: 10px; | ||
} |
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,34 @@ | ||
import { FC, ChangeEvent } from 'react'; | ||
import styles from './ToggleButtonOptions.module.css'; | ||
|
||
interface ToggleButtonOption { | ||
label: string; | ||
value: string; | ||
} | ||
|
||
interface ToggleButtonOptionsProps { | ||
options: ToggleButtonOption[]; | ||
selectedValue: string; | ||
onChange: (event: ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
const ToggleButtonOptions: FC<ToggleButtonOptionsProps> = ({ options, selectedValue, onChange }) => { | ||
return ( | ||
<div className={styles.toggleButtonOptions}> | ||
{options.map((option) => ( | ||
<label key={option.value} className={styles.toggleButton}> | ||
<input | ||
type="radio" | ||
name="toggleButtonOption" | ||
value={option.value} | ||
checked={selectedValue === option.value} | ||
onChange={onChange} | ||
/> | ||
{option.label} | ||
</label> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ToggleButtonOptions; |
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,44 @@ | ||
.toggleSwitch { | ||
position: relative; | ||
display: inline-block; | ||
width: 60px; | ||
height: 34px; | ||
} | ||
|
||
.toggleSwitch input { | ||
opacity: 0; | ||
width: 0; | ||
height: 0; | ||
} | ||
|
||
.slider { | ||
position: absolute; | ||
cursor: pointer; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: #ccc; | ||
transition: 0.4s; | ||
border-radius: 34px; | ||
} | ||
|
||
.slider:before { | ||
position: absolute; | ||
content: ""; | ||
height: 26px; | ||
width: 26px; | ||
left: 4px; | ||
bottom: 4px; | ||
background-color: white; | ||
transition: 0.4s; | ||
border-radius: 50%; | ||
} | ||
|
||
input:checked + .slider { | ||
background-color: #2196F3; | ||
} | ||
|
||
input:checked + .slider:before { | ||
transform: translateX(26px); | ||
} |
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,18 @@ | ||
import { FC, ChangeEvent } from 'react'; | ||
import styles from './ToggleSwitch.module.css'; | ||
|
||
interface ToggleSwitchProps { | ||
checked: boolean; | ||
onChange: (event: ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
const ToggleSwitch: FC<ToggleSwitchProps> = ({ checked, onChange }) => { | ||
return ( | ||
<label className={styles.toggleSwitch}> | ||
<input type="checkbox" checked={checked} onChange={onChange} /> | ||
<span className={styles.slider}></span> | ||
</label> | ||
); | ||
}; | ||
|
||
export default ToggleSwitch; |
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