@salesforcedevs/dx-components 0.54.5 → 0.54.6-alpha-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.
@@ -1,5 +1,3 @@
1
- @import "dxHelpers/slds";
2
-
3
1
  :host {
4
2
  display: block;
5
3
  }
@@ -8,7 +6,7 @@
8
6
  outline: none;
9
7
  }
10
8
 
11
- .slds-select_container::before {
9
+ .select_container::before {
12
10
  --icon-size: 0.5em;
13
11
 
14
12
  border-style: solid;
@@ -24,21 +22,196 @@
24
22
  width: var(--icon-size);
25
23
  }
26
24
 
27
- .placeholder {
25
+ .select-element_placeholder {
28
26
  color: var(--sds-g-gray-9);
29
27
  }
30
28
 
31
- select.slds-select:focus:not([disabled]),
32
- select.slds-select:active:not([disabled]) {
29
+ select.select-element:focus:not([disabled]),
30
+ select.select-element:active:not([disabled]) {
33
31
  border-width: 2px;
34
32
  border-color: var(--dx-g-blue-vibrant-50);
35
33
  box-shadow: none;
36
34
  -webkit-box-shadow: none;
37
35
  }
38
36
 
39
- :host(.slds-has-error) select.slds-select:focus,
40
- :host(.slds-has-error) select.slds-select:active {
37
+ .has-error select.select-element:focus,
38
+ .has-error select.select-element:active {
41
39
  border-color: #ea001e;
42
40
  box-shadow: 0 0 3px var(--dx-g-blue-vibrant-50);
43
41
  -webkit-box-shadow: 0 0 3px var(--dx-g-blue-vibrant-50);
44
42
  }
43
+
44
+ @media (min-width: 48em) {
45
+ .form-element_horizontal .form-element_control {
46
+ padding-left: 33%;
47
+ clear: none;
48
+ }
49
+ }
50
+
51
+ abbr[title] {
52
+ border-bottom: 1px dotted;
53
+ text-decoration: none;
54
+ cursor: help;
55
+ }
56
+
57
+ abbr[title]::after {
58
+ content: " (" attr(title) ")";
59
+ }
60
+
61
+ abbr[title],
62
+ fieldset,
63
+ hr {
64
+ border: 0;
65
+ }
66
+
67
+ button,
68
+ select {
69
+ text-transform: none;
70
+ }
71
+
72
+ .form-element_control {
73
+ clear: left;
74
+ position: relative;
75
+ }
76
+
77
+ .form-element_label {
78
+ overflow-wrap: break-word;
79
+ word-wrap: break-word;
80
+ -webkit-hyphens: auto;
81
+ -ms-hyphens: auto;
82
+ hyphens: auto;
83
+ display: inline-block;
84
+ color: #3e3e3c;
85
+ font-size: 0.75rem;
86
+ padding-right: 0.5rem;
87
+ padding-top: 0.25rem;
88
+ margin-bottom: 0.125rem;
89
+ }
90
+
91
+ .form-element_label:empty {
92
+ margin: 0;
93
+ }
94
+
95
+ .form-element_stacked .form-element_label,
96
+ .form-element_stacked .form-element_control {
97
+ border-bottom: 0;
98
+ padding-left: 0;
99
+ }
100
+
101
+ .form-element_stacked .form-element_control {
102
+ width: 100%;
103
+ -ms-flex-preferred-size: 100%;
104
+ flex-basis: 100%;
105
+ clear: left;
106
+ }
107
+
108
+ .assistive-text {
109
+ position: absolute !important;
110
+ margin: -1px !important;
111
+ border: 0 !important;
112
+ padding: 0 !important;
113
+ width: 1px !important;
114
+ height: 1px !important;
115
+ overflow: hidden !important;
116
+ clip: rect(0 0 0 0) !important;
117
+ text-transform: none !important;
118
+ white-space: nowrap !important;
119
+ }
120
+
121
+ .required-element {
122
+ color: #ea001e;
123
+ margin: 0 0.125rem;
124
+ }
125
+
126
+ .select-element {
127
+ height: calc(1.875rem + (1px * 2));
128
+ width: 100%;
129
+ border: 1px solid #dddbda;
130
+ border-radius: 0.25rem;
131
+ background-color: white;
132
+ -webkit-transition: border 0.1s linear, background-color 0.1s linear;
133
+ transition: border 0.1s linear, background-color 0.1s linear;
134
+ }
135
+
136
+ .select-element:focus,
137
+ .select-element:active {
138
+ outline: 0;
139
+ border-color: #1b96ff;
140
+ background-color:white;
141
+ -webkit-box-shadow: 0 0 3px #0176d3;
142
+ box-shadow: 0 0 3px #0176d3;
143
+ }
144
+
145
+ .select-element[disabled],
146
+ .select-element.slds-is-disabled {
147
+ background-color: #ecebea;
148
+ border-color: #c9c7c5;
149
+ color: #3e3e3c;
150
+ cursor: not-allowed;
151
+ -webkit-user-select: none;
152
+ -moz-user-select: none;
153
+ -ms-user-select: none;
154
+ user-select: none;
155
+ opacity: 1;
156
+ }
157
+
158
+ .select-element[disabled]:focus,
159
+ .select-element[disabled]:active,
160
+ .select-element.slds-is-disabled:focus,
161
+ .select-element.slds-is-disabled:active {
162
+ -webkit-box-shadow: none;
163
+ box-shadow: none;
164
+ }
165
+
166
+ .select-element[size] {
167
+ min-height: calc(1.875rem + (1px * 2));
168
+ height: inherit;
169
+ }
170
+
171
+ .select-element[size] option {
172
+ padding: 0.5rem;
173
+ }
174
+
175
+ .has-error .select-element {
176
+ border-color: #ea001e;
177
+ -webkit-box-shadow: #ea001e 0 0 0 1px inset;
178
+ box-shadow: #ea001e 0 0 0 1px inset;
179
+ background-clip: padding-box;
180
+ }
181
+
182
+ .select_container {
183
+ position: relative;
184
+ }
185
+
186
+ .select_container .select-element {
187
+ -moz-appearance: none;
188
+ -webkit-appearance: none;
189
+ padding-left: 0.5rem;
190
+ padding-right: 1.5rem;
191
+ }
192
+
193
+ .select_container .select-element::-ms-expand {
194
+ display: none;
195
+ }
196
+
197
+ .has-error .select-element:focus,
198
+ .has-error .select-element:active {
199
+ -webkit-box-shadow: #ea001e 0 0 0 1px inset, 0 0 3px #0176d3;
200
+ box-shadow: #ea001e 0 0 0 1px inset, 0 0 3px #0176d3;
201
+ }
202
+
203
+ .form-element:not(.has-error) .select-element:required {
204
+ -webkit-box-shadow: none;
205
+ box-shadow: none;
206
+ }
207
+
208
+ .form-element_help,
209
+ .form-element_helper {
210
+ font-size: 0.75rem;
211
+ margin-top: 0.125rem;
212
+ display: block;
213
+ }
214
+
215
+ .has-error .form-element_help {
216
+ color: #ea001e;
217
+ }
@@ -1,60 +1,57 @@
1
1
  <template>
2
- <label class={computedLabelClass} for="select">
3
- {label}
4
- <template if:true={required}>
5
- <abbr>*</abbr>
6
- </template>
7
- </label>
8
-
9
- <div class="slds-form-element__control">
10
- <div class="slds-select_container">
11
- <select
12
- autocomplete={autocomplete}
13
- class={selectClass}
14
- disabled={disabled}
15
- id="select"
16
- multiple={multiple}
17
- name={name}
18
- onblur={handleBlur}
19
- onchange={handleChange}
20
- onfocus={handleFocus}
21
- required={required}
22
- accesskey={accessKey}
23
- size={size}
24
- >
25
- <template if:true={placeholder}>
26
- <option if:false={value} value="" disabled>
27
- {placeholder}
28
- </option>
29
- </template>
30
- <template for:each={options} for:item="option">
31
- <template if:true={option.disabled}>
32
- <option
33
- disabled
34
- key={option.value}
35
- value={option.value}
36
- >
37
- {option.label}
38
- </option>
2
+ <div class={containerClass}>
3
+ <label class="form-element_label" for="select">
4
+ {label}
5
+ <template if:true={required}>
6
+ <abbr>*</abbr>
7
+ </template>
8
+ </label>
9
+ <div class="form-element_control">
10
+ <div class="select_container">
11
+ <select
12
+ autocomplete={autocomplete}
13
+ class={selectClass}
14
+ disabled={disabled}
15
+ id="select"
16
+ name={name}
17
+ onblur={handleBlur}
18
+ onchange={handleChange}
19
+ onfocus={handleFocus}
20
+ required={required}
21
+ accesskey={accessKey}
22
+ size={size}
23
+ >
24
+ <template if:true={placeholder}>
25
+ <option value="" disabled>{placeholder}</option>
39
26
  </template>
40
- <template if:false={option.disabled}>
41
- <option key={option.value} value={option.value}>
42
- {option.label}
43
- </option>
27
+ <template for:each={options} for:item="option">
28
+ <template if:true={option.disabled}>
29
+ <option
30
+ disabled
31
+ key={option.value}
32
+ value={option.value}
33
+ >
34
+ {option.label}
35
+ </option>
36
+ </template>
37
+ <template if:false={option.disabled}>
38
+ <option key={option.value} value={option.value}>
39
+ {option.label}
40
+ </option>
41
+ </template>
44
42
  </template>
45
- </template>
46
- </select>
43
+ </select>
44
+ </div>
47
45
  </div>
46
+ <template if:true={helpMessage}>
47
+ <div
48
+ aria-live="assertive"
49
+ class="form-element_help"
50
+ data-help-message
51
+ id="help-message"
52
+ >
53
+ {helpMessage}
54
+ </div>
55
+ </template>
48
56
  </div>
49
-
50
- <template if:true={_helpMessage}>
51
- <div
52
- aria-live="assertive"
53
- class="slds-form-element__help"
54
- data-help-message
55
- id="help-message"
56
- >
57
- {_helpMessage}
58
- </div>
59
- </template>
60
57
  </template>
@@ -1,23 +1,141 @@
1
1
  import cx from "classnames";
2
- import { api } from "lwc";
3
- import LightningSelect from "lightning/select";
4
- import { toJson } from "dxUtils/normalizers";
2
+ import { LightningElement, api } from "lwc";
3
+ import { SelectOption } from "typings/custom";
4
+ import { toJson, normalizeBoolean } from "dxUtils/normalizers";
5
5
 
6
- export default class Select extends LightningSelect {
6
+ export const DEFAULT_MISSING_MESSAGE = "This field is required";
7
+
8
+ export default class Select extends LightningElement {
9
+ @api accessKey!: string;
10
+ @api autocomplete?: string;
11
+ @api label?: string;
12
+ @api messageWhenValueMissing: string = DEFAULT_MISSING_MESSAGE;
13
+ @api name?: string;
7
14
  @api placeholder?: string;
15
+ @api size?: string;
16
+
17
+ @api
18
+ get disabled() {
19
+ return this._disabled;
20
+ }
21
+
22
+ set disabled(value) {
23
+ this._disabled = normalizeBoolean(value);
24
+ }
25
+
26
+ @api
27
+ get options() {
28
+ return this._options;
29
+ }
30
+
31
+ set options(value) {
32
+ this._options = toJson(value);
33
+ }
8
34
 
9
35
  @api
10
- get jsonOptions() {
11
- return this.options;
36
+ get required() {
37
+ return this._required;
12
38
  }
13
39
 
14
- set jsonOptions(value) {
15
- this.options = toJson(value);
40
+ set required(value) {
41
+ this._required = normalizeBoolean(value);
42
+ }
43
+
44
+ @api
45
+ get value() {
46
+ return this._value;
47
+ }
48
+
49
+ set value(value) {
50
+ this._value = value;
51
+ this.updateSelectValue();
52
+ }
53
+
54
+ _disabled = false;
55
+ _size = "";
56
+ _required = false;
57
+ _options: Array<SelectOption> = [];
58
+ _value: string = "";
59
+ _selectElement: HTMLSelectElement | null = null;
60
+ helpMessage?: string = "";
61
+
62
+ renderedCallback(): void {
63
+ this.updateSelectValue();
64
+ }
65
+
66
+ get containerClass() {
67
+ return cx("form-element", this.hasError && "has-error");
68
+ }
69
+
70
+ get hasError(): boolean {
71
+ return !!this.helpMessage;
16
72
  }
17
73
 
18
74
  get selectClass() {
19
- return cx("slds-select", {
20
- placeholder: !this.value
75
+ return cx("select-element", {
76
+ "select-element_placeholder": this.placeholder && !this.value
21
77
  });
22
78
  }
79
+
80
+ get selectElement() {
81
+ if (!this._selectElement) {
82
+ this._selectElement =
83
+ this.template.querySelector<HTMLSelectElement>("select");
84
+ }
85
+ return this._selectElement;
86
+ }
87
+
88
+ @api
89
+ blur(): void {
90
+ if (this.selectElement) {
91
+ this.selectElement.blur();
92
+ }
93
+ }
94
+
95
+ @api
96
+ focus(): void {
97
+ if (this.selectElement) {
98
+ this.selectElement.focus();
99
+ }
100
+ }
101
+
102
+ @api
103
+ reportValidity(): boolean {
104
+ const isInvalid = this._required && !this._value;
105
+ this.helpMessage = isInvalid
106
+ ? this.messageWhenValueMissing || DEFAULT_MISSING_MESSAGE
107
+ : "";
108
+ return !isInvalid;
109
+ }
110
+
111
+ handleBlur(): void {
112
+ this.reportValidity();
113
+ this.dispatchEvent(new CustomEvent("blur"));
114
+ }
115
+
116
+ handleChange(event: Event & { target: HTMLSelectElement }): void {
117
+ const { value } = event.target;
118
+ this._value = value;
119
+ this.dispatchEvent(
120
+ new CustomEvent("change", {
121
+ detail: { value }
122
+ })
123
+ );
124
+ }
125
+
126
+ handleFocus(): void {
127
+ this.helpMessage = "";
128
+ this.dispatchEvent(new CustomEvent("focus"));
129
+ }
130
+
131
+ // We have to do it programmatically because value binding doesn't work apparently.
132
+ updateSelectValue(): void {
133
+ if (!this._value && !this.placeholder) {
134
+ return;
135
+ }
136
+
137
+ if (this.selectElement) {
138
+ this.selectElement.value = this._value;
139
+ }
140
+ }
23
141
  }
@@ -1,6 +1,6 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import cx from "classnames";
3
- import { Brand, Option } from "typings/custom";
3
+ import { Brand, OptionWithLink, OptionWithNested } from "typings/custom";
4
4
  import { toJson } from "dxUtils/normalizers";
5
5
  import { track } from "dxUtils/analytics";
6
6
 
@@ -61,8 +61,8 @@ export abstract class HeaderBase extends LightningElement {
61
61
  this._versions = toJson(value);
62
62
  }
63
63
 
64
- private _navItems!: Option[];
65
- private _versions!: Option[];
64
+ private _navItems!: OptionWithNested[];
65
+ private _versions!: OptionWithLink[];
66
66
  private matchMedia!: MediaQueryList;
67
67
  protected mobile: boolean = false;
68
68
  private mobileNavMenuValue: string | null = null;
@@ -1,12 +1,12 @@
1
- import { Option } from "typings/custom";
1
+ import { OptionWithNested } from "typings/custom";
2
2
 
3
3
  const deepmapper = (
4
- _options: Option[],
5
- _callback: (option: Option, lavel: number) => Option,
4
+ _options: OptionWithNested[],
5
+ _callback: (option: OptionWithNested, lavel: number) => OptionWithNested,
6
6
  level: number = 0
7
- ): Option[] => {
7
+ ): OptionWithNested[] => {
8
8
  const _level = level + 1;
9
- return _options?.map((option: Option) =>
9
+ return _options?.map((option: OptionWithNested) =>
10
10
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
11
  option.options
12
12
  ? {
@@ -18,9 +18,13 @@ const deepmapper = (
18
18
  };
19
19
 
20
20
  export const deepmapOptions = (
21
- options: Option[],
22
- callback: (option: Option, index: number, level: number) => Option
23
- ): Option[] => {
21
+ options: OptionWithNested[],
22
+ callback: (
23
+ option: OptionWithNested,
24
+ index: number,
25
+ level: number
26
+ ) => OptionWithNested
27
+ ): OptionWithNested[] => {
24
28
  let index = 0;
25
29
  return deepmapper(options, (option, level) => {
26
30
  const newOption = callback(option, index, level);
@@ -29,7 +33,7 @@ export const deepmapOptions = (
29
33
  });
30
34
  };
31
35
 
32
- export const getOptionsCount = (options: Option[]) => {
36
+ export const getOptionsCount = (options: OptionWithNested[]) => {
33
37
  let count = 0;
34
38
  deepmapper(options, (option) => {
35
39
  count += 1;