@salesforcedevs/dx-components 0.58.1-alpha.1 → 0.59.0-avatar-button-2
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/package.json +4 -4
- package/src/assets/svg/login-widget-bg.png +0 -0
- package/src/modules/dx/avatarButton/avatarButton.css +133 -0
- package/src/modules/dx/avatarButton/avatarButton.html +151 -0
- package/src/modules/dx/avatarButton/avatarButton.ts +105 -0
- package/src/modules/dx/header/header.html +1 -0
- package/src/modules/dx/logo/logo.ts +1 -1
- package/LICENSE +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0-avatar-button-2",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"classnames": "^2.2.6",
|
|
18
18
|
"debounce": "^1.2.0",
|
|
19
19
|
"lodash.get": "^4.4.2",
|
|
20
|
-
"microtip": "0.2.2"
|
|
20
|
+
"microtip": "0.2.2",
|
|
21
|
+
"salesforce-oauth2": "^0.2.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/classnames": "^2.2.10",
|
|
24
25
|
"@types/debounce": "^1.2.0",
|
|
25
26
|
"@types/lodash.get": "^4.4.6",
|
|
26
27
|
"@types/vimeo__player": "^2.16.2"
|
|
27
|
-
}
|
|
28
|
-
"gitHead": "cdb39321a024284380127490c9a07f81dbfd0f36"
|
|
28
|
+
}
|
|
29
29
|
}
|
|
Binary file
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
--dx-c-button-custom-color: var(--dx-g-blue-vibrant-50);
|
|
3
|
+
--dx-c-button-custom-background: transparent;
|
|
4
|
+
--dx-c-button-custom-border: 1px solid transparent;
|
|
5
|
+
--dx-c-button-custom-color-hover: var(--dx-g-blue-vibrant-50);
|
|
6
|
+
--dx-c-button-custom-background-hover: var(--dx-g-cloud-blue-vibrant-90);
|
|
7
|
+
--dx-c-button-custom-border-hover: var(--dx-g-cloud-blue-vibrant-90);
|
|
8
|
+
--dx-c-slot-empty-width: max-content;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.avatar-small-container {
|
|
12
|
+
padding: 2px 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.avatar {
|
|
16
|
+
border-radius: 100%;
|
|
17
|
+
border: 2px solid #0d9dda;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.avatar.avatar-small {
|
|
21
|
+
display: block;
|
|
22
|
+
height: var(--dx-g-spacing-lg);
|
|
23
|
+
width: var(--dx-g-spacing-lg);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.avatar.avatar-medium {
|
|
27
|
+
margin-bottom: 14px;
|
|
28
|
+
width: var(--dx-g-spacing-2xl);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.login-control {
|
|
32
|
+
margin-left: var(--dx-g-spacing-smd);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.login-container {
|
|
36
|
+
padding: 16px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.login-container.logged-in {
|
|
40
|
+
padding-top: 68px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.header-img {
|
|
44
|
+
left: 0;
|
|
45
|
+
position: absolute;
|
|
46
|
+
top: 0;
|
|
47
|
+
width: 100%;
|
|
48
|
+
z-index: -1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.heading {
|
|
52
|
+
color: var(--dx-g-blue-vibrant-20);
|
|
53
|
+
display: block;
|
|
54
|
+
font-family: var(--dx-g-font-display);
|
|
55
|
+
font-size: var(--dx-g-text-lg);
|
|
56
|
+
line-height: 28px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.sub-heading {
|
|
60
|
+
color: var(--dx-g-blue-vibrant-20);
|
|
61
|
+
display: block;
|
|
62
|
+
font-family: var(--dx-g-font-sans);
|
|
63
|
+
font-size: 12px;
|
|
64
|
+
line-height: 18px;
|
|
65
|
+
padding: 8px 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ul {
|
|
69
|
+
list-style: none;
|
|
70
|
+
margin: 0;
|
|
71
|
+
padding: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.login-list-item {
|
|
75
|
+
padding-bottom: 10px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.login-section ~ .login-section {
|
|
79
|
+
border-top: 1px solid var(--dx-g-gray-90);
|
|
80
|
+
margin-top: 12px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.login-section-title {
|
|
84
|
+
color: var(--dx-g-gray-30);
|
|
85
|
+
display: inline-block;
|
|
86
|
+
font-family: var(--dx-g-font-sans);
|
|
87
|
+
font-size: 14px;
|
|
88
|
+
line-height: 20px;
|
|
89
|
+
padding: 20px 0 12px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.login-link {
|
|
93
|
+
color: var(--dx-g-blue-vibrant-20);
|
|
94
|
+
display: block;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.login-link-label {
|
|
98
|
+
display: inline-block;
|
|
99
|
+
font-family: var(--dx-g-font-display);
|
|
100
|
+
font-size: 16px;
|
|
101
|
+
line-height: 24px;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.login-link-img {
|
|
105
|
+
display: inline-block;
|
|
106
|
+
height: 16px;
|
|
107
|
+
margin-left: 6px;
|
|
108
|
+
vertical-align: middle;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.login-link-icon {
|
|
112
|
+
display: inline-block;
|
|
113
|
+
margin-left: 6px;
|
|
114
|
+
vertical-align: baseline;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.login-link-blurb {
|
|
118
|
+
font-family: var(--dx-g-font-sans);
|
|
119
|
+
font-size: 14px;
|
|
120
|
+
line-height: 20px;
|
|
121
|
+
padding-top: 4px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.heading-links {
|
|
125
|
+
color: var(--dx-g-gray-90);
|
|
126
|
+
font-family: var(--dx-g-font-sans);
|
|
127
|
+
font-size: 14px;
|
|
128
|
+
line-height: 20px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
a.inline-link {
|
|
132
|
+
color: var(--dx-g-blue-vibrant-50);
|
|
133
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div if:true={isLoggedIn}>
|
|
3
|
+
<dx-popover offset="small" width="320px" open-on-hover>
|
|
4
|
+
<div slot="control" class="avatar-small-container login-control">
|
|
5
|
+
<img src={userInfo.avatarImgSrc} class="avatar avatar-small" />
|
|
6
|
+
</div>
|
|
7
|
+
<div slot="content">
|
|
8
|
+
<div class="login-container logged-in">
|
|
9
|
+
<img
|
|
10
|
+
src="/assets/svg/login-widget-bg.png"
|
|
11
|
+
class="header-img"
|
|
12
|
+
/>
|
|
13
|
+
<img
|
|
14
|
+
src={userInfo.avatarImgSrc}
|
|
15
|
+
class="avatar avatar-medium"
|
|
16
|
+
/>
|
|
17
|
+
<span class="heading">{userInfo.fullName}</span>
|
|
18
|
+
<span class="sub-heading">{userInfo.username}</span>
|
|
19
|
+
<div class="heading-links">
|
|
20
|
+
<!--
|
|
21
|
+
<a href="#" class="inline-link">Switch account</a>
|
|
22
|
+
|
|
|
23
|
+
-->
|
|
24
|
+
<a href="#" onclick={handleLogout} class="inline-link">
|
|
25
|
+
Logout
|
|
26
|
+
</a>
|
|
27
|
+
</div>
|
|
28
|
+
<div class="login-section">
|
|
29
|
+
<span class="login-section-title">Trailblazer.me</span>
|
|
30
|
+
<ul>
|
|
31
|
+
<li class="login-list-item">
|
|
32
|
+
<a href={settingsUrl} class="login-link">
|
|
33
|
+
<span class="login-link-label">
|
|
34
|
+
Settings
|
|
35
|
+
</span>
|
|
36
|
+
<dx-icon
|
|
37
|
+
class="login-link-icon"
|
|
38
|
+
symbol="new_window"
|
|
39
|
+
size="xsmall"
|
|
40
|
+
></dx-icon>
|
|
41
|
+
</a>
|
|
42
|
+
</li>
|
|
43
|
+
<li class="login-list-item">
|
|
44
|
+
<a href={profileUrl} class="login-link">
|
|
45
|
+
<span class="login-link-label">
|
|
46
|
+
Profile
|
|
47
|
+
</span>
|
|
48
|
+
<dx-icon
|
|
49
|
+
class="login-link-icon"
|
|
50
|
+
symbol="new_window"
|
|
51
|
+
size="xsmall"
|
|
52
|
+
></dx-icon>
|
|
53
|
+
</a>
|
|
54
|
+
</li>
|
|
55
|
+
<li class="login-list-item">
|
|
56
|
+
<a href="#" class="login-link">
|
|
57
|
+
<span class="login-link-label">
|
|
58
|
+
Developer Forums
|
|
59
|
+
</span>
|
|
60
|
+
<dx-icon
|
|
61
|
+
class="login-link-icon"
|
|
62
|
+
symbol="new_window"
|
|
63
|
+
size="xsmall"
|
|
64
|
+
></dx-icon>
|
|
65
|
+
</a>
|
|
66
|
+
<div class="login-link-blurb">
|
|
67
|
+
Our Developer Forums have a new home!
|
|
68
|
+
<a href="#" class="inline-link">
|
|
69
|
+
Learn more
|
|
70
|
+
</a>
|
|
71
|
+
</div>
|
|
72
|
+
</li>
|
|
73
|
+
</ul>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</dx-popover>
|
|
78
|
+
</div>
|
|
79
|
+
<div if:false={isLoggedIn}>
|
|
80
|
+
<dx-popover offset="small" width="320px" open-on-hover>
|
|
81
|
+
<dx-button
|
|
82
|
+
slot="control"
|
|
83
|
+
class="login-control"
|
|
84
|
+
icon-symbol="user"
|
|
85
|
+
icon-position="left"
|
|
86
|
+
loading={isLoading}
|
|
87
|
+
variant="custom"
|
|
88
|
+
>
|
|
89
|
+
Login
|
|
90
|
+
</dx-button>
|
|
91
|
+
<div slot="content">
|
|
92
|
+
<div class="login-container">
|
|
93
|
+
<span class="heading">Login</span>
|
|
94
|
+
<div class="login-section">
|
|
95
|
+
<span class="login-section-title">Products</span>
|
|
96
|
+
<ul>
|
|
97
|
+
<li class="login-list-item">
|
|
98
|
+
<a href="#" class="login-link">
|
|
99
|
+
<span class="login-link-label">
|
|
100
|
+
Salesforce
|
|
101
|
+
</span>
|
|
102
|
+
<img
|
|
103
|
+
class="login-link-img"
|
|
104
|
+
src="/assets/svg/salesforce-cloud.svg"
|
|
105
|
+
alt="Salesforce logo"
|
|
106
|
+
/>
|
|
107
|
+
<dx-icon
|
|
108
|
+
class="login-link-icon"
|
|
109
|
+
symbol="new_window"
|
|
110
|
+
size="xsmall"
|
|
111
|
+
></dx-icon>
|
|
112
|
+
</a>
|
|
113
|
+
</li>
|
|
114
|
+
<li class="login-list-item">
|
|
115
|
+
<a href="#" class="login-link">
|
|
116
|
+
<span class="login-link-label">
|
|
117
|
+
Marketing Cloud
|
|
118
|
+
</span>
|
|
119
|
+
<dx-icon
|
|
120
|
+
class="login-link-icon"
|
|
121
|
+
symbol="new_window"
|
|
122
|
+
size="xsmall"
|
|
123
|
+
></dx-icon>
|
|
124
|
+
</a>
|
|
125
|
+
</li>
|
|
126
|
+
</ul>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="login-section">
|
|
129
|
+
<span class="login-section-title">
|
|
130
|
+
Community & Resources
|
|
131
|
+
</span>
|
|
132
|
+
<ul>
|
|
133
|
+
<li class="login-list-item">
|
|
134
|
+
<a href={loginUrl} class="login-link">
|
|
135
|
+
<span class="login-link-label">
|
|
136
|
+
Trailblazer.me
|
|
137
|
+
</span>
|
|
138
|
+
</a>
|
|
139
|
+
<div class="login-link-blurb">
|
|
140
|
+
Login into access a rich community of
|
|
141
|
+
Salesforce Developers, get ideas, and find
|
|
142
|
+
solutions.
|
|
143
|
+
</div>
|
|
144
|
+
</li>
|
|
145
|
+
</ul>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</dx-popover>
|
|
150
|
+
</div>
|
|
151
|
+
</template>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { api, LightningElement } from "lwc";
|
|
2
|
+
|
|
3
|
+
const TBID_BASE_URL = "https://dev1-trailblazer-identity.cs192.force.com";
|
|
4
|
+
const TBID_SETTINGS_URL = `${TBID_BASE_URL}/settings`;
|
|
5
|
+
const TBID_PROFILE_URL = `${TBID_BASE_URL}/id`;
|
|
6
|
+
const TBID_API_BASE_URL = "https://development.developer.salesforce.com/tbid";
|
|
7
|
+
const TBID_API_LOGOUT_URL = `${TBID_API_BASE_URL}/logout`;
|
|
8
|
+
const TBID_API_USERINFO_URL = `https://development.developer.salesforce.com/tbid/userinfo`;
|
|
9
|
+
const TBID_API_LOGIN_URL = `${TBID_API_BASE_URL}/dologin`;
|
|
10
|
+
// const TBID_LOGOUT_URL = `${TBID_BASE_URL}/services/auth/idp/oidc/logout`;
|
|
11
|
+
|
|
12
|
+
export interface UserInfo {
|
|
13
|
+
avatarImgSrc?: string;
|
|
14
|
+
firstName?: string;
|
|
15
|
+
lastName?: string;
|
|
16
|
+
username?: string;
|
|
17
|
+
readonly fullName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default class AvatarButton extends LightningElement {
|
|
21
|
+
@api size: "small" | "medium" | "large" = "medium";
|
|
22
|
+
|
|
23
|
+
private userInfo: UserInfo = {
|
|
24
|
+
get fullName() {
|
|
25
|
+
if (this.firstName && this.lastName) {
|
|
26
|
+
return `${this.firstName} ${this.lastName}`;
|
|
27
|
+
}
|
|
28
|
+
return this.firstName || this.lastName || "";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
private isLoading = false;
|
|
32
|
+
private settingsUrl = TBID_SETTINGS_URL;
|
|
33
|
+
private profileUrl = TBID_PROFILE_URL;
|
|
34
|
+
private loginUrl = TBID_API_LOGIN_URL;
|
|
35
|
+
private _didReceiveUserInfo = false;
|
|
36
|
+
|
|
37
|
+
private get isLoggedIn() {
|
|
38
|
+
return this._didReceiveUserInfo;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
connectedCallback() {
|
|
42
|
+
window.addEventListener("tbid-login", this.handleSsoLogin);
|
|
43
|
+
window.addEventListener("tbid-logout", this.handleLogout);
|
|
44
|
+
|
|
45
|
+
// Whenever this component is added to the DOM, immediately request user info; if the user is logged in
|
|
46
|
+
// and we receive the info, this component will display the avatar UI; otherwise, it will display the login
|
|
47
|
+
// button.
|
|
48
|
+
this.requestUserInfo();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
window.removeEventListener("tbid-login", this.handleSsoLogin);
|
|
53
|
+
window.removeEventListener("tbid-logout", this.handleLogout);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// This will only be called for "seamless SSO" login by the embedded login widget (SFWidget) on the website, if it exists.
|
|
57
|
+
private handleSsoLogin(event: Event) {
|
|
58
|
+
const userInfo = (event as CustomEvent).detail;
|
|
59
|
+
if (userInfo) {
|
|
60
|
+
this.updateAvatarWithUserInfo(userInfo);
|
|
61
|
+
this._didReceiveUserInfo = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// This can be called *either* by the embedded login widget (SFWidget) on the website, if it exists,
|
|
66
|
+
// in the event of "seamless SSO" logout, *or* by a user clicking logout on this component.
|
|
67
|
+
private async handleLogout() {
|
|
68
|
+
this._didReceiveUserInfo = false;
|
|
69
|
+
this.isLoading = false;
|
|
70
|
+
this.updateAvatarWithUserInfo({}); // clear old info
|
|
71
|
+
|
|
72
|
+
fetch(TBID_API_LOGOUT_URL); // no need to await this
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private updateAvatarWithUserInfo(userInfo: any) {
|
|
76
|
+
if (!userInfo) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.userInfo.avatarImgSrc = userInfo.photos?.thumbnail;
|
|
81
|
+
this.userInfo.firstName = userInfo.given_name;
|
|
82
|
+
this.userInfo.lastName = userInfo.family_name;
|
|
83
|
+
this.userInfo.username = userInfo.preferred_username;
|
|
84
|
+
// TODO: Consider displaying initials if no photo. Is there always a photo?
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async requestUserInfo() {
|
|
88
|
+
this.isLoading = true;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const userInfoRes = await fetch(TBID_API_USERINFO_URL);
|
|
92
|
+
|
|
93
|
+
if (userInfoRes.ok) {
|
|
94
|
+
const userInfo = await userInfoRes.json();
|
|
95
|
+
this.updateAvatarWithUserInfo(userInfo);
|
|
96
|
+
this._didReceiveUserInfo = true;
|
|
97
|
+
}
|
|
98
|
+
} catch (ex) {
|
|
99
|
+
// TODO: Something not directly related to auth went wrong. Unsure what to do here.
|
|
100
|
+
console.error("Invalid response received from TBID API, aborting.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.isLoading = false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -3,6 +3,6 @@ import { LightningElement, api } from "lwc";
|
|
|
3
3
|
export default class Logo extends LightningElement {
|
|
4
4
|
@api href: string = "/";
|
|
5
5
|
@api imgSrc: string = "/assets/svg/salesforce-cloud.svg";
|
|
6
|
-
@api imgAlt: string = "Salesforce
|
|
6
|
+
@api imgAlt: string = "Salesforce logo";
|
|
7
7
|
@api label!: string;
|
|
8
8
|
}
|
package/LICENSE
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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.
|