Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Components, patterns and sh*t it’s hard to deal...

Marco Cedaro
October 02, 2018
53

Components, patterns and sh*t it’s hard to deal with @ Intersection

This talk will cover one of the open questions of modern development:
When a pattern is a pattern?
How do we reuse one in a slightly different use case?

Not a recipe for success, more of a way to frame the problem, identify some coding strategies we tried and re-discuss the way we approach componentisation.

Marco Cedaro

October 02, 2018
Tweet

Transcript

  1. or… How I came up with a good use of

    quotes from Lost in Translation Components,
 patterns and sh*t it’s hard to deal with
  2. “This movie is an hour and some odd minutes of

    my life I will never get back.” JoeB. on Metacritic Disclaimer
  3. “Meaning is complex and often gets lost in translation. Everybody

    has their own mental model of things” Alla Kholmatova Lost in Translation
  4. Pattern Library “Pattern libraries are something I do a lot

    for client projects. […] It’s a technique I first saw […] Natalie Downe develop for client projects back in 2009” Anna Debenham
  5. Pattern Library “Pattern libraries are something I do a lot

    for client projects. […] It’s a technique I first saw […] Natalie Downe develop for client projects back in 2009” Anna Debenham
  6. It's not that simple “When you actually try to apply

    a modular approach to your day to day work, it isn’t really that simple” Alla Kholmatova · June 2015
  7. The issue How do we manage our code, to re-use

    patterns without making them too rigid for the day to day activities?
  8. The issue How do we manage our code, to re-use

    patterns without making them too rigid for the day to day activities? 
 How do we re-use our patterns in slightly different use cases?
  9. It’s NOT about any specific tech stack or module implementation:

    most of the patterns can be applied with BEM, styled components, css modules… *
 
 It’s about modularity at its core
 
 It’s about modules responsibilities
 
 It’s about maintainability
 (among other coding practices)
  10. //_content-actions.scss .content-actions { //[...] &__button { flex: 1 0 auto;

    padding: 1rem; line-height: 1.5; &:hover, &:focus { background: $grey-1; } &:active { background: $grey-2; } } }
  11. //_content-actions.scss .content-actions { //[...] &__button { flex: 1 0 auto;

    padding: 1rem; line-height: 1.5; &:hover, &:focus { background: $grey-1; } &:active { background: $grey-2; } } }
  12. //_content-actions.scss .content-actions { //[...] &__button { flex: 1 0 auto;

    padding: 1rem; line-height: 1.5; &:hover, &:focus { background: $grey-1; } &:active { background: $grey-2; } } } What's the effect on the base button?
  13. //_content-actions.scss .content-actions { //[...] &__button { flex: 1 0 auto;

    padding: 1rem; line-height: 1.5; &:hover, &:focus { background: $grey-1; } &:active { background: $grey-2; } } } Why is this button different from the pattern library ones?
  14. What really doesn't 1. The default style could be overridden

    in unexpected ways. 2. We are creating many variants of the original patterns.
  15. - You're too tall.
 - Anybody ever tell you you

    may be too small? Ad hoc modifiers
  16. //_dialog.scss .dialog { //[...] &--wizard { width: 43.75rem; height: 35rem;

    } &--register-user { width: 43.75rem; height: auto; } &--save-results { width: 23.75rem; height: auto; } } How many variants do we have to account for?
  17. This practice allows for flexibility, giving a reasonable control and

    keeping all the variants in proximity. What works
  18. What really doesn't 1. The generic component style have knowledge

    of specific implementations. 2. The file size might be effected by unused code. 3. It doesn't scale
  19. //_dialog.scss .dialog { //[...] &--prompt { display: block; overflow: hidden;

    max-width: map-get($dialog-prompt, max-width); height: auto; margin: map-get($dialog-prompt, margin); padding: 2rem 0 0; border-radius: 3px; } }
  20. //_dialog.scss .dialog { //[...] &--prompt { display: block; overflow: hidden;

    max-width: map-get($dialog-prompt, max-width); height: auto; margin: map-get($dialog-prompt, margin); padding: 2rem 0 0; border-radius: 3px; } } The semantic value 
 of the modifiers is different from the 
 ad-hoc ones.
  21. The patterns are at the centre: no special cases, but

    pre-defined flavours of the basic components. What works
  22. What really doesn't 1. It might drive to preemptive abstraction

    2. It does account for a finite number of use cases
  23. I still wish I could sleep A no go: it

    defies the point of having a pattern library A code smell, it's an hack and it should be treated like one The best approach, even though sometimes Classname 
 injection Ad hoc modifiers Specialised patterns
  24. //_dialog.scss .dialog { width: 100%; height: 100%; //[...] } //_game-intent.scss

    .game-intent { //[...] &__dialog { width: 43.75rem; height: auto; } }
  25. //_dialog.scss .dialog { width: 100%; height: 100%; //[...] } //_game-intent.scss

    .game-intent { //[...] &__dialog { width: 43.75rem; height: auto; } } Each component has its own responsibility
  26. This practices defines responsibilities in a neat way and it

    enables for specific implementations without invalidating patterns. What works
  27. It reduces the need to come up with new class

    names and it moves the conversation regarding component relationships back to the pattern library. What works
  28. What really doesn't 1. The positional classes might get stale

    if not codified properly in the pattern lib. 2. The flexibility of the helper classes is limited
  29. //_question-content-block.scss .question-content-block { //[...] &__icon-button { //[...] .icon { width:

    $content-block-icon-large-size; height: $content-block-icon-large-size; } }
  30. //_question-content-block.scss .question-content-block { //[...] &__icon-button { //[...] .icon { width:

    $content-block-icon-large-size; height: $content-block-icon-large-size; } }
  31. //_question-content-block.scss .question-content-block { //[...] &__icon-button { //[...] @include icon-size($content-block-icon-medium-size); }

    } //_icon.scss @mixin icon-size($size) { .icon { width: $size; height: $size; } } The responsibility of being flexible it back to the component itself
  32. 1. Every base component can be as flexible as it

    defines itself to be. 2. Developers always have control on what they expose. What works
  33. What really doesn't 1. This technique involves more complexity in

    thinking about the components 2. It's a slippery slope 3. How does an "open" component fit in the patterns?
  34. The more you know who you are and what you

    want, the less you let things upset you
  35. The issue How to understand - and convey - the

    meaning of an exception in our patterns?