@cfasim-ui/docs 0.3.17 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,12 @@ const ageRange = ref([18, 65])
16
16
  const coverageRange = ref([0.2, 0.8])
17
17
  const minAge = ref(18)
18
18
  const maxAge = ref(65)
19
+ const dayMs = 24 * 60 * 60 * 1000
20
+ const dateStart = Date.UTC(2024, 0, 1)
21
+ const dateEnd = Date.UTC(2024, 11, 31)
22
+ const dateRange = ref([Date.UTC(2024, 2, 1), Date.UTC(2024, 8, 30)])
23
+ const formatDate = (ms) =>
24
+ new Date(ms).toLocaleDateString("en-US", { month: "short", day: "numeric" })
19
25
  </script>
20
26
 
21
27
  <ComponentDemo>
@@ -226,6 +232,51 @@ Range mode works with `percent` and `live` as well:
226
232
  </template>
227
233
  </ComponentDemo>
228
234
 
235
+ ### Custom slider display
236
+
237
+ Pass `slider-display` (a `(value: number) => string` function) to format the
238
+ thumb labels and the min/max labels however you like. The internal model is
239
+ still a number — only the displayed text changes. This applies to single
240
+ sliders and ranges; the regular text input is unaffected.
241
+
242
+ <ComponentDemo>
243
+ <div style="width: 300px">
244
+ <NumberInput
245
+ v-model:range="dateRange"
246
+ label="Date range"
247
+ :min="dateStart"
248
+ :max="dateEnd"
249
+ :step="dayMs"
250
+ :slider-display="formatDate"
251
+ />
252
+ </div>
253
+
254
+ <template #code>
255
+
256
+ ```vue
257
+ <script setup>
258
+ import { ref } from "vue";
259
+ const dayMs = 24 * 60 * 60 * 1000;
260
+ const dateStart = Date.UTC(2024, 0, 1);
261
+ const dateEnd = Date.UTC(2024, 11, 31);
262
+ const dateRange = ref([Date.UTC(2024, 2, 1), Date.UTC(2024, 8, 30)]);
263
+ const formatDate = (ms) =>
264
+ new Date(ms).toLocaleDateString("en-US", { month: "short", day: "numeric" });
265
+ </script>
266
+
267
+ <NumberInput
268
+ v-model:range="dateRange"
269
+ label="Date range"
270
+ :min="dateStart"
271
+ :max="dateEnd"
272
+ :step="dayMs"
273
+ :slider-display="formatDate"
274
+ />
275
+ ```
276
+
277
+ </template>
278
+ </ComponentDemo>
279
+
229
280
  ### Live slider
230
281
 
231
282
  With `live`, the model updates while dragging the slider thumb rather than only on release.
@@ -415,4 +466,5 @@ the input visually.
415
466
  | `numberType` | `"integer" \| "float"` | No | — |
416
467
  | `required` | `boolean` | No | — |
417
468
  | `decimals` | `number` | No | — |
469
+ | `sliderDisplay` | `(value: number) =&gt; string` | No | — |
418
470
 
@@ -29,6 +29,10 @@ const props = defineProps<{
29
29
  numberType?: "integer" | "float";
30
30
  required?: boolean;
31
31
  decimals?: number;
32
+ // Custom formatter for slider thumb labels and min/max labels. Overrides
33
+ // the default percent/decimal formatting when provided. Only consulted in
34
+ // slider/range mode — the text input keeps its own number-shaped formatting.
35
+ sliderDisplay?: (value: number) => string;
32
36
  }>();
33
37
 
34
38
  function isRangeValue(v: unknown): v is NumberRange {
@@ -109,6 +113,7 @@ function roundToDecimals(v: number, d: number): number {
109
113
 
110
114
  function formatSliderValue(v: number | undefined) {
111
115
  if (v == null) return "";
116
+ if (props.sliderDisplay) return props.sliderDisplay(v);
112
117
  const d = displayDecimals.value;
113
118
  if (props.percent) return (v * 100).toFixed(d) + "%";
114
119
  return v.toLocaleString("en-US", {
package/index.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.17",
2
+ "version": "0.3.18",
3
3
  "package": "@cfasim-ui/docs",
4
4
  "content": {
5
5
  "components": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/docs",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "LLM-friendly component and chart documentation for cfasim-ui",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {