@placeholderco/placeholder-ui 3.3.5 → 3.3.7

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.
@@ -328,16 +328,29 @@
328
328
  padding-left: 0.25rem;
329
329
  }
330
330
 
331
+ /* One indent step per level. The default (chevron width + row gap) puts each
332
+ guide line directly under the parent folder's chevron. */
331
333
  .ft-indent {
332
- display: inline-flex;
334
+ --ft-indent-step: var(--filetree-indent, 1.25rem);
335
+ display: flex;
333
336
  flex-shrink: 0;
337
+ align-self: stretch;
338
+ /* Extend through the row's vertical padding so guides join up between rows */
339
+ margin-block: -0.375rem;
334
340
  }
335
341
 
336
342
  .ft-indent-line {
337
- display: inline-block;
338
- height: 100%;
343
+ position: relative;
344
+ width: var(--ft-indent-step);
345
+ }
346
+
347
+ .ft-indent-line::before {
348
+ content: '';
349
+ position: absolute;
350
+ inset-block: 0;
351
+ /* Centre of the ancestor's chevron: row gap + half the chevron width */
352
+ left: 0.75rem;
339
353
  border-left: 1px solid var(--border-color);
340
- margin-right: 2px;
341
354
  }
342
355
 
343
356
  .ft-chevron {
package/dist/index.d.ts CHANGED
@@ -140,6 +140,7 @@ export * from './models/ComboBoxItem.js';
140
140
  export * from './models/NavbarItem.js';
141
141
  export * from './models/NotifyModel.js';
142
142
  export * from './util/ClickOutside.js';
143
+ export * from './util/BeforeMatch.js';
143
144
  export * from './util/Floating.js';
144
145
  export * from './util/CronParser.js';
145
146
  export { dayjs } from './util/dayjs.js';
package/dist/index.js CHANGED
@@ -68,6 +68,7 @@ export * from './models/ComboBoxItem.js';
68
68
  export * from './models/NavbarItem.js';
69
69
  export * from './models/NotifyModel.js';
70
70
  export * from './util/ClickOutside.js';
71
+ export * from './util/BeforeMatch.js';
71
72
  export * from './util/Floating.js';
72
73
  export * from './util/CronParser.js';
73
74
  export { dayjs } from './util/dayjs.js';
@@ -26,6 +26,8 @@
26
26
  readonly size: AccordionSize;
27
27
  /** Colour variant applied to expanded item headers. Items can override individually */
28
28
  readonly variant: ButtonVariant;
29
+ /** Whether collapsed items keep their content in the page, hidden. Items can override individually */
30
+ readonly renderHidden: boolean;
29
31
  }
30
32
  </script>
31
33
 
@@ -43,6 +45,12 @@
43
45
  size?: AccordionSize;
44
46
  /** Colour scheme for expanded item headers, using the Button variants. Items can override individually */
45
47
  variant?: ButtonVariant;
48
+ /**
49
+ * Render the content of collapsed items too, hidden with `hidden="until-found"`, so it is in
50
+ * the page (and the SSR HTML), keeps its state while collapsed, and can be found with the
51
+ * browser's find-in-page, which opens the matching item. Items can override individually
52
+ */
53
+ renderHidden?: boolean;
46
54
  /** Custom snippet rendered as the title of every item. Item-level `header` snippets take precedence */
47
55
  itemTitle?: Snippet<[AccordionTitleContext]>;
48
56
  /** AccordionItem children */
@@ -55,6 +63,7 @@
55
63
  onchange,
56
64
  size = 'md',
57
65
  variant = 'primary',
66
+ renderHidden = false,
58
67
  itemTitle,
59
68
  children
60
69
  }: AccordionProps = $props();
@@ -88,6 +97,9 @@
88
97
  },
89
98
  get variant() {
90
99
  return variant;
100
+ },
101
+ get renderHidden() {
102
+ return renderHidden;
91
103
  }
92
104
  });
93
105
  </script>
@@ -22,6 +22,8 @@ export interface AccordionContext {
22
22
  readonly size: AccordionSize;
23
23
  /** Colour variant applied to expanded item headers. Items can override individually */
24
24
  readonly variant: ButtonVariant;
25
+ /** Whether collapsed items keep their content in the page, hidden. Items can override individually */
26
+ readonly renderHidden: boolean;
25
27
  }
