{"id":18734322,"url":"https://github.com/threespot/modal","last_synced_at":"2025-11-15T01:30:14.487Z","repository":{"id":39493347,"uuid":"276205799","full_name":"Threespot/modal","owner":"Threespot","description":"A progressively enhanced modal window that supports multiple toggles and multiple close buttons.","archived":false,"fork":false,"pushed_at":"2023-01-06T10:21:38.000Z","size":2561,"stargazers_count":0,"open_issues_count":19,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-28T20:19:10.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Threespot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-30T20:50:15.000Z","updated_at":"2020-10-08T14:19:10.000Z","dependencies_parsed_at":"2023-02-05T21:16:03.742Z","dependency_job_id":null,"html_url":"https://github.com/Threespot/modal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Threespot%2Fmodal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Threespot%2Fmodal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Threespot%2Fmodal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Threespot%2Fmodal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Threespot","download_url":"https://codeload.github.com/Threespot/modal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239605752,"owners_count":19667111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T15:13:01.928Z","updated_at":"2025-11-15T01:30:14.445Z","avatar_url":"https://github.com/Threespot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Modal\nA progressively enhanced modal window that supports multiple toggles, multiple close buttons, and works with pure CSS thanks to `:target` pseudo selector.  \n\n```bash\nyarn add @threespot/modal\n```\n\n## Usage\n\n### Javascript\n\n```jsx\nimport Modal from \"@threespot/modal\";\n\nconst container = document.getElementById(\"modal\");\n\nnew Modal(container, opts);\n\n// If you have more than one modal on the page\n\nconst containers = document.querySelectorAll(\".Modal\");\n\n// ES6\ncontainers.forEach(container =\u003e new Modal(container));\n\n// ES5 \nfor (var i = 0, len = containers.length; i \u003c len; i+=1) {\n\tnew Modal(containers[i]);\n}\n```\n\n**Styles needed** \n\n```scss\n//------------------------------------------------------------------------\n// Modal windows (required by modals.js)\n//\n// Content is shown by default and hidden once JS runs\n//------------------------------------------------------------------------\n.Modal {\n  $selector: \u0026;\n  $open-speed: 250ms;\n  $close-speed: 500ms;\n  $z-index: 900;\n  $bg-default: #fff; // This can be whatever you want the modal color to be\n\n  background-color: rgba(#000, 0.5);// overlay color\n  bottom: 0;\n  left: 0;\n  margin: 0 !important; // reset u-richtext div styles\n  max-height: 0; // iOS fix\n  opacity: 0;\n  overflow: auto; // allows scrollig when content exceeds viewport height\n  -webkit-overflow-scrolling: touch; // iOS “momentum” scrolling\n  position: fixed;\n  right: 0;\n  top: 0;\n  transition: max-height 0s linear $close-speed,\n              visibility 0s linear $close-speed,\n              opacity $close-speed;\n  visibility: hidden; // hide from screen readers and keyboards until active\n  z-index: $z-index; // must be greater than overlay\n\n  // Styles will be applied when URL hash matches modal ID attribute\n  \u0026:not([aria-hidden]):target,\n  \u0026[aria-hidden=\"false\"] {\n    max-height: 100vh; // can’t set to “none” because that can't be transitioned\n    opacity: 1;\n    transition: max-height 0s linear 0s, visibility 0s linear 0s, opacity $open-speed;\n    visibility: visible;\n  }\n\n  // Modal content wrapper\n  \u0026-content {\n    @include fs-print-hide;\n    background-color: $bg-default;\n    opacity: 0;\n    position: relative;\n    transform: scale(0.95);\n    transition: all $close-speed fs-easing('easeOutCubic');\n    visibility: hidden;\n    width: 100%;\n    z-index: $z-index + 1;\n\n    #{$selector}:not([aria-hidden]):target \u0026,\n    #{$selector}[aria-hidden=\"false\"] \u0026 {\n      opacity: 1;\n      transform: scale(1);\n      transition: all $open-speed fs-easing('easeOutCubic');\n      visibility: visible;\n    }\n  }// end content\n\n  // Close button\n  \u0026-close {\n    padding: fs-rem(15px);\n    position: fixed;\n    right: 0;\n    top: 0;\n    transition: all 150ms ease-in-out;\n    z-index: $z-index + 2;\n  }// end close\n\n  // if you want the modal window to take up the entire screen (optional)\n  \u0026--fullWidth {\n    #{$selector}-content {\n      min-height: 100%;\n    }\n  }\n\n}// end Modal\n\n```\n\n**Minimum markup needed**\n\n```html\n\u003c!-- you can have multiple toggle buttons --\u003e \n\u003ca data-modal=\"foo\"\u003eOpen\u003c/a\u003e\n\n\u003c!-- Div container --\u003e\n\u003c!-- Modal must have an aria-label / aria-labelledby attribute --\u003e\n\u003c!-- This modal window adds aria-hidden \u0026 role='dialog' out of the box --\u003e\n\u003cdiv class=\"Modal\" id=\"foo\"\u003e\n\u003c!-- It doesn't matter where this is located --\u003e\n\t\u003c!-- Codebase stores this by data-modal --\u003e\n\t\u003c!-- We add role=\"button\" to the close button automatically --\u003e\n\t\u003ca class=\"Modal-close\" href=\"#nav-modal-toggle\" data-modal-close\u003eClose\u003c/a\u003e\n\t\n\t\u003c!-- codebase stores this too by class name--\u003e\n\t\u003cdiv class=\"Modal-content\"\u003e\n\t\n\t\u003c/div\u003e\n\u003c/div\u003e\n```\n\n### API\n\n**Required Data Attributes for markup**\n\n`data-modal-close` tells Modal what button(s) can close the modal window. This can be anywhere inside of the `.Modal`\n\n`data-modal=\"{YOUR_MODAL_ID_GOES_HERE}\"` - toggle button(s) for the modal button must have this attribute with the `.Modal` corresponding ID as its value. This allow us to toggle the `.Modal` on and off.\n\n **`new Modal(el, [opts])`**\n\n```jsx\n// This is the Modal that wraps everything except for the toggle/open button(s). \nconst el = document.querySelector('.Modal'); \n\n// Opts Config (optional)\n{\n\t// {string} CSS transition speed to delay focus\n  // Default value: 100\n\ttransitionSpeed: \"100\", \n\n\t// {string} Class(es) to apply on open modal\n\t// Multiples classes are stored inside a string delimited by a space\n  // Default value: ''\n  activeClasses: \"is-active is-privacy-modal\",\n\t\n\t// {string} Class of modal content wrapper\n  // default value: \"Modal-content\"\n\tmodalContentClass: \"Modal-content\", \n\t\n\t// {function} Once Modal object is constructed, this function will be called\n\t// default value: null\n\tonReady: function() {\n\t\tconsole.log('Success!')\n\t}\n}\n```\n\n### License\n\nThis is free software and may be redistributed under the terms of the MIT license.\n\n### About Threespot\n\nThreespot is an independent digital agency hell-bent on helping those, and only those, who are committed to helping others. Find out more at [https://www.threespot.com](https://www.threespot.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreespot%2Fmodal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthreespot%2Fmodal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreespot%2Fmodal/lists"}