playbook_ui 14.0.0.pre.alpha.PBNTR415starratingform3492 → 14.0.0.pre.alpha.PBNTR416formpillsizes3506

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ea9088edfef4d9e59db2c6597b4f476e37bd6edefb8a76eea7f76d1818910c7
4
- data.tar.gz: e101c98a4cb0e480619b4b5f55dbcf2349a32b26d9028f4e80fd701d875887ef
3
+ metadata.gz: fb1f8b144b843e80a273836c1ca36bbeaf0805087e03977c4e2db65b180b75e9
4
+ data.tar.gz: c9fdf3e9bc64cb4ec72a048aabc43d05d17b2356e7637ee67dfe292dd25e5f0c
5
5
  SHA512:
6
- metadata.gz: 0eb4fc44d37ace56aef7b511255e2a62013e60c32213bd096a0b67a5a28f49aa6e7c484d631571914ee97fd3ae78a985cbae8f648b1ab8398816297a7787d4b3
7
- data.tar.gz: a2755e31f02392e6116f561337663769a5f358e0b576994197f0aa63ece93faf7398fe5d865bb44d99c5cc745ca368eee7debfe0795526718052a6b2c0565d68
6
+ metadata.gz: efdf11b236ee0a90af8bae6c2bca5a3057841804746ffac6e76e6e3c939ebae392c4c352fd927e1b3b463f4a95d40bce997bf82b81ff823c296ba98aef013356
7
+ data.tar.gz: d65038299477dfa06796130b8a116578bc5ffff990a219a91dd223b8d0af4592e307a34192dd2f6b91c9b976f5703b13cabc12e6240ec02e33055b25a338c5c4
@@ -35,7 +35,6 @@
35
35
  <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
36
36
  <%= form.check_box :example_checkbox, props: { text: "Example Checkbox", label: true, required: true } %>
37
37
  <%= form.date_picker :example_date_picker_2, props: { label: true, required: true } %>
38
- <%= form.star_rating_field :example_star_rating, props: { variant: "interactive", label: true, required: true } %>
39
38
 
40
39
  <%= form.actions do |action| %>
41
40
  <%= action.submit %>
@@ -3,9 +3,10 @@
3
3
  @import "../tokens/opacity";
4
4
  @import "../tokens/shadows";
5
5
  @import "../pb_avatar/avatar";
6
+ @import "../tokens/typography";
6
7
 
7
8
  $selector: ".pb_form_pill";
8
- $pb_form_pill_height: 37px;
9
+ $pb_form_pill_height: 27px;
9
10
  $form_pill_colors: (
10
11
  primary: map-get($status_color_text, "primary"),
11
12
  neutral: map-get($status_color_text, "neutral"),
@@ -16,18 +17,24 @@ $form_pill_colors: (
16
17
  display: inline-flex;
17
18
  justify-content: center;
18
19
  align-items: center;
19
- padding: 0 calc($space-sm/3);
20
+ padding: 0 calc($space-md/2);
20
21
  height: $pb_form_pill_height;
21
22
  border-radius: calc($pb_form_pill_height/2);
22
23
  margin-bottom: 2px;
23
24
  margin-top: 2px;
24
25
  cursor: pointer;
26
+ .pb_form_pill_text, .pb_form_pill_close, .pb_form_pill_tag{
27
+ font-size: $font_small !important;
28
+ }
25
29
  @each $color_name, $color_value in $form_pill_colors {
26
30
  &[class*=_#{$color_name}] {
27
31
  background-color: mix($color_value, $card_light, 10%);
28
32
  @if ($color_name == "neutral") {
29
33
  background-color: $white;
30
34
  border: 1px solid $border_light;
35
+ .pb_form_pill_icon {
36
+ color: $text_lt_default;
37
+ }
31
38
  }
32
39
  transition: background-color 0.2s ease;
33
40
  box-shadow: none;
@@ -51,20 +58,18 @@ $form_pill_colors: (
51
58
  @if ($color_name == "neutral") {
52
59
  color: $text_lt_default;
53
60
  }
54
- padding-left: $space-sm;
55
- padding-right: calc($space-sm/2);
61
+ padding: 0 $space-xs;
56
62
  }
57
63
  #{$selector}_close {
58
64
  color: $color_value;
59
- padding-left: calc($space-sm/4);
60
- padding-right: calc($space-sm/4);
61
65
  display: flex;
62
66
  align-items: center;
63
- // I had to temporarily change height to 27px so new hover state darker background forms a circle not an oval
64
- // before size change (ticket 2 of 4) - change back to 100% when $pb_form_pill_height changed to 27px from 37px
65
- height: 27px;
66
- border-radius: 70px;
67
+ height: 17px;
68
+ border-radius: calc(50%);
67
69
  cursor: pointer;
70
+ @if ($color_name == "neutral") {
71
+ color: $text_lt_default;
72
+ }
68
73
  &:hover {
69
74
  background-color: mix($color_value, $card_light, 40%);
70
75
  @if ($color_name == "neutral") {
@@ -74,7 +79,7 @@ $form_pill_colors: (
74
79
  }
75
80
  #{$selector}_tag {
76
81
  color: $color_value;
77
- padding-left: $space-sm;
82
+ padding: 0 $space-xs;
78
83
  @if ($color_name == "neutral") {
79
84
  color: $text_lt_default;
80
85
  }
@@ -92,24 +97,37 @@ $form_pill_colors: (
92
97
  .pb_form_pill_icon {
93
98
  height: 12px !important;
94
99
  width: 12px !important;
100
+ padding-right: $space_xs;
101
+ + .pb_form_pill_text, + .pb_form_pill_tag {
102
+ padding-left: 0;
103
+ }
95
104
  }
96
105
  &.small {
97
- height: fit-content;
98
- height: -moz-fit-content;
106
+ height: 17px;
107
+ padding: 0 $space-xs;
99
108
  .pb_form_pill_text, .pb_form_pill_close, .pb_form_pill_tag {
100
- font-size: $font_base;
101
- font-weight: $regular;
109
+ font-size: $font_smallest !important;
102
110
  }
103
111
  .pb_form_pill_text, .pb_form_pill_tag {
104
112
  line-height: 1.7;
105
- padding-left: $space_xs;
106
- padding-right: 2px;
113
+ padding: 0 $space_xxs;
114
+ }
115
+ .pb_form_pill_close {
116
+ height: 10px;
117
+ border-radius: calc(50%);
107
118
  }
108
- [class^=pb_avatar_kit], [class^=pb_avatar_kit] .avatar_wrapper {
109
- width: 20px;
110
- height: 20px;
111
- flex-basis: 20px;
112
- &::before { line-height: 21px; }
119
+ [class^=pb_avatar_kit] .avatar_wrapper {
120
+ flex-basis: 16px;
121
+ height: 16px;
122
+ margin-top: 2px;
123
+ width: 16px;
124
+ &::before { line-height: 16.5px; }
125
+ }
126
+ .pb_form_pill_icon {
127
+ padding-right: $space_xxs;
128
+ + .pb_form_pill_text, + .pb_form_pill_tag {
129
+ padding-left: 0;
130
+ }
113
131
  }
114
132
  }
115
133
  &.dark {
@@ -118,7 +136,7 @@ $form_pill_colors: (
118
136
  // Primary and Neutral are exceptions to the general rule in the handoff
119
137
  &[class*=_#{$color_name}] {
120
138
  // background-color: mix($color_value, $card_dark, 10%);
121
- // .pb_form_pill_tag {
139
+ // .pb_form_pill_text, .pb_form_pill_tag, .pb_form_pill_icon {
122
140
  // color: $color_name;
123
141
  // }
124
142
  // .pb_form_pill_close {
@@ -136,7 +154,7 @@ $form_pill_colors: (
136
154
  @if ($color_name == "neutral") {
137
155
  background-color: transparent;
138
156
  border: 1px solid $border_dark;
139
- .pb_form_pill_text, .pb_form_pill_tag {
157
+ .pb_form_pill_text, .pb_form_pill_tag, .pb_form_pill_icon {
140
158
  color: $text_dk_default;
141
159
  }
142
160
  .pb_form_pill_close {
@@ -157,7 +175,7 @@ $form_pill_colors: (
157
175
  }
158
176
  @if ($color_name == "primary") {
159
177
  background-color: mix($active_dark, $card_dark, 10%);
160
- .pb_form_pill_text, .pb_form_pill_tag {
178
+ .pb_form_pill_text, .pb_form_pill_tag, .pb_form_pill_icon {
161
179
  color: $active_dark;
162
180
  }
163
181
  .pb_form_pill_close {
@@ -46,6 +46,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
46
46
  } = props
47
47
 
48
48
  const iconClass = icon ? "_icon" : ""
49
+ const closeIconSize = size === "small" ? "xs" : "sm"
49
50
  const css = classnames(
50
51
  `pb_form_pill_kit_${color}${iconClass}`,
51
52
  globalProps(props),
@@ -69,7 +70,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
69
70
  <Avatar
70
71
  imageUrl={avatarUrl}
71
72
  name={name}
72
- size="xs"
73
+ size="xxs"
73
74
  status={null}
74
75
  />
75
76
  <Title
@@ -84,7 +85,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
84
85
  <Avatar
85
86
  imageUrl={avatarUrl}
86
87
  name={name}
87
- size="xs"
88
+ size="xxs"
88
89
  status={null}
89
90
  />
90
91
  <Title
@@ -94,6 +95,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
94
95
  />
95
96
  <Icon
96
97
  className="pb_form_pill_icon"
98
+ color={color}
97
99
  icon={icon}
98
100
  />
99
101
  </>
@@ -102,6 +104,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
102
104
  <>
103
105
  <Icon
104
106
  className="pb_form_pill_icon"
107
+ color={color}
105
108
  icon={icon}
106
109
  />
107
110
  <Title
@@ -126,6 +129,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
126
129
  <Icon
127
130
  fixedWidth
128
131
  icon="times"
132
+ size={closeIconSize}
129
133
  />
130
134
  </div>
131
135
  </div>
@@ -5,11 +5,11 @@ examples:
5
5
  - form_pill_size: Form Pill Size
6
6
  - form_pill_tag: Form Pill Tag
7
7
  - form_pill_example: Example
8
- # - form_pill_icon: Form Pill Icon
8
+ - form_pill_icon: Form Pill Icon
9
9
 
10
10
  react:
11
11
  - form_pill_user: Form Pill User
12
12
  - form_pill_size: Form Pill Size
13
13
  - form_pill_tag: Form Pill Tag
14
14
  - form_pill_example: Example
15
- # - form_pill_icon: Form Pill Icon
15
+ - form_pill_icon: Form Pill Icon
@@ -1,19 +1,19 @@
1
1
  <%= content_tag(:div, id: object.id, data: object.data, class: object.classname + object.size_class, tabindex: object.tabindex, **combined_html_options) do %>
2
2
  <% if object.name.present? %>
3
- <%= pb_rails("avatar", props: { name: object.name, image_url: object.avatar_url, size: "xs" }) %>
3
+ <%= pb_rails("avatar", props: { name: object.name, image_url: object.avatar_url, size: "xxs" }) %>
4
4
  <%= pb_rails("title", props: { text: object.name, size: 4, classname: "pb_form_pill_text" }) %>
5
5
  <% if object.icon.present? %>
6
- <%= pb_rails("icon", props: { classname: "pb_form_pill_icon", icon: object.icon }) %>
6
+ <%= pb_rails("icon", props: { classname: "pb_form_pill_icon", color: object.color, icon: object.icon }) %>
7
7
  <% end %>
8
8
  <% elsif object.text.present? %>
9
9
  <% if object.icon.present? %>
10
- <%= pb_rails("icon", props: { classname: "pb_form_pill_icon", icon: object.icon }) %>
10
+ <%= pb_rails("icon", props: { classname: "pb_form_pill_icon", color: object.color, icon: object.icon }) %>
11
11
  <% end %>
12
12
  <% if object.text.present? %>
13
13
  <%= pb_rails("title", props: { text: object.text, size: 4, classname: "pb_form_pill_tag" }) %>
14
14
  <% end %>
15
15
  <% end %>
16
16
  <%= pb_rails("body", props: { classname: "pb_form_pill_close" }) do %>
17
- <%= pb_rails("icon", props: { icon: 'times' , fixed_width: true }) %>
17
+ <%= pb_rails("icon", props: { icon: 'times', fixed_width: true, size: object.close_icon_size }) %>
18
18
  <% end %>
19
19
  <% end %>
@@ -32,6 +32,10 @@ module Playbook
32
32
  def icon_class
33
33
  icon ? "icon" : nil
34
34
  end
35
+
36
+ def close_icon_size
37
+ size == "small" ? "xs" : "sm"
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -1,156 +1,119 @@
1
- import PbEnhancedElement from "../pb_enhanced_element"
1
+ import PbEnhancedElement from "../pb_enhanced_element";
2
2
 
3
- const STAR_RATING_WRAPPER_SELECTOR = "[data-pb-star-rating-wrapper]"
4
- const STAR_RATING_SELECTOR = "[data-pb-star-rating]"
5
- const STAR_RATING_INPUT_DATA_SELECTOR = "[data-pb-star-rating-input]"
3
+ const STAR_RATING_SELECTOR = "[data-pb-star-rating]";
4
+ const STAR_RATING_INPUT_ID = "star-rating-input";
6
5
 
7
6
  export default class PbStarRating extends PbEnhancedElement {
8
7
  static get selector() {
9
- return STAR_RATING_WRAPPER_SELECTOR
8
+ return STAR_RATING_SELECTOR;
10
9
  }
11
10
 
12
11
  connect() {
13
- this.addEventListeners()
14
- this.handleFormReset()
15
- }
16
-
17
- addEventListeners() {
18
- this.element.querySelectorAll(STAR_RATING_SELECTOR).forEach(star => {
19
- star.addEventListener("click", (event) => {
20
- const clickedStarId = event.currentTarget.id
21
- this.updateStarColors(clickedStarId)
22
- this.updateHiddenInputValue(clickedStarId)
23
- this.clearFormValidation()
24
- })
12
+ this.element.addEventListener("click", (event) => {
13
+ const clickedStarId = event.currentTarget.id;
14
+ this.updateStarColors(clickedStarId);
15
+ this.updateHiddenInputValue(clickedStarId);
16
+ });
25
17
 
18
+ document.querySelectorAll(STAR_RATING_SELECTOR).forEach(star => {
26
19
  star.addEventListener("mouseenter", (event) => {
27
20
  const hoveredStarId = event.currentTarget.id
28
- this.updateStarHoverColors(hoveredStarId)
21
+ this.updateStarHoverColors(hoveredStarId);
29
22
  })
30
23
 
31
24
  star.addEventListener("mouseleave", () => {
32
- this.removeStarHoverColors()
25
+ this.removeStarHoverColors();
33
26
  })
34
27
 
35
28
  star.addEventListener("keydown", (event) => {
36
29
  if (event.key === 'Enter' || event.key === ' ') {
37
- event.preventDefault()
38
- this.handleStarClick(star.id)
30
+ event.preventDefault();
31
+ this.handleStarClick(star.id);
39
32
  }
40
33
  })
41
34
  })
42
35
  }
43
36
 
44
37
  handleStarClick(starId) {
45
- this.updateStarColors(starId)
46
- this.updateHiddenInputValue(starId)
38
+ this.updateStarColors(starId);
39
+ this.updateHiddenInputValue(starId);
47
40
  }
48
41
 
49
42
  updateStarColors(clickedStarId) {
50
- const allStars = this.element.querySelectorAll(STAR_RATING_SELECTOR)
43
+ const allStars = document.querySelectorAll(STAR_RATING_SELECTOR);
51
44
 
52
45
  allStars.forEach(star => {
53
- const starId = star.id
54
- const icon = star.querySelector(".interactive-star-icon")
46
+ const starId = star.id;
47
+ const icon = star.querySelector(".interactive-star-icon");
55
48
 
56
49
  if (icon) {
57
50
  if (starId <= clickedStarId) {
58
51
  if (star.classList.contains("yellow_star")) {
59
- icon.classList.add("yellow-star-selected")
52
+ icon.classList.add("yellow-star-selected");
60
53
  } else if (star.classList.contains("primary_star_light")) {
61
- icon.classList.add("primary-star-selected")
54
+ icon.classList.add("primary-star-selected");
62
55
  } else if (star.classList.contains("primary_star_dark")) {
63
- icon.classList.add("primary-star-selected")
56
+ icon.classList.add("primary-star-selected");
64
57
  } else if (star.classList.contains("subtle_star_light")) {
65
- icon.classList.add("subtle-star-selected")
58
+ icon.classList.add("subtle-star-selected");
66
59
  } else if (star.classList.contains("subtle_star_dark")) {
67
- icon.classList.add("subtle-star-selected")
60
+ icon.classList.add("subtle-star-selected");
68
61
  } else {
69
- icon.classList.add("yellow-star-selected")
62
+ icon.classList.add("yellow-star-selected");
70
63
  }
71
64
  } else {
72
- icon.classList.remove("yellow-star-selected", "primary-star-selected", "subtle-star-selected")
65
+ icon.classList.remove("yellow-star-selected", "primary-star-selected", "subtle-star-selected");
73
66
  }
74
- icon.classList.remove("star-hovered")
67
+ icon.classList.remove("star-hovered");
75
68
  }
76
- })
69
+ });
77
70
  }
78
71
 
79
72
  updateHiddenInputValue(value) {
80
- const hiddenInput = this.element.querySelector(STAR_RATING_INPUT_DATA_SELECTOR)
73
+ const hiddenInput = document.getElementById(STAR_RATING_INPUT_ID);
81
74
  if (hiddenInput) {
82
- hiddenInput.value = value
75
+ hiddenInput.value = value;
83
76
  }
84
77
  }
85
78
 
86
79
  updateStarHoverColors(hoveredStarId) {
87
- const allStars = this.element.querySelectorAll(STAR_RATING_SELECTOR)
80
+ const allStars = document.querySelectorAll(STAR_RATING_SELECTOR);
88
81
 
89
82
  allStars.forEach(star => {
90
- const starId = star.id
91
- const icon = star.querySelector(".interactive-star-icon")
83
+ const starId = star.id;
84
+ const icon = star.querySelector(".interactive-star-icon");
92
85
 
93
86
  if (icon) {
94
87
  if (starId <= hoveredStarId) {
95
88
  if (!icon.classList.contains("yellow-star-selected") &&
96
89
  !icon.classList.contains("primary-star-selected") &&
97
90
  !icon.classList.contains("subtle-star-selected")) {
98
- icon.classList.add("star-hovered")
91
+ icon.classList.add("star-hovered");
99
92
  }
100
93
  } else {
101
- icon.classList.remove("star-hovered")
94
+ icon.classList.remove("star-hovered");
102
95
  }
103
96
  }
104
- })
97
+ });
105
98
  }
106
99
 
107
100
 
108
101
  removeStarHoverColors() {
109
- const allStars = this.element.querySelectorAll(STAR_RATING_SELECTOR)
102
+ const allStars = document.querySelectorAll(STAR_RATING_SELECTOR);
110
103
 
111
104
  allStars.forEach(star => {
112
- const icon = star.querySelector(".interactive-star-icon")
105
+ const icon = star.querySelector(".interactive-star-icon");
113
106
  if (icon) {
114
107
  if (!icon.classList.contains("yellow-star-selected") &&
115
108
  !icon.classList.contains("primary-star-selected") &&
116
109
  !icon.classList.contains("subtle-star-selected")) {
117
- icon.classList.remove("star-hovered")
110
+ icon.classList.remove("star-hovered");
118
111
  }
119
112
  }
120
- })
113
+ });
121
114
  }
122
115
 
123
116
  isStarSelected() {
124
- return this.element.querySelectorAll(".yellow-star-selected, .primary-star-selected, .subtle-star-selected").length > 0
125
- }
126
-
127
- handleFormReset() {
128
- const form = this.element.closest("form")
129
- if (form) {
130
- form.addEventListener("reset", () => {
131
- this.updateHiddenInputValue("")
132
- this.resetStarRatingValues()
133
- })
134
- }
135
- }
136
-
137
- resetStarRatingValues() {
138
- const allStars = this.element.querySelectorAll(STAR_RATING_SELECTOR)
139
- allStars.forEach(star => {
140
- const icon = star.querySelector(".interactive-star-icon")
141
- if (icon) {
142
- icon.classList.remove("yellow-star-selected", "primary-star-selected", "subtle-star-selected")
143
- }
144
- })
145
- }
146
-
147
- clearFormValidation() {
148
- const hiddenInput = this.element.querySelector(STAR_RATING_INPUT_DATA_SELECTOR)
149
- if (hiddenInput.checkValidity()) {
150
- const errorLabelElement = this.element.querySelector(".pb_body_kit_negative")
151
- if (errorLabelElement) {
152
- errorLabelElement.remove()
153
- }
154
- }
117
+ return document.querySelectorAll(".yellow-star-selected, .primary-star-selected, .subtle-star-selected").length > 0;
155
118
  }
156
119
  }
@@ -39,13 +39,11 @@
39
39
  <% end %>
40
40
 
41
41
  <% else %>
42
- <%= pb_rails("flex", props: { data: {"pb-star-rating-wrapper": "true" }, orientation: "column" }) do %>
42
+ <%= pb_rails("flex", props: { orientation: "column" }) do %>
43
43
  <% if object.label.present? %>
44
44
  <%= pb_rails("caption", props: {text: object.label, margin_bottom:"xs"}) %>
45
45
  <% end %>
46
-
47
- <%= hidden_input_tag %>
48
-
46
+ <input type="hidden" id="star-rating-input" value="" name="<%= object.name %>"/>
49
47
  <%= pb_rails("flex", props: { orientation: "row" }) do %>
50
48
  <% object.denominator.times do |index| %>
51
49
  <div data-pb-star-rating id="<%= index + 1 %>" class="<%= star_color %>">
@@ -30,10 +30,6 @@ module Playbook
30
30
  default: "display"
31
31
  prop :label, type: Playbook::Props::String
32
32
  prop :name, type: Playbook::Props::String
33
- prop :required, type: Playbook::Props::Boolean,
34
- default: false
35
- prop :input_options, type: Playbook::Props::HashProp,
36
- default: {}
37
33
 
38
34
  def one_decimal_rating
39
35
  rating.to_f.round(1)
@@ -110,19 +106,6 @@ module Playbook
110
106
  def classname
111
107
  generate_classname("pb_star_rating_kit")
112
108
  end
113
-
114
- def hidden_input_tag
115
- tag(:input, all_input_options)
116
- end
117
-
118
- def all_input_options
119
- input_options.merge(
120
- data: { "pb-star-rating-input": true },
121
- name: name,
122
- required: required,
123
- style: "display: none"
124
- )
125
- end
126
109
  end
127
110
  end
128
111
  end