add vertical align buttons

This commit is contained in:
Sergey Krylov 2022-07-10 13:40:50 +05:00
parent 72b559b941
commit cdd94a5d02
7 changed files with 94 additions and 52 deletions

View File

@ -2,5 +2,6 @@ export type ToolbarStateType = {
fontWeight?: 'normal' | 'bold'; fontWeight?: 'normal' | 'bold';
fontStyle?: 'normal' | 'italic'; fontStyle?: 'normal' | 'italic';
textDecoration?: 'none' | 'underline'; textDecoration?: 'none' | 'underline';
textAlign?: 'left' | 'center' | 'right'; justifyContent?: 'start' | 'center' | 'end';
alignItems?: 'start' | 'center' | 'end';
}; };

View File

@ -8,52 +8,90 @@ type ButtonConfigType = {
}; };
export function createToolbar(state: ToolbarStateType): string { export function createToolbar(state: ToolbarStateType): string {
const btns: ButtonConfigType[] = [ const btns: (ButtonConfigType | ButtonConfigType[])[] = [
{ [
icon: 'format_bold', {
isActive: state.fontWeight === 'bold', icon: 'format_bold',
value: { isActive: state.fontWeight === 'bold',
fontWeight: state.fontWeight === 'bold' ? initialStyleState.fontWeight : 'bold', value: {
fontWeight: state.fontWeight === 'bold' ? initialStyleState.fontWeight : 'bold',
},
}, },
}, {
{ icon: 'format_italic',
icon: 'format_italic', isActive: state.fontStyle === 'italic',
isActive: state.fontStyle === 'italic', value: {
value: { fontStyle: state.fontStyle === 'italic' ? initialStyleState.fontStyle : 'italic',
fontStyle: state.fontStyle === 'italic' ? initialStyleState.fontStyle : 'italic', },
}, },
}, {
{ icon: 'format_underline',
icon: 'format_underline', isActive: state.textDecoration === 'underline',
isActive: state.textDecoration === 'underline', value: {
value: { textDecoration: state.textDecoration === 'underline' ? initialStyleState.textDecoration : 'underline',
textDecoration: state.textDecoration === 'underline' ? initialStyleState.textDecoration : 'underline', },
}, },
}, ],
{ [
icon: 'format_align_left', {
isActive: state.textAlign === 'left', icon: 'format_align_left',
value: { isActive: state.justifyContent === 'start',
textAlign: 'left', value: {
justifyContent: 'start',
},
}, },
}, {
{ icon: 'format_align_center',
icon: 'format_align_center', isActive: state.justifyContent === 'center',
isActive: state.textAlign === 'center', value: {
value: { justifyContent: state.justifyContent === 'center' ? initialStyleState.justifyContent : 'center',
textAlign: state.textAlign === 'center' ? initialStyleState.textAlign : 'center', },
}, },
}, {
{ icon: 'format_align_right',
icon: 'format_align_right', isActive: state.justifyContent === 'end',
isActive: state.textAlign === 'right', value: {
value: { justifyContent: state.justifyContent === 'end' ? initialStyleState.justifyContent : 'end',
textAlign: state.textAlign === 'right' ? initialStyleState.textAlign : 'right', },
}, },
}, ],
[
{
icon: 'vertical_align_bottom',
isActive: state.alignItems === 'end',
value: {
alignItems: state.alignItems === 'end' ? initialStyleState.alignItems : 'end',
},
},
{
icon: 'vertical_align_center',
isActive: state.alignItems === 'center',
value: {
alignItems: state.alignItems === 'center' ? initialStyleState.alignItems : 'center',
},
},
{
icon: 'vertical_align_top',
isActive: state.alignItems === 'start',
value: {
alignItems: state.alignItems === 'start' ? initialStyleState.alignItems : 'start',
},
},
],
]; ];
return btns.map(btn => toButton(btn)).join(' '); return btns.map(btn => (Array.isArray(btn) ? toButtonGroup(btn) : toButton(btn))).join(' ');
}
function toButtonGroup(buttons: ButtonConfigType[]) {
if (buttons.length === 1) return toButton(buttons[0]);
const btns = buttons.map(btn => toButton(btn));
return `
<div class="button__group">
${btns.join('')}
</div>
`;
} }
function toButton(button: ButtonConfigType) { function toButton(button: ButtonConfigType) {
@ -63,10 +101,7 @@ function toButton(button: ButtonConfigType) {
`; `;
return ` return `
<div <div class="button ${button.isActive ? 'active' : ''}"${meta}>
class="button ${button.isActive && 'active'}"
${meta}
>
<i class="material-icons" ${meta}>${button.icon}</i> <i class="material-icons" ${meta}>${button.icon}</i>
</div> </div>
`; `;

View File

@ -4,7 +4,7 @@ import { StateType } from 'redux/types';
import { storage } from 'core/utils'; import { storage } from 'core/utils';
export const initialStyleState: ToolbarStateType = { export const initialStyleState: ToolbarStateType = {
textAlign: 'left', justifyContent: 'start',
fontWeight: 'normal', fontWeight: 'normal',
textDecoration: 'none', textDecoration: 'none',
fontStyle: 'normal', fontStyle: 'normal',

View File

@ -12,7 +12,7 @@ type RoutesType = {
export class Router { export class Router {
private $placeholder: Dom; private $placeholder: Dom;
private routes: RoutesType; private routes: RoutesType;
private page: DashboardPage | ExcelPage | null; private page: DashboardPage | ExcelPage;
private loader: Dom; private loader: Dom;
constructor(selector: SelectorType, routes: RoutesType) { constructor(selector: SelectorType, routes: RoutesType) {
@ -20,7 +20,6 @@ export class Router {
this.$placeholder = $(selector); this.$placeholder = $(selector);
this.routes = routes; this.routes = routes;
this.page = null;
this.loader = Loader(); this.loader = Loader();
this.changePageHandler = this.changePageHandler.bind(this); this.changePageHandler = this.changePageHandler.bind(this);
@ -50,14 +49,13 @@ export class Router {
Page = this.routes.dashboard; Page = this.routes.dashboard;
break; break;
} }
// @ts-ignore
this.page = new Page(ActiveRoute.param); this.page = new Page(ActiveRoute.param);
const root = await this.page?.getRoot(); const root = await this.page.getRoot();
this.$placeholder.clear().append(root); this.$placeholder.clear().append(root);
this.page?.afterRender(); this.page.afterRender();
} }
destroy() { destroy() {

View File

@ -29,8 +29,8 @@ export class ExcelPage extends AbstractPage {
} }
async getRoot() { async getRoot() {
const normalizeState = await this.processor.get(); const state = await this.processor.get();
const store = new Store(rootReducer, normalizeState); const store = new Store(rootReducer, state);
this.storeSub = store.subscribe(this.processor.listen); this.storeSub = store.subscribe(this.processor.listen);

View File

@ -48,6 +48,7 @@
border-left: 0; border-left: 0;
white-space: nowrap; white-space: nowrap;
outline: none; outline: none;
display: flex;
&:hover:not(.selected) { &:hover:not(.selected) {
cursor: cell; cursor: cell;
} }

View File

@ -15,4 +15,11 @@
.button { .button {
@include button(green) @include button(green)
} }
}
.button__group {
border-right: 1px solid #c0c0c0;
&:last-child {
border: none;
}
}
}