Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib/components/combobox/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export { default as Root } from './combobox-root.svelte';
export { default as Trigger } from './combobox-trigger.svelte';
export { default as Item } from './compobox-item.svelte';
export { default as Input } from './combobox-input.svelte';
/**
* @deprecated use Combobox.Control instead
*/
export { default as Input } from './combobox-control.svelte';
export { default as Control } from './combobox-control.svelte';
export { Arrow, Indicator, List } from '$svelte-atoms/core/components/dropdown/atoms';
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
);
</script>

<Input.Value
<Input.Control
{value}
preset="combobox.input"
preset="combobox.control"
class={['flex-1 py-1', '$preset', klass]}
enter={enter?.bind(bond.state)}
exit={exit?.bind(bond.state)}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/form/form.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<Field.Label>First Name</Field.Label>
<Input.Root>
<Field.Control
base={Input.Value}
base={Input.Control}
placeholder="Enter your first name"
onblur={() => {
const results = field?.state.validate();
Expand All @@ -65,7 +65,7 @@
<Field.Root name="last name" schema={personSchema.shape.lastName}>
<Field.Label>Last Name</Field.Label>
<Input.Root>
<Field.Control base={Input.Value} placeholder="Enter your last name" />
<Field.Control base={Input.Control} placeholder="Enter your last name" />
</Input.Root>
</Field.Root>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/lib/components/input/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { default as Root } from './input-root.svelte';
export { default as Value } from './input-value.svelte';
/**
* @deprecated use Input.Control instead
*/
export { default as Value } from './input-control.svelte';
export { default as Control } from './input-control.svelte';
export { default as Icon } from './input-icon.svelte';
export { default as Placeholder } from './input-placeholder.svelte';
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
<script module lang="ts">
export type InputPortals = 'input.l0' | 'input.l1' | 'input.l2' | 'input.l3';

export type InputProps = {
value?: ClassValue;
files?: File[];
date?: Date | null;
number?: number;
checked?: boolean;
class?: string;
type?: HTMLInputTypeAttribute | null;
preset?: PresetModuleName | (string & {});
children?: Snippet<[]>;
};
</script>

<script>
import type { Snippet } from 'svelte';
import type { HTMLInputTypeAttribute } from 'svelte/elements';
<script lang="ts" generics="B extends Base = Base">
import { on } from '$svelte-atoms/core/attachments/event.svelte';
import { getPreset } from '$svelte-atoms/core/context';
import { cn, toClassValue, type ClassValue } from '$svelte-atoms/core/utils';
import { cn, toClassValue } from '$svelte-atoms/core/utils';
import type { PresetModuleName } from '$svelte-atoms/core/context/preset.svelte';
import type { Base } from '$svelte-atoms/core/components/atom';
import { InputBond } from './bond.svelte';
import type { InputControlProps } from './types';

const bond = InputBond.get();

Expand All @@ -33,11 +21,11 @@
checked = $bindable(),
class: klass = '',
type = 'text',
preset: presetKey = 'input.value',
preset: presetKey = 'input.control',
onchange = undefined,
oninput = undefined,
...restProps
}: InputProps = $props();
}: InputControlProps<B> = $props();

const preset = getPreset(presetKey as PresetModuleName)?.apply(bond, [bond]);

Expand Down Expand Up @@ -81,10 +69,15 @@
event: ev
});
}

function toFileList(files: File[]) {
const dataTransfer = new DataTransfer();
files.forEach((file) => dataTransfer.items.add(file));
return dataTransfer.files;
}
</script>

<input
{type}
bind:value={
() => value,
(v) => {
Expand All @@ -95,10 +88,11 @@
}
}
class={cn(
'h-full w-full flex-1 bg-transparent px-2 leading-1 outline-none',
'text-foreground placeholder:text-muted-foreground h-full w-full flex-1 bg-transparent px-2 leading-1 outline-none',
preset?.class,
toClassValue(klass, bond)
)}
type={type ?? 'text'}
onchange={handleChange}
oninput={handleInput}
{...valueProps}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/input/input-icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Icon
preset="input.icon"
class={[
'flex aspect-square h-full items-center justify-center bg-transparent text-sm leading-0',
'border-border flex aspect-square h-full items-center justify-center bg-transparent text-sm leading-0',
'$preset',
klass
]}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/components/input/input-placeholder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
return !bond?.state.props.files?.length;
}

console.log(!bond?.state.props.value);

return !bond?.state.props.value;
});
</script>
Expand All @@ -44,7 +42,7 @@
<HtmlAtom
preset="input.placeholder"
class={[
'pointer-events-none absolute inset-0 flex h-full w-full items-center px-1 leading-1 outline-none',
'text-muted-foreground pointer-events-none absolute inset-0 flex h-full w-full items-center px-1 leading-1 outline-none',
'$preset',
klass
]}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/input/input-root.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
type HtmlAtomProps,
type Base
} from '$svelte-atoms/core/components/atom';
import type { InputRootProps } from './types';

type Element = ElementType<E>;

Expand All @@ -20,7 +21,7 @@
children = undefined,
factory = _factory,
...restProps
}: HtmlAtomProps<E, B> & HTMLAttributes<Element> = $props();
}: InputRootProps<E, B> = $props();

const bondProps = defineState<InputStateProps>([
defineProperty(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/input/input.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<Label for="price-input">Price</Label>
<AInput.Root>
<AInput.Icon class="text-foreground box-content px-0">$</AInput.Icon>
<AInput.Value id="price-input" class="border-border box-content border-x px-2 py-2">
<AInput.Control id="price-input" class="border-border box-content border-x px-2 py-2">
<!-- -->
</AInput.Value>
</AInput.Control>
<AInput.Icon class="text-foreground box-content px-2">.00</AInput.Icon>

<AInput.Placeholder class="text-foreground/20 pl-2">Hello World</AInput.Placeholder>
Expand Down
30 changes: 30 additions & 0 deletions src/lib/components/input/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { HTMLAttributes, HTMLInputTypeAttribute } from 'svelte/elements';
import type { Base, ElementType, HtmlAtomProps } from '../atom';
import type { ClassValue } from '$svelte-atoms/core/utils';
import type { Snippet } from 'svelte';
import type { Override } from '$svelte-atoms/core/types';

export type InputRootProps<
E extends keyof HTMLElementTagNameMap = 'div',
B extends Base = Base
> = HtmlAtomProps<E, B> &
HTMLAttributes<ElementType<E>> & {
value?: string | number | string[] | null;
checked?: boolean;
files?: File[] | null;
children?: Snippet<[]>;
};

type InputControlBaseProps = {
value?: any;
files?: File[];
date?: Date | null;
number?: number;
checked?: boolean;
class?: string;
type?: HTMLInputTypeAttribute | null;
children?: Snippet<[]>;
};

export type InputControlProps<B extends Base = Base> = HtmlAtomProps<'input', B> &
Override<HTMLAttributes<HTMLInputElement>, InputControlBaseProps>;
4 changes: 2 additions & 2 deletions src/lib/context/preset.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type PresetModuleName =
| 'collapsible.header'
| 'collapsible.indicator'
| 'collapsible'
| 'combobox.input'
| 'combobox.control'
| 'combobox.trigger'
| 'combobox.item'
| 'dialog.close-button'
Expand All @@ -54,7 +54,7 @@ export type PresetModuleName =
| 'form'
| 'icon'
| 'input'
| 'input.value'
| 'input.control'
| 'input.placeholder'
| 'label'
| 'layer.inner'
Expand Down