@salesforcedevs/dx-components 0.19.3-alpha.4 → 0.20.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.19.3-alpha.4",
3
+ "version": "0.20.1",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -28,5 +28,6 @@
28
28
  "@types/classnames": "^2.2.10",
29
29
  "@types/debounce": "^1.2.0",
30
30
  "@types/lodash.get": "^4.4.6"
31
- }
31
+ },
32
+ "gitHead": "c7eab03d08445c1a6279f9480b7694d7e894e038"
32
33
  }
@@ -81,10 +81,6 @@ dx-button {
81
81
  }
82
82
 
83
83
  dx-type-badge {
84
- --dx-c-type-badge-border-radius: var(--dx-g-spacing-smd);
85
- --dx-c-type-badge-text-transform: capitalize;
86
- --dx-c-type-badge-height: var(--dx-g-spacing-lg);
87
-
88
84
  margin-top: var(--dx-g-spacing-sm);
89
85
  margin-bottom: var(--dx-g-spacing-sm);
90
86
  }
@@ -44,8 +44,9 @@
44
44
  {location}
45
45
  </span>
46
46
  <dx-type-badge
47
+ color={brandType}
48
+ type="content-type"
47
49
  value={type}
48
- brand={brand}
49
50
  if:true={type}
50
51
  ></dx-type-badge>
51
52
  </div>
