Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP/Extended options - Add slider form control #2220

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from

Conversation

rickyosser
Copy link
Contributor

This adds the Fomantic-slider as a form-control.
A demo will be added shortly as well as some kind of behat tests.

There are a myriad of extra options that can be added, ie, vertical and colors and stuff.
If there is anything missing feel free to add or ask for it.

public string $inputType = 'hidden';

/** The lowest value the slider can be. */
public int $min = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we limited to integers by something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I've changed this to float, but then the result is also returned in float.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can easily allow int|float to accept integers over 2^53, the deeper question is if the values are correctly typecasted for attributes (machine data) and UI (for user). To verify this, the easiest test is to use Slider together with field with this https://github.com/atk4/ui/blob/5.2.0/demos/init-db.php#L55 DBAL type - you can use any demo model which use this type for all IDs.

private $slider;

/** @var object */
private $owner;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

owner is stored in the parent API already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find this, do you have an example? I just need to know how to find the parent object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Whether the ticks and labels should be at the bottom. */
public bool $bottom = false;

/** @var object */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var object */
/** @var View */

at least if general View type is needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be View not object|View, not only because we do not want to support general object, but also PHPStan will simplify object|View into object only

use Atk4\Ui\Js\JsFunction;
use Atk4\Ui\Js\JsReload;

class Slider extends Input
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabled/disabled/readonly demo should be added into demos/form-control/input2.php

and there should be probably a separate demo for Slicer + Behat tests are needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get to this in time...

public int $labelDistance = 100;

/** Number of decimals to use with an unstepped slider. */
public int $decimalPlaces = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this helpful vs. step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decimalPlaces 2 Number of decimals to use with an unstepped slider
That is from the Fomantic doc, I don't know, just always use step! :)
We can always remove the option in the future.

public bool $autoAdjustLabels = true;

/** The distance between labels. */
public int $labelDistance = 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this helpful? Does this affect CSS only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it also defines what labels will be shown, depending on space available.

public $showLabelTicks = false;

/** Define smoothness when the slider is moving. */
public bool $smooth = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Contributor Author

@rickyosser rickyosser Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for the movement of the thumb, if it's in steps between ticks or smooth scrolling.

public bool $ticked = false;

/** Whether the slider should be labeled or not. */
public bool $labeled = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this controlled by something in Input or Control already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you are thinking of caption, that's the info "before" the controller, labeled is if the slider should have text at the ticks or not.

Comment on lines 209 to 214

#[\Override]
protected function recursiveRender(): void
{
parent::recursiveRender();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[\Override]
protected function recursiveRender(): void
{
parent::recursiveRender();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it later, now I'm using it to check variables and classes after render.


$this->owner = $this->getOwner();

$this->slider = View::addTo($this->owner)->addClass('ui slider');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public int $max = 10;

/** @var float|null The slider step. Set to 0 to disable step. */
public $step = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question for now - how feasible is histogram below the slider and non-liner steps or even non-numeric values (XS-S-M-L...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's possible!
According to Fomantic https://fomantic-ui.com/modules/slider.html#custom-interpreted-labels it can be done with:

var labels = ["α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "σ/ς", "τ", "υ", "φ", "χ", "ψ", "ω"];
$('#interpretedlabel')
  .slider({
    interpretLabel: function(value) {
      return labels[value];
    }
  })
;

As a matter of fact, all the options I've implemented, except this one is directly from Fomantic. I just broke out ticked, bottom align and labeled from the class and made those options. If some of them are funky, yes, I know, they can be removed if we deem the don't add anything. I just added it for completness for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvorisek, I think I need your help on this one. It seems that the function (interpretLabel) need to be existing before semantic.js (Fomantic-UI) is loaded. I've hacked a version of semantic.js to try this and it indeed added the custom labels then. This is not acceptable though as I know very well, it was just done for test.
I do need help though to add the function first on the page before loading Fomantic-UI. Maybe there is another way but I've already spent to much time on this without any workable solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the function (interpretLabel) need to be existing before semantic.js (Fomantic-UI) is loaded.

That seems weird to me. All user JS is evaluated "after page is fully loaded", so the elements are guaranteed to exists. And you can define a JS function before you setup the FUI slider by JS.

I do not understand the issue you are facing here.. If you need to define global JS code - to deduplicate long JS code - you can put the code in /js/*.js. If you need a small JS code per control, you should always use anonymous JS function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvorisek I fixed it... Using JsFunction and JsExpression was the way to go but I had trouble with the array but using slice instead of addressing the item directly solved it.

@mvorisek mvorisek changed the title Added Slider Form-control. Add slider form control Sep 12, 2024
@mvorisek mvorisek marked this pull request as draft September 12, 2024 06:44
@@ -53,6 +53,61 @@
$group->addControl('radio_read', [Form\Control\Radio::class, 'readOnly' => true], ['enum' => ['one', 'two', 'three']])->set('two');
$group->addControl('radio_disb', [Form\Control\Radio::class, 'disabled' => true], ['enum' => ['one', 'two', 'three']])->set('two');

$group = $form->addGroup('Sliders');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checkouted this PR and my feelings are the current state is too wild:

  • because the UX is very different to other controls - for example the vertical space is too large and the control is too wide,
  • there are too many options - for example labels above the horizontal axis/line, the atk4/ui framework aims to provide unified and robust developer experience, not 1:1 FUI port - think this way, in the future (in a decade or so), the FUI might became obsolete and we should be able to replace FUI and still support all supported options

So for now, please put this complex PR on hold and open another PR with minimal Slider impl. Just Slider class with normal/RO/disabled support and min/max value. This should be presented in demos/form-control/input2.php and min/max options in demos/form-control/slider.php and tested with Behat tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi everyone, just as food for thought (courtesy of @abbadon1334) a minimal implementation of Fomantic-UI slider sample code:

                $slider = $this->add([View::class] )->addClass('ui labeled ticked small slider');

                $slider->js(true)->slider([
                    "min" => 0,
                    "max" => 45,
                    'showThumbTooltip' => 'true',
                    'tooltipConfig' => ['position' => 'top center',
                        'variation' => 'small visible blue'],
                    "onChange" => new \Atk4\Ui\Js\JsFunction(['v'], [
                        new \Atk4\Ui\Js\JsExpression($field->js()->find('input')->jsRender().".val(v)")]),
                ]);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for now, please put this complex PR on hold and open another PR with minimal Slider impl. Just Slider class with normal/RO/disabled support and min/max value. This should be presented in demos/form-control/input2.php and min/max options in demos/form-control/slider.php and tested with Behat tests.

@rickyosser would you like to work on the first minimal implementation?

@mvorisek mvorisek changed the title Add slider form control WIP/Extended options - Add slider form control Sep 12, 2024
@rickyosser
Copy link
Contributor Author

rickyosser commented Nov 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants