@pharos-lab/blink v0.1.2
About The Project
Blink is a tool for quickly add tooltip, pop-up and more in your project within few lines of code.
Getting Started
All you need is installing the Blink package and add few lines of code.
Prerequisites
You just need npm installed to get Blink.
- npm
npm install npm@latest -g
Installation
Install NPM package
npm install @pharos-lab/blinkUsage
All you need to create a pop-up or else is two element at least:
- A trigger, like a button or any element you wish
- A popper, the element you want to appear based on the event you choose (hover or click)
Then, in your js file, you can import the Blink class and use the create method to create your pop-up, tooltip or whatever element you want to make appearance.
Here is a exemple:
In html file
<!DOCTYPE html>
<title>Popper example</title>
<button id="button" >I'm a button</button>
<div id="tooltip">I'm a tooltip</div>In Js file
import { Blink } from '@pharos-lab/blink'
const button = document.getElementById('button')
const tooltip = document.getElementById('tooltip')
Blink.create(button, tooltip)Use it with VUE
<template>
<title>Popper example</title>
<button id="button" ref="trigger">I'm a button</button>
<div id="tooltip" ref="popper">I'm a tooltip</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { Blink } from '@pharos-lab/blink'
const button = ref()
const tooltip = ref()
onMounted(() => {
Blink.create(button.value, tooltip.value)
})
</script>Use it with REACT
import { Blink } from 'pharos-lab/blink'
import { React } from 'react'
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.trigger = React.createRef();
this.popper = React.createRef();
}
componentDidMount() {
Blink.create(this.trigger.current, this.popper.current);
}
render() {
return (
<div>
<!-- your component JSX -->
<p>Lorem ipsum dolor sit amet <span ref={this.trigger}>adipiscing</span> elit, sed do</p>
<div className="popper" ref={this.popper}>
I'm a tooltip
</div>
</div>
);
}
}Customization
placement
The Blink create method will place your pop-up automatically based on the place available in the viewport.
By default, it will try at top of the trigger, then bottom, right and finally left. But you can choose by adding an option object as 3rd argument to create method.
Example
const options = {
placement: 'top'
}
Blink.create(trigger, tooltip, options)You may choose the placement among these values:
top,bottom,right,left,auto.
autois the default option
Event
In addition to the placement option, you can choose what kind of event will trigger the pop-up with the event option
Example
const options = {
event: 'click'
}
Blink.create(trigger, tooltip, options)You may choose the
eventamong these values:click,hover.
hoveris the default option
Arrow
Finally, you can add an arrow to the pop-up for UI/UX appreciation with the arrow option
Example
const options = {
arrow: true
}
Blink.create(trigger, tooltip, options)You may choose the
arrowoption among these values:true,false.
falseis the default option
Dropdown
If you want to create a dropdown that is right or left aligned with your trigger, you can use the dropdown option.
Example
const options = {
dropdown: 'right'
}
Blink.create(trigger, tooltip, options)You may choose the
dropdownoption among these values:right,left,none.
noneis the default option
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License.
Contact
pharos-lab - @pharOsLab - 1i6h7h0u53.lighthouse@gmail.com
Project Link: https://github.com/pharos-lab/blink