diff --git a/.github/workflows/helipopper.yml b/.github/workflows/helipopper.yml index 9da433e..bafac0b 100644 --- a/.github/workflows/helipopper.yml +++ b/.github/workflows/helipopper.yml @@ -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 diff --git a/README.md b/README.md index d5f6e3b..6178ddd 100644 --- a/README.md +++ b/README.md @@ -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 - ``` @@ -95,7 +95,7 @@ export const tooltipVariation = { ### Use `TemplateRef` as content ```html - @@ -117,7 +117,7 @@ class MyComponent { ``` ```html - ``` @@ -128,7 +128,7 @@ You can pass the `onlyTextOverflow` input to show the tooltip only when the host ```html
-

+

{{ text }}

@@ -141,7 +141,7 @@ 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 -

+

{{ text }}

``` @@ -149,12 +149,12 @@ You can instruct tippy to use the element textContent as the tooltip content: ### 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
{{ item.label }} + [tp]="item.label" + [tpIsLazy]="true">{{ item.label }}
``` @@ -196,9 +196,9 @@ Now you can use it in your template: @@ -207,7 +207,7 @@ Now you can use it in your template: ### Manual Trigger ```html -
+
Click Open to see me
@@ -215,12 +215,12 @@ Now you can use it in your template: ``` -### Show/hide declarativly +### Declarative show/hide Use isVisible to trigger show and hide. Set trigger to manual. ```html -
+
Click Open to see me
@@ -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 | Type | 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(); +tpVisible = new EventEmitter(); ``` ### Global Config @@ -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) { diff --git a/migrations/v7-migration.md b/migrations/v7-migration.md new file mode 100644 index 0000000..df04b8c --- /dev/null +++ b/migrations/v7-migration.md @@ -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(`(?(); - @Input() public isVisible = false; + @Input('tp') content: Content | undefined | null; + @Input('tpAppendTo') appendTo: TippyProps['appendTo']; + @Input('tpDelay') delay: TippyProps['delay']; + @Input('tpDuration') duration: TippyProps['duration']; + @Input('tpHideOnClick') hideOnClick: TippyProps['hideOnClick']; + @Input('tpInteractive') interactive: TippyProps['interactive']; + @Input('tpInteractiveBorder') interactiveBorder: TippyProps['interactiveBorder']; + @Input('tpMaxWidth') maxWidth: TippyProps['maxWidth']; + @Input('tpOffset') offset: TippyProps['offset']; + @Input('tpPlacement') placement: TippyProps['placement']; + @Input('tpPopperOptions') popperOptions: TippyProps['popperOptions']; + @Input('tpShowOnCreate') showOnCreate: TippyProps['showOnCreate']; + @Input('tpTrigger') trigger: TippyProps['trigger']; + @Input('tpTriggerTarget') triggerTarget: TippyProps['triggerTarget']; + @Input('tpZIndex') zIndex: TippyProps['zIndex']; + @Input('tpAnimation') animation: TippyProps['animation']; + @Input('tpUseTextContent') useTextContent: boolean; + @Input('tpIsLazy') isLazy: boolean; + @Input('tpVariation') variation: string; + @Input('tpIsEnabled') isEnabled: boolean; + @Input('tpClassName') className: string | string[]; + @Input('tpOnlyTextOverflow') onlyTextOverflow = false; + @Input('tpData') data: any; + @Input('tpUseHostWidth') useHostWidth = false; + @Input('tpHideOnEscape') hideOnEscape = false; + @Input('tpDetectChangesComponent') detectChangesComponent = true; + @Input('tpPopperWidth') popperWidth: number | string; + @Input('tpHost') customHost: HTMLElement; + @Input('tpIsVisible') isVisible = false; + + @Output('tpVisible') visible = new EventEmitter(); protected instance: TippyInstance; protected viewRef: ViewRef; @@ -150,7 +146,7 @@ export class TippyDirective implements OnChanges, AfterViewInit, OnDestroy, OnIn if (isPlatformServer(this.platformId)) return; this.zone.runOutsideAngular(() => { - if (this.lazy) { + if (this.isLazy) { if (this.onlyTextOverflow) { inView(this.host) .pipe( diff --git a/src/app/is-visible/isVisible.component.html b/src/app/is-visible/isVisible.component.html index 8acde86..92afa7d 100644 --- a/src/app/is-visible/isVisible.component.html +++ b/src/app/is-visible/isVisible.component.html @@ -1,16 +1,16 @@ -
Declaritive visibility (already set true before render in the component)
+
Declarative visibility (already set true before render in the component)
diff --git a/src/app/playground/playground.component.html b/src/app/playground/playground.component.html index 141014d..54bdbe3 100644 --- a/src/app/playground/playground.component.html +++ b/src/app/playground/playground.component.html @@ -31,10 +31,10 @@
@@ -46,7 +46,7 @@
Default variation
- +

@@ -55,23 +55,19 @@
Default variation
NIL values
-
-
-
@@ -83,7 +79,7 @@
NIL values
Custom Template
- + Visible: {{ tippy2.isVisible }}
@@ -97,7 +93,7 @@
Custom Template
ng-container
- +
@@ -122,10 +118,10 @@
Custom Component
@@ -138,7 +134,7 @@
Custom Component
Manual Trigger
-

Click open to see me

+

Click open to see me

@@ -150,7 +146,7 @@
Manual Trigger
Lazy
-
{{ item.label }}
+
{{ item.label }}
@@ -160,10 +156,10 @@
Lazy
Disabled
- +
- +

@@ -173,7 +169,7 @@
Text Overflow

Start with overflow and change to not overflow

-

+

{{ text }}

@@ -184,7 +180,7 @@
Text Overflow

Start with not overflow and change to overflow

-

+

{{ text }}

@@ -197,7 +193,7 @@
Text Overflow
Show on Create
-
@@ -208,12 +204,12 @@
Declaritive visibility (already set true before render in the component)
@@ -274,14 +276,14 @@
Use host width
Menu