nuvoleweb / ui_patterns

[NOTE] Development has moved to https://drupal.org/project/ui_patterns
https://drupal.org/project/ui_patterns
GNU General Public License v2.0
85 stars 56 forks source link

Next steps before stable releases: Variants, Subfields, Multiple fields, Tags and Hidden patterns #76

Open ademarco opened 7 years ago

ademarco commented 7 years ago

The following is a list of improvements we wish to include in the first stable release. We would like to hear your thoughts about it.

All issues above can be summarized in the following example of a carousel definition, we can use this to drive our discussion:

carousel:
  label: carousel
  variants:
    large:
      label: Large
      description: This is a large carousel.
    small:
      label: Small
      description: This is a small carousel.
  tags:
    - partial
  fields:
    title:
      type: string
      label: Title
    slides:
      type: pattern:slide
      multiple: true
{# pattern-carousel.html.twig #}
<div class="carousel">
  <h3 class="title">{{ title }}</h3>
  <div class="slides">
    {% for slide in slides %}
      {{ pattern('slide', slide) }}
    {% endfor %}
  </div>
</div>
slide:
  label: Slide
  hidden: true
  fields:
    image:
      type: pattern:image
    title:
      type: string
      label: Subtitle
      preview: Slide title.
    sudtitle:
      type: string
      label: Subtitle
      preview: Slide subtitle.
    url:
      type: url
      label: URL
      preview: URL the slide links to.
{# pattern-slide.html.twig #}
<a href="{{ url }}" class="slide">
  {{ pattern('image', image) }}
  <h4>{{ title }}</h4>
  <p>{{ subtitle }}</p>
</a>
image:
  label: Image
  hidden: true
  fields:
    url:
      label: URL      
      type: string
    title:
      label: Title       
      type: string
{# pattern-image.html.twig #}
<img src="{{ src }}" title="{{ title }}">
ademarco commented 7 years ago

As first users of the UI Patterns module your input would be of great help! πŸ˜„ \cc @drupol @pixelwhip @hctom @aleksip @haringsrob @bircher @kclarkson @capriosa @hctom @tanc

hctom commented 7 years ago

@ademarco This looks absolutely fantastic! ;)

Here are some of my thoughts/questions regarding your topics:

And last but not least, here is a little addon for your list: I would really appreciate something to be able to group components on the preview page. Right now every pattern is just listed and rendered, but with large component libraries this might run into problems really fast (e.g. rendering tons of components on a single page and some of them might even use a lot of JavaScript which might even crash the browser). What do you think about having something that allows setting a "path" of a specific component in a tree structure that is used to render a component menu (e.g. KSS uses something similar with its Styleguide syntax feature)?

... but all in all, this module is really heading the right way! Thanx a lot for that!

capriosa commented 7 years ago

Your ideas sounds really cool. Especially the type:pattern will be very useful. Btw. do you know that UI-Patterns works very well in conjunction with the Stacks module? And with the new features from above this will even get better.

kclarkson commented 7 years ago

+1 for @hctom suggestion for grouping patterns on the overview page. This is desperately needed for organization!

backlineint commented 7 years ago

Also agree that this feature list looks very promising. A few comments:

Excited to see where this goes and looking forward to following along.

ademarco commented 7 years ago

Now pattern definitions are actual TypedData objects, this will allow us to introduce things like variants or tags in a much easier and maintainable way. Check PR #79 for more details.

ademarco commented 7 years ago

To all those involved in this discussion you might be interested in this issue: Allow multiple sources to be mapped to the same destination #81

ademarco commented 7 years ago

I'm planning to work on this issue before our talk on UI Patterns on DDD in Seville

As first we could maybe tackle tags and a better overview page, I'm actually thinking to move out the overview page on its own module, say ui_patterns_overview so that we can isolate complex logic there.

It would be also good to have a pattern definition property dedicated to the overview, for example:

button:
  ...
  overview:
    parent: Buttons
    weight: 10

Or maybe we reverse it and we have a YAML file describing the overview page? Such YAML plugin could be exposed by the ui_patterns_overview module, so that we don't clutter the pattern definitions?

@hctom which one would you prefer?

hctom commented 7 years ago

Hm, thats quite tough to decide. On the one hand, a dedicated file is of course good to keep the actual pattern definition short and simple, but on the other hand, the pattern definition itself already contains information that is used in the overview (e.g. label and description).

For now, I think it should all reside in the same file, so you don't have to search different files for metadata information used in the overview or other places that display pattern information (e.g. select lists when assigning patterns).

tassilogroeper commented 7 years ago

At DDD17 we discussed a litte further. This is what we came up with:

List of possible styleguides ;-) github.com/davidhund/styleguide-generators

tassilogroeper commented 7 years ago

My proposed structure would be the following:

1. One basic assumption to be decided on

1.1. A [pattern_description].pattern.yml-file contains only one describable pattern target. Meaning all assets described in the pattern description belong to the very same library. Thus there can only be one library per pattern (ui_patterns/[pattern_description]). Unique pattern_description-names are implied. 1.2. A [pattern_description].pattern.yml-file may target multiple files and libraries. For this scenario I can not really make up a good usage for naming things. E.g. referencing a library with ui_patterns/[pattern_description]--[custom_name].

Discussion:

I think version 1. is somehow limiting but it can bring the most clarity. So instead of searching in a file for exact patterns and creating somewhat obscure library names, we stick to basic principles:

β”œβ”€β”€ components
β”‚   β”œβ”€β”€ shiny-buttons
β”‚   β”‚   └── buttons.css
β”‚   β”‚   └── button-default.html.twig
β”‚   β”‚   └── button-default.pattern.yml
β”‚   β”‚   └── button-primary.html.twig
β”‚   β”‚   └── button-primary.pattern.yml
β”‚   └── contact
β”‚       β”œβ”€β”€ contact-base.css  // may also be a compiled file
β”‚       β”œβ”€β”€ contact-base.scss
β”‚       β”œβ”€β”€ contact-actions.js
β”‚       β”œβ”€β”€ contact.config.js // belongs to style guide
β”‚       └── contact.html.twig
β”‚       └── contact.pattern.yml
β”‚   └── contact-preview
β”‚       └── contact-preview.html.twig
β”‚       └── contact-preview.pattern.yml

button-default.pattern.yml

label: Button Default
fields:
  url: Url
  title: Link title
library:
  css:
  # The SMACSS category (base, layout, component, state or theme)
    base:
    # The path relative to the css file.
      buttons.css: {}

contact.pattern.yml

label: Contact information
fields:
  title: Contact title
  emails: Emails
  phones: Telephones
  # ...
library:
  css:
    base:
      '//fonts.googleapis.com/css?family=Lato': { external: true }
    component:
      contact-base.css: {}
  js:
    contact-actions.js: {}
  dependencies:
    - ui_patterns/button-default
    - core/jquery

contact-preview.pattern.yml

label: Contact information preview
fields:
  title: Contact title
  emails: Emails
  phones: Telephones
  # ...
library:
  dependencies:
    - ui_patterns/contact

2. How to load twig files and their assets

How to the style guides will reference their templates is nothing we can influence. E.g. whether ID like include (Fractal: @box for a files situated under components/boxes/box/box.twig) or fully qualified (@components/boxes/box/box.twig). This may not be our problem, because other contrib modules, like components, can take care of that.

Our problem is rather, what if the contact-pattern references the button-pattern with an {% include %} statement? how does the button library get loaded if not directly addressed by our pattern description file? This may be a easy case, but I can think of a article having multiple optional includes...

ademarco commented 7 years ago

Thank you @pheadeaux ! I'll follow up tomorrow, for the moment https://github.com/nuvoleweb/ui_patterns/pull/84 will add support for any sort of file extension in the use: property, so we can just have:

image:
  label: Image
  use: '@molecules/media/image/image.twig'
  fields:
    image: Image
    caption: Caption
    credit: Credit
kalinchernev commented 7 years ago

Hi all, Just passing by this thread, few thoughts:

ademarco commented 7 years ago

I'm totally for [ID].pattern.yml, although we have been using [ID].ui_patterns.yml for now, but I guess we can support both and slowly fade out [ID].ui_patterns.yml.

Target file can be automatically discovered too, only I'm wondering what would happen with - separators as patterns IDs should not support that, maybe we can convert - into _ or allow it and see how the Drupal theme system reacts to that. For sure we cannot allow double-dash -- as it has a specific meaning for Drupal (i.e. theme suggestion components are separated by a double-dash).

Maybe the best would be to allow a redefinition of pattern ID in the YAML file, for example:

β”œβ”€β”€ components
β”‚   β”œβ”€β”€ shiny-buttons
β”‚   β”‚   └── buttons.css
β”‚   β”‚   └── button.twig
β”‚   β”‚   └── button.pattern.yml
β”‚   β”‚   └── button-primary.twig
β”‚   β”‚   └── button-primary.pattern.yml

then:

# button-primary.pattern.yml
id: button_primary
use: button-primary.twig
fields:
  label: Label
  url: URL

While for button it could simply be:

# button.pattern.yml
fields:
  label: Label
  url: URL

Pattern names are required to be globally unique too, so I guess allowing developers to re-define IDs is useful or even required.

Libraries already receive the following custom notation:

ui_patterns/[ID].[LOCAL_LIBRARY_NAME]

So if we have (note that the following is the correct way of defining local libraries):

image:
  label: Image
  fields:
    ...
  libraries:
    - library_name:
        css: ...
        js: ...
    - another_library:
        css: ...
        js: ...

Then UI Patterns module will expose its libraries as follow:

- ui_patterns/image.library_name
- ui_patterns/image.another_library

Also with new PR #84 this is now possible already:

  use: '@molecules/media/image/image.twig'
tassilogroeper commented 7 years ago

@ademarco I agree. also the way of referencing the libraries works for me.

About the use-key: please be very cautious about that one, since we might introduce an alias system, that can be hard to grasp:

in Drupal we might use @molecules/media/image/image.html.twig but inside the (whatever) styleguide the include may also go for the .twig version. I mean, we should enforce the parity of the reference methods - otherwise reusing patterns might not work correctly.

aleksip commented 7 years ago

These are all great improvements, but as development has slowed down in the past few months, I'd vote for releasing 1.0 as soon as possible. beta7 is already good enough for a lot of use cases (I've used it on several production websites), and a 1.0 release would be much more attractive for people considering the module.

sherakama commented 7 years ago

Ditto to the 1.0 release.

I am also planning on using this module for a production website and have some development cycles to share. Do you have a development plan outside of this issue or a contributing document?

sherakama commented 7 years ago

A first effort at the variant functionality can be found here: https://github.com/nuvoleweb/ui_patterns/pull/105