@targoninc/jess-components 0.0.42 → 0.0.44
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 +23 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/src/Components.d.ts +108 -0
- package/dist/src/src/Debounce.d.ts +8 -0
- package/dist/src/src/Types.d.ts +70 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Example usage - Button
|
|
2
|
+
|
|
3
|
+
```typescript
|
|
4
|
+
import {button} from "@targoninc/jess-components";
|
|
5
|
+
|
|
6
|
+
const disabled = signal(false);
|
|
7
|
+
|
|
8
|
+
const element = button({
|
|
9
|
+
text: "Info",
|
|
10
|
+
disabled: disabled,
|
|
11
|
+
icon: {
|
|
12
|
+
icon: "/assets/buttonIcon.svg",
|
|
13
|
+
adaptive: true,
|
|
14
|
+
isUrl: true
|
|
15
|
+
},
|
|
16
|
+
onclick: () => {
|
|
17
|
+
console.log("button clicked");
|
|
18
|
+
disabled.value = true;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
document.body.appendChild(element);
|
|
23
|
+
```
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point for the `jess-components` package.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all public component factories from `src/Components` and all
|
|
5
|
+
* shared type definitions from `src/Types` so consumers can import from the
|
|
6
|
+
* package root.
|
|
7
|
+
*
|
|
8
|
+
* @module jess-components
|
|
9
|
+
*/
|
|
1
10
|
export * from "./src/Components";
|
|
2
11
|
export * from "./src/Types";
|
|
@@ -1,18 +1,126 @@
|
|
|
1
1
|
import type { BooleanConfig, ButtonConfig, ContainerConfig, HeadingConfig, IconConfig, InputConfig, SearchableSelectConfig, SelectConfig, SelectOptionConfig, TextareaConfig, TextConfig } from "./Types.ts";
|
|
2
2
|
import { type AnyElement, Signal, type StringOrSignal } from "@targoninc/jess";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a button element.
|
|
5
|
+
*
|
|
6
|
+
* Renders optional icon and text, applies disabled styling from `config.disabled`,
|
|
7
|
+
* and wires the `onclick` handler.
|
|
8
|
+
*
|
|
9
|
+
* @param config - {@link ButtonConfig} for the button.
|
|
10
|
+
* @returns A Jess element representing a `<button>`.
|
|
11
|
+
*/
|
|
3
12
|
export declare function button(config: ButtonConfig): AnyElement;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a labeled input control with validation and optional debouncing.
|
|
15
|
+
*
|
|
16
|
+
* Shows error messages from `validators` and `required` when `touched`.
|
|
17
|
+
* Supports password visibility toggle when `type === InputType.password`.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - Value type for the input component.
|
|
20
|
+
* @param config - {@link InputConfig} describing the input.
|
|
21
|
+
* @returns A Jess element representing the input control.
|
|
22
|
+
*/
|
|
4
23
|
export declare function input<T>(config: InputConfig<T>): AnyElement;
|
|
24
|
+
/**
|
|
25
|
+
* Helper that renders an eye icon button used by password inputs.
|
|
26
|
+
*
|
|
27
|
+
* @param toggleState - Signal toggled when the button is clicked.
|
|
28
|
+
* @param onClick - Callback invoked on click.
|
|
29
|
+
* @returns A Jess element representing the eye icon button.
|
|
30
|
+
*/
|
|
5
31
|
export declare function eyeButton(toggleState: Signal<boolean>, onClick: Function): AnyElement;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a labeled `<textarea>` with validation handling.
|
|
34
|
+
*
|
|
35
|
+
* @param config - {@link TextareaConfig} for the textarea.
|
|
36
|
+
* @returns A Jess element representing the textarea control.
|
|
37
|
+
*/
|
|
6
38
|
export declare function textarea(config: TextareaConfig): AnyElement;
|
|
39
|
+
/**
|
|
40
|
+
* Renders a list of validation errors.
|
|
41
|
+
*
|
|
42
|
+
* @param errors - Signal containing error messages.
|
|
43
|
+
* @returns A Jess element with error items.
|
|
44
|
+
*/
|
|
7
45
|
export declare function errorList(errors: Signal<string[]>): any;
|
|
46
|
+
/**
|
|
47
|
+
* Renders a single error message.
|
|
48
|
+
*
|
|
49
|
+
* @param error - Error message content.
|
|
50
|
+
* @returns A Jess element representing the error line.
|
|
51
|
+
*/
|
|
8
52
|
export declare function error(error: StringOrSignal): AnyElement;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a simple bordered area container.
|
|
55
|
+
*
|
|
56
|
+
* @param config - {@link ContainerConfig} for the container.
|
|
57
|
+
* @returns A Jess element representing the area container.
|
|
58
|
+
*/
|
|
9
59
|
export declare function area(config: ContainerConfig): AnyElement;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a generic container element with provided `tag` and `children`.
|
|
62
|
+
*
|
|
63
|
+
* @param config - {@link ContainerConfig}.
|
|
64
|
+
* @returns A Jess element for the container.
|
|
65
|
+
*/
|
|
10
66
|
export declare function container(config: ContainerConfig): AnyElement;
|
|
67
|
+
/**
|
|
68
|
+
* Renders text inside a given `tag` (e.g., `span`, `p`).
|
|
69
|
+
*
|
|
70
|
+
* @param config - {@link TextConfig}.
|
|
71
|
+
* @returns A Jess element for the text node.
|
|
72
|
+
*/
|
|
11
73
|
export declare function text(config: TextConfig): AnyElement;
|
|
74
|
+
/**
|
|
75
|
+
* Renders a heading (h1-h6) based on `level`.
|
|
76
|
+
*
|
|
77
|
+
* @param config - {@link HeadingConfig}.
|
|
78
|
+
* @returns A Jess heading element.
|
|
79
|
+
*/
|
|
12
80
|
export declare function heading(config: HeadingConfig): AnyElement;
|
|
81
|
+
/**
|
|
82
|
+
* Renders an icon element. If `isUrl` is truthy, renders an `<img>`; otherwise,
|
|
83
|
+
* renders an inline icon. When `adaptive` is true, adapts styles to context.
|
|
84
|
+
*
|
|
85
|
+
* @param config - {@link IconConfig} specifying icon source and behavior.
|
|
86
|
+
* @returns A signal of Jess element, allowing updates when icon-related signals change.
|
|
87
|
+
*/
|
|
13
88
|
export declare function icon(config: IconConfig): Signal<AnyElement>;
|
|
89
|
+
/**
|
|
90
|
+
* Renders a non-searchable select control.
|
|
91
|
+
*
|
|
92
|
+
* @typeParam T - Type of the option value.
|
|
93
|
+
* @param config - {@link SelectConfig} for the select.
|
|
94
|
+
* @returns A Jess element for the select control.
|
|
95
|
+
*/
|
|
14
96
|
export declare function select<T = any>(config: SelectConfig<T>): AnyElement;
|
|
97
|
+
/**
|
|
98
|
+
* Renders a searchable select control with a filterable dropdown.
|
|
99
|
+
*
|
|
100
|
+
* @typeParam T - Type of the option value.
|
|
101
|
+
* @param config - {@link SearchableSelectConfig} for the control.
|
|
102
|
+
* @returns A Jess element for the searchable select.
|
|
103
|
+
*/
|
|
15
104
|
export declare function searchableSelect<T = any>(config: SearchableSelectConfig<T>): AnyElement;
|
|
105
|
+
/**
|
|
106
|
+
* Renders a single selectable option for the searchable select dropdown.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam T - Type of the option value.
|
|
109
|
+
* @param config - {@link SelectOptionConfig} for the option.
|
|
110
|
+
* @returns A Jess element representing the option.
|
|
111
|
+
*/
|
|
16
112
|
export declare function searchSelectOption<T = any>(config: SelectOptionConfig<T>): AnyElement;
|
|
113
|
+
/**
|
|
114
|
+
* Renders a checkbox control with label and validation support.
|
|
115
|
+
*
|
|
116
|
+
* @param config - {@link BooleanConfig}.
|
|
117
|
+
* @returns A Jess element for the checkbox.
|
|
118
|
+
*/
|
|
17
119
|
export declare function checkbox(config: BooleanConfig): AnyElement;
|
|
120
|
+
/**
|
|
121
|
+
* Renders a binary on/off toggle switch with label and validation support.
|
|
122
|
+
*
|
|
123
|
+
* @param config - {@link BooleanConfig}.
|
|
124
|
+
* @returns A Jess element for the toggle switch.
|
|
125
|
+
*/
|
|
18
126
|
export declare function toggle(config: BooleanConfig): AnyElement;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debounces the provided `func` by the specified `delay` using the unique
|
|
3
|
+
* `identifier`. If `delay` is `0` or falsy, `func` runs immediately.
|
|
4
|
+
*
|
|
5
|
+
* @param identifier - Unique key for the debounced action.
|
|
6
|
+
* @param func - Callback to execute after the delay.
|
|
7
|
+
* @param delay - Delay in milliseconds (default: `0`).
|
|
8
|
+
*/
|
|
1
9
|
export declare function debounce(identifier: any, func: () => void, delay?: number): void;
|
package/dist/src/src/Types.d.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type and interface definitions used by `jess-components`.
|
|
3
|
+
*
|
|
4
|
+
* These types model the configuration objects accepted by the component
|
|
5
|
+
* factory functions in `Components.ts` and are part of the public API.
|
|
6
|
+
*
|
|
7
|
+
* @module jess-components/types
|
|
8
|
+
*/
|
|
1
9
|
import { type CssClass, DomNode, type EventHandler, type HtmlPropertyValue, InputType, Signal, type StringOrSignal, type TypeOrSignal } from "@targoninc/jess";
|
|
10
|
+
/**
|
|
11
|
+
* Utility type to enumerate numeric literal union `[0, 1, ..., N-1]`.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam N - Upper bound (exclusive).
|
|
14
|
+
*/
|
|
2
15
|
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
16
|
+
/**
|
|
17
|
+
* Utility type that produces a numeric literal union from `F` (inclusive)
|
|
18
|
+
* up to `T` (exclusive).
|
|
19
|
+
*
|
|
20
|
+
* @typeParam F - Start of range (inclusive).
|
|
21
|
+
* @typeParam T - End of range (exclusive).
|
|
22
|
+
*/
|
|
3
23
|
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
24
|
+
/**
|
|
25
|
+
* Base configuration applied to most components.
|
|
26
|
+
*/
|
|
4
27
|
export interface BaseComponentConfig {
|
|
5
28
|
classes?: StringOrSignal[];
|
|
6
29
|
attributes?: StringOrSignal[];
|
|
@@ -12,13 +35,23 @@ export interface BaseComponentConfig {
|
|
|
12
35
|
ariaLabel?: HtmlPropertyValue;
|
|
13
36
|
css?: CssClass;
|
|
14
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for a clickable button component.
|
|
40
|
+
*/
|
|
15
41
|
export interface ButtonConfig extends BaseComponentConfig {
|
|
16
42
|
text?: StringOrSignal;
|
|
17
43
|
onclick: EventHandler<MouseEvent>;
|
|
18
44
|
icon?: IconConfig;
|
|
19
45
|
disabled?: TypeOrSignal<boolean>;
|
|
20
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Function used to validate values for changeable components.
|
|
49
|
+
* Should return an array of error messages or `null/undefined` if valid.
|
|
50
|
+
*/
|
|
21
51
|
export type ValidatorFunction<T> = (value: T) => (string[] | null | undefined) | Promise<string[] | null | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Base configuration for input-like components that can change value.
|
|
54
|
+
*/
|
|
22
55
|
export interface ChangeableConfig<T = any> extends BaseComponentConfig {
|
|
23
56
|
onchange?: (value: T) => void;
|
|
24
57
|
validators?: ValidatorFunction<T>[];
|
|
@@ -27,6 +60,11 @@ export interface ChangeableConfig<T = any> extends BaseComponentConfig {
|
|
|
27
60
|
label?: HtmlPropertyValue;
|
|
28
61
|
disabled?: TypeOrSignal<boolean>;
|
|
29
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Configuration for the `input` component.
|
|
65
|
+
*
|
|
66
|
+
* @typeParam T - The value type of the input.
|
|
67
|
+
*/
|
|
30
68
|
export interface InputConfig<T> extends ChangeableConfig<T> {
|
|
31
69
|
name: StringOrSignal;
|
|
32
70
|
type: TypeOrSignal<InputType>;
|
|
@@ -38,6 +76,9 @@ export interface InputConfig<T> extends ChangeableConfig<T> {
|
|
|
38
76
|
infoText?: StringOrSignal;
|
|
39
77
|
debounce?: number;
|
|
40
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Configuration for the `textarea` component.
|
|
81
|
+
*/
|
|
41
82
|
export interface TextareaConfig extends ChangeableConfig<string> {
|
|
42
83
|
name: StringOrSignal;
|
|
43
84
|
value: StringOrSignal;
|
|
@@ -45,26 +86,41 @@ export interface TextareaConfig extends ChangeableConfig<string> {
|
|
|
45
86
|
rows?: TypeOrSignal<number>;
|
|
46
87
|
resize?: "both" | "horizontal" | "vertical" | "none";
|
|
47
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Configuration for a generic container/section component.
|
|
91
|
+
*/
|
|
48
92
|
export interface ContainerConfig extends BaseComponentConfig {
|
|
49
93
|
tag: string;
|
|
50
94
|
children: (DomNode)[];
|
|
51
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Configuration for generic text elements (e.g., `span`, `p`).
|
|
98
|
+
*/
|
|
52
99
|
export interface TextConfig extends BaseComponentConfig {
|
|
53
100
|
text: HtmlPropertyValue;
|
|
54
101
|
tag: string;
|
|
55
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Configuration for the `icon` component.
|
|
105
|
+
*/
|
|
56
106
|
export interface IconConfig extends BaseComponentConfig {
|
|
57
107
|
icon: StringOrSignal;
|
|
58
108
|
adaptive?: boolean;
|
|
59
109
|
isUrl?: TypeOrSignal<boolean>;
|
|
60
110
|
onclick?: Function;
|
|
61
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Represents a single option for a select component.
|
|
114
|
+
*/
|
|
62
115
|
export interface SelectOption<T> extends BaseComponentConfig {
|
|
63
116
|
image?: string;
|
|
64
117
|
imageIsUrl?: boolean;
|
|
65
118
|
name: any;
|
|
66
119
|
id: any | T;
|
|
67
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Internal configuration passed to `searchSelectOption`.
|
|
123
|
+
*/
|
|
68
124
|
export interface SelectOptionConfig<T> extends BaseComponentConfig {
|
|
69
125
|
option: SelectOption<T>;
|
|
70
126
|
value: Signal<any>;
|
|
@@ -72,15 +128,29 @@ export interface SelectOptionConfig<T> extends BaseComponentConfig {
|
|
|
72
128
|
optionsVisible: Signal<boolean>;
|
|
73
129
|
selectedId: Signal<any>;
|
|
74
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Configuration for the `searchableSelect` and `select` components.
|
|
133
|
+
*
|
|
134
|
+
* @typeParam T - The type of the selected value.
|
|
135
|
+
*/
|
|
75
136
|
export interface SearchableSelectConfig<T = string> extends ChangeableConfig<T> {
|
|
76
137
|
options: Signal<SelectOption<T>[]>;
|
|
77
138
|
value: Signal<T>;
|
|
78
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Alias for a simple select configuration.
|
|
142
|
+
*/
|
|
79
143
|
export type SelectConfig<T> = SearchableSelectConfig<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Configuration for the `heading` component.
|
|
146
|
+
*/
|
|
80
147
|
export interface HeadingConfig extends BaseComponentConfig {
|
|
81
148
|
level?: IntRange<1, 6>;
|
|
82
149
|
text: StringOrSignal;
|
|
83
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Configuration for boolean components like `checkbox` and `toggle`.
|
|
153
|
+
*/
|
|
84
154
|
export interface BooleanConfig extends ChangeableConfig<boolean> {
|
|
85
155
|
text: HtmlPropertyValue;
|
|
86
156
|
checked: TypeOrSignal<boolean>;
|