Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.

Commit 3e5ddb0

Browse files
authored
refactor: migrate to Nx (#34)
1 parent 2352b73 commit 3e5ddb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+9656
-4828
lines changed

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add files here to ignore them from prettier formatting
2+
3+
/dist
4+
/coverage

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5"
4+
}

.travis.yml

-25
This file was deleted.

.vscode/extensions.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"nrwl.angular-console",
4+
"angular.ng-template",
5+
"ms-vscode.vscode-typescript-tslint-plugin",
6+
"esbenp.prettier-vscode"
7+
]
8+
}

LICENSE

-21
This file was deleted.

README.md

+102-91
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
[![Quality Gate](https://sonarcloud.io/api/project_badges/quality_gate?project=bikecoders_ngx-sticky)](https://sonarcloud.io/dashboard?id=bikecoders_ngx-sticky) [![Sonar Cloud](https://sonarcloud.io/images/project_badges/sonarcloud-white.svg)](https://sonarcloud.io/dashboard?id=bikecoders_ngx-sticky)
88

9-
10-
## TL;DR:
9+
## TL;DR
1110

1211
Angular directive that adds sticky position to an HTML element and also applies and remove a custom class when the element is sticky positioned.
1312

@@ -16,7 +15,7 @@ Angular directive that adds sticky position to an HTML element and also applies
1615
<div
1716
ngxSticky
1817
classWhenSticky="my-sticky-class"
19-
triggerOn="text-content"
18+
[triggerOn]="'text-content'"
2019
[scrollContainer]="scContainer"
2120
>
2221
Sticky Title
@@ -26,19 +25,22 @@ Angular directive that adds sticky position to an HTML element and also applies
2625
</div>
2726
</div>
2827
```
29-
[![Quick Demo](https://raw.githubusercontent.com/bikecoders/ngx-sticky/master/docs-img/demo-capture.gif)]()
28+
29+
![Quick Demo](https://raw.githubusercontent.com/bikecoders/ngx-sticky/master/docs-img/demo-capture.gif)
3030

3131
## How to use it
3232

3333
To accomplish the desired behavior you need to take in account the following:
34-
- You need to have a scroll container
35-
- Inside the scroll container you need:
36-
- The sticky element
37-
- An element that when the sticky element bypass it, the directive will trigger the custom class. We call this _triggerOn_ element
38-
- The _triggerOn_ element **must** be relative positioned (has this css property `position: relative`)
39-
- > _We decided that you control this, because adding `position: relative` to an element can change the visual aspect to something not desired and you will asking why and blaming yourself for something that you are not conscious of, so following the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) this directive will not take care of that_
34+
35+
- You need to have a scroll container
36+
- Inside the scroll container you need:
37+
- The sticky element
38+
- An element that when the sticky element bypass it, the directive will trigger the custom class. We call this _triggerOn_ element
39+
- The _triggerOn_ element **must** be relative positioned (has this css property `position: relative`)
40+
- > _We decided that you control this, because adding `position: relative` to an element can change the visual aspect to something not desired and you will asking why and blaming yourself for something that you are not conscious of, so following the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) this directive will not take care of that_
4041
4142
`dummy.component.scss`
43+
4244
```scss
4345
.scroll-container {
4446
border: #cccccc 1px solid;
@@ -48,7 +50,7 @@ To accomplish the desired behavior you need to take in account the following:
4850
}
4951

5052
.title {
51-
background-color: #1C5089;
53+
background-color: #1c5089;
5254
color: #ffffff;
5355
font-size: 32px;
5456
font-weight: bold;
@@ -61,18 +63,20 @@ To accomplish the desired behavior you need to take in account the following:
6163
}
6264

6365
.my-sticky-class {
64-
background-color: #1C8950 !important;
65-
box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12), 0 3px 5px -1px rgba(0, 0, 0, 0.4);
66+
background-color: #1c8950 !important;
67+
box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12),
68+
0 3px 5px -1px rgba(0, 0, 0, 0.4);
6669
}
6770
```
6871

6972
`dummy.component.html`
73+
7074
```html
7175
<div #scContainer>
7276
<div
7377
ngxSticky
7478
class="title"
75-
triggerOn="trigger-on"
79+
[triggerOn]="'trigger-on'"
7680
classWhenSticky="my-sticky-class"
7781
[scrollContainer]="scContainer"
7882
>
@@ -84,101 +88,108 @@ To accomplish the desired behavior you need to take in account the following:
8488
</div>
8589
```
8690

91+
### Note
92+
93+
If you're using angular version >= 9 and providing the `triggerOn` value as a string, you need to do it this way `[triggerOn]="'text-content'"` because Ivy changed something about how we pass parameters. There is an [issue](https://github.com/angular/angular/issues/34227) open about it
94+
95+
According to [Ivy Compatibility guide](https://angular.io/guide/ivy-compatibility)
96+
97+
> Unbound inputs for directives (e.g. name in <my-comp name="">) are now set upon creation of the view, before change detection runs (previously, all inputs were set during change detection).
98+
8799
## Demo
88-
- online demo: https://bikecoders.github.io/ngx-sticky/
89-
- [demo-app](https://github.com/bikecoders/ngx-sticky/tree/master/src): Source code available
90100

101+
- [online demo](https://bikecoders.github.io/ngx-sticky/)
102+
- [demo-app](https://github.com/bikecoders/ngx-sticky/tree/master/src): Source code available
91103

92104
## Getting started
93105

94106
1. Install `ngx-sticky-directive`:
95107

96-
```bash
97-
# using npm
98-
npm install ngx-sticky-directive --save
108+
```bash
109+
# using npm
110+
npm install ngx-sticky-directive --save
99111

100-
# using yarn <3
101-
yarn add ngx-sticky-directive
102-
```
112+
# using yarn
113+
yarn add ngx-sticky-directive
114+
```
103115

104116
2. Import the installed library:
105117

106-
```ts
107-
import { StickyDirectiveModule } from 'ngx-sticky-directive';
118+
```ts
119+
import { StickyDirectiveModule } from 'ngx-sticky-directive';
108120

109-
@NgModule({
110-
...
111-
imports: [
112-
...
113-
StickyDirectiveModule
114-
]
115-
})
116-
export class AppModule { }
117-
```
121+
@NgModule({
122+
...
123+
imports: [
124+
...
125+
StickyDirectiveModule
126+
]
127+
})
128+
export class AppModule { }
129+
```
118130

119131
3. Use it in your component
120132

121-
```ts
122-
@Component({
123-
selector: 'dummy-component',
124-
styles: [`
125-
.body-container {
126-
background-color: yellow;
127-
height: 2000px;
128-
overflow: scroll;
129-
padding: 10px;
130-
}
131-
132-
.super-height {
133-
background-color: black;
134-
height: 5000px;
135-
position: relative;
136-
width: 100%;
137-
}
138-
139-
#sticky-component {
140-
background-color: green;
141-
height: 50px;
142-
width: 100%;
143-
top: -10px;
144-
z-index: 10;
145-
}
146-
147-
.when-sticky {
148-
background-color: magenta !important;
149-
}
150-
`],
151-
template: `
152-
<div class="body-container" #scCont>
153-
<div
154-
id="sticky-component"
155-
ngxSticky
156-
classWhenSticky="when-sticky"
157-
triggerOn="trigger-on"
158-
[scrollContainer]="scCont"
159-
>
160-
</div>
161-
<div id="trigger-on" class="super-height">
162-
</div>
163-
</div>
164-
`,
165-
})
166-
class DummyComponent {
167-
}
168-
```
133+
```ts
134+
@Component({
135+
selector: 'dummy-component',
136+
styles: [
137+
`
138+
.body-container {
139+
background-color: yellow;
140+
height: 2000px;
141+
overflow: scroll;
142+
padding: 10px;
143+
}
144+
145+
.super-height {
146+
background-color: black;
147+
height: 5000px;
148+
position: relative;
149+
width: 100%;
150+
}
151+
152+
#sticky-component {
153+
background-color: green;
154+
height: 50px;
155+
width: 100%;
156+
top: -10px;
157+
z-index: 10;
158+
}
159+
160+
.when-sticky {
161+
background-color: magenta !important;
162+
}
163+
`,
164+
],
165+
template: `
166+
<div class="body-container" #scCont>
167+
<div
168+
id="sticky-component"
169+
ngxSticky
170+
classWhenSticky="when-sticky"
171+
[triggerOn]="'trigger-on'"
172+
[scrollContainer]="scCont"
173+
></div>
174+
<div id="trigger-on" class="super-height"></div>
175+
</div>
176+
`,
177+
})
178+
class DummyComponent {}
179+
```
169180

170181
## Properties
171182

172-
| Name | Description |
173-
| :---- | :---------- |
174-
| `@Input() scrollContainer: string | ElementRef | HTMLElement` | Top container of the sticky element that has the scroll. _If an string is provided, it must be the ID of the element._ |
175-
| `@Input() triggerOn: string | ElementRef | HTMLElement` | When the sticky element bypass this element the custom class will apply. _If an string is provided, it must be the ID of the element._ |
176-
| `@Input() debugMode: boolean` | Display or hide the sentinel element. |
177-
| `@Input() classWhenSticky: string` | CSS class to be added to the target element when becomes sticky. |
178-
| `@Input() zIndex: number = 10` | CSS `zIndex` value to set to the target element. By default is 10. |
179-
| `@Input() top: number = 0` | CSS `top` value to set to the sticky element. By default is 0. |
183+
| Name | Description |
184+
| :------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------- |
185+
| `@Input() scrollContainer: string | ElementRef | HTMLElement` | Top container of the sticky element that has the scroll. _If an string is provided, it must be the ID of the element._ |
186+
| `@Input() triggerOn: string | ElementRef | HTMLElement` | When the sticky element bypass this element the custom class will apply. _If an string is provided, it must be the ID of the element._ |
187+
| `@Input() debugMode: boolean` | Display or hide the sentinel element. |
188+
| `@Input() classWhenSticky: string` | CSS class to be added to the target element when becomes sticky. |
189+
| `@Input() zIndex: number = 10` | CSS `zIndex` value to set to the target element. By default is 10. |
190+
| `@Input() top: number = 0` | CSS `top` value to set to the sticky element. By default is 0. |
180191

181-
## Why?
192+
## Why
182193

183194
Adding a custom class when an element becomes sticky is the objective of this directive. This is achieved by using [Intersection Observer](https://developer.mozilla.org/docs/Web/API/Intersection_Observer_API) and avoid using scroll events to keep a good performance.
184195

@@ -193,10 +204,10 @@ The intention of this directive is to implement the article [An event for CSS po
193204
> The Intersection Observer API is highly [supported](https://caniuse.com/#feat=intersectionobserver) across the different browsers, however if you have a target audience that is not currently being supported you can use the [Intersection Observer Polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill)
194205
195206
### References
207+
196208
- [An event for CSS position:sticky](https://developers.google.com/web/updates/2017/09/sticky-headers)
197209
- [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Creating_an_intersection_observer)
198210

199-
200211
## Development tips
201212

202213
If you want to contribute with features, we recommend to read the section that we wrote about Development Tips that is in the

0 commit comments

Comments
 (0)