Skip to content

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 25 commits into from
Jun 11, 2025
Merged

Carousel #1333

merged 25 commits into from
Jun 11, 2025

Conversation

oscarcarlstrom
Copy link
Contributor

@oscarcarlstrom oscarcarlstrom commented Jun 6, 2025

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

<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>
Screen.Recording.2025-06-06.at.14.34.39.mov

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:

<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>
Screen.Recording.2025-06-06.at.14.32.40.mov
Screen.Recording.2025-06-06.at.14.33.11.mov

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 and might come in handy in other places as well.

Copy link

changeset-bot bot commented Jun 6, 2025

🦋 Changeset detected

Latest commit: 2db7498

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@obosbbl/grunnmuren-tailwind Minor
@obosbbl/grunnmuren-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

@SondreKanstad SondreKanstad left a comment

Choose a reason for hiding this comment

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

Bra jobba 💪

className={cx(className, _className)}
// This can be used (internally) in other components
// to apply custom styles to the media element depending on the fit
data-fit={fit}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Her var egentlig planen å prøve å targete Media fra Carousel med en slik selector: &.\*\:object-contain:bg-blue-dark, men får det ikke til å funke med tailwind. Så har derfor lagt til dette custom-attributtet istedenfor.

Det føles også litt mer riktig, for da er det lettere å bruke dette til evt. annen styling man ønsker i spesielle tilfeller.

Copy link
Contributor

@alexanbj alexanbj left a comment

Choose a reason for hiding this comment

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

Nå begynner det å ligne på noe! Bra jobbet 👏

@oscarcarlstrom oscarcarlstrom merged commit 841009a into main Jun 11, 2025
3 checks passed
@oscarcarlstrom oscarcarlstrom deleted the carousel branch June 11, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants