Skip to content

Commit 556117c

Browse files
authored
Merge pull request #23 from svelte-atoms/fix/improvements-013
fix: improve TypeScript props and other stability fixes
2 parents ad4e521 + 1d6c6ac commit 556117c

28 files changed

+335
-386
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414

1515
### 🧱 **Bond Architecture**
1616

17-
Built around the concept of "Bonds" - self-contained, reusable state management classes that encapsulate component state and DOM interactions. Each component uses the Bond pattern for consistent, predictable behavior across complex interactions. Simple components like Button don't require the Bond pattern as they have minimal state management needs.
18-
19-
### 🔗 **Context-Driven Communication**
20-
21-
Components seamlessly communicate through Svelte's context API using standardized static methods (`Bond.get()` / `Bond.set()`) of the Bond class, enabling powerful parent-child relationships without prop drilling.
17+
Self-contained state management classes that encapsulate component logic and DOM interactions. Bonds communicate through Svelte's context API using standardized `Bond.get()` / `Bond.set()` methods, enabling parent-child relationships without prop drilling.
2218

2319
### **Accessibility First**
2420

llm/variants.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ setPreset({
251251
**How it works:**
252252

253253
1. `defineVariants(config)` → returns a function
254-
2. You pass this function to `HtmlAtom` via `{variants}`
254+
2. You pass this function to `HtmlAtom` via `{variants}`
255255
3. `HtmlAtom` internally calls `variants(bond, restProps)`
256256
4. The function returns `{ class: [...], ...attributes }`
257257
5. `HtmlAtom` applies these to the rendered element
@@ -519,7 +519,7 @@ Combine global preset variants with component-specific variants:
519519
>
520520
{@render children?.()}
521521
</HtmlAtom>
522-
````
522+
```
523523

524524
### Example 4: Alert Component with Compound Variants
525525

@@ -664,9 +664,7 @@ Combine global preset variants with component-specific variants:
664664
</script>
665665
666666
<!-- Pass the variant function to HtmlAtom -->
667-
<HtmlAtom {variants} as="button" {variant} {size} {...props}>
668-
Click me
669-
</HtmlAtom>
667+
<HtmlAtom {variants} as="button" {variant} {size} {...props}>Click me</HtmlAtom>
670668
```
671669

672670
### Benefits After Migration

src/lib/components/atom/html-atom.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
preset: presetKey = undefined,
2222
bond = undefined,
2323
variants = undefined,
24-
children = undefined,
24+
children: childrenProp = undefined,
2525
...restProps
26-
}: HtmlAtomProps<E, B> & HTMLAttributes<Element> = $props();
26+
}: HtmlAtomProps<E, B> & Omit<HTMLAttributes<Element>, 'children'> = $props();
2727
2828
const preset = $derived(
2929
presetKey ? getPreset(presetKey as PresetModuleName)?.apply?.(bond, [bond]) : undefined
@@ -122,7 +122,7 @@
122122
if (isSnippet)
123123
return {
124124
component: SnippetRenderer,
125-
props: { snippet: snippet, class: _klass, as: _as, children, ..._restProps }
125+
props: { snippet: snippet, class: _klass, as: _as, children: childrenProp, ..._restProps }
126126
};
127127
128128
return {
@@ -201,5 +201,7 @@
201201
</script>
202202

203203
<renderer.component {...renderer.props}>
204-
{@render children?.()}
204+
{#snippet children(args)}
205+
{@render childrenProp?.(args)}
206+
{/snippet}
205207
</renderer.component>

src/lib/components/calendar/calendar-day.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import { isBefore, isSameDay, isWithinInterval } from 'date-fns';
3-
import { cn } from '$svelte-atoms/core/utils';
43
import { CalendarBond } from './bond.svelte';
54
import type { CalendarDayProps } from './types';
65
import { HtmlAtom } from '../atom';

src/lib/components/calendar/calendar-header.svelte

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const calendarBond = CalendarBond.get();
88
const currentMonth = $derived(calendarBond?.state.props.currentMonth);
99
10-
let { class: klass = '', preset = 'calendar.header', children, ...restProps } = $props();
10+
let { class: klass = '', preset = 'calendar.header', ...restProps } = $props();
1111
1212
const headerProps = $derived({
1313
...calendarBond?.header(),
@@ -24,10 +24,6 @@
2424
{...headerProps}
2525
>
2626
{#each (currentMonth?.days ?? []).filter((d) => d.week == 1) as day}
27-
{#if children}
28-
{@render children?.(day)}
29-
{:else}
30-
<CalendarWeekDay isWeekend={day.weekend}>{day.name}</CalendarWeekDay>
31-
{/if}
27+
<CalendarWeekDay isWeekend={day.weekend}>{day.name}</CalendarWeekDay>
3228
{/each}
3329
</HtmlAtom>

src/lib/components/calendar/calendar-root.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
2828
const monthCurrentDays = $derived(generator(pivote));
2929
30-
$inspect(min, max, monthCurrentDays);
31-
3230
const monthCurrent: Month = $derived.by(() => {
3331
const start = monthCurrentDays.at(0) as Day;
3432
const end = monthCurrentDays.at(-1) as Day;

src/lib/components/calendar/calendar.stories.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
</script>
99

1010
<script>
11-
import CalendarHeader from './calendar-header.svelte';
1211
import { Root } from '../root';
13-
import { Card } from '../card';
14-
15-
let value = $state(undefined);
16-
let checked = $state(false);
1712
</script>
1813

1914
<Story name="Calendar">

src/lib/components/calendar/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Snippet } from 'svelte';
2-
import type { CalendarContext } from './context';
32
import type { Factory } from '$svelte-atoms/core/types';
43
import type { CalendarBond } from './bond.svelte';
54

src/lib/components/datagrid/datagrid-root.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class: klass = '',
1111
values = $bindable([]),
1212
template = undefined,
13-
data = [],
13+
fallbackTemplate = 'auto',
1414
factory = _factory,
1515
children = undefined,
1616
onmount = undefined,
@@ -46,7 +46,7 @@
4646
{bond}
4747
preset="datagrid"
4848
class={['border-border', 'datagrid-root w-full gap-x-0 gap-y-0', '$preset', klass]}
49-
style="--template-columns:{bond.state.template}"
49+
style="--template-columns:{bond.state.template ?? fallbackTemplate}"
5050
enter={enter?.bind(bond.state)}
5151
exit={exit?.bind(bond.state)}
5252
initial={initial?.bind(bond.state)}

src/lib/components/datagrid/datagrid.css

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,3 @@
33
grid-auto-flow: row;
44
grid-template-columns: var(--template-columns, auto);
55
}
6-
7-
.cas-[data-screen='sm'] {
8-
@media (max-width: var(--screens-sm)) {
9-
display: none;
10-
}
11-
}
12-
13-
.cas-[data-screen='md'] {
14-
@media (max-width: var(--screens-md)) {
15-
display: none;
16-
}
17-
}
18-
19-
.cas-[data-screen='sd'] {
20-
@media (max-width: var(--screens-sd)) {
21-
display: none;
22-
}
23-
}
24-
25-
.cas-[data-screen='lg'] {
26-
@media (max-width: var(--screens-lg)) {
27-
display: none;
28-
}
29-
}
30-
31-
.cas-[data-screen='xl'] {
32-
@media (max-width: var(--screens-xl)) {
33-
display: none;
34-
}
35-
}
36-
37-
.cas-[data-screen='2xl'] {
38-
@media (max-width: var(--screens-2xl)) {
39-
display: none;
40-
}
41-
}
42-
43-
.cas-[data-screen='3xl'] {
44-
@media (max-width: var(--screens-3xl)) {
45-
display: none;
46-
}
47-
}

0 commit comments

Comments
 (0)