wingsuit-designsystem / wingsuit

Twig for Storybook
GNU General Public License v2.0
93 stars 16 forks source link

Add pattern configuration. #56

Closed christianwiedemann closed 4 years ago

christianwiedemann commented 4 years ago

Right now configuration is done inside the pattern. For example the grid template:

{% set column_configuration = {
  1:
  {
    equal: {default: 'w-full'},
  },
  2:
  {
    equal: {default: 'flex flex-col w-full md:w-1/2 mb-20 last:mb-0 md:mb-0'}, '66x33': {1: 'flex flex-col w-full md:w-2/3 mb-20 last:mb-0 md:mb-0', 2: 'flex flex-col w-full md:w-1/3 mb-20 last:mb-0 md:mb-0'}, '33x66': {1: 'flex flex-col w-full md:w-1/3 mb-20 last:mb-0 md:mb-0', 2: 'flex flex-col w-full md:w-2/3 mb-20 last:mb-0 md:mb-0'}
  },
  3:
  {
    equal: {default: 'flex flex-col w-full md:w-1/3 mb-20 last:mb-0 md:mb-0'},
  },
  4:
  {
    equal: {default: 'flex flex-col w-full md:w-1/4 mb-20 last:mb-0 md:mb-0'},
  },
  5:
  {
    equal: {default: 'flex flex-col w-full sm:w-1/2 md:w-1/5 mb-20 last:mb-0 md:mb-0'},
  }
} %}

This PR moves this configuration to wingsuit.yml. Sample YAML:

grid:
  use: "@organisms/grid/grid.twig"
  label: Grid
  description: "Flexible Grid with maximum Five Columns."
  fields:
   ......
  settings:
  ......
  variants:
     1_columns:
       .....
       configuration:
          columns:
            equal:
              default: 'w-full'
     2_columns:
       ......
       configuration:
          columns:
            equal:
              default: 'flex flex-col w-full md:w-1/2 mb-20 last:mb-0 md:mb-0'
            66x33:
              1: flex flex-col w-full md:w-2/3 mb-20 last:mb-0 md:mb-0
              2: flex flex-col w-full md:w-1/3 mb-20 last:mb-0 md:mb-0

// Global configuration
  configuration:
     gap:
       default: 'px-6 md:px-25'

  .... 

Access You can access the configuration with a twig function: To access the columns configuration pattern_configuration('gird', 'column_2','columns')

codecov[bot] commented 4 years ago

Codecov Report

Merging #56 into refactor_patterns will increase coverage by 0.23%. The diff coverage is 70.58%.

Impacted file tree graph

@@                  Coverage Diff                  @@
##           refactor_patterns      #56      +/-   ##
=====================================================
+ Coverage              59.29%   59.53%   +0.23%     
=====================================================
  Files                     27       27              
  Lines                    624      640      +16     
  Branches                 118      121       +3     
=====================================================
+ Hits                     370      381      +11     
- Misses                   212      217       +5     
  Partials                  42       42              
Impacted Files Coverage Δ
packages/pattern/src/twigRenderEngine.ts 72.50% <55.55%> (-2.15%) :arrow_down:
packages/pattern/src/PatternVariant.ts 75.00% <66.66%> (-0.48%) :arrow_down:
packages/pattern/src/Pattern.ts 67.77% <100.00%> (+1.11%) :arrow_up:
packages/pattern/src/TwingRenderer.ts 91.42% <100.00%> (+0.25%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c5a92a5...2908c01. Read the comment docs.

GiorgosK commented 4 years ago

Having had a 2nd thought about this I think the UX is improved if you move the configuration into the wingsuit.yml file. Configuration is more like the pattern settings and it probably makes sense to put it in the wingsuit.yml file.