PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
jetpack / jetpack_vendor / automattic / jetpack-forms / src / modules / slider-field / view.js

view.js in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-forms/src/modules/slider-field/view.js

40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { store, getContext } from '@wordpress/interactivity';
2 import { computeSliderValuePosition } from '../../blocks/input-range/utils.js';
3
4 const NAMESPACE = 'jetpack/form';
5
6 /**
7 * Gets the min and max values from the context object.
8 *
9 * @param {object} context - The interactivity context for the current slider field.
10 * @return {{min: number, max: number}} The min and max values for the slider.
11 */
12 function getSliderMinMax( context ) {
13 const min = typeof context.min !== 'undefined' ? Number( context.min ) : 0;
14 const max = typeof context.max !== 'undefined' ? Number( context.max ) : 100;
15 return { min, max };
16 }
17
18 store( NAMESPACE, {
19 state: {
20 get getSliderValue() {
21 const context = getContext();
22 const { min } = getSliderMinMax( context );
23 // Use context.default if fieldValue is not set
24 return context.fieldValue ?? context.default ?? min ?? 0;
25 },
26 get getSliderPosition() {
27 const context = getContext();
28 const { min, max } = getSliderMinMax( context );
29 const value = context.fieldValue ?? context.default ?? min;
30 return computeSliderValuePosition( min, max, value );
31 },
32 },
33 actions: {
34 onSliderChange( event ) {
35 const context = getContext();
36 context.fieldValue = event.target.value;
37 },
38 },
39 } );
40