fleetcor-lwc 2.1.1 → 2.2.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/README.md CHANGED
@@ -50,6 +50,21 @@ const pathConstants = 'frontend/common/mixins.scss';
50
50
 
51
51
  ## Components
52
52
 
53
+ ```html
54
+ Checkbox:
55
+
56
+ <flt-checkbox
57
+ size="s"
58
+ name="agreement"
59
+ disabled="true"
60
+ required="true"
61
+ group="main"
62
+ value="true"
63
+ label="Next"
64
+ ></flt-checkbox>
65
+ ...
66
+ ```
67
+
53
68
  ```html
54
69
  Button:
55
70
 
@@ -153,10 +168,48 @@ $FLT_BUTTON_LARGE_FONT_SIZE: var(--flt-button-large-font-size, 15px);
153
168
  $FLT_BUTTON_LABEL_PADDING: var(--flt-button-label-padding, 0);
154
169
 
155
170
  // <- BUTTON
171
+
172
+ // CHECKBOX ->
173
+ $FLT_CHECKBOX_BORDER_COLOR: var(--flt-checkbox-border-color, #6b7280);
174
+ $FLT_CHECKBOX_BG_COLOR: var(--flt-checkbox-bg-color, #ffffff);
175
+
176
+ $FLT_CHECKBOX_AGREE_COLOR: var(--flt-checkbox-agree-color, #59eb9c);
177
+ $FLT_CHECKBOX_COLOR: var(--flt-checkbox-color, #111827);
178
+ $FLT_CHECKBOX_ERROR_COLOR: var(--flt-checkbox-error-color, #ed123d);
179
+
180
+ $FLT_CHECKBOX_DISABLED_COLOR: var(--flt-checkbox-disabled-color, #6b7280);
181
+ $FLT_CHECKBOX_DISABLED_BORDER_COLOR: var(
182
+ --flt-checkbox-disabled-border-color,
183
+ #6b7280
184
+ );
185
+ $FLT_CHECKBOX_DISABLED_BG_COLOR: var(--flt-checkbox-disabled-bg-color, #e5e7eb);
186
+ $FLT_CHECKBOX_DISABLED_AGREE_COLOR: var(--flt-checkbox-agree-color, #9ca3af);
187
+
188
+ $FLT_CHECKBOX_HOVER_BORDER_COLOR: var(
189
+ --flt-checkbox-hover-border-color,
190
+ #111827
191
+ );
192
+ $FLT_CHECKBOX_HOVER_BG_COLOR: var(--flt-checkbox-hover-bg-color, #f9fafb);
193
+ // <- CHECKBOX
156
194
  ```
157
195
 
158
196
  ## Release Notes:
159
197
 
198
+ - v.2.2.2
199
+ - Bug fix checkbox link underline text
200
+
201
+ ---
202
+
203
+ - v.2.2.1
204
+ - Bug fix expose flt/checkbox
205
+
206
+ ---
207
+
208
+ - v.2.2.0
209
+ - Added Component `flt-checkbox`
210
+
211
+ ---
212
+
160
213
  - v.2.1.1
161
214
  - Added to `Button` new type `secondary`
162
215
  - Added to `Button` new size `xs`
@@ -42,5 +42,21 @@ $FLT_BUTTON_LARGE_HEIGHT: var(--flt-button-large-height, 56px);
42
42
  $FLT_BUTTON_LARGE_FONT_SIZE: var(--flt-button-large-font-size, 15px);
43
43
 
44
44
  $FLT_BUTTON_LABEL_PADDING: var(--flt-button-label-padding, 0);
45
-
46
45
  // <- BUTTON
