@planningcenter/topbar 12.6.0-rc.0 → 12.6.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.
package/dist/topbar.js CHANGED
@@ -3569,6 +3569,23 @@ function groupByType({
3569
3569
  };
3570
3570
  return [...groups.values()].sort((a, b) => rank(a.type) - rank(b.type));
3571
3571
  }
3572
+ const isBlankStateAction = action => typeof action === "object" && action !== null && "label" in action && "url" in action && typeof action.label === "string" && typeof action.url === "string" && (!("query_param" in action) || typeof action.query_param === "string");
3573
+ function blankStateActions({
3574
+ meta
3575
+ }) {
3576
+ const actions = meta === null || meta === void 0 ? void 0 : meta.blank_state_actions;
3577
+ return Array.isArray(actions) ? actions.filter(isBlankStateAction) : [];
3578
+ }
3579
+ // The product reads the search box's text from the action's `query_param`, to
3580
+ // fill in whatever it opens.
3581
+ function blankStateActionUrl({
3582
+ query_param = "search_term",
3583
+ url
3584
+ }, term) {
3585
+ const actionUrl = new URL(url);
3586
+ actionUrl.searchParams.set(query_param, term.trim());
3587
+ return actionUrl.toString();
3588
+ }
3572
3589
 
3573
3590
  function useDebouncedValue(value, delay) {
3574
3591
  const [debounced, setDebounced] = React.useState(value);
@@ -3591,6 +3608,7 @@ function useProductSearch(product, term) {
3591
3608
  // Services tab.
3592
3609
  const visibleResponse = request.status === "done" || settledProduct === product ? response : undefined;
3593
3610
  const groups = React.useMemo(() => visibleResponse && groupByType(visibleResponse), [visibleResponse]);
3611
+ const actions = React.useMemo(() => response ? blankStateActions(response) : [], [response]);
3594
3612
  if (!query) {
3595
3613
  return {
3596
3614
  status: "idle"
@@ -3602,6 +3620,7 @@ function useProductSearch(product, term) {
3602
3620
  };
3603
3621
  } else if (request.status === "done") {
3604
3622
  return {
3623
+ blankStateActions: actions,
3605
3624
  groups: groups !== null && groups !== void 0 ? groups : [],
3606
3625
  status: "done"
3607
3626
  };
@@ -4704,6 +4723,39 @@ function capitalize(word) {
4704
4723
  return word.charAt(0).toUpperCase() + word.slice(1);
4705
4724
  }
4706
4725
 
4726
+ // The first action is the button, and any others wait behind its caret.
4727
+ function BlankStateActions({
4728
+ actions,
4729
+ onOpen,
4730
+ term
4731
+ }) {
4732
+ const [primary, ...others] = actions;
4733
+ if (!primary) return null;
4734
+ const primaryLink = /*#__PURE__*/React.createElement(tapestry.Link, {
4735
+ href: blankStateActionUrl(primary, term),
4736
+ kind: "neutral",
4737
+ label: primary.label,
4738
+ onClick: onOpen,
4739
+ prefix: /*#__PURE__*/React.createElement(Icon, {
4740
+ name: "general.plus"
4741
+ })
4742
+ });
4743
+ if (others.length === 0) return primaryLink;
4744
+ return /*#__PURE__*/React.createElement(tapestry.ButtonGroup, {
4745
+ "aria-label": "Create"
4746
+ }, primaryLink, /*#__PURE__*/React.createElement(tapestry.Dropdown, null, /*#__PURE__*/React.createElement(tapestry.DropdownTrigger, null, /*#__PURE__*/React.createElement(tapestry.DropdownIconButton, {
4747
+ "aria-label": "More to create",
4748
+ icon: null,
4749
+ kind: "neutral"
4750
+ })), /*#__PURE__*/React.createElement(tapestry.DropdownMenu, {
4751
+ placement: "bottom start"
4752
+ }, others.map(action => (/*#__PURE__*/React.createElement(tapestry.DropdownLink, {
4753
+ href: blankStateActionUrl(action, term),
4754
+ id: action.url,
4755
+ key: action.url
4756
+ }, action.label))))));
4757
+ }
4758
+
4707
4759
  var styles$j = {"container":"container-YDdM1","hint":"hint-017Rd","keycap":"keycap-ENJM2","labels":"labels-GHPqL","copied":"copied-DUFa1"};
4708
4760
 
4709
4761
  const SYMBOLS = {
@@ -5386,6 +5438,7 @@ function BlankStateRecentlyVisited(props) {
5386
5438
  var styles$f = {"blank_state":"blank_state-wMOWN","image":"image-uy0Fd"};
5387
5439
 
5388
5440
  function BlankState$1({
5441
+ action,
5389
5442
  image,
5390
5443
  role,
5391
5444
  subtitle,
@@ -5403,7 +5456,7 @@ function BlankState$1({
5403
5456
  direction: "column",
5404
5457
  align: "center",
5405
5458
  gap: 1
5406
- }, /*#__PURE__*/React.createElement("h2", null, title), /*#__PURE__*/React.createElement("p", null, subtitle)));
5459
+ }, /*#__PURE__*/React.createElement("h2", null, title), /*#__PURE__*/React.createElement("p", null, subtitle)), action);
5407
5460
  }
5408
5461
 
5409
5462
  function EndOfResultsObserver({
@@ -6084,6 +6137,7 @@ function LoadingSpinner({
6084
6137
 
6085
6138
  function SearchResults({
6086
6139
  label,
6140
+ noResultsAction,
6087
6141
  sections,
6088
6142
  status,
6089
6143
  term,
@@ -6127,6 +6181,7 @@ function SearchResults({
6127
6181
  if (sections.length === 0) {
6128
6182
  // The panel's result count announces this, so it isn't read twice.
6129
6183
  return /*#__PURE__*/React.createElement(BlankState$1, {
6184
+ action: noResultsAction,
6130
6185
  image: /*#__PURE__*/React.createElement(BlankStateNoResults, null),
6131
6186
  subtitle: "Clear search and try again.",
6132
6187
  title: `No results for “${term.trim()}”`
@@ -6183,6 +6238,20 @@ function SearchPanel({
6183
6238
  const inputRef = React.useRef(null);
6184
6239
  const resultCount = useAnnouncement(hasTerm && search.status === "done" ? `${items.length === 0 ? "No results" : `${items.length} ${items.length === 1 ? "result" : "results"}`} for “${term.trim()}” in ${product.appName}` : null);
6185
6240
  const [announceHighlight, setAnnounceHighlight] = React.useState(false);
6241
+ const blankStateActions = hasTerm && search.status === "done" && items.length === 0 ? search.blankStateActions : [];
6242
+ // With nothing to highlight, Enter takes the first thing the product offers
6243
+ // to create instead, the way the old People search added the person.
6244
+ const handleKeyDown = event => {
6245
+ const [action] = blankStateActions;
6246
+ if (event.key === "Enter" && action && !event.nativeEvent.isComposing) {
6247
+ event.preventDefault();
6248
+ open(blankStateActionUrl(action, term), {
6249
+ newTab: hasCommandKey(event)
6250
+ });
6251
+ } else {
6252
+ navigation.handleKeyDown(event);
6253
+ }
6254
+ };
6186
6255
  // The tabs keep focus while arrowing through results, but only the focused
6187
6256
  // input can point screen readers at the highlight, so from the tabs it's
6188
6257
  // announced instead. Typing goes back to the input, keystroke and all.
@@ -6192,15 +6261,20 @@ function SearchPanel({
6192
6261
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
6193
6262
  } else if (verticalStep(event.key)) {
6194
6263
  setAnnounceHighlight(true);
6195
- navigation.handleKeyDown(event);
6264
+ handleKeyDown(event);
6196
6265
  } else {
6197
- navigation.handleKeyDown(event);
6266
+ handleKeyDown(event);
6198
6267
  }
6199
6268
  };
6200
6269
  const results = hasTerm ? (/*#__PURE__*/React.createElement(SearchResults, {
6201
6270
  highlightedIndex: highlightedIndex,
6202
6271
  id: listboxId,
6203
6272
  label: `Results from Planning Center ${product.appName}`,
6273
+ noResultsAction: /*#__PURE__*/React.createElement(BlankStateActions, {
6274
+ actions: blankStateActions,
6275
+ onOpen: onOpenResult,
6276
+ term: term
6277
+ }),
6204
6278
  onHighlight: navigation.highlightIndex,
6205
6279
  onOpen: onOpenResult,
6206
6280
  sections: sections,
@@ -6222,7 +6296,7 @@ function SearchPanel({
6222
6296
  onChange: setTerm,
6223
6297
  onClose: onClose,
6224
6298
  onFocus: () => setAnnounceHighlight(false),
6225
- onKeyDown: navigation.handleKeyDown,
6299
+ onKeyDown: handleKeyDown,
6226
6300
  value: term
6227
6301
  }), mobile ? (/*#__PURE__*/React.createElement(ProductSelect, {
6228
6302
  onSelect: setSelectedSlug,