-
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.
- Loading branch information
Showing
10 changed files
with
456 additions
and
23 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
165 changes: 165 additions & 0 deletions
165
src/components/Creator/LeftPanel/StylesPanel/Animations/Animations.tsx
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,165 @@ | ||
import styles from "@/components/Creator/LeftPanel/StylesPanel/StylesPanel.module.scss"; | ||
import {Option, Select} from "@/components/construction/Select"; | ||
import {useEffect, useState} from "react"; | ||
import {getInheritedStyleWith} from "@/helpers/block-styles"; | ||
import {useSelector} from "react-redux"; | ||
import Icon from "@/components/construction/Icon/Icon"; | ||
import SingleAnimation from "@/components/Creator/LeftPanel/StylesPanel/Animations/SingleAnimation/SingleAnimation"; | ||
|
||
type ChangeValue = { | ||
animations: string[]; | ||
durations: string[]; | ||
delays: string[]; | ||
directions: string[]; | ||
iterations: string[]; | ||
} | ||
|
||
interface Props { | ||
onChange: (value: string | null, property: string) => void | ||
} | ||
|
||
const allAnimationsNames: [id: string, name: string][] = [ | ||
['none', 'Brak'], | ||
['beat', 'Pulsowanie'], | ||
['beat-fade', 'Pulsowanie z wygaszaniem'], | ||
['bounce', 'Podskok'], | ||
['fade', 'Wygaszanie'], | ||
['flip', 'Odwracanie'], | ||
['shake', 'Potrząsanie'], | ||
['spin', 'Obrót'], | ||
]; | ||
export default function (props: Props) { | ||
const selectedBlock = useSelector((state: any) => state.structure.selectedBlock); | ||
const rwd = useSelector((state: any) => state.structure.rwdMode); | ||
const styleState = useSelector((state: any) => state.structure.styleState); | ||
const [animations, setAnimations] = useState<string[]>([]); | ||
const [durations, setDurations] = useState<string[]>([]); | ||
const [delays, setDelays] = useState<string[]>([]); | ||
const [directions, setDirections] = useState<string[]>([]); | ||
const [iterations, setIterations] = useState<string[]>([]); | ||
|
||
const changed = (value: ChangeValue) => { | ||
setIterations([...value.iterations]); | ||
setDirections([...value.directions]); | ||
setDelays([...value.delays]); | ||
setDurations([...value.durations]); | ||
setAnimations([...value.animations]); | ||
console.log({value}) | ||
if (value.animations.includes('none')) { | ||
props.onChange('', 'animationIterationCount'); | ||
props.onChange('', 'animationDirection'); | ||
props.onChange('', 'animationDelay'); | ||
props.onChange('', 'animationDuration'); | ||
props.onChange('none', 'animationName'); | ||
return; | ||
} | ||
props.onChange(value.iterations.join(', '), 'animationIterationCount'); | ||
props.onChange(value.directions.join(', '), 'animationDirection'); | ||
props.onChange(value.delays.join(', '), 'animationDelay'); | ||
props.onChange(value.durations.join(', '), 'animationDuration'); | ||
props.onChange(value.animations.join(', '), 'animationName'); | ||
} | ||
const splitValue = value => (value || '').split(',').map(val => val.trim()).filter(val => val.length > 0); | ||
useEffect(() => { | ||
const style = getInheritedStyleWith( | ||
selectedBlock.styles, | ||
rwd, styleState, | ||
['animationName', 'animationDuration', 'animationDelay', 'animationDirection', 'animationIterationCount'], | ||
) as any; | ||
setIterations(splitValue(style.animationIterationCount)); | ||
setDirections(splitValue(style.animationDirection)); | ||
setDelays(splitValue(style.animationDelay)); | ||
setDurations(splitValue(style.animationDuration)); | ||
setAnimations(splitValue(style.animationName)); | ||
}, [selectedBlock, rwd, styleState]) | ||
|
||
const addAnimation = (animationId: string) => { | ||
if (!animationId) { | ||
return; | ||
} | ||
if (animationId === 'none') { | ||
setIterations([]); | ||
setDirections([]); | ||
setDelays([]); | ||
setDurations([]); | ||
setAnimations(['none']); | ||
changed({animations: ['none'], durations: [], delays: [], directions: [], iterations: []}) | ||
return; | ||
} | ||
iterations.push('infinite'); | ||
directions.push('normal'); | ||
delays.push('0s'); | ||
durations.push('1s'); | ||
if (animations.includes('none')) { | ||
animations.length = 0; | ||
} | ||
animations.push(animationId); | ||
changed({ | ||
animations, | ||
durations, | ||
delays, | ||
directions, | ||
iterations, | ||
}); | ||
} | ||
const removeFilter = index => { | ||
iterations.splice(index, 1); | ||
directions.splice(index, 1); | ||
delays.splice(index, 1); | ||
durations.splice(index, 1); | ||
animations.splice(index, 1); | ||
changed({ | ||
animations, | ||
durations, | ||
delays, | ||
directions, | ||
iterations, | ||
}); | ||
} | ||
const getAnimationName =animationId=>allAnimationsNames.find(([id,name])=>id===animationId)?.[1]||''; | ||
const getAnimationsList = () => { | ||
return animations.map((id, index) => { | ||
return (<div className={styles.stylesFormRow} key={id}> | ||
<SingleAnimation name={id} | ||
duration={durations[index]} | ||
delay={delays[index]} | ||
direction={directions[index]} | ||
iteration={iterations[index]} | ||
label={getAnimationName(id)} | ||
onChange={e => changedAnimation(index, e)}/> | ||
<Icon type="material" name="close" onClick={e => removeFilter(index)}/> | ||
</div>) | ||
} | ||
) | ||
} | ||
|
||
const changedAnimation = (index: number, [name, duration, delay, direction, iteration]) => { | ||
iterations[index] = iteration; | ||
directions[index] = direction; | ||
delays[index] = delay; | ||
durations[index] = duration; | ||
changed({ | ||
animations, | ||
durations, | ||
delays, | ||
directions, | ||
iterations, | ||
}); | ||
} | ||
|
||
return ( | ||
<div className={styles.stylesFormGroup}> | ||
<div className={styles.stylesFormRow}> | ||
<Select onChange={addAnimation} label="Dodaj animacje"> | ||
<Option value="" selected={true}>Wybierz</Option> | ||
{allAnimationsNames.map(([id, name]) => | ||
<Option key={id} value={id} disabled={animations.includes(id)}>{name}</Option> | ||
)} | ||
</Select> | ||
</div> | ||
|
||
{getAnimationsList()} | ||
|
||
</div> | ||
) | ||
} |
86 changes: 86 additions & 0 deletions
86
src/components/Creator/LeftPanel/StylesPanel/Animations/SingleAnimation/SingleAnimation.tsx
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,86 @@ | ||
import styles from "@/components/Creator/LeftPanel/StylesPanel/StylesPanel.module.scss"; | ||
import InputWithUnits from "@/components/construction/InputWithUnits/InputWithUnits"; | ||
import {Units} from "@/types/units"; | ||
import {useState} from "react"; | ||
import {Option, Select} from "@/components/construction/Select"; | ||
|
||
type ValueType = [name: string, duration: string, delay: string, direction: string, iteration: string]; | ||
|
||
interface Props { | ||
label: string; | ||
name: string; | ||
duration: string; | ||
delay: string; | ||
direction: string; | ||
iteration: string; | ||
onChange: (value: ValueType) => void | ||
} | ||
|
||
export default function (props: Props) { | ||
const [duration, setDuration] = useState<string>(props.duration) | ||
const [delay, setDelay] = useState<string>(props.delay) | ||
const [direction, setDirection] = useState<string>(props.direction) | ||
const [iteration, setIteration] = useState<string>(props.iteration) | ||
const timeUnits: Units[] = ['s', 'ms']; | ||
|
||
const changeDuration = (val: string) => { | ||
setDuration(val); | ||
props.onChange([props.name, val, delay, direction, iteration]) | ||
} | ||
const changeDelay = (val: string) => { | ||
setDelay(val); | ||
props.onChange([props.name, duration, val, direction, iteration]) | ||
} | ||
const changeDirection = (val: string) => { | ||
setDirection(val); | ||
props.onChange([props.name, duration, delay, val, iteration]) | ||
} | ||
const changeIteration = (val: string) => { | ||
setIteration(val); | ||
props.onChange([props.name, duration, delay, direction, val]) | ||
} | ||
return ( | ||
<div className={styles.stylesFormColumn}> | ||
{props.label} | ||
{props.name !== 'none' | ||
? <> | ||
<div className={styles.stylesFormRow}> | ||
<div className={styles.stylesFormField}> | ||
<InputWithUnits units={timeUnits} label="Czas trwania" value={duration} | ||
onChange={changeDuration} | ||
min={0}/> | ||
</div> | ||
<div className={styles.stylesFormField}> | ||
<InputWithUnits units={timeUnits} label="Opóźnienie startu" value={delay} | ||
onChange={changeDelay} | ||
min={0}/> | ||
</div> | ||
</div> | ||
<div className={styles.stylesFormRow}> | ||
<div className={styles.stylesFormField}> | ||
<Select label="Liczba iteracji" onChange={changeIteration}> | ||
<Option value="infinite" selected={iteration === 'infinite'}>Nieskończona</Option> | ||
<Option value="1" selected={iteration === '1'}>1</Option> | ||
<Option value="2" selected={iteration === '2'}>2</Option> | ||
<Option value="3" selected={iteration === '3'}>3</Option> | ||
<Option value="4" selected={iteration === '4'}>4</Option> | ||
<Option value="5" selected={iteration === '5'}>5</Option> | ||
</Select> | ||
</div> | ||
<div className={styles.stylesFormField}> | ||
<label htmlFor="animation-direction"></label> | ||
<Select label="Kierunek animacji" onChange={changeDirection}> | ||
<Option value="normal" selected={direction === 'normal'}>Do przodu</Option> | ||
<Option value="reverse" selected={direction === 'reverse'}>Do tyłu</Option> | ||
<Option value="alternate" selected={direction === 'alternate'}>Do przodu i do | ||
tyłu</Option> | ||
<Option value="alternate-reverse" selected={direction === 'alternate-reverse'}>Do tyłu i | ||
do | ||
przodu</Option> | ||
</Select> | ||
</div> | ||
</div> | ||
</> : ''} | ||
</div> | ||
) | ||
} |
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
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
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
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
Oops, something went wrong.