Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(carousel): Add Carousel and Carousel Item components #8995

Merged
merged 77 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
2529282
feat(carousel): Add Carousel and Carousel Item components
macandcheese Mar 26, 2024
14565bf
Update Stencil config
macandcheese Mar 26, 2024
16e1846
Clean up
macandcheese Mar 26, 2024
bb61196
Clean up stories
macandcheese Mar 27, 2024
ecba582
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Mar 27, 2024
4202fd7
Add `tooltipsDisabled` property
macandcheese Mar 27, 2024
2cf3c34
Clean up
macandcheese Mar 27, 2024
ab95eb4
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Mar 27, 2024
0172cbc
Add `arrowType`, `controlApperance`, `label` properties
macandcheese Mar 27, 2024
7f9ea62
Clean up
macandcheese Mar 27, 2024
e957363
Clean up
macandcheese Mar 27, 2024
6d3f778
Remove `control-appearance` property
macandcheese Mar 28, 2024
7666e9a
Clean up
macandcheese Mar 28, 2024
280c955
Pr feedback
macandcheese Mar 28, 2024
64ef0d7
Pr feedback
macandcheese Mar 28, 2024
8792610
Clean up
macandcheese Mar 28, 2024
e36ba3e
Fix tests
macandcheese Mar 29, 2024
f8859ce
Update a11y
macandcheese Apr 1, 2024
14c37e8
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 1, 2024
7b27dd4
Update keyboard navigation
macandcheese Apr 1, 2024
e4f8cf5
Add tokens
macandcheese Apr 1, 2024
60523da
Clean up
macandcheese Apr 1, 2024
5e01998
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 2, 2024
232aea7
Pr feedback
macandcheese Apr 3, 2024
c5b8f1c
Pr feedback
macandcheese Apr 3, 2024
a356ff5
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 3, 2024
1acd4b7
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 3, 2024
c8083b3
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 8, 2024
263fc0f
Pr feedback
macandcheese Apr 8, 2024
8985835
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 8, 2024
b8cc6f8
Clean up
macandcheese Apr 9, 2024
7ffd224
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 9, 2024
dd41da3
Clean up
macandcheese Apr 9, 2024
332ad7a
Add `rotation` functionality
macandcheese Apr 9, 2024
5d298ff
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 9, 2024
8193945
Clean up
macandcheese Apr 9, 2024
bd3fe0b
Add swipe support
macandcheese Apr 9, 2024
63fafd2
Revert unrelated changes
macandcheese Apr 9, 2024
c143e53
Clean up
macandcheese Apr 9, 2024
3ee9203
Update tests
macandcheese Apr 10, 2024
6680d1a
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 15, 2024
c484694
Update `rotation` functionality
macandcheese Apr 18, 2024
2876f66
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 18, 2024
192c400
Clean up
macandcheese Apr 18, 2024
c78fe66
Add `rotationDuration` property
macandcheese Apr 18, 2024
72b889b
Clean up
macandcheese Apr 19, 2024
67517e9
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 19, 2024
2dfe6e6
Pause rotation on focus and hover, clean up
macandcheese Apr 19, 2024
2ee3d67
Clean up
macandcheese Apr 23, 2024
ba669a0
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 23, 2024
00ec116
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 23, 2024
dcdfcff
Localize a11y strings
macandcheese Apr 24, 2024
62f161f
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 25, 2024
b234d63
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 26, 2024
c5e648d
Pr feedback
macandcheese Apr 26, 2024
f6366cb
Pr feedback
macandcheese Apr 26, 2024
6fdc62e
Pr feedback
macandcheese Apr 26, 2024
fc7fdf7
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 26, 2024
18f9bc5
Clean up
macandcheese Apr 27, 2024
bc696d2
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 27, 2024
30e71a9
Clean up
macandcheese Apr 27, 2024
83e11c4
Pr feedback
macandcheese Apr 27, 2024
33f7914
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 29, 2024
79e9e9f
Pr feedback
macandcheese Apr 29, 2024
000c6b0
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 29, 2024
25c38d9
Pr feedback
macandcheese Apr 30, 2024
ba3842e
Pr feedback
macandcheese Apr 30, 2024
a41cee9
Pr feedback
macandcheese Apr 30, 2024
db346aa
Clean up
macandcheese Apr 30, 2024
683c1d0
Add method test
macandcheese Apr 30, 2024
d3a5df4
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 30, 2024
37424bb
Clean Up
macandcheese Apr 30, 2024
6ceea9d
Clean up
macandcheese Apr 30, 2024
93f8799
Merge branch 'main' into macandcheese/6536-add-new-carousel-component
macandcheese Apr 30, 2024
aeade1d
Clean up
macandcheese Apr 30, 2024
410141d
Clean up
macandcheese Apr 30, 2024
3b3576f
Clean up
macandcheese Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
162 changes: 162 additions & 0 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { BlockSectionMessages } from "./components/block-section/assets/block-se
import { ButtonAlignment, DropdownIconType } from "./components/button/interfaces";
import { ButtonMessages } from "./components/button/assets/button/t9n";
import { CardMessages } from "./components/card/assets/card/t9n";
import { ArrowType } from "./components/carousel/interfaces";
import { CarouselMessages } from "./components/carousel/assets/carousel/t9n";
import { ChipMessages } from "./components/chip/assets/chip/t9n";
import { ColorValue, InternalColor } from "./components/color-picker/interfaces";
import { Format } from "./components/color-picker/utils";
Expand Down Expand Up @@ -110,6 +112,8 @@ export { BlockSectionMessages } from "./components/block-section/assets/block-se
export { ButtonAlignment, DropdownIconType } from "./components/button/interfaces";
export { ButtonMessages } from "./components/button/assets/button/t9n";
export { CardMessages } from "./components/card/assets/card/t9n";
export { ArrowType } from "./components/carousel/interfaces";
export { CarouselMessages } from "./components/carousel/assets/carousel/t9n";
export { ChipMessages } from "./components/chip/assets/chip/t9n";
export { ColorValue, InternalColor } from "./components/color-picker/interfaces";
export { Format } from "./components/color-picker/utils";
Expand Down Expand Up @@ -826,6 +830,59 @@ export namespace Components {
*/
"setFocus": () => Promise<void>;
}
interface CalciteCarousel {
/**
* Specifies how and if the "previous" and "next" arrows are displayed.
*/
"arrowType": ArrowType;
/**
* Specifies if the component's controls are positioned absolutely on top of slotted Carousel Items.
*/
"controlOverlay": boolean;
/**
* When `true`, interaction is prevented and the component is displayed with lower opacity.
*/
"disabled": boolean;
/**
* Accessible name for the component.
*/
"label": string;
/**
* Use this property to override individual strings used by the component.
*/
"messageOverrides": Partial<CarouselMessages>;
/**
* Made into a prop for testing purposes only
*/
"messages": CarouselMessages;
/**
* When `true`, and `rotation` is `true`, the carousel will auto-rotate.
*/
"rotating": boolean;
/**
* When `true`, the rotation control is displayed.
*/
"rotation": boolean;
/**
* When `rotation` is `true`, specifies in milliseconds the length of time to display each Carousel Item.
*/
"rotationDuration": number;
/**
* The component's selected `calcite-carousel-item`.
* @readonly
*/
"selectedItem": HTMLCalciteCarouselItemElement;
}
interface CalciteCarouselItem {
/**
* Accessible name for the component.
*/
"label": string;
/**
* When `true`, the component is selected.
*/
"selected": boolean;
}
interface CalciteCheckbox {
/**
* When `true`, the component is checked.
Expand Down Expand Up @@ -5478,6 +5535,10 @@ export interface CalciteCardGroupCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLCalciteCardGroupElement;
}
export interface CalciteCarouselCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLCalciteCarouselElement;
}
export interface CalciteCheckboxCustomEvent<T> extends CustomEvent<T> {
detail: T;
target: HTMLCalciteCheckboxElement;
Expand Down Expand Up @@ -5956,6 +6017,32 @@ declare global {
prototype: HTMLCalciteCardGroupElement;
new (): HTMLCalciteCardGroupElement;
};
interface HTMLCalciteCarouselElementEventMap {
"calciteCarouselChange": void;
"calciteCarouselRotatingChange": void;
"calciteCarouselRotatingPause": void;
"calciteCarouselRotatingResume": void;
}
interface HTMLCalciteCarouselElement extends Components.CalciteCarousel, HTMLStencilElement {
addEventListener<K extends keyof HTMLCalciteCarouselElementEventMap>(type: K, listener: (this: HTMLCalciteCarouselElement, ev: CalciteCarouselCustomEvent<HTMLCalciteCarouselElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLCalciteCarouselElementEventMap>(type: K, listener: (this: HTMLCalciteCarouselElement, ev: CalciteCarouselCustomEvent<HTMLCalciteCarouselElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
var HTMLCalciteCarouselElement: {
prototype: HTMLCalciteCarouselElement;
new (): HTMLCalciteCarouselElement;
};
interface HTMLCalciteCarouselItemElement extends Components.CalciteCarouselItem, HTMLStencilElement {
}
var HTMLCalciteCarouselItemElement: {
prototype: HTMLCalciteCarouselItemElement;
new (): HTMLCalciteCarouselItemElement;
};
interface HTMLCalciteCheckboxElementEventMap {
"calciteInternalCheckboxBlur": boolean;
"calciteCheckboxChange": void;
Expand Down Expand Up @@ -7437,6 +7524,8 @@ declare global {
"calcite-button": HTMLCalciteButtonElement;
"calcite-card": HTMLCalciteCardElement;
"calcite-card-group": HTMLCalciteCardGroupElement;
"calcite-carousel": HTMLCalciteCarouselElement;
"calcite-carousel-item": HTMLCalciteCarouselItemElement;
"calcite-checkbox": HTMLCalciteCheckboxElement;
"calcite-chip": HTMLCalciteChipElement;
"calcite-chip-group": HTMLCalciteChipGroupElement;
Expand Down Expand Up @@ -8205,6 +8294,75 @@ declare namespace LocalJSX {
SelectionMode
>;
}
interface CalciteCarousel {
/**
* Specifies how and if the "previous" and "next" arrows are displayed.
*/
"arrowType"?: ArrowType;
/**
* Specifies if the component's controls are positioned absolutely on top of slotted Carousel Items.
*/
"controlOverlay"?: boolean;
/**
* When `true`, interaction is prevented and the component is displayed with lower opacity.
*/
"disabled"?: boolean;
/**
* Accessible name for the component.
*/
"label": string;
/**
* Use this property to override individual strings used by the component.
*/
"messageOverrides"?: Partial<CarouselMessages>;
/**
* Made into a prop for testing purposes only
*/
"messages"?: CarouselMessages;
/**
* Fires when the selected `calcite-carousel-item` changes.
*/
"onCalciteCarouselChange"?: (event: CalciteCarouselCustomEvent<void>) => void;
/**
* Fires when the carousel rotation state changes.
*/
"onCalciteCarouselRotatingChange"?: (event: CalciteCarouselCustomEvent<void>) => void;
/**
* Fires when the carousel rotation state pauses.
*/
"onCalciteCarouselRotatingPause"?: (event: CalciteCarouselCustomEvent<void>) => void;
/**
* Fires when the carousel rotation state resumes.
*/
"onCalciteCarouselRotatingResume"?: (event: CalciteCarouselCustomEvent<void>) => void;
/**
* When `true`, and `rotation` is `true`, the carousel will auto-rotate.
*/
"rotating"?: boolean;
/**
* When `true`, the rotation control is displayed.
*/
"rotation"?: boolean;
/**
* When `rotation` is `true`, specifies in milliseconds the length of time to display each Carousel Item.
*/
"rotationDuration"?: number;
/**
* The component's selected `calcite-carousel-item`.
* @readonly
*/
"selectedItem"?: HTMLCalciteCarouselItemElement;
}
interface CalciteCarouselItem {
/**
* Accessible name for the component.
*/
"label": string;
/**
* When `true`, the component is selected.
*/
"selected"?: boolean;
}
interface CalciteCheckbox {
/**
* When `true`, the component is checked.
Expand Down Expand Up @@ -13070,6 +13228,8 @@ declare namespace LocalJSX {
"calcite-button": CalciteButton;
"calcite-card": CalciteCard;
"calcite-card-group": CalciteCardGroup;
"calcite-carousel": CalciteCarousel;
"calcite-carousel-item": CalciteCarouselItem;
"calcite-checkbox": CalciteCheckbox;
"calcite-chip": CalciteChip;
"calcite-chip-group": CalciteChipGroup;
Expand Down Expand Up @@ -13184,6 +13344,8 @@ declare module "@stencil/core" {
"calcite-button": LocalJSX.CalciteButton & JSXBase.HTMLAttributes<HTMLCalciteButtonElement>;
"calcite-card": LocalJSX.CalciteCard & JSXBase.HTMLAttributes<HTMLCalciteCardElement>;
"calcite-card-group": LocalJSX.CalciteCardGroup & JSXBase.HTMLAttributes<HTMLCalciteCardGroupElement>;
"calcite-carousel": LocalJSX.CalciteCarousel & JSXBase.HTMLAttributes<HTMLCalciteCarouselElement>;
"calcite-carousel-item": LocalJSX.CalciteCarouselItem & JSXBase.HTMLAttributes<HTMLCalciteCarouselItemElement>;
"calcite-checkbox": LocalJSX.CalciteCheckbox & JSXBase.HTMLAttributes<HTMLCalciteCheckboxElement>;
"calcite-chip": LocalJSX.CalciteChip & JSXBase.HTMLAttributes<HTMLCalciteChipElement>;
"calcite-chip-group": LocalJSX.CalciteChipGroup & JSXBase.HTMLAttributes<HTMLCalciteChipGroupElement>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { accessible, hidden, renders } from "../../tests/commonTests";

describe("calcite-carousel-item", () => {
describe("renders", () => {
renders("<calcite-carousel-item selected></calcite-carousel-item>", {
display: "flex",
});
});

describe("honors hidden attribute", () => {
hidden("calcite-carousel-item");
});

describe("accessible", () => {
accessible("calcite-carousel-item");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:host {
@apply flex;
}

:host([selected]) .container {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should carousel be handling the visibility of items instead? I find it odd that a component would render invisible by default. cc @driskull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to match Tab's css rules, can change if needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move forward with this since there's already precedent. We can discuss hidden-by-default rules and make any adjustments in 3.x or 4.x. Impact might be low since item/child components aren't expected to be used standalone.

display: block;
}

.container {
macandcheese marked this conversation as resolved.
Show resolved Hide resolved
display: none;
inline-size: var(--calcite-container-size-content-fluid);
}

@include base-component();
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Component, Element, h, Host, Prop, VNode } from "@stencil/core";
import {
LoadableComponent,
setComponentLoaded,
setUpLoadableComponent,
} from "../../utils/loadable";
import { guid } from "../../utils/guid";
import { CSS } from "./resources";

/**
* @slot - A slot for adding content.
*/
@Component({
tag: "calcite-carousel-item",
styleUrl: "carousel-item.scss",
shadow: true,
})
export class CarouselItem implements LoadableComponent {
// --------------------------------------------------------------------------
//
// Properties
//
// --------------------------------------------------------------------------

/**
* When `true`, the component is selected.
*/
@Prop({ reflect: true }) selected = false;

/**
* Accessible name for the component.
*/
@Prop() label!: string;
macandcheese marked this conversation as resolved.
Show resolved Hide resolved

// --------------------------------------------------------------------------
//
// Private Properties
//
// --------------------------------------------------------------------------

@Element() el: HTMLCalciteCarouselItemElement;

private guid = `calcite-carousel-item-${guid()}`;

// --------------------------------------------------------------------------
//
// Lifecycle
//
// --------------------------------------------------------------------------

componentDidLoad(): void {
setComponentLoaded(this);
macandcheese marked this conversation as resolved.
Show resolved Hide resolved
}

async componentWillLoad(): Promise<void> {
setUpLoadableComponent(this);
}

// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------

render(): VNode {
const id = this.el.id || this.guid;
driskull marked this conversation as resolved.
Show resolved Hide resolved
return (
<Host id={id}>
<div
macandcheese marked this conversation as resolved.
Show resolved Hide resolved
aria-label={this.label}
class={{ [CSS.container]: true, [CSS.selected]: this.selected }}
role="tabpanel"
>
<slot />
</div>
</Host>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# calcite-carousel-item

<!-- Auto Generated Below -->

## Properties

| Property | Attribute | Description | Type | Default |
| -------------------- | ---------- | ---------------------------------------------------------------------------------------- | --------------------- | ----------- |
| `active` | `active` | When `true`, the component is active if it has a parent `calcite-carousel`. | `boolean` | `false` |
| `disabled` | `disabled` | When `true`, interaction is prevented and the component is displayed with lower opacity. | `boolean` | `false` |
| `label` *(required)* | `label` | The component label text. | `string` | `undefined` |
| `messageOverrides` | -- | Use this property to override individual strings used by the component. | `{ close?: string; }` | `undefined` |

## Methods

### `setFocus() => Promise<void>`

Sets focus on the component.

#### Returns

Type: `Promise<void>`

## Slots

| Slot | Description |
| ---- | -------------------------- |
| | A slot for adding content. |

---

*Built with [StencilJS](https://stenciljs.com/)*
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const CSS = {
container: "container",
selected: "selected",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"previous": "Previous",
"next": "Next",
"play": "Play",
"pause": "Pause",
"carousel": "Carousel",
"carouselItemProgress": "Progress indicator for Carousel Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"previous": "السابق",
"next": "التالي",
"play": "Play",
"pause": "Pause",
"carousel": "Carousel",
"carouselItemProgress": "Progress indicator for Carousel Item"
}