Home

Awesome

Ngx Stories

An Angular component to render instagram like stories.

npm downloads npm version

For Version 17+

Installation

Install the library via npm:

npm install ngx-stories
import { NgxStoriesComponent, StoryGroup } from 'ngx-stories';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [NgxStoriesComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  storyGroups: StoryGroup[] = [
      {
        id: 1,
        name: 'John Doe',
        stories: [
          { id: 101, type: 'image', content: 'https://example.com/story1.jpg' },
          { id: 101, type: 'component', content: CustomComponent }, // pass any angular component to render in stories
        ],
      },
      {
        id: 2,
        name: 'Jane Smith',
        stories: [
          { id: 103, type: 'image', content: 'https://example.com/story3.jpg' },
          { id: 3, type: 'video', content: 'https://example.com/video-story.mp4' },
        ],
      },
    ];
  }
<ngx-stories [storyGroups]="storyGroups"></ngx-stories>

Properties

PropertyTypeRequiredDescription
storyGroupsStoryGroup[]YesAn input property that accepts an array of story groups. Each group contains a list of stories to display.
optionsNgxStoriesOptionsNoConfiguration options for the story display. Options include width and height to customize the dimensions.
triggerOnEndEventEmitter<void>NoOutput event that is triggered when the user reaches the end of all stories.
triggerOnExitEventEmitter<void>NoOutput event that is triggered when the user manually exits the story view.
triggerOnSwipeUpEventEmitter<void>NoOutput event that is triggered when the user performs a swipe-up gesture, typically for additional actions.
onStoryGroupChangeEventEmitter<number>NoOutput event that is triggered when the user changes the storyGroup.
interface NgxStoriesOptions {
  width: number, // width of story
  height: number, // height of story
  currentStoryIndex: 0, // index from where stories should start
  currentStoryGroupIndex: 0, // index from where story group should start
  backlitColor: string // background color of story default is #1b1b1b
}

Features

Contributing

Contributing Guide

License

This library is licensed under the MIT License. Feel free to use and modify the code as per your needs.