Skip to content

Commit

Permalink
refactor: 💡 Rename directive inputs
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
* Rename `tippy` to `tp`
* Prefix all inputs with `tp`
* Rename `lazy` input to `tpIsLazy`
  • Loading branch information
shaharkazaz committed Mar 9, 2023
1 parent a349e30 commit cc1a5a6
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 161 deletions.
25 changes: 5 additions & 20 deletions .github/workflows/helipopper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,21 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
strategy:
fail-fast: true

steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
id: npm-cache
with:
# We also specify `~/.cache` because Cypress binary is installed
# in that location.
path: |
node_modules
~/.cache
key: ${{ runner.os }}-v1-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-v1-npm

- uses: actions/setup-node@v3
- name: Npm install
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
# If checksum for the `package-lock.json` hasn't changed then we shouldn't run
# `npm ci` because it will hit the `postinstall` hook
# that will run `ngcc` compiler accordingly.
if: steps.npm-cache.outputs.cache-hit != 'true'
cache: 'npm'
env:
HUSKY_SKIP_INSTALL: 'true'
run: npm ci
- run: npm i

- name: Build library
run: npm run build:lib
Expand Down
88 changes: 46 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ You have the freedom to [customize](https://atomiks.github.io/tippyjs/v6/themes/
Import the standalone `TippyDirective` and use it in your templates:

```html
<button tippy="Helpful Message">
<button tp="Helpful Message">
I have a tooltip
</button>
```
Expand All @@ -95,7 +95,7 @@ export const tooltipVariation = {
### Use `TemplateRef` as content

```html
<button [tippy]="tpl" variation="popper">
<button [tp]="tpl" tpVariation="popper">
Click Me
</button>

Expand All @@ -117,7 +117,7 @@ class MyComponent {
```

```html
<button [tippy]="MyComponent">
<button [tp]="MyComponent">
Click Me
</button>
```
Expand All @@ -128,7 +128,7 @@ You can pass the `onlyTextOverflow` input to show the tooltip only when the host

```html
<div style="max-width: 100px;" class="overflow-hidden flex">
<p class="ellipsis" [tippy]="text" placement="right" [onlyTextOverflow]="true">
<p class="ellipsis" [tp]="text" tpPlacement="right" [tpOnlyTextOverflow]="true">
{{ text }}
</p>
</div>
Expand All @@ -141,20 +141,20 @@ Note that it's using [`ResizeObserver`](https://caniuse.com/resizeobserver) api.
You can instruct tippy to use the element textContent as the tooltip content:

```html
<p tippy useTextContent>
<p tp tpUseTextContent>
{{ text }}
</p>
```


### Lazy

You can pass the `lazy` input when you want to defer the creation of tippy only when the element is in the view:
You can pass the `tpIsLazy` input when you want to defer the creation of tippy only when the element is in the view:

```html
<div *ngFor="let item of items"
[tippy]="item.label"
[lazy]="true">{{ item.label }}
[tp]="item.label"
[tpIsLazy]="true">{{ item.label }}
</div>
```

Expand Down Expand Up @@ -196,9 +196,9 @@ Now you can use it in your template:

<ul>
<li *ngFor="let item of list"
[tippy]="contextMenu"
[data]="item"
variation="contextMenu">
[tp]="contextMenu"
[tpData]="item"
tpVariation="contextMenu">
{{ item.label }}
</li>
</ul>
Expand All @@ -207,20 +207,20 @@ Now you can use it in your template:
### Manual Trigger

```html
<div tippy="Helpful Message" trigger="manual" #tooltip="tippy">
<div tp="Helpful Message" tpTrigger="manual" #tooltip="tippy">
Click Open to see me
</div>

<button (click)="tooltip.show()">Open</button>
<button (click)="tooltip.hide()">Close</button>
```

### Show/hide declarativly
### Declarative show/hide

Use isVisible to trigger show and hide. Set trigger to manual.

```html
<div tippy="Helpful Message" trigger="manual" [isVisible]="visibility">
<div tp="Helpful Message" tpTrigger="manual" [tpIsVisible]="visibility">
Click Open to see me
</div>

Expand All @@ -235,38 +235,42 @@ live [here](https://ngneat.github.io/helipopper/).
### Inputs

```ts
appendTo: TippyProps['appendTo'];
delay: TippyProps['delay'];
duration: TippyProps['duration'];
hideOnClick: TippyProps['hideOnClick'];
interactive: TippyProps['interactive'];
interactiveBorder: TippyProps['interactiveBorder'];
maxWidth: TippyProps['maxWidth'];
offset: TippyProps['offset'];
placement: TippyProps['placement'];
popperOptions: TippyProps['popperOptions'];
showOnCreate: TippyProps['showOnCreate'];
trigger: TippyProps['trigger'];
triggerTarget: TippyProps['triggerTarget'];
zIndex: TippyProps['zIndex'];
tippyHost: HTMLElement;

useTextContent: boolean;
lazy: boolean;
variation: string;
isEnabled: boolean;
isVisible: boolean;
className: string;
onlyTextOverflow: boolean;
useHostWidth: boolean;
hideOnEscape: boolean;
data: any;
tp: string | TemplateRef<any> | Type<any> | undefined | null;
tpAppendTo: TippyProps['appendTo'];
tpDelay: TippyProps['delay'];
tpDuration: TippyProps['duration'];
tpHideOnClick: TippyProps['hideOnClick'];
tpInteractive: TippyProps['interactive'];
tpInteractiveBorder: TippyProps['interactiveBorder'];
tpMaxWidth: TippyProps['maxWidth'];
tpOffset: TippyProps['offset'];
tpPlacement: TippyProps['placement'];
tpPopperOptions: TippyProps['popperOptions'];
tpShowOnCreate: TippyProps['showOnCreate'];
tpTrigger: TippyProps['trigger'];
tpTriggerTarget: TippyProps['triggerTarget'];
tpZIndex: TippyProps['zIndex'];
tpAnimation: TippyProps['animation'];
tpUseTextContent: boolean;
tpIsLazy: boolean;
tpVariation: string;
tpIsEnabled: boolean;
tpIsVisible: boolean;
tpClassName: string;
tpOnlyTextOverflow: boolean;
tpData: any;
tpUseHostWidth: boolean;
tpHideOnEscape: boolean;
tpDetectChangesComponent: boolean;
tpPopperWidth: number | string;
tpHost: HTMLElement;
tpIsVisible: boolean;
```

### Outputs

```ts
visible = new EventEmitter<boolean>();
tpVisible = new EventEmitter<boolean>();
```

### Global Config
Expand All @@ -280,8 +284,8 @@ import { TippyService, TippyInstance } from '@ngneat/helipopper';

class Component {
@ViewChild('inputName') inputName: ElementRef;
tippy: TippyInstance;
private tippyService = inject(TippyService);
tippy:TippyInstance;

show() {
if(!this.tippy) {
Expand Down
168 changes: 168 additions & 0 deletions migrations/v7-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# v7 Migration

In v7 all the inputs of the `TippyDirective` are now prefixed with `tippy`.

You can use the following search-n-replace script to help you migrate to the latest version:

```js
const glob = require('glob');
const fs = require('node:fs');

function getFiles(ext) {
return glob.sync(`**/*.${ext}`, {ignore: ['node_modules/**', 'dist/**', 'tmp/**', 'coverage/**']});
}

const files = getFiles('html').concat(getFiles('component.ts'));

const inputMappings = [
[
"appendTo",
"tpAppendTo"
],
[
"delay",
"tpDelay"
],
[
"duration",
"tpDuration"
],
[
"hideOnClick",
"tpHideOnClick"
],
[
"interactive",
"tpInteractive"
],
[
"interactiveBorder",
"tpInteractiveBorder"
],
[
"maxWidth",
"tpMaxWidth"
],
[
"offset",
"tpOffset"
],
[
"placement",
"tpPlacement"
],
[
"popperOptions",
"tpPopperOptions"
],
[
"showOnCreate",
"tpShowOnCreate"
],
[
"trigger",
"tpTrigger"
],
[
"triggerTarget",
"tpTriggerTarget"
],
[
"zIndex",
"tpZIndex"
],
[
"animation",
"tpAnimation"
],
[
"useTextContent",
"tpUseTextContent"
],
[
"lazy",
"tpIsLazy"
],
[
"variation",
"tpVariation"
],
[
"isEnabled",
"tpIsEnabled"
],
[
"className",
"tpClassName"
],
[
"onlyTextOverflow",
"tpOnlyTextOverflow"
],
[
"useHostWidth",
"tpUseHostWidth"
],
[
"hideOnEscape",
"tpHideOnEscape"
],
[
"detectChangesComponent",
"tpDetectChangesComponent"
],
[
"popperWidth",
"tpPopperWidth"
],
[
"customHost",
"tpHost"
],
[
"isVisible",
"tpIsVisible"
],
[
"data",
"tpData"
],
[
"tippy",
"tp"
]
];
const outputMapping = [['visible', 'tpVisible']];
let updatedFiles = 0;

for (const file of files) {
const content = fs.readFileSync(file, {encoding: "utf-8"});
if (!content.includes('tippy')) {
continue;
}

let updated = content;
for (const [prev, current] of inputMappings) {
const matcher = new RegExp(`(?<![\\w'"-\\.])${prev}(?![\\w'"-\\.])`, 'g');
updated = updated.replace(matcher, current);
}

for (const [prev, current] of outputMapping) {
const matcher = new RegExp(`\\(${prev}\\)`, 'g');
updated = updated.replace(matcher, `(${current})`);
}

if(updated !== content) {
updatedFiles++;
}

fs.writeFileSync(file, updated, {encoding: "utf-8"});
}

console.log(`Scanned a total of ${files.length} files and updated ${updatedFiles} of them.`);
```

Make sure you review which keywords are going to be matched since some previous tippy input
names might be used in other components in your system. (e.g. `data`).

This script will help you with most of the replacements but please review the replaced files after running it.
Loading

0 comments on commit cc1a5a6

Please sign in to comment.