@julianelda/domos 1.3.0 → 2.0.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/README.md +21 -0
- package/dist/button/button.mocks.js +3 -12
- package/dist/button/button.stories.svelte +9 -9
- package/dist/button/button.svelte +4 -13
- package/dist/button/button.types.d.ts +5 -6
- package/dist/checkbox/checkbox.mocks.js +2 -4
- package/dist/checkbox/checkbox.stories.svelte +5 -14
- package/dist/checkbox/checkbox.svelte +3 -14
- package/dist/checkbox/checkbox.types.d.ts +2 -5
- package/dist/input/input.stories.svelte +11 -23
- package/dist/input/input.svelte +2 -19
- package/dist/input/input.types.d.ts +5 -2
- package/dist/input-button/input-button.svelte +2 -12
- package/dist/input-button/input-button.types.d.ts +4 -4
- package/dist/input-field/input-field.mocks.js +5 -0
- package/dist/input-field/input-field.svelte +2 -15
- package/dist/input-field/input-field.types.d.ts +2 -7
- package/dist/input-select/input-select.mocks.js +28 -16
- package/dist/input-select/input-select.svelte +20 -33
- package/dist/input-select/input-select.types.d.ts +10 -15
- package/dist/select/select.mocks.js +0 -2
- package/dist/select/select.stories.svelte +41 -0
- package/dist/select/select.stories.svelte.d.ts +27 -0
- package/dist/select/select.svelte +2 -13
- package/dist/select/select.types.d.ts +5 -2
- package/dist/select-field/select-field.mocks.js +2 -2
- package/dist/select-field/select-field.svelte +3 -11
- package/dist/select-field/select-field.types.d.ts +2 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# scratchpad
|
|
2
|
+
|
|
3
|
+
> Svelte components and styles. Designed and developed by Julius Polar.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@julianelda/domos)
|
|
6
|
+
[](https://github.com/JulianElda/domos/blob/master/LICENSE)
|
|
7
|
+
|
|
8
|
+
# Usage
|
|
9
|
+
|
|
10
|
+
Install from npm
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bun add @julianelda@domos
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Add import and source in tailwind file
|
|
17
|
+
|
|
18
|
+
```css
|
|
19
|
+
@import "@julianelda/domos/tailwind";
|
|
20
|
+
@import "@julianelda/domos/background";
|
|
21
|
+
```
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
export const buttonPropsPrimary = {
|
|
2
|
+
"data-testid": "primary-button",
|
|
2
3
|
id: "primary-button",
|
|
3
|
-
|
|
4
|
-
console.log("");
|
|
5
|
-
},
|
|
6
|
-
style: "primary",
|
|
7
|
-
text: "Primary button",
|
|
8
|
-
type: "button",
|
|
4
|
+
variant: "primary",
|
|
9
5
|
};
|
|
10
6
|
export const buttonPropsSecondary = {
|
|
11
7
|
id: "secondary-button",
|
|
12
|
-
|
|
13
|
-
console.log("");
|
|
14
|
-
},
|
|
15
|
-
style: "secondary",
|
|
16
|
-
text: "Secondary button",
|
|
17
|
-
type: "button",
|
|
8
|
+
variant: "secondary",
|
|
18
9
|
};
|
|
@@ -10,26 +10,26 @@
|
|
|
10
10
|
onclick: fn(),
|
|
11
11
|
},
|
|
12
12
|
argTypes: {
|
|
13
|
-
|
|
14
|
-
style: {
|
|
13
|
+
variant: {
|
|
15
14
|
control: { type: "select" },
|
|
16
15
|
options: ["primary", "secondary"],
|
|
17
16
|
},
|
|
18
|
-
text: { control: "text" },
|
|
19
|
-
type: {
|
|
20
|
-
control: { type: "select" },
|
|
21
|
-
options: ["button", "submit"],
|
|
22
|
-
},
|
|
23
17
|
},
|
|
24
18
|
component: Button,
|
|
25
19
|
title: "Button",
|
|
26
20
|
});
|
|
27
21
|
</script>
|
|
28
22
|
|
|
23
|
+
{#snippet children()}
|
|
24
|
+
Button
|
|
25
|
+
{/snippet}
|
|
26
|
+
|
|
29
27
|
<Story
|
|
30
28
|
name="Primary"
|
|
31
|
-
args={buttonPropsPrimary}
|
|
29
|
+
args={{ buttonPropsPrimary, children }}>
|
|
30
|
+
</Story>
|
|
32
31
|
|
|
33
32
|
<Story
|
|
34
33
|
name="Secondary"
|
|
35
|
-
args={buttonPropsSecondary}
|
|
34
|
+
args={{ buttonPropsSecondary, children }}>
|
|
35
|
+
</Story>
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { ButtonProps } from "./button.types.js";
|
|
3
3
|
|
|
4
|
-
const {
|
|
5
|
-
id,
|
|
6
|
-
onClick,
|
|
7
|
-
style = "primary",
|
|
8
|
-
text,
|
|
9
|
-
type = "button",
|
|
10
|
-
}: ButtonProps = $props();
|
|
4
|
+
const { children, variant = "primary", ...rest }: ButtonProps = $props();
|
|
11
5
|
</script>
|
|
12
6
|
|
|
13
7
|
<button
|
|
14
|
-
|
|
15
|
-
{id}
|
|
16
|
-
onclick={onClick}
|
|
17
|
-
{type}
|
|
8
|
+
{...rest}
|
|
18
9
|
class={[
|
|
19
10
|
"cursor-pointer appearance-none rounded-lg p-2 text-lg shadow-sm hover:border-primary-500 hover:bg-primary-500 focus:ring-primary-300 focus-visible:outline focus-visible:outline-offset-2 focus-visible:outline-primary-300 active:bg-primary-700 dark:hover:bg-primary-500",
|
|
20
|
-
|
|
11
|
+
variant === "primary"
|
|
21
12
|
? "border-primary-700 bg-primary-700 text-ink-white"
|
|
22
13
|
: "border border-ink-500 bg-card-background-light text-ink-black hover:text-white dark:bg-slate dark:text-ink-white",
|
|
23
14
|
]}>
|
|
24
|
-
{
|
|
15
|
+
{@render children?.()}
|
|
25
16
|
</button>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type: "button" | "submit";
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
3
|
+
export interface ButtonProps extends HTMLButtonAttributes {
|
|
4
|
+
children?: Snippet;
|
|
5
|
+
variant?: "primary" | "secondary";
|
|
7
6
|
}
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
const { Story } = defineMeta({
|
|
9
9
|
args: {
|
|
10
|
-
|
|
10
|
+
onchange: fn(),
|
|
11
11
|
},
|
|
12
12
|
argTypes: {
|
|
13
|
+
checked: { control: "boolean" },
|
|
13
14
|
hideLabel: { control: "boolean" },
|
|
14
15
|
id: { control: "text" },
|
|
15
16
|
label: { control: "text" },
|
|
16
|
-
value: { control: "boolean" },
|
|
17
17
|
},
|
|
18
18
|
component: Checkbox,
|
|
19
19
|
title: "Checkbox",
|
|
@@ -22,21 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
<Story
|
|
24
24
|
name="Checked"
|
|
25
|
-
args={{
|
|
26
|
-
...checkboxProps,
|
|
27
|
-
value: true,
|
|
28
|
-
}} />
|
|
25
|
+
args={{ ...checkboxProps, checked: true }} />
|
|
29
26
|
|
|
30
27
|
<Story
|
|
31
28
|
name="Unchecked"
|
|
32
|
-
args={{
|
|
33
|
-
...checkboxProps,
|
|
34
|
-
value: false,
|
|
35
|
-
}} />
|
|
29
|
+
args={{ ...checkboxProps, checked: false }} />
|
|
36
30
|
|
|
37
31
|
<Story
|
|
38
32
|
name="Hidden Label"
|
|
39
|
-
args={{
|
|
40
|
-
...checkboxProps,
|
|
41
|
-
hideLabel: true,
|
|
42
|
-
}} />
|
|
33
|
+
args={{ ...checkboxProps, hideLabel: true }} />
|
|
@@ -3,26 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
import type { CheckboxProps } from "./checkbox.types.js";
|
|
5
5
|
|
|
6
|
-
const {
|
|
7
|
-
disabled = false,
|
|
8
|
-
hideLabel,
|
|
9
|
-
id,
|
|
10
|
-
label,
|
|
11
|
-
onChange,
|
|
12
|
-
value,
|
|
13
|
-
}: CheckboxProps = $props();
|
|
6
|
+
const { hideLabel, id, label, ...rest }: CheckboxProps = $props();
|
|
14
7
|
</script>
|
|
15
8
|
|
|
16
9
|
<div class="relative flex items-start gap-1">
|
|
17
10
|
<div class="flex h-6 items-center">
|
|
18
11
|
<input
|
|
19
|
-
|
|
20
|
-
class="form-checkbox inline-block size-4 rounded-md border-0 bg-white p-1 text-primary-500 accent-primary-500 ring-1 ring-ink-500 ring-inset focus:border-primary-300 focus:ring-1 focus:ring-primary-300 focus:ring-inset dark:bg-ink-500"
|
|
21
|
-
data-testid={id}
|
|
22
|
-
{disabled}
|
|
12
|
+
{...rest}
|
|
23
13
|
{id}
|
|
24
|
-
|
|
25
|
-
onchange={(event) => onChange((event.target as HTMLInputElement).checked)}
|
|
14
|
+
class="form-checkbox inline-block size-4 rounded-md border-0 bg-white p-1 text-primary-500 accent-primary-500 ring-1 ring-ink-500 ring-inset focus:border-primary-300 focus:ring-1 focus:ring-primary-300 focus:ring-inset dark:bg-ink-500"
|
|
26
15
|
type="checkbox" />
|
|
27
16
|
</div>
|
|
28
17
|
<div class="leading-6">
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
2
|
+
export interface CheckboxProps extends HTMLInputAttributes {
|
|
3
3
|
hideLabel?: boolean;
|
|
4
|
-
id: string;
|
|
5
4
|
label: string;
|
|
6
|
-
onChange: (value: boolean) => void;
|
|
7
|
-
value: boolean;
|
|
8
5
|
}
|
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
const { Story } = defineMeta({
|
|
9
9
|
args: {
|
|
10
|
-
|
|
11
|
-
onKeyDown: fn(),
|
|
10
|
+
oninput: fn(),
|
|
12
11
|
},
|
|
13
12
|
argTypes: {
|
|
13
|
+
disabled: { control: "boolean" },
|
|
14
14
|
hideLabel: { control: "boolean" },
|
|
15
15
|
id: { control: "text" },
|
|
16
16
|
label: { control: "text" },
|
|
17
17
|
placeholder: { control: "text" },
|
|
18
|
-
value: { control: "text" },
|
|
19
18
|
},
|
|
20
19
|
component: Input,
|
|
21
20
|
title: "Input",
|
|
@@ -24,31 +23,19 @@
|
|
|
24
23
|
|
|
25
24
|
<Story
|
|
26
25
|
name="Input type text"
|
|
27
|
-
args={{
|
|
28
|
-
...inputProps1,
|
|
29
|
-
hideLabel: false,
|
|
30
|
-
}} />
|
|
26
|
+
args={{ ...inputProps1, hideLabel: false }} />
|
|
31
27
|
|
|
32
28
|
<Story
|
|
33
29
|
name="Input type number"
|
|
34
|
-
args={{
|
|
35
|
-
...inputProps2,
|
|
36
|
-
hideLabel: false,
|
|
37
|
-
}} />
|
|
30
|
+
args={{ ...inputProps2, hideLabel: false }} />
|
|
38
31
|
|
|
39
32
|
<Story
|
|
40
33
|
name="Input type search"
|
|
41
|
-
args={{
|
|
42
|
-
...inputProps3,
|
|
43
|
-
hideLabel: false,
|
|
44
|
-
}} />
|
|
34
|
+
args={{ ...inputProps3, hideLabel: false }} />
|
|
45
35
|
|
|
46
36
|
<Story
|
|
47
37
|
name="Input without label"
|
|
48
|
-
args={{
|
|
49
|
-
...inputProps1,
|
|
50
|
-
hideLabel: true,
|
|
51
|
-
}} />
|
|
38
|
+
args={{ ...inputProps1, hideLabel: true }} />
|
|
52
39
|
|
|
53
40
|
<Story
|
|
54
41
|
name="Input with placeholder"
|
|
@@ -61,7 +48,8 @@
|
|
|
61
48
|
|
|
62
49
|
<Story
|
|
63
50
|
name="Borderless"
|
|
64
|
-
args={{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
args={{ ...inputProps1, borderless: true }} />
|
|
52
|
+
|
|
53
|
+
<Story
|
|
54
|
+
name="Disabled"
|
|
55
|
+
args={{ ...inputProps1, hideLabel: false, disabled: true }} />
|
package/dist/input/input.svelte
CHANGED
|
@@ -4,18 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { InputProps } from "./input.types.js";
|
|
6
6
|
|
|
7
|
-
const {
|
|
8
|
-
borderless,
|
|
9
|
-
disabled,
|
|
10
|
-
hideLabel,
|
|
11
|
-
id,
|
|
12
|
-
label,
|
|
13
|
-
onChange,
|
|
14
|
-
onKeyDown,
|
|
15
|
-
placeholder,
|
|
16
|
-
type,
|
|
17
|
-
value,
|
|
18
|
-
}: InputProps = $props();
|
|
7
|
+
const { hideLabel, id, label, ...rest }: InputProps = $props();
|
|
19
8
|
</script>
|
|
20
9
|
|
|
21
10
|
<div class="flex flex-1 flex-col gap-1">
|
|
@@ -24,12 +13,6 @@
|
|
|
24
13
|
{id}
|
|
25
14
|
{label} />
|
|
26
15
|
<InputField
|
|
27
|
-
{borderless}
|
|
28
|
-
{disabled}
|
|
29
16
|
{id}
|
|
30
|
-
{
|
|
31
|
-
{onKeyDown}
|
|
32
|
-
{placeholder}
|
|
33
|
-
{type}
|
|
34
|
-
{value} />
|
|
17
|
+
{...rest} />
|
|
35
18
|
</div>
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { InputFieldProps } from "./../input-field/input-field.types.ts";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export interface InputProps extends InputFieldProps {
|
|
3
|
+
hideLabel?: boolean;
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
@@ -6,17 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
8
|
buttonAriaLabel,
|
|
9
|
-
disabled,
|
|
10
9
|
hideLabel,
|
|
11
10
|
icon,
|
|
12
11
|
id,
|
|
13
12
|
label,
|
|
14
13
|
onButtonClick,
|
|
15
|
-
|
|
16
|
-
onKeyDown,
|
|
17
|
-
placeholder,
|
|
18
|
-
type,
|
|
19
|
-
value,
|
|
14
|
+
...rest
|
|
20
15
|
}: InputButtonProps = $props();
|
|
21
16
|
</script>
|
|
22
17
|
|
|
@@ -27,13 +22,8 @@
|
|
|
27
22
|
{label} />
|
|
28
23
|
<div class="relative flex grow items-stretch focus-within:z-10">
|
|
29
24
|
<InputField
|
|
30
|
-
{disabled}
|
|
31
25
|
{id}
|
|
32
|
-
|
|
33
|
-
onKeyDown={(value) => onKeyDown?.(value)}
|
|
34
|
-
{placeholder}
|
|
35
|
-
{type}
|
|
36
|
-
{value}
|
|
26
|
+
{...rest}
|
|
37
27
|
withIconLeft={true} />
|
|
38
28
|
</div>
|
|
39
29
|
<button
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Component } from "svelte";
|
|
2
2
|
import type { InputFieldProps } from "./../input-field/input-field.types.ts";
|
|
3
|
-
|
|
4
|
-
export type InputButtonProps = IconButtonProps & InputFieldProps & InputLabelProps;
|
|
5
|
-
interface IconButtonProps {
|
|
3
|
+
export interface InputButtonProps extends InputFieldProps {
|
|
6
4
|
buttonAriaLabel: string;
|
|
5
|
+
hideLabel?: boolean;
|
|
7
6
|
icon?: Component;
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
8
9
|
onButtonClick: () => void;
|
|
9
10
|
}
|
|
10
|
-
export {};
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
export const inputFieldProps1 = {
|
|
2
|
+
"data-testid": "input-id-1",
|
|
2
3
|
id: "input-id-1",
|
|
3
4
|
type: "text",
|
|
4
5
|
value: "Input value",
|
|
5
6
|
};
|
|
6
7
|
export const inputFieldProps2 = {
|
|
8
|
+
"data-testid": "input-id-2",
|
|
7
9
|
id: "input-id-2",
|
|
8
10
|
type: "number",
|
|
9
11
|
value: 100,
|
|
10
12
|
};
|
|
11
13
|
export const inputFieldProps3 = {
|
|
14
|
+
"data-testid": "input-id-3",
|
|
12
15
|
id: "input-id-3",
|
|
13
16
|
type: "search",
|
|
14
17
|
value: "Search query",
|
|
15
18
|
};
|
|
16
19
|
export const inputFieldProps4 = {
|
|
20
|
+
"data-testid": "input-id-4",
|
|
17
21
|
id: "input-id-4",
|
|
18
22
|
type: "number",
|
|
19
23
|
value: 100,
|
|
20
24
|
};
|
|
21
25
|
export const inputFieldProps5 = {
|
|
26
|
+
"data-testid": "input-id-5",
|
|
22
27
|
id: "input-id-5",
|
|
23
28
|
type: "range",
|
|
24
29
|
value: 10,
|
|
@@ -3,26 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
borderless = false,
|
|
6
|
-
disabled = false,
|
|
7
|
-
id,
|
|
8
|
-
onChange,
|
|
9
|
-
onKeyDown,
|
|
10
|
-
placeholder = "",
|
|
11
|
-
type = "text",
|
|
12
|
-
value,
|
|
13
6
|
withIconLeft = false,
|
|
7
|
+
...rest
|
|
14
8
|
}: InputFieldProps = $props();
|
|
15
9
|
</script>
|
|
16
10
|
|
|
17
11
|
<input
|
|
18
|
-
|
|
19
|
-
{id}
|
|
20
|
-
{disabled}
|
|
21
|
-
oninput={(e) => onChange?.((e.target as HTMLInputElement).value)}
|
|
22
|
-
onkeydown={(e) => onKeyDown?.((e.target as HTMLInputElement).value)}
|
|
23
|
-
{placeholder}
|
|
24
|
-
{type}
|
|
25
|
-
{value}
|
|
12
|
+
{...rest}
|
|
26
13
|
class={[
|
|
27
14
|
"form-input block w-full appearance-none border text-ink-black dark:text-app-text-dark",
|
|
28
15
|
borderless === true
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { HTMLInputAttributes } from "svelte/elements";
|
|
2
|
+
export interface InputFieldProps extends HTMLInputAttributes {
|
|
2
3
|
borderless?: boolean;
|
|
3
|
-
disabled?: boolean;
|
|
4
4
|
id: string;
|
|
5
|
-
onChange?: (value: string) => void;
|
|
6
|
-
onKeyDown?: (value: string) => void;
|
|
7
|
-
placeholder?: string;
|
|
8
|
-
type: InputFieldTypes;
|
|
9
|
-
value: number | string;
|
|
10
5
|
withIconLeft?: boolean;
|
|
11
6
|
}
|
|
12
7
|
export type InputFieldTypes = "number" | "range" | "search" | "text";
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import { selectFieldOptions1, selectFieldOptions2, } from "./../select-field/select-field.mocks.js";
|
|
2
2
|
export const inputSelectProps1 = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
inputProps: {
|
|
4
|
+
"data-testid": "input-id-1",
|
|
5
|
+
id: "input-id-1",
|
|
6
|
+
label: "Currency amount",
|
|
7
|
+
type: "text",
|
|
8
|
+
value: "100",
|
|
9
|
+
},
|
|
10
|
+
selectProps: {
|
|
11
|
+
"data-testid": "select-id-1",
|
|
12
|
+
id: "select-id-1",
|
|
13
|
+
label: "Currency select",
|
|
14
|
+
options: [...selectFieldOptions1],
|
|
15
|
+
value: selectFieldOptions1[0].value,
|
|
16
|
+
},
|
|
11
17
|
};
|
|
12
18
|
export const inputSelectProps2 = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
inputProps: {
|
|
20
|
+
"data-testid": "input-id-2",
|
|
21
|
+
id: "input-id-2",
|
|
22
|
+
label: "Currency amount",
|
|
23
|
+
type: "text",
|
|
24
|
+
value: "100",
|
|
25
|
+
},
|
|
26
|
+
selectProps: {
|
|
27
|
+
"data-testid": "select-id-2",
|
|
28
|
+
id: "select-id-2",
|
|
29
|
+
label: "Currency select",
|
|
30
|
+
options: [...selectFieldOptions2],
|
|
31
|
+
value: selectFieldOptions2[2].value,
|
|
32
|
+
},
|
|
21
33
|
};
|
|
@@ -5,49 +5,36 @@
|
|
|
5
5
|
|
|
6
6
|
import type { InputSelectProps } from "./input-select.types.js";
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
selectValue,
|
|
22
|
-
type,
|
|
23
|
-
}: InputSelectProps = $props();
|
|
8
|
+
const { hideLabel, inputProps, selectProps }: InputSelectProps = $props();
|
|
9
|
+
|
|
10
|
+
const inputFieldProps = $derived.by(() => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
+
const { label: _label, ...rest } = inputProps;
|
|
13
|
+
return rest;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const selectFieldProps = $derived.by(() => {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
const { label: _label, ...rest } = selectProps;
|
|
19
|
+
return rest;
|
|
20
|
+
});
|
|
24
21
|
</script>
|
|
25
22
|
|
|
26
23
|
<div class="flex flex-1 flex-col gap-1">
|
|
27
24
|
<InputLabel
|
|
28
25
|
{hideLabel}
|
|
29
|
-
id={
|
|
30
|
-
label={
|
|
26
|
+
id={inputProps.id}
|
|
27
|
+
label={inputProps.label} />
|
|
31
28
|
<div class="relative rounded-md shadow-xs">
|
|
32
|
-
<InputField
|
|
33
|
-
disabled={inputDisabled}
|
|
34
|
-
id={inputId}
|
|
35
|
-
onChange={(value) => onInputChange?.(value)}
|
|
36
|
-
onKeyDown={(value) => onInputKeydown?.(value)}
|
|
37
|
-
placeholder={inputPlaceholder}
|
|
38
|
-
{type}
|
|
39
|
-
value={inputValue} />
|
|
29
|
+
<InputField {...inputFieldProps} />
|
|
40
30
|
<div class="absolute inset-y-0 right-0 flex items-center">
|
|
41
31
|
<InputLabel
|
|
42
32
|
hideLabel={true}
|
|
43
|
-
id={
|
|
44
|
-
label={
|
|
33
|
+
id={selectProps.id}
|
|
34
|
+
label={selectProps.label} />
|
|
45
35
|
<SelectField
|
|
46
|
-
|
|
47
|
-
inInputField={true}
|
|
48
|
-
onChange={(value) => onSelectChange?.(value)}
|
|
49
|
-
{options}
|
|
50
|
-
value={selectValue} />
|
|
36
|
+
{...selectFieldProps}
|
|
37
|
+
inInputField={true} />
|
|
51
38
|
</div>
|
|
52
39
|
</div>
|
|
53
40
|
</div>
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { InputFieldProps } from "./../input-field/input-field.types.ts";
|
|
2
|
+
import type { SelectFieldProps } from "./../select-field/select-field.types.ts";
|
|
3
|
+
export interface InputSelectInputProps extends InputFieldProps {
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
3
6
|
export interface InputSelectProps {
|
|
4
7
|
hideLabel?: boolean;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
onInputChange?: (value: number | string) => void;
|
|
11
|
-
onInputKeydown?: (key: number | string) => void;
|
|
12
|
-
onSelectChange?: (value: string) => void;
|
|
13
|
-
options: SelectFieldOption[];
|
|
14
|
-
selectId: string;
|
|
15
|
-
selectLabel: string;
|
|
16
|
-
selectValue: string;
|
|
17
|
-
type: InputFieldTypes;
|
|
8
|
+
inputProps: InputSelectInputProps;
|
|
9
|
+
selectProps: InputSelectSelectProps;
|
|
10
|
+
}
|
|
11
|
+
export interface InputSelectSelectProps extends SelectFieldProps {
|
|
12
|
+
label: string;
|
|
18
13
|
}
|
|
@@ -2,10 +2,8 @@ import { selectFieldProps1, selectFieldProps2, } from "./../select-field/select-
|
|
|
2
2
|
export const selectProps1 = {
|
|
3
3
|
...selectFieldProps1,
|
|
4
4
|
label: "Select currency",
|
|
5
|
-
value: selectFieldProps1.options[0].value,
|
|
6
5
|
};
|
|
7
6
|
export const selectProps2 = {
|
|
8
7
|
...selectFieldProps2,
|
|
9
8
|
label: "Select currency",
|
|
10
|
-
value: selectFieldProps2.options[2].value,
|
|
11
9
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
|
+
import { fn } from "storybook/test";
|
|
4
|
+
|
|
5
|
+
import { selectProps1, selectProps2 } from "./select.mocks.js";
|
|
6
|
+
import Select from "./select.svelte";
|
|
7
|
+
|
|
8
|
+
const { Story } = defineMeta({
|
|
9
|
+
args: {
|
|
10
|
+
onchange: fn(),
|
|
11
|
+
},
|
|
12
|
+
argTypes: {
|
|
13
|
+
disabled: { control: "boolean" },
|
|
14
|
+
hideLabel: { control: "boolean" },
|
|
15
|
+
id: { control: "text" },
|
|
16
|
+
label: { control: "text" },
|
|
17
|
+
},
|
|
18
|
+
component: Select,
|
|
19
|
+
title: "Select",
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<Story
|
|
24
|
+
name="Select with long labels"
|
|
25
|
+
args={{ ...selectProps1, hideLabel: false }} />
|
|
26
|
+
|
|
27
|
+
<Story
|
|
28
|
+
name="Select with short labels"
|
|
29
|
+
args={{ ...selectProps2, hideLabel: false }} />
|
|
30
|
+
|
|
31
|
+
<Story
|
|
32
|
+
name="Select without label"
|
|
33
|
+
args={{ ...selectProps1, hideLabel: true }} />
|
|
34
|
+
|
|
35
|
+
<Story
|
|
36
|
+
name="Borderless"
|
|
37
|
+
args={{ ...selectProps1, borderless: true, hideLabel: true }} />
|
|
38
|
+
|
|
39
|
+
<Story
|
|
40
|
+
name="Disabled"
|
|
41
|
+
args={{ ...selectProps1, hideLabel: false, disabled: true }} />
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default Select;
|
|
2
|
+
type Select = SvelteComponent<{
|
|
3
|
+
[x: string]: never;
|
|
4
|
+
}, {
|
|
5
|
+
[evt: string]: CustomEvent<any>;
|
|
6
|
+
}, {}> & {
|
|
7
|
+
$$bindings?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
declare const Select: $$__sveltets_2_IsomorphicComponent<{
|
|
10
|
+
[x: string]: never;
|
|
11
|
+
}, {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
}, {}, {}, string>;
|
|
14
|
+
import Select from "./select.svelte";
|
|
15
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
16
|
+
new (options: import("svelte").ComponentConstructorOptions<Props>): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
17
|
+
$$bindings?: Bindings;
|
|
18
|
+
} & Exports;
|
|
19
|
+
(internal: unknown, props: {
|
|
20
|
+
$$events?: Events;
|
|
21
|
+
$$slots?: Slots;
|
|
22
|
+
}): Exports & {
|
|
23
|
+
$set?: any;
|
|
24
|
+
$on?: any;
|
|
25
|
+
};
|
|
26
|
+
z_$$bindings?: Bindings;
|
|
27
|
+
}
|
|
@@ -4,15 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { SelectProps } from "./select.types.js";
|
|
6
6
|
|
|
7
|
-
const {
|
|
8
|
-
borderless,
|
|
9
|
-
hideLabel,
|
|
10
|
-
id,
|
|
11
|
-
label,
|
|
12
|
-
onChange,
|
|
13
|
-
options,
|
|
14
|
-
value,
|
|
15
|
-
}: SelectProps = $props();
|
|
7
|
+
const { hideLabel, id, label, ...rest }: SelectProps = $props();
|
|
16
8
|
</script>
|
|
17
9
|
|
|
18
10
|
<div class="flex flex-1 flex-col gap-1">
|
|
@@ -21,9 +13,6 @@
|
|
|
21
13
|
{id}
|
|
22
14
|
{label} />
|
|
23
15
|
<SelectField
|
|
24
|
-
{borderless}
|
|
25
16
|
{id}
|
|
26
|
-
{
|
|
27
|
-
{options}
|
|
28
|
-
{value} />
|
|
17
|
+
{...rest} />
|
|
29
18
|
</div>
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type { InputLabelProps } from "./../input-label/input-label.types.ts";
|
|
2
1
|
import type { SelectFieldProps } from "./../select-field/select-field.types.ts";
|
|
3
|
-
export
|
|
2
|
+
export interface SelectProps extends SelectFieldProps {
|
|
3
|
+
hideLabel?: boolean;
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
@@ -35,16 +35,16 @@ export const selectFieldOptions2 = [
|
|
|
35
35
|
},
|
|
36
36
|
];
|
|
37
37
|
export const selectFieldProps1 = {
|
|
38
|
+
"data-testid": "select-id-1",
|
|
38
39
|
id: "select-id-1",
|
|
39
40
|
inInputField: false,
|
|
40
|
-
onChange: () => { },
|
|
41
41
|
options: [...selectFieldOptions1],
|
|
42
42
|
value: selectFieldOptions1[0].value,
|
|
43
43
|
};
|
|
44
44
|
export const selectFieldProps2 = {
|
|
45
|
+
"data-testid": "select-id-2",
|
|
45
46
|
id: "select-id-2",
|
|
46
47
|
inInputField: false,
|
|
47
|
-
onChange: () => { },
|
|
48
48
|
options: [...selectFieldOptions2],
|
|
49
49
|
value: selectFieldOptions2[2].value,
|
|
50
50
|
};
|
|
@@ -3,31 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
borderless = false,
|
|
6
|
-
id,
|
|
7
6
|
inInputField = false,
|
|
8
|
-
onChange,
|
|
9
7
|
options,
|
|
10
|
-
|
|
8
|
+
...rest
|
|
11
9
|
}: SelectFieldProps = $props();
|
|
12
10
|
</script>
|
|
13
11
|
|
|
14
12
|
<select
|
|
13
|
+
{...rest}
|
|
15
14
|
class={[
|
|
16
15
|
"form-select w-full appearance-none rounded-md text-ink-black dark:bg-slate dark:text-ink-white",
|
|
17
|
-
|
|
18
16
|
borderless === true
|
|
19
17
|
? "border-0 bg-transparent p-0 ring-0 outline-none focus:ring-0 focus:outline-none"
|
|
20
18
|
: "border border-ink-gray py-2 pr-8 pl-2 focus:ring-1 focus:ring-primary-300 focus:ring-inset",
|
|
21
|
-
|
|
22
19
|
inInputField === true
|
|
23
20
|
? "h-full rounded-l-none bg-transparent"
|
|
24
21
|
: "block pl-3",
|
|
25
|
-
]}
|
|
26
|
-
data-testid={id}
|
|
27
|
-
{id}
|
|
28
|
-
name={id}
|
|
29
|
-
oninput={(e) => onChange((e.target as HTMLSelectElement).value as string)}
|
|
30
|
-
{value}>
|
|
22
|
+
]}>
|
|
31
23
|
{#each options as option (option.value)}
|
|
32
24
|
<option value={option.value}>
|
|
33
25
|
{option.label}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import type { HTMLSelectAttributes } from "svelte/elements";
|
|
1
2
|
export interface SelectFieldOption {
|
|
2
3
|
label: string;
|
|
3
4
|
value: string;
|
|
4
5
|
}
|
|
5
|
-
export interface SelectFieldProps {
|
|
6
|
+
export interface SelectFieldProps extends HTMLSelectAttributes {
|
|
6
7
|
borderless?: boolean;
|
|
7
8
|
id: string;
|
|
8
9
|
inInputField?: boolean;
|
|
9
|
-
onChange: (value: string) => void;
|
|
10
10
|
options: SelectFieldOption[];
|
|
11
|
-
value: string;
|
|
12
11
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@julianelda/domos",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"svelte"
|
|
6
6
|
],
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/JulianElda/arche",
|
|
9
|
+
"url": "git+https://github.com/JulianElda/arche.git",
|
|
10
10
|
"directory": "packages/domos"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|