Skip to content

feat(splitter): splitter component #53

Merged
merged 50 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
dfd3442
Merge remote-tracking branch 'remotes/upstream/master'
Oct 8, 2018
e446b8e
feat(visual): initial composition
Oct 9, 2018
7d6aaee
feat(visual): script to run splitter example
Oct 9, 2018
1151012
feat(visual): cursor depends on gutter direction
Oct 10, 2018
9fe4e7c
feat(visual): default gutter image
Oct 10, 2018
fe5d613
feat(visual): support direction in parent container
Oct 10, 2018
1ee2195
feat(visual): gutter disabling
Oct 10, 2018
16470b6
feat(visual): splitter poc
Oct 10, 2018
4145970
feat(visual): unsubscribe from events when mouseup happens
Oct 11, 2018
fee2705
feat(visual): move ordering from code to html
Oct 11, 2018
91645c6
feat(visual): gutter moving animation
Oct 11, 2018
b2b4be8
feat(visual): update gutter icon
Oct 11, 2018
9eed2ca
feat(visual): fix area size determination
Oct 11, 2018
452bb2f
feat(visual): cleanup unused gutter properties
Oct 11, 2018
337318f
feat(visual): example update
Oct 11, 2018
81e4bec
feat(visual): fix vertical splitter icon
Oct 11, 2018
d739e54
feat(visual): refactoring
Oct 11, 2018
b0cae36
feat(visual): disabled splitter fix
Oct 11, 2018
2423935
feat(visual): disabled splitter example
Oct 11, 2018
3f0e342
feat(visual): clean
Oct 11, 2018
cf7fc5a
feat(visual): fix disabled splitter
Oct 11, 2018
5c602fa
feat(visual): inline layout direction
Oct 11, 2018
cfb0574
feat(visual): remove hardcoded border and fix
Oct 12, 2018
752c764
feat(visual): splitter theme support
Oct 12, 2018
8f3feb4
feat(visual): default direction
Oct 12, 2018
eee5eee
feat(splitter): add splitter to commitlint rules
Oct 12, 2018
91210b2
feat(splitter): fix splitter area remove
Oct 12, 2018
30b96aa
feat(splitter): default direction test
Oct 12, 2018
e5cecd7
feat(splitter): decrease gutter size
Oct 12, 2018
fe2543f
feat(splitter): apply theme for split icon
Oct 12, 2018
e17a8dc
feat(splitter): min-height and min-width support
Oct 12, 2018
4145601
feat(splitter): min-width example
Oct 12, 2018
424c6c0
feat(splitter): min-width example styles
Oct 12, 2018
c2dd9fe
feat(splitter): switch splitter color to secondary theme color
Oct 12, 2018
ef11957
feat(splitter): lint error fix
Oct 12, 2018
b9afd84
feat(splitter): sort commitlint
Oct 12, 2018
2f71c31
feat(splitter): splitter direction change test
Oct 12, 2018
b4b5535
feat(splitter): tests for specified direction
Oct 15, 2018
f2cdfce
feat(splitter): clean
Oct 15, 2018
6439c93
feat(splitter): add missed config
Oct 15, 2018
20bc081
feat(splitter): fix icon import
Oct 15, 2018
478d0fc
feat(splitter): remove superfluous exports
Oct 15, 2018
f2e90a0
feat(splitter): clean test
Oct 15, 2018
dbde386
feat(splitter): fix style for code review
Oct 16, 2018
0058754
feat(splitter): fix boolean properties for code review
Oct 16, 2018
c6d426b
feat(splitter): code review fix
Oct 16, 2018
f822570
feat(splitter): code review fix
Oct 16, 2018
8f784ce
feat(splitter): code review fix
Oct 17, 2018
91c2781
feat(splitter): code review fix
Oct 18, 2018
7f59911
feat(splitter): correct tests
Oct 18, 2018
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
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'progress-spinner',
'radio',
'select',
'splitter',
'tabs',
'timepicker',
'tooltip',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"server-dev:progress-spinner": "npm run server-dev -- --env.component progress-spinner",
"server-dev:radio": "npm run server-dev -- --env.component radio",
"server-dev:select": "npm run server-dev -- --env.component select",
"server-dev:splitter": "npm run server-dev -- --env.component splitter",
"server-dev:tag": "npm run server-dev -- --env.component tag",
"server-dev:theme-picker": "npm run server-dev -- --env.component theme-picker",
"server-dev:tree": "npm run server-dev -- --env.component tree",
Expand Down
34 changes: 34 additions & 0 deletions src/lib-dev/splitter/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, NgModule, ViewEncapsulation } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { McSplitterModule } from '../../lib/splitter';


@Component({
selector: 'app',
template: require('./template.html'),
styleUrls: ['./styles.scss'],
encapsulation: ViewEncapsulation.None
})
export class DemoComponent {}


@NgModule({
declarations: [
DemoComponent
],
imports: [
BrowserModule,
McSplitterModule
],
bootstrap: [
DemoComponent
]
})
export class DemoModule {}

platformBrowserDynamic()
.bootstrapModule(DemoModule)
.catch((error) => console.error(error));

17 changes: 17 additions & 0 deletions src/lib-dev/splitter/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@import '~@ptsecurity/mosaic-icons/dist/styles/mc-icons';
@import '../../lib/core/theming/prebuilt/default-theme';
@import '../../lib/core/visual/prebuilt/default-visual';

.horizontal-block {
height: 100px;
border: 1px solid black;
}

.vertical-block {
height: 300px;
border: 1px solid black;
}

.min-width-500 {
min-width: 30%;
}
55 changes: 55 additions & 0 deletions src/lib-dev/splitter/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<h1 class="mc-h1">Splitter examples</h1>

<p>
Splitter is designer to use with Mosaic icons and Mosaic flex layout so import VISUAL and ICONS to use it.
</p>

<h2 class="mc-h2">Horizontal</h2>

<mc-splitter class="horizontal-block" direction="horizontal">
<mc-splitter-area class="layout-padding">first</mc-splitter-area>
<mc-splitter-area class="flex-20 layout-padding">second</mc-splitter-area>
<mc-splitter-area class="layout-padding">third</mc-splitter-area>
</mc-splitter>

<br>

<h2 class="mc-h2">Vertical</h2>

<mc-splitter class="vertical-block" direction="vertical">
<mc-splitter-area class="layout-padding">first</mc-splitter-area>
<mc-splitter-area class="layout-padding">second</mc-splitter-area>
<mc-splitter-area class="layout-padding">third</mc-splitter-area>
</mc-splitter>

<br>

<h2 class="mc-h2">Default direction</h2>

<mc-splitter class="horizontal-block">
<mc-splitter-area class="flex-33 layout-padding">first</mc-splitter-area>
<mc-splitter-area class="flex layout-padding">second</mc-splitter-area>
<mc-splitter-area class="flex-33 layout-padding">third</mc-splitter-area>
</mc-splitter>

<br>

<h2 class="mc-h2">Disabled</h2>

<mc-splitter class="horizontal-block" direction="horizontal" disabled>
<mc-splitter-area class="flex-33 layout-padding">first</mc-splitter-area>
<mc-splitter-area class="flex-20 layout-padding">second</mc-splitter-area>
<mc-splitter-area class="flex layout-padding">third</mc-splitter-area>
</mc-splitter>

<br>

<h2 class="mc-h2">min-width for the first area</h2>

<mc-splitter class="horizontal-block">
<mc-splitter-area class="flex-33 layout-padding min-width-500">first</mc-splitter-area>
<mc-splitter-area class="flex-20 layout-padding">second</mc-splitter-area>
<mc-splitter-area class="flex layout-padding">third</mc-splitter-area>
</mc-splitter>

<br>
2 changes: 2 additions & 0 deletions src/lib/core/theming/_all-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import '../option/option-theme';
@import '../../tag/tag-theme';
@import '../../tooltip/tooltip-theme';
@import '../../splitter/splitter-theme';


@mixin mosaic-theme($theme) {
Expand All @@ -42,4 +43,5 @@
@include mc-option-theme($theme);
@include mc-tag-theme($theme);
@include mc-tooltip-theme($theme);
@include mc-splitter-theme($theme);
}
1 change: 1 addition & 0 deletions src/lib/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export * from '@ptsecurity/mosaic/radio';
export * from '@ptsecurity/mosaic/tree';
export * from '@ptsecurity/mosaic/tag';
export * from '@ptsecurity/mosaic/select';
export * from '@ptsecurity/mosaic/splitter';
export * from '@ptsecurity/mosaic/tooltip';

9 changes: 9 additions & 0 deletions src/lib/splitter/_splitter-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@mixin mc-splitter-theme($theme) {
$primary: map-get($theme, primary);
$second: map-get($theme, second);

.mc-gutter {
background-color: mc-color($second, 60);
color: mc-color($second, 600);
}
}
1 change: 1 addition & 0 deletions src/lib/splitter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
2 changes: 2 additions & 0 deletions src/lib/splitter/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './splitter.module';
export * from './splitter.component';
119 changes: 119 additions & 0 deletions src/lib/splitter/spliltter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { Component, Type } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { Direction, McGutterDirective, McSplitterAreaDirective, McSplitterComponent, McSplitterModule } from './index';


function createTestComponent<T>(component: Type<T>) {
TestBed
.resetTestingModule()
.configureTestingModule({
imports: [ McSplitterModule ],
declarations: [ component ],
providers: []
})
.compileComponents();

return TestBed.createComponent<T>(component);
}

function checkDirection<T>(fixture: ComponentFixture<T>,
direction: Direction,
guttersCount: number,
gutterSize: number) {

const splitter = fixture.debugElement.query(By.directive(McSplitterComponent));
const gutters = fixture.debugElement.queryAll(By.directive(McGutterDirective));

const mainAxisClass = direction === Direction.Vertical
? 'layout-column'
: 'layout-row';

const crossAxisClass = direction === Direction.Vertical
? 'layout-row'
: 'layout-column';

const expectedWidth = (direction === Direction.Vertical)
? ''
: `${gutterSize}px`;

const expectedHeight = (direction === Direction.Vertical)
? `${gutterSize}px`
: '';

expect(splitter.nativeElement.classList.contains(mainAxisClass)).toBe(true);
expect(splitter.nativeElement.classList.contains(crossAxisClass)).toBe(false);
expect(gutters.length).toBe(guttersCount);
expect(gutters.every((gutter) => gutter.nativeElement.style.width === expectedWidth)).toBe(true);
expect(gutters.every((gutter) => gutter.nativeElement.style.height === expectedHeight)).toBe(true);
}


@Component({
selector: 'mc-demo-spllitter',
template: `
<mc-splitter>
<mc-splitter-area>first</mc-splitter-area>
<mc-splitter-area>second</mc-splitter-area>
<mc-splitter-area>third</mc-splitter-area>
</mc-splitter>
`
})
class McSplitterDefaultDirection {}

@Component({
selector: 'mc-demo-spllitter',
template: `
<mc-splitter [direction]="direction">
<mc-splitter-area>first</mc-splitter-area>
<mc-splitter-area>second</mc-splitter-area>
<mc-splitter-area>third</mc-splitter-area>
</mc-splitter>
`
})
class McSplitterDirection {
direction: Direction = Direction.Vertical;
}

describe('McSplitter', () => {
describe('direction', () => {
it('should be default', () => {
const fixture = createTestComponent(McSplitterDefaultDirection);

fixture.detectChanges();

const areas = fixture.debugElement.queryAll(By.directive(McSplitterAreaDirective));
const expectedAreasCount = 3;
const expectedGuttersCount = expectedAreasCount - 1;
const expectedGutterSize = 6;

checkDirection(fixture, Direction.Horizontal, expectedGuttersCount, expectedGutterSize);

expect(areas.length).toBe(expectedAreasCount);
});


it('should be horizontal', () => {
const fixture = createTestComponent(McSplitterDirection);
const expectedGuttersCount = 2;
const expectedGutterSize = 6;

fixture.componentInstance.direction = Direction.Horizontal;
fixture.detectChanges();

checkDirection(fixture, Direction.Horizontal, expectedGuttersCount, expectedGutterSize);
});

it('should be vertical', () => {
const fixture = createTestComponent(McSplitterDirection);
const expectedGuttersCount = 2;
const expectedGutterSize = 6;

fixture.componentInstance.direction = Direction.Vertical;
fixture.detectChanges();

checkDirection(fixture, Direction.Vertical, expectedGuttersCount, expectedGutterSize);
});
});
});
12 changes: 12 additions & 0 deletions src/lib/splitter/splitter.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ng-content></ng-content>
<ng-template ngFor let-area [ngForOf]="areas" let-index="index" let-last="last">
<mc-gutter *ngIf="last === false"
[direction]="direction"
[disabled]="disabled"
[size]="gutterSize"
(mousedown)="onMouseDown($event, index, index + 1)"
class="mc-gutter flex-none layout-row layout-align-center-center flex-order-{{index * 2 + 1}}"
lskramarov marked this conversation as resolved.
Show resolved Hide resolved
>
<i class="mc-splitter-icon" mc-icon="mc-ellipsis_16" [class.mc-splitter-icon-vertical]="direction === 'vertical'" *ngIf="!disabled"></i>
</mc-gutter>
</ng-template>
Loading