Skip to content

Commit

Permalink
feat(storefront): BCTHEME-343 No tooltips provided for carousel butto…
Browse files Browse the repository at this point in the history
…ns (#1934)
  • Loading branch information
yurytut1993 committed Dec 30, 2020
1 parent babdd27 commit 50741d9
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- No tooltips provided for carousel buttons. [#1934](https://github.com/bigcommerce/cornerstone/pull/1934)

## 5.0.0 (12-14-2020)
- Parse HTML entities in jsContext. [#1917](https://github.com/bigcommerce/cornerstone/pull/1917)
Expand Down
2 changes: 2 additions & 0 deletions assets/js/theme/common/carousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'slick-carousel';

import {
dotsSetup,
tooltipSetup,
setTabindexes,
arrowAriaLabling,
heroCarouselSetup,
Expand Down Expand Up @@ -33,6 +34,7 @@ const onCarouselChange = (event, carousel) => {
dotsSetup($dots, actualSlide, actualSlideCount, $slider.data('dots-labels'));
setTabindexes($slider.find('.slick-slide'), $prevArrow, $nextArrow, actualSlide, actualSlideCount);
arrowAriaLabling($prevArrow, $nextArrow, actualSlide, actualSlideCount);
tooltipSetup($prevArrow, $nextArrow, $dots);
};

export default function () {
Expand Down
1 change: 1 addition & 0 deletions assets/js/theme/common/carousel/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as arrowAriaLabling } from './arrowAriaLabling';
export { default as dotsSetup } from './dotsSetup';
export { default as getRealSlidesQuantityAndCurrentSlide } from './getRealSlidesQuantityAndCurrentSlide';
export { default as setTabindexes } from './setTabindexes';
export { default as tooltipSetup } from './tooltipSetup';
30 changes: 30 additions & 0 deletions assets/js/theme/common/carousel/utils/tooltipSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const carouselTooltipClass = 'carousel-tooltip';
const carouselTooltip = `<span class="${carouselTooltipClass}"></span>`;

const setupTooltipAriaLabel = ($node) => {
const $existedTooltip = $node.find(`.${carouselTooltipClass}`);

if ($existedTooltip.length) {
$existedTooltip.attr('aria-label', $node.attr('aria-label'));
} else {
const $tooltip = $(carouselTooltip).attr('aria-label', $node.attr('aria-label'));
$node.append($tooltip);
}
};

const setupArrowTooltiops = (...arrowNodes) => {
arrowNodes.forEach($arrow => setupTooltipAriaLabel($arrow));
};

const setupDotTooltiops = ($dots) => {
$dots.children().each((idx, dot) => setupTooltipAriaLabel($(dot).find('button')));
};

export default ($prevArrow, $nextArrow, $dots) => {
if ($prevArrow.length && $nextArrow.length) {
setupArrowTooltiops($prevArrow, $nextArrow);
}
if ($dots) {
setupDotTooltiops($dots);
}
};
37 changes: 37 additions & 0 deletions assets/scss/common/_focus-tooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@mixin addFocusTooltip ($attr: title) {
&:before {
content: " ";
position: absolute;
right: 0;
top: 50%;
border-width: remCalc(10px);
border-style: solid;
border-color: transparent transparent $adminBar-tooltip-bg-backgroundColor transparent;
}

&:after {
content: attr($attr);
padding: remCalc(4px) remCalc(6px);
background-color: $adminBar-tooltip-bg-backgroundColor;
color: white;
position: absolute;
font-size: 1rem;
white-space: nowrap;
right: 0;
top: 100%;
cursor: default;
border-radius: remCalc(8px);
}

&:before,
&:after {
display: none;
}

&:focus {
&:before,
&:after {
display: block;
}
}
}
1 change: 1 addition & 0 deletions assets/scss/common/index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import 'aria';
@import 'focus-tooltip';
28 changes: 0 additions & 28 deletions assets/scss/components/foundation/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@
// // 1. Fix for content shifted to top in modal window when bottom variant option selected
// =============================================================================

@mixin addFocusTooltip () {
&:focus {
&:before {
content: " ";
position: absolute;
right: 0;
top: 50%;
border-width: remCalc(10px);
border-style: solid;
border-color: transparent transparent $adminBar-tooltip-bg-backgroundColor transparent;
}

&:after {
content: attr(title);
padding: remCalc(4px) remCalc(6px);
background-color: $adminBar-tooltip-bg-backgroundColor;
color: white;
position: absolute;
font-size: 1rem;
white-space: nowrap;
right: 0;
top: 100%;
cursor: default;
border-radius: remCalc(8px);
}
}
}

.modal {
margin: 0;
max-height: 90%;
Expand Down
27 changes: 15 additions & 12 deletions assets/scss/components/stencil/heroCarousel/_heroCarousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
min-width: 100%;
margin-bottom: (spacing("double") + spacing("single"));
margin-top: -(spacing("single")); // 3
overflow: hidden;
opacity: 0;

&.is-visible {
Expand All @@ -30,8 +29,6 @@
}

&.slick-initialized {
max-height: 100vh;

@include breakpoint("small") {
max-height: remCalc(400px);
}
Expand Down Expand Up @@ -126,11 +123,11 @@
}

.heroCarousel-image-wrapper {
height: remCalc(250px);
display: flex;
justify-content: center;
align-items: flex-start;
height: 56.25vw;
max-height: 100vh;

@include breakpoint("small") {
max-height: remCalc(400px);
Expand All @@ -142,24 +139,30 @@
}

&.is-square-image-type {

.heroCarousel-image-wrapper {
height: 100vw;

@include breakpoint("small") {
height: 56.25vw;
}
}
}

&.is-vertical-image-type {

.heroCarousel-image-wrapper {
height: 110vw;

}
}

&.is-square-image-type,
&.is-vertical-image-type {
.heroCarousel-image-wrapper {
max-height: 100vh;

@include breakpoint("small") {
height: 56.25vw;
}
max-height: remCalc(400px);
}

@include breakpoint("medium") {
max-height: remCalc(600px);
}
}
}
}
Expand Down
68 changes: 66 additions & 2 deletions assets/scss/components/vendor/slick/_slick.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}

.slick-next {
right: -10px;
right: $slick-arrows-offset;

@include breakpoint("large") {
right: -(spacing("double") + spacing("quarter"));
Expand All @@ -64,7 +64,7 @@
}

.slick-prev {
left: -15px;
left: $slick-arrows-offset;

@include breakpoint("large") {
left: -(spacing("double") + spacing("quarter"));
Expand Down Expand Up @@ -180,3 +180,67 @@ div.slick-slider {
*width: 100%;
}


//
// Carousel tooltips for buttons and bullets
// -----------------------------------------------------------------------------

.carousel-tooltip {
height: 1px;
display: block;
position: relative;
margin-top: 10px;
@include addFocusTooltip($attr: aria-label);

&:after {
padding: 15px 10px;
top: 10px;
}

.slick-prev:focus &,
.slick-next:focus &,
.slick-dots button:focus & {
&:before,
&:after {
display: block;
}
}

.slick-prev &,
.slick-next & {
&:before {
top: -7px;
}
}

.slick-prev & {
&:before {
right: -2px;
}

&:after {
right: auto;
left: -5px;
}
}

.slick-next & {
&:after {
right: -5px;
}
}

.slick-dots button & {
margin-top: 25px;

&:before,
&:after {
right: 50%;
transform: translateX(50%);
}

&:before {
top: -7px;
}
}
}
1 change: 1 addition & 0 deletions assets/scss/settings/vendor/slick/_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ $slick-dot-size: 60px;
$slick-opacity-default: 1;
$slick-opacity-on-hover: 0.8;
$slick-opacity-not-active: 0.6;
$slick-arrows-offset: -5px;


// Stencil Additional Settings
Expand Down
11 changes: 6 additions & 5 deletions assets/scss/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
//
// 1. Stencil global settings get imported first.
// 2. Import all Citadel and Foundation settings.
// 3. Import Citadel's version of foundation.
// - This enables the ability to "null" variables in the Stencil settings.
// 3. Common aria helpers.
// 4. Import Stencil's component settings overrides.
// 5. Import tools which set/reset Citadel's global settings, to be consumed by
// the rest of Stencil.
// 6. Import Citadel's version of foundation.
// - This enables the ability to "null" variables in the Stencil settings.
//
// -----------------------------------------------------------------------------

Expand All @@ -36,7 +37,7 @@
@import "../../node_modules/@bigcommerce/citadel/dist/settings/foundation/foundation"; // 2
@import "../../node_modules/@bigcommerce/citadel/dist/settings/bigcommerce/bigcommerce"; // 2

@import "../../node_modules/@bigcommerce/citadel/dist/vendor/foundation/foundation"; // 3
@import "../../node_modules/@bigcommerce/citadel/dist/vendor/foundation/foundation"; // 6

@import "settings/normalize/normalize"; // 4
@import "settings/vendor/vendor"; // 4
Expand Down Expand Up @@ -70,8 +71,8 @@

@import "../../node_modules/@bigcommerce/citadel/dist/vendor/normalize/normalize"; // 1
@import "../../node_modules/@bigcommerce/citadel/dist/components/components"; // 2
@import "components/components"; // 3
@import "common/index";
@import "common/index"; // 3
@import "components/components"; // 6


// Layouts
Expand Down

0 comments on commit 50741d9

Please sign in to comment.