Skip to content

Commit

Permalink
feat: implement modal creation function
Browse files Browse the repository at this point in the history
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
chessurisme committed May 28, 2024
1 parent 21cb22f commit 9993003
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/components/modal/modal-create.js
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 }

0 comments on commit 9993003

Please sign in to comment.