css-zero 0.0.43 → 0.0.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/lib/css_zero/version.rb +1 -1
  4. data/lib/generators/css_zero/add/USAGE +1 -1
  5. data/lib/generators/css_zero/add/resources.yml +8 -0
  6. data/lib/generators/css_zero/add/templates/app/assets/stylesheets/dialog.css +2 -2
  7. data/lib/generators/css_zero/add/templates/app/assets/stylesheets/flash.css +10 -2
  8. data/lib/generators/css_zero/add/templates/app/assets/stylesheets/input.css +1 -1
  9. data/lib/generators/css_zero/add/templates/app/assets/stylesheets/menu.css +39 -0
  10. data/lib/generators/css_zero/add/templates/app/assets/stylesheets/popover.css +41 -0
  11. data/lib/generators/css_zero/add/templates/app/javascript/controllers/autoselect_controller.js +1 -1
  12. data/lib/generators/css_zero/add/templates/app/javascript/controllers/dialog_controller.js +1 -5
  13. data/lib/generators/css_zero/add/templates/app/javascript/controllers/filter_controller.js +13 -13
  14. data/lib/generators/css_zero/add/templates/app/javascript/controllers/fullscreen_controller.js +1 -1
  15. data/lib/generators/css_zero/add/templates/app/javascript/controllers/hotkey_controller.js +1 -1
  16. data/lib/generators/css_zero/add/templates/app/javascript/controllers/menu_controller.js +36 -0
  17. data/lib/generators/css_zero/add/templates/app/javascript/controllers/popover_controller.js +54 -0
  18. data/lib/generators/css_zero/add/templates/app/javascript/controllers/tabs_controller.js +16 -10
  19. data/lib/generators/css_zero/add/templates/app/javascript/controllers/web_share_controller.js +3 -3
  20. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ced95bc29890a4882d0c31a40d2b109ac5c118f6fce4e7663e48d710b8d54a50
4
- data.tar.gz: 62f21e06f144267737c578db2942dddbfd46d36f30a4c3e78b85ceea550408f6
3
+ metadata.gz: fd059d67d4f761e329571d4e4eefac0325a6cf14224717ed3581a7ffe7acaf0e
4
+ data.tar.gz: 13afe2beaba626b1925504904160f01ab1c5589eb87d3bbe2baa9009c3e04cc2
5
5
  SHA512:
6
- metadata.gz: 1e2c45036d2d68f17ac5a064cb7c84acb9d6870e375c35afd7c03dbf9c6b8e4c0931db0ba9ce6d77e2ef699f199cc854a589f856033f419f183909da22c1b4ca
7
- data.tar.gz: f33fc4eb0c24ab0fca8c8ac37155f0378c93cb11e0ad34c748cde9ee94204cf3a7f218d245a783126d8da412b852306c1b5905d910be924fee33daa135c3b51f
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
@@ -89,7 +90,7 @@ Check the [CSS files](app/assets/stylesheets) in the repository to see the avail
89
90
 
90
91
  ## Components
91
92
 
92
- [<img src="https://github.com/user-attachments/assets/989b0ddd-064a-4ac6-8aee-f9eaaf07ff38">](https://css-zero-showcase.onrender.com/lookbook)
93
+ [<img src="https://github.com/user-attachments/assets/989b0ddd-064a-4ac6-8aee-f9eaaf07ff38">](https://csszero.lazaronixon.com)
93
94
 
94
95
  More components soon...
95
96
 
@@ -1,3 +1,3 @@
1
1
  module CssZero
2
- VERSION = "0.0.43"
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);
@@ -6,14 +6,12 @@
6
6
  color: var(--color-text-reversed);
7
7
  display: flex;
8
8
  gap: var(--size-2);
9
- inset: 0;
10
9
  justify-content: center;
11
10
  line-height: var(--leading-none);
12
11
  margin-block-start: var(--flash-position, 0);
13
12
  margin-inline: auto;
14
13
  min-block-size: var(--size-11);
15
14
  padding: var(--size-1) var(--size-4);
16
- position: fixed;
17
15
  text-align: center;
18
16
 
19
17
  @media (width >= 40rem) {
@@ -25,7 +23,17 @@
25
23
  }
26
24
  }
27
25
 
26
+ .flash--extended {
27
+ animation-name: appear-then-fade-extended;
28
+ animation-duration: 12s;
29
+ }
30
+
28
31
  @keyframes appear-then-fade {
29
32
  0%, 100% { opacity: 0; }
30
33
  5%, 60% { opacity: 1; }
31
34
  }
35
+
36
+ @keyframes appear-then-fade-extended {
37
+ 0%, 100% { opacity: 0; }
38
+ 2%, 90% { opacity: 1; }
39
+ }
@@ -63,7 +63,7 @@
63
63
  /* Checkbox, radio, and range */
64
64
  .checkbox, .radio {
65
65
  accent-color: var(--color-primary);
66
- transform: scale(1.15);
66
+ block-size: 18px; inline-size: 18px;
67
67
  }
68
68
 
69
69
  .range {
@@ -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
  }
@@ -9,23 +9,21 @@ export default class extends Controller {
9
9
  this.filter = debounce(this.filter.bind(this), 300)
10
10
  }
11
11
 
12
- filter(event) {
12
+ filter({ target }) {
13
13
  this.#reset()
14
14
 
15
- if (event.target.value != "") {
16
- this.#selectMatches(event.target.value)
15
+ if (target.value != "") {
16
+ this.#selectMatches(target.value)
17
17
  this.#activate()
18
18
  } else {
19
19
  this.#deactivate()
20
20
  }
21
21
  }
22
22
 
23
- #activate() {
24
- this.listTarget.classList.add(this.activeClass)
25
- }
26
-
27
- #deactivate() {
28
- this.listTarget.classList.remove(this.activeClass)
23
+ #reset() {
24
+ this.listTarget.querySelectorAll(`.${this.selectedClass}`).forEach((element) => {
25
+ element.classList.remove(this.selectedClass)
26
+ })
29
27
  }
30
28
 
31
29
  #selectMatches(value) {
@@ -34,9 +32,11 @@ export default class extends Controller {
34
32
  })
35
33
  }
36
34
 
37
- #reset() {
38
- this.listTarget.querySelectorAll(`.${this.selectedClass}`).forEach((element) => {
39
- element.classList.remove(this.selectedClass)
40
- })
35
+ #activate() {
36
+ this.listTarget.classList.add(this.activeClass)
37
+ }
38
+
39
+ #deactivate() {
40
+ this.listTarget.classList.remove(this.activeClass)
41
41
  }
42
42
  }
@@ -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
12
  select({ target }) {
12
- this.indexValue = target.dataset.index
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.43
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-04 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