Skip to content

Commit

Permalink
feat(carousel): allow to display multiple items per one slide
Browse files Browse the repository at this point in the history
  • Loading branch information
musienkoyuriy committed Apr 16, 2019
1 parent 4711a61 commit dd1fe87
Show file tree
Hide file tree
Showing 24 changed files with 723 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Component } from '@angular/core';

import { demoComponentContent } from './carousel-section.list';
import { ContentSection } from '../../docs/models/content-section.model';

@Component({
selector: 'carousel-section',
templateUrl: './carousel-section.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
templateUrl: './carousel-section.component.html'
})
export class CarouselSectionComponent {
name = 'Carousel';
Expand Down
24 changes: 24 additions & 0 deletions demo/src/app/components/+carousel/carousel-section.list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { DemoCarouselIntervalComponent } from './demos/interval/interval';
import { DemoCarouselDisableIndicatorComponent } from './demos/disable-indicator/disable-indicator';
import { DemoCarouselDisableLoopingComponent } from './demos/disable-looping/disable-looping';
import { DemoCarouselSlideChangedEventComponent } from './demos/slide-changed-event/slide-changed-event';
import { DemoCarouselMultilistComponent } from './demos/multilist/multilist';
import { DemoCarouselMultilistSingleOffsetComponent } from './demos/multilist-single-offset/multilist-single-offset';
import { DemoCarouselMultilistFromIndexComponent } from './demos/multilist-from-index/multilist-from-index';
import { DemoAccessibilityComponent } from './demos/accessibility/accessibility';

import { ContentSection } from '../../docs/models/content-section.model';
Expand Down Expand Up @@ -105,6 +108,27 @@ export const demoComponentContent: ContentSection[] = [
html: require('!!raw-loader?lang=markup!./demos/slide-changed-event/slide-changed-event.html'),
outlet: DemoCarouselSlideChangedEventComponent
},
{
title: 'Multilist',
anchor: 'multilist',
component: require('!!raw-loader?lang=typescript!./demos/multilist/multilist.ts'),
html: require('!!raw-loader?lang=markup!./demos/multilist/multilist.html'),
outlet: DemoCarouselMultilistComponent
},
{
title: 'Multilist Single Offset',
anchor: 'multilist-single-offset',
component: require('!!raw-loader?lang=typescript!./demos/multilist-single-offset/multilist-single-offset.ts'),
html: require('!!raw-loader?lang=markup!./demos/multilist-single-offset/multilist-single-offset.html'),
outlet: DemoCarouselMultilistSingleOffsetComponent
},
{
title: 'Multilist Start From Index',
anchor: 'multilist-from-index',
component: require('!!raw-loader?lang=typescript!./demos/multilist-from-index/multilist-from-index.ts'),
html: require('!!raw-loader?lang=markup!./demos/multilist-from-index/multilist-from-index.html'),
outlet: DemoCarouselMultilistFromIndexComponent
},
{
title: 'Accessibility',
anchor: 'accessibility',
Expand Down
6 changes: 6 additions & 0 deletions demo/src/app/components/+carousel/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { DemoCarouselIntervalComponent } from './interval/interval';
import { DemoCarouselDisableIndicatorComponent } from './disable-indicator/disable-indicator';
import { DemoCarouselDisableLoopingComponent } from './disable-looping/disable-looping';
import { DemoCarouselSlideChangedEventComponent } from './slide-changed-event/slide-changed-event';
import { DemoCarouselMultilistComponent } from './multilist/multilist';
import { DemoCarouselMultilistSingleOffsetComponent } from './multilist-single-offset/multilist-single-offset';
import { DemoCarouselMultilistFromIndexComponent } from './multilist-from-index/multilist-from-index';
import { DemoAccessibilityComponent } from './accessibility/accessibility';

export const DEMO_COMPONENTS = [
Expand All @@ -22,5 +25,8 @@ export const DEMO_COMPONENTS = [
DemoCarouselDisableIndicatorComponent,
DemoCarouselDisableLoopingComponent,
DemoCarouselSlideChangedEventComponent,
DemoCarouselMultilistComponent,
DemoCarouselMultilistSingleOffsetComponent,
DemoCarouselMultilistFromIndexComponent,
DemoAccessibilityComponent
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>
You can set specific index to start from it
</p>
<carousel [itemsPerSlide]="itemsPerSlide"
[singleSlideOffset]="singleSlideOffset"
[startFromIndex]="6"
[interval]="false"
[infinite]="infinite">
<slide *ngFor="let slide of slides; let index=index">
<img [src]="slide.image" alt="image slide" style="display: block; width: 100%;">
<div class="carousel-caption">
<h4>Slide {{index}}</h4>
</div>
</slide>
</carousel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-carousel-multilist-from-index',
templateUrl: './multilist-from-index.html'
})
export class DemoCarouselMultilistFromIndexComponent {
itemsPerSlide = 5;
singleSlideOffset = true;
infinite = true;

slides = [
{image: 'assets/images/nature/1.jpg'},
{image: 'assets/images/nature/2.jpg'},
{image: 'assets/images/nature/3.jpg'},
{image: 'assets/images/nature/4.jpg'},
{image: 'assets/images/nature/5.jpg'},
{image: 'assets/images/nature/6.jpg'},
{image: 'assets/images/nature/7.jpg'},
{image: 'assets/images/nature/8.jpg'},
{image: 'assets/images/nature/1.jpg'},
{image: 'assets/images/nature/2.jpg'}
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p>
There is ability to shift slide not only by amount of all visible slides but also for one item
</p>
<carousel [itemsPerSlide]="itemsPerSlide"
[singleSlideOffset]="singleSlideOffset"
[interval]="false"
[infinite]="infinite">
<slide *ngFor="let slide of slides; let index=index">
<img [src]="slide.image" alt="image slide" style="display: block; width: 100%;">
<div class="carousel-caption">
<h4>Slide {{index}}</h4>
</div>
</slide>
</carousel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-carousel-multilist-single-offset',
templateUrl: './multilist-single-offset.html'
})
export class DemoCarouselMultilistSingleOffsetComponent {
itemsPerSlide = 5;
singleSlideOffset = true;
infinite = true;

slides = [
{image: 'assets/images/nature/1.jpg'},
{image: 'assets/images/nature/2.jpg'},
{image: 'assets/images/nature/3.jpg'},
{image: 'assets/images/nature/4.jpg'},
{image: 'assets/images/nature/5.jpg'},
{image: 'assets/images/nature/6.jpg'},
{image: 'assets/images/nature/7.jpg'},
{image: 'assets/images/nature/8.jpg'},
{image: 'assets/images/nature/1.jpg'},
{image: 'assets/images/nature/2.jpg'}
];
}
24 changes: 24 additions & 0 deletions demo/src/app/components/+carousel/demos/multilist/multilist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<carousel [itemsPerSlide]="itemsPerSlide"
[singleSlideOffset]="singleSlideOffset"
[infinite]="infinite"
[interval]="false"
[startFromIndex]="5"
(slideRangeChange)="onSlideRangeChange($event)">
<slide *ngFor="let slide of slides; let index=index">
<img [src]="slide.image" alt="image slide" style="display: block; width: 100%;">
<div class="carousel-caption">
<h4>Slide {{index}}</h4>
</div>
</slide>
</carousel>

<div class="container" [ngStyle]="{'marginTop': '20px'}">
<div class="checkbox">
<label>
<input type="checkbox" [(ngModel)]="infinite">
Infinite
</label>
</div>
</div>

<pre class="card card-block card-header">{{slidesChangeMessage}}</pre>
30 changes: 30 additions & 0 deletions demo/src/app/components/+carousel/demos/multilist/multilist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-carousel-multilist',
templateUrl: './multilist.html'
})
export class DemoCarouselMultilistComponent {
itemsPerSlide = 3;
singleSlideOffset = false;
infinite = false;

slidesChangeMessage = '';

slides = [
{image: 'assets/images/nature/1.jpg'},
{image: 'assets/images/nature/2.jpg'},
{image: 'assets/images/nature/3.jpg'},
{image: 'assets/images/nature/4.jpg'},
{image: 'assets/images/nature/5.jpg'},
{image: 'assets/images/nature/6.jpg'},
{image: 'assets/images/nature/7.jpg'},
{image: 'assets/images/nature/8.jpg'},
{image: 'assets/images/nature/1.jpg'},
{image: 'assets/images/nature/2.jpg'}
];

onSlideRangeChange(indexes: number[]): void {
this.slidesChangeMessage = `Slides have been switched: ${indexes}`;
}
}
5 changes: 2 additions & 3 deletions demo/src/app/docs/api-docs/sample-box/sample-box.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Component, Input } from '@angular/core';

