From 60d005a78ef9088df28b4e8fbc0b83387c5ad1c0 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Mon, 7 Aug 2023 10:39:09 +0300 Subject: [PATCH] TAL-37 - limit shown skill pills to 3 rows --- .../talent-card/TalentCard.module.scss | 6 +++ .../src/components/talent-card/TalentCard.tsx | 47 ++++++++++++++----- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/apps/talent-search/src/components/talent-card/TalentCard.module.scss b/src/apps/talent-search/src/components/talent-card/TalentCard.module.scss index f3ae7e033..285f0afa2 100644 --- a/src/apps/talent-search/src/components/talent-card/TalentCard.module.scss +++ b/src/apps/talent-search/src/components/talent-card/TalentCard.module.scss @@ -98,4 +98,10 @@ align-items: center; gap: $sp-1; flex-wrap: wrap; + position: relative; + + &:global(.init) { + max-height: 116px; + overflow: hidden; + } } diff --git a/src/apps/talent-search/src/components/talent-card/TalentCard.tsx b/src/apps/talent-search/src/components/talent-card/TalentCard.tsx index 5c335022f..52c2a927a 100644 --- a/src/apps/talent-search/src/components/talent-card/TalentCard.tsx +++ b/src/apps/talent-search/src/components/talent-card/TalentCard.tsx @@ -1,4 +1,4 @@ -import { FC, useMemo } from 'react' +import { FC, useEffect, useMemo, useRef } from 'react' import { Link } from 'react-router-dom' import { orderBy } from 'lodash' import classNames from 'classnames' @@ -23,6 +23,12 @@ const getAddrString = (city: string, country: string): string => ( .join(', ') ) +function isOverflow(el: HTMLElement): boolean { + const parentHeight = el.parentElement?.offsetHeight ?? 0 + const bottom = el.offsetTop + el.offsetHeight + return bottom > parentHeight +} + interface TalentCardProps { queriedSkills: Skill[] member: Member @@ -30,6 +36,7 @@ interface TalentCardProps { } const TalentCard: FC = props => { + const skillsWrapRef = useRef(null) const talentRoute = `${TALENT_SEARCH_PATHS.talent}/${props.member.handle}` const isMatchingSkill = useIsMatchingSkill(props.queriedSkills) @@ -40,23 +47,38 @@ const TalentCard: FC = props => { ) .filter(isMatchingSkill) - const limitMatchedSkills = matchedSkills.slice(0, 7) + const limitMatchedSkills = matchedSkills - const provenSkills = limitMatchedSkills.filter(isSkillVerified) - const selfSkills = limitMatchedSkills.filter(s => !isSkillVerified(s)) - const restSkills = matchedSkills.length - limitMatchedSkills.length - - const restLabel = restSkills > 0 && ( -
- {`+${restSkills} more matched skill${restSkills > 1 ? 's' : ''}`} -
- ) + const provenSkills = matchedSkills.filter(isSkillVerified) + const selfSkills = matchedSkills.filter(s => !isSkillVerified(s)) const matchState = useMemo(() => ({ matchValue: props.match, queriedSkills: props.queriedSkills, }), [props.match, props.queriedSkills]) + // after initial render, check and limit to 3 rows of skills + useEffect(() => { + if (!skillsWrapRef.current) { + return + } + + // check if there are more than 3 rows of skills displayed initially, and hide them + const isHidden: HTMLElement[] = [].filter.call(skillsWrapRef.current.childNodes, isOverflow) + isHidden.forEach(c => { c.style.display = 'none' }) + + // remove css height limit from the skillsWrap el + skillsWrapRef.current.classList.toggle('init', false) + + // if there are hidden skill pills, show the "+N more matched skills" pill + if (isHidden.length) { + const restLabel = document.createElement('div') + restLabel.classList.add(styles.unmatchedSkills) + restLabel.innerText = `+${isHidden.length} more matched skill${isHidden.length > 1 ? 's' : ''}` + skillsWrapRef.current.appendChild(restLabel) + } + }, [limitMatchedSkills]) + return (
@@ -94,7 +116,7 @@ const TalentCard: FC = props => {
{`${matchedSkills.length} Matched skills`}
-
+
{provenSkills.length > 0 && provenSkills.map(skill => ( = props => { skill={skill} /> ))} - {restLabel}