Add toggle button to disable / enable dynamic update
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
af73fa6083
commit
6ae8322144
3 changed files with 100 additions and 44 deletions
|
@ -1,5 +1,6 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import ContainerProperties from '../../Interfaces/Properties';
|
import ContainerProperties from '../../Interfaces/Properties';
|
||||||
|
import { ToggleButton } from '../ToggleButton/ToggleButton';
|
||||||
import { INPUT_TYPES } from './PropertiesInputTypes';
|
import { INPUT_TYPES } from './PropertiesInputTypes';
|
||||||
|
|
||||||
interface IPropertiesProps {
|
interface IPropertiesProps {
|
||||||
|
@ -9,12 +10,12 @@ interface IPropertiesProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps) => {
|
export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps) => {
|
||||||
|
const [isDynamicInput, setIsDynamicInput] = useState<boolean>(false);
|
||||||
|
|
||||||
if (props.properties === undefined) {
|
if (props.properties === undefined) {
|
||||||
return <div></div>;
|
return <div></div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [isDynamicInput, setIsDynamicInput] = useState<boolean>(true);
|
|
||||||
|
|
||||||
const groupInput: React.ReactNode[] = [];
|
const groupInput: React.ReactNode[] = [];
|
||||||
const refs: Array<React.RefObject<HTMLInputElement>> = [];
|
const refs: Array<React.RefObject<HTMLInputElement>> = [];
|
||||||
Object
|
Object
|
||||||
|
@ -36,10 +37,12 @@ export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='h-3/5 p-3 bg-slate-200 overflow-y-auto'>
|
<div className='h-3/5 p-3 bg-slate-200 overflow-y-auto'>
|
||||||
<input
|
<ToggleButton
|
||||||
type='checkbox'
|
id='isDynamic'
|
||||||
onChange={() => { setIsDynamicInput(!isDynamicInput); }}
|
text='Dynamic update'
|
||||||
|
title='Enable dynamic svg update'
|
||||||
checked={isDynamicInput}
|
checked={isDynamicInput}
|
||||||
|
onChange={() => setIsDynamicInput(!isDynamicInput)}
|
||||||
/>
|
/>
|
||||||
{ form }
|
{ form }
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,52 +73,45 @@ const handleProperties = (
|
||||||
refs.push(ref);
|
refs.push(ref);
|
||||||
|
|
||||||
const isDisabled = ['id', 'parentId'].includes(key);
|
const isDisabled = ['id', 'parentId'].includes(key);
|
||||||
if (isDynamicInput) {
|
const input = isDynamicInput
|
||||||
groupInput.push(
|
? <input
|
||||||
<div key={id} className='mt-4'>
|
className='text-base font-medium transition-all text-gray-800 mt-1 block w-full px-3 py-2
|
||||||
<label className='text-sm font-medium text-gray-800' htmlFor={id}>{key}</label>
|
|
||||||
<input
|
|
||||||
className='text-base font-medium transition-all text-gray-800 mt-1 block w-full px-3 py-2
|
|
||||||
bg-white border-2 border-white rounded-lg placeholder-gray-800
|
bg-white border-2 border-white rounded-lg placeholder-gray-800
|
||||||
focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500
|
focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500
|
||||||
disabled:bg-slate-300 disabled:text-gray-500 disabled:border-slate-300 disabled:shadow-none
|
disabled:bg-slate-300 disabled:text-gray-500 disabled:border-slate-300 disabled:shadow-none
|
||||||
'
|
'
|
||||||
type={type}
|
type={type}
|
||||||
id={id}
|
id={key}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
value={value}
|
value={value}
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
if (type === 'checkbox') {
|
if (type === 'checkbox') {
|
||||||
onChange(key, event.target.checked);
|
onChange(key, event.target.checked);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onChange(key, event.target.value);
|
onChange(key, event.target.value);
|
||||||
}}
|
}}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
: <input
|
||||||
);
|
className='text-base font-medium transition-all text-gray-800 mt-1 block w-full px-3 py-2
|
||||||
return;
|
bg-white border-2 border-white rounded-lg placeholder-gray-800
|
||||||
}
|
focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500
|
||||||
|
disabled:bg-slate-300 disabled:text-gray-500 disabled:border-slate-300 disabled:shadow-none
|
||||||
|
'
|
||||||
|
type={type}
|
||||||
|
id={key}
|
||||||
|
ref={ref}
|
||||||
|
defaultValue={value}
|
||||||
|
defaultChecked={checked}
|
||||||
|
disabled={isDisabled}
|
||||||
|
/>;
|
||||||
|
|
||||||
///
|
|
||||||
groupInput.push(
|
groupInput.push(
|
||||||
<div key={id} className='mt-4'>
|
<div key={id} className='mt-4'>
|
||||||
<label className='text-sm font-medium text-gray-800' htmlFor={id}>{key}</label>
|
<label className='text-sm font-medium text-gray-800' htmlFor={key}>{key}</label>
|
||||||
<input
|
{input}
|
||||||
className='text-base font-medium transition-all text-gray-800 mt-1 block w-full px-3 py-2
|
|
||||||
bg-white border-2 border-white rounded-lg placeholder-gray-800
|
|
||||||
focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500
|
|
||||||
disabled:bg-slate-300 disabled:text-gray-500 disabled:border-slate-300 disabled:shadow-none
|
|
||||||
'
|
|
||||||
type={type}
|
|
||||||
id={key}
|
|
||||||
ref={ref}
|
|
||||||
defaultValue={value}
|
|
||||||
defaultChecked={checked}
|
|
||||||
disabled={isDisabled}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
8
src/Components/ToggleButton/ToggleButton.scss
Normal file
8
src/Components/ToggleButton/ToggleButton.scss
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
input:checked ~ .dot {
|
||||||
|
transform: translateX(100%);
|
||||||
|
}
|
||||||
|
input:checked ~ .line {
|
||||||
|
background-color: #3B82F6;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
52
src/Components/ToggleButton/ToggleButton.tsx
Normal file
52
src/Components/ToggleButton/ToggleButton.tsx
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
import React, { FC } from 'react';
|
||||||
|
import './ToggleButton.scss';
|
||||||
|
|
||||||
|
interface IToggleButtonProps {
|
||||||
|
id: string
|
||||||
|
text: string
|
||||||
|
type?: TOGGLE_TYPE
|
||||||
|
title: string
|
||||||
|
checked: boolean
|
||||||
|
onChange: React.ChangeEventHandler<HTMLInputElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum TOGGLE_TYPE {
|
||||||
|
MATERIAL,
|
||||||
|
IOS
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ToggleButton: FC<IToggleButtonProps> = (props) => {
|
||||||
|
const id = `toggle-${props.id}`;
|
||||||
|
const type = props.type ?? TOGGLE_TYPE.MATERIAL;
|
||||||
|
let classLine = 'line w-10 h-4 bg-gray-400 rounded-full shadow-inner';
|
||||||
|
let classDot = 'dot absolute w-6 h-6 bg-white rounded-full shadow -left-1 -top-1 transition';
|
||||||
|
if (type === TOGGLE_TYPE.IOS) {
|
||||||
|
classLine = 'line block bg-gray-600 w-14 h-8 rounded-full';
|
||||||
|
classDot = 'dot absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div title={props.title}>
|
||||||
|
<div className="flex items-center justify-center w-full mb-12">
|
||||||
|
<label
|
||||||
|
htmlFor={id}
|
||||||
|
className="flex items-center cursor-pointer"
|
||||||
|
>
|
||||||
|
<div className="relative">
|
||||||
|
<input
|
||||||
|
id={id}
|
||||||
|
type="checkbox"
|
||||||
|
onChange={props.onChange}
|
||||||
|
checked={props.checked}
|
||||||
|
className="sr-only" />
|
||||||
|
<div className={classLine}></div>
|
||||||
|
<div className={classDot}></div>
|
||||||
|
</div>
|
||||||
|
<div className="ml-3 text-gray-700 font-medium">
|
||||||
|
{ props.text }
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue