-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ๐ธ added frame to player * feat: ๐ธ added validation for states * feat: ๐ธ added title edit feature * feat: ๐ธ added animation rename feature * fix: ๐ fixed enterkey behaviour * feat: ๐ธ added color picker element * chore: ๐ค updated ui add new form * fix: ๐ updating src doesn't clear previously loaded states * chore: ๐ค added changeset * fix: ๐ recreate instance on src update * Revert "fix: ๐ updating src doesn't clear previously loaded states" This reverts commit 5acb38c. * chore: ๐ค fixed changeset * refactor: ๐ก change to use abstracted initDotlottiePlayer method * chore: ๐ค updated interactivity example lottie
- Loading branch information
Showing
14 changed files
with
353 additions
and
56 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,5 @@ | ||
--- | ||
'@dotlottie/react-player': patch | ||
--- | ||
|
||
fix: ๐ updating src doesn't clear previously loaded states |
Binary file renamed
BIN
+200 KB
...round/public/lf_interactivity_page.lottie โ ...round/public/interactivity_example.lottie
Binary file not shown.
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
58 changes: 58 additions & 0 deletions
58
apps/dotlottie-playground/src/components/editable-title.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,58 @@ | ||
/** | ||
* Copyright 2023 Design Barn Inc. | ||
*/ | ||
|
||
import React, { useCallback, useState, useRef, type KeyboardEventHandler } from 'react'; | ||
import { BiSolidEdit } from 'react-icons/bi'; | ||
|
||
import { cn } from '../utils'; | ||
|
||
interface EditableTitleProps { | ||
onChange: (value: string) => void; | ||
title: string; | ||
} | ||
|
||
export const EditableTitle: React.FC<EditableTitleProps> = ({ onChange, title }) => { | ||
const [edit, setEdit] = useState(false); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const handleClick = useCallback((): void => { | ||
if (!edit) { | ||
setEdit(true); | ||
} | ||
}, [edit]); | ||
|
||
const handleSave = useCallback(() => { | ||
onChange(inputRef.current?.value ? `${inputRef.current.value}.lottie` : title); | ||
setEdit(false); | ||
}, [onchange, setEdit]); | ||
|
||
const checkForEnterKey = useCallback<KeyboardEventHandler<HTMLInputElement>>( | ||
(event) => { | ||
if (event.key === 'Enter') { | ||
handleSave(); | ||
} | ||
}, | ||
[handleSave], | ||
); | ||
|
||
return ( | ||
<div className="group flex items-center"> | ||
{edit && ( | ||
<input | ||
ref={inputRef} | ||
autoFocus | ||
className="bg-transparent outline-none" | ||
type="text" | ||
onKeyDown={checkForEnterKey} | ||
onBlur={handleSave} | ||
defaultValue={title.replace(/.lottie$/u, '')} | ||
/> | ||
)} | ||
{!edit && <span>{title || 'unnamed.lottie'}</span>} | ||
<button onClick={handleClick} className={cn('invisible', !edit && 'group-hover:visible')}> | ||
<BiSolidEdit size={20} /> | ||
</button> | ||
</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
99 changes: 99 additions & 0 deletions
99
apps/dotlottie-playground/src/components/file-tree/editable-item.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,99 @@ | ||
/** | ||
* Copyright 2023 Design Barn Inc. | ||
*/ | ||
|
||
import React, { | ||
type HTMLAttributes, | ||
useCallback, | ||
type MouseEventHandler, | ||
useState, | ||
useRef, | ||
type KeyboardEventHandler, | ||
} from 'react'; | ||
import { BiSolidEdit } from 'react-icons/bi'; | ||
import { RxCross2 } from 'react-icons/rx'; | ||
|
||
import { processFilename } from '../../utils'; | ||
|
||
import { FileIcon } from './file-icon'; | ||
|
||
import { type SupportedFile } from '.'; | ||
|
||
interface EditableItemProps extends HTMLAttributes<HTMLButtonElement> { | ||
editable?: boolean; | ||
file: SupportedFile; | ||
onClick?: () => void; | ||
onRemove?: (fileName: string) => void; | ||
onRename?: (previousId: string, newId: string) => void; | ||
} | ||
|
||
export const EditableItem: React.FC<EditableItemProps> = ({ editable, file, onRemove, onRename, ...props }) => { | ||
const [editMode, setEditMode] = useState(false); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const handleRemove = useCallback<MouseEventHandler<HTMLSpanElement>>( | ||
(event) => { | ||
event.stopPropagation(); | ||
onRemove?.(file.name); | ||
}, | ||
[onRemove, file.name], | ||
); | ||
|
||
const enterEditMode = useCallback<MouseEventHandler<HTMLSpanElement>>( | ||
(event) => { | ||
event.stopPropagation(); | ||
setEditMode(true); | ||
}, | ||
[setEditMode, editMode], | ||
); | ||
|
||
const triggerRename = useCallback(() => { | ||
if (inputRef.current && inputRef.current.value !== file.name) { | ||
onRename?.(file.name, processFilename(inputRef.current.value)); | ||
} | ||
setEditMode(false); | ||
}, [onRename, setEditMode, inputRef]); | ||
|
||
const checkForEnterKey = useCallback<KeyboardEventHandler<HTMLInputElement>>( | ||
(event) => { | ||
if (event.key === 'Enter') { | ||
triggerRename(); | ||
} | ||
}, | ||
[triggerRename], | ||
); | ||
|
||
return ( | ||
<button | ||
className="group w-full flex items-center gap-1 px-2 py-1 pl-4 text-sm whitespace-nowrap hover:text-white" | ||
{...props} | ||
> | ||
<span> | ||
<FileIcon type={file.type} /> | ||
</span> | ||
{editMode && ( | ||
<input | ||
ref={inputRef} | ||
onKeyDown={checkForEnterKey} | ||
onBlur={triggerRename} | ||
autoFocus | ||
className="outline-none bg-transparent flex-1 text-left" | ||
defaultValue={file.name} | ||
/> | ||
)} | ||
{!editMode && <span className="flex-1 text-left">{file.name}</span>} | ||
{!editMode && ( | ||
<div className="flex justify-self-end text-gray-400 gap-1"> | ||
{editable && ( | ||
<span onClick={enterEditMode} className="hover:text-white opacity-0 group-hover:opacity-100"> | ||
<BiSolidEdit size={20} /> | ||
</span> | ||
)} | ||
<span onClick={handleRemove} title="Remove" className="hover:text-white opacity-0 group-hover:opacity-100"> | ||
<RxCross2 size={20} /> | ||
</span> | ||
</div> | ||
)} | ||
</button> | ||
); | ||
}; |
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
45 changes: 45 additions & 0 deletions
45
apps/dotlottie-playground/src/components/input-fields/input-color-picker.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,45 @@ | ||
/** | ||
* Copyright 2023 Design Barn Inc. | ||
*/ | ||
|
||
import React, { type ChangeEventHandler, useCallback, useRef } from 'react'; | ||
|
||
interface InputColorPickerProps { | ||
label: string; | ||
onChange?: (value: string) => void; | ||
value?: string; | ||
} | ||
|
||
export const InputColorPicker: React.FC<InputColorPickerProps> = ({ label, onChange, value }) => { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>( | ||
(event) => { | ||
onChange?.(event.target.value); | ||
}, | ||
[onChange], | ||
); | ||
|
||
const openPicker = useCallback(() => inputRef.current?.click(), [inputRef]); | ||
|
||
return ( | ||
<div className="flex flex-col text-gray-400 w-full max-w-xs hover:text-white"> | ||
<span className="flex-1 text-lg text-left">{label}</span> | ||
<button | ||
onClick={openPicker} | ||
className={`flex items-center justify-between py-2 px-3 rounded bg-white text-gray-600`} | ||
> | ||
<div className="py-1 px-2 w-full text-left rounded" style={{ backgroundColor: value }}> | ||
<span className="text-white mix-blend-difference">{value || 'transparent'}</span> | ||
</div> | ||
</button> | ||
<input | ||
ref={inputRef} | ||
type="color" | ||
onChange={handleChange} | ||
value={value} | ||
name={label} | ||
className={`invisible h-0 w-0`} | ||
/> | ||
</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
Oops, something went wrong.