1.0.4 • Published 5 months ago

modalitor v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

📦 Modalitor.js

A modern, accessible modal system with focus management, URL hash support, and rich animations.

✨ Features

  • 🎨 Rich animations with multiple presets
  • ♿️ Full accessibility support with ARIA attributes and keyboard navigation
  • 🔗 URL hash state management
  • 📱 Responsive design with mobile-optimized animations
  • 🎯 Focus trap and management
  • 🖼️ Multiple size options
  • 🔒 Scroll lock management
  • 🎮 Comprehensive API

📥 Installation

npm install modalitor
# or
yarn add modalitor

Include the files directly:

<link rel="stylesheet" href="modalitor.css">
<script src="modalitor.js"></script>

🚀 Quick Start

<!-- Modal trigger -->
<button data-modal-target="my-modal">Open Modal</button>

<!-- Modal template -->
<div id="my-modal" class="modalitor">
    <div class="modalitor-header">
        <h2 class="modalitor-title">Modal Title</h2>
        <button class="modalitor-close"></button>
    </div>
    <div class="modalitor-content">
        Modal content goes here
    </div>
    <div class="modalitor-footer">
        <button class="modalitor-close">Close</button>
    </div>
</div>
// JavaScript initialization
const modal = new Modalitor({
    id: 'my-modal',
    animation: 'zoom',
    size: 'md'
});

// Show programmatically
modal.show();

⚙️ Options

OptionTypeDefaultDescription
idstring-Modal element ID (required)
sizestring'md'Modal size ('sm', 'md', 'lg', 'xl', 'full')
animationstring'default'Animation type
closeOnOverlaybooleantrueClose when clicking overlay
closeOnEscapebooleantrueClose on Escape key
preventScrollbooleantruePrevent body scroll when open
rolestring'dialog'ARIA role attribute
labelledBystringnullID of labelling element
describedBystringnullID of describing element
updateUrlbooleantrueUpdate URL hash on open/close
hashPrefixstring'modal-'Prefix for URL hash

🎭 Available Animations

AnimationDescription
defaultSimple fade animation
zoomScale in/out effect
slide-upSlides up from bottom
slide-downSlides down from top
flip3D flip animation
rotateRotating entrance/exit
doorDoor opening effect
unfoldUnfolding paper effect
roadrunnerFast horizontal slide

📱 Mobile Support

Modalitor automatically switches to optimized animations on mobile devices for better performance. The default mobile animation is a simple slide-up regardless of the specified animation type.

🎯 Methods

const modal = new Modalitor({ id: 'my-modal' });

modal.show();      // Show the modal
modal.hide();      // Hide the modal
modal.destroy();   // Remove the modal instance

// Check if modal is visible
if (modal.isVisible()) {
    // Do something
}

🔄 Events

new Modalitor({
    id: 'my-modal',
    onShow: () => console.log('Modal shown'),
    onHide: () => console.log('Modal hidden')
});

📝 License

MIT License

Copyright (c) 2024 HamidReza Yazdani

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.4

5 months ago

1.0.2

5 months ago

1.0.0

5 months ago