From b634a3c5885471416e2ae5692e73a37f83ed5908 Mon Sep 17 00:00:00 2001 From: Sub-Xaero Date: Fri, 21 May 2021 02:06:23 +0100 Subject: [PATCH] feat: DurationController - A controller to display the duration that has elapsed since a given timestamp. Similar to TimeDistanceController, but with numbers instead of words. --- docs/docs/controllers/duration_controller.mdx | 59 ++++++++++ docs/sidebars.js | 1 + src/controllers/visual/duration_controller.ts | 106 ++++++++++++++++++ src/index.ts | 1 + 4 files changed, 167 insertions(+) create mode 100644 docs/docs/controllers/duration_controller.mdx create mode 100644 src/controllers/visual/duration_controller.ts diff --git a/docs/docs/controllers/duration_controller.mdx b/docs/docs/controllers/duration_controller.mdx new file mode 100644 index 00000000..5f7560e9 --- /dev/null +++ b/docs/docs/controllers/duration_controller.mdx @@ -0,0 +1,59 @@ +--- +id: DurationController +title: DurationController +--- + +import NoEvents from "../_partials/no-events.md"; +import NoActions from "../_partials/no-actions.md"; +import NoClasses from "../_partials/no-classes.md"; +import NoTargets from "../_partials/no-targets.md"; + + +## Purpose + +A controller that displays the distance in numbers between the specified time and the current time. Works for past dates. +Similar to TimeDistance controller, but outputs fully qualified numbers for the duration rather than trying to construct a sentence. + +Implemented using https://date-fns.org/v2.21.1/docs/formatDuration. + +Fire and forget. The only configuration this controller takes is the timestamp, and whether to show seconds/minutes. + +## [Actions](https://stimulus.hotwire.dev/reference/actions) + + + +## [Targets](https://stimulus.hotwire.dev/reference/targets) + + + +## [Classes](https://stimulus.hotwire.dev/reference/classes) + + + +## [Values](https://stimulus.hotwire.dev/reference/values) + +| Value | Type | Description | Default | +| --- | --- | --- | --- | +| `timestamp` | String | The UNIX timestamp in seconds of the date/time to show "time elapsed" for | - | +| `minutes` (Optional) | Number | Whether or not to show minutes in the outputted string | true | +| `seconds` (Optional) | Number | Whether or not to show seconds in the outputted string | true | + +## Events + + + +## Side Effects + +The controller will intelligently set a `setTimeout` according to the fastest unit of time shown. If minutes/seconds are hidden, then the controller will update less frequently. + +All timeouts are cleaned up when the controller disconnects. + +## How to Use + +