Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. // ----
  2. // libsass (v3.5.4)
  3. // ----
  4.  
  5. // conclusions:
  6.  
  7. // placeholders:
  8. // 1. SASS is easier to read because no logic, but can be spread out
  9. // 2. outputted CSS far harder to read due to long selector lists that
  10. // grow with each new extend
  11.  
  12. // mixins:
  13. // 1. SASS harder to write because logic is necessary to keep mixins
  14. // simple and consistent, but is compact due to function.
  15. // 2. outputted CSS way easier to read because it's grouped via
  16. // component and not selector
  17.  
  18. // performance:
  19. // on pure performance placeholders win due to less generated code.
  20. // the real question: is the performance win high enough to offset
  21. // the cognitive load when viewing outputted CSS in inspector?
  22.  
  23.  
  24.  
  25. /*
  26. *** typography
  27. */
  28. /*
  29. using placeholders
  30. */
  31. /* these selector lists are going to get very long due to future code */
  32. %body,
  33. %small-head {
  34. font-family: arial;
  35. font-weight: 400;
  36. }
  37.  
  38. %body,
  39. %typography3 {
  40. font-style: italic;
  41. }
  42.  
  43. %body,
  44. %small-head,
  45. %typography3 {
  46. color: black;
  47. }
  48.  
  49. %body {
  50. font-size: 1.4rem;
  51. line-height: 1.2;
  52. }
  53.  
  54. %small-head {
  55. font-size: 2rem;
  56. line-height: 1.5;
  57. }
  58.  
  59. %typography3 {
  60. font-size: 1.2rem;
  61. line-height: 1.1;
  62. }
  63.  
  64. .body { @extend %body; }
  65. .small-head { @extend %small-head; }
  66. .typography3 { @extend %typography3; }
  67.  
  68.  
  69.  
  70. /*
  71. using mixin
  72. */
  73. @mixin typography($type: ''){
  74. color: black;
  75.  
  76. @if $type == 'body' or $type == 'sm-head' {
  77. font-family: arial;
  78. font-weight: 400;
  79. }
  80.  
  81.  
  82. @if $type == 'body' or $type == 'typography3' {
  83. font-style: italic;
  84. }
  85.  
  86.  
  87. @if $type == 'sm-head' {
  88. font-size: 2rem;
  89. line-height: 1.5;
  90. }
  91.  
  92. @elseif $type == 'typography3' {
  93. font-size: 1.2rem;
  94. line-height: 1.1;
  95. }
  96.  
  97. @else {
  98. font-size: 1.4rem;
  99. line-height: 1.2;
  100. }
  101. }
  102.  
  103. .component {
  104. p {@include typography('body');}
  105. .title {@include typography('sm-head');}
  106. .other {@include typography('typography3');}
  107. }
  108.  
  109.  
  110.  
  111. /*
  112. *** cards
  113. */
  114. $major-component-buffer: 4rem;
  115. $minor-component-buffer: 2rem;
  116.  
  117. /*
  118. mashing up mixins and placeholders
  119. */
  120. %card {
  121. margin-bottom: $major-component-buffer;
  122. padding: 2rem;
  123.  
  124. // mixing between placeholders and mixins to show diff in outputted CSS
  125. p { @extend %body; }
  126. // only title will show up with card grouping, rest will be higher in output with previous typography selector groups */
  127. .title { @include typography('sm-head'); }
  128. .sub-head { @extend %typography3; }
  129. }
  130.  
  131. .mixed-card {
  132. &,
  133. &--variant1,
  134. &--variant2 {
  135. @extend %card;
  136. }
  137.  
  138. &--variant1 {
  139. .img { float: right; }
  140. }
  141.  
  142. &--variant2 {
  143. .img { float: left; }
  144. }
  145. }
  146.  
  147. // all of these will be grouped with like selectors
  148. /*
  149. using placeholders only - selectors grouped, not outputted CSS
  150. */
  151. %placeholder-card {
  152. margin-bottom: $major-component-buffer;
  153. padding: 2rem;
  154.  
  155. // mixing between placeholders and mixins to show diff in outputted CSS
  156. p { @extend %body; }
  157. // only title will show up with card grouping, rest will be higher in output with previous typography selector groups */
  158. .title { @extend %small-head; }
  159. .sub-head { @extend %typography3; }
  160. }
  161.  
  162. .placeholder-card {
  163. &,
  164. &--variant1,
  165. &--variant2 {
  166. @extend %placeholder-card;
  167. }
  168.  
  169. &--variant1 {
  170. .img { float: right; }
  171. }
  172.  
  173. &--variant2 {
  174. .img { float: left; }
  175. }
  176. }
  177.  
  178. /*
  179. using mixins only - outputted CSS grouped, not selectors
  180. */
  181. @mixin card {
  182. margin-bottom: $major-component-buffer;
  183. padding: 2rem;
  184.  
  185. // mixing between placeholders and mixins to show diff in outputted CSS
  186. p { @include typography('body'); }
  187. // only title will show up with card grouping, rest will be higher in output with previous typography selector groups */
  188. .title { @include typography('sm-head'); }
  189. .sub-head { @include typography('typography3'); }
  190. }
  191.  
  192. .mixin-card {
  193. &,
  194. &--variant1,
  195. &--variant2 {
  196. @include card;
  197. }
  198.  
  199. &--variant1 {
  200. .img { float: right; }
  201. }
  202.  
  203. &--variant2 {
  204. .img { float: left; }
  205. }
  206. }
  207.  
  208.  
  209. // random playground tests
  210. @mixin button(
  211. $background-color: gray,
  212. $invert: false
  213. ) {
  214. font-weight: bold;
  215. font-style: arial;
  216. background-color: #{$background-color};
  217.  
  218.  
  219. @if $invert == true {
  220. color: white;
  221. }
  222.  
  223. @else {
  224. color: black;
  225. }
  226. }
  227.  
  228. /*
  229. mixin buttons
  230. */
  231. .button {@include button};
  232. .button-success,
  233. // save this as a placeholder for component use
  234. %button-success {@include button($background-color:'green')};
  235. // just messing around with sending variables without keywords
  236. .button-error {@include button('red', true)};
  237. .button-invert {@include button($invert: true)};
  238.  
  239. // placeholder makes longer selector, mixin duplicates CSS
  240. // placeholder harder to read in inspector, but better performance (would make smaller file)
  241. .component .button {@include button($background-color:'green')};
  242. .component2 .button {@extend %button-success;}
  243.  
  244.  
  245.  
  246. /*
  247. placeholder buttons generated from list
  248. */
  249. $buttons:
  250. // [name] [background-color] [font-color] [border-color]
  251. 'foo' gray black green,
  252. 'bar' green blue black,
  253. 'magic' red white orange;
  254.  
  255. @each $button-config in $buttons {
  256. %button-#{nth($button-config, 1)} {
  257. font-family: arial;
  258. font-weight: bold;
  259. background-color: nth($button-config, 2);
  260. color: nth($button-config, 3);
  261. border-color: nth($button-config, 4);
  262. }
  263.  
  264. // separating class and placeholder to prevent potential weird nesting because SASS
  265. .button-#{nth($button-config, 1)} {
  266. @extend %button-#{nth($button-config, 1)};
  267. }
  268. }
  269.  
  270. .simple-button-placeholder {@extend %button-magic; }
  271.  
  272.  
  273.  
  274. /*
  275. icon list - probably simpler than our current map implementation
  276. */
  277. $icon-list:
  278. // [icon name], [icon image path]
  279.  
  280. // group 1
  281. 'check' 'check.svg',
  282. 'foo' 'random-icon-name.svg',
  283.  
  284. // group 2
  285. 'bar' 'nested/test.svg';
  286.  
  287. @each $icon-configs in $icon-list {
  288. %icon-#{nth($icon-configs, 1)} {
  289. background-image: url('/path/to/image/#{nth($icon-configs, 2)}');
  290. }
  291.  
  292. // separating class and placeholder to prevent potential weird nesting because SASS
  293. .icon-#{nth($icon-configs, 1)} {
  294. @extend %icon-#{nth($icon-configs, 1)};
  295. }
  296. }
  297.  
  298. // allows swapping of icon via SASS rather than markup
  299. .component .icon {@extend %icon-foo;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement