Skip to content

Commit

Permalink
feat(grid): add ability to hide ctas on indiv. cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheridan Sunier authored and Sheridan Sunier committed Mar 1, 2023
1 parent 1d6c0ad commit 1df96e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions react/src/js/components/Consonant/Grid/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import parseHTML from 'html-react-parser';

import FullCard from '../Cards/Full';
import { cardType } from '../types/card';
import { getByPath } from '../Helpers/general';
import { getByPath, getHideCta } from '../Helpers/general';
import { useConfig } from '../Helpers/hooks';
import ThreeFourthCard from '../Cards/ThreeFourth';
import OneHalfCard from '../Cards/OneHalf';
Expand Down Expand Up @@ -203,6 +203,7 @@ const Grid = (props) => {
const cardStyle = collectionStyleOverride || cardStyleOverride;
const { contentArea: { title = '' } = {}, id } = card;
const cardNumber = index + 1;
const hideCTA = getHideCta(card, collectionButtonStyle);

switch (cardStyle) {
case CARD_STYLES.FULL:
Expand Down Expand Up @@ -257,7 +258,7 @@ const Grid = (props) => {
renderBorder={renderCardsBorders}
{...card}
renderOverlay={renderCardsOverlay}
hideCTA={collectionButtonStyle === 'hidden'}
hideCTA={hideCTA}
onFocus={() => scrollCardIntoView(card.id)} />
);
case CARD_STYLES.TEXT:
Expand All @@ -272,7 +273,7 @@ const Grid = (props) => {
locale={locale}
renderBorder={renderCardsBorders}
renderOverlay={renderCardsOverlay}
hideCTA={collectionButtonStyle === 'hidden'}
hideCTA={hideCTA}
onFocus={() => scrollCardIntoView(card.id)} />
);
case CARD_STYLES.CUSTOM:
Expand All @@ -289,7 +290,7 @@ const Grid = (props) => {
locale={locale}
renderBorder={renderCardsBorders}
renderOverlay={renderCardsOverlay}
hideCTA={collectionButtonStyle === 'hidden'}
hideCTA={hideCTA}
onFocus={() => scrollCardIntoView(card.id)} />
);
}
Expand Down
11 changes: 11 additions & 0 deletions react/src/js/components/Consonant/Helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ export const getByPath = (object, path, defaultValue) => {
return result;
};

/**
* Determines whether ctas should be hidden on a given card
* @param {Object} object - object to get value
* @param {String} style - the collection button style
* @returns {bool} - whether a cta should be hidden
*/
export const getHideCta = (object, style) => {
if (object.hideCtaId || style === 'hidden') return true;
return false;
};

/**
* Return sum of the selected filters
* @param {items} array - filter items
Expand Down

0 comments on commit 1df96e6

Please sign in to comment.