css-zero 0.0.44 → 0.0.45

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec1e04072b39a7556be9b33bc9c9736689f9463cdd1acc56076727394035a6b6
4
- data.tar.gz: 54997d4c8310db5f9366cac4f51bb3db65fac4616e5336779180e8ce2ae5b5d2
3
+ metadata.gz: fd059d67d4f761e329571d4e4eefac0325a6cf14224717ed3581a7ffe7acaf0e
4
+ data.tar.gz: 13afe2beaba626b1925504904160f01ab1c5589eb87d3bbe2baa9009c3e04cc2
5
5
  SHA512:
6
- metadata.gz: 480ea51dad6b42f1fd414823868aee05cb709a44038d243d931a079d037f60b477612cd289b7ee5da55ae0f635db3cbf747f0506a73cd7b8c34f89afce2f2955
7
- data.tar.gz: c48c5b925f47966e8b67f3a25582e6980b70cc02f7cc3c5d89f30ac1c1262611795a2f20d18b5faead4b3a3d25980f02759bfda555287fd42ca16c179788e654
6
+ metadata.gz: 5bfb100356389b839542aa74775abce26f05fc0f8816df589fabb91af96892b28fac6fe2179bb8aa11476595ae7457ce0a33b9faef7b91d771151ef2100f581b
7
+ data.tar.gz: 340f487beff85601804945afe83121df0c2ac1cf42ddd8fa80261a746754f788e8a31f2264b159de654745a7ee56dfa8b89e37175bdcbcdd5d9ca37aa32ae436
data/README.md CHANGED
@@ -19,7 +19,8 @@ bin/rails generate css_zero:install
19
19
  Add only the components you need. (Optional)
20
20
 
21
21
  ```
22
- bin/rails generate css_zero:add accordion alert avatar badge breadcrumb button card carousel check_all command collapsible dialog flash fullscreen hotkey input input_concerns layouts lightbox local_time pagination progress prose sheet skeleton switch table tabs upload_preview toggle web_share
22
+ bin/rails generate css_zero:add --help
23
+ bin/rails generate css_zero:add layouts flash button input switch table ...
23
24
  ```
24
25
 
25
26
  ### Requirements
@@ -1,3 +1,3 @@
1
1
  module CssZero
2
- VERSION = "0.0.44"
2
+ VERSION = "0.0.45"
3
3
  end
@@ -2,7 +2,7 @@ Description:
2
2
  This will add components into your project.
3
3
 
4
4
  Components:
5
- accordion alert avatar badge breadcrumb button card carousel check_call command collapsible dialog flash fullscreen hotkey input input_concerns layouts lightbox local_time pagination progress prose sheet skeleton switch table tabs upload_preview toggle web_share
5
+ accordion alert avatar badge breadcrumb button card carousel check_all command collapsible dialog dropdown flash fullscreen hotkey input input_concerns layouts lightbox local_time pagination progress prose sheet skeleton switch table tabs upload_preview toggle web_share
6
6
 
7
7
  Example:
8
8
  bin/rails generate css_zero:add [components...]
@@ -32,6 +32,11 @@ dialog:
32
32
  - app/assets/stylesheets/dialog.css
33
33
  - app/javascript/controllers/dialog_controller.js
34
34
  - app/assets/images/x.svg
35
+ dropdown:
36
+ - app/assets/stylesheets/popover.css
37
+ - app/javascript/controllers/popover_controller.js
38
+ - app/assets/stylesheets/menu.css
39
+ - app/javascript/controllers/menu_controller.js
35
40
  flash:
36
41
  - app/assets/stylesheets/flash.css
37
42
  - app/javascript/controllers/element_removal_controller.js
@@ -68,6 +73,9 @@ pagination:
68
73
  - app/assets/images/chevron-right.svg
69
74
  - app/assets/images/chevron-left.svg
70
75
  - app/assets/images/ellipsis.svg
76
+ popover:
77
+ - app/assets/stylesheets/popover.css
78
+ - app/javascript/controllers/popover_controller.js
71
79
  progress:
72
80
  - app/assets/stylesheets/progress.css
73
81
  prose:
@@ -1,12 +1,12 @@
1
1
  .dialog {
2
2
  background-color: var(--color-bg);
3
- border-width: var(--border);
4
3
  border-radius: var(--rounded-lg);
4
+ border-width: var(--border);
5
5
  box-shadow: var(--shadow-lg);
6
6
  color: var(--color-text);
7
7
  inline-size: var(--size-full);
8
8
  margin: auto;
9
- max-inline-size: var(--dialog-width, var(--max-i-lg));
9
+ max-inline-size: var(--max-i-lg);
10
10
 
11
11
  &::backdrop {
12
12
  background-color: rgba(0, 0, 0, .8);
@@ -0,0 +1,39 @@
1
+ .menu {
2
+ display: flex;
3
+ flex-direction: column;
4
+ padding: var(--size-1);
5
+ gap: var(--size-1);
6
+ }
7
+
8
+ .menu__header {
9
+ font-size: var(--text-xs);
10
+ font-weight: var(--font-semibold);
11
+ padding: var(--size-1_5) var(--size-2);
12
+ }
13
+
14
+ .menu__group {
15
+ display: flex;
16
+ flex-direction: column;
17
+ }
18
+
19
+ .menu__separator {
20
+ margin-inline: -0.25rem;
21
+ }
22
+
23
+ .menu__item {
24
+ --btn-border-color: transparent;
25
+ --btn-font-weight: var(--font-normal);
26
+ --btn-justify-content: start;
27
+ --btn-outline-size: 0;
28
+ --btn-padding: var(--size-1_5) var(--size-2);
29
+
30
+ .menu:not(:hover) &:focus {
31
+ --btn-background: var(--color-secondary);
32
+ }
33
+ }
34
+
35
+ .menu__item-key {
36
+ color: var(--color-text-subtle);
37
+ font-size: var(--text-xs);
38
+ margin-inline-start: auto;
39
+ }
@@ -0,0 +1,41 @@
1
+ .popover {
2
+ background-color: var(--color-bg);
3
+ border-radius: var(--rounded-md);
4
+ border-width: var(--border);
5
+ box-shadow: var(--shadow-md);
6
+ color: var(--color-text);
7
+ margin-block: var(--size-1);
8
+ inline-size: var(--popover-size, max-content);
9
+ inset-inline-start: var(--popover-position, 0);
10
+
11
+ /* Setup animation */
12
+ opacity: 0;
13
+ transform: var(--scale-95);
14
+ transition-behavior: allow-discrete;
15
+ transition-duration: var(--time-150);
16
+ transition-property: display, overlay, opacity, transform;
17
+
18
+ /* In animation */
19
+ &[open] {
20
+ opacity: 1; transform: var(--scale-100);
21
+ }
22
+
23
+ /* Out animation */
24
+ @starting-style {
25
+ &[open] {
26
+ opacity: 0; transform: var(--scale-95);
27
+ }
28
+ }
29
+ }
30
+
31
+ .popover--flip {
32
+ inset-block-end: 100%;
33
+ }
34
+
35
+ .popover--start {
36
+ --popover-position: 0;
37
+ }
38
+
39
+ .popover--end {
40
+ --popover-position: auto;
41
+ }
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  connect() {
5
- if (this.autoselect) this.element.select()
5
+ this.autoselect && this.element.select()
6
6
  }
7
7
 
8
8
  get autoselect() {
@@ -3,10 +3,6 @@ import { Controller } from "@hotwired/stimulus"
3
3
  export default class extends Controller {
4
4
  static targets = [ "menu" ]
5
5
 
6
- show() {
7
- this.menuTarget.show()
8
- }
9
-
10
6
  showModal() {
11
7
  this.menuTarget.showModal()
12
8
  }
@@ -16,6 +12,6 @@ export default class extends Controller {
16
12
  }
17
13
 
18
14
  closeOnClickOutside({ target }) {
19
- if (target.nodeName === "DIALOG") this.close()
15
+ target.nodeName === "DIALOG" && this.close()
20
16
  }
21
17
  }
@@ -4,7 +4,7 @@ export default class extends Controller {
4
4
  static targets = [ "button" ]
5
5
 
6
6
  connect() {
7
- if (this.hasButtonTarget) this.#hideButtonIfNotSupported()
7
+ this.hasButtonTarget && this.#hideButtonIfNotSupported()
8
8
  }
9
9
 
10
10
  toggle() {
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  click(event) {
5
- if (this.#isClickable && !this.#shouldIgnore(event)) this.element.click()
5
+ this.#isClickable && !this.#shouldIgnore(event) && this.element.click()
6
6
  }
7
7
 
8
8
  #shouldIgnore(event) {
@@ -0,0 +1,36 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = [ "item" ]
5
+ static values = { index: Number }
6
+
7
+ indexValueChanged() {
8
+ this.#removeTabstops()
9
+ this.#focusCurrentItem()
10
+ }
11
+
12
+ prev() {
13
+ this.indexValue > 0 && this.indexValue--
14
+ }
15
+
16
+ next() {
17
+ this.indexValue < this.#lastIndex && this.indexValue++
18
+ }
19
+
20
+ reset() {
21
+ this.indexValue = 0
22
+ }
23
+
24
+ #removeTabstops() {
25
+ this.itemTargets.forEach(item => item.tabIndex = -1)
26
+ }
27
+
28
+ #focusCurrentItem() {
29
+ this.itemTargets[this.indexValue].tabIndex = 0
30
+ this.itemTargets[this.indexValue].focus()
31
+ }
32
+
33
+ get #lastIndex() {
34
+ return this.itemTargets.length -1
35
+ }
36
+ }
@@ -0,0 +1,54 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ const BOTTOM_THRESHOLD = 0
4
+
5
+ export default class extends Controller {
6
+ static targets = [ "button", "menu" ]
7
+ static classes = [ "flip" ]
8
+
9
+ #closeTimer
10
+
11
+ show() {
12
+ this.#resetTimer()
13
+ this.menuTarget.show()
14
+ this.#updateExpanded()
15
+ this.#orient()
16
+ }
17
+
18
+ close() {
19
+ this.menuTarget.close()
20
+ this.#updateExpanded()
21
+ }
22
+
23
+ closeLater() {
24
+ this.#closeTimer = setTimeout(() => this.close(), 300)
25
+ }
26
+
27
+ toggle() {
28
+ this.menuTarget.open ? this.close() : this.show()
29
+ }
30
+
31
+ closeOnClickOutside({ target }) {
32
+ !this.element.contains(target) && this.close()
33
+ }
34
+
35
+ #resetTimer() {
36
+ clearTimeout(this.#closeTimer)
37
+ }
38
+
39
+ #orient() {
40
+ this.menuTarget.classList.toggle(this.flipClass, this.#distanceToBottom < BOTTOM_THRESHOLD)
41
+ }
42
+
43
+ #updateExpanded() {
44
+ this.buttonTarget.ariaExpanded = this.menuTarget.open
45
+ }
46
+
47
+ get #distanceToBottom() {
48
+ return window.innerHeight - this.#boundingClientRect.bottom
49
+ }
50
+
51
+ get #boundingClientRect() {
52
+ return this.menuTarget.getBoundingClientRect()
53
+ }
54
+ }
@@ -4,32 +4,38 @@ export default class extends Controller {
4
4
  static targets = [ "button", "tab" ]
5
5
  static values = { index: Number }
6
6
 
7
- indexValueChanged() {
8
- this.#showSelectedTab()
7
+ indexValueChanged(index, previousIndex) {
8
+ this.#showCurrentTab()
9
+ this.#focusCurrentButton(previousIndex !== undefined)
9
10
  }
10
11
 
11
- select({ params }) {
12
- this.indexValue = params.index
12
+ select({ target }) {
13
+ this.indexValue = this.buttonTargets.indexOf(target)
13
14
  }
14
15
 
15
16
  prev() {
16
- if (this.indexValue > 0) this.indexValue--
17
+ this.indexValue > 0 && this.indexValue--
17
18
  }
18
19
 
19
20
  next() {
20
- if (this.indexValue < this.#lastIndex) this.indexValue++
21
+ this.indexValue < this.#lastIndex && this.indexValue++
21
22
  }
22
23
 
23
- #showSelectedTab() {
24
- this.buttonTargets.forEach((element, index) => {
25
- element.ariaSelected = index === this.indexValue
24
+ #showCurrentTab() {
25
+ this.buttonTargets.forEach((button, index) => {
26
+ button.ariaSelected = index == this.indexValue
27
+ button.tabIndex = index == this.indexValue ? 0 : -1
26
28
  })
27
29
 
28
- this.tabTargets.forEach((element, index) => {
29
- element.hidden = index !== this.indexValue
30
+ this.tabTargets.forEach((tab, index) => {
31
+ tab.hidden = index !== this.indexValue
30
32
  })
31
33
  }
32
34
 
35
+ #focusCurrentButton(shouldFocus) {
36
+ shouldFocus && this.buttonTargets[this.indexValue].focus()
37
+ }
38
+
33
39
  get #lastIndex() {
34
40
  return this.tabTargets.length -1
35
41
  }
@@ -1,10 +1,10 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
+ const APPLICATION_NAME = "my_application"
4
+
3
5
  export default class extends Controller {
4
6
  static values = { title: String, text: String, url: String, file: String }
5
7
 
6
- #applicationName = 'MyApplication'
7
-
8
8
  connect() {
9
9
  this.element.hidden = !navigator.canShare
10
10
  }
@@ -34,7 +34,7 @@ export default class extends Controller {
34
34
  async #getFileObject() {
35
35
  const response = await fetch(this.fileValue)
36
36
  const blob = await response.blob()
37
- const randomPrefix = `${this.#applicationName}_${Math.random().toString(36).slice(2)}`
37
+ const randomPrefix = `${APPLICATION_NAME}_${Math.random().toString(36).slice(2)}`
38
38
  const fileName = `${randomPrefix}.${blob.type.split('/').pop()}`
39
39
 
40
40
  return new File([ blob ], fileName, { type: blob.type })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lázaro Nixon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-09 00:00:00.000000000 Z
11
+ date: 2024-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: lazaronixon@hotmail.com
@@ -70,6 +70,8 @@ files:
70
70
  - lib/generators/css_zero/add/templates/app/assets/stylesheets/input.css
71
71
  - lib/generators/css_zero/add/templates/app/assets/stylesheets/layouts.css
72
72
  - lib/generators/css_zero/add/templates/app/assets/stylesheets/lightbox.css
73
+ - lib/generators/css_zero/add/templates/app/assets/stylesheets/menu.css
74
+ - lib/generators/css_zero/add/templates/app/assets/stylesheets/popover.css
73
75
  - lib/generators/css_zero/add/templates/app/assets/stylesheets/progress.css
74
76
  - lib/generators/css_zero/add/templates/app/assets/stylesheets/prose.css
75
77
  - lib/generators/css_zero/add/templates/app/assets/stylesheets/sheet.css
@@ -92,6 +94,8 @@ files:
92
94
  - lib/generators/css_zero/add/templates/app/javascript/controllers/hotkey_controller.js
93
95
  - lib/generators/css_zero/add/templates/app/javascript/controllers/lightbox_controller.js
94
96
  - lib/generators/css_zero/add/templates/app/javascript/controllers/local_time_controller.js
97
+ - lib/generators/css_zero/add/templates/app/javascript/controllers/menu_controller.js
98
+ - lib/generators/css_zero/add/templates/app/javascript/controllers/popover_controller.js
95
99
  - lib/generators/css_zero/add/templates/app/javascript/controllers/revealable_input_controller.js
96
100
  - lib/generators/css_zero/add/templates/app/javascript/controllers/tabs_controller.js
97
101
  - lib/generators/css_zero/add/templates/app/javascript/controllers/upload_preview_controller.js