@@ -49,6 +49,7 @@ export const Base = () => html`
49
49
  img-alt="Scenic view of a mountain."
50
50
  img-src="https://i.imgur.com/FUsyxR5.jpg"
51
51
  short-description="Dev Talkies is back in June! Kris Lande, SVP Trailhead Marketing and Trailblazer Relations at Salesforce, is joining us to inspire you and give you an exclusive peek into TrailheaDX."
52
+ type="Live Event"
52
53
  ></dx-card-event>
53
54
 
54
55
  <dx-card-event
@@ -36,7 +36,7 @@ export default class CardEvent extends LightningElement {
36
36
  this.isLinkHovered = false;
37
37
  }
38
38
 
39
- private get brand() {
40
- return this.type === "Webinar" ? "sales" : "service";
39
+ private get brandType() {
40
+ return this.type === "Webinar" ? "green" : "red";
41
41
  }
42
42
  }
@@ -122,6 +122,7 @@ input::placeholder {
122
122
  }
123
123
 
124
124
  .shortcut {
125
+ align-items: center;
125
126
  display: flex;
126
127
  flex-shrink: 0;
127
128
  flex-direction: row;
@@ -19,7 +19,7 @@
19
19
  <dx-type-badge
20
20
  if:true={showMethod}
21
21
  class={badgeClass}
22
- size="xs"
22
+ size="small"
23
23
  value={methodText}
24
24
  ></dx-type-badge>
25
25
  </div>
@@ -1,63 +1,77 @@
1
1
  import TypeBadge from "dx/typeBadge";
2
2
  import { createRenderComponent } from "utils/tests";
3
+ import { TypeBadgeSize, BadgeType } from "typings/custom";
3
4
 
4
5
  const TAG = "dx-type-badge";
5
6
  const render = createRenderComponent(TAG, TypeBadge);
6
7
 
7
8
  const value = "banana";
8
9
 
10
+ const assertContainerClasses = (
11
+ container: HTMLElement,
12
+ type: BadgeType = "metadata",
13
+ size: TypeBadgeSize = "default"
14
+ ) => {
15
+ expect(container).not.toBeNull();
16
+ expect(container.classList).toHaveLength(3);
17
+ expect(container.classList).toContain("typebadge");
18
+ expect(container.classList).toContain(`typebadge_${type}`);
19
+ expect(container.classList).toContain(`size-${size}`);
20
+ };
21
+
9
22
  describe(TAG, () => {
10
23
  it("renders", () => {
11
24
  const element = render({ value });
12
- const el = element.shadowRoot.querySelector(".typebadge");
13
- expect(el).not.toBeNull();
25
+ const el: HTMLElement = element.shadowRoot.querySelector(".typebadge");
26
+ assertContainerClasses(el);
14
27
  expect(el.getAttribute("style")).toBe(null);
15
- return expect(element).toBeAccessible();
16
- });
17
28
 
18
- it("renders the correct value", () => {
19
- const element = render({ value });
20
- const span = element.shadowRoot.querySelector("div");
21
- expect(span.textContent).toEqual(value);
22
- expect(element.getAttribute("style")).toBe(null);
29
+ const spanLabel = el.querySelector("span");
30
+ expect(spanLabel?.textContent).toBe(value);
31
+
23
32
  return expect(element).toBeAccessible();
24
33
  });
25
34
 
26
- it("renders medium class by default", () => {
27
- const element = render({ value });
28
- const el = element.shadowRoot.querySelector(".typebadge");
29
- expect(el.className).toContain("size-medium");
35
+ it("renders a content-type badge and size small", () => {
36
+ const element = render({ value, type: "content-type", size: "small" });
37
+ const el: HTMLElement = element.shadowRoot.querySelector(".typebadge");
38
+ assertContainerClasses(el, "content-type", "small");
30
39
  expect(el.getAttribute("style")).toBe(null);
40
+
31
41
  return expect(element).toBeAccessible();
32
42
  });
33
43
 
34
- it("can render small class", () => {
35
- const element = render({ size: "small", value });
36
- const el = element.shadowRoot.querySelector(".typebadge");
37
- expect(el.className).toContain("size-small");
38
- expect(el.getAttribute("style")).toBe(null);
39
- return expect(element).toBeAccessible();
44
+ it("renders as default type in case type is falsy", () => {
45
+ const element = render({ value, type: null });
46
+ const container = element.shadowRoot.querySelector(".typebadge");
47
+ assertContainerClasses(container);
48
+ expect(container.getAttribute("style")).toBe(null);
40
49
  });
41
50
 
42
- it("can render branded badges", () => {
43
- const element = render({ size: "small", brand: "industries", value });
51
+ it("renders with an specific color", () => {
52
+ const element = render({ value, color: "blue" });
53
+ const el: HTMLElement = element.shadowRoot.querySelector(".typebadge");
44
54
 
45
- const el = element.shadowRoot.querySelector(".typebadge");
46
- expect(el.className).toContain("size-small");
47
55
  expect(el.getAttribute("style")).toContain(
48
- `--dx-c-type-badge-color: var(--dx-g-brand-industries-color)`
56
+ "--background: var(--dx-g-blue-vibrant-95)"
49
57
  );
50
58
  expect(el.getAttribute("style")).toContain(
51
- `--dx-c-type-badge-background: var(--dx-g-brand-industries-color-background);`
59
+ "--color: var(--dx-g-blue-vibrant-40)"
52
60
  );
61
+
53
62
  return expect(element).toBeAccessible();
54
63
  });
55
64
 
56
- it("can render xs class", () => {
57
- const element = render({ size: "xs", value });
65
+ it("can pass a brand as color", () => {
66
+ const element = render({ color: "industries", value });
67
+
58
68
  const el = element.shadowRoot.querySelector(".typebadge");
59
- expect(element.getAttribute("style")).toBe(null);
60
- expect(el.className).toContain("size-xs");
69
+ expect(el.getAttribute("style")).toContain(
70
+ `--color: var(--dx-g-brand-industries-color)`
71
+ );
72
+ expect(el.getAttribute("style")).toContain(
73
+ `--background: var(--dx-g-brand-industries-color-background)`
74
+ );
61
75
  return expect(element).toBeAccessible();
62
76
  });
63
77
  });
@@ -1,52 +1,67 @@
1
1
  @import "helpers/reset";
2
2
 
3
- :host {
4
- --dx-c-type-badge-color: var(--dx-g-blue-vibrant-20);
5
- --dx-c-type-badge-background: var(--dx-g-cloud-blue-natural-90);
6
- --dx-c-type-badge-text-width: unset;
7
- --dx-c-type-badge-border-radius: var(--dx-g-spacing-xs);
8
- --dx-c-type-badge-text-transform: uppercase;
9
- --dx-c-type-badge-height: var(--dx-g-spacing-xl);
10
- }
11
-
12
3
  .typebadge {
13
- display: flex;
14
4
  align-items: center;
5
+ background: var(--dx-c-type-badge-background, var(--background));
6
+ border-radius: var(--dx-c-type-badge-border-radius, var(--border-radius));
7
+ color: var(--dx-c-type-badge-color, var(--color));
8
+ display: flex;
15
9
  justify-content: center;
10
+ height: var(--dx-c-type-badge-height, var(--height));
11
+ text-align: center;
12
+ white-space: nowrap;
16
13
  width: min-content;
17
- height: var(--dx-c-type-badge-height);
18
- padding: 0 var(--dx-g-spacing-md);
19
- border-radius: var(--dx-c-type-badge-border-radius);
20
- background: var(--dx-c-type-badge-background);
21
- color: var(--dx-c-type-badge-color);
22
- text-transform: var(--dx-c-type-badge-text-transform);
23
- font-size: var(--dx-g-text-xs);
14
+ }
15
+
16
+ .typebadge.typebadge_metadata {
17
+ --background: var(--dx-g-cloud-blue-natural-90);
18
+ --border-radius: var(--dx-g-spacing-xs);
19
+ --color: var(--dx-g-blue-vibrant-20);
20
+ --height: var(--dx-g-spacing-md);
21
+ --horizontal-spacing: var(--dx-g-spacing-sm);
22
+
24
23
  font-family: var(--dx-g-font-display);
25
- letter-spacing: 0.7px;
26
- white-space: nowrap;
24
+ font-size: 10px;
25
+ letter-spacing: 0.6px;
26
+ text-transform: var(--dx-c-type-badge-text-transform, uppercase);
27
+ padding: 0 var(--horizontal-spacing);
27
28
  }
28
29
 
29
- .typebadge div {
30
- text-align: center;
31
- transform: translateY(2px);
32
- width: var(--dx-c-type-badge-text-width);
30
+ .typebadge.typebadge_content-type {
31
+ --background: var(--sds-g-gray-3);
32
+ --border-radius: var(--dx-g-spacing-smd);
33
+ --color: var(--sds-g-gray-10);
34
+ --height: var(--dx-g-spacing-lg);
35
+ --horizontal-spacing: var(--dx-g-spacing-smd);
36
+ --vertical-spacing: var(--dx-g-spacing-xs);
37
+
38
+ font-family: var(--dx-g-font-sans);
39
+ font-size: var(--dx-g-text-xs);
40
+ font-weight: var(--dx-g-font-bold);
41
+ padding: var(--vertical-spacing) var(--horizontal-spacing);
33
42
  }
34
43
 
35
- .typebadge.size-small {
36
- height: var(--dx-g-spacing-md);
37
- padding: 0 var(--dx-g-spacing-sm);
44
+ .typebadge.typebadge_content-type.size-small {
45
+ --height: var(--dx-g-spacing-mlg);
46
+ --horizontal-spacing: var(--dx-g-spacing-sm);
47
+
38
48
  font-size: 10px;
39
- letter-spacing: 0.6px;
40
49
  }
41
50
 
42
- .typebadge.size-xs {
43
- height: var(--dx-g-spacing-md);
44
- padding: 0 var(--dx-g-spacing-xs);
51
+ .typebadge.typebadge_metadata.size-small {
52
+ --height: var(--dx-g-spacing-md);
53
+ --horizontal-spacing: var(--dx-g-spacing-xs);
54
+
45
55
  font-size: 8px;
46
56
  letter-spacing: 0.5px;
47
57
  }
48
58
 
49
- .typebadge.size-xs div {
59
+ .typebadge.typebadge_metadata span {
60
+ transform: translateY(2px);
61
+ width: var(--dx-c-type-badge-text-width, unset);
62
+ }
63
+
64
+ .typebadge.typebadge_metadata.size-small span {
50
65
  transform: translateY(1px);
51
66
  }
52
67
 
@@ -1,5 +1,5 @@
1
1
  <template>
2
2
  <div class={className} style={style}>
3
- <div>{value}</div>
3
+ <span>{value}</span>
4
4
  </div>
5
5
  </template>
@@ -1,15 +1,59 @@
1
1
  import { html } from "lit-html";
2
+ import { TypeBadgeColor, TypeBadgeSize, BadgeType } from "typings/custom";
3
+
4
+ const BADGE_COLOR_OPTIONS: Array<TypeBadgeColor> = [
5
+ "default",
6
+ "hot-orange",
7
+ "orange",
8
+ "yellow",
9
+ "green",
10
+ "teal",
11
+ "cloud-blue",
12
+ "blue",
13
+ "indigo",
14
+ "purple",
15
+ "violet",
16
+ "pink",
17
+ "red",
18
+ "analytics",
19
+ "employees",
20
+ "marketing",
21
+ "partners",
22
+ "commerce",
23
+ "sales",
24
+ "success",
25
+ "integration",
26
+ "platform",
27
+ "industries",
28
+ "learning",
29
+ "service"
30
+ ];
31
+ const SIZE_OPTIONS: Array<TypeBadgeSize> = ["default", "small"];
32
+ const BADGE_TYPE_OPTIONS: Array<BadgeType> = ["metadata", "content-type"];
2
33
 
3
34
  export default {
4
35
  title: "dx/dx-type-badge",
5
36
  component: "dx-type-badge",
6
37
  argTypes: {
7
- value: {
38
+ color: {
8
39
  control: {
9
- type: "text"
10
- }
40
+ type: "select"
41
+ },
42
+ options: BADGE_COLOR_OPTIONS
43
+ },
44
+ type: {
45
+ control: {
46
+ type: "select"
47
+ },
48
+ options: BADGE_TYPE_OPTIONS
49
+ },
50
+ size: {
51
+ control: {
52
+ type: "select"
53
+ },
54
+ options: SIZE_OPTIONS
11
55
  },
12
- brand: {
56
+ value: {
13
57
  control: {
14
58
  type: "text"
15
59
  }
@@ -19,43 +63,26 @@ export default {
19
63
 
20
64
  export const Base = (args: any) => html`
21
65
  <dx-type-badge
22
- value="${args.value || "Developer Experience"}"
23
- brand="${args.brand}"
66
+ value="${args.value}"
67
+ color="${args.color}"
68
+ size="${args.size}"
69
+ type="${args.type}"
24
70
  ></dx-type-badge>
25
71
  `;
26
-
27
- export const Branded = () => html`
28
- <dx-type-badge value="industries brand" brand="industries"></dx-type-badge>
29
-
30
- <br />
31
-
32
- <dx-type-badge value="sales brand" brand="sales"></dx-type-badge>
33
-
34
- <br />
35
-
36
- <dx-type-badge value="partners brand" brand="partners"></dx-type-badge>
37
-
38
- <br />
39
-
40
- <dx-type-badge value="invalid brand" brand="invalid"></dx-type-badge>
41
- `;
42
-
43
- export const Small = (args: any) => html`
44
- <dx-type-badge
45
- size="small"
46
- value="${args.value || "Analytics"}"
47
- ></dx-type-badge>
48
- `;
49
-
50
- export const XsWithCustomColorAndFixedWidth = (args: any) => html`
51
- <dx-type-badge size="xs" value="${args.value || "POST"}"></dx-type-badge>
52
- `;
72
+ Base.args = {
73
+ color: BADGE_COLOR_OPTIONS[0],
74
+ type: BADGE_TYPE_OPTIONS[0],
75
+ size: SIZE_OPTIONS[0],
76
+ value: "Developer Experience"
77
+ };
53
78
 
54
79
  export const CSSHooked = () => html`
