diff --git a/components/jambonz-ui.js b/components/jambonz-ui.js index cc63726..aa3a62e 100644 --- a/components/jambonz-ui.js +++ b/components/jambonz-ui.js @@ -14,6 +14,11 @@ export function normalizeSubtext(subtext) { return subtext; } +// Simple method to normalize string as slug +export function normalizeSlug(key) { + return String(key.toLowerCase()).split(' ').join('-'); +} + // Normalize how we listen for mobile media queries export function useMobileMedia() { const [mobile, setMobile] = useState(false); @@ -87,8 +92,6 @@ export function Hero({ data, subStyle }) { classes[`hero--${subStyle}`] = true; } - data.subtext = normalizeSubtext(data.subtext); - return (
@@ -96,7 +99,7 @@ export function Hero({ data, subStyle }) {

{data.headline}

- {data.subtext.map((subtext) => { + {normalizeSubtext(data.subtext).map((subtext) => { return
{subtext}
; })}
diff --git a/data/home.yml b/data/home.yml index af4aaf3..d5c4b6a 100644 --- a/data/home.yml +++ b/data/home.yml @@ -63,6 +63,7 @@ dilemma: icon: XCircle text: costly to manage over time - + title: jambonz logo: /svg/jambonz.svg points: - diff --git a/pages/index.js b/pages/index.js index 50c0ed7..b1e7bc8 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,8 +1,9 @@ import { nanoid } from 'nanoid'; import classNames from 'classnames'; import Layout from '../components/layout'; -import { Hero, Icon, Button, H6, H5, H2, P, MS, normalizeSubtext } from '../components/jambonz-ui'; +import { Hero, Icon, Button, H6, H5, H2, P, MS, normalizeSubtext, normalizeSlug, useMobileMedia } from '../components/jambonz-ui'; import { getData } from '../lib/data'; +import { useState, useEffect, useRef } from 'react'; function Tech({data}) { return ( @@ -27,7 +28,28 @@ function Tech({data}) { } function Dilemma({data}) { - data.subtext = normalizeSubtext(data.subtext); + const mobile = useMobileMedia(); + const initialRef = useRef(); + const [active, setActive] = useState(null); + + const handleToggle = (e) => { + const toggleData = e.target.dataset; + + if (toggleData.key === active) { + setActive(null); + + } else { + setActive(toggleData.key); + } + }; + + // Make sure jambonz is the default open toggle on mobile... + useEffect(() => { + if (mobile && !active && !initialRef.current) { + initialRef.current = true; + setActive('jambonz'); + } + }, [mobile, active, setActive, initialRef]); return (
@@ -37,7 +59,7 @@ function Dilemma({data}) {
- {data.subtext.map((subtext) => { + {normalizeSubtext(data.subtext).map((subtext) => { {/* Use dangerouslySetInnerHTML to render inline spans from YAML data */} return
; })} @@ -49,26 +71,33 @@ function Dilemma({data}) { 'dilemma__table': true, 'dilemma__table--jambonz': table.logo ? true : false, }; + const slug = normalizeSlug(table.title); + const isActiveToggle = (active === slug); + const pointsClasses = { + 'dilemma__table__points': true, + 'active': isActiveToggle, + }; return ( -
+
{table.logo ? :

{table.title}

} + + {isActiveToggle ? : } +
-
+
{table.points.map((point) => { const classes = { 'dilemma__table__point': true, [point.icon.toLowerCase()]: true, }; - point.text = normalizeSubtext(point.text); - return (
- {point.text.map((text) => { + {normalizeSubtext(point.text).map((text) => { return
{text}
; })}
diff --git a/styles/_homepage.scss b/styles/_homepage.scss index 78f500e..c27145f 100644 --- a/styles/_homepage.scss +++ b/styles/_homepage.scss @@ -111,6 +111,10 @@ } &__title { + display: flex; + justify-content: center; + align-items: center; + img { width: 50%; @@ -120,12 +124,36 @@ } } - &__title, - &__point { - margin-bottom: 16px; + &__toggle { + margin-left: auto; + display: none; + cursor: pointer; + + svg { + pointer-events: none; + } + + @media (max-width: $width-tablet-2) { + display: block; + } + } + + &__points { + margin-top: 16px; + + @media (max-width: $width-tablet-2) { + display: none; + } + + &.active { + @media (max-width: $width-tablet-2) { + display: block; + } + } } &__point { + margin-bottom: 16px; display: flex; align-items: flex-start; text-align: left;