playbook_ui 12.35.0 → 12.36.0.pre.alpha.svgiconmethods1043

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: 9b982d7d15691df84bc2a32b4f67b5dab67cf90ab7f9fc072ebfd4d81b800684
4
- data.tar.gz: 293f1da6a6611a18106a6f0f1a3cccf2edc2520657ff5f17f3e06a2b74de7839
3
+ metadata.gz: a55076e0e8167e0db8cbbe9509bf5c99f10e376e0ac56a769c1cc5a5185178ba
4
+ data.tar.gz: 0e9efeea039a9149b34cfbc3d445845de2c937d892ce380a8af16f449f09e096
5
5
  SHA512:
6
- metadata.gz: 46f096f0c12c8c764ab72c44ff5fd42f0bc8c547c6807a2ae06dae1e073c055abbbfae072144524ddeeba99e2397d7deaa81b9f64cb07b904b2582b636c4da9b
7
- data.tar.gz: 992a01e77be2823afea2e8e8ece093d84114fb0e85a3e58bb1dc57a50d8ff4f86fb3ccaae38f16d8554de1334285463b155bb28b28c2bccbbb1969e21af4807e
6
+ metadata.gz: 2002845578b53dd39bb6f23d5a16de27bdc92618f22b31a8f9f0d4f9134418509b7c80f077112bbccb9b3fa1bf2a1a56376b9cc7d0626423406729e5bce37a5f
7
+ data.tar.gz: c61aed1e059b92f3fc5753f1ed723425f4bbe4265a1f2cc595f2f0d05ab439ebb17da6cab3251a19830b6a08d996c590a68ce15c889e15029d803c2d64391f11
@@ -21,13 +21,17 @@ const dialogHelper = () => {
21
21
 
22
22
  // Close dialog box on outside click
23
23
  dialogs.forEach((dialogElement) => {
24
- dialogElement.addEventListener("click", (event) => {
24
+ dialogElement.addEventListener("mousedown", (event) => {
25
25
  const dialogParentDataset = dialogElement.parentElement.dataset
26
26
  if (dialogParentDataset.overlayClick === "overlay_close") return
27
27
 
28
- const clickedOutsideDialogBox = event.target.classList.contains("pb_dialog_rails")
28
+ const dialogModal = event.target.getBoundingClientRect()
29
+ const clickedOutsideDialogModal = event.clientX < dialogModal.left ||
30
+ event.clientX > dialogModal.right ||
31
+ event.clientY < dialogModal.top ||
32
+ event.clientY > dialogModal.bottom
29
33
 
30
- if (clickedOutsideDialogBox) {
34
+ if (clickedOutsideDialogModal) {
31
35
  dialogElement.close()
32
36
  event.stopPropagation()
33
37
  }
@@ -1,3 +1,4 @@
1
1
  <p><%= pb_rails("icon", props: { icon: "spinner", spin: true, fixed_width: true, size: "2x" }) %> <span>Spin</span></p>
2
2
  <br/>
3
3
  <p><%= pb_rails("icon", props: { icon: "spinner", pulse: true, fixed_width: true, size: "2x" }) %> <span>Pulse</span></p>
4
+
@@ -14,3 +14,5 @@
14
14
  parent element's css color properties."
15
15
  } ) %>
16
16
  </div>
17
+
18
+
@@ -0,0 +1,4 @@
1
+ <%= pb_rails("icon", props: { size: "5x", custom_icon: "copilot", padding_left: "xl" } ) %>
2
+ <%= pb_rails("icon", props: { size: "5x", custom_icon: "squirrel" } ) %>
3
+ <%= pb_rails("icon", props: { size: "5x", custom_icon: "star" } ) %>
4
+
@@ -1,14 +1,15 @@
1
1
  examples:
2
2
  rails:
3
- - icon_default: Icon Default
4
- - icon_rotate: Icon Rotate
5
- - icon_flip: Icon Flip
6
- - icon_animate: Icon Animation
7
- - icon_pull: Icon Pull
8
- - icon_border: Icon Border
9
- - icon_sizes: Icon Sizes
10
- - icon_custom: Icon Custom
11
- - icon_fa_kit: Icon with FontAwesome Kit
3
+ # - icon_default: Icon Default
4
+ # - icon_rotate: Icon Rotate
5
+ # - icon_flip: Icon Flip
6
+ # - icon_animate: Icon Animation
7
+ # - icon_pull: Icon Pull
8
+ # - icon_border: Icon Border
9
+ # - icon_sizes: Icon Sizes
10
+ # - icon_custom: Icon Custom
11
+ # - icon_fa_kit: Icon with FontAwesome Kit
12
+ - icon_svg: Icon SVG
12
13
 
13
14
  react:
14
15
  - icon_default: Icon Default
@@ -1,15 +1,15 @@
1
1
  <% if object.custom_icon %>
2
- <%= object.render_svg(object.custom_icon) %>
2
+ <%= object.embedded_svg(object.custom_icon) %>
3
3
  <% elsif object.valid_emoji(object.icon) %>
4
4
  <span class="pb_icon_kit_emoji"><%= object.icon.html_safe %></span>
5
5
  <% else %>
6
6
  <%= content_tag(:i, nil,
7
7
  id: object.id,
8
8
  data: object.data,
9
- class: object.classname
9
+ class: object.classname,
10
10
  ) %>
11
11
  <%= content_tag(:span, nil,
12
12
  aria: { label: "#{object.icon} icon" }.merge(object.aria),
13
13
  hidden: true
14
14
  ) %>
15
- <% end %>
15
+ <% end %>
@@ -90,6 +90,23 @@ module Playbook
90
90
  end
91
91
  end
92
92
 
93
+ def embedded_svg(icon_name)
94
+ file = File.read(Rails.root.join("app", "javascript", "images", "#{icon_name}.svg"))
95
+ doc = Nokogiri::HTML::DocumentFragment.parse file
96
+ svg = doc.at_css "svg"
97
+
98
+ doc.to_html.html_safe
99
+
100
+ size_factor = size.to_i
101
+ if size_factor > 1
102
+ pixel_size = size_factor * 16
103
+ svg["width"] = pixel_size.to_s
104
+ svg["height"] = pixel_size.to_s
105
+ end
106
+
107
+ raw doc
108
+ end
109
+
93
110
  private
94
111
 
95
112
  def border_class
@@ -1,4 +1,4 @@
1
- import React, { useEffect } from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import {
4
4
  Popper,
@@ -17,6 +17,7 @@ import {
17
17
 
18
18
  import classnames from "classnames";
19
19
  import { globalProps, GlobalProps } from "../utilities/globalProps";
20
+ import _uniqueId from 'lodash/uniqueId';
20
21
 
21
22
  type PbPopoverProps = {
22
23
  aria?: { [key: string]: string };
@@ -72,6 +73,7 @@ const Popover = (props: PbPopoverProps) => {
72
73
  maxWidth,
73
74
  minHeight,
74
75
  minWidth,
76
+ targetId,
75
77
  } = props;
76
78
 
77
79
  const popoverSpacing =
@@ -123,6 +125,7 @@ const Popover = (props: PbPopoverProps) => {
123
125
  popoverSpacing,
124
126
  overflowHandling
125
127
  )}
128
+ id={targetId}
126
129
  style={widthHeightStyles()}
127
130
  >
128
131
  {children}
@@ -136,6 +139,7 @@ const Popover = (props: PbPopoverProps) => {
136
139
  };
137
140
 
138
141
  const PbReactPopover = (props: PbPopoverProps) => {
142
+ const [targetId] = useState(_uniqueId('id-'))
139
143
  const {
140
144
  className,
141
145
  children,
@@ -163,25 +167,27 @@ const PbReactPopover = (props: PbPopoverProps) => {
163
167
  "click",
164
168
  ({ target }) => {
165
169
  const targetIsPopover =
166
- (target as HTMLElement).closest("[class^=pb_popover_tooltip]") !==
170
+ (target as HTMLElement).closest("#" + targetId) !==
167
171
  null;
168
172
  const targetIsReference =
169
- (target as HTMLElement).closest(".pb_popover_reference_wrapper") !==
173
+ (target as HTMLElement).closest("#reference-" + targetId) !==
170
174
  null;
171
175
 
172
176
  switch (closeOnClick) {
173
177
  case "outside":
174
- if (!targetIsPopover || targetIsReference) {
178
+ if (!targetIsPopover && !targetIsReference) {
175
179
  shouldClosePopover(true);
176
180
  }
177
181
  break;
178
182
  case "inside":
179
- if (targetIsPopover || targetIsReference) {
183
+ if (targetIsPopover) {
180
184
  shouldClosePopover(true);
181
185
  }
182
186
  break;
183
187
  case "any":
184
- shouldClosePopover(true);
188
+ if (targetIsPopover || !targetIsPopover && !targetIsReference) {
189
+ shouldClosePopover(true);
190
+ }
185
191
  break;
186
192
  }
187
193
  },
@@ -200,6 +206,7 @@ const PbReactPopover = (props: PbPopoverProps) => {
200
206
  offset={offset}
201
207
  placement={placement}
202
208
  referenceElement={referenceElement}
209
+ targetId={targetId}
203
210
  zIndex={zIndex}
204
211
  {...props}
205
212
  >
@@ -214,6 +221,7 @@ const PbReactPopover = (props: PbPopoverProps) => {
214
221
  <PopperReference>
215
222
  {({ ref }) => (
216
223
  <span
224
+ id={"reference-" + targetId}
217
225
  className="pb_popover_reference_wrapper"
218
226
  ref={ref}>
219
227
  <reference.type {...reference.props} />
@@ -24,6 +24,7 @@ const PopoverClose = (props) => {
24
24
 
25
25
  const handleOutsideTogglePopover = () => {
26
26
  setOutsideShowPopover(!showOutsidePopover)
27
+ setAnyShowPopover(false)
27
28
  }
28
29
 
29
30
  const handleAnyShouldClosePopover = (shouldClosePopover) => {
@@ -32,6 +33,7 @@ const PopoverClose = (props) => {
32
33
 
33
34
  const handleAnyTogglePopover = () => {
34
35
  setAnyShowPopover(!showAnyPopover)
36
+ setOutsideShowPopover(false)
35
37
  }
36
38
 
37
39
  const insidePopoverTrigger = (
@@ -49,13 +49,16 @@ export default class PbPopover extends PbEnhancedElement {
49
49
  checkCloseTooltip() {
50
50
  document.querySelector('body').addEventListener('click', ({ target } ) => {
51
51
  const isTooltipElement = (target as HTMLElement).closest(`#${this.tooltipId}`) !== null
52
+ const isTriggerElement = (target as HTMLElement).closest(`#${this.triggerElementId}`) !== null
52
53
 
53
54
  switch (this.closeOnClick) {
54
55
  case 'any':
55
- this.hideTooltip()
56
+ if (isTooltipElement || !isTooltipElement && !isTriggerElement) {
57
+ this.hideTooltip()
58
+ }
56
59
  break
57
60
  case 'outside':
58
- if (!isTooltipElement) {
61
+ if (!isTooltipElement && !isTriggerElement) {
59
62
  this.hideTooltip()
60
63
  }
61
64
  break