Added documentation for conditional rendering in Stac#411
Added documentation for conditional rendering in Stac#411Chidwan3578 wants to merge 6 commits intoStacDev:devfrom
Conversation
Summary Created documentation for conditional rendering in Stac. Created Documentation File Location: docs/concepts/conditional_rendering.mdx Content: Covers: What conditional rendering is — overview of the conditional widget and its purpose Supported conditions and operators — tables for: Comparison operators (==, !=, >, <, >=, <=) Logical operators (&&, ||) Mathematical operations (+, -, *, /, %) Supported values (numbers, booleans, strings, null) How conditions are evaluated at runtime — explanation of the ExpressionResolver evaluation process Usage examples — including: Basic boolean comparisons String comparisons Mathematical expressions Logical operators Nested conditionals Real-world examples (authentication, feature flags) Updated Navigation Added the new documentation page to docs/docs.json in the Concepts section The documentation includes: Overview and explanation of how conditional rendering works Complete operator reference with examples Multiple usage examples from simple to advanced JSON schema reference Best practices and limitations Error handling information The documentation is ready and integrated into the Stac documentation site. Users can find it in the Concepts section alongside other core concepts like theming, caching, and custom widgets.
📝 WalkthroughWalkthroughAdds a new documentation page for Stac's conditional rendering feature, updates site navigation to include it, and adds a Stac DSL/Dart example to the Stac package README. No runtime code or exported API changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @docs/concepts/conditional_rendering.mdx:
- Around line 308-312: The "Limitations" section currently claims conditions
cannot access app state, which contradicts the examples using user.isLoggedIn ==
true and featureFlags.newUI == true; update the Limitations paragraph to clarify
that condition expressions can reference variables from the evaluation context
(e.g., user.isLoggedIn, featureFlags.newUI) and describe the
substitution/evaluation behavior (what scope is available and any restrictions),
or alternatively change the examples to show explicit variable substitution
before evaluation — ensure you mention the example patterns user.isLoggedIn ==
true and featureFlags.newUI == true so readers see the clarified behavior.
- Line 99: Update the example so the "condition" property uses quoted string
operands consistent with the documented format: inside the condition string wrap
each string operand in quotes (double or single) rather than leaving them
unquoted, so the expression follows the documented `"hello"`/`'world'` style;
change the example value assigned to the "condition" key accordingly and keep
the surrounding JSON string syntax intact.
🧹 Nitpick comments (1)
docs/concepts/conditional_rendering.mdx (1)
311-311: Clarify "built-in math functions" statement.The parenthetical "(except built-in math functions)" is vague. If there are built-in functions available, they should be documented in the "Supported Conditions and Operators" section. If there are none, consider removing this exception clause.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/concepts/conditional_rendering.mdxdocs/docs.json
🧰 Additional context used
🪛 LanguageTool
docs/concepts/conditional_rendering.mdx
[style] ~298-~298: To elevate your writing, try using a synonym here.
Context: ...ns simple**: Complex expressions can be hard to debug. Consider breaking them into n...
(HARD_TO)
🔇 Additional comments (2)
docs/concepts/conditional_rendering.mdx (1)
1-328: Overall documentation is comprehensive and well-structured.The documentation covers the essential aspects of conditional rendering including operators, usage examples, JSON schema, best practices, and error handling. The examples progress logically from basic to advanced usage.
docs/docs.json (1)
41-41: Navigation entry correctly added.The new page entry aligns with the documentation file path and is logically placed in the Concepts group after the rendering widgets concept.
|
Hey @Chidwan3578!! Thank you for the quick contribution 🎉 |
|
Done ;) |
divyanshub024
left a comment
There was a problem hiding this comment.
Hey @Chidwan3578!!
Thank you for this amazing PR. Can you please check my suggestions.
Also, can you please update the PR title and a proper description.
| ```json | ||
| { | ||
| "type": "conditional", | ||
| "condition": "5 > 3", | ||
| "ifTrue": { | ||
| "type": "text", | ||
| "data": "5 is greater than 3" | ||
| }, | ||
| "ifFalse": { | ||
| "type": "text", | ||
| "data": "5 is not greater than 3" | ||
| } | ||
| } |
There was a problem hiding this comment.
Can you also add the Stac DSL/Dart example as well. Since it's the recommended way for Stac.
There was a problem hiding this comment.
added an example for DSL/Dart.
There was a problem hiding this comment.
Can we add the Dart example for all JSONs?
| }, | ||
| "body": { | ||
| "type": "conditional", | ||
| "condition": "user.isLoggedIn == true", |
There was a problem hiding this comment.
The variables in stac are used like this {{user.isLoggedIn}}
|
|
||
| ## Limitations | ||
|
|
||
| - **No variable access**: Currently, conditions cannot access app state or variables directly. They evaluate static expressions only. |
There was a problem hiding this comment.
This is not fully true. It can access variables from the network request.
There was a problem hiding this comment.
Updated the documentation to clarify that conditions can access variables from resolved data sources (e.g. network responses), while still not supporting local widget state or arbitrary Dart variables.
|
|
||
| - **No variable access**: Currently, conditions cannot access app state or variables directly. They evaluate static expressions only. | ||
| - **No function calls**: Custom functions cannot be called within conditions (except built-in math functions). | ||
| - **String operations**: String concatenation is supported, but other string operations are limited. |
There was a problem hiding this comment.
Can you please eleborate on this?
There was a problem hiding this comment.
Added more detailed explanations for each limitation to clarify what is and isn’t supported in conditional expressions.
Changed according to requests
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/stac/README.md`:
- Around line 40-62: Move the entire "Stac DSL/Dart Example" section (the
heading "## Stac DSL/Dart Example" and its Dart code block plus the "For more
details..." line) out of the middle of the Features list and place it after the
existing feature bullets (i.e., after the block that continues on line ~66) so
all feature bullets remain contiguous under "Features" and the example becomes
its own standalone section; update surrounding spacing so the Features list is
uninterrupted and the relocated section has a blank line before and after.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/concepts/conditional_rendering.mdxpackages/stac/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/concepts/conditional_rendering.mdx
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
|
|
||
| ## Stac DSL/Dart Example | ||
|
|
||
| The Stac DSL allows you to define widgets directly in Dart, which is then compiled to JSON. Here's a simple example: | ||
|
|
||
| ```dart | ||
| import 'package:stac/stac.dart'; | ||
|
|
||
| @StacWidget() | ||
| class MyButton extends StatelessWidget { | ||
| const MyButton({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return ElevatedButton( | ||
| onPressed: () {}, | ||
| child: const Text('Click me'), | ||
| ); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| For more details, see the [documentation](https://docs.stac.dev/). |
There was a problem hiding this comment.
Hey, this change is not required.
|
Hey @Chidwan3578! Hope you're doing well. Do you have any updates on the PR? |
|
@Chidwan3578 Thanks a lot for your contribution. Please let us know once you’re able to update the PR with the requested changes. If not, we’ll have to close it for now. |
|
Closing this for now. Feel free to create another PR :) |
Summary
Created documentation for conditional rendering in Stac. Created Documentation File
Location: docs/concepts/conditional_rendering.mdx
Content: Covers:
What conditional rendering is — overview of the conditional widget and its purpose Supported conditions and operators — tables for:
Comparison operators (==, !=, >, <, >=, <=)
Logical operators (&&, ||)
Mathematical operations (+, -, *, /, %)
Supported values (numbers, booleans, strings, null) How conditions are evaluated at runtime — explanation of the ExpressionResolver evaluation process Usage examples — including:
Basic boolean comparisons
String comparisons
Mathematical expressions
Logical operators
Nested conditionals
Real-world examples (authentication, feature flags) Updated Navigation
Added the new documentation page to docs/docs.json in the Concepts section The documentation includes:
Overview and explanation of how conditional rendering works Complete operator reference with examples
Multiple usage examples from simple to advanced
JSON schema reference
Best practices and limitations
Error handling information
The documentation is ready and integrated into the Stac documentation site. Users can find it in the Concepts section alongside other core concepts like theming, caching, and custom widgets.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.