-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
439f5c9
commit 0eaf476
Showing
19 changed files
with
103 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { LitElement } from 'lit'; | ||
import { property } from 'lit/decorators.js'; | ||
|
||
import type { AbstractConstructor } from './constructor.js'; | ||
|
||
export declare class SbbNowMixinType { | ||
public set now(value: number | string); | ||
public get now(): number; | ||
protected get dateNow(): number; | ||
} | ||
|
||
/** | ||
* Enhance your component with a `now` property. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const SbbNowMixin = <T extends AbstractConstructor<LitElement>>( | ||
superClass: T, | ||
): AbstractConstructor<SbbNowMixinType> & T => { | ||
abstract class SbbNowElement extends superClass implements Partial<SbbNowMixinType> { | ||
/** A specific date for the current datetime (timestamp in milliseconds). */ | ||
@property({ type: Number }) | ||
public get now(): number | undefined { | ||
return this._now; | ||
} | ||
public set now(value: number | string) { | ||
this._now = +value; | ||
} | ||
private _now?: number; | ||
|
||
/** Returns the `_now` value if available, otherwise the current datetime (as timestamp in millisecond). */ | ||
protected get dateNow(): number { | ||
return this._now ?? Date.now(); | ||
} | ||
} | ||
|
||
return SbbNowElement as unknown as AbstractConstructor<SbbNowMixinType> & T; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.