Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orb typing reactivity on site prompt input #449

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/OnboardingSPA/components/OrbAnimation/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import { useEffect } from '@wordpress/element';

const OrbAnimation = ( { height = '80px' } ) => {
// Inline style to handle custom properties
const logoStyle = {
'--wnd-ai-logo-size': height,
height: `var(--wnd-ai-logo-size, ${ height })`,
};

useEffect( () => {
document
.querySelectorAll( '[data-wnd-ai-logo]' )
.forEach( function ( input ) {
let keyIsDown = false;
let animationFrameId = null;

const toggleClass = () => {
if ( keyIsDown ) {
document.body.classList.add( 'wnd-ai-logo-keydown' );
} else {
document.body.classList.remove( 'wnd-ai-logo-keydown' );
}
animationFrameId = null;
};

input.addEventListener( 'keydown', function () {
if ( ! keyIsDown ) {
keyIsDown = true;
if ( ! animationFrameId ) {
animationFrameId =
window.requestAnimationFrame( toggleClass );
}
}
} );

input.addEventListener( 'keyup', function () {
keyIsDown = false;
if ( ! animationFrameId ) {
animationFrameId =
window.requestAnimationFrame( toggleClass );
}
} );
} );
}, [] );

return (
<span className="wnd-ai-logo" style={ logoStyle }>
<span className="wnd-ai-logo__circle wnd-ai-logo__circle--bg"></span>
Expand Down
6 changes: 5 additions & 1 deletion src/OnboardingSPA/components/OrbAnimation/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,16 @@ body.wnd-ai-logo-loading .wnd-ai-logo {
}

/* Focus & Hover */
body:has([data-wnd-ai-logo]:focus) .wnd-ai-logo,
body:not(.wnd-ai-logo-loading) .wnd-ai-logo:hover {
transform: scale(1.05);
filter: brightness(1.35) saturate(1.5);
}

body:has([data-wnd-ai-logo]:focus) .wnd-ai-logo {
transform: scale(1.2);
filter: brightness(1.35) saturate(1.5);
}

/* Keydown */
body.wnd-ai-logo-keydown .wnd-ai-logo.wnd-ai-logo {
transform: scale(1.1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
const analysisResult = calculateAnalysisScore( customerInput?.trim() );
setAnalysisScore( analysisResult );
setIsValidInput( analysisResult >= 2 );
}, [ customerInput ] );

Check warning on line 26 in src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'height' and 'setIsValidInput'. Either include them or remove the dependency array. If 'setIsValidInput' changes too often, find the parent component that defines it and wrap that definition in useCallback

Check warning on line 26 in src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'height' and 'setIsValidInput'. Either include them or remove the dependency array. If 'setIsValidInput' changes too often, find the parent component that defines it and wrap that definition in useCallback

const calculateAnalysisScore = ( input ) => {
/* Number of Characters in the input
Expand Down Expand Up @@ -78,6 +78,7 @@
<label htmlFor={ inputText }>
<div className={ 'nfd-sg-input-box' }>
<textarea
data-wnd-ai-logo
type="text"
className={ inputText }
ref={ textareaRef }
Expand Down
Loading