Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New theme: Corner layout #40

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
69e2847
feat(theme): add corner theme
vandangnhathung Nov 18, 2024
39e9d3f
feat(theme): update "corner" theme, style & turn off preventScroll
vandangnhathung Nov 19, 2024
fa5c1b1
style(close-button): make the button be sticky with fixed position
vandangnhathung Dec 26, 2024
7754a46
refactor(close-button): move easy-popup-master-corner div into easy p…
vandangnhathung Dec 26, 2024
7719cb6
refactor(close-button): refactor CSS
vandangnhathung Dec 26, 2024
1966be8
refactor(close-button): refactor CSS
vandangnhathung Dec 26, 2024
495ffec
refactor: add comment and avoid returning all the function
vandangnhathung Dec 26, 2024
ef0153b
refactor: use isCornerTheme as global variable
vandangnhathung Dec 26, 2024
bdef612
refactor(corner-theme): show warning if user input wrong position value
vandangnhathung Dec 26, 2024
00f39f4
refactor(corner-theme): use CLASSES.cornerMaster instead of CLASSES.m…
vandangnhathung Dec 26, 2024
a9725cc
refactor(corner-theme): return default position value if the position…
vandangnhathung Dec 26, 2024
685ae4c
refactor(corner-theme): rename global variable
vandangnhathung Dec 26, 2024
dbe4d73
refactor(corner-theme): refactor js
vandangnhathung Dec 26, 2024
f1cb189
refactor(corner-theme): add comment
vandangnhathung Dec 26, 2024
ffe697f
refactor(corner-theme): add comment
vandangnhathung Dec 26, 2024
a6c8f7e
refactor(corner-theme): rename "position" to "cornerPosition"
vandangnhathung Dec 26, 2024
69aa105
feat(html): update structure html
phucbm Dec 26, 2024
796424a
feat(html): allow click outside to close
phucbm Dec 26, 2024
31adad1
refactor(corner-theme): clean up css (not done yet)
vandangnhathung Dec 26, 2024
92a894e
refactor: convert css to scss
vandangnhathung Dec 30, 2024
e21c929
refactor: refactor scss
vandangnhathung Dec 30, 2024
310d87b
refactor: refactor scss
vandangnhathung Dec 30, 2024
8bf7168
refactor(html): add comment, rename var
phucbm Dec 31, 2024
e4a0198
refactor(corner-theme): revise code
vandangnhathung Jan 14, 2025
580c238
refactor(corner-theme): add cornerFade layout
vandangnhathung Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 66 additions & 5 deletions dev/md/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

Layout could be customized with these provided options.

