playbook_ui 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/playbook/application_controller.rb +1 -0
  3. data/app/controllers/playbook/pages_controller.rb +0 -4
  4. data/app/controllers/playbook/samples_controller.rb +40 -0
  5. data/app/helpers/playbook/pb_doc_helper.rb +7 -1
  6. data/app/helpers/playbook/pb_sample_helper.rb +19 -0
  7. data/app/helpers/playbook/redcarpet_helper.rb +1 -1
  8. data/app/pb_kits/playbook/_playbook.scss +1 -0
  9. data/app/pb_kits/playbook/config/_kit_samples_list.html.erb +3 -0
  10. data/app/pb_kits/playbook/config/_kit_ui.html.slim +9 -5
  11. data/app/pb_kits/playbook/data/menu.yml +4 -0
  12. data/app/pb_kits/playbook/index.js +2 -0
  13. data/app/pb_kits/playbook/kits/pb_flex.js +4 -0
  14. data/app/pb_kits/playbook/kits/pb_highlight.js +4 -0
  15. data/app/pb_kits/playbook/packs/examples.js +4 -0
  16. data/app/pb_kits/playbook/packs/kits/pb_highlight.js +2 -0
  17. data/app/pb_kits/playbook/packs/kits/pb_popover.js +1 -0
  18. data/app/pb_kits/playbook/packs/main.scss +3 -0
  19. data/app/pb_kits/playbook/packs/samples.js +50 -0
  20. data/app/pb_kits/playbook/packs/site_styles/_samples.scss +71 -0
  21. data/app/pb_kits/playbook/packs/site_styles/_site-style.scss +6 -0
  22. data/app/pb_kits/playbook/packs/site_styles/docs/_flex_examples.scss +11 -3
  23. data/app/pb_kits/playbook/pb_body/_body.html.erb +1 -1
  24. data/app/pb_kits/playbook/pb_body/_body.jsx +10 -1
  25. data/app/pb_kits/playbook/pb_body/body.rb +17 -1
  26. data/app/pb_kits/playbook/pb_editor/_editor.html.erb +6 -0
  27. data/app/pb_kits/playbook/pb_hashtag/_hashtag.jsx +2 -1
  28. data/app/pb_kits/playbook/pb_hashtag/docs/_hashtag_dark.html.erb +4 -0
  29. data/app/pb_kits/playbook/pb_hashtag/docs/_hashtag_dark.jsx +7 -0
  30. data/app/pb_kits/playbook/pb_hashtag/docs/_hashtag_default.html.erb +4 -0
  31. data/app/pb_kits/playbook/pb_hashtag/docs/_hashtag_default.jsx +6 -0
  32. data/app/pb_kits/playbook/pb_hashtag/hashtag.rb +3 -1
  33. data/app/pb_kits/playbook/pb_highlight/_highlight.html.erb +6 -0
  34. data/app/pb_kits/playbook/pb_highlight/_highlight.jsx +38 -0
  35. data/app/pb_kits/playbook/pb_highlight/_highlight.scss +6 -0
  36. data/app/pb_kits/playbook/pb_highlight/docs/_highlight_default.html.erb +20 -0
  37. data/app/pb_kits/playbook/pb_highlight/docs/_highlight_default.jsx +26 -0
  38. data/app/pb_kits/playbook/pb_highlight/docs/example.yml +9 -0
  39. data/app/pb_kits/playbook/pb_highlight/docs/index.js +1 -0
  40. data/app/pb_kits/playbook/pb_highlight/highlight.rb +17 -0
  41. data/app/pb_kits/playbook/pb_popover/_popover.html.erb +1 -1
  42. data/app/pb_kits/playbook/pb_popover/_popover.js +13 -22
  43. data/app/pb_kits/playbook/pb_popover/_popover.jsx +121 -0
  44. data/app/pb_kits/playbook/pb_popover/_popover.scss +4 -0
  45. data/app/pb_kits/playbook/pb_popover/docs/_popover_default.jsx +29 -0
  46. data/app/pb_kits/playbook/pb_popover/docs/_popover_list.jsx +46 -0
  47. data/app/pb_kits/playbook/pb_popover/docs/_popover_portal.jsx +36 -0
  48. data/app/pb_kits/playbook/pb_popover/docs/_popover_with_button.jsx +35 -0
  49. data/app/pb_kits/playbook/pb_popover/docs/example.yml +4 -0
  50. data/app/pb_kits/playbook/pb_popover/docs/index.js +4 -0
  51. data/app/pb_kits/playbook/pb_popover/popover.rb +1 -1
  52. data/app/pb_kits/playbook/pb_select/_select.jsx +51 -51
  53. data/app/pb_kits/playbook/pb_select/docs/_select_blank.jsx +8 -14
  54. data/app/pb_kits/playbook/pb_select/docs/_select_dark.jsx +17 -15
  55. data/app/pb_kits/playbook/pb_select/docs/_select_dark_error.jsx +17 -15
  56. data/app/pb_kits/playbook/pb_select/docs/_select_default.jsx +16 -15
  57. data/app/pb_kits/playbook/pb_select/docs/_select_disabled.jsx +8 -14
  58. data/app/pb_kits/playbook/pb_select/docs/_select_disabled_options.jsx +31 -29
  59. data/app/pb_kits/playbook/pb_select/docs/_select_error.jsx +17 -15
  60. data/app/pb_kits/playbook/pb_select/docs/_select_required.jsx +7 -11
  61. data/app/pb_kits/playbook/pb_select/docs/_select_value_text_same.jsx +8 -14
  62. data/app/pb_kits/playbook/pb_selectable_card/_selectable_card.jsx +2 -2
  63. data/app/pb_kits/playbook/pb_textarea/_textarea.jsx +2 -2
  64. data/app/pb_kits/playbook/pb_toggle/_toggle.jsx +3 -3
  65. data/app/pb_kits/playbook/types.js +1 -1
  66. data/app/pb_kits/playbook/vendor.js +2 -2
  67. data/app/views/layouts/playbook/samples.html.erb +37 -0
  68. data/app/views/playbook/pages/kit_show.html.slim +1 -1
  69. data/app/views/playbook/pages/principles.html.slim +1 -1
  70. data/app/views/playbook/samples/dashboards/dashboards.html.erb +82 -0
  71. data/app/views/playbook/samples/dashboards/dashboards.jsx +35 -0
  72. data/app/views/playbook/samples/sample_show.html.erb +25 -0
  73. data/lib/playbook/version.rb +1 -1
  74. metadata +32 -5
  75. data/app/pb_kits/playbook/config/_kit_example.html.slim +0 -5
