What are Fragments?
Fragments are self-contained pieces of code or content that Factory can generate, display, and allow you to interact with. They come in several types, each suited for different purposes:- HTML
- SVG
- React
- Mermaid
- Python
General Fragment Usage
1
Generate a Fragment
Ask Factory to create a specific type of fragment. For example:
“Create a React component for a user profile card”
2
View the Fragment
The generated fragment will appear in the Fragment Viewer.
3
Interact and Refine
You can ask Factory to modify the fragment, explain parts of it, or generate variations.
4
Copy or Export
Once satisfied, you can copy the fragment to use in your project or export it as a file.
HTML Fragments
HTML fragments allow you to create and preview web content, including styling and interactivity.HTML Fragment Features
HTML Fragment Features
- Combine HTML, CSS, and JavaScript in a single fragment
- Import libraries from CDNJS for enhanced functionality
- Preview the rendered result directly in Factory
Example: Creating an Interactive HTML Fragment
1
Request an HTML Fragment
Ask Factory: “Create an HTML fragment for a responsive navigation menu with a dropdown”
2
View and Refine
Factory will generate the HTML, CSS, and JavaScript for the menu. You can ask for modifications, such as:
“Add a search bar to the navigation menu”
3
Import External Library
To add animations, you might say:
“Import the Animate.css library from CDNJS and apply a fade-in animation to the dropdown”
SVG Fragments
SVG fragments are perfect for creating scalable graphics and animations.SVG Fragment Features
SVG Fragment Features
- Create vector graphics that scale perfectly
- Design logos, icons, or complex illustrations
- Add animations to your SVG elements
Example: Generating an Animated SVG Logo
1
Request an SVG Fragment
Ask Factory: “Create an SVG fragment for an animated logo of a rocket launching”
2
Refine the Design
You can request changes like:
“Make the rocket trail change colors as it animates”
React Fragments
React fragments allow you to create powerful, interactive components with access to popular libraries.React Fragment Features
React Fragment Features
- Utilize Shadcn UI components for rapid development
- Implement complex UIs with React Flow
- Style components easily with Tailwind CSS
- Preview components directly in Factory
Example: Building a Data Visualization Component
1
Request a React Fragment
Ask Factory: “Create a React component for a data dashboard using Shadcn UI”
2
Add Interactivity
Refine the component by saying:
“Add a filter functionality to the dashboard using Shadcn’s Select component”
3
Style with Tailwind
Enhance the styling:
“Apply Tailwind classes to make the dashboard responsive and add a dark mode toggle”
Mermaid Fragments
Mermaid fragments enable you to create various types of diagrams using a simple markdown-like syntax.Mermaid Fragment Features
Mermaid Fragment Features
- Create flowcharts, sequence diagrams, Gantt charts, and more
- Use a simple text-based syntax to define complex diagrams
- Preview the rendered diagram directly in Factory
Example: Creating a System Architecture Diagram
1
Request a Mermaid Fragment
Ask Factory: “Create a Mermaid diagram showing the architecture of a microservices-based e-commerce system”
2
Refine the Diagram
You can ask for changes like:
“Add a database component to the user service in the diagram”
Python Fragments
Python fragments are ideal for data analysis, scientific computing, and creating quick visualizations.Python Fragment Features
Python Fragment Features
- Access to popular data science libraries like pandas and matplotlib
- Execute code and see results directly in Factory
- Create data visualizations and perform statistical analyses
Example: Analyzing and Visualizing Sales Data
1
Request a Python Fragment
Ask Factory: “Create a Python fragment to analyze monthly sales data and visualize the trend”
2
Refine the Analysis
You can request additional analysis:
“Add a comparison of this year’s sales to last year’s”
Best Practices for Using Fragments
- Start Simple, Then Refine: Begin with a basic request and iteratively refine your fragment.
- Combine Fragment Types: Use different fragment types together for comprehensive solutions.
- Version Control: Save important fragments and track changes as you refine them.
- Documentation: Add comments to your fragments to explain complex logic or usage.
- Reusability: Design fragments with reusability in mind, using parameters where appropriate.