
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
@cosmo-design/tooltip
Advanced tools
[](https://github.com/cosmo-design/tooltip) [](https://github.com/cosmo-design/tooltip)
@cosmo-design/tooltip is a powerful and flexible tooltip pure JS library based on @cosmo-design/popper.
npm i -S @cosmo-design/tooltip
or via CDN
<link rel="stylesheet" href="https://unpkg.com/@cosmo-design/tooltip@latest/dist/index.min.css">
<script src="https://unpkg.com/@cosmo-design/tooltip@latest/dist/index.min.js"></script>
<script>
console.log(tooltip)
</script>
import Tooltip from '@cosmo-design/tooltip'
import '@cosmo-design/tooltip/lib/index.css'
// or import '@cosmo-design/tooltip/lib/index.scss'
// or import '@cosmo-design/tooltip/dist/index.min.css'
const container = document.querySelector('.container'); // default: document.body
const trigger = document.querySelector('.trigger');
// or virtual element. type: { getBoundingClientRect: () => { left: number, top: number, width: number, height: number } }
const tooltip = new Tooltip({
container,
trigger, // required
content: 'It can be a string or a DOM element.', // It will not be displayed when it is an empty string.
})
setTimeout(() => {
tooltip.updateConfig({ // You can update any parameter using the updateConfig method.
content: 'xxx'
})
}, 5000)
// if you don't need it anymore
tooltip.destroy()
You can refer to the documentation of @cosmo-design/popper for a complete tutorial.
The class names and CSS variables of Tooltip begin with cdt
.
--cdt-color: #fff; // font color
--cdt-bg: #1f2329; // background color
--cdt-padding: 8px 12px; // padding
--cdt-radius: 8px; // radius
--cdt-arrow: 12px; // The width and height of the arrow element
--cdt-shadow: 0; // box shadow
You can customize the style by modifying CSS variables.
html[data-theme='dark'] .cdt, html.dark .cdt {
--cdt-bg: #373739;
}
Please refer to the @cosmo-design/popper CSS animation parameters for more information.
Tooltip has added cdt_ani
as the default CSS animation name, and you can customize the CSS animation by configuring the cssName
parameter.
const tooltip = new Tooltip({
cssName: 'fade'
})
You can write the following CSS styles:
.fade-enter-from, .fade-exit-to {
transform: scale(.7);
opacity: 0;
}
.fade-enter-active, .fade-exit-active {
transition: transform .1s ease, opacity .1s ease;
}
You can configure a custom arrow element using the arrow parameter. By default, a div
element with a class name of cdt_arrow
will be added as the arrow element.
const arrow = document.createElement('div')
arrow.classList.add('arrow')
const popper = new Tooltip({
arrow: true, // default
// arrow: false Do not display the arrow element.
// arrow: document.createElement('div') Customize the arrow element.
})
Please refer to the @cosmo-design/popper API documentation for the complete API.
Name | Type | Description |
---|---|---|
content | string | Node | Content to be displayed |
arrow | boolean | Node | Arrow element |
FAQs
[](https://github.com/cosmo-design/tooltip) [](https://github.com/cosmo-design/tooltip)
We found that @cosmo-design/tooltip demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.