From bc3db0c93c5b9414e3fffd99b6e7bb73b8eaa939 Mon Sep 17 00:00:00 2001 From: trovster Date: Wed, 4 Oct 2023 13:25:57 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20trovster?= =?UTF-8?q?/fitness.trovster.com@72450f933bd47621e802a26d1ca2cb0d80c3c435?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/site.css | 2 +- index.html | 288 ++++++++++++++++++++++++++++------------------ js/FitnessCard.js | 69 +++++------ js/FitnessRing.js | 72 ++++++++++-- 4 files changed, 272 insertions(+), 159 deletions(-) diff --git a/css/site.css b/css/site.css index 2d8f69a..dd7822d 100644 --- a/css/site.css +++ b/css/site.css @@ -1 +1 @@ -/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.mx-auto{margin-left:auto;margin-right:auto}.mt-6{margin-top:1.5rem}.flex{display:flex}.min-w-full{min-width:100%}.max-w-3xl{max-width:48rem}.max-w-4xl{max-width:56rem}.flex-col{flex-direction:column}.justify-center{justify-content:center}.gap-4{gap:1rem}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem*var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.5rem*var(--tw-space-y-reverse))}.overflow-hidden{overflow:hidden}.scroll-smooth{scroll-behavior:smooth}.rounded-2xl{border-radius:1rem}.rounded-3xl{border-radius:1.5rem}.bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity))}.bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity))}.p-6{padding:1.5rem}.py-6{padding-bottom:1.5rem}.pt-6,.py-6{padding-top:1.5rem}.text-center{text-align:center}.font-sans{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.text-2xl{font-size:1.5rem;line-height:2rem}.text-4xl{font-size:2.25rem;line-height:2.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.font-black{font-weight:900}.font-bold{font-weight:700}.not-italic{font-style:normal}.leading-none{line-height:1}.tracking-tight{letter-spacing:-.025em}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity))}.text-zinc-800{--tw-text-opacity:1;color:rgb(39 39 42/var(--tw-text-opacity))}.underline{text-decoration-line:underline}.ring{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}fitness-card{--fitness-value:#a1a1aa}fitness-card::part(header){margin-bottom:2rem;border-width:0 0 2px;border-style:solid;--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity));padding-top:1.5rem;padding-bottom:1.5rem}fitness-card::part(summary){margin-top:2rem;border-width:2px 0 0;border-style:solid;--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity));padding-top:1.5rem;padding-bottom:1.5rem}.muted{--fitness-move:#f472b6;--fitness-exercise:#38bdf8;--fitness-stand:#2dd4bf}.bright{--fitness-move:#2563eb;--fitness-exercise:#059669;--fitness-stand:#c026d3}.focus\:no-underline:focus,.hover\:no-underline:hover{text-decoration-line:none}@media (prefers-color-scheme:dark){.dark\:bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity))}.dark\:text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity))}}@media (min-width:640px){.sm\:min-w-\[31\%\]{min-width:31%}.sm\:flex-row{flex-direction:row}.sm\:flex-wrap{flex-wrap:wrap}}@media (min-width:768px){.md\:text-4xl{font-size:2.25rem;line-height:2.5rem}.md\:text-8xl{font-size:6rem;line-height:1}.md\:text-lg{font-size:1.125rem;line-height:1.75rem}.md\:text-xl{font-size:1.25rem;line-height:1.75rem}} \ No newline at end of file +/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.mx-auto{margin-left:auto;margin-right:auto}.\!mt-14{margin-top:3.5rem!important}.mt-2{margin-top:.5rem}.block{display:block}.flex{display:flex}.w-full{width:100%}.min-w-\[50px\]{min-width:50px}.max-w-3xl{max-width:48rem}.max-w-4xl{max-width:56rem}.max-w-\[12\%\]{max-width:12%}.scroll-py-4{scroll-padding-top:1rem;scroll-padding-bottom:1rem}.flex-row{flex-direction:row}.flex-wrap{flex-wrap:wrap}.justify-center{justify-content:center}.gap-2{gap:.5rem}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem*var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1.5rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.5rem*var(--tw-space-y-reverse))}.space-y-8>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(2rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(2rem*var(--tw-space-y-reverse))}.overflow-hidden{overflow:hidden}.scroll-smooth{scroll-behavior:smooth}.rounded-3xl{border-radius:1.5rem}.border-t-2{border-top-width:2px}.border-solid{border-style:solid}.border-slate-300{--tw-border-opacity:1;border-color:rgb(203 213 225/var(--tw-border-opacity))}.bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity))}.bg-zinc-200{--tw-bg-opacity:1;background-color:rgb(228 228 231/var(--tw-bg-opacity))}.p-6{padding:1.5rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pt-12{padding-top:3rem}.text-center{text-align:center}.font-sans{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.text-4xl{font-size:2.25rem;line-height:2.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.font-black{font-weight:900}.font-bold{font-weight:700}.not-italic{font-style:normal}.leading-none{line-height:1}.tracking-tight{letter-spacing:-.025em}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.text-zinc-400{--tw-text-opacity:1;color:rgb(161 161 170/var(--tw-text-opacity))}.text-zinc-800{--tw-text-opacity:1;color:rgb(39 39 42/var(--tw-text-opacity))}.ring{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}a{--tw-text-opacity:1;color:rgb(29 78 216/var(--tw-text-opacity));text-decoration-line:underline;text-decoration-thickness:2px;text-underline-offset:2px}a:focus,a:hover{text-decoration-line:none}fitness-card{--fitness-value:#a1a1aa}fitness-card::part(header){margin-bottom:2rem;border-width:0 0 2px;border-style:solid;--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity));padding-top:1.5rem;padding-bottom:1.5rem}fitness-card::part(footer){margin-top:2rem;border-width:2px 0 0;border-style:solid;--tw-border-opacity:1;border-color:rgb(228 228 231/var(--tw-border-opacity));padding-top:1.5rem;padding-bottom:1.5rem}@media (min-width:640px){fitness-card::part(ring){max-width:250px}}.muted{--fitness-move:#f472b6;--fitness-exercise:#38bdf8;--fitness-stand:#2dd4bf}.bright{--fitness-move:#2563eb;--fitness-exercise:#059669;--fitness-stand:#c026d3}@media (prefers-color-scheme:dark){.dark\:bg-zinc-900{--tw-bg-opacity:1;background-color:rgb(24 24 27/var(--tw-bg-opacity))}.dark\:text-zinc-300{--tw-text-opacity:1;color:rgb(212 212 216/var(--tw-text-opacity))}}@media (min-width:768px){.md\:mt-8{margin-top:2rem}.md\:text-2xl{font-size:1.5rem;line-height:2rem}.md\:text-8xl{font-size:6rem;line-height:1}.md\:text-lg{font-size:1.125rem;line-height:1.75rem}.md\:leading-\[0\.75\]{line-height:.75}} \ No newline at end of file diff --git a/index.html b/index.html index 78c784b..b6a0741 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + @@ -23,75 +23,108 @@ -
-
-
-

+
+
+

Fitness Web Components

-

Simple Web Components for fitness cards and rings.

+

Simple Web Components for fitness cards and rings.

-
-

The Code

- -

- You can download the - repository of this project - and configure your `fitness.json` data to generate cards and rings. The code in the repository has been organised into - different nunjuck components for easiser compartmentalisation. -

- -

There are two main web components; a ring and a fully featured card.

- -
<fitness-ring
-    move-total="item.move.total" move-goal="item.move.goal"
-    exercise-total="item.exercise.total" exercise-goal="item.exercise.goal"
-    stand-total="item.stand.total" move-goal="item.stand.goal"
-></fitness-ring>
-
-<fitness-card
-    steps="item.steps" distance="item.distance" flights="item.flights"
-    move-total="item.move.total" move-goal="item.move.goal"
-    exercise-total="item.exercise.total" exercise-goal="item.exercise.goal"
-    stand-total="item.stand.total" move-goal="item.stand.goal"
-></fitness-card>
- -

On this example, I am looping thought JSON data that looks like the following.

- -
{
-	"date": "2023-09-25T00:00:00+00:00",
-	"steps": 18935,
-	"distance": 16254,
-	"flights": 8,
-	"move": {
-		"total": 500,
-		"goal": 750
-	},
-	"exercise": {
-		"total": 30,
-		"goal": 60
-	},
-	"stand": {
-		"total": 8,
-		"goal": 10
-	}
-}
+
+
-
-

Cards

- +
    -
  • +
  • -

    Rings

    - -
      - -
    • - +
    • +
    • -
    • - + + >
    • -
    • - + -
    • - -
    - -
      - -
    • - -
    • - -
    • - + >
    • -
    • - +
    • +
+ +
+

The Code

+ +

+ You can download the + repository of this project + and configure your `fitness.json` data to generate cards and rings. This uses the + fitness visualisations + Web Components. +

+ +

There are two main web components; a ring and a fully featured card.

+ +
<fitness-ring
+    move-total="item.move.total" move-goal="item.move.goal"
+    exercise-total="item.exercise.total" exercise-goal="item.exercise.goal"
+    stand-total="item.stand.total" move-goal="item.stand.goal"
+></fitness-ring>
+
+<fitness-card
+    date="item.date"
+    steps="item.steps" distance="item.distance" flights="item.flights"
+    move-total="item.move.total" move-goal="item.move.goal"
+    exercise-total="item.exercise.total" exercise-goal="item.exercise.goal"
+    stand-total="item.stand.total" move-goal="item.stand.goal"
+></fitness-card>
+ +

On this example, I am looping thought JSON data that looks like the following.

+ +
{
+	"date": "2023-09-25T00:00:00+00:00",
+	"steps": 18935,
+	"distance": 16254,
+	"flights": 8,
+	"move": {
+		"total": 500,
+		"goal": 750
+	},
+	"exercise": {
+		"total": 30,
+		"goal": 60
+	},
+	"stand": {
+		"total": 8,
+		"goal": 10
+	}
+}
+

diff --git a/js/FitnessCard.js b/js/FitnessCard.js index a53d419..d7d9b0f 100644 --- a/js/FitnessCard.js +++ b/js/FitnessCard.js @@ -29,20 +29,22 @@ export default class FitnessCard extends HTMLElement { wrapper.innerHTML = this.render(); this.shadow.appendChild(wrapper); - this.observer = new IntersectionObserver( - elements => { - elements.forEach(element => { - if (element.isIntersecting) { - element.target.classList.add('visible'); - } else { - element.target.classList.remove('visible'); - } - }); - }, - { threshold: 0.5 } - ); - - this.observer.observe(wrapper); + if ('IntersectionObserver' in window) { + this.observer = new IntersectionObserver( + elements => { + elements.forEach(element => { + if (element.isIntersecting) { + element.target.classList.add('visible'); + } else { + element.target.classList.remove('visible'); + } + }); + }, + { threshold: 0.5 } + ); + + this.observer.observe(wrapper); + } } disconnectedCallback() { @@ -66,7 +68,7 @@ export default class FitnessCard extends HTMLElement { // Check attributes exist. hasHeader = () => this.getAttribute('date'); - hasSummary = () => + hasFooter = () => this.getAttribute('steps') || this.getAttribute('distance') || this.getAttribute('flights'); @@ -189,7 +191,7 @@ export default class FitnessCard extends HTMLElement { font-size: 1.25rem; text-align: center; } - [part="fitness"] { + [part="main"] { display: flex; margin: 1rem 0; padding: 0 1rem; @@ -197,11 +199,11 @@ export default class FitnessCard extends HTMLElement { align-items: center; justify-content: space-evenly; } - [part="summary"] { + [part="footer"] { margin: 1rem 0 0; padding: 0 0.5rem 1rem; } - [part="summary"] dl { + [part="footer"] dl { display: flex; flex-direction: column; items-align: center; @@ -214,7 +216,7 @@ export default class FitnessCard extends HTMLElement { max-width: 360px; } - @media (min-width: 640px) { + @media (min-width: 40rem) { dl { line-height: 1.1; } @@ -227,19 +229,19 @@ export default class FitnessCard extends HTMLElement { [part="header"] { font-size: 1.66rem; } - [part="fitness"] { + [part="main"] { flex-direction: row; } - [part="fitness"] dl { + [part="main"] dl { text-align: left; } - [part="summary"] dl { + [part="footer"] dl { flex-direction: row; } - [part="summary"] dl > div { + [part="footer"] dl > div { margin-bottom: 0; } - [part="summary"] dl dt { + [part="footer"] dl dt { margin-bottom: 0.25rem; } fitness-ring { @@ -248,7 +250,7 @@ export default class FitnessCard extends HTMLElement { } } - @media (min-width: 870px) { + @media (min-width: 54rem) { dt { font-size: 1.5rem; } @@ -269,7 +271,7 @@ export default class FitnessCard extends HTMLElement { ${this.date(this.getAttribute('date'))} ` - : ''; + : ''; stats = () => `
@@ -326,10 +328,10 @@ export default class FitnessCard extends HTMLElement { ` : ''; - summary = () => - this.hasSummary() + footer = () => + this.hasFooter() ? ` -
+
${this.steps()} ${this.distance()} @@ -343,10 +345,11 @@ export default class FitnessCard extends HTMLElement { return ` ${this.header()} -
+
${this.stats()}
- ${this.summary()} + ${this.footer()} `; } } -window.customElements.define('fitness-card', FitnessCard); +if ('customElements' in window) { + window.customElements.define('fitness-card', FitnessCard); +} diff --git a/js/FitnessRing.js b/js/FitnessRing.js index 1b1c8c1..0d7b9d6 100644 --- a/js/FitnessRing.js +++ b/js/FitnessRing.js @@ -22,18 +22,22 @@ export default class FitnessRing extends HTMLElement { wrapper.innerHTML = this.render(); this.shadow.appendChild(wrapper); - this.observer = new IntersectionObserver( - elements => { - elements.forEach(element => { - if (element.isIntersecting) { - element.target.classList.add('viewed'); - } - }); - }, - { threshold: 0.5 } - ); + if ('IntersectionObserver' in window) { + this.observer = new IntersectionObserver( + elements => { + elements.forEach(element => { + if (element.isIntersecting) { + element.target.classList.add('viewed'); + } + }); + }, + { threshold: 0.5 } + ); - this.observer.observe(wrapper); + this.observer.observe(wrapper); + } else { + wrapper.classList.add('viewed'); + } } disconnectedCallback() { @@ -81,6 +85,15 @@ export default class FitnessRing extends HTMLElement { stroke: var(--fitness-stand, var(--fitness-ring-stand)); transform: translate(50%, 50%) scale(0.5); } + .move feDropShadow { + flood-color: var(--fitness-move, var(--fitness-ring-move)); + } + .exercise feDropShadow { + flood-color: var(--fitness-exercise, var(--fitness-ring-exercise)); + } + .stand feDropShadow { + flood-color: var(--fitness-stand, var(--fitness-ring-stand)); + } .viewed .move circle { animation: ring 1450ms ease-in-out 50ms forwards; } @@ -124,6 +137,17 @@ export default class FitnessRing extends HTMLElement { this.getAttribute('move-goal') )}, 100" > + + + + @@ -141,6 +165,17 @@ export default class FitnessRing extends HTMLElement { this.getAttribute('exercise-goal') )}, 100" > + + + + @@ -158,10 +193,23 @@ export default class FitnessRing extends HTMLElement { this.getAttribute('stand-goal') )}, 100" > + + + + `; } } -window.customElements.define('fitness-ring', FitnessRing); +if ('customElements' in window) { + window.customElements.define('fitness-ring', FitnessRing); +}