playbook_ui 14.19.0.pre.alpha.PLAY20937693 → 14.19.0.pre.alpha.play1997dropdownenablepillsinselection7702

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c5ff1137945a937ea4a81fda473a39b7d9e8016a537ea01abfa7ae79b41e1a0
4
- data.tar.gz: 0fbe9b0d22ffecc88c65ba5794b0e3c02d3aeccb4221894abb82e1c9603b5104
3
+ metadata.gz: 5e1acc819228475b290eaea87ff0b86b2b62cea0c8d53baa8527c2bab9714a3a
4
+ data.tar.gz: 6ae3b6b23aae3dd4f27fc2b4ffd1c575f6bdfe51710fe5814661e81a36d8d810
5
5
  SHA512:
6
- metadata.gz: aa662ae46bf92185d89461416cb7312875bb89fd938d1a204156975bfc5044128af090e39fdb8e5b97d123976b8105a4d76aea4555984068e1222349bb230f25
7
- data.tar.gz: aaeb07f57c2923c857afeb9a49fb5a83fb8c44eb2d81bfdc488f20f9ed5603d0b29f6c4e82b164ff05330a9e717a3492384d14e03607b2b4fb341c4e5916aaaa
6
+ metadata.gz: a60e87407b7cdc3186cc515e4a0e783343b7e7257278f8dc3fa711c91447a5c3711911371121e4c3075799c305dc2da709b18f87e10cb9d51825c528ad797dec
7
+ data.tar.gz: '05912e775970c5b43a34112f4338c7269863c251a10cac6078c1a263db1a11b4d8207e363ab6377f1ea598fb8528bcc23a7d6e73a72c5f930f0b7fc15a276278'
@@ -6,6 +6,7 @@ import Flex from '../../pb_flex/_flex'
6
6
  import FlexItem from '../../pb_flex/_flex_item'
7
7
  import Avatar from '../../pb_avatar/_avatar'
8
8
  import User from '../../pb_user/_user'
9
+ import Body from '../../pb_body/_body'
9
10
 
