playbook_ui 12.16.0.pre.alpha.lightboxcurrentphotoprop531 → 12.16.0.pre.alpha.tooltippositionprop566

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: accf792d3ae05665b499210171ab0a2401b7d89109b53f18904bbb23a73a7d5a
4
- data.tar.gz: 5d2ceb2031b2a4fcc38245e5584dcd94da4a97b61a5eb6fe4324163a91938b30
3
+ metadata.gz: 1aa71e42598e3d4a2cc59995711033c0b2aabe7bb25a7c11254955f7c679a2ca
4
+ data.tar.gz: a2e6816d1ab2faa4bb7b650e8445ec7797edcd753267c68aa4a136ce7220935b
5
5
  SHA512:
6
- metadata.gz: 1f44a2e628700f4579afa50346aa506b6a57e43ddbc50e30685b5b977f81f49c9fcfb864df1e08adc27788d487316ae475cf740f7522ebe9ceca4c829d3ac567
7
- data.tar.gz: dc0ee866dd0e92ba69c8688fb331535a743d6f4f362de42ed5641d3151a5485533cbb05b6296ba665360385df839322f59d38fa76d2763a5c2a43c8fe3e1ec88
6
+ metadata.gz: 11ac217ec0bfb4c58e087eaad581d77559b810589896f37bc96ab505c2aa2df6bcf0b4486ef646b681b241e8cbaf85efceee78685dd821f57d0555555d59b899
7
+ data.tar.gz: 6dae5b2762529cfab815e82c7b0be2d9455bd2a2809732ad1860b1db948626db4e7dba0b9b9108e73528e873dc1dbd92da82976bf735996780d93fe251c9939f
@@ -41,7 +41,7 @@ const CardBackground = (props) => {
41
41
  marginBottom="sm"
42
42
  {...props}
43
43
  >
44
- <Body text="Light" />
44
+ <Body text="Light"/>
45
45
  </Card>
46
46
 
47
47
 
@@ -1,12 +1,299 @@
1
- <div data-action="toggle" data-togglable="prop_example" class="pb--propsTable">
1
+ <% if !local_prop_data.present? %>
2
+ <div data-action="toggle" data-togglable="prop_example" class="pb--propsTable">
2
3
  <%= pb_rails("title", props: { text: "Available Props", size: 3, margin_bottom: "sm" }) %>
3
- <%= pb_rails("card", props: { padding: "none" }) do %>
4
- <%= pb_rails("list", props: { xpadding: true }) do %>
5
- <% kit_props.each do |key, _def| %>
6
- <%= pb_rails("list/item") do %>
7
- <%= key %>
4
+ <%= pb_rails("card", props: { padding: "none" }) do %>
5
+ <%= pb_rails("card/card_body", props: { padding: "sm" }) do %>
6
+ <%= pb_rails("nav", props: { orientation: "horizontal", variant: "subtle" }) do %>
7
+ <%= pb_rails("nav/item", props: { text: "Global Props", link: "#", active: true }) %>
8
+ <% end %>
9
+ <% end %>
10
+ <%= pb_rails("section_separator") %>
11
+ <%= pb_rails("card/card_body", props: {}) do %>
12
+ <%= pb_rails("table", props: {container: false, disable_hover: true }) do %>
13
+ <thead>
14
+ <tr>
15
+ <th>Props</th>
16
+ <th>Type</th>
17
+ <th>Values</th>
18
+ <th>Default</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <% global_prop_data.each do |key, value|%>
23
+ <tr>
24
+ <td>
25
+ <%= pb_rails("title", props: { text: key, tag: "h4", size: 4 }) %>
26
+ </td>
27
+ <td>
28
+ <%= pb_rails("card", props: {
29
+ classname: "card",
30
+ padding: "xxs",
31
+ background: "light",
32
+ border_none: true,
33
+ border_radius: "sm"
34
+ }) do %>
35
+ <%= pb_rails("body", props: {
36
+ classname: "kearning"
37
+ }) do %>
38
+ <%= value[:type].downcase %>
39
+ <% end %>
40
+ <% end %>
41
+ </td>
42
+ <td>
43
+ <% if value[:values].present? %>
44
+ <% value[:values].each do |item| %>
45
+ <% if item != nil %>
46
+ <%= pb_rails("card", props: {
47
+ flex_direction: "row",
48
+ classname: "card",
49
+ padding: "xxs",
50
+ background: "light",
51
+ border_none: true,
52
+ border_radius: "sm",
53
+ margin: "xxs"
54
+ }) do %>
55
+ <%= pb_rails("body", props: {
56
+ classname: "kearning"
57
+ }) do %>
58
+ <%= item %>
59
+ <% end %>
60
+ <% end %>
61
+ <% end %>
62
+ <% end %>
63
+ <% end %>
64
+ </td>
65
+ <td>
66
+ <% if value[:default].present? || value[:default].is_a?(TrueClass) || value[:default].is_a?(FalseClass) %>
67
+ <%= pb_rails("card", props: {
68
+ classname: "card",
69
+ padding: "xxs",
70
+ background: "light",
71
+ border_none: true,
72
+ border_radius: "sm"
73
+ }) do %>
74
+ <%= pb_rails("body", props: {
75
+ classname: "kearning"
76
+ }) do %>
77
+ <%= value[:default] %>
78
+ <% end %>
79
+ <% end %>
80
+ <% end %>
81
+ </td>
82
+ </tr>
83
+ <% end %>
84
+ </tbody>
85
+ <% end %>
86
+ <% end %>
87
+ <% end %>
88
+ </div>
89
+ <% else %>
90
+ <div data-action="toggle" data-togglable="prop_example" class="pb--propsTable">
91
+ <%= pb_rails("title", props: { text: "Available Props", size: 3, margin_bottom: "sm" }) %>
92
+ <%= pb_rails("card", props: { padding: "none" }) do %>
93
+ <%= pb_rails("card/card_body", props: { padding: "sm" }) do %>
94
+ <%= pb_rails("nav", props: { orientation: "horizontal", variant: "subtle" }) do %>
95
+ <% if local_prop_data.present? %>
96
+ <%= pb_rails("nav/item", props: { text: "Kit Props", link: "#", active: true, id: "local-button-active", classname: "local-active" }) %>
97
+ <% end %>
98
+ <% if local_prop_data.present? %>
99
+ <%= pb_rails("nav/item", props: { text: "Kit Props", link: "#", id: "local-button", classname: "global-active" }) %>
100
+ <% end %>
101
+ <%= pb_rails("nav/item", props: { text: "Global Props", link: "#", active: true, id: "global-button-active", classname: "global-active" }) %>
102
+ <%= pb_rails("nav/item", props: { text: "Global Props", link: "#", id: "global-button", classname: "local-active" }) %>
103
+ <% end %>
104
+ <% end %>
105
+ <%= pb_rails("section_separator") %>
106
+ <%= pb_rails("card/card_body", props: {}) do %>
107
+ <%= pb_rails("table", props: {container: false, disable_hover: true, id: "global-prop-table", classname: "global-active"}) do %>
108
+ <thead>
109
+ <tr>
110
+ <th>Props</th>
111
+ <th>Type</th>
112
+ <th>Values</th>
113
+ <th>Default</th>
114
+ </tr>
115
+ </thead>
116
+ <tbody>
117
+ <% global_prop_data.each do |key, value|%>
118
+ <tr>
119
+ <td>
120
+ <%= pb_rails("title", props: { text: key, tag: "h4", size: 4 }) %>
121
+ </td>
122
+ <td>
123
+ <%= pb_rails("card", props: {
124
+ classname: "card",
125
+ padding: "xxs",
126
+ background: "light",
127
+ border_none: true,
128
+ border_radius: "sm"
129
+ }) do %>
130
+ <%= pb_rails("body", props: {
131
+ classname: "kearning"
132
+ }) do %>
133
+ <%= value[:type].downcase %>
134
+ <% end %>
135
+ <% end %>
136
+ </td>
137
+ <td>
138
+ <% if value[:values].present? %>
139
+ <% value[:values].each do |item| %>
140
+ <% if item != nil %>
141
+ <%= pb_rails("card", props: {
142
+ flex_direction: "row",
143
+ classname: "card",
144
+ padding: "xxs",
145
+ background: "light",
146
+ border_none: true,
147
+ border_radius: "sm",
148
+ margin: "xxs"
149
+ }) do %>
150
+ <%= pb_rails("body", props: {
151
+ classname: "kearning"
152
+ }) do %>
153
+ <%= item %>
154
+ <% end %>
155
+ <% end %>
156
+ <% end %>
157
+ <% end %>
158
+ <% end %>
159
+ </td>
160
+ <td>
161
+ <% if value[:default].present? || value[:default].is_a?(TrueClass) || value[:default].is_a?(FalseClass) %>
162
+ <%= pb_rails("card", props: {
163
+ classname: "card",
164
+ padding: "xxs",
165
+ background: "light",
166
+ border_none: true,
167
+ border_radius: "sm"
168
+ }) do %>
169
+ <%= pb_rails("body", props: {
170
+ classname: "kearning"
171
+ }) do %>
172
+ <%= value[:default] %>
173
+ <% end %>
174
+ <% end %>
175
+ <% end %>
176
+ </td>
177
+ </tr>
178
+ <% end %>
179
+ </tbody>
180
+ <% end %>
181
+ <%= pb_rails("table", props: {container: false, disable_hover: true, id: "local-prop-table", classname: "local-active"}) do %>
182
+ <thead>
183
+ <tr>
184
+ <th>Props</th>
185
+ <th>Type</th>
186
+ <th>Values</th>
187
+ <th>Default</th>
188
+ </tr>
189
+ </thead>
190
+ <tbody>
191
+ <% local_prop_data.each do |key, value|%>
192
+ <tr>
193
+ <td>
194
+ <%= pb_rails("title", props: { text: key, tag: "h4", size: 4 }) %>
195
+ </td>
196
+ <td>
197
+ <%= pb_rails("card", props: {
198
+ classname: "card",
199
+ padding: "xxs",
200
+ background: "light",
201
+ border_none: true,
202
+ border_radius: "sm"
203
+ }) do %>
204
+ <%= pb_rails("body", props: {
205
+ classname: "kearning"
206
+ }) do %>
207
+ <%= value[:type].downcase %>
208
+ <% end %>
209
+ <% end %>
210
+ </td>
211
+ <td>
212
+ <% if value[:values].present? %>
213
+ <% value[:values].each do |item| %>
214
+ <% if item != nil %>
215
+ <%= pb_rails("card", props: {
216
+ flex_direction: "row",
217
+ classname: "card",
218
+ padding: "xxs",
219
+ background: "light",
220
+ border_none: true,
221
+ border_radius: "sm",
222
+ margin: "xxs"
223
+ }) do %>
224
+ <%= pb_rails("body", props: {
225
+ classname: "kearning"
226
+ }) do %>
227
+ <%= item %>
228
+ <% end %>
229
+ <% end %>
230
+ <% end %>
231
+ <% end %>
232
+ <% end %>
233
+ </td>
234
+ <td>
235
+ <% if value[:default].present? || value[:default].is_a?(TrueClass) || value[:default].is_a?(FalseClass) %>
236
+ <%= pb_rails("card", props: {
237
+ classname: "card",
238
+ padding: "xxs",
239
+ background: "light",
240
+ border_none: true,
241
+ border_radius: "sm"
242
+ }) do %>
243
+ <%= pb_rails("body", props: {
244
+ classname: "kearning"
245
+ }) do %>
246
+ <%= value[:default] %>
247
+ <% end %>
248
+ <% end %>
249
+ <% end %>
250
+ </td>
251
+ </tr>
252
+ <% end %>
253
+ </tbody>
8
254
  <% end %>
9
255
  <% end %>
10
256
  <% end %>
11
- <% end %>
12
- </div>
257
+ </div>
258
+ <% end %>
259
+
260
+ <script>
261
+
262
+ const globalNavAndTable = document.querySelectorAll('.global-active');
263
+ const localNavAndTable = document.querySelectorAll('.local-active');
264
+
265
+ globalNavAndTable.forEach(element => {
266
+ element.style.display = 'none';
267
+ });
268
+
269
+ const globalButton = document.getElementById("global-button");
270
+ if (globalButton) {
271
+ globalButton.addEventListener("click", showGlobal);
272
+ }
273
+
274
+ const localButton = document.getElementById("local-button");
275
+ if (localButton) {
276
+ localButton.addEventListener("click", showLocal);
277
+ }
278
+
279
+ function showGlobal() {
280
+ localNavAndTable.forEach(element => {
281
+ element.style.display = 'none';
282
+ });
283
+
284
+ globalNavAndTable.forEach(element => {
285
+ element.style.display = 'table';
286
+ });
287
+ }
288
+
289
+ function showLocal() {
290
+ localNavAndTable.forEach(element => {
291
+ element.style.display = 'table';
292
+ });
293
+
294
+ globalNavAndTable.forEach(element => {
295
+ element.style.display = 'none';
296
+ });
297
+ }
298
+
299
+ </script>
@@ -5,6 +5,48 @@ module Playbook
5
5
  class KitApi < Playbook::KitBase
6
6
  prop :kit, type: Playbook::Props::String, required: true
7
7
 
8
+ def kit_local_props
9
+ local = []
10
+ kit_props.each do |key, value|
11
+ value.kit != Playbook::KitBase && local.push({ key: key, value: value })
12
+ end
13
+ local
14
+ end
15
+
16
+ def local_prop_data
17
+ local_props = {}
18
+
19
+ kit_local_props.each do |key, _value|
20
+ name = key[:value].instance_variable_get(:@name)
21
+ type = key[:value].class.to_s.split("::").last
22
+ default = key[:value].instance_variable_get(:@default)
23
+ values = key[:value].instance_variable_get(:@values)
24
+ local_props[name.to_sym] = { "type": type, "default": default, "values": values }
25
+ end
26
+ local_props
27
+ end
28
+
29
+ def kit_global_props
30
+ global = []
31
+ kit_props.each do |key, value|
32
+ value.kit == Playbook::KitBase && global.push({ key: key, value: value })
33
+ end
34
+ global
35
+ end
36
+
37
+ def global_prop_data
38
+ global_props = {}
39
+
40
+ kit_global_props.each do |key, _value|
41
+ name = key[:value].instance_variable_get(:@name)
42
+ type = key[:value].class.to_s.split("::").last
43
+ default = key[:value].instance_variable_get(:@default)
44
+ values = key[:value].instance_variable_get(:@values)
45
+ global_props[name.to_sym] = { "type": type, "default": default, "values": values }
46
+ end
47
+ global_props
48
+ end
49
+
8
50
  def kit_props
9
51
  kit_class.props
10
52
  end
@@ -1,3 +1,5 @@
1
+ <% example_html = ERB.new(example).result %>
2
+
1
3
  <%= pb_rails("card", props: { classname: "pb--doc", padding: "none", dark: dark }) do %>
2
4
  <div class="pb--kit-example">
3
5
  <%= pb_rails("caption", props: { text: example_title, dark: dark }) %>
@@ -13,6 +15,13 @@
13
15
  <div id="code-wrapper">
14
16
  <div class="pb--codeControls">
15
17
  <ul>
18
+ <% if type == "rails" %>
19
+ <li>
20
+ <a href="#" id="copy-<%= example_key %>-trigger" onclick="copyOnClick(`<%= example_html %>`, `copy-<%= example_key %>`)">
21
+ Copy HTML
22
+ </a>
23
+ </li>
24
+ <% end %>
16
25
  <li>
17
26
  <a href="#" id="toggle-open" data-toggle="code_example">Code Example</a>
18
27
  </li>
@@ -26,3 +35,11 @@
26
35
  </div>
27
36
  <% end %>
28
37
  <% end %>
38
+
39
+ <script>
40
+ function copyOnClick(content, elementID) {
41
+ copyContent(content)
42
+ }
43
+
44
+ </script>
45
+
@@ -33,12 +33,29 @@ module Playbook
33
33
  def source
34
34
  @source ||= begin
35
35
  extension = type == "react" ? "jsx" : "html.erb"
36
- read_kit_file("_#{example_key}.#{extension}")
36
+ stringified_code = read_kit_file("_#{example_key}.#{extension}")
37
+ sanitize_code(stringified_code)
37
38
  end
38
39
  end
39
40
 
40
41
  private
41
42
 
43
+ def sanitize_code(stringified_code)
44
+ stringified_code = stringified_code.gsub('"../.."', '"playbook-ui"')
45
+ .gsub('"../../"', '"playbook-ui"')
46
+ .gsub("'../../'", "'playbook-ui'")
47
+ .gsub("'../..'", "'playbook-ui'")
48
+ .gsub(%r{from "../.*}, "from 'playbook-ui'")
49
+ .gsub(%r{from '../.*}, "from 'playbook-ui'")
50
+ stringified_code = dark ? stringified_code.gsub("{...props}", "dark") : stringified_code.gsub(/\s*{...props}\s*\n/, "\n")
51
+ if stringified_code.include?("props: { ")
52
+ stringified_code = stringified_code.gsub("props: {", "props: {dark: true,") if type == "rails" && dark
53
+ elsif type == "rails" && dark
54
+ stringified_code = stringified_code.gsub("props: {", "props: {\n dark: true,")
55
+ end
56
+ stringified_code
57
+ end
58
+
42
59
  def read_kit_file(*args)
43
60
  path = ::Playbook.kit_path(kit, "docs", *args)
44
61
  path.exist? ? path.read : ""
@@ -2,7 +2,7 @@ import React from 'react'
2
2
 
3
3
  import Image from '../_image'
4
4
 
5
- const DefaultImage = (props: any) => {
5
+ const DefaultImage = (props) => {
6
6
  return (
7
7
  <>
8
8
  <br />
@@ -4,6 +4,7 @@ import Slides from './Slides'
4
4
  import Thumbnails from './Thumbnails'
5
5
 
6
6
  type CarouselType = {
7
+ initialPhoto?: string,
7
8
  onClose?: () => void,
8
9
  icon?: string,
9
10
  currentIndex: number,
@@ -12,11 +12,11 @@ type LightboxType = {
12
12
  aria?: {[key: string]: string},
13
13
  children: React.ReactNode[] | React.ReactNode | string,
14
14
  className?: string,
15
- currentPhotoIndex?: number,
16
15
  data?: {[key: string]: string | number},
17
16
  description?: string | any,
18
17
  id?: string,
19
18
  photos: [],
19
+ initialPhoto?: number,
20
20
  onChange?: (index: number)=> {},
21
21
  onClickRight?: () => void,
22
22
  onClose?: () => void,
@@ -31,10 +31,10 @@ const Lightbox = (props: LightboxType): React.ReactNode => {
31
31
  aria = {},
32
32
  children,
33
33
  className,
34
- currentPhotoIndex,
35
34
  data = {},
36
35
  description,
37
36
  id = '',
37
+ initialPhoto = 0,
38
38
  photos,
39
39
  onChange = ()=>{},
40
40
  onClose,
@@ -44,15 +44,12 @@ const Lightbox = (props: LightboxType): React.ReactNode => {
44
44
  title,
45
45
  } = props
46
46
 
47
- const [activePhoto, setActivePhoto] = useState(0)
47
+ const [activePhoto, setActivePhoto] = useState(initialPhoto)
48
+
48
49
  useEffect(() => {
49
50
  onChange(activePhoto)
50
51
  },[activePhoto])
51
52
 
52
- useEffect(() => {
53
- setActivePhoto(currentPhotoIndex)
54
- },[currentPhotoIndex])
55
-
56
53
  const ariaProps = buildAriaProps(aria)
57
54
  const dataProps = buildDataProps(data)
58
55
  const classes = classnames(
@@ -10,14 +10,17 @@ const LightboxCompoundComponent = (props) => {
10
10
  'https://images.unsplash.com/photo-1501045337096-542a73dafa4f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2052&q=80',
11
11
  'https://images.unsplash.com/photo-1563693998336-93c10e5d8f91?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80,',
12
12
  ]
13
+ const [selectedPhoto, setSelectedPhoto] = useState(0)
13
14
  const [showLightbox, toggleShowLightbox] = useState(false)
14
15
 
15
16
  const handleCloseLightbox = () => {
16
17
  toggleShowLightbox(!showLightbox)
18
+ setSelectedPhoto(null)
17
19
  }
18
20
 
19
- const onPhotoClick = () => {
21
+ const onPhotoClick = (photo) => {
20
22
  toggleShowLightbox(!showLightbox)
23
+ setSelectedPhoto(photo)
21
24
  }
22
25
 
23
26
  const exampleStyles = {
@@ -31,6 +34,7 @@ const LightboxCompoundComponent = (props) => {
31
34
  {showLightbox ? (
32
35
  <Lightbox
33
36
  description='Description Content Goes Here.'
37
+ initialPhoto={selectedPhoto}
34
38
  onClose={handleCloseLightbox}
35
39
  photos={photos}
36
40
  title='Windows, Sidings, & Gutters'
@@ -10,14 +10,17 @@ const LightboxCustomHeader = (props) => {
10
10
  "https://images.unsplash.com/photo-1501045337096-542a73dafa4f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2052&q=80",
11
11
  "https://images.unsplash.com/photo-1563693998336-93c10e5d8f91?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80,",
12
12
  ];
13
+ const [selectedPhoto, setSelectedPhoto] = useState(0);
13
14
  const [showLightbox, toggleShowLightbox] = useState(false);
14
15
 
15
16
  const handleCloseLightbox = () => {
16
17
  toggleShowLightbox(!showLightbox);
18
+ setSelectedPhoto(null);
17
19
  };
18
20
 
19
- const onPhotoClick = () => {
21
+ const onPhotoClick = (photo) => {
20
22
  toggleShowLightbox(!showLightbox);
23
+ setSelectedPhoto(photo);
21
24
  };
22
25
 
23
26
  const exampleStyles = {
@@ -52,6 +55,7 @@ const LightboxCustomHeader = (props) => {
52
55
  {showLightbox ? (
53
56
  <Lightbox
54
57
  description={customDescription}
58
+ initialPhoto={selectedPhoto}
55
59
  navRight="All Photos"
56
60
  onClickRight={()=> alert("Clicked!")}
57
61
  onClose={handleCloseLightbox}
@@ -8,14 +8,17 @@ const LightboxDefault = (props) => {
8
8
  const photos = [
9
9
  'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
10
10
  ]
11
+ const [selectedPhoto, setSelectedPhoto] = useState(0)
11
12
  const [showLightbox, toggleShowLightbox] = useState(false)
12
13
 
13
14
  const handleCloseLightbox = () => {
14
15
  toggleShowLightbox(!showLightbox)
16
+ setSelectedPhoto(null)
15
17
  }
16
18
 
17
- const onPhotoClick = () => {
19
+ const onPhotoClick = (photoIndex) => {
18
20
  toggleShowLightbox(!showLightbox)
21
+ setSelectedPhoto(photoIndex)
19
22
  }
20
23
 
21
24
  return (
@@ -24,6 +27,7 @@ const LightboxDefault = (props) => {
24
27
  {showLightbox ? (
25
28
  <Lightbox
26
29
  icon="times"
30
+ initialPhoto={selectedPhoto}
27
31
  onClose={handleCloseLightbox}
28
32
  photos={photos}
29
33
  {...props}
@@ -1 +1 @@
1
- Lightbox contains several props: `photos` (an array of urls), `onClickLeft` (an optional callback function for top left close button), `title` and `description` (string or custom components), `icon` ( optional prop for the close button in the top left of the header), `navRight` (optional prop that renders clickable text in the top right section of the header), `onClickRight` (optional callback function of navRight) and `onChange` (optional event handler prop exposing index of current photo).
1
+ Lightbox contains several props: `photos` (an array of urls), `initialPhoto` (a number), `onClickLeft` (an optional callback function for top left close button), `title` and `description` (string or custom components), `icon` ( optional prop for the close button in the top left of the header), `navRight` (optional prop that renders clickable text in the top right section of the header), `onClickRight` (optional callback function of navRight) and `onChange` (optional event handler prop exposing index of current photo).
@@ -29,14 +29,17 @@ const LightboxMultiple = (props) => {
29
29
  'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
30
30
  'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
31
31
  ]
32
+ const [selectedPhoto, setSelectedPhoto] = useState(0)
32
33
  const [light, toggleLight] = useState(false)
33
34
 
34
35
  const handleCloseLightbox = () => {
35
36
  toggleLight(!light)
37
+ setSelectedPhoto(null)
36
38
  }
37
39
 
38
- const onPhotoClick = () => {
40
+ const onPhotoClick = (photo) => {
39
41
  toggleLight(!light)
42
+ setSelectedPhoto(photo)
40
43
  }
41
44
 
42
45
  const exampleStyles = {
@@ -49,6 +52,7 @@ const LightboxMultiple = (props) => {
49
52
  {light ? (
50
53
  <Lightbox
51
54
  icon="times"
55
+ initialPhoto={selectedPhoto}
52
56
  onChange={(index) => console.log(`current photo index: ${index}`)}
53
57
  onClose={handleCloseLightbox}
54
58
  photos={photos}
@@ -5,4 +5,3 @@ examples:
5
5
  - lightbox_multiple: Multiple
6
6
  - lightbox_compound_component: Compound Component
7
7
  - lightbox_custom_header: Custom Header
8
- - lightbox_current_photo: Current Photo
@@ -2,4 +2,3 @@ export { default as LightboxDefault } from './_lightbox_default.jsx'
2
2
  export { default as LightboxMultiple } from './_lightbox_multiple.jsx'
3
3
  export { default as LightboxCompoundComponent } from './_lightbox_compound_component.jsx'
4
4
  export { default as LightboxCustomHeader } from './_lightbox_custom_header'
5
- export { default as LightboxCurrentPhoto } from './_lightbox_current_photo'
@@ -18,6 +18,7 @@ test('Kit renders', () => {
18
18
  data={{ testid: testId }}
19
19
  icon="close"
20
20
  id="test1"
21
+ initialPhoto={1}
21
22
  onClose={() => {}}
22
23
  photos={TEST_PHOTOS}
23
24
  />
@@ -34,6 +35,7 @@ test('Shows selected images', () => {
34
35
  data={{ testid: testId }}
35
36
  icon="close"
36
37
  id="test1"
38
+ initialPhoto={1}
37
39
  onClose={() => {}}
38
40
  photos={TEST_PHOTOS}
39
41
  />
@@ -41,7 +43,7 @@ test('Shows selected images', () => {
41
43
  const kit = screen.getByTestId(testId)
42
44
  const slide = kit.getElementsByClassName('Slide')[0]
43
45
  const image = slide.getElementsByTagName('img')[0]
44
- expect(image).toHaveAttribute('src', TEST_PHOTOS[0])
46
+ expect(image).toHaveAttribute('src', TEST_PHOTOS[1])
45
47
 
46
48
  const thumbnails = kit.getElementsByClassName('Thumbnail')
47
49
 
@@ -75,6 +77,7 @@ test('Closes on escape key', async () => {
75
77
  data={{ testid: testId }}
76
78
  icon="close"
77
79
  id="test1"
80
+ initialPhoto={0}
78
81
  onClose={mockClose}
79
82
  photos={TEST_PHOTOS}
80
83
  />
@@ -103,6 +106,7 @@ test('Closes on close button', async () => {
103
106
  data={{ testid: testId }}
104
107
  icon="close"
105
108
  id="test1"
109
+ initialPhoto={0}
106
110
  onClose={mockClose}
107
111
  photos={TEST_PHOTOS}
108
112
  />
@@ -6,7 +6,7 @@ import {
6
6
  offset,
7
7
  Placement,
8
8
  safePolygon,
9
- shift,
9
+ shift,
10
10
  useFloating,
11
11
  useHover,
12
12
  useInteractions,
@@ -17,9 +17,6 @@ import { GlobalProps, globalProps } from "../utilities/globalProps"
17
17
  import { buildAriaProps, buildDataProps } from "../utilities/props"
18
18
  import Flex from "../pb_flex/_flex"
19
19
 
20
-
21
-
22
-
23
20
  type TooltipProps = {
24
21
  aria?: { [key: string]: string },
25
22
  className?: string | string[],
@@ -29,8 +26,8 @@ type TooltipProps = {
29
26
  icon?: string,
30
27
  interaction?: boolean,
31
28
  placement?: Placement,
29
+ position: "absolute" | "fixed";
32
30
  text: string,
33
- zIndex?: Pick<GlobalProps, "ZIndex">,
34
31
  } & GlobalProps
35
32
 
36
33
  const Tooltip = (props: TooltipProps): React.ReactElement => {
@@ -43,6 +40,7 @@ const Tooltip = (props: TooltipProps): React.ReactElement => {
43
40
  icon = null,
44
41
  interaction = false,
45
42
  placement: preferredPlacement = "top",
43
+ position = "absolute",
46
44
  text,
47
45
  zIndex,
48
46
  ...rest
@@ -50,24 +48,26 @@ const Tooltip = (props: TooltipProps): React.ReactElement => {
50
48
 
51
49
  const dataProps: { [key: string]: any } = buildDataProps(data)
52
50
  const ariaProps: { [key: string]: any } = buildAriaProps(aria)
53
-
51
+
54
52
  const css = classnames(
55
53
  globalProps({...rest}),
56
54
  className,
57
55
  )
58
56
  const [open, setOpen] = useState(false)
59
57
  const arrowRef = useRef(null)
60
- const {
61
58
 
59
+
60
+ const {
62
61
  context,
63
62
  floating,
64
- middlewareData: { arrow: { x: arrowX, y: arrowY } = {} },
63
+ middlewareData: { arrow: { x: arrowX, y: arrowY } = {}, },
65
64
  placement,
66
65
  reference,
67
66
  strategy,
68
67
  x,
69
68
  y,
70
69
  } = useFloating({
70
+ strategy: position,
71
71
  middleware: [
72
72
  arrow({
73
73
  element: arrowRef,
@@ -87,6 +87,7 @@ const Tooltip = (props: TooltipProps): React.ReactElement => {
87
87
  placement: preferredPlacement
88
88
  })
89
89
 
90
+
90
91
  const { getFloatingProps } = useInteractions([
91
92
  useHover(context, {
92
93
  delay,
@@ -142,7 +143,7 @@ const Tooltip = (props: TooltipProps): React.ReactElement => {
142
143
  className="arrow_bg"
143
144
  ref={arrowRef}
144
145
  style={{
145
- position: strategy,
146
+ position: "absolute",
146
147
  left: arrowX != null ? `${arrowX}px` : "",
147
148
  top: arrowY != null ? `${arrowY}px` : "",
148
149
  [staticSide]: "-5px",
@@ -65,3 +65,32 @@ test("closes on mouseleave", async () => {
65
65
 
66
66
  cleanup();
67
67
  });
68
+
69
+ test("has default position absolute", async () => {
70
+ render(<TooltipTest />);
71
+
72
+ fireEvent.mouseEnter(screen.getByRole("tooltip_trigger"));
73
+ await waitFor(() => {
74
+ expect(screen.queryByRole("tooltip")).toHaveStyle({"position": "absolute"});
75
+ cleanup();
76
+ })
77
+
78
+ cleanup();
79
+ });
80
+
81
+ test("has position fixed", async () => {
82
+ render(
83
+ <Tooltip
84
+ data={{ testid: "fixed-position-test" }}
85
+ position="fixed"
86
+ />
87
+ );
88
+
89
+ fireEvent.mouseEnter(screen.getByRole("tooltip_trigger"));
90
+ await waitFor(() => {
91
+ expect(screen.queryByRole("tooltip")).toHaveStyle({"position": "fixed"});
92
+ cleanup();
93
+ })
94
+
95
+ cleanup();
96
+ });
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Playbook
4
4
  PREVIOUS_VERSION = "12.16.0"
5
- VERSION = "12.16.0.pre.alpha.lightboxcurrentphotoprop531"
5
+ VERSION = "12.16.0.pre.alpha.tooltippositionprop566"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playbook_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.16.0.pre.alpha.lightboxcurrentphotoprop531
4
+ version: 12.16.0.pre.alpha.tooltippositionprop566
5
5
  platform: ruby
6
6
  authors:
7
7
  - Power UX
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-25 00:00:00.000000000 Z
12
+ date: 2023-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -1221,7 +1221,7 @@ files:
1221
1221
  - app/pb_kits/playbook/pb_image/docs/_custom_error_image.html.erb
1222
1222
  - app/pb_kits/playbook/pb_image/docs/_custom_error_image.jsx
1223
1223
  - app/pb_kits/playbook/pb_image/docs/_default_image.html.erb
1224
- - app/pb_kits/playbook/pb_image/docs/_default_image.tsx
1224
+ - app/pb_kits/playbook/pb_image/docs/_default_image.jsx
1225
1225
  - app/pb_kits/playbook/pb_image/docs/_description.md
1226
1226
  - app/pb_kits/playbook/pb_image/docs/_rounded_image.html.erb
1227
1227
  - app/pb_kits/playbook/pb_image/docs/_rounded_image.jsx
@@ -1332,8 +1332,6 @@ files:
1332
1332
  - app/pb_kits/playbook/pb_lightbox/docs/_description.md
1333
1333
  - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_compound_component.jsx
1334
1334
  - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_compound_component.md
1335
- - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_current_photo.jsx
1336
- - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_current_photo.md
1337
1335
  - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_custom_header.jsx
1338
1336
  - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_custom_header.md
1339
1337
  - app/pb_kits/playbook/pb_lightbox/docs/_lightbox_default.jsx
@@ -1,121 +0,0 @@
1
- /* @flow */
2
- /* eslint-disable jsx-control-statements/jsx-use-if-tag */
3
- import React, { useState } from 'react'
4
- import { Flex, Image, Button, Body, FlexItem } from '../../'
5
- import Lightbox from '../_lightbox.tsx'
6
-
7
- const LightboxCurrentPhoto = (props) => {
8
- const photos = [
9
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
10
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
11
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
12
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
13
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
14
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
15
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
16
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
17
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
18
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
19
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
20
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
21
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
22
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
23
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
24
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
25
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
26
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
27
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
28
- 'https://images.unsplash.com/photo-1638727228877-d2a79ab75e68?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2668&q=80',
29
- 'https://images.unsplash.com/photo-1526657782461-9fe13402a841?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1984&q=80',
30
- 'https://images.unsplash.com/photo-1523057530100-383d7fbc77a1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2669&q=80',
31
- ]
32
- const [light, toggleLight] = useState(false)
33
- //Setting state with the index of the current slide exposed by the onChange prop
34
- const [active, setActive] = useState(0)
35
- //Setting state for the current photo to pass to the kit
36
- const [currentPhoto, setCurrentPhoto] = useState(active)
37
-
38
- const handleCloseLightbox = () => {
39
- toggleLight(!light)
40
- }
41
-
42
- const onPhotoClick = () => {
43
- toggleLight(!light)
44
- }
45
-
46
- const exampleStyles = {
47
- width: "100%",
48
- overflow: "auto"
49
- }
50
-
51
- return (
52
- <div className="lightbox_doc_example_custom">
53
- {light ? (
54
- <>
55
- <Flex alignItems="center"
56
- className='custom_lightbox_sidebar'
57
- justifyContent="center"
58
- >
59
- <Flex margin='lg'
60
- orientation='column'
61
- >
62
- <Body marginBottom='md'>
63
- This UI is for demonstration purposes only to demonstrate how external buttons can be used to change the slides.
64
- </Body>
65
- <FlexItem alignSelf="center">
66
- <Flex justifyContent="center">
67
- <Button
68
- onClick={()=> setCurrentPhoto(active > 0 ? active - 1 : 0)}
69
- >
70
- Back
71
- </Button>
72
- <Button marginLeft='sm'
73
- onClick={() => setCurrentPhoto(active < photos.length - 1 ? active + 1 : photos.length - 1)}
74
- >
75
- Next
76
- </Button>
77
- </Flex>
78
- </FlexItem>
79
- </Flex>
80
- </Flex>
81
- <Lightbox
82
- currentPhotoIndex={currentPhoto}
83
- icon="times"
84
- onChange={(index) => setActive(index)}
85
- onClose={handleCloseLightbox}
86
- photos={photos}
87
- {...props}
88
- />
89
- </>
90
- ) : (
91
- <div
92
- className="PhotoViewer"
93
- style={exampleStyles}
94
- >
95
- <Flex>
96
- {photos.map((photo, index) => {
97
- return (
98
- <div
99
- key={index}
100
- onClick={() => onPhotoClick(index)}
101
- >
102
- <Image
103
- cursor="pointer"
104
- marginRight="xl"
105
- rounded
106
- size="lg"
107
- url={photo}
108
- />
109
-
110
- <div className="overlay" />
111
- </div>
112
- )
113
- })}
114
- </Flex>
115
- </div>
116
- )}
117
- </div>
118
- )
119
- }
120
-
121
- export default LightboxCurrentPhoto
@@ -1 +0,0 @@
1
- The `currentPhotoIndex` prop allows the user to pass a number to the lightbox that will set the current slide by index. This can be leveraged if the user wants to change slides using custom buttons. To do this, the user must also make use of the current slide's index that is exposed by the `onChange` prop.