-
Notifications
You must be signed in to change notification settings - Fork 2
Carousel #1333
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
Merged
Merged
Carousel #1333
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c58a366
Add carousel component
oscarcarlstrom 265c16c
Add examples with carousel
oscarcarlstrom 9defe09
Fix prev/next buttons
oscarcarlstrom c6f6304
Update examples
oscarcarlstrom d2dcb28
Sync scoll snap with buttons
oscarcarlstrom 30b9971
Fix focus styles
oscarcarlstrom c0f18e4
Fix object-fit default
oscarcarlstrom 1a1d131
Expose carousel components
oscarcarlstrom f8894b4
Make classNames easier to read
oscarcarlstrom bb94dcf
Remove opacity transition on buttons
oscarcarlstrom 6de4fa4
Add changeset
oscarcarlstrom 2899aad
Update examples
oscarcarlstrom c12301a
Update notes
oscarcarlstrom 4d6542d
Organize imports
oscarcarlstrom d39da93
Auto-render prev/next button
oscarcarlstrom d60de41
Remove console.log
oscarcarlstrom 2b45ddc
Merge branch 'main' into carousel
oscarcarlstrom bdf6e65
Refactor Carousel API
oscarcarlstrom adc0a25
Remove redundant CSS classes
oscarcarlstrom e473704
Remove comment
oscarcarlstrom 8c0053f
Fix comment
oscarcarlstrom baa0d8a
Update code examples
oscarcarlstrom 08c0a45
Organize imports
oscarcarlstrom b446473
Update notes
oscarcarlstrom 2db7498
Only apply bg color to object-contain images
oscarcarlstrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
"@obosbbl/grunnmuren-tailwind": minor | ||
"@obosbbl/grunnmuren-react": minor | ||
--- | ||
|
||
# Carousel | ||
|
||
## grunnmuren-react | ||
New `Carousel` component that can be used for any content, all though primarily intended for media such as images and `VideoLoops`. | ||
|
||
## Usage | ||
``` tsx | ||
<Carousel> | ||
<CarouselItems> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/f_auto,c_limit,w_2048,q_auto/v1582122753/Boligprosjekter/Oslo/Ulven/Ulven-N%C3%A6romr%C3%A5de-Oslo-OBOS-Construction-city.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/v1587988823/Boligprosjekter/Oslo/Frysjaparken/Frysjalia/Frysjaparken_interi%C3%B8r_30.jpg" | ||
alt="" | ||
/> | ||
</CarouselI | ||
</Media>tem> | ||
<CarouselItem> | ||
// This image has a portrait aspect ratio | ||
<Media fit="contain"> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/f_auto,c_limit,w_1080,q_auto:best/t_2_3/v1747985572/Temasider/Folk/Hans%20Petter%20%20-%20Trang%20f%C3%B8dsel/Obos-Hans-Petter-Aaserud-Photo-Einar-Aslaksen-03093_web.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/v1699879884/Boligprosjekter/Oslo/Frysjaparken/Ager/Originale%20bilder/OBOS_Frysja-Ager-Illustrasjon_av_Frysja_torg_i_Ager_borettslag.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
</CarouselItems> | ||
</Carousel> | ||
``` | ||
|
||
Use the `fit` prop on the `<Media>` primitive to control the `object-fit` (`cover` | `contain`) behavior of it's children, this is a way to prevent cropping of images in portrait format. This defaults to `cover`, so for portrait images set it to `contain`. | ||
|
||
### In Hero | ||
|
||
The component can also be used inside the `<Hero>` component: | ||
``` tsx | ||
<Hero variant="full-bleed"> | ||
<Content> | ||
<Heading level={1}>Ulven</Heading> | ||
<Description>– et nytt nabolag i Oslo</Description> | ||
</Content> | ||
<Carousel> | ||
<CarouselItems> | ||
<CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<VideoLoop | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/video/upload/v1732199756/Mellom%20husene/Frysja_Loop2.mp4" | ||
format="mp4" | ||
alt="En postbil kjører rundt i det moderne nabolaget på Frysja. Her finnes det fine uteområder, med husker og kafeer." | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/f_auto,c_limit,w_2048,q_auto/v1582122753/Boligprosjekter/Oslo/Ulven/Ulven-N%C3%A6romr%C3%A5de-Oslo-OBOS-Construction-city.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/v1587988823/Boligprosjekter/Oslo/Frysjaparken/Frysjalia/Frysjaparken_interi%C3%B8r_30.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
// This image has a portrait aspect ratio | ||
<Media fit="contain"> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/f_auto,c_limit,w_1080,q_auto:best/t_2_3/v1747985572/Temasider/Folk/Hans%20Petter%20%20-%20Trang%20f%C3%B8dsel/Obos-Hans-Petter-Aaserud-Photo-Einar-Aslaksen-03093_web.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/v1699879884/Boligprosjekter/Oslo/Frysjaparken/Ager/Originale%20bilder/OBOS_Frysja-Ager-Illustrasjon_av_Frysja_torg_i_Ager_borettslag.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
</CarouselItems> | ||
</Carousel> | ||
</Hero> | ||
``` | ||
|
||
## grunnmuren-tailwind | ||
|
||
A new `scrollbar-hidden` utility class has been added which hides scorllbar visually. This is needed in the `<Carousel>` component, as it uses `snap-scroll`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { | ||
UNSAFE_Carousel as Carousel, | ||
UNSAFE_CarouselItem as CarouselItem, | ||
UNSAFE_CarouselItems as CarouselItems, | ||
} from '../carousel'; | ||
import { Media } from '../content'; | ||
|
||
const meta: Meta<typeof Carousel> = { | ||
title: 'Carousel', | ||
component: Carousel, | ||
parameters: { | ||
// disable built in padding in story, because we provide our own | ||
variant: 'fullscreen', | ||
}, | ||
render: () => ( | ||
<main className="container grid gap-y-8"> | ||
<Carousel> | ||
<CarouselItems> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/f_auto,c_limit,w_2048,q_auto/v1582122753/Boligprosjekter/Oslo/Ulven/Ulven-N%C3%A6romr%C3%A5de-Oslo-OBOS-Construction-city.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/v1587988823/Boligprosjekter/Oslo/Frysjaparken/Frysjalia/Frysjaparken_interi%C3%B8r_30.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media fit="contain"> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/f_auto,c_limit,w_1080,q_auto:best/t_2_3/v1747985572/Temasider/Folk/Hans%20Petter%20%20-%20Trang%20f%C3%B8dsel/Obos-Hans-Petter-Aaserud-Photo-Einar-Aslaksen-03093_web.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
<CarouselItem> | ||
<Media> | ||
<img | ||
src="https://res.cloudinary.com/obosit-prd-ch-clry/image/upload/v1699879884/Boligprosjekter/Oslo/Frysjaparken/Ager/Originale%20bilder/OBOS_Frysja-Ager-Illustrasjon_av_Frysja_torg_i_Ager_borettslag.jpg" | ||
alt="" | ||
/> | ||
</Media> | ||
</CarouselItem> | ||
</CarouselItems> | ||
</Carousel> | ||
</main> | ||
), | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Carousel>; | ||
|
||
export const StandardWithLeadAndImage: Story = { | ||
args: {}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.