Skip to content

Commit c9cbcdb

Browse files
State class updates (#4)
* Fixed issue with ngClass for default node and value classes which was occuring in Ivy by switching to class. Added positive and negative state classes. Updated documentation. * Added ngAfterViewInit for initial positivity check * updated package version manually to be ready for publish * updated README checklist to accurately reflect todos
1 parent f5a857d commit c9cbcdb

4 files changed

Lines changed: 64 additions & 9 deletions

File tree

README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This component is perfect for:
2525

2626
- Small, simple, configurable, performant
2727
- Maintained by a team of finance industry professionals
28+
- Includes linting, prettier & unit test validations
2829

2930

3031
## Table of contents
@@ -38,7 +39,7 @@ This component is perfect for:
3839

3940
## Demo
4041

41-
Hosted demo: TBD
42+
Hosted Storybook demo: [https://main--60be66a91843f400393d1747.chromatic.com/](https://main--60be66a91843f400393d1747.chromatic.com/)
4243

4344
You can also run the demo locally. To get started:
4445

@@ -61,7 +62,7 @@ npm install angular-value-flash
6162
## Usage
6263

6364
```js
64-
// Include in an @ngModule:
65+
// Include in a module:
6566
import { ValueFlashModule } from 'angular-value-flash';
6667
...
6768
@NgModule({
@@ -78,11 +79,47 @@ import { ValueFlashModule } from 'angular-value-flash';
7879
</value-flash>
7980
```
8081
82+
There are a number of classnames you can use to add your own styles. This [Storybook example](https://60be66a91843f400393d1747-pyomkpvvzt.chromatic.com/?path=/story/components-value-flash--make-it-nice) demonstrates a potential custom styling. Find the story source code [here](https://github.com/lab49/angular-value-flash/blob/main/stories/ValueFlash.stories.ts#L86) and the SCSS used [here](https://github.com/lab49/angular-value-flash/blob/main/stories/styles/make-it-nice-theme.scss). Below is a list of all the available classnames, with the default `.rvf_Flash` prefix.
83+
84+
_Note that due to view encapsulation, these styles will need to be included in global CSS/SCSS files, so be sure to properly scope the styles using wrapper `div` elements or by using specific prefixes as input to the `value-flash` component._
85+
86+
| Class | Description |
87+
| --- | --- |
88+
| `.rvf_Flash` | Root DOM node |
89+
| `.rvf_Flash__value` | Rendered value, direct (and only) child of the root node. |
90+
| `.rvf_Flash--flashing` | Applied only when the component is in the flashing state. |
91+
| `.rvf_Flash--flashing-up` | Applied when flashing 'up'. |
92+
| `.rvf_Flash--flashing-down` | Applied when flashing 'down'. |
93+
| `.rvf_Flash--positive` | Applied when the value is positive. |
94+
| `.rvf_Flash--negative` | Applied when the value is negative. |
95+
96+
8197
###### [⇡ Top](#table-of-contents)
8298
8399
## API
84100
85-
_To be completed_
101+
### Directives
102+
103+
#### `ValueFlashComponent`
104+
105+
Selector: `value-flash`
106+
107+
Exported As: `ValueFlashComponent`
108+
109+
#### Properties
110+
111+
| Name | Default | Description |
112+
| --- | --- | --- |
113+
| @Input() downColor: string | 'red' | Color value when the component flashes 'down'. |
114+
| @Input() formatter: FormatterType | 'default' | Value display formatter type. Options are: 'currency', 'percentage', 'number', 'default'. See formatter definititions [here](https://github.com/lab49/angular-value-flash/blob/main/projects/value-flash/src/lib/formatters/index.ts). |
115+
| @Input() formatterFn: Formatter | | Custom formatter to use. Overrides `formatter` input. |
116+
| @Input() stylePrefix: string | 'rvf_Flash' | Class for root DOM node and prefix for flashing states, positive/negative states, and value node. |
117+
| @Input() timeout: number | 200 | Amount of time the flashed state is visible for, in milliseconds. |
118+
| @Input() transition: string | | Custom CSS transition property. |
119+
| @Input() transitionLength: number | 100 | Transition length, in milliseconds. |
120+
| @Input() upColor: string | 'green' | Color value when the component flashes 'up'. |
121+
| @Input() value: number | 0 | Value to display. |
122+
86123
87124
## License
88125
@@ -94,15 +131,14 @@ MIT @ [Lab49](https://lab49.com)
94131
95132
These items are very high level right now. Further discussion and proper roadmap planning will happen in GitHub issues and projects.
96133
97-
- [ ] Incorporate linting and unit tests into GitHub Action CI builds.
98134
- [ ] Finalize CI process for publishing.
99135
- [ ] Add a code of conduct.
100136
- [ ] Add a contributing guide.
101137
- [ ] Create a feature roadmap.
102138
- [ ] Publish code coverage to codecov.io.
103139
- [ ] Finanlize README.md (logo, coverage/version link info, API documentation).
104-
- [ ] Complete Chromatic setup and incorporate into CI/CD.
105140
- [ ] Expand Storybook demos.
141+
- [ ] Expand unit tests.
106142
107143
## Sponsored by Lab49
108144

projects/value-flash/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-value-flash",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Flash on value change. Perfect for financial applicaitons.",
55
"license": "MIT",
66
"repository": "@lab49/angular-value-flash",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div [ngClass]="stylePrefix" #valueHolder>
2-
<span [ngClass]="stylePrefix + '__value'">{{ formattedValue }}</span>
1+
<div [class]="stylePrefix" #valueHolder>
2+
<span [class]="stylePrefix + '__value'">{{ formattedValue }}</span>
33
</div>

projects/value-flash/src/lib/value-flash.component.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AfterViewInit,
23
ChangeDetectionStrategy,
34
Component,
45
ElementRef,
@@ -16,7 +17,7 @@ import { Formatter, formatters, FormatterType } from './formatters';
1617
changeDetection: ChangeDetectionStrategy.OnPush,
1718
styles: [],
1819
})
19-
export class ValueFlashComponent implements OnChanges {
20+
export class ValueFlashComponent implements OnChanges, AfterViewInit {
2021
// #region Properties (11)
2122

2223
/**
@@ -116,6 +117,7 @@ export class ValueFlashComponent implements OnChanges {
116117
}
117118
clearTimeout(this.animationTimeout);
118119
this.animationTimeout = setTimeout(() => this.clearFlashingState(), this.timeout);
120+
this.handleValuePositivity();
119121
}
120122

121123
public ngOnChanges(changes: SimpleChanges): void {
@@ -124,6 +126,10 @@ export class ValueFlashComponent implements OnChanges {
124126
}
125127
}
126128

129+
public ngAfterViewInit() {
130+
this.handleValuePositivity();
131+
}
132+
127133
// #endregion Public Methods (3)
128134

129135
// #region Private Methods (1)
@@ -139,5 +145,18 @@ export class ValueFlashComponent implements OnChanges {
139145
this.valueHolder.style.backgroundColor = '';
140146
}
141147

148+
private handleValuePositivity() {
149+
if (this.value > 0) {
150+
this.valueHolder.classList.add(this.stylePrefix + '--positive');
151+
} else {
152+
this.valueHolder.classList.remove(this.stylePrefix + '--positive');
153+
}
154+
if (this.value < 0) {
155+
this.valueHolder.classList.add(this.stylePrefix + '--negative');
156+
} else {
157+
this.valueHolder.classList.remove(this.stylePrefix + '--negative');
158+
}
159+
}
160+
142161
// #endregion Private Methods (1)
143162
}

0 commit comments

Comments
 (0)