@newlogic-digital/stimulus-components 1.1.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newlogic-digital/stimulus-components",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "eslint": "eslint '**/*.js'",
@@ -9,14 +9,17 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@hotwired/stimulus": "^3.2.2",
12
- "@newlogic-digital/utils-js": "^1.1.1",
13
- "winduum-stimulus": "^2.0.11"
12
+ "@newlogic-digital/utils-js": "^1.2.0",
13
+ "winduum-stimulus": "^2.0.13"
14
14
  },
15
15
  "devDependencies": {
16
- "@newlogic-digital/cookieconsent-js": "^1.0.0",
16
+ "@eslint/js": "^10.0.1",
17
+ "@stylistic/eslint-plugin": "^5.10.0",
18
+ "@googlemaps/js-api-loader": "^2.0.2",
19
+ "@newlogic-digital/cookieconsent-js": "^1.1.1",
17
20
  "@types/grecaptcha": "^3.0.9",
18
- "eslint": "^9.19.0",
19
- "neostandard": "^0.12.0",
21
+ "eslint": "^10.1.0",
22
+ "globals": "^17.4.0",
20
23
  "winduum": "^2.1.0"
21
24
  },
22
25
  "files": [
@@ -7,53 +7,83 @@
7
7
  }
8
8
 
9
9
  & :where(div[aria-hidden]) {
10
+ border-radius: var(--x-control-select-picker-border-radius);
11
+ border:
12
+ var(--x-control-select-picker-border-width) solid
13
+ color-mix(
14
+ in var(--x-control-select-picker-border-color-space, srgb),
15
+ var(--x-control-select-picker-border-color) var(--x-control-select-picker-border-color-opacity, 15%),
16
+ var(--x-control-select-picker-border-color-mix, transparent)
17
+ );
18
+ background-color: var(--x-control-select-picker-background-color);
19
+ margin-block: var(--x-control-select-picker-margin-block);
20
+ padding-block: var(--x-control-select-picker-padding-block);
21
+ padding-inline: var(--x-control-select-picker-padding-inline);
22
+ gap: var(--x-control-select-picker-gap);
23
+ scrollbar-color: var(--x-control-select-picker-scrollbar-color);
24
+ transition-property: var(--x-control-select-picker-transition-property, var(--default-transition-property));
25
+ transition-duration: var(--x-control-select-picker-transition-duration, var(--default-transition-duration));
26
+ transition-timing-function: var(--x-control-select-picker-transition-timing-function, var(--ease-in-out));
27
+ transition-behavior: allow-discrete;
28
+ will-change: var(--x-control-select-picker-will-change, transform, opacity);
29
+ opacity: var(--x-control-select-picker-closed-opacity, 0);
30
+ transform: var(--x-control-select-picker-closed-transform, scale(0.9));
31
+ display: flex;
32
+ flex-direction: column;
33
+ cursor: auto;
34
+ transform-origin: top center;
35
+ scrollbar-width: thin;
10
36
  grid-area: x-control;
11
- will-change: transform;
12
- border-radius: inherit;
13
37
  position: absolute;
14
- background-color: var(--color-body-primary);
15
38
  z-index: var(--z-index-10);
16
39
  inset-inline: 0;
17
40
  top: 100%;
18
- margin-block-start: 0.5rem;
19
- border: 1px solid color-mix(in srgb, currentcolor 10%, transparent);
20
- transform: scaleY(0.75);
21
- opacity: 0;
22
- transition-property: var(--default-transition-property);
23
- transition-timing-function: var(--ease-in-out);
24
- transition-duration: var(--default-transition-duration);
25
41
  backface-visibility: hidden;
26
- transform-origin: center top;
27
42
  user-select: none;
28
43
  max-height: 12rem;
29
44
  overflow-y: auto;
30
- box-shadow: 0 0.15em 1.5em 0 color-mix(in srgb, var(--color-dark) 5%, transparent), 0 0 1em 0 color-mix(in srgb, var(--color-dark) 5%, transparent);
31
- padding: 0.375rem;
32
- color: currentcolor;
33
- cursor: default;
34
45
  visibility: hidden;
35
46
 
36
47
  & [data-option] {
37
- padding: calc(var(--x-control-padding-inline) / 1.5) var(--x-control-padding-inline);
48
+ padding-block: var(--x-control-select-option-padding-block);
49
+ padding-inline: var(--x-control-select-option-padding-inline);
50
+ font-size: var(--x-control-select-option-font-size);
51
+ font-weight: var(--x-control-select-option-font-weight);
52
+ line-height: var(--x-control-select-option-line-height);
53
+ border-radius: var(--x-control-select-option-border-radius);
54
+ transition: var(--transition-background), var(--transition-color);
38
55
  cursor: pointer;
39
- transition: var(--transition-background);
40
- font-size: var(--x-control-font-size);
41
- border-radius: inherit;
42
56
 
43
57
  &[data-disabled] {
44
58
  opacity: 0.5;
45
59
  pointer-events: none;
46
60
  }
47
61
 
48
- &:is(:hover, :focus) {
49
- background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
62
+ &[data-active] {
63
+ color: var(--x-control-select-option-checked-color, var(--color-accent));
64
+ background-color:
65
+ color-mix(
66
+ in var(--x-control-select-option-checked-background-color-space, srgb),
67
+ var(--x-control-select-option-checked-background-color, var(--color-accent)) var(--x-control-select-option-checked-background-color-opacity, 10%),
68
+ var(--x-control-select-option-checked-background-color-mix, transparent)
69
+ );
70
+ }
71
+
72
+ &:hover {
73
+ background-color: var(--x-control-select-option-hocus-background-color);
50
74
  }
51
75
  }
52
76
  }
53
77
 
54
- &:focus-within select ~ div[aria-hidden] {
55
- opacity: 1;
56
- transform: none;
57
- visibility: visible;
78
+ &:focus-within:not(:has(:focus-visible)) {
79
+ &::after {
80
+ transform: var(--x-control-select-open-icon-transform, rotate(180deg));
81
+ }
82
+
83
+ select ~ div[aria-hidden] {
84
+ opacity: 1;
85
+ transform: none;
86
+ visibility: visible;
87
+ }
58
88
  }
59
- }
89
+ }
@@ -2,24 +2,27 @@ import { Controller } from '@hotwired/stimulus'
2
2
  import { dataset, dispatchCustomEvent } from '@newlogic-digital/utils-js'
