# st-three-dimensional-card-carousel

> Experimental 3D card carousel Web Component built with Stencil.

Latest version **0.0.44** (published 2020-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install st-three-dimensional-card-carousel
pnpm add st-three-dimensional-card-carousel
yarn add st-three-dimensional-card-carousel
bun add st-three-dimensional-card-carousel
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.44 |
| Published | 2020-04-09 |
| First published | 2019-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Adrián Brito |
| Maintainers | abritopach |
| Keywords | stencil, stenciljs, stencil-component, stenciljs-component, webcomponents |

## Links

- npm: https://www.npmjs.com/package/st-three-dimensional-card-carousel
- Repository: https://github.com/abritopach/st-3d-card-carousel
- Homepage: https://github.com/abritopach/st-3d-card-carousel#readme
- Issues: https://github.com/abritopach/st-3d-card-carousel/issues
- npm.io page: https://npm.io/package/st-three-dimensional-card-carousel

## Dependencies (2)

- [hammerjs](https://npm.io/package/hammerjs.md) ^2.0.8
- [font-awesome](https://npm.io/package/font-awesome.md) ^4.7.0

## Recent versions

- 0.0.44 (latest) — 2020-04-09
- 0.0.43 — 2020-04-09
- 0.0.42 — 2019-11-09
- 0.0.41 — 2019-11-07
- 0.0.39 — 2019-08-02
- 0.0.38 — 2019-07-26
- 0.0.37 — 2019-07-25
- 0.0.36 — 2019-07-24
- 0.0.35 — 2019-07-24
- 0.0.34 — 2019-07-23
- 0.0.33 — 2019-07-22
- 0.0.32 — 2019-07-22
- 0.0.31 — 2019-07-19
- 0.0.30 — 2019-07-18
- 0.0.29 — 2019-07-18
- … 24 more at https://npm.io/package/st-three-dimensional-card-carousel/versions

## README

![Built With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NjguNlYxNDEuN3oiLz4KPC9zdmc%2BCg%3D%3D&colorA=16161d&style=flat-square)

# Stencil 3D Card Carousel

[![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/abritopach) [![Version](https://img.shields.io/npm/v/st-three-dimensional-card-carousel.svg)](https://www.npmjs.com/package/st-three-dimensional-card-carousel) [![Downloads](https://img.shields.io/npm/dt/st-three-dimensional-card-carousel.svg)](https://www.npmjs.com/package/st-three-dimensional-card-carousel)

Sample project that shows an experimental 3D card carousel Web Component built with Stencil. A framework-agnostic web component that works in Ionic, Angular, React, Vue,...

Stencil is also great for building entire apps. For that, use the [stencil-app-starter](https://github.com/ionic-team/stencil-app-starter) instead.

<a href="https://www.buymeacoffee.com/h6WVj4HcD" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>

# Stencil

Stencil is a compiler for building fast web apps using Web Components.

Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool.  Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec.

Stencil components are just Web Components, so they work in any major framework or with no framework at all.

## Component preview

![Component](readme_resources/component_preview.gif "Component")

## Slides model

Slides: CardItem[] interface.

```bash

INTERFACE

export interface CardItem {
    id: number;
    title: string;
    description?: string;
    subtitle?: {
        text: string;
        icon?: string;
    };
    color: string;
    imgUrl: string;
    backgroundImgUrl?: string;
    footer?: {
        icons: {
            leftIcon: string;
            rightIcon: string;
        },
        values: {
            leftValue: number;
            rightValue: number;
        }
    },
    currentPlacement: number;
}

EXAMPLE SLIDES

slides = [{
    id: 1,
    title: 'User 1',
    description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
    subtitle: {
      text: 'Spain',
      icon: "fa fa-flag"
    },
    color: '#1abc9c',
    currentPlacement: 0,
    imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
    backgroundImgUrl: 'http://oxygennacdn3.oxygenna.com/wp-content/uploads/2015/11/18.jpg',
    footer: {
      icons: {
          leftIcon: "fa fa-users",
          rightIcon: "fa fa-comments"
      },
      values: {
          leftValue:12,
          rightValue: 4
      }
    }
  },
  {
      id: 2,
      title: 'User 2',
      description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin placerat molestie euismod. Etiam tincidunt luctus diam non ullamcorper. Maecenas eros est, iaculis hendrerit imperdiet nec, rhoncus in turpis. Vestibulum elementum mauris vitae nibh sagittis, et fermentum nunc aliquet. Donec sed ex sollicitudin, tristique sapien non, lacinia enim.',
      subtitle: {
        text: 'Spain',
        icon: "fa fa-flag"
      },
      color: '#e67e22',
      currentPlacement: 0,
      imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
      backgroundImgUrl: 'https://s-media-cache-ak0.pinimg.com/originals/d2/7b/4f/d27b4fa995194a0c77b8871a326a7c0b.jpg'
  }];

```

## Component properties

| Property       | Attribute        | Description | Type                                                        | Default                                                               |
| -------------- | ---------------- | ----------- | ----------------------------------------------------------- | --------------------------------------------------------------------- |
| `allowSwipeSlide`        | --                         |             | `{ prev: boolean; next: boolean; }`     | `{     prev: true,     next: true   }`                                      |
| `animationSelectedSlide` | `animation-selected-slide` |             | `boolean`                               | `true`
| `autoloop`     | --               |             | `{ enabled: boolean; seconds: number; direction: string; }` | `{     enabled: false,     seconds: 2000,     direction: 'right'   }` |
| `axis`         | `axis`           |             | `string`                                                    | `'horizontal'`
| `controls`     | --               |             | `{ enabled: boolean; position: string; text: string[]; }`   | `{     enabled: false,     position: 'top',     text: ['prev', 'next']   }` |
| `distance`     | `distance`       |             | `number`                                                    | `undefined`
| `initialSlide` | `initial-slide`  |             | `number`                                                    | `1`                                                                   |
| `keyboard`     | `keyboard`       |             | `boolean`                                                   | `false`
| `slideStyle`   | --               |             | `{}`                                                        | `{   }`
| `slides`       | --               |             | `CardItem[]`                                                | `[]`                                                                  |
| `slidesToShow` | `slides-to-show` |             | `number`                                                    | `6`

## Component events

| Event                  | Description | Type               |
| ---------------------- | ----------- | ------------------ |
| `currentItem`          |             | `CustomEvent<any>` |
| `reachBeginningSlides` |             | `CustomEvent<any>` |
| `reachEndSlides`       |             | `CustomEvent<any>` |
| `selectedItem`         |             | `CustomEvent<any>` |
| `slideChange`          |             | `CustomEvent<any>` |
| `slideDoubleTap`       |             | `CustomEvent<any>` |

## Component public API methods

### `addSlide(index: number, slides: CardItem | CardItem[]) => Promise<CardItem[]>`

```bash
Add new slides to the required index. Slides could be new slide or array with such slides.

const newSlides = [
  {
    id: Math.floor(Math.random() * 100),
    title: 'User ' + Math.random().toString(36).substr(2, 4),
    description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
    subtitle: {
      text: 'Spain',
      icon: "fa fa-flag"
    },
    color: '#e67e22',
    currentPlacement: 0,
    imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
    backgroundImgUrl: 'https://ak2.picdn.net/shutterstock/videos/19300069/thumb/9.jpg'
  },
  {
      id: Math.floor(Math.random() * 100),
      title: 'User ' + Math.random().toString(36).substr(2, 4),
      description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
      subtitle: {
        text: 'Spain',
        icon: "fa fa-flag"
      },
      color: '#e74c3c',
      currentPlacement: 0,
      imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
      backgroundImgUrl: 'http://oxygennacdn1.oxygenna.com/wp-content/uploads/2017/01/header-image-6.jpg'
  }
];

.addSlide(newSlides);
```



#### Returns

Type: `Promise<CardItem[]>`

### `appendSlide(slides: CardItem[]) => Promise<CardItem[]>`

```bash
Add new slide / slides to the end. Slides could be new slide or array with such slides.

const newSlides = [
  {
    id: Math.floor(Math.random() * 100),
    title: 'User ' + Math.random().toString(36).substr(2, 4),
    description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
    subtitle: {
      text: 'Spain',
      icon: "fa fa-flag"
    },
    color: '#e67e22',
    currentPlacement: 0,
    imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
    backgroundImgUrl: 'https://ak2.picdn.net/shutterstock/videos/19300069/thumb/9.jpg'
  },
  {
      id: Math.floor(Math.random() * 100),
      title: 'User ' + Math.random().toString(36).substr(2, 4),
      description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
      subtitle: {
        text: 'Spain',
        icon: "fa fa-flag"
      },
      color: '#e74c3c',
      currentPlacement: 0,
      imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
      backgroundImgUrl: 'http://oxygennacdn1.oxygenna.com/wp-content/uploads/2017/01/header-image-6.jpg'
  },
  {
    id: Math.floor(Math.random() * 100),
    title: 'User ' + Math.random().toString(36).substr(2, 4),
    description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
    subtitle: {
      text: 'Spain',
      icon: "fa fa-flag"
    },
    color: '#e67e22',
    currentPlacement: 0,
    imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
    backgroundImgUrl: 'https://ak2.picdn.net/shutterstock/videos/19300069/thumb/9.jpg'
  },
  {
      id: Math.floor(Math.random() * 100),
      title: 'User ' + Math.random().toString(36).substr(2, 4),
      description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
      subtitle: {
        text: 'Spain',
        icon: "fa fa-flag"
      },
      color: '#e74c3c',
      currentPlacement: 0,
      imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
      backgroundImgUrl: 'http://oxygennacdn1.oxygenna.com/wp-content/uploads/2017/01/header-image-6.jpg'
  },
];

  const newSlide = {
    id: 18,
    title: 'User 18',
    description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
    subtitle: {
      text: 'Spain',
      icon: "fa fa-flag"
    },
    color: '#e67e22',
    currentPlacement: 0,
    imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
    backgroundImgUrl: 'https://ak2.picdn.net/shutterstock/videos/19300069/thumb/9.jpg'
  }

.appendSlide(newSlides);
.appendSlide(newSlide);

```



#### Returns

Type: `Promise<CardItem[]>`




### `cycle() => Promise<boolean>`

```bash
Restarts cycling through the slides from left to right.
```



#### Returns

Type: `Promise<boolean>`



### `getActiveIndex() => Promise<number>`

```bash
Get the index of the active slide.
```



#### Returns

Type: `Promise<number>`



### `getNextIndex() => Promise<number>`

```bash
Get the index of the next slide.
```



#### Returns

Type: `Promise<number>`



### `getPreviousIndex() => Promise<number>`

```bash
Get the index of the previous slide.
```



#### Returns

Type: `Promise<number>`



### `isBeginning() => Promise<boolean>`

```bash
Get whether or not the current slide is the first slide.
```



#### Returns

Type: `Promise<boolean>`



### `isEnd() => Promise<boolean>`

```bash
Get whether or not the current slide is the last slide.
```



#### Returns

Type: `Promise<boolean>`



### `length() => Promise<number>`

```bash
Get the total number of slides.
```



#### Returns

Type: `Promise<number>`



### `loadMore() => Promise<CardItem[]>`



#### Returns

Type: `Promise<CardItem[]>`



### `moreSlides() => Promise<boolean>`



#### Returns

Type: `Promise<boolean>`



### `next() => Promise<CardItem>`

```bash
Navigates to the next slide.
```



#### Returns

Type: `Promise<CardItem>`



### `prependSlide(slides: CardItem | CardItem[]) => Promise<CardItem[]>`

```bash
Add new slide / slides to the beginning. Slides could be new slide or array with such slides.

const newSlides = [
  {
    id: Math.floor(Math.random() * 100),
    title: 'User ' + Math.random().toString(36).substr(2, 4),
    description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
    subtitle: {
      text: 'Spain',
      icon: "fa fa-flag"
    },
    color: '#e67e22',
    currentPlacement: 0,
    imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
    backgroundImgUrl: 'https://ak2.picdn.net/shutterstock/videos/19300069/thumb/9.jpg'
  },
  {
      id: Math.floor(Math.random() * 100),
      title: 'User ' + Math.random().toString(36).substr(2, 4),
      description: 'Wait a minute. Wait a minute, Doc. Uhhh...',
      subtitle: {
        text: 'Spain',
        icon: "fa fa-flag"
      },
      color: '#e74c3c',
      currentPlacement: 0,
      imgUrl: 'https://www.resa.es/wp-content/uploads/2015/07/icon-user-default.png',
      backgroundImgUrl: 'http://oxygennacdn1.oxygenna.com/wp-content/uploads/2017/01/header-image-6.jpg'
  }
];

.prependSlide(newSlides);
```



#### Returns

Type: `Promise<CardItem[]>`




### `prev() => Promise<CardItem>`

```bash
Navigates to the previous slide.
```


#### Returns

Type: `Promise<CardItem>`



### `reloadSlides() => Promise<CardItem[]>`



#### Returns

Type: `Promise<CardItem[]>`



### `removeAllSlides() => Promise<CardItem[]>`



#### Returns

Type: `Promise<CardItem[]>`



### `removeSlide(slideIndex: number | number[]) => Promise<CardItem[]>`



#### Returns

Type: `Promise<CardItem[]>`



### `select(slideId: string | number) => Promise<CardItem>`

```bash
Go to specific slide by number or keywords.

.select(3);
.select('prev');
.select('next');
.select('first');
.select('last');
```


#### Returns

Type: `Promise<CardItem>`



### `slideReset() => Promise<CardItem>`

```bash
Reset swiper position to initial slide.
```


#### Returns

Type: `Promise<CardItem>`



## Getting Started

Before you go through this component, you should have at least a basic understanding of Stencil concepts.

```bash
git clone https://github.com/abritopach/st-3d-card-carousel
cd st-3d-card-carousel
```

and run:

```bash
npm install
npm start
```

To build the component for production, run:

```bash
npm run build
```

To run the unit tests for the components, run:

```bash
npm test
```

## Naming Components

When creating new component tags, we recommend _not_ using `stencil` in the component name (ex: `<stencil-datepicker>`). This is because the generated component has little to nothing to do with Stencil; it's just a web component!

Instead, use a prefix that fits your company or any name for a group of related components. For example, all of the Ionic generated web components use the prefix `ion`.


## Using this component


### Ionic / Angular project

1) Install the package.

```bash
npm install st-three-dimensional-card-carousel --save
```

2) Modify main.ts to import and make a call to defineCustomElements.

```bash
import { enableProdMode } from '@angular/core'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'

import { AppModule } from './app/app.module'
import { environment } from './environments/environment'

import { defineCustomElements } from 'st-three-dimensional-card-carousel/dist/loader'

if (environment.production) {
  enableProdMode()
}

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch(err => console.log(err))
defineCustomElements(window)
```

3) Add the CUSTOM_ELEMENTS_SCHEMA.

```bash
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
import { CommonModule } from '@angular/common'
import { IonicModule } from '@ionic/angular'
import { FormsModule } from '@angular/forms'
import { RouterModule } from '@angular/router'

import { HomePage } from './home.page'

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild([
      {
        path: '',
        component: HomePage,
      },
    ]),
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  declarations: [HomePage],
})
export class HomePageModule {}
```

4) Use 3D card carousel web component in html

```bash
<st-3D-card-carousel [slides]="slides" [autoloop]="autoloop" [distance]="slideDistance" (selectedItem)="handleSelectedItem($event)"
  (slideChange)="handleSlideChange($event)"></st-3D-card-carousel>
```

### Vue project

1) Install the package.

```bash
npm install st-three-dimensional-card-carousel --save
```

2) Modify main.js to import and make a call to defineCustomElements.


```bash
import Vue from 'vue'
import App from './App.vue'

import { defineCustomElements, applyPolyfills } from 'st-three-dimensional-card-carousel/loader';

Vue.config.productionTip = false

// tell Vue to ignore all components defined in the st-three-dimensional-card-carousel/loader
// package. The regex assumes all components names are prefixed.
// 'st'
Vue.config.ignoredElements = [/st-\w*/];

// Bind the custom elements to the window object.
applyPolyfills().then(() => {
  defineCustomElements(window);
});

new Vue({
  render: h => h(App),
}).$mount('#app')
```

3) Use 3D card carousel web component in jsx

Vue provides a way to explicitly pass the object as a property rather than an attribute, it is as simple as adding .prop to the property name of the stencil component.

```bash
<st-3D-card-carousel v-bind:slides.prop="slides" v-bind:autoloop.prop="autoloop"></st-3D-card-carousel>
```

### Example Ionic project

- Component in Ionic project: https://github.com/abritopach/ionic-employees-stitch-mongodb

![Component](readme_resources/component_ionic.gif "Component")

### Example Angular project

- Component in Angular project: https://github.com/abritopach/angular-architecture

![Component](readme_resources/component_angular.gif "Component")

### Example React project

### Example Vue project

- Component in Vue project: https://github.com/abritopach/vue-stencil-3d-card-carousel

![Component](readme_resources/component_vue.gif "Component")

### Script tag

- [NPM](https://www.npmjs.com/package/st-three-dimensional-card-carousel)
- Put a script tag similar to this `<script src='https://unpkg.com/st-three-dimensional-card-carousel@0.0.1/dist/st-three-dimensional-card-carousel.js'></script>` in the head of your index.html
- Then you can use the element anywhere in your template, JSX, html etc

### Node Modules
- Run `npm install st-three-dimensional-card-carousel --save`
- Put a script tag similar to this `<script src='node_modules/my-component/dist/st-three-dimensional-card-carousel.js'></script>` in the head of your index.html
- Then you can use the element anywhere in your template, JSX, html etc

### In a stencil-starter app
- Run `npm install st-three-dimensional-card-carousel --save`
- Add an import to the npm packages `import st-three-dimensional-card-carousel;`
- Then you can use the element anywhere in your template, JSX, html etc

---
_Source: https://npm.io/package/st-three-dimensional-card-carousel · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
