-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
:host .carousel-container /deep/ > * { | ||
flex-shrink: 0; | ||
} | ||
:host { | ||
position: relative; | ||
} | ||
.carousel-step-dot { | ||
width: 6px; | ||
height: 6px; | ||
border-radius: 6px; | ||
position: relative; | ||
} | ||
.carousel-step-dot:after { | ||
content: ''; | ||
position: absolute; | ||
left: -4px; | ||
top: -4px; | ||
width: 14px; | ||
height: 14px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div #carouselOverflowContainer class="overflow-hidden h-full w-full"> | ||
<div class="carousel-container flex flex-row" [ngClass]="containerClass"> | ||
<ng-content></ng-content> | ||
</div> | ||
</div> | ||
<div | ||
class="absolute right-0 top-0 flex flex-row justify-center gap-[10px] p-1" | ||
[ngClass]="stepsContainerClass" | ||
> | ||
<button | ||
*ngFor="let step of steps; let i = index" | ||
class="carousel-step-dot" | ||
(click)="scrollToStep(i)" | ||
[ngClass]="selectedStep === i ? 'bg-secondary' : 'bg-gray-400'" | ||
></button> | ||
</div> |
21 changes: 21 additions & 0 deletions
21
libs/ui/layout/src/lib/carousel/carousel.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { CarouselComponent } from './carousel.component' | ||
|
||
describe('CarouselComponent', () => { | ||
let component: CarouselComponent | ||
let fixture: ComponentFixture<CarouselComponent> | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [CarouselComponent], | ||
}).compileComponents() | ||
|
||
fixture = TestBed.createComponent(CarouselComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
libs/ui/layout/src/lib/carousel/carousel.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Meta, StoryObj } from '@storybook/angular' | ||
import { CarouselComponent } from './carousel.component' | ||
import { componentWrapperDecorator } from '@storybook/angular' | ||
|
||
const meta: Meta<CarouselComponent> = { | ||
component: CarouselComponent, | ||
title: 'Layout/CarouselComponent', | ||
decorators: [ | ||
componentWrapperDecorator( | ||
(story) => | ||
`<div class="border border-gray-300 h-[150px] w-[800px] overflow-auto" style="resize: both">${story}</div>` | ||
), | ||
], | ||
} | ||
export default meta | ||
type Story = StoryObj<CarouselComponent> | ||
|
||
export const Primary: Story = { | ||
args: {}, | ||
render: (args) => ({ | ||
props: args, | ||
template: ` | ||
<gn-ui-carousel containerClass='py-4 gap-4 h-full'> | ||
<div class='border border-black w-[160px] ml-[calc(50%-80px)]'> | ||
First box | ||
</div> | ||
<div class='border border-black w-[240px]'> | ||
Second box | ||
</div> | ||
<div class='border border-black w-[180px]'> | ||
Third box | ||
</div> | ||
<div class='border border-black w-[120px]'> | ||
Fourth box | ||
</div> | ||
<div class='border border-black w-[280px] mr-[calc(50%-140px)]'> | ||
Fifth box | ||
</div> | ||
</gn-ui-carousel> | ||
`, | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
AfterViewInit, | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
ElementRef, | ||
Input, | ||
ViewChild, | ||
} from '@angular/core' | ||
import EmblaCarousel, { EmblaCarouselType } from 'embla-carousel' | ||
|
||
@Component({ | ||
selector: 'gn-ui-carousel', | ||
templateUrl: './carousel.component.html', | ||
styleUrls: ['./carousel.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class CarouselComponent implements AfterViewInit { | ||
@Input() containerClass = '' | ||
@Input() stepsContainerClass = '' | ||
@ViewChild('carouselOverflowContainer') | ||
carouselOverflowContainer: ElementRef | ||
steps: number[] = [] | ||
selectedStep = -1 | ||
emblaApi: EmblaCarouselType | ||
|
||
constructor(private changeDetector: ChangeDetectorRef) {} | ||
|
||
ngAfterViewInit() { | ||
this.emblaApi = EmblaCarousel( | ||
this.carouselOverflowContainer.nativeElement, | ||
{ | ||
duration: 15, | ||
} | ||
) | ||
const refreshSteps = () => { | ||
this.steps = this.emblaApi.scrollSnapList() | ||
this.selectedStep = this.emblaApi.selectedScrollSnap() | ||
this.changeDetector.detectChanges() | ||
} | ||
this.emblaApi | ||
.on('init', refreshSteps) | ||
.on('reInit', refreshSteps) | ||
.on('select', refreshSteps) | ||
} | ||
|
||
scrollToStep(stepIndex: number) { | ||
this.emblaApi.scrollTo(stepIndex) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters