uistiti 0.1.5 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -1
  3. data/app/assets/javascript/controllers/uistiti/alpha/toggle_controller.js +39 -0
  4. data/app/assets/stylesheets/uistiti/components/alpha/toggle.scss +61 -0
  5. data/app/assets/stylesheets/uistiti/config/_variables.scss +7 -3
  6. data/app/assets/stylesheets/uistiti/uistiti.scss +1 -0
  7. data/app/components/previews/uistiti/alpha/button_preview.rb +17 -0
  8. data/app/components/previews/uistiti/alpha/image_preview.rb +27 -1
  9. data/app/components/previews/uistiti/alpha/toggle_preview.rb +21 -0
  10. data/app/components/uistiti/alpha/toggle.html.erb +4 -0
  11. data/app/components/uistiti/alpha/toggle.rb +41 -0
  12. data/app/controllers/uistiti/lookbook/dummy_controller.rb +19 -0
  13. data/app/views/layouts/uistiti/component_preview.html.erb +1 -5
  14. data/config/routes.rb +5 -0
  15. data/lib/generators/uistiti/component_generator.rb +1 -1
  16. data/lib/uistiti/version.rb +1 -1
  17. metadata +17 -11
  18. /data/app/assets/javascript/controllers/uistiti/alpha/{button/button_controller.js → button_controller.js} +0 -0
  19. /data/app/assets/javascript/controllers/uistiti/alpha/{container/container_controller.js → container_controller.js} +0 -0
  20. /data/app/assets/javascript/controllers/uistiti/alpha/{flex/flex_controller.js → flex_controller.js} +0 -0
  21. /data/app/assets/javascript/controllers/uistiti/alpha/{form_input_group/form_input_group_controller.js → form_input_group_controller.js} +0 -0
  22. /data/app/assets/javascript/controllers/uistiti/alpha/{form_submit/form_submit_controller.js → form_submit_controller.js} +0 -0
  23. /data/app/assets/javascript/controllers/uistiti/alpha/{image/image_controller.js → image_controller.js} +0 -0
  24. /data/app/assets/javascript/controllers/uistiti/alpha/{link/link_controller.js → link_controller.js} +0 -0
  25. /data/app/assets/javascript/controllers/uistiti/alpha/{main_layout/main_layout_controller.js → main_layout_controller.js} +0 -0
  26. /data/app/assets/javascript/controllers/uistiti/alpha/{navbar/navbar_controller.js → navbar_controller.js} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa282e7f54a0ba956a174bc5c74070491e1ed823ccc1e99d9029cac31388d352
4
- data.tar.gz: 1d59a8c0c9bfc7f69c2b355223840368be7fb12c4d0b977167c5ba1a3395ba2f
3
+ metadata.gz: b9732c4f34313d6c1ab97d5edb45e533acbf754d9d69341f91885b0396029f44
4
+ data.tar.gz: 4aef700894a086669e3c3d1920760e66ce9d8a0c9aad4865d5fbcd5d60f909d9
5
5
  SHA512:
6
- metadata.gz: ee5656aeff2a4556a6f2bcdab355567aee48d1f8bb4455ce5a15a1d5f8bb16d3ce480e03f59212ab20a2e99f1fbb481a630f14e0cec84c2d94fc77cf295df8d3
7
- data.tar.gz: f9edd14a293228eef3830e364b2e6724ecfb962a8a7dad6119a8b21814366d9b130843a166d7fb2fe7f4e2bbd7fd16f00c4e079ea6fe58ea82c37e96580fac4d
6
+ metadata.gz: eb41fc4c7f26bfd5494bdaf136b06f5fa14a415a981d842ab8e452fccba6c85489f8d9ccf297461d7fea075acf9d5e5817b5101de45f4e41b37b7ac13f328707
7
+ data.tar.gz: d30b99fb9d4ab56822c7f1b1c639ba90ec35c332a852b8ea1a65efaa395e7731e6e0c060d4572698bef43a6a8b110edde547a3b45a0614105b2826707c15a91b
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <img width="1200" alt="Capture d’écran 2023-07-30 à 21 42 11" src="https://github.com/rails-hackathon/team-173/assets/75135824/8e38a2bf-2ae8-4cc0-a99b-d553eb374a34">
2
+
1
3
  # Uistiti UI kit for Rails
2
4
  This gem holds everything you need (UI speaking) to create nice User interface.
3
5
  It comes with CSS style (customisable for sure) and Javascript out of the bout.
