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

IBX-6843: Focus mode #955

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
:IBX-6843: Focus mode
  • Loading branch information
OstafinL authored and micszo committed Nov 16, 2023
commit 52d87c6168ef8883f9397483d4b5e55a30c7580e
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const layout = [
path.resolve(__dirname, '../public/js/scripts/admin.form.autosubmit.js'),
path.resolve(__dirname, '../public/js/scripts/admin.anchor.navigation'),
path.resolve(__dirname, '../public/js/scripts/admin.context.menu'),
path.resolve(__dirname, '../public/js/scripts/admin.focus.mode.js'),
path.resolve(__dirname, '../public/js/scripts/sidebar/main.menu.js'),
path.resolve(__dirname, '../public/js/scripts/admin.input.text.js'),
path.resolve(__dirname, '../public/js/scripts/admin.table.js'),
Expand Down
6 changes: 6 additions & 0 deletions src/bundle/Resources/public/img/ibexa-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/bundle/Resources/public/img/icons/un-focus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions src/bundle/Resources/public/js/scripts/admin.focus.mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
(function (global, doc) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe stick to one logic enable/disable || on/off?

let activeFieldEdit = null;
const ENABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:on';
const DISABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:off';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe?

Suggested change
const ENABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:on';
const DISABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:off';
const FOCUS_MODE_ON_EVENT = 'ibexa-focus-mode:on';
const FOCUS_MODE_OFF_EVENT = 'ibexa-focus-mode:off';
Suggested change
const ENABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:on';
const DISABLE_FOCUS_MODE_EVENT_NAME = 'ibexa-focus-mode:off';
const FOCUS_MODE_ENABLE_EVENT = 'ibexa-focus-mode:enable';
const FOCUS_MODE_DISABLE_EVENT = 'ibexa-focus-mode:disable';

const focusModeEnableBtns = doc.querySelectorAll('.ibexa-field-edit__focus-mode-control-btn--enable');
const focusModeDisbaleBtns = doc.querySelectorAll('.ibexa-field-edit__focus-mode-control-btn--disable');
const changeFocusModeState = (active) => {
if (!activeFieldEdit) {
return;
}

const dispatchEventName = active ? ENABLE_FOCUS_MODE_EVENT_NAME : DISABLE_FOCUS_MODE_EVENT_NAME;
const editorSourceElement = activeFieldEdit.querySelector('.ibexa-data-source__richtext');
const editorInstance = editorSourceElement.ckeditorInstance;

activeFieldEdit.classList.toggle('ibexa-field-edit--focus-mode-active', active);
editorInstance.set('focusModeActive', active);

doc.body.dispatchEvent(
new CustomEvent(dispatchEventName, {
detail: {
activeFieldEdit,
},
}),
);

if (!active) {
activeFieldEdit = null;
}
};
const watchDisableFocusModeByKeyboard = (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we always add Keyboard with func name for keydown but never Click when using click? 😄
Maybe exitFocusMode || exitFocusModeByKeyboard

if (event.key === 'Escape' || event.keyCode === 27) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (event.key === 'Escape' || event.keyCode === 27) {
if (event.key === 'Escape') {

changeFocusModeState(false);
}
};

focusModeEnableBtns.forEach((btn) => {
btn.addEventListener(
'click',
({ currentTarget }) => {
activeFieldEdit = currentTarget.closest('.ibexa-field-edit');
changeFocusModeState(true);
},
false,
);
});
focusModeDisbaleBtns.forEach((btn) => {
btn.addEventListener('click', () => changeFocusModeState(false), false);
});

doc.body.addEventListener(
ENABLE_FOCUS_MODE_EVENT_NAME,
() => doc.body.addEventListener('keydown', watchDisableFocusModeByKeyboard),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
() => doc.body.addEventListener('keydown', watchDisableFocusModeByKeyboard),
() => doc.body.addEventListener('keydown', watchDisableFocusModeByKeyboard, false),

Copy link
Contributor

Choose a reason for hiding this comment

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

We use it everywhere like this but u know @GrabowskiM its default false? 🧆

false,
);
doc.body.addEventListener(
DISABLE_FOCUS_MODE_EVENT_NAME,
() => doc.body.removeEventListener('keydown', watchDisableFocusModeByKeyboard),
false,
);
})(window, window.document);
10 changes: 10 additions & 0 deletions src/bundle/Resources/public/scss/_alerts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,14 @@
}
}
}

&--complementary {
color: $ibexa-color-complementary-700;
background-color: $ibexa-color-complementary-100;
border-color: $ibexa-color-complementary;

.ibexa-icon {
fill: $ibexa-color-complementary-700;
}
}
}
131 changes: 131 additions & 0 deletions src/bundle/Resources/public/scss/fieldType/edit/_base-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
color: $ibexa-color-danger;
}

&__focus-mode {
display: flex;
flex-direction: column;
height: auto;
background: $ibexa-color-white;
border-radius: $ibexa-border-radius $ibexa-border-radius 0 0;
}

&__focus-mode-notice-container {
display: none;
}

&__focus-mode-control-container {
display: flex;
align-self: flex-end;
}

&__focus-mode-control-btn {
align-self: flex-end;

&--enable {
display: inline-flex;
}

&--disable {
display: none;
}
}

.ibexa-input-text-wrapper {
width: auto;
}
Expand Down Expand Up @@ -59,6 +88,108 @@
}
}
}

&--has-focus-mode {
display: flex;
flex-wrap: wrap;

.ibexa-field-edit {
&__focus-mode {
margin: auto 0 0 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
margin: auto 0 0 0;
margin: auto 0 0;

align-self: baseline;
}

&__label-wrapper {
width: 80%;
}

&__focus-mode {
width: 20%;
}

&__data {
width: 100%;
}
}
}

&--focus-mode-active {
position: fixed;
top: 0;
left: 0;
z-index: 1080;
flex-direction: column;
width: 100vw;
height: 100vh;
padding: calculateRem(16px);
background: $ibexa-color-black;

.ibexa-field-edit {
&__label-wrapper {
display: none;
}

&__focus-mode {
width: 100%;
height: fit-content;
padding: calculateRem(32px) calculateRem(32px) 0 calculateRem(32px);
}

&__focus-mode-notice-container {
display: block;
width: 100%;
}

&__focus-mode-control-container {
height: calculateRem(40px);
}

&__focus-mode-control-btn {
margin: 0;

&--enable {
display: none;
}

&--disable {
display: inline-flex;
}
}

&__data {
width: 100%;
overflow-y: auto;
align-self: stretch;
flex-grow: 1;
padding: calculateRem(8px) calculateRem(32px) calculateRem(32px) calculateRem(32px);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
padding: calculateRem(8px) calculateRem(32px) calculateRem(32px) calculateRem(32px);
padding: calculateRem(8px) calculateRem(32px) calculateRem(32px);

background: $ibexa-color-white;
border-radius: 0 0 $ibexa-border-radius $ibexa-border-radius;

.ibexa-data-source {
height: 100%;
}
}
}

.ibexa-alert {
margin-bottom: calculateRem(4px);
}
}

&--focus-mode-active.is-invalid {
.ibexa-field-edit {
&__data {
border-radius: 0;
padding-bottom: 0;
}
}

.ibexa-form-error {
padding: calculateRem(16px) calculateRem(32px);
background: $ibexa-color-white;
border-radius: 0 0 $ibexa-border-radius $ibexa-border-radius;
}
}
}

.ibexa-content-edit {
Expand Down
Loading