3
3
 
4
4
  export class ControlSelect extends Controller {
5
- connect() {
6
- this.select = this.element.querySelector('select')
7
- const option = this.element.querySelectorAll('[data-option]')
5
+ connect() {
6
+ this.select = this.element.querySelector('select')
7
+ this.options = this.element.querySelectorAll('[data-option]')
8
8
 
9
- if (option[0]) {
10
- option.forEach((option) => {
11
- if (option.dataset.disabled) {
12
- return
13
- }
9
+ dataset(this.select, 'action').add('change->x-control-select#active')
14
10
 
15
- dataset(option, 'action').add('click->x-control-select#choose', 'keydown.enter->x-control-select#choose')
16
- })
17
- }
18
- }
11
+ this.options.forEach((option) => {
12
+ if (option.dataset.disabled) return
19
13
 
20
- choose({ currentTarget }) {
21
- this.select.value = currentTarget.dataset.option
22
- dispatchCustomEvent(this.select)
23
- document.activeElement.blur()
24
- }
14
+ dataset(option, 'action').add('click->x-control-select#choose')
15
+ })
16
+ }
17
+
18
+ choose({ currentTarget }) {
19
+ this.select.value = currentTarget.dataset.option
20
+ dispatchCustomEvent(this.select)
21
+ document.activeElement.blur()
22
+ }
23
+
24
+ active() {
25
+ this.options.forEach(option => option.removeAttribute('data-active'))
26
+ this.element.querySelector(`[data-option="${this.select.value}"]`).setAttribute('data-active', '')
27
+ }
25
28
  }
@@ -2,83 +2,84 @@ import { Controller } from '@hotwired/stimulus'
2
2
  import { setCookieConsent, initCookieConsent } from '@newlogic-digital/cookieconsent-js'
3
3
 
