playbook_ui 12.17.0 → 12.18.0.pre.alpha.PLAY603datepickerquickpickinputpresetdropdown617
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/index.js +1 -1
- data/app/pb_kits/playbook/pb_avatar_action_button/avatar_action_button.html.erb +1 -2
- data/app/pb_kits/playbook/pb_collapsible/_collapsible.tsx +2 -2
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.scss +26 -0
- data/app/pb_kits/playbook/pb_date_picker/_date_picker.tsx +99 -95
- data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +1 -1
- data/app/pb_kits/playbook/pb_date_picker/date_picker.rb +1 -1
- data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +44 -1
- data/app/pb_kits/playbook/pb_date_picker/date_picker_helper.ts +34 -2
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick.html.erb +8 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick.jsx +18 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_date_picker/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_date_picker/plugins/quickPick.tsx +161 -0
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_calendar_input_icon.scss +4 -3
- data/app/pb_kits/playbook/pb_date_picker/sass_partials/_quick_pick_styles.scss +75 -0
- data/app/pb_kits/playbook/pb_docs/kit_api.html.erb +48 -36
- data/app/pb_kits/playbook/pb_docs/kit_api.rb +97 -9
- data/app/pb_kits/playbook/pb_docs/kit_example.html.erb +1 -1
- data/app/pb_kits/playbook/pb_docs/kit_example.rb +9 -5
- data/app/pb_kits/playbook/pb_lightbox/_lightbox.tsx +3 -0
- data/app/pb_kits/playbook/pb_lightbox/docs/_lightbox_compound_component.jsx +5 -1
- data/app/pb_kits/playbook/pb_lightbox/docs/_lightbox_current_photo.jsx +1 -1
- data/app/pb_kits/playbook/pb_lightbox/docs/_lightbox_custom_header.jsx +5 -1
- data/app/pb_kits/playbook/pb_lightbox/docs/_lightbox_default.jsx +5 -1
- data/app/pb_kits/playbook/pb_lightbox/docs/_lightbox_default.md +1 -1
- data/app/pb_kits/playbook/pb_lightbox/docs/_lightbox_multiple.jsx +5 -1
- data/app/pb_kits/playbook/pb_lightbox/lightbox.test.jsx +5 -1
- data/app/pb_kits/playbook/pb_nav/_item.tsx +7 -7
- data/app/pb_kits/playbook/pb_nav/_nav.tsx +4 -4
- data/app/pb_kits/playbook/pb_nav/_subtle_mixin.scss +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/EditorButton.tsx +49 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/EditorTypes.ts +9 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/Toolbar.tsx +62 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/ToolbarDropdown.tsx +139 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/ToolbarHistory.tsx +45 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/TipTap/ToolbarNodes.tsx +59 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.scss +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.tsx +28 -12
- data/app/pb_kits/playbook/pb_rich_text_editor/_tiptap_styles.scss +231 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_description.md +1 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_default.jsx +36 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_advanced_default.md +4 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_time_range_inline/_time_range_inline.tsx +185 -0
- data/app/pb_kits/playbook/pb_time_range_inline/time_range_inline.test.js +85 -0
- data/app/pb_kits/playbook/pb_title/_title.tsx +1 -1
- data/app/pb_kits/playbook/pb_title_detail/_title_detail.tsx +45 -0
- data/app/pb_kits/playbook/pb_title_detail/title_detail.test.js +71 -0
- data/app/pb_kits/playbook/pb_toggle/{_toggle.jsx → _toggle.tsx} +20 -22
- data/app/pb_kits/playbook/pb_toggle/toggle.test.js +67 -0
- data/app/pb_kits/playbook/pb_tooltip/_tooltip.scss +11 -6
- data/app/pb_kits/playbook/pb_tooltip/docs/_tooltip_default.html.erb +4 -4
- data/app/pb_kits/playbook/pb_tooltip/docs/_tooltip_with_icon_circle.html.erb +1 -2
- data/app/pb_kits/playbook/pb_tooltip/docs/example.yml +0 -1
- data/app/pb_kits/playbook/pb_user/_user.tsx +1 -1
- data/lib/playbook/markdown/helper.rb +50 -71
- data/lib/playbook/markdown.rb +0 -1
- data/lib/playbook/number_spacing.rb +10 -10
- data/lib/playbook/position.rb +10 -10
- data/lib/playbook/spacing.rb +10 -10
- data/lib/playbook/version.rb +2 -2
- data/lib/playbook/z_index.rb +10 -10
- metadata +29 -14
- data/app/pb_kits/playbook/pb_time_range_inline/_time_range_inline.jsx +0 -172
- data/app/pb_kits/playbook/pb_title_detail/_title_detail.jsx +0 -44
- data/app/pb_kits/playbook/pb_tooltip/docs/_tooltip_white.html.erb +0 -9
- data/lib/playbook/markdown/template_handler.rb +0 -47
@@ -0,0 +1,161 @@
|
|
1
|
+
import moment from 'moment'
|
2
|
+
|
3
|
+
type FpTypes = {
|
4
|
+
setDate: (arg0: any, arg1: boolean) => void,
|
5
|
+
config: { [key: string]: string },
|
6
|
+
clear: (arg0: boolean, arg1: boolean) => void,
|
7
|
+
close: () => void,
|
8
|
+
calendarContainer?: {
|
9
|
+
classList: { add: (arg0: string) => void };
|
10
|
+
prepend: (arg0: HTMLDivElement) => void;
|
11
|
+
append: (arg0: HTMLDivElement) => void;
|
12
|
+
},
|
13
|
+
loadedPlugins: string[],
|
14
|
+
};
|
15
|
+
|
16
|
+
type pluginDataType = {
|
17
|
+
ranges: { [key: string]: Date[] },
|
18
|
+
rangesNav: HTMLUListElement,
|
19
|
+
rangesButtons: [] | any,
|
20
|
+
}
|
21
|
+
|
22
|
+
const quickPickPlugin = () => {
|
23
|
+
return function (fp: FpTypes & any): any {
|
24
|
+
|
25
|
+
let activeLabel = ""
|
26
|
+
|
27
|
+
// variable that holds the ranges available
|
28
|
+
const ranges = {
|
29
|
+
'Today': [new Date(), new Date()],
|
30
|
+
'Yesterday': [moment().subtract(1, 'days').toDate(), moment().subtract(1, 'days').toDate()],
|
31
|
+
'This week': [moment().startOf('week').toDate(), moment().endOf('week').toDate()],
|
32
|
+
'This month': [moment().startOf('month').toDate(), new Date()],
|
33
|
+
'This quarter': [moment().startOf('quarter').toDate(), new Date()],
|
34
|
+
'This year': [moment().startOf('year').toDate(), new Date()],
|
35
|
+
'Last week': [
|
36
|
+
moment().subtract(1, 'week').startOf('week').toDate(),
|
37
|
+
moment().subtract(1, 'week').endOf('week').toDate()
|
38
|
+
],
|
39
|
+
'Last month': [
|
40
|
+
moment().subtract(1, 'month').startOf('month').toDate(),
|
41
|
+
moment().subtract(1, 'month').endOf('month').toDate()
|
42
|
+
],
|
43
|
+
'Last quarter': [
|
44
|
+
moment().subtract(1, 'quarter').startOf('quarter').toDate(),
|
45
|
+
moment().subtract(1, 'quarter').endOf('quarter').toDate()
|
46
|
+
],
|
47
|
+
'Last year': [
|
48
|
+
moment().subtract(1, 'year').startOf('year').toDate(),
|
49
|
+
moment().subtract(1, 'year').endOf('year').toDate()
|
50
|
+
]
|
51
|
+
}
|
52
|
+
//creating the ul element for the nav dropdown and giving it classnames
|
53
|
+
const rangesNav = document.createElement('ul');
|
54
|
+
|
55
|
+
// creating the pluginData object that will hold the properties of this plugin
|
56
|
+
const pluginData: pluginDataType = {
|
57
|
+
ranges: ranges,
|
58
|
+
rangesNav: rangesNav,
|
59
|
+
rangesButtons: [],
|
60
|
+
};
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @param {string} label
|
64
|
+
* @returns HTML Element
|
65
|
+
*/
|
66
|
+
|
67
|
+
//funciton for creating the range buttons in the nav
|
68
|
+
const addRangeButton = (label: string) => {
|
69
|
+
|
70
|
+
// creating new elements to mimick selectable card component
|
71
|
+
const div2 = document.createElement('div');
|
72
|
+
div2.className = "nav-item-link"
|
73
|
+
div2.innerHTML = label;
|
74
|
+
|
75
|
+
pluginData.rangesButtons[label] = div2;
|
76
|
+
|
77
|
+
// create li elements inside the dropdown
|
78
|
+
const item = document.createElement('li');
|
79
|
+
item.className = "nav-item";
|
80
|
+
|
81
|
+
// append those nav items to the li items
|
82
|
+
item.appendChild(pluginData.rangesButtons[label]);
|
83
|
+
|
84
|
+
// append the li item to the ul rangeNav prop
|
85
|
+
pluginData.rangesNav.appendChild(item);
|
86
|
+
|
87
|
+
// return the ranges buton prop
|
88
|
+
return pluginData.rangesButtons[label];
|
89
|
+
};
|
90
|
+
|
91
|
+
const selectActiveRangeButton = (selectedDates: Array<string>) => {
|
92
|
+
const current = pluginData.rangesNav.querySelector('.active');
|
93
|
+
|
94
|
+
if (current) {
|
95
|
+
current.classList.remove('active');
|
96
|
+
}
|
97
|
+
/** conditional statment to extract start and end dates from selectedDates,
|
98
|
+
* then loop through ranges prop in pluginData
|
99
|
+
* and check if chosen dates equal to a date in the ranges prop
|
100
|
+
* if they are equal, add the active class
|
101
|
+
*/
|
102
|
+
if (selectedDates.length > 0) {
|
103
|
+
pluginData.rangesButtons[activeLabel].classList.add('active');
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
return {
|
109
|
+
// onReady is a hook from flatpickr that runs when calender is in a ready state
|
110
|
+
onReady(selectedDates: Array<string>) {
|
111
|
+
// loop through the ranges and create an anchor tag for each range and add an event listiner to set the date when user clicks on a date range
|
112
|
+
for (const [label, range] of Object.entries(pluginData.ranges)) {
|
113
|
+
addRangeButton(label).addEventListener('click', function () {
|
114
|
+
|
115
|
+
const start = moment(range[0]).toDate();
|
116
|
+
const end = moment(range[1]).toDate();
|
117
|
+
|
118
|
+
if (!start) {
|
119
|
+
fp.clear();
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
activeLabel = label
|
123
|
+
fp.setDate([start, end], true);
|
124
|
+
fp.close();
|
125
|
+
}
|
126
|
+
|
127
|
+
});
|
128
|
+
}
|
129
|
+
|
130
|
+
// conditional to check if there is a dropdown to add it to the calendar container and git it the classes it needs
|
131
|
+
if (pluginData.rangesNav.children.length > 0) {
|
132
|
+
|
133
|
+
fp.calendarContainer.prepend(pluginData.rangesNav);
|
134
|
+
pluginData.rangesNav.classList.add('quick-pick-ul')
|
135
|
+
fp.calendarContainer.classList.add('quick-pick-drop-down');
|
136
|
+
|
137
|
+
/**
|
138
|
+
*
|
139
|
+
* @param {Array} selectedDates
|
140
|
+
*/
|
141
|
+
|
142
|
+
// function to give the active butto the active class
|
143
|
+
selectActiveRangeButton(selectedDates);
|
144
|
+
}
|
145
|
+
|
146
|
+
},
|
147
|
+
onValueUpdate(selectedDates: Array<string>) {
|
148
|
+
selectActiveRangeButton(selectedDates);
|
149
|
+
},
|
150
|
+
|
151
|
+
onClose(selectedDates: Array<string>) {
|
152
|
+
// set the input value to the selected dates when the dropdown is closed
|
153
|
+
if (!selectedDates[1]) {
|
154
|
+
fp.input.value = fp.formatDate(this.selectedDates[0], fp.config.dateFormat) + ' → ' + fp.formatDate(this.selectedDates[1], fp.config.dateFormat);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
};
|
158
|
+
};
|
159
|
+
}
|
160
|
+
|
161
|
+
export default quickPickPlugin;
|
@@ -1,6 +1,7 @@
|
|
1
|
+
@import "../../tokens/colors";
|
1
2
|
// Calendar Icon Styles
|
2
3
|
.cal_icon_wrapper {
|
3
|
-
|
4
|
+
cursor: pointer;
|
4
5
|
position: absolute;
|
5
6
|
top: $space_md + 2;
|
6
7
|
right: 0;
|
@@ -13,8 +14,8 @@
|
|
13
14
|
padding-left: $space_sm - 1;
|
14
15
|
color: $text_lt_light;
|
15
16
|
@media (hover: hover) {
|
16
|
-
&:hover
|
17
|
-
|
17
|
+
&:hover{
|
18
|
+
background-color: rgba($focus_input_light,$opacity_5);
|
18
19
|
}
|
19
20
|
}
|
20
21
|
&.dark {
|
@@ -0,0 +1,75 @@
|
|
1
|
+
@import "../../tokens/animation-curves";
|
2
|
+
@import "../../tokens/colors";
|
3
|
+
@import "../../tokens/typography";
|
4
|
+
@import "../../tokens/titles";
|
5
|
+
@import "../../tokens/spacing";
|
6
|
+
|
7
|
+
$pb_card_border_width: 1px;
|
8
|
+
$pb_card_border_radius: $border_rad_heavier;
|
9
|
+
|
10
|
+
// used to display dropdown on the left of the calender
|
11
|
+
.quick-pick-drop-down {
|
12
|
+
width: auto;
|
13
|
+
display: grid;
|
14
|
+
}
|
15
|
+
|
16
|
+
.quick-pick-ul {
|
17
|
+
padding: $space_xs 0px;
|
18
|
+
margin: 0;
|
19
|
+
list-style: none;
|
20
|
+
}
|
21
|
+
|
22
|
+
.nav-item {
|
23
|
+
list-style: none;
|
24
|
+
border-radius: 6px;
|
25
|
+
border-bottom: 0;
|
26
|
+
margin: $space_xs $space_sm;
|
27
|
+
}
|
28
|
+
|
29
|
+
.nav-item-link {
|
30
|
+
text-decoration: none;
|
31
|
+
border-width: $pb_card_border_width;
|
32
|
+
border-style: solid;
|
33
|
+
border-color: $border_light;
|
34
|
+
border-radius: $pb_card_border_radius;
|
35
|
+
padding: $space_xs 14px;
|
36
|
+
transition-property: color, background-color;
|
37
|
+
transition-duration: 0.15s;
|
38
|
+
transition-timing-function: $bezier;
|
39
|
+
line-height: 1.4;
|
40
|
+
color: $charcoal;
|
41
|
+
font-size: $font_default;
|
42
|
+
font-weight: $regular;
|
43
|
+
&.active {
|
44
|
+
border-width: 2px;
|
45
|
+
border-color: $primary;
|
46
|
+
}
|
47
|
+
@media (hover:hover) {
|
48
|
+
&:hover {
|
49
|
+
cursor: pointer;
|
50
|
+
box-shadow: $shadow-deep;
|
51
|
+
border-color: $slate;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
// Hide the calendar
|
57
|
+
.quick-pick-drop-down > .flatpickr-months, .quick-pick-drop-down > .flatpickr-innerContainer {
|
58
|
+
display: none;
|
59
|
+
}
|
60
|
+
|
61
|
+
@media only screen and (max-width: 767px) {
|
62
|
+
.quick-pick-ul {
|
63
|
+
padding: $space_xs $space_xs;
|
64
|
+
display: grid;
|
65
|
+
grid-template-columns: 1fr 1fr;
|
66
|
+
}
|
67
|
+
|
68
|
+
.nav-item {
|
69
|
+
margin: $space_xxs $space_xs;
|
70
|
+
}
|
71
|
+
|
72
|
+
.nav-item-link {
|
73
|
+
padding: $space_xs $space_xxs;
|
74
|
+
}
|
75
|
+
}
|
@@ -15,7 +15,6 @@
|
|
15
15
|
<th>Props</th>
|
16
16
|
<th>Type</th>
|
17
17
|
<th>Values</th>
|
18
|
-
<th>Default</th>
|
19
18
|
</tr>
|
20
19
|
</thead>
|
21
20
|
<tbody>
|
@@ -35,11 +34,34 @@
|
|
35
34
|
<%= pb_rails("body", props: {
|
36
35
|
classname: "kearning"
|
37
36
|
}) do %>
|
38
|
-
|
37
|
+
<% if key =~ /^padding|^margin/ %>
|
38
|
+
<%= "array" %>
|
39
|
+
<% else %>
|
40
|
+
<%= value[:type].to_s.downcase %>
|
41
|
+
<% end %>
|
39
42
|
<% end %>
|
40
43
|
<% end %>
|
41
44
|
</td>
|
42
45
|
<td>
|
46
|
+
<% if key =~ /^padding|^margin/ %>
|
47
|
+
<% padding_margin_values.each do |item| %>
|
48
|
+
<%= pb_rails("card", props: {
|
49
|
+
flex_direction: "row",
|
50
|
+
classname: "card",
|
51
|
+
padding: "xxs",
|
52
|
+
background: "light",
|
53
|
+
border_none: true,
|
54
|
+
border_radius: "sm",
|
55
|
+
margin: "xxs"
|
56
|
+
}) do %>
|
57
|
+
<%= pb_rails("body", props: {
|
58
|
+
classname: "kearning"
|
59
|
+
}) do %>
|
60
|
+
<%= item %>
|
61
|
+
<% end %>
|
62
|
+
<% end %>
|
63
|
+
<% end %>
|
64
|
+
<% else %>
|
43
65
|
<% if value[:values].present? %>
|
44
66
|
<% value[:values].each do |item| %>
|
45
67
|
<% if item != nil %>
|
@@ -61,22 +83,6 @@
|
|
61
83
|
<% end %>
|
62
84
|
<% end %>
|
63
85
|
<% 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
86
|
<% end %>
|
81
87
|
</td>
|
82
88
|
</tr>
|
@@ -110,7 +116,6 @@
|
|
110
116
|
<th>Props</th>
|
111
117
|
<th>Type</th>
|
112
118
|
<th>Values</th>
|
113
|
-
<th>Default</th>
|
114
119
|
</tr>
|
115
120
|
</thead>
|
116
121
|
<tbody>
|
@@ -130,11 +135,34 @@
|
|
130
135
|
<%= pb_rails("body", props: {
|
131
136
|
classname: "kearning"
|
132
137
|
}) do %>
|
133
|
-
|
138
|
+
<% if key =~ /^padding|^margin/ %>
|
139
|
+
<%= "array" %>
|
140
|
+
<% else %>
|
141
|
+
<%= value[:type].to_s.downcase %>
|
142
|
+
<% end %>
|
134
143
|
<% end %>
|
135
144
|
<% end %>
|
136
145
|
</td>
|
137
146
|
<td>
|
147
|
+
<% if key =~ /^padding|^margin/ %>
|
148
|
+
<% padding_margin_values.each do |item| %>
|
149
|
+
<%= pb_rails("card", props: {
|
150
|
+
flex_direction: "row",
|
151
|
+
classname: "card",
|
152
|
+
padding: "xxs",
|
153
|
+
background: "light",
|
154
|
+
border_none: true,
|
155
|
+
border_radius: "sm",
|
156
|
+
margin: "xxs"
|
157
|
+
}) do %>
|
158
|
+
<%= pb_rails("body", props: {
|
159
|
+
classname: "kearning"
|
160
|
+
}) do %>
|
161
|
+
<%= item %>
|
162
|
+
<% end %>
|
163
|
+
<% end %>
|
164
|
+
<% end %>
|
165
|
+
<% else %>
|
138
166
|
<% if value[:values].present? %>
|
139
167
|
<% value[:values].each do |item| %>
|
140
168
|
<% if item != nil %>
|
@@ -156,22 +184,6 @@
|
|
156
184
|
<% end %>
|
157
185
|
<% end %>
|
158
186
|
<% 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
187
|
<% end %>
|
176
188
|
</td>
|
177
189
|
</tr>
|
@@ -13,6 +13,10 @@ module Playbook
|
|
13
13
|
local
|
14
14
|
end
|
15
15
|
|
16
|
+
def padding_margin_values
|
17
|
+
%w[none xxs xs sm md lg xl]
|
18
|
+
end
|
19
|
+
|
16
20
|
def local_prop_data
|
17
21
|
local_props = {}
|
18
22
|
|
@@ -27,22 +31,106 @@ module Playbook
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def kit_global_props
|
30
|
-
|
34
|
+
global_props = {}
|
35
|
+
global_prop_names = []
|
36
|
+
global_prop_values = {}
|
37
|
+
global_props_with_values = {}
|
38
|
+
global_props_without_values = []
|
39
|
+
parent_child_object = {}
|
40
|
+
updated_global_props_with_values = {}
|
41
|
+
|
42
|
+
# extracts the modules from kit_base.rb, which is where we import all the global props that we inject into every rails kit
|
43
|
+
pb_module = Playbook::KitBase.included_modules.select { |mod| mod.to_s.include?("Playbook::") }
|
44
|
+
|
45
|
+
# loops through the kits and extracts each prop with its values and pushes that to the global_props hash
|
31
46
|
kit_props.each do |key, value|
|
32
|
-
value.kit == Playbook::KitBase &&
|
47
|
+
value.kit == Playbook::KitBase && global_props[key.to_sym] = value
|
48
|
+
end
|
49
|
+
|
50
|
+
# loops through the global_props and extracts the name of each prop and pushes that to global_prop_names array
|
51
|
+
global_props.each do |name, _values|
|
52
|
+
global_prop_names.push(name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Loops through each module in pb_module and searches for methods that end in _values, as these methods hold the values for each prop
|
56
|
+
# we then save the values and type and push that to the values hash as a key value pair
|
57
|
+
pb_module.each do |mod|
|
58
|
+
mod.instance_methods.each do |method_name|
|
59
|
+
next unless method_name.to_s.end_with?("_values")
|
60
|
+
|
61
|
+
value = send(method_name)
|
62
|
+
type = value.class
|
63
|
+
global_prop_values[method_name.to_s.chomp("_values").to_sym] = { "type": type, "values": value }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# loops through the global_prop_names array
|
68
|
+
# then loops through the global_prop_values hash and extracts the values that have the same name found in global_prop_names
|
69
|
+
# this loop helps ensure only global props values are actually extracted, as there could be other methods that end in _values in the modules we are iterating over
|
70
|
+
# these verified global props with values are then pushed to the global_props_with_values hash
|
71
|
+
global_prop_names.each do |name, _prop|
|
72
|
+
global_prop_values.each do |key, value|
|
73
|
+
global_props_with_values[key] = value if key == name
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# now we grab all the global_prop_names that do not have a matching key in global_prop_values.
|
78
|
+
# This gives us any global prop that did not have any predefined value. like classname and dark
|
79
|
+
global_props_without_values = global_prop_names - global_prop_values.keys
|
80
|
+
|
81
|
+
# Loops through each module in pb_module and searches for methods that end in _options, as these methods hold all the props in the module
|
82
|
+
# save the prop names prop values and and parent module name to parent_child_object hash
|
83
|
+
# this is a comprehensive list of all parent module and children props for edge cases like spacing.rb, that is not named after the props it represents
|
84
|
+
pb_module.each do |mod|
|
85
|
+
mod.instance_methods.each do |method_name|
|
86
|
+
next unless method_name.to_s.end_with?("_options")
|
87
|
+
|
88
|
+
props = send(method_name)
|
89
|
+
parent = mod.to_s.split("::").last
|
90
|
+
values = send("#{parent.underscore}_values")
|
91
|
+
parent_child_object[parent] = { "props": props, "values": values }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# loops through each object in parent_child_object and extracts its children (props and values)
|
96
|
+
# loops through each child and extracts the individual props
|
97
|
+
# Checks if the props match any of the props in global_props_without_values
|
98
|
+
# if it does, then we push that prop to global_props_with_values hash
|
99
|
+
# This extracts the props in the spacing.rb file and any file that is not named after the props it represents
|
100
|
+
parent_child_object.each do |_parent, children|
|
101
|
+
children.each do |_child, props|
|
102
|
+
props.each do |prop, _value|
|
103
|
+
type = children[:values].class
|
104
|
+
values = children[:values]
|
105
|
+
global_props_with_values[prop] = { "type": type, "values": values } if global_props_without_values.include?(prop)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# loop through the global_props hash and the global_props_with_values hash.
|
111
|
+
# extract the props from global_props that are not found in global_props_with_values into updated_global_props_with_values
|
112
|
+
# This is the last piece that grabs the global props that did not have values at all, like classname and dark, and adds it to our hash
|
113
|
+
global_props.each do |prop, value|
|
114
|
+
unless global_props_with_values.include?(prop)
|
115
|
+
type = value.class.to_s.split("::").last
|
116
|
+
updated_global_props_with_values[prop] = { "type": type }
|
117
|
+
end
|
33
118
|
end
|
34
|
-
|
119
|
+
|
120
|
+
# Merge updated_global_props_with_values into global_props_with_values
|
121
|
+
# global_props_with_values will now hold all the global props thier values and type
|
122
|
+
global_props_with_values.merge!(updated_global_props_with_values)
|
123
|
+
|
124
|
+
global_props_with_values
|
35
125
|
end
|
36
126
|
|
37
127
|
def global_prop_data
|
38
128
|
global_props = {}
|
39
129
|
|
40
|
-
kit_global_props.each do |key,
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
values = key[:value].instance_variable_get(:@values)
|
45
|
-
global_props[name.to_sym] = { "type": type, "default": default, "values": values }
|
130
|
+
kit_global_props.each do |key, value|
|
131
|
+
type = value[:type]
|
132
|
+
values = value[:values]
|
133
|
+
global_props[key] = { "type": type, "values": values }
|
46
134
|
end
|
47
135
|
global_props
|
48
136
|
end
|
@@ -23,7 +23,7 @@ module Playbook
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def description
|
26
|
-
@description ||= read_kit_file("_#{example_key}.md")
|
26
|
+
@description ||= read_kit_file("docs", "_#{example_key}.md")
|
27
27
|
end
|
28
28
|
|
29
29
|
def highlighter
|
@@ -33,11 +33,15 @@ module Playbook
|
|
33
33
|
def source
|
34
34
|
@source ||= begin
|
35
35
|
extension = type == "react" ? "jsx" : "html.erb"
|
36
|
-
stringified_code = read_kit_file("_#{example_key}.#{extension}")
|
36
|
+
stringified_code = read_kit_file("docs", "_#{example_key}.#{extension}")
|
37
37
|
sanitize_code(stringified_code)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
def tsx_source
|
42
|
+
read_kit_file("", "_#{example_key}.tsx")
|
43
|
+
end
|
44
|
+
|
41
45
|
private
|
42
46
|
|
43
47
|
def sanitize_code(stringified_code)
|
@@ -53,11 +57,11 @@ module Playbook
|
|
53
57
|
elsif type == "rails" && dark
|
54
58
|
stringified_code = stringified_code.gsub("props: {", "props: {\n dark: true,")
|
55
59
|
end
|
56
|
-
stringified_code
|
60
|
+
stringified_code.gsub(" {...props}", "")
|
57
61
|
end
|
58
62
|
|
59
|
-
def read_kit_file(*args)
|
60
|
-
path = ::Playbook.kit_path(kit,
|
63
|
+
def read_kit_file(folder, *args)
|
64
|
+
path = ::Playbook.kit_path(kit, folder, *args)
|
61
65
|
path.exist? ? path.read : ""
|
62
66
|
end
|
63
67
|
end
|
@@ -47,12 +47,15 @@ const Lightbox = (props: LightboxType): React.ReactNode => {
|
|
47
47
|
} = props
|
48
48
|
|
49
49
|
const [activePhoto, setActivePhoto] = useState(initialPhoto)
|
50
|
+
|
50
51
|
useEffect(() => {
|
51
52
|
onChange(activePhoto)
|
52
53
|
},[activePhoto])
|
53
54
|
|
54
55
|
useEffect(() => {
|
56
|
+
currentPhotoIndex !== undefined && currentPhotoIndex !== null && (
|
55
57
|
setActivePhoto(currentPhotoIndex)
|
58
|
+
)
|
56
59
|
},[currentPhotoIndex])
|
57
60
|
|
58
61
|
const ariaProps = buildAriaProps(aria)
|
@@ -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).
|