26
28
  export interface AccordionProps {
27
29
  /** Allow more than one item to be expanded at the same time */
@@ -34,6 +36,12 @@ export interface AccordionProps {
34
36
  size?: AccordionSize;
35
37
  /** Colour scheme for expanded item headers, using the Button variants. Items can override individually */
36
38
  variant?: ButtonVariant;
39
+ /**
40
+ * Render the content of collapsed items too, hidden with `hidden="until-found"`, so it is in
41
+ * the page (and the SSR HTML), keeps its state while collapsed, and can be found with the
42
+ * browser's find-in-page, which opens the matching item. Items can override individually
43
+ */
44
+ renderHidden?: boolean;
37
45
  /** Custom snippet rendered as the title of every item. Item-level `header` snippets take precedence */
38
46
  itemTitle?: Snippet<[AccordionTitleContext]>;
39
47
  /** AccordionItem children */
@@ -4,6 +4,7 @@
4
4
  import { slide } from 'svelte/transition';
5
5
  import Icon from '../icon/Icon.svelte';
6
6
  import { iconChevronDown } from '../icon/index.js';
7
+ import { beforeMatch } from '../util/BeforeMatch.js';
7
8
  import type { AccordionContext } from './Accordion.svelte';
8
9
  import type { ButtonVariant } from './ButtonVariant.js';
9
10
 
@@ -18,6 +19,8 @@
18
19
  disabled?: boolean;
19
20
  /** Colour variant for this item's expanded header, overriding the accordion-level variant */
20
21
  variant?: ButtonVariant;
22
+ /** Keep this item's content in the page while collapsed, overriding the accordion-level `renderHidden` */
23
+ renderHidden?: boolean;
21
24
  /** Custom header content, replaces `title` */
22
25
  header?: Snippet;
23
26
  /** Collapsible body content */
@@ -32,6 +35,7 @@
32
35
  icon,
33
36
  disabled = false,
34
37
  variant,
38
+ renderHidden,
35
39
  header,
36
40
  children
37
41
  }: AccordionItemProps = $props();
@@ -46,8 +50,51 @@
46
50
  const small = $derived(accordion.size === 'sm');
47
51
  const iconSize = $derived(small ? '16' : '18');
48
52
  const effectiveVariant = $derived(variant ?? accordion.variant);
53
+ const keepRendered = $derived(renderHidden ?? accordion.renderHidden);
49
54
  const contentId = `${uid}-content`;
50
55
  const headerId = `${uid}-header`;
56
+
57
+ // With `renderHidden` the content stays mounted, so the slide transition never runs.
58
+ // Animate its height on toggle instead.
59
+ let contentEl = $state<HTMLDivElement>();
60
+ let shownOpen: boolean | undefined;
61
+ let animation: Animation | undefined;
62
+ let revealedByFind = false;
63
+
64
+ $effect(() => {
65
+ const el = contentEl;
66
+ const isOpen = open;
67
+ if (!el || shownOpen === undefined || shownOpen === isOpen || revealedByFind) {
68
+ shownOpen = el ? isOpen : undefined;
69
+ revealedByFind = false;
70
+ return;
71
+ }
72
+ shownOpen = isOpen;
73
+
74
+ // Svelte has already hidden it; keep it visible until it has slid shut
75
+ if (!isOpen) el.removeAttribute('hidden');
76
+ const from =
77
+ animation?.playState === 'running'
78
+ ? el.getBoundingClientRect().height
79
+ : isOpen
80
+ ? 0
81
+ : el.scrollHeight;
82
+ animation?.cancel();
83
+ animation = el.animate(
84
+ [{ height: `${from}px` }, { height: `${isOpen ? el.scrollHeight : 0}px` }],
85
+ { duration: 200, easing: 'ease-out' }
86
+ );
87
+ if (!isOpen) {
88
+ animation.onfinish = () => el.setAttribute('hidden', 'until-found');
89
+ }
90
+ });
91
+
92
+ // Find-in-page has already revealed the content; open the item to match, without animating
93
+ function openFromFind() {
94
+ if (open) return;
95
+ revealedByFind = true;
96
+ accordion.toggle(value);
97
+ }
51
98
  </script>
52
99
 
53
100
  <div class="accordion-item variant-{effectiveVariant}" class:open class:small>
@@ -79,7 +126,25 @@
79
126
  </button>
80
127
  </h3>
81
128
 
82
- {#if open}
129
+ {#snippet body()}
130
+ <div class="accordion-body">
131
+ {@render children?.()}
132
+ </div>
133
+ {/snippet}
134
+
135
+ {#if keepRendered}
136
+ <div
137
+ bind:this={contentEl}
138
+ id={contentId}
139
+ class="accordion-content"
140
+ role="region"
141
+ aria-labelledby={headerId}
142
+ hidden={open ? undefined : 'until-found'}
143
+ use:beforeMatch={openFromFind}
144
+ >
145
+ {@render body()}
146
+ </div>
147
+ {:else if open}
83
148
  <div
84
149
  id={contentId}
85
150
  class="accordion-content"
@@ -87,9 +152,7 @@
87
152
  aria-labelledby={headerId}
88
153
  transition:slide={{ duration: 200 }}
89
154
  >
90
- <div class="accordion-body">
91
- {@render children?.()}
92
- </div>
155
+ {@render body()}
93
156
  </div>
94
157
  {/if}
95
158
  </div>
@@ -11,6 +11,8 @@ export interface AccordionItemProps {
11
11
  disabled?: boolean;
12
12
  /** Colour variant for this item's expanded header, overriding the accordion-level variant */
13
13
  variant?: ButtonVariant;
14
+ /** Keep this item's content in the page while collapsed, overriding the accordion-level `renderHidden` */
15
+ renderHidden?: boolean;
14
16
  /** Custom header content, replaces `title` */
15
17
  header?: Snippet;
16
18
  /** Collapsible body content */
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { ComboBoxItem } from '../models/ComboBoxItem.js';
3
3
  import Tooltip, { type TooltipLocation } from './Tooltip.svelte';
4
- import { onMount } from 'svelte';
4
+ import { beforeMatch } from '../util/BeforeMatch.js';
5
+ import { onMount, type Snippet } from 'svelte';
5
6
 
6
7
  export interface TabsProps {
7
8
  /**
@@ -18,6 +19,17 @@
18
19
  tooltipLocation?: TooltipLocation;
19
20
  /** Callback when active tab changes */
20
21
  onchange?: (newValue: string) => void;
22
+ /**
23
+ * Content for each tab, rendered below the bar. Receives the tab option and whether it is
24
+ * active. Only the active tab's panel is rendered unless `renderHidden` is set
25
+ */
26
+ panel?: Snippet<[option: ComboBoxItem, active: boolean]>;
27
+ /**
28
+ * Render every tab's `panel`, keeping inactive ones hidden with `hidden="until-found"`, so
29
+ * all content is in the page (and the SSR HTML), keeps its state across tab switches, and
30
+ * can be found with the browser's find-in-page, which switches to the matching tab
31
+ */
32
+ renderHidden?: boolean;
21
33
  }
22
34
 
23
35
  let {
@@ -25,7 +37,9 @@
25
37
  activeTab = $bindable(''),
26
38
  solidBg = false,
27
39
  tooltipLocation = 'top',
28
- onchange
40
+ onchange,
41
+ panel,
42
+ renderHidden = false
29
43
  }: TabsProps = $props();
30
44
  let containerRef: HTMLDivElement;
31
45
  let scrollRef: HTMLDivElement;
@@ -125,6 +139,24 @@
125
139
  </div>
126
140
  </div>
127
141
 
142
+ {#if panel}
143
+ <!-- One wrapper: hidden="until-found" panels still get an (empty) box, which would add gaps -->
144
+ <div class="tab-panels">
145
+ {#each tabOptions as option (option.value)}
146
+ {@const isSelected = option.value === activeTab}
147
+ {#if isSelected || renderHidden}
148
+ <div
149
+ class="tab-panel"
150
+ hidden={isSelected ? undefined : 'until-found'}
151
+ use:beforeMatch={() => setValue(option.value)}
152
+ >
153
+ {@render panel(option, isSelected)}
154
+ </div>
155
+ {/if}
156
+ {/each}
157
+ </div>
158
+ {/if}
159
+
128
160
  <style>
129
161
  .tabs-scroll {
130
162
  display: inline-block;
@@ -1,5 +1,6 @@
1
1
  import type { ComboBoxItem } from '../models/ComboBoxItem.js';
2
2
  import { type TooltipLocation } from './Tooltip.svelte';
3
+ import { type Snippet } from 'svelte';
3
4
  export interface TabsProps {
4
5
  /**
5
6
  * Available tab options. `class` is added to the tab button (style it with `:global()`),
@@ -15,6 +16,17 @@ export interface TabsProps {
15
16
  tooltipLocation?: TooltipLocation;
16
17
  /** Callback when active tab changes */
17
18
  onchange?: (newValue: string) => void;
19
+ /**
20
+ * Content for each tab, rendered below the bar. Receives the tab option and whether it is
21
+ * active. Only the active tab's panel is rendered unless `renderHidden` is set
22
+ */
23
+ panel?: Snippet<[option: ComboBoxItem, active: boolean]>;
24
+ /**
25
+ * Render every tab's `panel`, keeping inactive ones hidden with `hidden="until-found"`, so
26
+ * all content is in the page (and the SSR HTML), keeps its state across tab switches, and
27
+ * can be found with the browser's find-in-page, which switches to the matching tab
28
+ */
29
+ renderHidden?: boolean;
18
30
  }
19
31
  declare const Tabs: import("svelte").Component<TabsProps, {}, "activeTab">;
20
32
  type Tabs = ReturnType<typeof Tabs>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calls `handler` when the browser's find-in-page reveals a `hidden="until-found"` element
3
+ * (the `beforematch` event), so the component can mark that content as open.
4
+ */
5
+ export declare function beforeMatch(node: HTMLElement, handler: () => void): {
6
+ update(next: () => void): void;
7
+ destroy(): void;
8
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Calls `handler` when the browser's find-in-page reveals a `hidden="until-found"` element
3
+ * (the `beforematch` event), so the component can mark that content as open.
4
+ */
5
+ export function beforeMatch(node, handler) {
6
+ let current = handler;
7
+ const handleMatch = () => current();
8
+ node.addEventListener('beforematch', handleMatch);
9
+ return {
10
+ update(next) {
11
+ current = next;
12
+ },
13
+ destroy() {
14
+ node.removeEventListener('beforematch', handleMatch);
15
+ }
16
+ };
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placeholderco/placeholder-ui",
3
- "version": "3.3.5",
3
+ "version": "3.3.7",
4
4
  "description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
5
5
  "license": "MIT",
6
6
  "author": "Placeholderco",