-
Notifications
You must be signed in to change notification settings - Fork 106
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
base: develop
Are you sure you want to change the base?
Conversation
demos/form-control/Slider.php
Outdated
public string $inputType = 'hidden'; | ||
|
||
/** The lowest value the slider can be. */ | ||
public int $min = 0; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
demos/form-control/Slider.php
Outdated
private $slider; | ||
|
||
/** @var object */ | ||
private $owner; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
demos/form-control/Slider.php
Outdated
/** Whether the ticks and labels should be at the bottom. */ | ||
public bool $bottom = false; | ||
|
||
/** @var object */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @var object */ | |
/** @var View */ |
at least if general View type is needed
There was a problem hiding this comment.
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
demos/form-control/Slider.php
Outdated
use Atk4\Ui\Js\JsFunction; | ||
use Atk4\Ui\Js\JsReload; | ||
|
||
class Slider extends Input |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
demos/form-control/Slider.php
Outdated
public int $labelDistance = 100; | ||
|
||
/** Number of decimals to use with an unstepped slider. */ | ||
public int $decimalPlaces = 2; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
demos/form-control/Slider.php
Outdated
public bool $autoAdjustLabels = true; | ||
|
||
/** The distance between labels. */ | ||
public int $labelDistance = 100; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
demos/form-control/Slider.php
Outdated
public $showLabelTicks = false; | ||
|
||
/** Define smoothness when the slider is moving. */ | ||
public bool $smooth = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
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.
demos/form-control/Slider.php
Outdated
public bool $ticked = false; | ||
|
||
/** Whether the slider should be labeled or not. */ | ||
public bool $labeled = false; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
demos/form-control/Slider.php
Outdated
|
||
#[\Override] | ||
protected function recursiveRender(): void | ||
{ | ||
parent::recursiveRender(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[\Override] | |
protected function recursiveRender(): void | |
{ | |
parent::recursiveRender(); | |
} |
There was a problem hiding this comment.
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.
demos/form-control/Slider.php
Outdated
|
||
$this->owner = $this->getOwner(); | ||
|
||
$this->slider = View::addTo($this->owner)->addClass('ui slider'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
demos/form-control/Slider.php
Outdated
public int $max = 10; | ||
|
||
/** @var float|null The slider step. Set to 0 to disable step. */ | ||
public $step = 0; |
There was a problem hiding this comment.
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...)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
… implement readOnly and disabled. Fixed so that class-data can be used on the slider from the code.
…o slider_form_controller
@@ -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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)")]),
]);
There was a problem hiding this comment.
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 indemos/form-control/slider.php
and tested with Behat tests.
@rickyosser would you like to work on the first minimal implementation?
Hi,
yes, though I've been busy the last months with other work. I hope to
have some more time around new years, I've done some changes already
which aren't pushed yet, I'll remove the more complex options
next, except those I need for my project.
Thanks for asking,
Rickard
|
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.