@@ -4,7 +4,8 @@ module Playbook
4
4
  module PbBody
5
5
  class Body
6
6
  include Playbook::Props
7
-
7
+ include ActionView::Helpers
8
+
8
9
  partial "pb_body/body"
9
10
 
10
11
  prop :color, type: Playbook::Props::Enum,
@@ -19,13 +20,28 @@ module Playbook
19
20
  values: %w[h1 h2 h3 h4 h5 h6 p span div],
20
21
  default: "div"
21
22
  prop :text
23
+ prop :highlighting, type: Playbook::Props::Boolean,
24
+ default: false
25
+ prop :highlighted_text, type: Playbook::Props::Array,
26
+ default: []
22
27
 
23
28
  def classname
24
29
  generate_classname("pb_body_kit", color_class, dark_class, status_class)
25
30
  end
26
31
 
32
+ def content
33
+ highlighting ? apply_highlight : text
34
+ end
35
+
27
36
  private
28
37
 
38
+ def apply_highlight
39
+ pb_highlight = Playbook::PbHighlight::Highlight.new() {"|"}
40
+ pb_highlight_output = ApplicationController.renderer.render(partial: pb_highlight, as: :object)
41
+ highlight_tags = pb_highlight_output.split("|")
42
+ highlight(text, highlighted_text, highlighter: "#{highlight_tags.first.html_safe} \\1 #{highlight_tags.last.html_safe}")
43
+ end
44
+
29
45
  def color_class
30
46
  color != "default" ? color : nil
31
47
  end
