Download react-spring/packages/animated/src/AnimatedString.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedString.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedString.ts
-
curl -L -o AnimatedString.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/packages/animated/src/AnimatedString.ts
1.16 kB
| import { AnimatedValue } from './AnimatedValue' | |
| import { is, createInterpolator } from '@react-spring/shared' | |
| type Value = string | number | |
| export class AnimatedString extends AnimatedValue<Value> { | |
| declare protected _value: number | |
| protected _string: string | null = null | |
| protected _toString: (input: number) => string | |
| constructor(value: string) { | |
| super(0) | |
| this._toString = createInterpolator({ | |
| output: [value, value], | |
| }) | |
| } | |
| /** @internal */ | |
| static create(value: string) { | |
| return new AnimatedString(value) | |
| } | |
| getValue() { | |
| const value = this._string | |
| return value == null ? (this._string = this._toString(this._value)) : value | |
| } | |
| setValue(value: Value) { | |
| if (is.str(value)) { | |
| if (value == this._string) { | |
| return false | |
| } | |
| this._string = value | |
| this._value = 1 | |
| } else if (super.setValue(value)) { | |
| this._string = null | |
| } else { | |
| return false | |
| } | |
| return true | |
| } | |
| reset(goal?: string) { | |
| if (goal) { | |
| this._toString = createInterpolator({ | |
| output: [this.getValue(), goal], | |
| }) | |
| } | |
| this._value = 0 | |
| super.reset() | |
| } | |
| } | |