4
4
  export class CookieConsentCommon extends Controller {
5
- cookieConsentItemKey = 'cookieconsent-js'
6
- cookieConsentExpireItemKey = 'cookieconsent-js-expire'
5
+ cookieConsentItemKey = 'cookieconsent-js'
6
+ cookieConsentExpireItemKey = 'cookieconsent-js-expire'
7
7
 
8
- getCookieConsentItem() {
9
- return localStorage.getItem(this.cookieConsentItemKey)
10
- }
8
+ getCookieConsentItem() {
9
+ return localStorage.getItem(this.cookieConsentItemKey)
10
+ }
11
11
 
12
- getCookieConsentExpireItem() {
13
- return localStorage.getItem(this.cookieConsentExpireItemKey)
14
- }
12
+ getCookieConsentExpireItem() {
13
+ return localStorage.getItem(this.cookieConsentExpireItemKey)
14
+ }
15
15
  }
16
16
 
17
17
  export class CookieConsentDialog extends CookieConsentCommon {
18
- async connect() {
19
- initCookieConsent(document, this.getCookieConsentItem() ?? [])
20
-
21
- if (document.querySelector('.x-cookieconsent-form')) {
22
- return
23
- }
24
-
25
- if (!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now()) {
26
- setTimeout(async () => {
27
- const { showDialog } = await import('winduum/src/components/dialog/index.js')
28
-
29
- await showDialog(this.element, { closable: false })
30
- }, 1500)
31
- } else {
32
- this.element.remove()
33
- }
34
- }
18
+ async connect() {
19
+ initCookieConsent(document, this.getCookieConsentItem() ?? [])
35
20
 
36
- async approve() {
37
- await this.hide(['performance', 'marketing'])
21
+ if (document.querySelector('.x-cookieconsent-form')) {
22
+ return
38
23
  }
39
24
 
40
- async decline() {
41
- await this.hide([])
42
- }
43
-
44
- async hide(type) {
45
- const { closeDialog } = await import('winduum/src/components/dialog/index.js')
25
+ if (!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now()) {
26
+ setTimeout(async () => {
27
+ const { showDialog } = await import('winduum/src/components/dialog/index.js')
46
28
 
47
- await setCookieConsent(type)
48
- initCookieConsent(document, type)
49
- await closeDialog(this.element, { remove: true })
29
+ await showDialog(this.element, { closable: false })
30
+ }, 1500)
50
31
  }
51
- }
52
-
53
- export class CookieConsentForm extends CookieConsentCommon {
54
- connect() {
55
- document.querySelector('.x-cookieconsent-dialog')?.close()
56
-
57
- this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
58
- input.checked = false
59
- })
60
-
61
- JSON.parse(this.getCookieConsentItem())?.forEach((type) => {
62
- if (this.element.querySelector(`input[value="${type}"]`) !== null) {
63
- this.element.querySelector(`input[value="${type}"]`).checked = true
64
- }
65
- })
32
+ else {
33
+ this.element.remove()
66
34
  }
35
+ }
67
36
 
68
- async update() {
69
- const type = []
37
+ async approve() {
38
+ await this.hide(['performance', 'marketing'])
39
+ }
70
40
 
71
- this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
72
- input.checked && type.push(input.value)
73
- })
41
+ async decline() {
42
+ await this.hide([])
43
+ }
74
44
 
75
- await setCookieConsent(type)
76
- location.reload()
77
- }
45
+ async hide(type) {
46
+ const { closeDialog } = await import('winduum/src/components/dialog/index.js')
78
47
 
79
- disconnect() {
80
- if ((!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now())) {
81
- document.querySelector('.x-cookieconsent-dialog')?.showModal()
82
- }
48
+ await setCookieConsent(type)
49
+ initCookieConsent(document, type)
50
+ await closeDialog(this.element, { remove: true })
51
+ }
52
+ }
53
+
54
+ export class CookieConsentForm extends CookieConsentCommon {
55
+ connect() {
56
+ document.querySelector('.x-cookieconsent-dialog')?.close()
57
+
58
+ this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
59
+ input.checked = false
60
+ })
61
+
62
+ JSON.parse(this.getCookieConsentItem())?.forEach((type) => {
63
+ if (this.element.querySelector(`input[value="${type}"]`) !== null) {
64
+ this.element.querySelector(`input[value="${type}"]`).checked = true
65
+ }
66
+ })
67
+ }
68
+
69
+ async update() {
70
+ const type = []
71
+
72
+ this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
73
+ input.checked && type.push(input.value)
74
+ })
75
+
76
+ await setCookieConsent(type)
77
+ location.reload()
78
+ }
79
+
80
+ disconnect() {
81
+ if ((!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now())) {
82
+ document.querySelector('.x-cookieconsent-dialog')?.showModal()
83
83
  }
84
+ }
84
85
  }
