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

added event agenda component #7

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
65 changes: 65 additions & 0 deletions blocks/event-agenda-component/event-agenda-component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.event-agenda-component .field-container {
display: flex;
align-items: center;
justify-content: space-between;
gap: 35px;
}

.event-agenda-component .text-field-row .time-pickers {
display: flex;
align-items: center;
gap: 16px;
padding-bottom: 13px;
}

.event-agenda-component .text-field-row .time-pickers > p {
font-size: var(--type-heading-m-size);
font-weight: 700;
}

.event-agenda-component .text-field-row .time-pickers .time-picker-wrapper {
flex: 1;
min-width: 150px;
}

.event-agenda-component .text-field-row .time-pickers .time-picker-wrapper select {
border-radius: 4px;
padding: 4px;
height: 40px;
width: 100%;
border: 1px solid var(--color-gray-500);
font-size: var(--type-body-xs-size);
}

.event-agenda-component .text-field-wrapper {
display: flex;
flex-direction: column;
width: 100%;
}

.event-agenda-component .text-field-wrapper sp-textfield {
width: 100%;
margin-bottom: 0px;
}

.event-agenda-component .text-field-wrapper .attr-text {
font-size: var(--type-body-xs-size);
color: var(--color-secondary);
text-align: right;
}

.event-agenda-component .checkbox-wrapper {
display: flex;
justify-content: flex-end;
margin-top: 12px;
}

.event-agenda-component .checkbox-input {
margin-right: 8px;
}

.event-agenda-component .checkbox-label {
font-size: var(--type-body-xs-size);
font-weight: normal;
}

127 changes: 127 additions & 0 deletions blocks/event-agenda-component/event-agenda-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { getLibs } from '../../scripts/utils.js';
import { getIcon, handlize, generateToolTip } from '../../utils/utils.js';

const { createTag } = await import(`${getLibs()}/utils/utils.js`);
const miloLibs = getLibs();

await Promise.all([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these + the miloLibs = getLibs() into the init call. The convention is that these. I don't think this will break anything but we should try to load the modules with as little side effects as possible.

import(`${miloLibs}/deps/lit-all.min.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/textfield.js`),
import(`${miloLibs}/features/spectrum-web-components/dist/checkbox.js`),
]);

async function decorateField(row, type = 'text') {
row.classList.add('text-field-row');
const cols = row.querySelectorAll(':scope > div');
if (!cols.length) return;
const [placeholderCol, maxLengthCol] = cols;
const text = placeholderCol.textContent.trim();
const attrTextEl = createTag(
'div',
{ class: 'attr-text' },
maxLengthCol.textContent.trim()
);

const maxCharNum = maxLengthCol.querySelector('strong')?.textContent.trim();
const isRequired = attrTextEl.textContent.trim().endsWith('*');
let input;

if (type === 'text') {
input = createTag('sp-textfield', {
id: 'agenda-field-details',
class: 'text-input',
placeholder: text,
required: isRequired,
quiet: true,
size: 'xl',
});
}

if (maxCharNum) {
input.setAttribute('maxlength', maxCharNum);
}

const wrapper = createTag('div', { class: 'field-container' });
const textWrapper = createTag('div', { class: 'text-field-wrapper' });
textWrapper.append(input, attrTextEl);
row.innerHTML = '';
wrapper.append(cols[2], textWrapper);
row.append(wrapper);

const timePickerContainer = createTag('div');
timePickerContainer.classList.add('custom-time-picker');

buildTimePicker(cols[2]);

return row;
}

function buildTimePicker(column) {
column.classList.add('time-pickers');
const header = column.querySelector(':scope > p');
const rows = column.querySelectorAll('table tr');
const timePickerWrappers = [];

rows.forEach((r) => {
const timePickerWrapper = createTag('div', {
class: 'time-picker-wrapper',
});
const cols = r.querySelectorAll('td');

cols.forEach((c, j) => {
if (j === 0) {
const timeSlots = c.querySelectorAll('li');
const select = createTag('select', {
id: 'time-picker',
class: 'select-input',
});

timeSlots.forEach((t) => {
const text = t.textContent.trim();
const option = createTag('option', { value: handlize(text) }, text);
select.append(option);
});

timePickerWrapper.append(select);
}
});

timePickerWrappers.push(timePickerWrapper);
});

column.innerHTML = '';
if (header) column.append(header);
column.prepend(getIcon('clock'));
timePickerWrappers.forEach((w) => {
column.append(w);
});
}

async function decorateCheckBox(row) {
const fieldSet = createTag('fieldset', { class: 'checkboxes' });
row.classList.add('agenda-info-addition');
const cols = row.querySelectorAll(':scope > div');
const[checkboxText] = cols
const cn = checkboxText.textContent.trim();
row.innerHTML = '';

const checkbox = document.createElement('sp-checkbox');
checkbox.id = 'checkbox-agenda-info';
checkbox.name = 'checkbox-agenda-info-name';
checkbox.value = cn;
checkbox.textContent = cn;

const wrapper = createTag('div', { class: 'checkbox-wrapper' });
wrapper.append(checkbox);

fieldSet.append(wrapper);
row.append(fieldSet);
}

export default async function init(el) {
el.classList.add('form-component');
generateToolTip(el);
const rows = [...el.querySelectorAll(':scope > div')];
decorateField(rows[1], 'text');
decorateCheckBox(rows[2]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function onSubmit(component, inputMap) {
//Todo agenda details
const agendaDetails = component.querySelector('#textfield > input');
const time = component.querySelector('#time-picker-time').value;
const agendaInfoVisible = component.querySelector('#checkbox-agenda-info-will-appear-post-event').checked;




const eventInfo = {
...getMappedInputsOutput(component, inputMap),
agendaInfoVisible,
'Time': time,
};


return eventInfo;
}



12 changes: 12 additions & 0 deletions icons/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading