ASU Web Standards-based implementation of @glidejs/glide
npm library carousel.
This component is a simple react application showing four different carousels in the Component views
section.
The core functionalities, such as transitions, responsiveness, are provided by the library glidejs
.
The BaseCarousel
component is the core of the application that implements glidejs
APIs,
it used as a blueprint
to create every custom carousel, it can be found in /src/core/components/BaseCarousel/index.js
.
The new Carousel Component
has 4 types of views:
- Card Carousel view
- Immge Carousel view
- Image Galllery Carousel view
- Testomonial Carousel view
/**
* @typedef {{
* id: number
* imageSource: string
* imageAltText: string
* title: string
* content?: string
* eventLocation?: string
* buttons?: {
* ariaLabel: string,
* color?: "gold" | "maroon" | "gray" | "dark"
* href?: string,
* label: string,
* onClick?: () => void,
* size: "default" | "small" | "xsmall"
* }[]
* eventTime?: string
* linkLabel?: string
* linkUrl?: string
* tags?: {
* ariaLabel: string,
* color: "white" | "gray" | "dark"
* href: string,
* label: string,
* onClick: () => void,
* } []
* }} CardItem
*/
/**
* @param {{
* perView: string | number
* cardItems: CardItem []
* cardType?: "default" | "degree" | "event" | "news" | "story"
* cardEventFormat?: "stack" | "inline"
* cardHorizontal?: boolean
* maxWidth?: string
* width?: string
* imageAutoSize?: boolean
* }} props
*/
/**
* @typedef {{
* id: number
* imageSource: string
* imageAltText: string
* title?: string
* content?: string
* }} ImageItem
*/
/**
* @param {{
* perView: number
* imageItems: ImageItem []
* maxWidth?: string
* width?: string
* imageAutoSize?: boolean
* }} props
*/
/**
* @typedef {{
* id: number,
* imageSource: string,
* thumbnailSource?: string,
* imageAltText:string
* content?: any
* }} ImageCarouselItem
*/
/**
* @param {{
* maxWidth?: string
* width?: string
* hasContent?: boolean
* imageItems: ImageCarouselItem []
* imageAutoSize?: boolean
* }} props
*/
/**
* @typedef {{
* containerCssClass?: string[]
* titleCssClass?: string[]
* contentCssClass?: string[]
* }} TestimonialStyle
*/
/**
* @typedef {{
* id: number
* imageSource?: string
* imageAltText?:string
* quote: {
* title?: string
* content: string
* cite?: {
* name: string
* description?: string
* }
* }
* }} TestimonialItem
*/
/**
* @param {{
* testimonialItems: TestimonialItem[]
* maxWidth: string
* width?: string
* hasPositionIndicators?: boolean
* hasNavButtons?: boolean
* itemStyle?:ItemCssClass
* imageAutoSize?: boolean
* }} props
*/
You can find a full list of props into the docs/README.props.md
# add component-carousel
yarn add @asu/component-carousel
# run storybook
yarn storybook
# build for production with minification
yarn build
# run tests
yarn test
# it generates the document `docs/README.props.md`
yarn docs
# it generates full jsdoc documentation
yarn jsdoc
- Make sure you are set up to use the private npm registry at registry.web.asu.edu. See instructures in the 'How to use private package registry' here: README.md
yarn add @asu/component-carousel
import { AsuCarousel } from '@asu/component-carousel@dev'
// Define your carousel items. Contents of "item:" should be a Unity
// Design System Card. Only one example provided below.
const myCarouselItems = [
{
id: 0,
imageSource: "https://source.unsplash.com/random/500x400?a=-1",
imageAltText: "Card image cap",
title: "Card 1",
content:
"Body 1 copy goes here. Limit to 5 lines max. Lorem ipsum dolor sit\n amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt\n ut labore et dolore magna aliqua eiusmod tempo.",
buttons: [
{
ariaLabel: "dummy button",
color: "maroon",
href: "#",
label: `Button 1 link here`,
size: "default",
onClick: () => window.alert("Holoa Amigo π."),
},
],
},
{
id: 1,
imageSource: "https://source.unsplash.com/random/300x400?a=0",
imageAltText: "Card image cap",
title: "Card 2",
content:
"Body 2 copy goes here. Limit to 5 lines max. Lorem ipsum dolor sit\n amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt\n ut labore et dolore magna aliqua eiusmod tempo.",
buttons: [
{
ariaLabel: "dummy button",
color: "maroon",
href: "#",
label: `Button 2 link here`,
size: "default",
onClick: () => window.alert("Holoa Amigo π."),
},
],
},
{
id: 2,
imageSource: "https://source.unsplash.com/random/400x400?a=1",
imageAltText: "Card image cap",
title: "Card 3",
content:
"Body 3 copy goes here. Limit to 5 lines max. Lorem ipsum dolor sit\n amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt\n ut labore et dolore magna aliqua eiusmod tempo.",
buttons: [
{
ariaLabel: "dummy button",
color: "maroon",
href: "#",
label: `Button 3 link here`,
size: "default",
onClick: () => window.alert("Holoa Amigo π."),
},
],
},
{
id: 3,
imageSource: "https://source.unsplash.com/random/200x200?a=2",
imageAltText: "Card image cap",
title: "Card 4",
content:
"Body 4 copy goes here. Limit to 5 lines max. Lorem ipsum dolor sit\n amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt\n ut labore et dolore magna aliqua eiusmod tempo.",
buttons: [
{
ariaLabel: "dummy button",
color: "maroon",
href: "#",
label: `Button 4 link here`,
size: "default",
onClick: () => window.alert("Hola Amigo π."),
},
],
},
];
// Build out the component, providing your carousel items and setting the
// perView prop to either 1, 2 or 3 to define number of slides to show at a
// time.
const App = (props) => {
return (
<div>
<CardCarousel perView={1} cardItems={myCarouselItems} />
</div>
)
};
export default App;
<!-- Provide target divs for two carousels. Must have unique ids. -->
<div id="carouselContainer"></div>
<div id="anotherCarouselContainer"></div>
<!-- include bundled scripts from Preact packages -->
<script src="/node_modules/@asu/component-carousel/dist/vendor.umd.js"></script>
<script src="/node_modules/@asu/component-carousel/dist/asuCarousel.umd.js"></script>
<script>
// Setup and initialize the first carousel.
var props = {
targetSelector: "#carouselContainer",
carouselItems: myCarouselItems, // See myCarouselItems example above.
perView: 3,
maxWidth: "100%", // Is not mandatory
};
AsuWebCarousel.initCardCarousel(props);
// Setup and initialize the second carousel.
AsuWebCarousel.initCardCarousel({
targetSelector: "#anotherCarouselContainer",
props: {
cardItems: differentCarouselItems,// To be built by implementer.
perView: 1,
maxWidth: "500px", // Is not mandatory
},
});
</script>
The folder packages/component-carousel/examples
contains examples to use the carousel on static HTML page
If you want to test the examples files you need to install an application server
and run it into the folder /packages/component-carousel/examples
.
For example, if you want to use the npm
package lite-server
follow these steps:
- run
npm -g i lite-server
. MAC users may need to usesudo npm -g i lite-server
- run
cd packages/component-carousel
- run
lite-server
- open the broweser to the url
http://localhost:3000/examples/card.html
(port number may be different)
All the requirements for this component were covered, so there is no need of any further enhancements at the moment this is being written.