@Component({
selector: 'ng-sample-box',
templateUrl: './sample-box.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
templateUrl: './sample-box.component.html'
})
export class SampleBoxComponent {
@Input() ts: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ChangeDetectionStrategy, Component, HostListener } from '@angular/core';
import { Component, HostListener } from '@angular/core';

import { ContentSection } from '../../models/content-section.model';
import { ComponentExample } from '../../models/components-examples.model';

@Component({
selector: 'examples',
templateUrl: './examples.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
templateUrl: './examples.component.html'
})
export class ExamplesComponent {
examples: ComponentExample[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Component } from '@angular/core';
import { ContentSection } from '../../models/content-section.model';
import { ComponentsTopSection } from '../../models/components-top-section.model';

@Component({
selector: 'demo-top-section',
templateUrl: './demo-top-section.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
templateUrl: './demo-top-section.component.html'
})
export class DemoTopSectionComponent {
sectionContent: ComponentsTopSection;
Expand Down
3 changes: 1 addition & 2 deletions demo/src/app/docs/docs-section/docs-section.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ContentSection } from '../models/content-section.model';
import { ChangeDetectionStrategy, Component, Injector, Input, ReflectiveInjector } from '@angular/core';
import { Component, Injector, Input, ReflectiveInjector } from '@angular/core';

@Component({
selector: 'docs-section',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-container *ngFor="let section of content">
<ng-container *ngComponentOutlet="section.outlet; injector: sectionInjections(section)">
Expand Down
1 change: 0 additions & 1 deletion demo/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'classlist-polyfill';

// import 'intl';
// import 'intl/locale-data/jsonp/en';
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"ci:rename-pkg": "mv node_modules/ngx-bootstrap-ci node_modules/ngx-bootstrap",
"build.sass": "node-sass --recursive src --output dist --source-map true --source-map-contents sass",
"start": "ng serve --aot --host 0.0.0.0",
"pretest": "run-s lint build",
"test": "ng test && npm run test:schematics",
"test:schematics": "jasmine schematics/src/**/*.spec.js",
"test-cross": "SAUCE=true ng test",
Expand Down
8 changes: 5 additions & 3 deletions scripts/build-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ async function buildAll() {

await execa.shell(`npm run link`);

const requiredModules = ['collapse', 'chronos', 'utils', 'positioning', 'component-loader', 'dropdown', 'locale',
'alert', 'buttons', 'carousel', 'mini-ngrx', 'modal', 'pagination', 'popover', 'progressbar', 'rating',
'sortable', 'tabs', 'timepicker', 'tooltip', 'typeahead', 'datepicker', 'accordion', 'common'];
// const requiredModules = ['collapse', 'chronos', 'utils', 'positioning', 'component-loader', 'dropdown', 'locale',
// 'alert', 'buttons', 'carousel', 'mini-ngrx', 'modal', 'pagination', 'popover', 'progressbar', 'rating',
// 'sortable', 'tabs', 'timepicker', 'tooltip', 'typeahead', 'datepicker', 'accordion', 'common'];

const requiredModules = ['utils', 'carousel', 'common'];

await buildModules(requiredModules);

Expand Down
6 changes: 3 additions & 3 deletions src/carousel/carousel.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<ol class="carousel-indicators" *ngIf="showIndicators && slides.length > 1">
<li *ngFor="let slidez of slides; let i = index;" [class.active]="slidez.active === true" (click)="selectSlide(i)"></li>
</ol>
<div class="carousel-inner"><ng-content></ng-content></div>
<a class="left carousel-control carousel-control-prev" [class.disabled]="activeSlide === 0 && noWrap" (click)="previousSlide()" *ngIf="slides.length > 1">
<div class="carousel-inner" [ngStyle]="{'display': multilist ? 'flex' : 'block'}"><ng-content></ng-content></div>
<a class="left carousel-control carousel-control-prev" [class.disabled]="activeSlide === 0 && noWrap && !infinite" (click)="previousSlide()" *ngIf="slides.length > 1">
<span class="icon-prev carousel-control-prev-icon" aria-hidden="true"></span>
<span *ngIf="isBs4" class="sr-only">Previous</span>
</a>
<a class="right carousel-control carousel-control-next" (click)="nextSlide()" [class.disabled]="isLast(activeSlide) && noWrap" *ngIf="slides.length > 1">
<a class="right carousel-control carousel-control-next" (click)="nextSlide()" [class.disabled]="isLast(activeSlide) && noWrap && !infinite" *ngIf="slides.length > 1">
<span class="icon-next carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
Expand Down
Loading

0 comments on commit dd1fe87

Please sign in to comment.