Puppertino

repository·master·Indexed 22 days ago

https://github.com/codedgar/puppertino

A lightweight, modular CSS/JS framework designed to bring the macOS look and feel to web applications, adhering to Apple's Human Interface Guidelines. It includes components such as buttons, modals, forms, tabs, navigation bars, and a dark mode manager. The framework supports integration via CDN or NPM and provides programmatic APIs for managing action cards, modals, and tabbed interfaces.

Tokens
4.5K
Snippets
15
Records
17
Agent score
78%

What's inside @codedgar/puppertino

  1. Integrate Puppertino via CDN

    master

    To quickly add Puppertino to your project without a build step, include the newfull.css file in your HTML <head> tag. For a modular approach, you can include only specific component CSS files to reduce file size.

    <!-- Full framework -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/codedgar/Puppertino@latest/dist/css/newfull.css">
    
    <!-- Individual component (e.g., buttons) -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/codedgar/Puppertino@latest/dist/css/buttons.css">
  2. Install Puppertino via NPM

    master

    You can install the @codedgar/puppertino package using NPM. You can install the latest version, a specific branch, or via SSH/HTTPS protocols.

    # Via NPM (recommended)
    npm install @codedgar/puppertino@github:codedgar/Puppertino
    
    # Or install from a specific branch
    npm install @codedgar/puppertino@github:codedgar/Puppertino#master
    
    # Via SSH
    npm install git+ssh://git@github.com/codedgar/Puppertino.git
    
    # Via HTTPS
    npm install https://github.com/codedgar/Puppertino.git
  3. Import Puppertino in JavaScript or CSS

    master

    After installing via NPM, you can import the framework or individual components into your build pipeline.

    // --- JavaScript/TypeScript --- 
    
    // Import the full framework
    import '@codedgar/puppertino';
    
    // Import individual components (modular approach)
    import '@codedgar/puppertino/buttons';
    import '@codedgar/puppertino/modals';
    import '@codedgar/puppertino/forms';
    import '@codedgar/puppertino/tabs';
    
    // Import JavaScript modules (ES6)
    import '@codedgar/puppertino/js/modals.js';
    import '@codedgar/puppertino/js/dakmode_manager.js';
    import '@codedgar/puppertino/js/tabs.js';
    
    // Import JavaScript modules (CommonJS)
    const modals = require('@codedgar/puppertino/src/js/modals.js');
    
    // --- CSS --- 
    
    // Import full framework
    @import '@codedgar/puppertino';
    
    // Import individual components
    @import '@codedgar/puppertino/buttons';
    @import '@codedgar/puppertino/modals';
    @import '@codedgar/puppertino/dark-mode';
  4. Trigger action cards using data attributes

    master

    You can trigger the opening and closing of action cards (modals) using specific HTML data attributes. This allows you to manage UI actions without writing custom JavaScript for every button.

    Open an Action Card

    Add the data-p-open-actions attribute to a button or element. The value of this attribute must be a valid CSS selector (e.g., an ID or class) for the action card you wish to display.

    Close an Action Card

    Add the data-p-cancel-action attribute to a button or element to trigger the closing of the currently active action card.

    Close on Outside Click

    To allow a user to close an action card by clicking the background overlay, add the attribute data-p-close-on-outside="true" to the action card container (which should have the class .p-action-big-container).

    <!-- Triggering an action card with ID 'my-action-card' -->
    <button data-p-open-actions="#my-action-card">Open Actions</button>
    
    <!-- The action card itself -->
    <div id="my-action-card" class="p-action-big-container" data-p-close-on-outside="true" aria-hidden="true">
      <p>Action Content</p>
      <!-- Button to close the card -->
      <button data-p-cancel-action>Cancel</button>
    </div>
    
    <!-- The background overlay (required for the manager to work) -->
    <div class="p-action-background"></div>
  5. Configure Puppertino theme manager options

    master

    When calling init(), you can provide the following configuration keys:

    • autoDetect (boolean): If true, the manager automatically detects the system's color scheme preference. Defaults to true.
    • darkThemeClass (string): The CSS class name applied to document.body when dark mode is active. Defaults to 'p-dark-mode'.
  6. Available Puppertino Components

    master

    Puppertino provides a variety of macOS-inspired components. For detailed usage instructions for each, visit the Components page.

    Current Components:

    • Buttons (Push, Icon, Action)
    • Modals
    • Forms and Inputs
    • Layout
    • Official Apple Colors
    • Segmented Controls
    • Shadows & Blur
    • Tabs
    • Navigation Bars
    • Dark Mode Manager
  7. Programmatically control modals using PuppertinoModalMan

    master

    If you need to control modals via JavaScript instead of relying on data attributes, use the methods available on the PuppertinoModalManager instance.

    Methods

    • openModal(selector): Opens the modal matching the provided CSS selector. It adds the active class to the modal, nowactive to the background, and p-modal-opened to the body.
    • closeActiveModal(): Closes whichever modal currently has the .p-modal.active class.
    • closeModal(selector): Closes a specific modal matching the provided selector, provided it is currently active.
    • isModalOpen(selector): Returns true if the modal matching the selector has the active class, otherwise false.
    // Open a specific modal
    PuppertinoModalManager.openModal('#login-modal');
    
    // Check if a modal is open
    if (PuppertinoModalManager.isModalOpen('#login-modal')) {
      console.log('Login modal is visible');
    }
    
    // Close the currently active modal
    PuppertinoModalManager.closeActiveModal();
    
    // Close a specific modal
    PuppertinoModalManager.closeModal('#login-modal');
  8. Initialize Puppertino with Puppertino()

    master

    To start using the framework, call the Puppertino function. It accepts an options object and a selector string. The function returns an object containing your configuration and a modal method for managing modal components.

    const instance = Puppertino(options, selector);
  9. Initialize the Puppertino theme manager

    master

    Use init() to set up theme management. You can pass an optional userOptions object to configure how the theme is detected and which CSS class is used for dark mode.

    By default, autoDetect is true and the darkThemeClass is 'p-dark-mode'. If autoDetect is enabled, the manager will listen to system color scheme changes via prefers-color-scheme. The manager also synchronizes theme changes across different browser tabs using the storage event on the puppertino_theme localStorage key.

    puppertinoThemeMan.init({
      autoDetect: true, 
      darkThemeClass: 'custom-dark-theme'
    });
  10. Use PuppertinoActionsManager to control actions programmatically

    master

    The PuppertinoActionsManager instance provides a programmatic API to manage the state of action cards. This is useful when you need to open or close modals based on application logic rather than direct user clicks.

    Methods

    • openAction(selector): Opens the action card matching the provided CSS selector. It adds the active class to the card, sets aria-hidden="false", and activates the background overlay.
    • closeActiveAction(): Closes whichever action card currently has the .active class.
    • closeAction(selector): Closes a specific action card matching the selector, provided it is currently active.
    • isActionOpen(selector): Returns true if the action card matching the selector is currently open (has the .active class), otherwise false.
    import { PuppertinoActionsManager } from './path/to/puppertino/actions.js';
    
    // Check if a specific action is open
    if (PuppertinoActionsManager.isActionOpen('#settings-menu')) {
      console.log('Settings are open');
    }
    
    // Programmatically open an action
    PuppertinoActionsManager.openAction('#settings-menu');
    
    // Programmatically close the active action
    PuppertinoActionsManager.closeActiveAction();
  11. Use PuppertinoTabsMan to manage tabbed interfaces

    master

    The PuppertinoTabsMan class manages tabbed UI components by handling click events for both desktop and mobile layouts. It automatically initializes upon instantiation and attaches listeners to specific DOM structures.

    Desktop Tabs

    Desktop tabs are managed via a container with the class .p-tabs-container. The manager expects:

    • A .p-tabs element containing the tab triggers.
    • A .p-panels element containing the content panels.
    • The manager uses the container's id to target specific tab sets.

    Mobile Tabs

    Mobile tabs are managed via elements with the class .p-mobile-tabs.

    • Triggers can be <a> or <button> elements.
    • Use the data-p-mobile-toggle attribute on the trigger to specify the selector of the panel to show.
    • The manager toggles the .active class on the trigger and the target panel.
    • It expects a content container with the class .p-mobile-tabs--content.active to manage visibility transitions.
    // The instance is automatically initialized when the script is loaded
    // but you can interact with the class logic if needed.
    
    // Desktop HTML Structure Example:
    /*
    <div id="my-tabs" class="p-tabs-container">
      <div class="p-tabs">
        <button>Tab 1</button>
        <button>Tab 2</button>
      </div>
      <div class="p-panels">
        <div class="panel">Content 1</div>
        <div class="panel">Content 2</div>
      </div>
    </div>
    */
    
    // Mobile HTML Structure Example:
    /*
    <div class="p-mobile-tabs">
      <button data-p-mobile-toggle="#panel-1" class="active">Tab 1</button>
      <button data-p-mobile-toggle="#panel-2">Tab 2</button>
    </div>
    
    <div class="p-mobile-tabs--content active">
      <div id="panel-1">Content 1</div>
      <div id="panel-2">Content 2</div>
    </div>
    */