55
80
  <style>
56
81
  .hooks {
57
82
  --dx-c-type-badge-color: var(--dx-g-green-vibrant-40);
58
83
  --dx-c-type-badge-background: var(--dx-g-green-vibrant-90);
84
+ --dx-c-type-badge-border-radius: var(--dx-g-spacing-xl);
85
+ --dx-c-type-badge-height: var(--dx-g-spacing-xl);
59
86
  }
60
87
  .hookinfo {
61
88
  color: gray;
@@ -70,6 +97,14 @@ export const CSSHooked = () => html`
70
97
  <b>--dx-c-type-badge-background:</b>
71
98
  <i>var(--dx-g-green-vibrant-90);</i>
72
99
  </p>
100
+ <p class="hookinfo">
101
+ <b>--dx-c-type-badge-border-radius:</b>
102
+ <i>var(--dx-g-spacing-xl);</i>
103
+ </p>
104
+ <p class="hookinfo">
105
+ <b>--dx-c-type-badge-height:</b>
106
+ <i>var(--dx-g-spacing-xl);</i>
107
+ </p>
73
108
  <br />
74
109
 
75
110
  <dx-type-badge
@@ -1,21 +1,65 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import cx from "classnames";
3
- import { TypeBadgeSize } from "typings/custom";
4
- import { Brand } from "typings/custom";
3
+ import {
4
+ TypeBadgeColor,
5
+ Color,
6
+ TypeBadgeSize,
7
+ BadgeType,
8
+ Brand
9
+ } from "typings/custom";
10
+ import { colorToDxColors } from "utils/css";
11
+
12
+ const DEFAULT_TYPE = "typebadge_metadata";
13
+ const VALID_BRANDS: Array<Brand> = [
14
+ "employees",
15
+ "marketing",
16
+ "partners",
17
+ "commerce",
18
+ "sales",
19
+ "success",
20
+ "integration",
21
+ "platform",
22
+ "industries",
23
+ "learning",
24
+ "service",
25
+ "analytics"
26
+ ];
5
27
 
6
28
  export default class TypeBadge extends LightningElement {
7
- @api size: TypeBadgeSize = "medium";
29
+ @api size: TypeBadgeSize = "default";
8
30
  @api value: string = "";
9
- @api brand?: Brand;
31
+ @api color?: TypeBadgeColor = "default";
32
+ @api type?: BadgeType = "metadata";
10
33
 
11
34
  private get className(): string {
12
- return cx("typebadge", `size-${this.size}`);
35
+ return cx(
36
+ "typebadge",
37
+ `size-${this.size}`,
38
+ (this.type && `typebadge_${this.type}`) || DEFAULT_TYPE
39
+ );
13
40
  }
14
41
 
15
42
  private get style(): string {
16
- if (this.brand) {
17
- return `--dx-c-type-badge-color: var(--dx-g-brand-${this.brand}-color); --dx-c-type-badge-background: var(--dx-g-brand-${this.brand}-color-background);`;
43
+ if (VALID_BRANDS.includes(this.color as Brand)) {
44
+ return this.buildStyleString({
45
+ background: `--dx-g-brand-${this.color}-color-background`,
46
+ color: `--dx-g-brand-${this.color}-color`
47
+ });
48
+ }
49
+ const variables = colorToDxColors(this.color as Color);
50
+ if (variables) {
51
+ return this.buildStyleString(variables);
18
52
  }
19
53
  return "";
20
54
  }
55
+
56
+ private buildStyleString({
57
+ background,
58
+ color
59
+ }: {
60
+ background: string;
61
+ color: string;
62
+ }): string {
63
+ return `--color: var(${color}); --background: var(${background})`;
64
+ }
21
65
  }
@@ -1,2 +1,43 @@
1
+ import { Color } from "typings/custom";
2
+
3
+ const LABEL_TO_DX_VAR: { [key: string]: string } = {
4
+ blue: "blue-vibrant",
5
+ "cloud-blue": "cloud-blue-vibrant",
6
+ green: "green-vibrant",
7
+ "hot-orange": "hot-orange-vibrant",
8
+ indigo: "indigo-vibrant",
9
+ orange: "orange-vibrant",
10
+ pink: "pink-vibrant",
11
+ purple: "purple-vibrant",
12
+ red: "red-vibrant",
13
+ teal: "teal-natural",
14
+ violet: "violet-vibrant",
15
+ yellow: "yellow-natural"
16
+ };
17
+
18
+ const DEFAULT_BACKGROUND_LEVEL = 95;
19
+ const DEFAULT_COLOR_LEVEL = 40;
20
+
21
+ export const colorToDxColors = (
22
+ color?: Color
23
+ ): {
24
+ background: string;
25
+ color: string;
26
+ } | null => {
27
+ if (!color) {
28
+ return null;
29
+ }
30
+
31
+ const dxVarColor = LABEL_TO_DX_VAR[color];
32
+ if (!dxVarColor) {
33
+ return null;
34
+ }
35
+
36
+ return {
37
+ background: `--dx-g-${dxVarColor}-${DEFAULT_BACKGROUND_LEVEL}`,
38
+ color: `--dx-g-${dxVarColor}-${DEFAULT_COLOR_LEVEL}`
39
+ };
40
+ };
41
+
1
42
  export const toDxColor = (color: string) =>
2
43
  ["white", "transparent"].includes(color) ? color : `var(--dx-g-${color})`;
@@ -29,8 +29,4 @@ export const highlightTerms = (
29
29
 
30
30
  element.innerHTML = innerHtml;
31
31
  });
32
- if (elements.length > 0) {
33
- console.log(elements[0], 'scrolling')
34
- elements[0].scrollIntoView(true);
35
- }
36
32
  };
package/src/.DS_Store DELETED
Binary file
Binary file
Binary file