@@ -0,0 +1,49 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+ import { getId } from '@newlogic-digital/utils-js'
3
+
4
+ export class GoogleMaps extends Controller {
5
+ static targets = ['map']
6
+
7
+ static values = {
8
+ options: Object,
9
+ key: String,
10
+ }
11
+
12
+ markerContent = `<svg class="size-16 text-accent"><use href="#heroicons-solid/map-pin"></use></svg>`
13
+
14
+ async connect() {
15
+ const { setOptions, importLibrary } = await import('@googlemaps/js-api-loader')
16
+
17
+ setOptions({
18
+ key: this.keyValue,
19
+ })
20
+
21
+ const { Map } = await importLibrary('maps')
22
+
23
+ this.map = new Map(this.mapTarget, {
24
+ zoom: 13,
25
+ mapId: getId(),
26
+ mapTypeControl: false,
27
+ streetViewControl: false,
28
+ ...this.optionsValue,
29
+ })
30
+
31
+ this.dispatch('connect')
32
+ }
33
+
34
+ async renderMarker() {
35
+ if (this.optionsValue.center?.lat == null || this.optionsValue.center?.lng == null) {
36
+ return
37
+ }
38
+
39
+ const { importLibrary } = await import('@googlemaps/js-api-loader')
40
+ const { AdvancedMarkerElement } = await importLibrary('marker')
41
+ const content = new DOMParser().parseFromString(this.markerContent, 'text/html').body.firstChild
42
+
43
+ this.marker = new AdvancedMarkerElement({
44
+ map: this.map,
45
+ position: this.optionsValue.center,
46
+ content,
47
+ })
48
+ }
49
+ }
package/src/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ControlSelect } from './control-select/index.js'
2
2
  import { CookieConsentDialog, CookieConsentForm } from './cookieconsent/index.js'
3
+ import { GoogleMaps } from './google-maps/index.js'
3
4
  import { Popover } from './popover/index.js'
4
5
  import { ReCaptcha } from './recaptcha/index.js'
5
6
  import { Reveal } from './reveal/index.js'
6
7
 
7
- export { ControlSelect, CookieConsentDialog, CookieConsentForm, Popover, ReCaptcha, Reveal }
8
+ export { ControlSelect, CookieConsentDialog, CookieConsentForm, GoogleMaps, Popover, ReCaptcha, Reveal }
@@ -2,23 +2,24 @@ import { Popover as PopoverController } from 'winduum-stimulus/components/popove
2
2
  import { animationsFinished } from 'winduum/src/common.js'
3
3
 
