@salesforcedevs/mrkt-components 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2020, Salesforce.com, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,7 @@
1
+ {
2
+ "modules": [
3
+ { "dir": "src/modules" },
4
+ { "npm": "@salesforcedevs/dx-components" }
5
+ ],
6
+ "expose": ["mrkt/subNavBar"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@salesforcedevs/mrkt-components",
3
+ "version": "0.30.0",
4
+ "description": "Marketing Lightning web components for DSC",
5
+ "license": "MIT",
6
+ "engines": {
7
+ "node": ">= 14.x"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "dependencies": {
13
+ "classnames": "^2.2.6"
14
+ },
15
+ "devDependencies": {
16
+ "@types/classnames": "^2.2.10"
17
+ },
18
+ "gitHead": "2892ffcc573566253f854054c4186226dd182ef0"
19
+ }
@@ -0,0 +1,120 @@
1
+ @import "helpers/reset";
2
+ @import "helpers/text";
3
+
4
+ :host {
5
+ --subnav-height: 60px;
6
+ --subnav-height-neg: calc(-1 * var(--subnav-height));
7
+ }
8
+
9
+ @keyframes slide {
10
+ 0% {
11
+ top: var(--subnav-height-neg);
12
+ }
13
+
14
+ 100% {
15
+ top: 0;
16
+ }
17
+ }
18
+
19
+ .subnav {
20
+ position: fixed;
21
+ top: 0;
22
+ left: 0;
23
+ width: 100%;
24
+ height: var(--subnav-height);
25
+ background: white;
26
+ padding: 0 var(--dx-g-page-padding-horizontal);
27
+ display: flex;
28
+ flex-direction: row;
29
+ align-items: center;
30
+ justify-content: space-between;
31
+ animation: slide 0.3s cubic-bezier(0.3, 0.73, 0.3, 0.74) forwards;
32
+ }
33
+
34
+ .subnav.hide {
35
+ display: none;
36
+ }
37
+
38
+ nav {
39
+ height: 100%;
40
+ overflow-y: auto;
41
+ margin: 0 var(--dx-g-spacing-smd);
42
+ }
43
+
44
+ ul {
45
+ height: 100%;
46
+ display: flex;
47
+ flex-direction: row;
48
+ align-items: center;
49
+ }
50
+
51
+ li {
52
+ height: 100%;
53
+ text-decoration: none;
54
+ }
55
+
56
+ ul > li:not(:last-of-type) {
57
+ margin-right: var(--dx-g-text-3xl);
58
+ }
59
+
60
+ a {
61
+ position: relative;
62
+ height: 100%;
63
+ display: flex;
64
+ align-items: center;
65
+ justify-content: center;
66
+ }
67
+
68
+ a::after {
69
+ content: "";
70
+ position: absolute;
71
+ bottom: 0;
72
+ left: 0;
73
+ width: 100%;
74
+ height: 0;
75
+ background: var(--dx-g-blue-vibrant-50);
76
+ transition: height 0.15s ease-in, var(--dx-g-transition-hue-1x);
77
+ }
78
+
79
+ a.active::after {
80
+ height: 7px;
81
+ }
82
+
83
+ a > dx-icon-badge {
84
+ --dx-c-icon-badge-size: 40px;
85
+ --dx-c-icon-badge-background-color: var(--dx-g-blue-vibrant-20);
86
+ --dx-c-icon-badge-transition: var(--dx-g-transition-hue-1x);
87
+
88
+ margin-right: var(--dx-g-spacing-sm);
89
+ }
90
+
91
+ a.active > dx-icon-badge {
92
+ --dx-c-icon-badge-background-color: var(--dx-g-blue-vibrant-50);
93
+ }
94
+
95
+ a:not(.active):hover > dx-icon-badge {
96
+ --dx-c-icon-badge-background-color: var(--dx-g-blue-vibrant-40);
97
+ }
98
+
99
+ /* accounts for font gap */
100
+ a > span {
101
+ transform: translateY(2px);
102
+ }
103
+
104
+ dx-button {
105
+ flex-shrink: 0;
106
+ }
107
+
108
+ @media (max-width: 1024px) {
109
+ ul > li:not(:last-of-type) {
110
+ margin-right: var(--dx-g-spacing-md);
111
+ }
112
+
113
+ a.active {
114
+ color: var(--dx-g-blue-vibrant-50) !important;
115
+ }
116
+
117
+ a:not(.active):hover {
118
+ color: var(--dx-g-blue-vibrant-40);
119
+ }
120
+ }
@@ -0,0 +1,36 @@
1
+ <template>
2
+ <div class={className}>
3
+ <template if:false={isMobile}>
4
+ <dx-button
5
+ variant="tertiary"
6
+ icon-symbol="arrowup"
7
+ onclick={scrollToTop}
8
+ >
9
+ Back to Top
10
+ </dx-button>
11
+ </template>
12
+ <template if:true={isMobile}>
13
+ <dx-button
14
+ variant="tertiary"
15
+ icon-symbol="arrowup"
16
+ onclick={scrollToTop}
17
+ ></dx-button>
18
+ </template>
19
+ <nav role="navigation" aria-label="Secondary Navigation">
20
+ <ul>
21
+ <template for:each={navItems} for:item="navItem">
22
+ <li key={navItem.id}>
23
+ <a class={navItem.className} href={navItem.link.href}>
24
+ <dx-icon-badge
25
+ symbol={navItem.iconSymbol}
26
+ if:true={isDesktop}
27
+ ></dx-icon-badge>
28
+ <span>{navItem.label}</span>
29
+ </a>
30
+ </li>
31
+ </template>
32
+ </ul>
33
+ </nav>
34
+ <dx-button href={subscribeHref}>Subscribe</dx-button>
35
+ </div>
36
+ </template>
@@ -0,0 +1,115 @@
1
+ import { api } from "lwc";
2
+ import cx from "classnames";
3
+ import { MatchMediaElement } from "base-elements/matchMediaElement";
4
+ import type { OptionWithLink } from "typings/custom";
5
+ import { toJson } from "utils/normalizers";
6
+
7
+ export default class SubNavBar extends MatchMediaElement {
8
+ @api subscribeHref!: string;
9
+
10
+ @api
11
+ get navItems() {
12
+ return this._navItems.map((item) => ({
13
+ ...item,
14
+ className: cx(
15
+ "nav-item",
16
+ "dx-text-heading-6",
17
+ this.activeHash === item?.link?.href && "active"
18
+ )
19
+ }));
20
+ }
21
+ set navItems(value) {
22
+ this._navItems = toJson(value);
23
+ }
24
+
25
+ private _navItems!: OptionWithLink[];
26
+ private isVisible?: boolean = true;
27
+ private sectionIntersectionEntryMap:
28
+ | {
29
+ [id: string]: IntersectionObserverEntry;
30
+ }
31
+ | {} = {};
32
+ private sectionsObserver!: IntersectionObserver;
33
+
34
+ private get className(): string {
35
+ return cx("subnav", !this.isVisible && "hide");
36
+ }
37
+
38
+ private get hashIds(): string[] {
39
+ return this.navItems.map((item: OptionWithLink) =>
40
+ item.link.href.replace("#", "")
41
+ );
42
+ }
43
+
44
+ private get activeHash(): string | null {
45
+ const activeEntry = Object.values(
46
+ this.sectionIntersectionEntryMap
47
+ ).reduce(
48
+ (
49
+ acc: IntersectionObserverEntry | null,
50
+ val: IntersectionObserverEntry
51
+ ) => {
52
+ if (
53
+ val.intersectionRatio > 0 &&
54
+ (!acc || val.intersectionRatio > acc.intersectionRatio)
55
+ ) {
56
+ return val;
57
+ }
58
+ return acc;
59
+ },
60
+ null
61
+ );
62
+ return activeEntry ? `#${activeEntry?.target?.id}` : null;
63
+ }
64
+
65
+ connectedCallback(): void {
66
+ super.connectedCallback();
67
+ this.observeSectionIntersections();
68
+ this.onPageScroll();
69
+ window.addEventListener("scroll", this.onPageScroll);
70
+ }
71
+
72
+ disconnectedCallback(): void {
73
+ super.disconnectedCallback();
74
+ this.sectionsObserver.disconnect();
75
+ window.removeEventListener("scroll", this.onPageScroll);
76
+ }
77
+
78
+ private onPageScroll = () => {
79
+ const firstSection = document.getElementById(this.hashIds[0]);
80
+ if (firstSection) {
81
+ this.isVisible = firstSection.getBoundingClientRect().y <= 1;
82
+ }
83
+ };
84
+
85
+ private observeSectionIntersections() {
86
+ const observerOptions = {
87
+ root: document,
88
+ threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
89
+ };
90
+ this.sectionsObserver = new IntersectionObserver(
91
+ (entries) =>
92
+ entries.forEach((entry) => {
93
+ this.sectionIntersectionEntryMap = {
94
+ ...this.sectionIntersectionEntryMap,
95
+ [entry.target.id]: entry
96
+ };
97
+ }),
98
+ observerOptions
99
+ );
100
+ this.hashIds.forEach((id) => {
101
+ const el = document.getElementById(id);
102
+ if (el) {
103
+ this.sectionsObserver.observe(el);
104
+ }
105
+ });
106
+ }
107
+
108
+ private scrollToTop() {
109
+ window.scroll({
110
+ top: 0,
111
+ left: 0,
112
+ behavior: "smooth"
113
+ });
114
+ }
115
+ }