| Description | Option | Buttons |
|--|--|--|
| Use custom layout on mobile | `hasMobileLayout: true` | [View popup](#popup-mobile) |
| Display popup on the right side | `theme: "right-side"` | [View popup](#popup-right-side) |
| Change the close button text | `closeButtonInnerText: "CLOSE"` | [View popup](#popup-custom-close) |
| Description | Option | Buttons |
|---------------------------------|---------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Use custom layout on mobile | `hasMobileLayout: true` | [View popup](#popup-mobile) |
| Display popup on the right side | `theme: "right-side"` | [View popup](#popup-right-side) |
| Change the close button text | `closeButtonInnerText: "CLOSE"` | [View popup](#popup-custom-close) |
| Display the popup in the corner | `theme: "corner"` | [Bottom right](#popup-corner-bottom-right) - [Bottom left](#popup-corner-bottom-left) - [Top right](#popup-corner-top-right) - [Top left](#popup-corner-top-left) |

<div data-easy-popup='{"id": "popup-mobile", "hasMobileLayout": "true"}'>
<!-- Popup content -->
Expand Down Expand Up @@ -75,6 +76,66 @@ nostra lorem libero curabitur.
</p>
</div>

<div data-easy-popup='{"id": "popup-corner-bottom-right", "theme": "corner" }'>
<!-- Popup content -->
<h2>Ac lectus interdum auctor praesent quis</h2>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
</div>

<div data-easy-popup='{"id": "popup-corner-bottom-left", "theme": "corner", "position":"bottom left" }'>
<!-- Popup content -->
<h2>Ac lectus interdum auctor praesent quis</h2>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
</div>

<div data-easy-popup='{"id": "popup-corner-top-right", "theme": "corner", "position":"top right" }'>
<!-- Popup content -->
<h2>Ac lectus interdum auctor praesent quis</h2>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
</div>

<div data-easy-popup='{"id": "popup-corner-top-left", "theme": "corner", "position":"top left" }'>
<!-- Popup content -->
<h2>Ac lectus interdum auctor praesent quis</h2>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
<p>Elementum sollicitudin pharetra nascetur purus risus bibendum arcu fermentum vestibulum diam consequat. Senectus nam
sodales ridiculus torquent et natoque commodo placerat adipiscing. Elementum donec faucibus nulla viverra letius porta
sit. Tempor finibus si mi dictum molestie id pede hac proin curae. Vestibulum tortor parturient interdum litora
adipiscing morbi lobortis bibendum aliquet platea sed. Velit fames ultricies tincidunt netus lectus lacinia nullam
congue cubilia cursus.</p>
</div>

<div data-easy-popup='{"id": "popup-custom-close", "closeButtonInnerText": "CLOSE"}'>
<!-- Popup content -->
<h2>Ac lectus interdum auctor praesent quis</h2>
Expand Down
3 changes: 2 additions & 1 deletion dev/md/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
| Attribute | Type | Default | Description |
|------------------------|------------------------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `id` | string | Auto-generated ID | Set an ID for this popup |
| `theme` | string | `default` | Other layouts: `right-side` |
| `theme` | string | `default` | Other layouts: `right-side`, `corner` |
| `position` | string | `bottom right` | Requires `theme: "corner"`. All values: `top left`, `top right`, `bottom left`, `bottom right` |
| `hasMobileLayout` | boolean | `false` | Enable mobile layout (`theme` options will not work when mobile layout is active) |
| `mobileBreakpoint` | number | `768` | Activate mobile layout when the screen size is <=768px |
| `closeButtonInnerText` | string | `svg/icon` | Custom `innerText` of the close button |
Expand Down
10 changes: 10 additions & 0 deletions src/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class Popup{

/** ------ **/

/** THEMES **/

// corner theme
this.isCornerTheme = this.options.theme === 'corner';


/** COOKIE **/

// cookie
Expand Down Expand Up @@ -137,6 +143,10 @@ class Popup{

// prevent scroll > on
if(this.options.preventScroll){

// "corner" theme will not prevent scroll
if(this.isCornerTheme) return;

if(this.lenis.enabled()){
// prevent with Lenis
this.root.classList.add(CLASSES.preventScrollLenis);
Expand Down
1 change: 1 addition & 0 deletions src/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import "./css/close-button";
@import "./css/theme-right-side";
@import "./css/layout-mobile";
@import "./css/corner-layout";


/* prevent scroll */
Expand Down
1 change: 1 addition & 0 deletions src/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const DEFAULTS = {

// theme
theme: 'default', // right-side
position: 'bottom right', // position of the popup, e.g. 'top left', 'top right', 'bottom left', 'bottom right'

keyboard: true, // option for closing the popup by keyboard (ESC)

Expand Down
131 changes: 131 additions & 0 deletions src/css/corner-layout.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
html.easy-popup-open:has(.easy-popup-master-corner.open) .easy-popup-master {
opacity: 0;
visibility: hidden;
}

.easy-popup-master-corner {
transition: opacity .4s ease, visibility .4s ease, transform .4s ease;
}

.easy-popup-master-corner:not(.open) {
pointer-events: none;
}

.easy-popup-master-corner {
transform: translateX(0);
}

// Popup close button
.easy-popup-master-corner .ep-close-button {
--ep-close-color: #000;
transform: translate(0);
position: fixed;
}

@media only screen and (min-width: 769px) {
// html.easy-popup-open:has(.easy-popup-master-corner).ep-prevent-scroll {overflow:auto;}

.easy-popup-master-corner.easy-popup {

}

.easy-popup-master-corner {
--ep-max-width: 450px;
max-width: var(--ep-max-width);
position: fixed;
bottom: 0;
right: 0;

// Remove default CSS of easy popup
opacity: 1;
visibility: visible;
top: unset;
left: unset;
height: unset;
width: unset;
display: block;
}

// Popup container
.easy-popup-master-corner .easy-popup-container {
padding: 0 20px 20px 0;
}

// Animation
.easy-popup-master-corner[class*="right"]:not(.open) {
transform: translateX(100%);
}
.easy-popup-master-corner[class*="left"]:not(.open) {
transform: translateX(-100%);
}

// Popup position on the top left side
.easy-popup-master-corner.top-left {
top: 0;
left: 0;
bottom: unset;
right: unset;
}
.easy-popup-master-corner.top-left .easy-popup-container {
padding: 20px 0 0 20px;
}

// Popup position on the top right side
.easy-popup-master-corner.top-right {
top: 0;
right: 0;
bottom: unset;
}
.easy-popup-master-corner.top-right .easy-popup-container {
padding: 20px 20px 0 0;
}

// Popup position on the bottom left side
.easy-popup-master-corner.bottom-left {
left: 0;
right: unset;
}
.easy-popup-master-corner.bottom-left .easy-popup-container {
padding: 0 0 20px 20px;
}

// Popup inner
.easy-popup-master-corner .easy-popup-container .easy-popup-inner {
border: 1px solid #d0d7de;
max-height: calc(100vh - 20px * 2);
overflow-y: auto;
}
.easy-popup-master-corner .easy-popup-container .easy-popup-inner .easy-popup-content {
border-radius: 0;
}

// Popup close button
.easy-popup-master-corner.top-left .ep-close-button {
top: 20px;
}
.easy-popup-master-corner.bottom-right .ep-close-button {
right: 20px;
}
.easy-popup-master-corner.top-right .ep-close-button {
top: 20px;
right: 20px;
}
}

@media only screen and (max-width: 768px) {
.easy-popup-master-corner {
position: fixed;
top: 0;
left: 0;
z-index: 9999;
width: 100%;
height: 100%;
background: var(--ep-bg);
backdrop-filter: blur(2px);
}

.easy-popup-master-corner:not(.open) {
opacity: 0;
visibility: hidden;
}
}
16 changes: 9 additions & 7 deletions src/css/master.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/* master */
html:not(.easy-popup-open) .easy-popup-master {
opacity: 0;
visibility: hidden;
}

.easy-popup-master {
:root {
--ep-bg: rgba(0, 0, 0, .4);
--ep-padding: clamp(20px, 2vw, 40px);
--ep-max-width: 915px;
Expand All @@ -14,7 +8,15 @@ html:not(.easy-popup-open) .easy-popup-master {
--ep-close-color-hover: #ef1616;

--ep-popup-bg: #fff;
}

/* master */
html:not(.easy-popup-open) .easy-popup-master {
opacity: 0;
visibility: hidden;
}

.easy-popup-master {
position: fixed;
top: 0;
left: 0;
Expand Down
17 changes: 15 additions & 2 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ export function generateHTML(context){
context.masterContainer = document.createElement('div');
context.masterContainer.classList.add(CLASSES.master);
}
document.querySelector('body').appendChild(context.masterContainer);
context.masterContainer.appendChild(context.el);

if(!context.isCornerTheme){
document.querySelector('body').appendChild(context.masterContainer);
context.masterContainer.appendChild(context.el);
}

// inner
context.inner = wrapElement(context.el);
context.inner.classList.add(CLASSES.inner);

if(context.isCornerTheme){
document.querySelector('body').appendChild(context.inner);
}

// container
context.container = wrapElement(context.inner);
context.container.classList.add(CLASSES.container);
Expand All @@ -31,6 +38,12 @@ export function generateHTML(context){
// outer
context.outer = wrapElement(context.overflow);
context.outer.classList.add(CLASSES.outer);

// theme: corner
if(context.isCornerTheme){
context.outer.classList.add(CLASSES.master + '-corner');
}

if(context.options.outerClass){
const classes = context.options.outerClass.trim().split(' ');
for(let i = 0; i < classes.length; i++) context.outer.classList.add(classes[i])
Expand Down
5 changes: 5 additions & 0 deletions src/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function setTheme(context, removeTheme = false){

// set theme
context.outer.setAttribute(ATTRS.theme, context.options.theme);

if(context.isCornerTheme){
const formatPosition = context.options.position.trim().split(" ").join("-");
context.outer.classList.add(formatPosition);
}
}


Expand Down