-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Dropdown family (possibly) needs architecture refactoring #5441
Comments
TL;DR:
After reading requirements and having possible combinations I don't see helper only solution nice. Creating helpers for every possible solution doesn't look maintainable. The process of creating a toolbar dropdown goes like described above:
Resulting dropdown. Maybe we should think which interactions should be defined by UI and which by features?
Those should be provided as 'event' interfaces of two required elements (button + contents) so one could pass any compatible Some feature specific are:
Those are mostly controller by the The building DP process might look like this: const model = new Model();
const button = createDropdownButton( model, locale );
const dp = crateDropdown( model, button, locale );
addListToDropdown( dp, listItems );
// OR
addToolbarToDropdown( dp, buttons );
// This will add 'close', 'open' behaviors.
addDefaultBehavior( dp ); Now having some common toolbar configurations we can have creator methods similar to current For instance I would remove current const model = new Model();
const button = createDropdownButton( model, locale );
const dp = crateDropdown( model, button, locale );
addToolbarToDropdown( dp, buttons );
addDefaultBehavior( dp );
bindIconToActiveButtonIcon( dp ); As an alternative we could use const dp = new DropdownBuilder( model, locale )
.withButton()
.openingToolbarDropdown()
.bindingIconToActiveButton()
.build(); // this would add default behavior as it is always required Some CSS cleanup: One example is previous refactoring of when to add background color to dropdown button - styling Another example is dropdown triangle added to every |
ps.: I would love to make it together with |
The idea sounds good to me. Creating dropdowns is a pain ATM. What we need is a tree of possible combinations to understand the scope: Buttons
Panel
Types of content in the panel
Did I miss anything? Behaviours
Since #645, the arrow is an instance of |
@oleq: Yep that summarizes my thoughts on the behavior and responsibility split. |
I've tried reading through your discussion but I see that it will be very hard for me to give a more detailed feedback. However, I see that you're doing a great job analysing these components, so I'll focus on some general aspects.
We're right now killing the builder idea in the engine. It turned out that you can easily do stuff by using the builder but if you need anything more custom or slightly different, then you can't use the builder at all. Therefore, a set of utils seems to be a safer solution. However, the trickiness here lays in proposing meaningful and useful utils. E.g. I proposed things like So, I'd propose the following goals for this task:
|
Other: Introduced `SplitButtonView` and new dropdown creation helpers (`createDropdown()`, `addListToDropdown()` and `addToolbarToDropdown()`) Closes #344. Closes #356. BREAKING CHANGE: Removed `DropdownModel` interface – you can use dropdown properties directly now. See #356. BREAKING CHANGE: Removed `createButtonDropdown()` and `ButtonDropdownView`. See #356. BREAKING CHANGE: Removed `createListDropdown()` and `ListDropdownView`. See #356.
Other: Manual tests should be aligned to the newest dropdown API (ckeditor/ckeditor5-ui#356). Minor refactoring in the drop-down ecosystem. Closes #129.
ATM there are 2 base classes:
and 3 helpers combining them with
ToolbarView
,ListView
, etc.:However, the new Highlight feature we're implementing requires a split button,
which does not actually fit that well into the family because it actually comes with 2 buttons in the toolbar:
The goal: We need to somehow make it possible to create such a dropdown supporting all events like
execute
and attributes likeisOpen
using just base classes and helper functions.JS requirements
ATM
DropdownView
accepts button and panel as constructor arguments. Then it extends button's template and starts reacting toButtonView#execute
by opening the panel.In case of the split button, the situation is quite different. The left (main) part of the split button usually executes some commands (e.g. applies last used highlight), while the right button acts as the panel opener. So, in fact, the main button is "extra" here, something new.
With the current
DropdownView
architecture, it is not possible to pass such split–button and handle it without lots of hacking.CSS requirements
There are 2 dropdown styles in Lark:
The later is ATM supported only by
createButtonDropdown()
but it should become a standard feature of theDropdownView
, I guess. Every dropdown should come with that option to use just an icon or just a text, which obviously should be reflected in a class of the element:vs.
The class corresponds to
ck-button_with-text
.Note: While the styling could change soon and all dropdowns might look the same, this still must be differentiated.
Possible solutions
Allow passing the split button directly into
DropdownView
constructorThat could work if we figured an interface for such split button which makes sense. Note that both parts of the split button have
isEnabled
attribute and they both fireexecute
when clicked.How to allow the
DropdownView
to listen to the "right"execute
and open the panel?How to let the
DropdownView
knew which of the two split buttons is enabled to activate the keyboard support?Maybe it should be
createDropdown()'s
job, limiting theDropdownView
to just being a dull container?Let's just create a new kind of
DropdownView
for the split button purposesIt's quite simple but it will duplicate tons of code (and tests) doing exactly the same just to allow a fancy button. It does not make much sense to me, IMO the new feature should remain in the base
DropdownView
family.???
Post-refactoring
Some naming issues should probably be resolved, like this one because we should name dropdown helpers by the kind of content it contains:
Which name to use for the "split dropdown" then?
createSplitButtonDropdown
? Probably yes, because it should be able to contain any sort of content. Or maybe we should figure out the new set of helpers according to the following methodology?like
I'm not sure how to resolve that. Which helpers should exist and to what extent things should be "helperized"?
cc @Reinmar @jodator @oskarwrobel
The text was updated successfully, but these errors were encountered: