Skip to content

Commit c55f012

Browse files
committed
Updated TW animation and sidebar onHover handler
1 parent 5595b8c commit c55f012

File tree

4 files changed

+57
-53
lines changed

4 files changed

+57
-53
lines changed

components/layout/sidebar/header/ActionDropdown.es6.js

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,57 @@ import SidebarHeaderActionButton from './SidebarHeaderActionButton.es6.js'
55
import classnames from 'classnames'
66

77
const ActionDropdown = forwardRef(({
8-
icon,
9-
actionsAvailable,
10-
actionsVisible,
11-
setActionsVisibility,
12-
quickDialog,
13-
quickActions,
14-
onClick,
15-
dropdownMenuLabel,
16-
onQuickActionSelected,
17-
isLogoDropDown,
18-
}, ref) => (
8+
icon,
9+
actionsAvailable,
10+
actionsVisible,
11+
setActionsVisibility,
12+
quickDialog,
13+
quickActions,
14+
onClick,
15+
dropdownMenuLabel,
16+
onQuickActionSelected,
17+
isLogoDropDown,
18+
handleHover,
19+
}, ref) => {
20+
const hoverHandlers = handleHover ? {
21+
onMouseEnter: onClick,
22+
onMouseLeave: onClick,
23+
} : {}
24+
25+
return (
1926
<div
20-
className={classnames({
21-
'ds-dropdown': actionsAvailable && icon,
22-
'ds-dropdown--right': actionsAvailable && icon && !isLogoDropDown,
23-
'ds-dropdown--left': isLogoDropDown,
24-
'ds-dropdown--menu-visible': actionsAvailable && actionsVisible,
25-
'ds-sidebar__header-action': !actionsAvailable
26-
})}
27-
ref={ref}
27+
className={classnames({
28+
'ds-dropdown': actionsAvailable && icon,
29+
'ds-dropdown--right': actionsAvailable && icon && !isLogoDropDown,
30+
'ds-dropdown--left': isLogoDropDown,
31+
'ds-dropdown--menu-visible': actionsAvailable && actionsVisible,
32+
'ds-sidebar__header-action': !actionsAvailable
33+
})}
34+
ref={ref}
35+
{...hoverHandlers}
2836
>
29-
{icon && (
30-
<SidebarHeaderActionButton
31-
dropdown={actionsAvailable}
32-
icon={icon}
33-
onClick={onClick}
34-
/>
35-
)}
37+
{icon && (
38+
<SidebarHeaderActionButton
39+
dropdown={actionsAvailable}
40+
icon={icon}
41+
onClick={onClick}
42+
/>
43+
)}
3644

37-
{quickDialog}
45+
{quickDialog}
3846

39-
{actionsVisible && (
40-
<QuickActions
41-
actions={quickActions}
42-
label={dropdownMenuLabel}
43-
onSelect={(idx) => {
44-
setActionsVisibility(false)
45-
onQuickActionSelected && onQuickActionSelected(idx)
46-
}}
47-
/>
48-
)}
47+
{actionsVisible && (
48+
<QuickActions
49+
actions={quickActions}
50+
label={dropdownMenuLabel}
51+
onSelect={(idx) => {
52+
setActionsVisibility(false)
53+
onQuickActionSelected && onQuickActionSelected(idx)
54+
}}
55+
/>
56+
)}
4957
</div>
50-
))
58+
)
59+
})
5160

5261
export default ActionDropdown

components/layout/sidebar/header/SidebarHeader.es6.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class SidebarHeader extends React.Component {
127127
dropdownMenuLabel={dropdownMenuLabel}
128128
onQuickActionSelected={onQuickActionSelected}
129129
isLogoDropDown
130+
handleHover
130131
/>)
131132
}
132133

components/lib/useTypingSimulation.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useEffect, useRef, useCallback } from 'react'
22

3-
const CHARS_PER_SEC = 50 // Simulated typing speed
3+
const ANIMATION_TIME = 2000 // Type text in 2 seconds
44

55
export const TypingStatus = {
66
IDLE: 'idle',
@@ -25,7 +25,7 @@ function useTypingSimulation(onStatusChange) {
2525
)
2626

2727
const startTyping = useCallback(
28-
(text, charactersPerSecond = CHARS_PER_SEC) => {
28+
(text) => {
2929
if (intervalRef.current) {
3030
clearInterval(intervalRef.current)
3131
intervalRef.current = null
@@ -39,25 +39,19 @@ function useTypingSimulation(onStatusChange) {
3939
setIsTyping(true)
4040
updateStatus(TypingStatus.TYPING)
4141

42-
const typingInterval = 1000 / charactersPerSecond
42+
const intervalMs = ANIMATION_TIME / text.length
4343

4444
intervalRef.current = window.setInterval(() => {
4545
charIndexRef.current++
46+
const partialText = text.substring(0, charIndexRef.current)
47+
setTypedText(partialText)
4648

47-
if (charIndexRef.current > text.length) {
48-
if (intervalRef.current) {
49-
clearInterval(intervalRef.current)
50-
intervalRef.current = null
51-
}
52-
49+
if (charIndexRef.current >= fullTextRef.current.length) {
50+
clearInterval(intervalRef.current)
5351
setIsTyping(false)
5452
updateStatus(TypingStatus.COMPLETED)
55-
return
5653
}
57-
58-
const partialText = text.substring(0, charIndexRef.current)
59-
setTypedText(partialText)
60-
}, typingInterval)
54+
}, intervalMs)
6155

6256
return text
6357
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@b12/metronome",
3-
"version": "1.1.28",
3+
"version": "1.1.29",
44
"description": "",
55
"main": "index.es6.js",
66
"scripts": {

0 commit comments

Comments
 (0)