@@ -0,0 +1,6 @@
1
+ <%= content_tag(:div,
2
+ id: object.id,
3
+ data: object.data,
4
+ class: object.classname) do %>
5
+ <span>EDITOR CONTENT</span>
6
+ <% end %>
@@ -13,13 +13,14 @@ type HashtagProps = {
13
13
  dark?: Boolean,
14
14
  id?: String,
15
15
  text?: String,
16
- type: 'default' | 'home' | 'project',
16
+ type: 'default' | 'home' | 'project' | 'appointment',
17
17
  url?: String,
18
18
  }
19
19
 
20
20
  const typeMap = {
21
21
  'home': 'H#',
22
22
  'project': 'P#',
23
+ 'appointment': 'A#',
23
24
  'default': '#',
24
25
  }
25
26
 
@@ -6,4 +6,8 @@
6
6
 
7
7
  <br/><br/>
8
8
 
9
+ <%= pb_rails("hashtag", props: {text: "345678", url: "https://google.com", type: "appointment", dark: true}) %>
10
+
11
+ <br/><br/>
12
+
9
13
  <%= pb_rails("hashtag", props: {text: "123456", url: "https://google.com", type: "default", dark: true}) %>
@@ -18,6 +18,13 @@ const HashtagDark = () => {
18
18
  url="https://google.com"
19
19
  />
20
20
  <br />
21
+ <Hashtag
22
+ dark
23
+ text="456789"
24
+ type="appointment"
25
+ url="https://google.com"
26
+ />
27
+ <br />
21
28
  <Hashtag
22
29
  dark
23
30
  text="654321"
@@ -6,4 +6,8 @@
6
6
 
7
7
  <br/><br/>
8
8
 
9
+ <%= pb_rails("hashtag", props: {text: "345678", url: "https://google.com", type: "appointment"}) %>
10
+
11
+ <br/><br/>
12
+
9
13
  <%= pb_rails("hashtag", props: {text: "123456", url: "https://google.com", type: "default"}) %>
@@ -16,6 +16,12 @@ const HashtagDefault = () => {
16
16
  url="https://google.com"
17
17
  />
18
18
  <br />
19
+ <Hashtag
20
+ text="456789"
21
+ type="appointment"
22
+ url="https://google.com"
23
+ />
24
+ <br />
19
25
  <Hashtag
20
26
  text="654321"
21
27
  type="default"
@@ -10,7 +10,7 @@ module Playbook
10
10
  prop :text
11
11
  prop :dark, type: Playbook::Props::Boolean, default: false
12
12
  prop :type, type: Playbook::Props::Enum,
13
- values: %w[default project home],
13
+ values: %w[default project home appointment],
14
14
  default: "default"
15
15
  prop :url
16
16
 
@@ -33,6 +33,8 @@ module Playbook
33
33
  "H#"
34
34
  elsif type === "project"
35
35
  "P#"
36
+ elsif type === "appointment"
37
+ "A#"
36
38
  else
37
39
  "#"
38
40
  end
@@ -0,0 +1,6 @@
1
+ <%= content_tag(:span,
2
+ id: object.id,
3
+ data: object.data,
4
+ class: object.classname) do %>
5
+ <%= object.children.nil? ? object.text : capture(&object.children) %>
6
+ <% end %>
@@ -0,0 +1,38 @@
1
+ /* @flow */
2
+ /* eslint-disable react/no-multi-comp, flowtype/space-before-type-colon */
3
+ import Highlighter from 'react-highlight-words'
4
+ import React from 'react'
5
+
6
+ type HighlightProps = {
7
+ className?: String,
8
+ data?: String,
9
+ id?: String,
10
+ children?: React.Node,
11
+ text?: String,
12
+ highlightedText?: Array<String>
13
+ }
14
+
15
+ const Highlight = ({
16
+ className = 'pb_highlight_kit',
17
+ children,
18
+ data,
19
+ id,
20
+ text,
21
+ highlightedText = ['highlight'],
22
+ }: HighlightProps) => {
23
+ return (
24
+
25
+ <Highlighter
26
+ autoEscape
27
+ data={data}
28
+ highlightClassName={className}
29
+ highlightTag="span"
30
+ id={id}
31
+ searchWords={highlightedText}
32
+ textToHighlight={text || children}
33
+ />
34
+
35
+ )
36
+ }
37
+
38
+ export default Highlight
@@ -0,0 +1,6 @@
1
+ @import "../tokens/colors";
2
+ @import "../tokens/opacity";
3
+
4
+ [class^=pb_highlight_kit] {
5
+ background-color: rgba($yellow,$opacity_2);
6
+ }
@@ -0,0 +1,20 @@
1
+
2
+ <%= pb_rails("highlight", props: {text: "Highlight Kit"})%>
3
+ <br>
4
+ <br>
5
+ <%= pb_rails("title", props: {text: "Kit wrapping",size: 4})%>
6
+ <br>
7
+ <%= pb_rails("body") do%>
8
+ This an example<%= pb_rails("highlight") do%>Highlight Example<% end %>around.
9
+ <% end %>
10
+ <br>
11
+ <br>
12
+ <%= pb_rails("title", props: {text: "Search",size: 4})%>
13
+ </br>
14
+ <%= pb_rails("body", props: {text: "hello helpers are great even highlighting this", highlighting: true, highlighted_text: ["hello","great"]})%>
15
+
16
+ <br>
17
+ <br>
18
+ <%= pb_rails("caption", props: {size: "xs", text: "To enable highlighting make sure the [highlighting] flag is set to true. "}) %>
19
+ <br>
20
+ <br>
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import { Body, Highlight } from '../../'
3
+
4
+ const HighlightDefault = () => (
5
+ <div>
6
+ <Highlight
7
+ highlightedText={['highlight kit']}
8
+ text="This is the Highlight Kit"
9
+ />
10
+ <br />
11
+ <Body>
12
+ {' '}
13
+ {'Hello this is a'}
14
+ {' '}
15
+ <Highlight>{' highlight wrapped'}</Highlight>
16
+ </Body>
17
+ <br />
18
+ <Body
19
+ highlightedText={['highlighted in the Body Kit ']}
20
+ highlighting
21
+ text="This is text highlighted in the Body Kit using the text prop."
22
+ />
23
+ </div>
24
+ )
25
+
26
+ export default HighlightDefault
@@ -0,0 +1,9 @@
1
+ examples:
2
+
3
+ rails:
4
+ - highlight_default: Default
5
+
6
+
7
+ react:
8
+ - highlight_default: Default
9
+
@@ -0,0 +1 @@
1
+ export { default as HighlightDefault } from './_highlight_default.jsx'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Playbook
4
+ module PbHighlight
5
+ class Highlight
6
+ include Playbook::Props
7
+
8
+ partial "pb_highlight/highlight"
9
+
10
+ prop :text
11
+
12
+ def classname
13
+ generate_classname("pb_highlight_kit")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -14,7 +14,7 @@
14
14
  <% content_for :pb_js do %>
15
15
  <%= javascript_tag do %>
16
16
  window.addEventListener('DOMContentLoaded', function() {
17
- new Popover(
17
+ new PbPopover(
18
18
  "#<%= object.trigger_element_id %>",
19
19
  "#<%= object.tooltip_id %>",
20
20
  "<%= object.position %>",
@@ -1,11 +1,11 @@
1
- import { createPopper } from '@popperjs/core'
1
+ import Popper from 'popper.js'
2
2
 
3
- class Popover {
3
+ class PbPopover {
4
4
  constructor(
5
5
  triggerElement = '#triggerElement',
6
6
  tooltip = '#tooltip',
7
7
  placement = 'left',
8
- offset = ''
8
+ offset,
9
9
  ) {
10
10
  this.triggerElement = triggerElement
11
11
  this.tooltip = tooltip
@@ -15,41 +15,32 @@ class Popover {
15
15
  }
16
16
 
17
17
  //getters
18
- get popoverTriggerElement() {
18
+ get referenceElement() {
19
19
  return document.querySelector(this.triggerElement)
20
20
  }
21
21
  get popoverTooltip() {
22
22
  return document.querySelector(this.tooltip)
23
23
  }
24
- get popoverPlacement() {
25
- return this.placement
26
- }
27
- get popoverOffset() {
28
- return this.offset
29
- }
30
24
 
31
25
  attachEvents() {
32
- this.popoverTriggerElement.addEventListener('click', () => {
26
+ this.referenceElement.addEventListener('click', () => {
33
27
  this.popoverTooltip.classList.toggle('show')
34
- this.popper.update()
28
+ this.popper.scheduleUpdate()
35
29
  })
36
30
  }
37
31
 
38
32
  setupPopper() {
39
- this.popper = createPopper(this.popoverTriggerElement, this.popoverTooltip, {
40
- placement: this.popoverPlacement,
41
- modifiers: [
42
- {
43
- name: 'offset',
44
- options: {
45
- offset: this.offset,
46
- },
33
+ this.popper = new Popper(this.referenceElement, this.popoverTooltip, {
34
+ placement: this.placement,
35
+ modifiers: {
36
+ offset: {
37
+ offset: this.offset,
47
38
  },
48
- ],
39
+ },
49
40
  })
50
41
 
51
42
  this.attachEvents()
52
43
  }
53
44
  }
54
45
 
55
- export default Popover
46
+ export default PbPopover
@@ -0,0 +1,121 @@
1
+ // @flow
2
+
3
+ import React from 'react'
4
+ import ReactDOM from 'react-dom'
5
+
6
+ import {
7
+ Popper,
8
+ Manager as PopperManager,
9
+ PopperProps,
10
+ Reference as PopperReference,
11
+ } from 'react-popper'
12
+
13
+ import { buildCss } from '../utilities/props'
14
+ import { Card } from '../'
15
+
16
+ type PbPopoverProps = {
17
+ className?: String,
18
+ offset?: Boolean,
19
+ reference: PopperReference,
20
+ show?: Boolean,
21
+ } & PopperProps
22
+
23
+ const POPOVER_OFFSET_Y = {
24
+ offset: {
25
+ offset: '0, 8',
26
+ },
27
+ }
28
+
29
+ const popoverModifiers = ({ modifiers, offset }) => {
30
+ return offset ? { ...modifiers, ...POPOVER_OFFSET_Y } : modifiers
31
+ }
32
+
33
+ const Popover = ({
34
+ children,
35
+ className,
36
+ modifiers,
37
+ offset,
38
+ placement,
39
+ referenceElement,
40
+ show,
41
+ }: PbPopoverProps) => (
42
+ <Popper
43
+ modifiers={popoverModifiers({ modifiers, offset })}
44
+ placement={placement}
45
+ referenceElement={referenceElement}
46
+ >
47
+ {({ placement, ref, scheduleUpdate, style }) => {
48
+ scheduleUpdate()
49
+ return (
50
+ <div
51
+ className={buildCss('pb_popover_kit', className)}
52
+ data-placement={placement}
53
+ ref={ref}
54
+ style={style}
55
+ >
56
+ <div className={buildCss('popover_tooltip', show ? 'show' : '')}>
57
+ <Card shadow="deeper">
58
+ { children }
59
+ </Card>
60
+ </div>
61
+ </div>
62
+ )
63
+ }
64
+ }
65
+ </Popper>
66
+ )
67
+
68
+ const PbReactPopover = ({
69
+ className,
70
+ children,
71
+ modifiers = {},
72
+ offset = false,
73
+ placement = 'left',
74
+ portal = 'body',
75
+ reference,
76
+ referenceElement,
77
+ show = false,
78
+ usePortal = false,
79
+ }: PbPopoverProps) => {
80
+ const popoverComponent = (
81
+ <Popover
82
+ className={className}
83
+ modifiers={modifiers}
84
+ offset={offset}
85
+ placement={placement}
86
+ referenceElement={referenceElement}
87
+ show={show}
88
+ >
89
+ {children}
90
+ </Popover>
91
+ )
92
+
93
+ return (
94
+ <PopperManager>
95
+ <If condition={reference && !referenceElement}>
96
+ <PopperReference>
97
+ {({ ref }) => (
98
+ <span
99
+ className="pb_popover_reference_wrapper"
100
+ ref={ref}
101
+ >
102
+ <reference.type
103
+ {...reference.props}
104
+ />
105
+ </span>
106
+ )}
107
+ </PopperReference>
108
+ </If>
109
+ <If condition={usePortal}>
110
+ {ReactDOM.createPortal(
111
+ popoverComponent,
112
+ document.querySelector(portal)
113
+ )}
114
+ <Else />
115
+ {popoverComponent}
116
+ </If>
117
+ </PopperManager>
118
+ )
119
+ }
120
+
121
+ export default PbReactPopover