Skip to content

Commit

Permalink
feat(ng2-gauge): drop required: true input metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkgs committed Feb 4, 2024
1 parent 62ed074 commit 32de5d2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- Gauge input is now limited by the max value
- Improved validation
- Changed component input names to better and more descriptive ones (see **Breaking changes**)
- `max` and `value` are now required
- Fixed issue #5
- Other smaller improvements
- Project upgraded to Angular 17
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class MyComponent {
The component provides a list of the following options:

- **`max: number`** _(required)_ – The maximal value of the gauge. It is suggested to use a number that is divisible by 10^n (e.g. 100, 1000, etc.)
- **`value: number`** _(required)_ – The current value of the gauge
- **`value: number`** – The current value of the gauge
- **`unit: string`** – The unit of the gauge (i.e. mph, psi, etc.)
- **`size: number`** – Size/width of the gauge _in pixels_
- **`arcStart: number`** – The start/beginning of the scale arc _in degrees_. Default `225`
Expand Down
5 changes: 3 additions & 2 deletions projects/ng2-gauge/src/lib/gauge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class GaugeComponent implements OnInit, AfterViewInit, GaugeProps {
/**
* The current value of the gauge
*/
@Input({ required: true })
@Input()
set value(val: number) {
this._value = Math.min(val, this._max);
this._updateArrowPos(this._value);
Expand All @@ -112,7 +112,8 @@ export class GaugeComponent implements OnInit, AfterViewInit, GaugeProps {
/**
* The maximal value of the gauge. It is suggested to use a number that is divisible by 10^n (e.g. 100, 1000, etc.)
*/
@Input({ required: true })
// Note(Georgi): Don't use { require: true } since it's v16+ only
@Input()
set max(val: number) {
if (this._max) {
this._max = val;
Expand Down
4 changes: 4 additions & 0 deletions projects/ng2-gauge/src/lib/shared/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const error = (text: string, throwErr?: boolean) => {
};

export const validate = (props: GaugeProps) => {
if (!props.max) {
error('Missing "max" input property', true);
}

if (
!(0 <= props.arcStart && props.arcStart <= 359) ||
!(0 <= props.arcEnd && props.arcEnd <= 359)
Expand Down

0 comments on commit 32de5d2

Please sign in to comment.