@@ -5,6 +7,11 @@ For productivity enhancement i also published a [VsCode extension](https://marke
5
7
 
6
8
  ![uistiti_extension](https://github.com/rails-hackathon/team-173/assets/75135824/afdcacc9-81b7-4ec1-9eb2-69e01a21af12)
7
9
 
10
+ Example of something that have been built very fast with the GEM [demo](https://polished-field-4685.fly.dev/) (The source code is [here](https://github.com/troptropcontent/uistiti-showcase))
11
+
12
+ [LookBook of the different component developped during the Hackathon](https://polished-field-4685.fly.dev/uistiti/lookbook/inspect/uistiti/alpha/button/playground)
13
+
14
+ [Quick video to explain how it work](https://share.vidyard.com/watch/2JSLZidGCBD1UohAUYexEf?)
8
15
 
9
16
  ## Usage
10
17
  How to use the plug in :
@@ -44,9 +51,21 @@ Then, for each component you use you can import the related css
44
51
  @import 'uistiti/components/alpha/flex';
45
52
  ```
46
53
 
47
- For Component with javascript behavior, there is nothing to do, the controllers are automatically registered through the asset pipe line and import-map.
54
+ For Component with javascript behavior, there is no much things to do, the controllers are automatically registered through the asset pipe line and import-map:
48
55
 
56
+ ```javascript
57
+ //app/assets/config/manifest.js
58
+ ...
59
+ //= link uistiti_manifest.js
60
+ ```
61
+
62
+ ```ruby
63
+ #config/importmap.rb
64
+ ...
65
+ pin_all_from Uistiti.stimulus_controllers_directory, under: "controllers/uistiti"
66
+ ```
49
67
 
68
+ and you should be good to go, no npm, nothing more 🥰
50
69
 
51
70
  ## Contributing
52
71
  Contribution directions go here.
@@ -0,0 +1,39 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ // this stimulus controller can be registered with identifier : uistiti--alpha--toggle
4
+ export default class extends Controller {
5
+ static values = {
6
+ url: String,
7
+ model: String,
8
+ field: String,
9
+ }
10
+
11
+ connect() {
12
+ console.log("Hello, from toggle stimulus controller !", this.element);
13
+ }
14
+
15
+ sendPutRequest(event) {
16
+ const input_element = event.target
17
+ const input_changed_to = input_element.checked
18
+ const csrf_token = document.getElementsByName('csrf-token')[0].content
19
+ const data = new FormData()
20
+ data.append( `${this.modelValue}[${this.fieldValue}]`,input_changed_to)
21
+
22
+ const requestOptions = {
23
+ method: 'PUT',
24
+ headers: { 'X-CSRF-Token': csrf_token },
25
+ body: data,
26
+ };
27
+
28
+ console.log({requestOptions})
29
+ const revert_input = () => input_element.checked = !input_changed_to
30
+
31
+ fetch(this.urlValue, requestOptions)
32
+ .then(({status}) => status)
33
+ .then(status => {
34
+ const status_string = status.toString()
35
+ const is_put_request_succesfull = status_string[0] == '2'
36
+ !is_put_request_succesfull && revert_input()
37
+ })
38
+ }
39
+ }
@@ -0,0 +1,61 @@
1
+ /* CSS for Toggle */
2
+ .Toggle {
3
+ &__button {
4
+ box-sizing: border-box;
5
+ display: inline-block;
6
+ width: $size-font-xxxl;
7
+ height: $size-font-xl;
8
+ background-color: $color-background-disabled;
9
+ &--off--disabled {
10
+ background-color: $color-background-disabled;
11
+ };
12
+ &--off--danger {
13
+ background-color: $color-background-error;
14
+ };
15
+ &--off--success {
16
+ background-color: $color-background-success;
17
+ };
18
+ transition: all .4s ease;
19
+ padding: $size-font-xxxxs;
20
+ border-radius: $size-font-xxl;
21
+ &:after,
22
+ &:before {
23
+ position: relative;
24
+ display: block;
25
+ content: "";
26
+ width: 50%;
27
+ height: 100%;
28
+ }
29
+ &:after{
30
+ left: 0;
31
+ background-color: $color-base-white;
32
+ border-radius: 50%;
33
+ transition: all .2s ease;
34
+ }
35
+ &:before{
36
+ display: none;
37
+ }
38
+ }
39
+
40
+ &__input {
41
+ display: none;
42
+ &:checked {
43
+ + .Toggle__button {
44
+ background-color: $color-background-success;
45
+ &--on--disabled {
46
+ background-color: $color-background-disabled;
47
+ };
48
+ &--on--danger {
49
+ background-color: $color-background-error;
50
+ };
51
+ &--on--success {
52
+ background-color: $color-background-success;
53
+ };
54
+ &:after{
55
+ left: 50%;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ }
@@ -344,10 +344,10 @@ $color-font-inverse-error: #ef5350;
344
344
  $color-font-inverse-warning: #ffa726;
345
345
  $color-font-inverse-success: #66bb6a;
346
346
  $color-font-inverse-disabled: #f5f5f5;
347
- //################### FONT LINK ####################
347
+ //################## FONT BUTTON ###################
348
348
  $color-font-button-primary: #ffffff;
349
349
  $color-font-button-secondary: #009688;
350
- //################## FONT BUTTON ###################
350
+ //################### FONT LINK ####################
351
351
  $color-font-link-primary: $color-brand-primary-base;
352
352
  $color-font-link-secondary: $color-brand-secondary-base;
353
353
  $color-font-link-base: $color-font-base;
@@ -361,13 +361,17 @@ $radii-base-sm: 8px;
361
361
  //##################### SIZES ######################
362
362
  //##################################################
363
363
  //###################### FONT ######################
364
- $size-font-tiny: 0.75rem;
364
+ $size-font-xxxxs: 0.05rem;
365
+ $size-font-xxxs: 0.25rem;
366
+ $size-font-xxs: 0.5rem;
367
+ $size-font-xs: 0.75rem;
365
368
  $size-font-small: 0.875rem;
366
369
  $size-font-medium: 1rem;
367
370
  $size-font-large: 1.25rem;
368
371
  $size-font-xl: 1.5rem;
369
372
  $size-font-xxl: 2rem;
370
373
  $size-font-xxxl: 3rem;
374
+ $size-font-xxxxl: 4rem;
371
375
  $size-font-base: 1rem;
372
376
  //###################### ICON ######################
373
377
  $size-icon-small: 1.5rem;
@@ -22,3 +22,4 @@
22
22
  @import "components/alpha/button";
23
23
  @import "components/alpha/form_submit";
24
24
  @import "components/alpha/form_input_group";
25
+ @import "components/alpha/toggle";
@@ -6,12 +6,29 @@
6
6
  module Uistiti
7
7
  module Alpha
8
8
  class ButtonPreview < ViewComponent::Preview
9
+ # @!group Colors
10
+
11
+ def primary
12
+ render(Uistiti::Alpha::Button.new(color: :primary).with_content('Button'))
13
+ end
14
+
15
+ def secondary
16
+ render(Uistiti::Alpha::Button.new(color: :secondary).with_content('Button'))
17
+ end
18
+
19
+ def danger
20
+ render(Uistiti::Alpha::Button.new(color: :danger).with_content('Button'))
21
+ end
22
+
23
+ # @!endgroup
24
+
9
25
  # Simple button style
10
26
 
11
27
  # @param color select [primary, secondary, danger]
12
28
  def playground(color: 'primary')
13
29
  render(Uistiti::Alpha::Button.new(color:).with_content('Button'))
14
30
  end
31
+
15
32
  end
16
33
  end
17
34
  end
@@ -6,12 +6,38 @@
6
6
  module Uistiti
7
7
  module Alpha
8
8
  class ImagePreview < ViewComponent::Preview
9
+
10
+ # @!group Sizes
11
+
12
+ def small
13
+ render(Uistiti::Alpha::Image.new(source: 'https://www.lesterresdenatae.fr/wp-content/uploads/2022/05/Masque-20.png', size: :small))
14
+ end
15
+
16
+ def medium
17
+ render(Uistiti::Alpha::Image.new(source: 'https://www.lesterresdenatae.fr/wp-content/uploads/2022/05/Masque-20.png', size: :medium))
18
+ end
19
+
20
+ def large
21
+ render(Uistiti::Alpha::Image.new(source: 'https://www.lesterresdenatae.fr/wp-content/uploads/2022/05/Masque-20.png', size: :large))
22
+ end
23
+
24
+ def xl
25
+ render(Uistiti::Alpha::Image.new(source: 'https://www.lesterresdenatae.fr/wp-content/uploads/2022/05/Masque-20.png', size: :xl))
26
+ end
27
+
28
+ def xxl
29
+ render(Uistiti::Alpha::Image.new(source: 'https://www.lesterresdenatae.fr/wp-content/uploads/2022/05/Masque-20.png', size: :xxl))
30
+ end
31
+
32
+
33
+ # @!endgroup
34
+
9
35
  # Declare each possible params bellow, please see how to declare params and annotate previews https://lookbook.build/guide/previews/annotations
10
36
 
11
37
  # @param source
12
38
  # @param size select [small, medium, large, xl, xxl]
13
39
  def playground(source: 'https://www.lesterresdenatae.fr/wp-content/uploads/2022/05/Masque-20.png', size: 'large')
14
- render(Uistiti::Alpha::Image.new(source:, size:))
40
+ render(Uistiti::Alpha::Image.new(source: , size:))
15
41
  end
16
42
  end
17
43
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Uistiti
3
+ module Alpha
4
+ class TogglePreview < ViewComponent::Preview
5
+ # Toggle
6
+ # ---------------
7
+ # On each changes, this component makes PUT request to @path with body sent as follow {@model: {@field: value}} where value is true/false for now.
8
+ # If the request retunr something else than a 2XX the toglle is reverted to its original state
9
+ #
10
+ # @param checked [Boolean]
11
+ # @param path select [/uistiti/lookbook/dummy/success, /uistiti/lookbook/dummy/error]
12
+ # @param model
13
+ # @param field
14
+ # @param color_on select [disabled, success, danger]
15
+ # @param color_off select [disabled, success, danger]
16
+ def playground(checked: false, path: '/uistiti/lookbook/dummy/success', model: 'automated_ticket', field: 'active', color_on: :success, color_off: :disabled)
17
+ render(Uistiti::Alpha::Toggle.new(checked:, path:, model:, field:, color_on:, color_off:))
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ <%= label_tag input_name, nil, class: 'Toggle', data: wrapper_data_set do %>
2
+ <%= check_box_tag input_name, @checked, @checked, class: 'Toggle__input', data: {action: "change->uistiti--alpha--toggle#sendPutRequest"} %>
3
+ <%= content_tag :div, nil, class: button_classes %>
4
+ <% end %>
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uistiti
4
+ module Alpha
5
+ class Toggle < ViewComponent::Base
6
+ def initialize(checked: , path:, model:, field:, color_on: :success, color_off: :disabled)
7
+ super()
8
+
9
+ @checked = checked
10
+ @path = path
11
+ @model = model
12
+ @field = field
13
+ @color_off = color_off
14
+ @color_on = color_on
15
+ end
16
+
17
+ private
18
+
19
+ def button_classes
20
+ [
21
+ "Toggle__button",
22
+ "Toggle__button--off--#{@color_off}",
23
+ "Toggle__button--on--#{@color_on}",
24
+ ]
25
+ end
26
+
27
+ def input_name
28
+ "toggle-#{@model}-#{@field}"
29
+ end
30
+
31
+ def wrapper_data_set
32
+ {
33
+ controller: 'uistiti--alpha--toggle',
34
+ 'uistiti--alpha--toggle-url-value': @path,
35
+ 'uistiti--alpha--toggle-model-value': @model,
36
+ 'uistiti--alpha--toggle-field-value': @field
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ module Uistiti
2
+ module Lookbook
3
+ class DummyController < ApplicationController
4
+
5
+ #PUT /lookbook/dummy/success
6
+ #GET /lookbook/dummy/success
7
+ def success
8
+ render status: 200, json: {message: 'OK'}.to_json
9
+ end
10
+
11
+ #PUT /lookbook/dummy/error
12
+ #GET /lookbook/dummy/error
13
+ def error
14
+ puts params
15
+ render status: 400, json: {:error => 'Bad request'}.to_json
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,12 +5,8 @@
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <%= csrf_meta_tags %>
7
7
  <%= csp_meta_tag %>
8
- <style>
9
- body {
10
- background: beige;
11
- }
12
- </style>
13
8
  <%= stylesheet_link_tag "application" %>
9
+ <%= javascript_importmap_tags %>
14
10
  </head>
15
11
 
16
12
  <body>
data/config/routes.rb CHANGED
@@ -1,3 +1,8 @@
1
1
  Uistiti::Engine.routes.draw do
2
+ put '/lookbook/dummy/success', to: 'lookbook/dummy#success'
3
+ get '/lookbook/dummy/success', to: 'lookbook/dummy#success'
4
+ put '/lookbook/dummy/error', to: 'lookbook/dummy#error'
5
+ get '/lookbook/dummy/error', to: 'lookbook/dummy#error'
2
6
  mount Lookbook::Engine, at: "/lookbook"
7
+ #dummy routes for lookbook AJAX behavior testing
3
8
  end
@@ -19,7 +19,7 @@ module Uistiti
19
19
  end
20
20
 
21
21
  def create_stimulus
22
- template("component.js.tt", "app/assets/javascript/controllers/uistiti/#{status_path}#{underscore_name}/#{underscore_name}_controller.js")
22
+ template("component.js.tt", "app/assets/javascript/controllers/uistiti/#{status_path}#{underscore_name}_controller.js")
23
23
  end
24
24
 
25
25
  def create_preview
@@ -1,3 +1,3 @@
1
1
  module Uistiti
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uistiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ecrepont
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-30 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -70,15 +70,16 @@ files:
70
70
  - README.md
71
71
  - Rakefile
72
72
  - app/assets/config/uistiti_manifest.js
73
- - app/assets/javascript/controllers/uistiti/alpha/button/button_controller.js
74
- - app/assets/javascript/controllers/uistiti/alpha/container/container_controller.js
75
- - app/assets/javascript/controllers/uistiti/alpha/flex/flex_controller.js
76
- - app/assets/javascript/controllers/uistiti/alpha/form_input_group/form_input_group_controller.js
77
- - app/assets/javascript/controllers/uistiti/alpha/form_submit/form_submit_controller.js
78
- - app/assets/javascript/controllers/uistiti/alpha/image/image_controller.js
79
- - app/assets/javascript/controllers/uistiti/alpha/link/link_controller.js
80
- - app/assets/javascript/controllers/uistiti/alpha/main_layout/main_layout_controller.js
81
- - app/assets/javascript/controllers/uistiti/alpha/navbar/navbar_controller.js
73
+ - app/assets/javascript/controllers/uistiti/alpha/button_controller.js
74
+ - app/assets/javascript/controllers/uistiti/alpha/container_controller.js
75
+ - app/assets/javascript/controllers/uistiti/alpha/flex_controller.js
76
+ - app/assets/javascript/controllers/uistiti/alpha/form_input_group_controller.js
77
+ - app/assets/javascript/controllers/uistiti/alpha/form_submit_controller.js
78
+ - app/assets/javascript/controllers/uistiti/alpha/image_controller.js
79
+ - app/assets/javascript/controllers/uistiti/alpha/link_controller.js
80
+ - app/assets/javascript/controllers/uistiti/alpha/main_layout_controller.js
81
+ - app/assets/javascript/controllers/uistiti/alpha/navbar_controller.js
82
+ - app/assets/javascript/controllers/uistiti/alpha/toggle_controller.js
82
83
  - app/assets/stylesheets/uistiti/components/alpha/button.scss
83
84
  - app/assets/stylesheets/uistiti/components/alpha/container.scss
84
85
  - app/assets/stylesheets/uistiti/components/alpha/flex.scss
@@ -88,6 +89,7 @@ files:
88
89
  - app/assets/stylesheets/uistiti/components/alpha/link.scss
89
90
  - app/assets/stylesheets/uistiti/components/alpha/main_layout.scss
90
91
  - app/assets/stylesheets/uistiti/components/alpha/navbar.scss
92
+ - app/assets/stylesheets/uistiti/components/alpha/toggle.scss
91
93
  - app/assets/stylesheets/uistiti/config/_variables.scss
92
94
  - app/assets/stylesheets/uistiti/uistiti.scss
93
95
  - app/components/previews/uistiti/alpha/button_preview.rb
@@ -97,6 +99,7 @@ files:
97
99
  - app/components/previews/uistiti/alpha/link_preview.rb
98
100
  - app/components/previews/uistiti/alpha/main_layout_preview.rb
99
101
  - app/components/previews/uistiti/alpha/navbar_preview.rb
102
+ - app/components/previews/uistiti/alpha/toggle_preview.rb
100
103
  - app/components/uistiti/alpha/button.html.erb
101
104
  - app/components/uistiti/alpha/button.rb
102
105
  - app/components/uistiti/alpha/container.html.erb
@@ -115,7 +118,10 @@ files:
115
118
  - app/components/uistiti/alpha/main_layout.rb
116
119
  - app/components/uistiti/alpha/navbar.html.erb
117
120
  - app/components/uistiti/alpha/navbar.rb
121
+ - app/components/uistiti/alpha/toggle.html.erb
122
+ - app/components/uistiti/alpha/toggle.rb
118
123
  - app/controllers/uistiti/application_controller.rb
124
+ - app/controllers/uistiti/lookbook/dummy_controller.rb
119
125
  - app/helpers/uistiti/application_helper.rb
120
126
  - app/jobs/uistiti/application_job.rb
121
127
  - app/mailers/uistiti/application_mailer.rb