-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Implement Material 3 image carousel component #113
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { html, LitElement, css, isServer } from 'lit' | ||
|
|
||
| export class CarouselItem extends LitElement { | ||
| constructor() { | ||
| super() | ||
| this.internals = this.attachInternals() | ||
| if (!isServer) { | ||
| this.internals.role = 'listitem' | ||
| } | ||
| } | ||
|
|
||
| render() { | ||
| return html` | ||
| <div class="carousel-item"> | ||
| <slot></slot> | ||
| </div> | ||
| ` | ||
| } | ||
|
|
||
| static styles = [ | ||
| css` | ||
| :host { | ||
| display: block; | ||
| border-radius: var(--md-carousel-item-border-radius, 28px); | ||
| overflow: hidden; | ||
| height: 100%; | ||
| width: var(--md-carousel-item-width, 240px); /* Multi-browse width by default */ | ||
| } | ||
| .carousel-item { | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| align-items: center; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
| ::slotted(img) { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
| } | ||
| `, | ||
| ] | ||
| } | ||
|
|
||
| customElements.define('md-carousel-item', CarouselItem) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||
| import { html, LitElement, css, isServer } from 'lit' | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export class Carousel extends LitElement { | ||||||||||||||||||||||||||
| constructor() { | ||||||||||||||||||||||||||
| super() | ||||||||||||||||||||||||||
| this.internals = this.attachInternals() | ||||||||||||||||||||||||||
| if (!isServer) { | ||||||||||||||||||||||||||
| this.internals.role = 'list' | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| render() { | ||||||||||||||||||||||||||
| return html` | ||||||||||||||||||||||||||
| <div class="carousel" aria-label="carousel"> | ||||||||||||||||||||||||||
| <slot></slot> | ||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| static styles = [ | ||||||||||||||||||||||||||
| css` | ||||||||||||||||||||||||||
| :host { | ||||||||||||||||||||||||||
| display: block; | ||||||||||||||||||||||||||
| width: 100%; | ||||||||||||||||||||||||||
| overflow: hidden; | ||||||||||||||||||||||||||
| border-radius: var(--md-carousel-border-radius, 28px); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| .carousel { | ||||||||||||||||||||||||||
| display: flex; | ||||||||||||||||||||||||||
| overflow-x: auto; | ||||||||||||||||||||||||||
| scroll-snap-type: x mandatory; | ||||||||||||||||||||||||||
| scrollbar-width: none; /* Firefox */ | ||||||||||||||||||||||||||
| -ms-overflow-style: none; /* Internet Explorer 10+ */ | ||||||||||||||||||||||||||
| gap: var(--md-carousel-gap, 8px); | ||||||||||||||||||||||||||
| padding: var(--md-carousel-padding, 0); | ||||||||||||||||||||||||||
| height: 100%; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| .carousel::-webkit-scrollbar { | ||||||||||||||||||||||||||
| display: none; /* WebKit */ | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| ::slotted(*) { | ||||||||||||||||||||||||||
| flex: 0 0 auto; | ||||||||||||||||||||||||||
| scroll-snap-align: start; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* M3 dynamic item sizing using CSS Scroll-driven Animations */ | ||||||||||||||||||||||||||
| animation: material-carousel-item-resize linear both; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||
| animation-timeline: view(inline); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @keyframes material-carousel-item-resize { | ||||||||||||||||||||||||||
| 0% { | ||||||||||||||||||||||||||
| width: var(--md-carousel-small-width, 40px); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 15% { | ||||||||||||||||||||||||||
| width: var(--md-carousel-large-width, 240px); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| 85% { | ||||||||||||||||||||||||||
| width: var(--md-carousel-large-width, 240px); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable name
Suggested change
|
||||||||||||||||||||||||||
| 100% { | ||||||||||||||||||||||||||
| width: var(--md-carousel-small-width, 40px); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| customElements.define('md-carousel', Carousel) | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
aria-label="carousel"is a hardcoded string, which is problematic for internationalization. Additionally,aria-labelshould generally not be used on adivwithout a semantic role (likeregionorlist), as it may be ignored by assistive technologies. Since the host element already hasrole="list", any descriptive label should be provided by the consumer on the host element itself.