-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
un-repeatable event materials basic structures built
- Loading branch information
Showing
7 changed files
with
209 additions
and
8 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
blocks/event-materials-component/event-materials-component.css
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,96 @@ | ||
.event-materials-component > div { | ||
margin-bottom: 32px; | ||
} | ||
|
||
.event-materials-component .image-dropzones { | ||
display: grid; | ||
gap: 16px; | ||
margin-bottom: 24px; | ||
} | ||
|
||
.event-materials-component sp-textfield { | ||
width: 100%; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper { | ||
border: 2px dashed var(--color-gray-400); | ||
border-radius: 8px; | ||
height: 124px; | ||
width: 124px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
text-align: center; | ||
align-items: center; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper .preview-wrapper { | ||
width: 100%; | ||
height: 100%; | ||
position: relative; | ||
z-index: 1; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper .preview-wrapper .icon-delete { | ||
position: absolute; | ||
top: 8px; | ||
right: 8px; | ||
cursor: pointer; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper .preview-material-placeholder { | ||
height: 100%; | ||
overflow: hidden; | ||
border-radius: 8px; | ||
|
||
} | ||
|
||
.event-materials-component .material-file-input-wrapper .preview-material-placeholder img { | ||
height: 100%; | ||
width: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper label { | ||
border-radius: 8px; | ||
display: flex; | ||
flex-direction: column; | ||
box-sizing: border-box; | ||
align-items: center; | ||
padding: 16px; | ||
height: 100%; | ||
width: 100%; | ||
line-height: var(--type-body-xxs-lh); | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper label:hover { | ||
background-color: var(--color-gray-100); | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper label input.material-file-input { | ||
display: none; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper label .icon { | ||
width: 40px; | ||
opacity: 0.5; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper label p { | ||
margin: 0; | ||
font-size: var(--type-body-xs-size);; | ||
} | ||
|
||
.event-materials-component .material-file-input-wrapper .hidden { | ||
display: none; | ||
} | ||
|
||
.event-materials-component .attr-text { | ||
text-align: right; | ||
} | ||
|
||
@media (min-width: 900px) { | ||
.event-materials-component .file-dropzones { | ||
grid-template-columns: 1fr 1fr 1fr; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
blocks/event-materials-component/event-materials-component.js
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,88 @@ | ||
import { getLibs } from '../../scripts/utils.js'; | ||
import { getIcon, generateToolTip } from '../../utils/utils.js'; | ||
|
||
const { createTag } = await import(`${getLibs()}/utils/utils.js`); | ||
|
||
async function decorateSWCTextField(row, id, extraOptions) { | ||
const miloLibs = getLibs(); | ||
await Promise.all([ | ||
import(`${miloLibs}/deps/lit-all.min.js`), | ||
import(`${miloLibs}/features/spectrum-web-components/dist/textfield.js`), | ||
]); | ||
|
||
row.classList.add('text-field-row'); | ||
|
||
const existingFileInput = document.querySelectorAll('.material-file-input'); | ||
const cols = row.querySelectorAll(':scope > div'); | ||
if (!cols.length) return; | ||
const [placeholderCol, maxLengthCol] = cols; | ||
const text = placeholderCol.textContent.trim(); | ||
|
||
let maxCharNum, attrTextEl; | ||
if (maxLengthCol) { | ||
attrTextEl = createTag('div', { class: 'attr-text' }, maxLengthCol.textContent.trim()); | ||
maxCharNum = maxLengthCol.querySelector('strong')?.textContent.trim(); | ||
} | ||
|
||
const isRequired = attrTextEl?.textContent.trim().endsWith('*'); | ||
|
||
const input = createTag('sp-textfield', { | ||
id, class: 'text-input', placeholder: text, ...extraOptions | ||
}); | ||
|
||
if (isRequired) input.required = true; | ||
|
||
if (maxCharNum) input.setAttribute('maxlength', maxCharNum); | ||
|
||
const wrapper = createTag('div', { class: 'info-field-wrapper' }); | ||
row.innerHTML = ''; | ||
wrapper.append(input); | ||
if (attrTextEl) wrapper.append(attrTextEl); | ||
row.append(wrapper); | ||
} | ||
|
||
function decorateFileDropzone(row) { | ||
row.classList.add('file-dropzones'); | ||
const cols = row.querySelectorAll(':scope > div'); | ||
const dropzones = []; | ||
|
||
cols.forEach((c, i) => { | ||
c.classList.add('file-dropzone'); | ||
const text = c.textContent.trim(); | ||
const existingFileInputs = document.querySelectorAll('.material-file-input'); | ||
const inputId = `material-file-input-${existingFileInputs.length + i + 1}`; | ||
const fileInput = createTag('input', { id: inputId, type: 'file', class: 'material-file-input' }); | ||
const inputWrapper = createTag('div', { class: 'material-file-input-wrapper' }); | ||
const inputLabel = createTag('label', { class: 'material-file-input-label' }); | ||
|
||
const previewWrapper = createTag('div', { class: 'preview-wrapper hidden' }); | ||
const previewImg = createTag('div', { class: 'preview-img-placeholder' }); | ||
const previewDeleteButton = getIcon('delete'); | ||
|
||
previewWrapper.append(previewImg, previewDeleteButton); | ||
|
||
inputWrapper.append(previewWrapper, inputLabel); | ||
inputLabel.append(fileInput, getIcon('upload-cloud'), text); | ||
dropzones.push(inputWrapper); | ||
}) | ||
|
||
row.innerHTML = ''; | ||
dropzones.forEach((dz) => { | ||
row.append(dz); | ||
}); | ||
} | ||
|
||
export default function init(el) { | ||
const existingFileInputs = document.querySelectorAll('.event-materials-component'); | ||
const blockIndex = Array.from(existingFileInputs).findIndex((b) => b === el); | ||
|
||
el.classList.add('form-component'); | ||
generateToolTip(el); | ||
|
||
const rows = el.querySelectorAll(':scope > div'); | ||
rows.forEach(async (r, i) => { | ||
if (i === 0) decorateFileDropzone(r); | ||
if (i === 1) await decorateSWCTextField(r, `event-material-url-${blockIndex}`); | ||
if (i === 2) await decorateSWCTextField(r, `event-material-name-${blockIndex}`, { quiet: true, size: 'xl' }); | ||
}); | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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