46
+
47
+ // CHECKBOX ->
48
+ $FLT_CHECKBOX_BORDER_COLOR: var(--flt-checkbox-border-color, #6b7280);
49
+ $FLT_CHECKBOX_BG_COLOR: var(--flt-checkbox-bg-color, #ffffff);
50
+
51
+ $FLT_CHECKBOX_AGREE_COLOR: var(--flt-checkbox-agree-color, #59eb9c);
52
+ $FLT_CHECKBOX_COLOR: var(--flt-checkbox-color, #111827);
53
+ $FLT_CHECKBOX_ERROR_COLOR: var(--flt-checkbox-error-color, #ed123d);
54
+
55
+ $FLT_CHECKBOX_DISABLED_COLOR: var(--flt-checkbox-disabled-color, #6b7280);
56
+ $FLT_CHECKBOX_DISABLED_BORDER_COLOR: var(--flt-checkbox-disabled-border-color, #6b7280);
57
+ $FLT_CHECKBOX_DISABLED_BG_COLOR: var(--flt-checkbox-disabled-bg-color, #e5e7eb);
58
+ $FLT_CHECKBOX_DISABLED_AGREE_COLOR: var(--flt-checkbox-agree-color, #9ca3af);
59
+
60
+ $FLT_CHECKBOX_HOVER_BORDER_COLOR: var(--flt-checkbox-hover-border-color, #111827);
61
+ $FLT_CHECKBOX_HOVER_BG_COLOR: var(--flt-checkbox-hover-bg-color, #f9fafb);
62
+ // <- CHECKBOX
@@ -44,3 +44,20 @@ $FLT_BUTTON_LARGE_FONT_SIZE: var(--flt-button-large-font-size, 15px);
44
44
  $FLT_BUTTON_LABEL_PADDING: var(--flt-button-label-padding, 0);
45
45
 
46
46
  // <- BUTTON
47
+
48
+ // CHECKBOX ->
49
+ $FLT_CHECKBOX_BORDER_COLOR: var(--flt-checkbox-border-color, #6b7280);
50
+ $FLT_CHECKBOX_BG_COLOR: var(--flt-checkbox-bg-color, #ffffff);
51
+
52
+ $FLT_CHECKBOX_AGREE_COLOR: var(--flt-checkbox-agree-color, #59eb9c);
53
+ $FLT_CHECKBOX_COLOR: var(--flt-checkbox-color, #111827);
54
+ $FLT_CHECKBOX_ERROR_COLOR: var(--flt-checkbox-error-color, #ed123d);
55
+
56
+ $FLT_CHECKBOX_DISABLED_COLOR: var(--flt-checkbox-disabled-color, #6b7280);
57
+ $FLT_CHECKBOX_DISABLED_BORDER_COLOR: var(--flt-checkbox-disabled-border-color, #6b7280);
58
+ $FLT_CHECKBOX_DISABLED_BG_COLOR: var(--flt-checkbox-disabled-bg-color, #e5e7eb);
59
+ $FLT_CHECKBOX_DISABLED_AGREE_COLOR: var(--flt-checkbox-agree-color, #9ca3af);
60
+
61
+ $FLT_CHECKBOX_HOVER_BORDER_COLOR: var(--flt-checkbox-hover-border-color, #111827);
62
+ $FLT_CHECKBOX_HOVER_BG_COLOR: var(--flt-checkbox-hover-bg-color, #f9fafb);
63
+ // <- CHECKBOX
@@ -0,0 +1,76 @@
1
+ import { createElement } from 'lwc'
2
+
3
+ import Checkbox from 'flt/checkbox'
4
+
5
+ describe('flt-checkbox', () => {
6
+ afterEach(() => {
7
+ while (document.body.firstChild) {
8
+ document.body.removeChild(document.body.firstChild)
9
+ }
10
+ })
11
+
12
+ it('Generate default checkbox', async () => {
13
+ const checkboxDefault = createElement('flt-checkbox', { is: Checkbox })
14
+ checkboxDefault.label = 'Hello world'
15
+ checkboxDefault.name = 'agree'
16
+ document.body.appendChild(checkboxDefault)
17
+
18
+ await expect(checkboxDefault.firstChild.classList).toContain('flt-checkbox')
19
+ await expect(checkboxDefault.firstChild.classList).toContain('flt-checkbox_size_s')
20
+ await expect(checkboxDefault.firstChild.classList).not.toContain('flt-checkbox_disabled')
21
+
22
+ const valid = checkboxDefault.isValid()
23
+ await expect(valid).toBeTruthy()
24
+ let data = checkboxDefault.getData()
25
+ await expect(data.value).toBeFalsy()
26
+ await checkboxDefault.firstChild.click()
27
+ data = checkboxDefault.getData()
28
+ await expect(data.value).toBeTruthy()
29
+ await expect(checkboxDefault.firstChild.classList).toContain('flt-checkbox_active')
30
+ })
31
+
32
+ it('Generate requie checkbox', async () => {
33
+ const checkboxRequie = createElement('flt-checkbox', { is: Checkbox })
34
+ checkboxRequie.label = 'Hello world'
35
+ checkboxRequie.name = 'agree'
36
+ checkboxRequie.required = true
37
+ document.body.appendChild(checkboxRequie)
38
+
39
+ const valid = checkboxRequie.isValid()
40
+ await expect(valid).toBeFalsy()
41
+ let data = checkboxRequie.getData()
42
+ await expect(data.value).toBeFalsy()
43
+
44
+ const checkboxRequieErrorElement = document.querySelector('.flt-checkbox__error-message')
45
+ await expect(checkboxRequieErrorElement.classList).toContain('flt-checkbox__error-message_active')
46
+
47
+ await checkboxRequie.firstChild.click()
48
+ data = checkboxRequie.getData()
49
+ await expect(data.value).toBeTruthy()
50
+ await expect(checkboxRequie.firstChild.classList).not.toContain('flt-checkbox_error')
51
+ await expect(checkboxRequieErrorElement.classList).not.toContain(
52
+ 'flt-checkbox__error-message_active'
53
+ )
54
+ })
55
+
56
+ it('Generate disbled checkbox', async () => {
57
+ const checkboxDisabled = createElement('flt-checkbox', { is: Checkbox })
58
+ checkboxDisabled.label = 'Hello world'
59
+ checkboxDisabled.name = 'agree'
60
+ checkboxDisabled.disabled = true
61
+ document.body.appendChild(checkboxDisabled)
62
+
63
+ await expect(checkboxDisabled.firstChild.classList).toContain('flt-checkbox')
64
+ await expect(checkboxDisabled.firstChild.classList).toContain('flt-checkbox_size_s')
65
+ await expect(checkboxDisabled.firstChild.classList).toContain('flt-checkbox_disabled')
66
+
67
+ const valid = checkboxDisabled.isValid()
68
+ await expect(valid).toBeTruthy()
69
+ let data = checkboxDisabled.getData()
70
+ await expect(data.value).toBeFalsy()
71
+ await checkboxDisabled.firstChild.click()
72
+ data = checkboxDisabled.getData()
73
+ await expect(data.value).toBeFalsy()
74
+ await expect(checkboxDisabled.firstChild.classList).not.toContain('flt-checkbox_active')
75
+ })
76
+ })
@@ -0,0 +1,29 @@
1
+ <template lwc:render-mode="light">
2
+ <label class={computedLabelClass}>
3
+ <input
4
+ class="flt-checkbox__input"
5
+ type="checkbox"
6
+ checked={value}
7
+ disabled={disabled}
8
+ onchange={handleChange} />
9
+ <span class={computedSpanClass}>
10
+ <svg
11
+ if:true={value}
12
+ class="flt-checkbox__icon-agree"
13
+ width="20"
14
+ height="20"
15
+ viewBox="0 0 20 20"
16
+ fill="none"
17
+ xmlns="http://www.w3.org/2000/svg">
18
+ <path
19
+ class="flt-checkbox__icon-agree-path"
20
+ d="M3.75 10.625L8.75 15.625L16.25 4.375"
21
+ stroke-width="2"
22
+ stroke-linecap="round"
23
+ stroke-linejoin="round"></path>
24
+ </svg>
25
+ </span>
26
+ <div class="flt-checkbox__label"></div>
27
+ </label>
28
+ <div class={computedErrorMessage}>{errorMessage}</div>
29
+ </template>
@@ -0,0 +1,51 @@
1
+ import './checkbox.scss'
2
+
3
+ import { api } from 'lwc'
4
+ import { CheckboxElement } from 'fleetcor-lwc'
5
+
6
+ /**
7
+ * @class Checkbox
8
+ * @extends CheckboxElement
9
+ * @description Flt checkbox component
10
+ */
11
+ export default class Checkbox extends CheckboxElement {
12
+ error
13
+
14
+ @api errorMessage
15
+ @api size = SIZES.SMALL
16
+
17
+ @api validate() {
18
+ this.error = !this.isValid()
19
+ }
20
+
21
+ get computedErrorMessage() {
22
+ return this.generateClassNameList({
23
+ 'flt-checkbox__error-message': true,
24
+ 'flt-checkbox__error-message_active': this.error
25
+ })
26
+ }
27
+ get computedSpanClass() {
28
+ return this.generateClassNameList({
29
+ 'flt-checkbox__icon': true,
30
+ 'flt-checkbox__icon_active': this.value
31
+ })
32
+ }
33
+ get computedLabelClass() {
34
+ return this.generateClassNameList({
35
+ 'flt-checkbox': true,
36
+ 'flt-checkbox_active': this.value,
37
+ 'flt-checkbox_disabled': this.disabled,
38
+ 'flt-checkbox_error': this.error,
39
+ [`flt-checkbox_size_${this.size}`]: true
40
+ })
41
+ }
42
+
43
+ renderedCallback() {
44
+ super.renderedCallback()
45
+ this.querySelector('.flt-checkbox__label').innerHTML = this.label
46
+ }
47
+ }
48
+
49
+ const SIZES = {
50
+ SMALL: 's'
51
+ }
@@ -0,0 +1,98 @@
1
+ @import './../../../common/mixins_aquamarine';
2
+ /* mixins */
3
+
4
+ .flt-checkbox {
5
+ display: flex;
6
+ cursor: pointer;
7
+
8
+ &:hover:not(.flt-checkbox_disabled, .flt-checkbox_error) {
9
+ .flt-checkbox__icon {
10
+ border-color: $FLT_CHECKBOX_HOVER_BORDER_COLOR;
11
+ background-color: $FLT_CHECKBOX_HOVER_BG_COLOR;
12
+ }
13
+ }
14
+
15
+ &_disabled {
16
+ cursor: not-allowed;
17
+
18
+ .flt-checkbox__icon {
19
+ border-color: $FLT_CHECKBOX_DISABLED_BORDER_COLOR;
20
+ background-color: $FLT_CHECKBOX_DISABLED_BG_COLOR;
21
+ }
22
+
23
+ .flt-checkbox__label {
24
+ color: $FLT_CHECKBOX_DISABLED_COLOR;
25
+ }
26
+
27
+ .flt-checkbox__icon-agree-path {
28
+ stroke: $FLT_CHECKBOX_DISABLED_AGREE_COLOR;
29
+ }
30
+ }
31
+
32
+ &_error {
33
+ .flt-checkbox__icon {
34
+ border-color: $FLT_CHECKBOX_ERROR_COLOR;
35
+ }
36
+ }
37
+
38
+ &_size_s {
39
+ font-size: 14px;
40
+ line-height: 1.5;
41
+
42
+ & + .flt-checkbox__error-message {
43
+ font-size: 12px;
44
+ }
45
+
46
+ .flt-checkbox__icon {
47
+ width: 1.25rem;
48
+ height: 1.25rem;
49
+ }
50
+ }
51
+
52
+ &__input {
53
+ display: none;
54
+ }
55
+
56
+ &__icon {
57
+ display: flex;
58
+ border: 1px solid $FLT_CHECKBOX_BORDER_COLOR;
59
+ background-color: $FLT_CHECKBOX_BG_COLOR;
60
+ border-radius: 6px;
61
+ box-sizing: border-box;
62
+ margin-right: 1rem;
63
+ flex-shrink: 0;
64
+ transition: all 0.3s;
65
+ }
66
+
67
+ &__icon-agree {
68
+ display: inline-block;
69
+ width: 100%;
70
+ height: 100%;
71
+ }
72
+
73
+ &__icon-agree-path {
74
+ stroke: $FLT_CHECKBOX_AGREE_COLOR;
75
+ }
76
+
77
+ &__label {
78
+ color: $FLT_CHECKBOX_COLOR;
79
+
80
+ a {
81
+ color: inherit;
82
+ text-decoration: underline;
83
+ }
84
+ }
85
+
86
+ &__error-message {
87
+ color: $FLT_CHECKBOX_ERROR_COLOR;
88
+ margin-left: 36px;
89
+ opacity: 0;
90
+ line-height: 0;
91
+ transition: all 0.3s;
92
+
93
+ &_active {
94
+ opacity: 1;
95
+ line-height: 1.5;
96
+ }
97
+ }
98
+ }
@@ -1,3 +1,4 @@
1
+ import { api } from 'lwc'
1
2
  import { UserDataValidator } from 'fleetcor-lwc'
2
3
 
3
4
  /**
@@ -6,4 +7,20 @@ import { UserDataValidator } from 'fleetcor-lwc'
6
7
  * @extends UserDataValidator
7
8
  * @description This class is used to mark a component as a checkbox element
8
9
  */
9
- export default class CheckboxElement extends UserDataValidator {}
10
+ export default class CheckboxElement extends UserDataValidator {
11
+ @api isValid() {
12
+ return this.required ? !!this.value : true
13
+ }
14
+
15
+ handleChange(event) {
16
+ event.stopPropagation()
17
+ if (!this.disabled) {
18
+ this.value = !this.value
19
+ this.dispatchEvent(
20
+ new CustomEvent('change', {
21
+ detail: this.getData()
22
+ })
23
+ )
24
+ }
25
+ }
26
+ }
@@ -12,11 +12,17 @@ export default class UserDataManager extends BaseElement {
12
12
  @api name
13
13
  @api value
14
14
  @api group
15
+ @api disabled
16
+ @api required
17
+ @api label
15
18
 
16
19
  @api getData() {
17
20
  return {
18
21
  name: this.name,
22
+ disabled: this.disabled,
19
23
  value: this.value,
24
+ required: this.required,
25
+ label: this.label,
20
26
  group: this.group
21
27
  }
22
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetcor-lwc",
3
- "version": "2.1.1",
3
+ "version": "2.2.2",
4
4
  "description": "LWC framework by Fleetcor",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,6 +28,7 @@
28
28
  }
29
29
  ],
30
30
  "expose": [
31
+ "flt/checkbox",
31
32
  "flt/button",
32
33
  "flt/icon",
33
34
  "flt/tooltip"