Add toggle switch checkbox.
This commit is contained in:
		
							parent
							
								
									0af652b413
								
							
						
					
					
						commit
						32d5006d9b
					
				
					 3 changed files with 49 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -22,6 +22,7 @@ import {MainMenuItemSubmenu, MainMenuLink} from "../src/Components/Menus/MainMen
 | 
			
		|||
import {AppItem, AppLink, AppsMenu} from "../src/Components/Menus/AppsMenu";
 | 
			
		||||
import {Application} from "../src/Application/Application";
 | 
			
		||||
import {Outlet} from "react-router-dom";
 | 
			
		||||
import {ToggleSwitch} from "../src/Components/Forms/ToggleSwitch";
 | 
			
		||||
 | 
			
		||||
export function DemoApp()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -120,6 +121,7 @@ export function DemoApp()
 | 
			
		|||
				<p>Currently selected datetime: <strong>{datetime ? datetime.toISOString() : "none"}</strong></p>
 | 
			
		||||
 | 
			
		||||
				<Checkbox>Checkbox demo</Checkbox>
 | 
			
		||||
				<ToggleSwitch>Toggle switch demo</ToggleSwitch>
 | 
			
		||||
				<Radio name={"radio-test"}>Radio box test</Radio>
 | 
			
		||||
				<Radio name={"radio-test"}>Radio box test</Radio>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								src/Components/Forms/ToggleSwitch.tsx
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Components/Forms/ToggleSwitch.tsx
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
import React from "react";
 | 
			
		||||
import {Check} from "@phosphor-icons/react";
 | 
			
		||||
import {classes} from "../../Utils";
 | 
			
		||||
 | 
			
		||||
export function ToggleSwitch({children, className, type, ...inputProps}: React.PropsWithChildren<React.InputHTMLAttributes<HTMLInputElement>>): React.ReactElement
 | 
			
		||||
{
 | 
			
		||||
	return (
 | 
			
		||||
		<label className={classes("toggleswitch", className)}>
 | 
			
		||||
			<input type={"checkbox"} {...inputProps} />
 | 
			
		||||
			<a className={"button"} tabIndex={-1}><span className={"switch"}></span></a>
 | 
			
		||||
			{children}
 | 
			
		||||
		</label>
 | 
			
		||||
	);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
label.box
 | 
			
		||||
label.box, label.toggleswitch
 | 
			
		||||
{
 | 
			
		||||
	display: block;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -50,3 +50,35 @@ label.box
 | 
			
		|||
		background: var(--background-lighter);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
label.toggleswitch
 | 
			
		||||
{
 | 
			
		||||
	> .button
 | 
			
		||||
	{
 | 
			
		||||
		display: inline-flex;
 | 
			
		||||
		align-items: center;
 | 
			
		||||
		width: 2.5em;
 | 
			
		||||
 | 
			
		||||
		> .switch
 | 
			
		||||
		{
 | 
			
		||||
			transition: margin-left 0.25s ease, box-shadow 0.25s ease;
 | 
			
		||||
 | 
			
		||||
			display: inline-block;
 | 
			
		||||
 | 
			
		||||
			margin: auto 0.25em;
 | 
			
		||||
			width: 0.9em;
 | 
			
		||||
			height: 0.8em;
 | 
			
		||||
			border-radius: 0.25em;
 | 
			
		||||
			box-shadow: 0 0 0 0 var(--foreground-shadow);
 | 
			
		||||
			border: solid var(--background-darkest) thin;
 | 
			
		||||
			background: var(--background);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	> input:checked + .button > .switch
 | 
			
		||||
	{
 | 
			
		||||
		margin-left: 1.2em;
 | 
			
		||||
		border-color: transparent;
 | 
			
		||||
		box-shadow: 0 0 0.4em 0 var(--foreground-shadow);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue