Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(packages/ui-svelte): add input component #51

Merged
merged 2 commits into from
Apr 23, 2024
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
2 changes: 1 addition & 1 deletion apps/sveltekit-example-app/src/routes/sign-up/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { zodClient } from 'sveltekit-superforms/adapters'

import { schema } from '$lib'
import { Button } from '@packages/ui-svelte/atoms/button'
import { Button } from '@packages/ui-svelte'

import type { PageData } from './$types.js'

Expand Down
6 changes: 5 additions & 1 deletion packages/ui-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "UI Component Library for Svelte and SvelteKit",
"type": "module",
"exports": {
"./atoms/*": "./src/components/atoms/*/index.ts",
".": {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to a root export file as not getting code completion for auto-import and resolving sub components to work correctly.

"types": "./src/index.ts",
"svelte": "./src/index.ts",
"default": "./src/index.ts"
},
"./styles/*": "./src/styles/*",
"./tailwind.config.js": "./tailwind.config.js"
},
Expand Down
29 changes: 29 additions & 0 deletions packages/ui-svelte/src/components/atoms/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Root from './input.svelte'

export type FormInputEvent<T extends Event = Event> = T & {
currentTarget: EventTarget & HTMLInputElement
}

export interface InputEvents {
blur: FormInputEvent<FocusEvent>
change: FormInputEvent<Event>
click: FormInputEvent<MouseEvent>
focus: FormInputEvent<FocusEvent>
focusin: FormInputEvent<FocusEvent>
focusout: FormInputEvent<FocusEvent>
keydown: FormInputEvent<KeyboardEvent>
keypress: FormInputEvent<KeyboardEvent>
keyup: FormInputEvent<KeyboardEvent>
mouseover: FormInputEvent<MouseEvent>
mouseenter: FormInputEvent<MouseEvent>
mouseleave: FormInputEvent<MouseEvent>
paste: FormInputEvent<ClipboardEvent>
input: FormInputEvent<InputEvent>
wheel: FormInputEvent<WheelEvent>
}

export {
Root,
//
Root as Input,
}
41 changes: 41 additions & 0 deletions packages/ui-svelte/src/components/atoms/input/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script lang="ts">
import { cn } from '../../../utils/index.js'

import type { InputEvents } from './index.js'
import type { HTMLInputAttributes } from 'svelte/elements'

type $$Props = HTMLInputAttributes
type $$Events = InputEvents

let className: $$Props['class'] = undefined
export let value: $$Props['value'] = undefined
export { className as class }

// Workaround for https://github.com/sveltejs/svelte/issues/9305
// Fixed in Svelte 5, but not backported to 4.x.
export let readonly: $$Props['readonly'] = undefined
</script>

<input
class={cn(
'border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
bind:value
{readonly}
on:blur
on:change
on:click
on:focus
on:focusin
on:focusout
on:keydown
on:keypress
on:keyup
on:mouseover
on:mouseenter
on:mouseleave
on:paste
on:input
on:wheel
{...$$restProps} />
44 changes: 44 additions & 0 deletions packages/ui-svelte/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* src/components/atoms/accordion
*/
export {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from './components/atoms/accordion/index.js'

/**
* src/components/atoms/button
*/
export {
Button,
type ButtonEvents,
type ButtonProps,
buttonVariants,
} from './components/atoms/button/index.js'

/**
* src/components/atoms/form
*/
export {
FormField,
FormControl,
FormDescription,
FormLabel,
FormFieldErrors,
FormFieldset,
FormLegend,
FormElementField,
FormButton,
} from './components/atoms/form/index.js'

/**
* src/components/atoms/input
*/
export { Input } from './components/atoms/input/index.js'

/**
* src/components/atoms/label
*/
export { Label } from './components/atoms/label/index.js'