-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement modal creation function
This function creates a modal container element based on the provided configuration. It utilizes strict mode and imports necessary functions for setting attributes and verifying configuration. The modal container includes a title, icon, and buttons as specified in the configuration.
- Loading branch information
1 parent
21cb22f
commit 9993003
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict' | ||
|
||
import { setAttributes } from '../../utilities/components/set-attributes' | ||
import { isConfigVerified } from '../../utilities/config/config-verifier' | ||
|
||
function createModal(config) { | ||
if (!isConfigVerified(config)) return | ||
|
||
const { id, title, icon, buttons } = config | ||
const MODAL = createModalContainer(id, title, icon, buttons) | ||
|
||
return MODAL | ||
} | ||
|
||
function createModalContainer(id, title, icon, buttons) { | ||
const MODAL = document.createElement('div') | ||
setAttributes(MODAL, { | ||
id: id, | ||
class: 'modal' | ||
}) | ||
|
||
const BUTTONS = createModalButtons(buttons) | ||
const title_container = document.createElement('div') | ||
const icon_holder = document.createElement('i') | ||
const title_text = document.createElement('p') | ||
setAttributes(icon_holder, { | ||
'data-lucide': icon | ||
}) | ||
title_text.textContent = title | ||
|
||
title_container.appendChild(icon_holder) | ||
title_container.appendChild(title_text) | ||
MODAL.appendChild(title_container) | ||
|
||
BUTTONS.forEach((button) => { | ||
MODAL.appendChild(button) | ||
}) | ||
|
||
return MODAL | ||
} | ||
|
||
function createModalButtons(buttons) { | ||
let BUTTONS = [] | ||
|
||
buttons.forEach((button, index) => { | ||
button.id = `modal-button-${index}` | ||
BUTTONS.push(button) | ||
}) | ||
|
||
return BUTTONS | ||
} | ||
|
||
export { createModal } |