Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@closeio/smart-tooltip-delay
Advanced tools
Smart tooltip delay experience in a breeze.
This tiny library can help you create a tooltip experience where the first one is shown with a delay and any subsequent ones are shown immediately or with a different delay. After a defined amount of time of no tooltip activity, the original tooltip delay is restored.
The GIF above shows a smart tooltip delay where tooltips are shown after 600ms, but once the first one is shown, any subsequent ones are shown immediately. After 2500ms of no tooltip activity the original 600ms delay is restored.
Interested in working on projects like this? Close is looking for great engineers to join our team!
yarn add @closeio/smart-tooltip-delay
When instantiating SmartTooltipDelay
, you can provide an object with 3 options:
delay
– default delay for each tooltipnoDelay
– delay set for each subsequently shown tooltip (going from delay
to noDelay
)resetAfterTime
– time in milliseconds after which the default delay is restored (going from noDelay
to delay
)To integrate with a tooltip library, follow these steps:
const instance = new SmartTooltipDelay({ delay: 600, noDelay: 0, resetAfterTime: 2500 })
instance.getCurrentDelay()
whenever the user attempts to show a tooltipinstance.show()
instance.hide()
You can create a single SmartTooltipDelay
instance for the entire app or you can create instances for each button toolbar.
This example uses a single shared smart delay and a tooltip library called Tippy.js.
sharedDelay.js
import SmartTooltipDelay from '@closeio/smart-tooltip-delay';
export default new SmartTooltipDelay({
delay: 600,
noDelay: 0,
resetAfterTime: 2500,
});
MyTooltip.js
import sharedSmartDelay from './sharedDelay.js';
export default function MyTooltip({ content /** … more props … */ }) {
// Show with a smart delay, hide immediately
const delayArrayRef = useRef([sharedSmartDelay.getCurrentDelay(), 0]);
// Update Tippy's delay when we try to interact with it.
const handleOnTrigger = useCallback(() => {
delayArrayRef.current[0] = sharedSmartDelay.getCurrentDelay();
}, []);
// Tell the smart delay that the tooltip has been shown.
const handleOnShow = useCallback(() => {
sharedSmartDelay.show();
}, []);
// Tell the smart delay that the tooltip has been hidden.
const handleOnHide = useCallback(() => {
sharedSmartDelay.hide();
}, []);
return (
<Tippy
delay={delayArrayRef.current}
onTrigger={handleOnTrigger}
onShow={handleOnShow}
onHide={handleOnHide}
// … more props
>
{content}
</Tippy>
);
}
This example uses a single shared smart delay and a tooltips from the Bootstrap framework.
sharedDelay.js
import SmartTooltipDelay from '@closeio/smart-tooltip-delay';
export default new SmartTooltipDelay({
delay: 600,
noDelay: 0,
resetAfterTime: 2500,
});
applySmartDelay.js
import $ from 'jquery';
import sharedSmartDelay from './sharedDelay.js';
/**
* Extends Bootstrap Tooltip v2.3.2 with smart delay.
*/
export default function applySmartDelay() {
// Do "Smart" tooltip delay by default.
$.fn.tooltip.defaults.delay = { show: sharedSmartDelay.getCurrentDelay() };
// Override Tooltip's `enter` method to sneak in a different "show" delay.
const Tooltip = $.fn.tooltip.Constructor;
const _enter = Tooltip.prototype.enter;
Tooltip.prototype.enter = function (e) {
const self = $(e.currentTarget).data(this.type);
if (self && self.options && self.options.hasSmartDelay) {
self.options.delay = { show: sharedSmartDelay.getCurrentDelay() };
}
_enter.call(this, e);
};
// Set the "Smart" behaviour without overriding potential custom per-tooltip delay.
const _getOptions = Tooltip.prototype.getOptions;
Tooltip.prototype.getOptions = function (initialOptions) {
const options = _getOptions.call(this, initialOptions);
// If delay wasn't set, and it is not 0, use smart delay
options.hasSmartDelay = !initialOptions.delay && initialOptions.delay !== 0;
return options;
};
$(document).on({
'show.bs.tooltip': sharedSmartDelay.show,
'hide.bs.tooltip': sharedSmartDelay.hide,
});
}
MIT © Close
FAQs
Smart tooltip delay experience in a breeze
We found that @closeio/smart-tooltip-delay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.