|
17 | 17 | * [UiComponent](#uicomponent) |
18 | 18 | * __[Fluent-style component consumption](#fluent-style-component-consumption)__ |
19 | 19 | * __[DOM components and props](#dom-components-and-props)__ |
| 20 | +* __[Component Formatting](#component-formatting)__ |
20 | 21 | * __[Building custom components](#building-custom-components)__ |
21 | 22 | * __[Component Boilerplates](#component-boilerplate-templates)__ |
22 | | - * __[Component Formatting](#component-formatting)__ |
| 23 | + * __[Component Best Practices](#component-best-practices)__ |
23 | 24 | * __[Common Pitfalls](#common-pitfalls)__ |
24 | 25 | * __[Contributing](#contributing)__ |
25 | 26 |
|
@@ -491,6 +492,90 @@ as shown in the examples above. |
491 | 492 |
|
492 | 493 |
|
493 | 494 |
|
| 495 | +## Component Formatting |
| 496 | + |
| 497 | +> NOTE: At this time, we __do not recommend using [`dartfmt`](https://github.com/dart-lang/dart_style)__, as it |
| 498 | +> _greatly_ decreases the readability of components built using |
| 499 | +> [OverReact's fluent-style](#fluent-style-component-consumption). |
| 500 | +> |
| 501 | +> _We have a long-term goal of writing our own formatter that extends from `dartfmt` to make it possible for our |
| 502 | +> fluent-style to remain readable even after the formatter executes._ |
| 503 | + |
| 504 | +Since using `dartfmt` results in unreadable code, we have documented the following formatting best-practices that |
| 505 | +we _strongly recommended_ when building components using the `over_react` library. |
| 506 | + |
| 507 | + |
| 508 | + |
| 509 | +* __ALWAYS__ place the closing builder parent on a new line. |
| 510 | + |
| 511 | + _Good:_ |
| 512 | + ```dart |
| 513 | + (Button() |
| 514 | + ..skin = ButtonSkin.SUCCESS |
| 515 | + ..isDisabled = true |
| 516 | + )('Submit') |
| 517 | + ``` |
| 518 | + |
| 519 | + _Bad:_ |
| 520 | + ```dart |
| 521 | + (Button() |
| 522 | + ..skin = ButtonSkin.SUCCESS |
| 523 | + ..isDisabled = true)('Submit') |
| 524 | + ``` |
| 525 | + |
| 526 | + |
| 527 | + |
| 528 | +* __ALWAYS__ pass nested components as variadic children when keys are not specified, on a new line with a __2 space__ |
| 529 | + indentation. |
| 530 | + |
| 531 | + _Good:_ |
| 532 | + ```dart |
| 533 | + Dom.div()( |
| 534 | + Dom.span()('nested component'), |
| 535 | + Dom.span()('nested component') |
| 536 | + ) |
| 537 | + ``` |
| 538 | + |
| 539 | + _Bad:_ |
| 540 | + ```dart |
| 541 | + // Nested component is not on a new line |
| 542 | + Dom.div()(Dom.span()('nested component')) |
| 543 | +
|
| 544 | + // Nested component has a continuation indent |
| 545 | + Dom.div()( |
| 546 | + Dom.span()('nested component'), |
| 547 | + ) |
| 548 | +
|
| 549 | + // Nested components are within a list instead of |
| 550 | + // being passed in as variadic children. |
| 551 | + Dom.div()([ |
| 552 | + Dom.span()('nested component'), |
| 553 | + Dom.span()('nested component') |
| 554 | + ]) |
| 555 | + ``` |
| 556 | + |
| 557 | + |
| 558 | + |
| 559 | +* __AVOID__ specifying more than one cascading prop setter on the same line. |
| 560 | + |
| 561 | + _Good:_ |
| 562 | + ```dart |
| 563 | + (Dom.div() |
| 564 | + ..id = 'my_div' |
| 565 | + ..className = 'my-class' |
| 566 | + )() |
| 567 | + ``` |
| 568 | + |
| 569 | + _Bad:_ |
| 570 | + ```dart |
| 571 | + (Dom.div()..id = 'my_div'..className = 'my-class')() |
| 572 | + ``` |
| 573 | + |
| 574 | + |
| 575 | + |
| 576 | + |
| 577 | + |
| 578 | + |
494 | 579 | ## Building custom components |
495 | 580 |
|
496 | 581 | Now that we’ve gone over how to [use the `over_react` package in your project](#using-it-in-your-project), |
@@ -603,81 +688,8 @@ that you get for free from OverReact, you're ready to start building your own cu |
603 | 688 |
|
604 | 689 | |
605 | 690 |
|
606 | | -### Component Formatting |
607 | | - |
608 | | -> NOTE: At this time, we __do not recommend using [`dartfmt`](https://github.com/dart-lang/dart_style)__, as it _greatly_ decreases the readability of components built using [OverReact's fluent-style](#fluent-style-component-consumption). |
609 | | -> |
610 | | -> _We have a long-term goal of writing our own formatter that extends from `dartfmt` to make it possible for our fluent-style to remain readable even after the formatter executes._ |
611 | | - |
612 | | -Since using `dartfmt` results in unreadable code, we have documented the following formatting best-practices that we _strongly recommended_ when building components using the `over_react` library. |
613 | | - |
614 | | - |
615 | | - |
616 | | -* __ALWAYS__ place the closing builder parent on a new line. |
617 | | - |
618 | | - _Good:_ |
619 | | - ```dart |
620 | | - (Button() |
621 | | - ..skin = ButtonSkin.SUCCESS |
622 | | - ..isDisabled = true |
623 | | - )('Submit') |
624 | | - ``` |
625 | | - |
626 | | - _Bad:_ |
627 | | - ```dart |
628 | | - (Button() |
629 | | - ..skin = ButtonSkin.SUCCESS |
630 | | - ..isDisabled = true)('Submit') |
631 | | - ``` |
632 | | - |
633 | | - |
634 | | - |
635 | | -* __ALWAYS__ pass nested components as variadic children when keys are not specified, on a new line with a __2 space__ indentation. |
| 691 | +### Component Best Practices |
636 | 692 |
|
637 | | - _Good:_ |
638 | | - ```dart |
639 | | - Dom.div()( |
640 | | - Dom.span()('nested component'), |
641 | | - Dom.span()('nested component') |
642 | | - ) |
643 | | - ``` |
644 | | - |
645 | | - _Bad:_ |
646 | | - ```dart |
647 | | - // Nested component is not on a new line |
648 | | - Dom.div()(Dom.span()('nested component')) |
649 | | -
|
650 | | - // Nested component has a continuation indent |
651 | | - Dom.div()( |
652 | | - Dom.span()('nested component'), |
653 | | - ) |
654 | | -
|
655 | | - // Nested components are within a list instead of |
656 | | - // being passed in as variadic children. |
657 | | - Dom.div()([ |
658 | | - Dom.span()('nested component'), |
659 | | - Dom.span()('nested component') |
660 | | - ]) |
661 | | - ``` |
662 | | - |
663 | | - |
664 | | - |
665 | | -* __AVOID__ specifying more than one cascading prop setter on the same line. |
666 | | - |
667 | | - _Good:_ |
668 | | - ```dart |
669 | | - (Dom.div() |
670 | | - ..id = 'my_div' |
671 | | - ..className = 'my-class' |
672 | | - )() |
673 | | - ``` |
674 | | - |
675 | | - _Bad:_ |
676 | | - ```dart |
677 | | - (Dom.div()..id = 'my_div'..className = 'my-class')() |
678 | | - ``` |
679 | | - |
680 | | - |
681 | 693 |
|
682 | 694 | * __ALWAYS__ write informative comments for your component factories. |
683 | 695 | Include what the component relates to, relies on, or if it extends |
@@ -876,7 +888,8 @@ Yes please! ([__Please read our contributor guidelines first__][contributing-doc |
876 | 888 | The `over_react` library adheres to [Semantic Versioning](http://semver.org/): |
877 | 889 |
|
878 | 890 | * Any API changes that are not backwards compatible will __bump the major version__ _(and reset the minor / patch)_. |
879 | | -* Any new functionality that is added in a backwards-compatible manner will __bump the minor version__ _(and reset the patch)_. |
| 891 | +* Any new functionality that is added in a backwards-compatible manner will __bump the minor version__ |
| 892 | + _(and reset the patch)_. |
880 | 893 | * Any backwards-compatible bug fixes that are added will __bump the patch version__. |
881 | 894 |
|
882 | 895 |
|
|
0 commit comments