10
11
  const DropdownWithCustomDisplay = (props) => {
11
12
  const [selectedOption, setSelectedOption] = useState();
@@ -50,10 +51,20 @@ const DropdownWithCustomDisplay = (props) => {
50
51
  <>
51
52
  {
52
53
  selectedOption && (
54
+ <Flex align="center">
53
55
  <Avatar
54
56
  name={selectedOption.label}
55
57
  size="xs"
56
58
  />
59
+ <Body
60
+ marginX="xs"
61
+ text={selectedOption.label}
62
+ />
63
+ <Badge
64
+ text={selectedOption.status}
65
+ variant={selectedOption.status == "Offline" ? "neutral" : selectedOption.status == "Online" ? "success" : "warning"}
66
+ />
67
+ </Flex>
57
68
  )
58
69
  }
59
70
  </>
@@ -1,4 +1,4 @@
1
- Optionally utilize `customDisplay` on the `Dropdown.Trigger` subcomponent to customize its content after an option is selected. The component passed to customDisplay will be rendered to the left of the default text-based display. In this example the Avatar kit is being used.
1
+ Optionally utilize `customDisplay` on the `Dropdown.Trigger` subcomponent to customize its content after an option is selected. Pass in any combination of kits to create a custom display. When a user clicks on an option, the kits passed into `customDisplay` will display as the selected option.
2
2
 
3
3
  The `placeholder` prop can also be used to customize the placeholder text for the default `Dropdown.Trigger`.
4
4
 
@@ -38,7 +38,11 @@
38
38
 
39
39
  <%
40
40
  custom_display = capture do
41
- pb_rails("avatar", props: { name: "Courtney Long", size: "xs" })
41
+ pb_rails("flex", props: { align: "center" }) do
42
+ concat(pb_rails("avatar", props: { name: "", size: "xs", id: "dropdown-avatar" }))
43
+ concat(pb_rails("body", props: { text: "", size: "xs", margin_x: "xs", id: "dropdown-avatar-name" }))
44
+ concat(pb_rails("badge", props: { text: "", id: "dropdown-avatar-status" }))
45
+ end
42
46
  end
43
47
  %>
44
48
 
@@ -62,4 +66,31 @@
62
66
  <% end %>
63
67
  <% end %>
64
68
  <% end %>
65
- <% end %>
69
+ <% end %>
70
+
71
+
72
+ <script>
73
+ document.addEventListener("pb:dropdown:selected", (e) => {
74
+ const option = e.detail;
75
+ const dropdown = e.target;
76
+
77
+ const display = dropdown.querySelector("#dropdown_trigger_custom_display");
78
+ if (!display) return;
79
+
80
+ const nameEl = display.querySelector("#dropdown-avatar-name");
81
+ if (nameEl) nameEl.textContent = option.label;
82
+
83
+ const avatarEl = display.querySelector("#dropdown-avatar").querySelector(".avatar_wrapper");
84
+ const initials = (option.label[0] + option.label.split(" ").pop()[0]).toUpperCase();
85
+ if (avatarEl) {
86
+ avatarEl.dataset.name = option.label;
87
+ avatarEl.setAttribute("data-initials", initials);
88
+ }
89
+ const badgeEl = display.querySelector("#dropdown-avatar-status");
90
+ const variant = option.status === "Online" ? "success" : option.status === "Offline" ? "neutral" : "warning";
91
+ if (badgeEl) {
92
+ badgeEl.querySelector("span").textContent = option.status;
93
+ badgeEl.className = 'pb_badge_kit_' + variant;
94
+ }
95
+ });
96
+ </script>
@@ -1,4 +1,6 @@
1
- Optionally utilize `custom_display` on the `dropdown/dropdown_trigger` subcomponent to customize its content after an option is selected. The component passed to custom_display will be rendered to the left of the default text-based display. In this example the Avatar kit is being used.
1
+ Optionally utilize `custom_display` on the `dropdown/dropdown_trigger` subcomponent to customize its content after an option is selected. Pass in any combination of kits to create a custom display. When a user clicks on an option, the kits passed into `custom_display` will display as the selected option.
2
+
3
+ Make use of a script to help set the custom_display with the correct value. By using the pb:dropdown:selected event listener, you can target the kits with a querySelector and update them dynamically with the values needed to match the selected option. Make sure to add an ID to the kits being passed in.
2
4
 
3
5
  The `placeholder` prop can also be used to customize the placeholder text for the default `dropdown/dropdown_trigger`.
4
6
 
@@ -142,9 +142,22 @@ export default class PbDropdown extends PbEnhancedElement {
142
142
  const customDisplayElement = this.element.querySelector(
143
143
  "#dropdown_trigger_custom_display"
144
144
  );
145
+
145
146
  if (triggerElement) {
146
147
  const selectedLabel = JSON.parse(value).label;
147
- triggerElement.textContent = selectedLabel;
148
+ if (customDisplayElement) {
149
+ triggerElement.textContent = ""
150
+ this.element.setAttribute("data-option-selected", value);
151
+ const selectedObj = JSON.parse(value);
152
+ this.element.dispatchEvent(
153
+ new CustomEvent("pb:dropdown:selected", {
154
+ detail: selectedObj,
155
+ bubbles: true,
156
+ })
157
+ );
158
+ } else {
159
+ triggerElement.textContent = selectedLabel
160
+ }
148
161
  if (customDisplayElement) {
149
162
  customDisplayElement.style.display = "block";
150
163
  customDisplayElement.style.paddingRight = "8px";
@@ -73,7 +73,7 @@ const DropdownTrigger = (props: DropdownTriggerProps) => {
73
73
  );
74
74
 
75
75
  const customDisplayPlaceholder = selected?.label ? (
76
- <b>{selected.label}</b>
76
+ ""
77
77
  ) : autocomplete ? (
78
78
  ""
79
79
  ) : placeholder ? (