4
4
  export class Popover extends PopoverController {
5
- static targets = ['content', 'autocomplete']
5
+ static targets = ['content', 'autocomplete']
6
6
 
7
- minAutocompleteLength = 2
7
+ minAutocompleteLength = 2
8
8
 
9
- async autocomplete({ currentTarget }) {
10
- if (currentTarget.value.length < this.minAutocompleteLength) {
11
- currentTarget.ariaExpanded = 'false'
12
- await animationsFinished(this.contentTarget)
13
- this.contentTarget.replaceChildren()
14
- } else {
15
- currentTarget.ariaExpanded = 'true'
16
- }
9
+ async autocomplete({ currentTarget }) {
10
+ if (currentTarget.value.length < this.minAutocompleteLength) {
11
+ currentTarget.ariaExpanded = 'false'
12
+ await animationsFinished(this.contentTarget)
13
+ this.contentTarget.replaceChildren()
17
14
  }
18
-
19
- selectDescendant({ currentTarget }) {
20
- this.autocompleteTarget.setAttribute('aria-activedescendant', currentTarget.id)
21
- this.autocompleteTarget.value = currentTarget.textContent.trim()
22
- currentTarget.blur()
15
+ else {
16
+ currentTarget.ariaExpanded = 'true'
23
17
  }
18
+ }
19
+
20
+ selectDescendant({ currentTarget }) {
21
+ this.autocompleteTarget.setAttribute('aria-activedescendant', currentTarget.id)
22
+ this.autocompleteTarget.value = currentTarget.textContent.trim()
23
+ currentTarget.blur()
24
+ }
24
25
  }
@@ -2,24 +2,24 @@ import { Controller } from '@hotwired/stimulus'
2
2
  import { importScript } from '@newlogic-digital/utils-js'
3
3
 
4
4
  export class ReCaptcha extends Controller {
5
- static values = {
6
- api: String,
7
- action: String,
8
- url: {
9
- default: 'https://www.google.com/recaptcha/enterprise.js?render={apikey}'
10
- }
11
- }
5
+ static values = {
6
+ api: String,
7
+ action: String,
8
+ url: {
9
+ default: 'https://www.google.com/recaptcha/enterprise.js?render={apikey}',
10
+ },
11
+ }
12
12
 
13
- connect() {
14
- importScript(this.urlValue.replace('{apikey}', this.apiValue))
15
- }
13
+ connect() {
14
+ importScript(this.urlValue.replace('{apikey}', this.apiValue))
15
+ }
16
16
 
17
- execute(event) {
18
- if (event?.detail?.recaptchaExecuted) return
17
+ execute(event) {
18
+ if (event?.detail?.recaptchaExecuted) return
19
19
 
20
- window.grecaptcha.enterprise.ready(async () => {
21
- this.element.gtoken.value = await window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' })
22
- this.element.dispatchEvent(new CustomEvent('submit', { cancelable: true, detail: { recaptchaExecuted: true } }))
23
- })
24
- }
20
+ window.grecaptcha.enterprise.ready(async () => {
21
+ this.element.gtoken.value = await window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' })
22
+ this.element.dispatchEvent(new CustomEvent('submit', { cancelable: true, detail: { recaptchaExecuted: true } }))
23
+ })
24
+ }
25
25
  }
@@ -2,31 +2,31 @@ import { Controller } from '@hotwired/stimulus'
2
2
  import { dataset } from '@newlogic-digital/utils-js'
3
3
 
4
4
  export class Reveal extends Controller {
5
- static targets = ['item']
5
+ static targets = ['item']
6
6
 
7
- intersectionObserver() {
8
- this.observer = new IntersectionObserver((entries) => {
9
- entries.forEach((entry) => {
10
- if (entry.intersectionRatio > 0.1 && !entry.target.hasAttribute('data-in')) {
11
- entry.target.setAttribute('data-in', '')
7
+ intersectionObserver() {
8
+ this.observer = new IntersectionObserver((entries) => {
9
+ entries.forEach((entry) => {
10
+ if (entry.intersectionRatio > 0.1 && !entry.target.hasAttribute('data-in')) {
11
+ entry.target.setAttribute('data-in', '')
12
12
 
13
- if (entry.target.dataset.lazyController) {
14
- dataset(entry.target, 'controller').add(entry.target.dataset.lazyController)
15
- }
16
- }
17
- })
18
- }, {
19
- threshold: 0.1
20
- })
21
- }
13
+ if (entry.target.dataset.lazyController) {
14
+ dataset(entry.target, 'controller').add(entry.target.dataset.lazyController)
15
+ }
16
+ }
17
+ })
18
+ }, {
19
+ threshold: 0.1,
20
+ })
21
+ }
22
22
 
23
- itemTargetConnected(element) {
24
- if (!this.observer) this.intersectionObserver()
23
+ itemTargetConnected(element) {
24
+ if (!this.observer) this.intersectionObserver()
25
25
 
26
- this.observer?.observe(element)
27
- }
26
+ this.observer?.observe(element)
27
+ }
28
28
 
29
- itemTargetDisconnected(element) {
30
- this.observer?.unobserve(element)
31
- }
29
+ itemTargetDisconnected(element) {
30
+ this.observer?.unobserve(element)
31
+ }
32
32
  }