Categories of Snippets
DevSnips organizes snippets into distinct categories based on language and purpose. Understanding the scope of each category is essential for effectively finding and combining snippets to build complete, functional components.
HTML Snippets
Scope: HTML snippets provide the structural foundation for UI components. They are focused exclusively on semantic and accessible markup.
- What you'll find: Well-structured markup for components like cards, forms, buttons, modals, and layout containers.
- Limitations: These snippets are unstyled. They are intended to be paired with CSS snippets or your own custom styles. They do not contain any inline styles or <style>tags.
CSS Snippets
Scope: CSS snippets provide the visual styling for components. They are designed to be modular and are often built to target the structures provided by the HTML snippets.
- What you'll find: Style rules for individual components (e.g., styling a card), layout utilities (e.g., a flexbox grid system), and aesthetic effects (e.g., gradients, box shadows, animations).
- Relationship to HTML: Most CSS snippets are written to work with a corresponding HTML snippet. The class names in the CSS (following the BEM convention) will match the classes in the HTML.
JavaScript Snippets
Scope: JavaScript snippets provide client-side interactivity and functionality. They are written in vanilla JavaScript to ensure maximum compatibility and avoid framework dependencies.
- What you'll find: Logic for common UI interactions, such as toggling a modal, validating a form, handling a dropdown menu, or sending an AJAX request.
- Decoupled by Design: JavaScript snippets are intentionally kept separate from the HTML structure. To use them, you should copy the code and place it in your project's main JavaScript file, ensuring it runs after the DOM has loaded. The snippets will typically use document.querySelectorordocument.getElementByIdto attach event listeners to the elements defined in the HTML snippets.
Combining Snippets
The true power of DevSnips comes from combining snippets from different categories. A typical workflow might look like this:
- Find an HTML snippet for the basic structure of the component you need.
- Find a corresponding CSS snippet to apply a visual style.
- If the component requires interaction, find a JavaScript snippet and integrate it to manage the component's state and behavior.
By providing these building blocks in a decoupled way, DevSnips allows for maximum flexibility and customization.
