@theroutingcompany/components 0.0.18-alpha.1 → 0.0.18-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -182,12 +182,29 @@ Some reading material on this:
182
182
  - [Why you should use HSL over other colour formats in your CSS.](https://sujansundareswaran.com/blog/why-hsl-is-better-than-hex-and-rgb)
183
183
  - [Using HSL Colors In CSS](https://www.smashingmagazine.com/2021/07/hsl-colors-css/)
184
184
 
185
+ ## Avoid adding margins by default to components
186
+
187
+ Avoid “leaky margins”. When possible, prefer a flex or grid container to space child items.
188
+
189
+ There are exceptions, eg a header or footer that is expected to always have some room below or above it.
190
+
191
+ <figure>
192
+ <blockquote>The trouble with confining styles to objects is that not everything should be considered a property of an object per se. Take margins: margins are something that exist between elements. Simply giving an element a top margin makes no sense, no matter how few or how many times you do it. <em>It’s like applying glue to one side of an object before you’ve determined whether you actually want to stick it to something or what that something might be.</em>
193
+ </blockquote>
194
+ <figcaption>
195
+ <cite>
196
+ <a href="https://alistapart.com/article/axiomatic-css-and-lobotomized-owls/#section5">Axiomatic CSS and Lobotomized Owls — Dispensing with margins
197
+ by Heydon Pickering</a>
198
+ </cite>
199
+ </figcaption>
200
+ </figure>
201
+
185
202
  ## Style variants
186
203
 
187
204
  > **Warning**
188
205
  > This is not settled and this pattern is not followed consistently (yet?).
189
206
 
190
- Use CSS variables for the dynamic parts in styled-components using.
207
+ Use CSS variables for the dynamic parts in styled-components using.
191
208
 
192
209
  See [The styled-components Happy Path](https://www.joshwcomeau.com/css/styled-components/)
193
210
 
@@ -257,14 +274,14 @@ The linting config is also quite strict with `@typescript-eslint`.
257
274
 
258
275
  ### Types of component props should be strong
259
276
 
260
- Correct component types make it easier to use components without having to look at the source or example.
277
+ Correct component types make it easier to use components without having to look at the source or an example.
261
278
  Exact types for props (for editor autocomplete) is a necessity, not a nice-to-have. Be as detailed as possible.
262
279
 
263
280
  <figure>
264
281
  <blockquote>
265
282
  <ul>
266
283
  <li>Avoid “stringly typed” code. Prefer more appropriate types where not every string is a possibility.</li>
267
- <li>Prefer a union of string literal types to string if that more accurately describes the domain of a variable. You’ll get stricter type checking and improve the development experience.</li>
284
+ <li><em>Prefer a union of string literal types to string if that more accurately describes the domain of a variable. You’ll get stricter type checking and improve the development experience.</em></li>
268
285
  </ul>
269
286
  </blockquote>
270
287
  <figcaption>
@@ -285,12 +302,23 @@ Exact types for props (for editor autocomplete) is a necessity, not a nice-to-ha
285
302
 
286
303
  See [Avoiding JSX spread on foreign data prevents weird bugs sometimes.](https://www.gabe.pizza/notes-on-component-libraries/#avoiding-jsx-spread-on-foreign-data-prevents-weird-bugs-sometimes).
287
304
 
305
+ > I recommend, whenever possible, to destructure the props object and forward keys as needed. Breaking the props down removes excessive keys, allows setting defaults, and makes grepping the code easier.
306
+
288
307
  Two ways we can solve this
289
308
 
290
309
  1. Filter spread props. Reject all non-DOM props using a utility. Note react-aria has a util names `filterDOMProps` despite its name it does not filter DOM props (I think it's a legacy util).
291
310
  2. Be more explicit. Write out all the props to forward and types explicitly.
292
311
 
293
- > I recommend, whenever possible, to destructure the props object and forward keys as needed. Breaking the props down removes excessive keys, allows setting defaults, and makes grepping the code easier.
312
+ ## Configurable Components Should Have Sane Defaults & Not Blow Up Without Props
313
+
314
+ > **Warning**
315
+ > This is a principle we don't always abide by but should!
316
+
317
+ Every component should have enough default props to render without exploding and look normal.
318
+
319
+ - ❌ `<Title>Hi</Title>` without `size` prop raising `Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined`
320
+ - ✅ `<Title>Hi</Hi>` without `size` prop defaults to `size='medium'` and doesn’t blow up.
321
+
294
322
 
295
323
  ## Examples
296
324