Skip to content

Commit

Permalink
refactor(cxl-ui): cxl-section - improve hero responsiveness and visua…
Browse files Browse the repository at this point in the history
…l balance
  • Loading branch information
freudFlintstone committed Nov 29, 2023
1 parent f23d523 commit 936b9e9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
35 changes: 31 additions & 4 deletions packages/cxl-lumo-styles/scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
background-position: bottom right calc(50vw + clamp(48px,5%,100px)) !important;

&::before {
right: 47%;
height: 60%;
right: 50%;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
Expand All @@ -77,13 +76,41 @@
background-position: bottom left calc(50vw + clamp(48px,5%,100px)) !important;

&::before {
left: 47%;
height: 60%;
left: 50%;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
}

@mixin wide-background-header {
&::before {
height: clamp(164px, calc(2 * var(--figure-height-factor)), calc(100 * var(--figure-height-factor))/2);
bottom: 50%;
transform: translateY(50%);
}
}

// Use ::after pseudo element to add hero background image. url must be set to CSS custom property --hero-image
@mixin wide-background-header-image {
&::after {
content: "";
position: absolute;
left: 55%;
width: 100%;
height: clamp(calc(50% + 82px), calc(50% + var(--figure-height-factor)), calc(50% + var(--figure-height-factor)));
max-height: calc(50% + var(--figure-height-factor));
background-image: var(--hero-image);
background-repeat: no-repeat !important;
background-size: auto clamp(65%, 40vw, 100%) !important;
background-position-x: left !important;
background-position-y: bottom;
overflow: visible;
z-index: -1;
bottom: 50%;
transform: translateY(var(--figure-height-factor));
}
}

@mixin wide-background-color($background-color: var(--lumo-base-color)) {
&::before {
background-color: $background-color;
Expand Down
21 changes: 19 additions & 2 deletions packages/cxl-ui/scss/cxl-section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

:host {
display: block;
--figure-height-multiplier: 0.10;
--figure-height-factor: calc(var(--figure-height-multiplier) * var(--cxl-content-max-width-wide));
}

:host([theme~="cxl-section-dashboard-team-content"]) {
Expand Down Expand Up @@ -64,17 +66,32 @@
}

@media #{mq.$large} {
:host(#view-hero),
:host([theme~="cxl-header"]) {
:host(#view-hero) {
@include mixins.wide-background();
@include mixins.extend-background-right();
@include mixins.wide-background-header();
@include mixins.wide-background-header-image();
}

:host([theme~="cxl-header"]) {
@include mixins.wide-background();
@include mixins.extend-background-right();
@include mixins.wide-background-header();
@include mixins.wide-background-header-image();
}

:host(.wide-background) {
@include mixins.wide-background();
}

:host(.wide-background-header) {
@include mixins.wide-background-header();
}

:host(.wide-background-header-image) {
@include mixins.wide-background-header-image();
}

:host(.wide-background-left) {
@include mixins.extend-background-left();
}
Expand Down
19 changes: 16 additions & 3 deletions packages/cxl-ui/scss/global/cxl-section.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/* stylelint-disable selector-no-qualifying-type */
@use "~@conversionxl/cxl-lumo-styles/scss/mq";


// Use more specific selector to hide cxl-section background-image.
cxl-section.wp-block-group.wp-block-cxl-section#view-hero {
background: none !important;
}

cxl-section#view-hero, cxl-section[theme~="cxl-header"] {
.column-1 {
@media #{mq.$large} {
max-width: 40%;
max-width: 45%;
}
}

Expand All @@ -19,8 +25,15 @@ cxl-section#view-hero, cxl-section[theme~="cxl-header"] {
}

&.wide-background-light-blue {
.column-2 * {
color: var(--lumo-shade);
#view-hero .cxl-hero-titles {
bottom: 0;
transform: translateY(50%);
}

.column-2 {
* {
color: var(--lumo-shade);
}
}
}

Expand Down
24 changes: 19 additions & 5 deletions packages/storybook/cxl-ui/cxl-section/cxl-section.stories.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-multi-str */
import { html } from 'lit';
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import '@conversionxl/cxl-lumo-styles';
Expand All @@ -6,6 +7,21 @@ import '@vaadin/button';

export default {
title: 'CXL UI/cxl-section',
parameters: {
docs: {
description: {
component: 'Use `<cxl-section theme="cxl-header">` to create a section header component. \
`cxl-section` components with id="view-hero" are automatically themed as hero headers. \
Additionally, it is necessary to add CSS code in wordpress block-editor: \
\
\
`#view-hero::after { \
background-image: url([wpv-post-featured-image size="xx-large" output="url"]); \
}` \
',
},
}
}
};

export const CXLSectionHeader = (args) => html`
Expand Down Expand Up @@ -50,15 +66,13 @@ export const CXLSectionHeader = (args) => html`
}
@media screen and (min-width: 1024px) {
cxl-section {
background: url(https://cxl.com/institute/wp-content/uploads/2020/07/ben-labay_team_headshot-1x1-bw-min-1024x1024.png) no-repeat bottom right;
background-size: auto 100%;
background-position: bottom right 30%;
cxl-section#view-hero::after {
background-image: url("https://cxl.com/institute/wp-content/uploads/2020/07/ben-labay_team_headshot-1x1-bw-min-1024x1024.png");
}
}
</style>
<cxl-section theme="cxl-header" class="${args.backgroundColor} wide">
<cxl-section id="view-hero" class="${args.backgroundColor} wide">
<div class="wp-block-columns">
<div class="wp-block-column column-1 column-span-1 column-push-0">
<h1>${unsafeHTML(args.title)}</h1>
Expand Down

0 comments on commit 936b9e9

Please sign in to comment.