@simple-base/contracts 0.1.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/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/badge.d.ts +12 -0
- package/dist/badge.js +7 -0
- package/dist/button.d.ts +12 -0
- package/dist/button.js +7 -0
- package/dist/card.d.ts +11 -0
- package/dist/card.js +7 -0
- package/dist/combobox.d.ts +22 -0
- package/dist/combobox.js +0 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/placement.d.ts +3 -0
- package/dist/placement.js +0 -0
- package/dist/select.d.ts +22 -0
- package/dist/select.js +0 -0
- package/dist/status.d.ts +17 -0
- package/dist/status.js +4 -0
- package/dist/table.d.ts +6 -0
- package/dist/table.js +0 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reda Salmi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @simple-base/contracts
|
|
2
|
+
|
|
3
|
+
Shared component option types and default constants for framework adapters such as
|
|
4
|
+
Solid and React. CSS owns styling; adapters own rendering, native props, and
|
|
5
|
+
behavior. This package has no runtime dependencies.
|
|
6
|
+
|
|
7
|
+
`packages/css/styles/` is the source of truth for supported styling options. Only
|
|
8
|
+
components with shared custom options need a contract. There are no class-name
|
|
9
|
+
maps, attribute-name maps, CSS-property maps, or class-only contracts.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
buttonDefaults,
|
|
16
|
+
type ButtonOptions,
|
|
17
|
+
type ButtonSize,
|
|
18
|
+
type ButtonVariant,
|
|
19
|
+
} from "@simple-base/contracts";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The same exports are available from `@simple-base/contracts/button`. Other
|
|
23
|
+
subpaths are `/badge`, `/card`, `/combobox`, `/placement`, `/select`, and
|
|
24
|
+
`/status`.
|
|
25
|
+
|
|
26
|
+
Adapters compose the shared options with their framework's native element props,
|
|
27
|
+
apply defaults when options are omitted, and emit the appropriate CSS classes and
|
|
28
|
+
attributes directly. Share framework-neutral public configuration and value
|
|
29
|
+
callbacks. Children, refs, framework-specific DOM events, native element prop
|
|
30
|
+
interfaces, internal context, and accessibility implementation stay in the adapters.
|
|
31
|
+
Every adapter part accepts a reactive `class` plus the native attributes for the
|
|
32
|
+
element it renders, excluding the attributes the widget owns. Widget event
|
|
33
|
+
handlers are composed with consumer handlers rather than replaced.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
export type ButtonOptions = {
|
|
37
|
+
variant?: ButtonVariant;
|
|
38
|
+
size?: ButtonSize;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const buttonDefaults = {
|
|
42
|
+
variant: "primary",
|
|
43
|
+
size: "medium",
|
|
44
|
+
} as const satisfies Required<ButtonOptions>;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Types are erased from runtime JavaScript. Only the default constants are runtime
|
|
48
|
+
exports; there are no allowed-value arrays without a runtime use case.
|
|
49
|
+
|
|
50
|
+
## Available options
|
|
51
|
+
|
|
52
|
+
| Component | Types | Defaults |
|
|
53
|
+
| ----------- | ---------------------------------------------- | ------------------------------------- |
|
|
54
|
+
| Button | `ButtonVariant`, `ButtonSize`, `ButtonOptions` | `buttonDefaults`: `primary`, `medium` |
|
|
55
|
+
| Badge | `BadgeVariant`, `BadgeSize`, `BadgeOptions` | `badgeDefaults`: `default`, `medium` |
|
|
56
|
+
| Card | `CardVariant`, `CardOptions` | `cardDefaults`: `padding: false` |
|
|
57
|
+
| Combobox | `ComboboxOption`, `ComboboxOptions` | No defaults |
|
|
58
|
+
| Select | `SelectOption`, `SelectOptions` | No defaults |
|
|
59
|
+
| Status line | `StatusValue`, `StatusOptions` | No default status |
|
|
60
|
+
| Alert | `AlertStatus`, `AlertOptions` | No default status |
|
|
61
|
+
| Toast | `ToastStatus`, `ToastOptions` | `toastDefaults`: `status: "success"` |
|
|
62
|
+
|
|
63
|
+
- Button variants: `primary`, `secondary`, `tertiary`, `ghost`, `danger`,
|
|
64
|
+
`danger-subtle`. Sizes: `small`, `medium`, `large`. Apply the default attributes
|
|
65
|
+
explicitly; the bare CSS class is not identical to every default variant rule.
|
|
66
|
+
- Badge variants: `default`, `success`, `danger`, `warning`, `info`, `accent`,
|
|
67
|
+
`command`, `outline`, `muted`. Sizes: `small`, `medium`.
|
|
68
|
+
- Card variants: `flat`, `rule`. Omit `variant` for the base card; there is no
|
|
69
|
+
explicit `default` variant. `padding` is boolean and maps to
|
|
70
|
+
`data-padding="true"` when enabled.
|
|
71
|
+
- `ComboboxOption` contains `label`, a unique `value`, and optional `disabled`.
|
|
72
|
+
`ComboboxOptions` defines the shared root API: required `id`, `label`, `options`,
|
|
73
|
+
and `onValueChange`, plus optional `placeholder`, `value`, `disabled`,
|
|
74
|
+
`invalid`, `required`, `name`, `placement`, and `onOpenChange`. The callback
|
|
75
|
+
receives the selected option's string value, or an empty string when selection
|
|
76
|
+
is cleared. Adapters add their own children type and keep context and rendering
|
|
77
|
+
internal.
|
|
78
|
+
- `SelectOption` mirrors `ComboboxOption`, and `SelectOptions` mirrors
|
|
79
|
+
`ComboboxOptions` for the keyboard-driven single-select. The `placeholder`
|
|
80
|
+
string renders in place of the value text until an option is selected. Both
|
|
81
|
+
option lists stay independent so each adapter can evolve its own surface.
|
|
82
|
+
- `value` is the controlled counterpart of `onValueChange`. An empty string means
|
|
83
|
+
no selection, and omitting `value` leaves the component uncontrolled. Adapters
|
|
84
|
+
must therefore treat `""` as a controlled empty selection, not as uncontrolled.
|
|
85
|
+
- `disabled` dims and blocks the field, `invalid` switches the border and focus
|
|
86
|
+
ring to the danger tokens, and `required` adds the label marker. `placement` is
|
|
87
|
+
the shared `top`/`bottom` union with `-start` and `-end` variants and picks the
|
|
88
|
+
popup side; it is deliberately narrower than the adapter's positioning options,
|
|
89
|
+
not a pass-through. `onOpenChange` reports popup visibility for lazy loading
|
|
90
|
+
and analytics.
|
|
91
|
+
- `name` has different meaning per component. Combobox applies it to the visible
|
|
92
|
+
input, so the submitted value is the option label, not its value. Select keeps a
|
|
93
|
+
hidden native select for the option value and always renders it, so the label
|
|
94
|
+
stays associated and form reset and fieldset state are tracked; `name` alone
|
|
95
|
+
decides whether the control is submitted.
|
|
96
|
+
- Status line statuses: `success`, `danger`, `info`.
|
|
97
|
+
- Alert statuses: `danger`, `info`. Only the border changes with status; the CSS
|
|
98
|
+
keeps the alert mark danger-colored.
|
|
99
|
+
- Toast status: `success` only. Status line, alert, and toast types are exported
|
|
100
|
+
from `/status`, but intentionally do not share an interchangeable status union.
|
|
101
|
+
|
|
102
|
+
Native-only components such as checkbox, input, and the plain `.sb-select`
|
|
103
|
+
pattern do not need shared custom options. Typography classes and the progress
|
|
104
|
+
CSS custom property remain part of the CSS API, not this package.
|
|
105
|
+
|
|
106
|
+
## Migration from the class-map contracts
|
|
107
|
+
|
|
108
|
+
Use `buttonDefaults`, `badgeDefaults`, `cardDefaults`, and `toastDefaults` instead
|
|
109
|
+
of the corresponding `*Contract.defaults`. Use CSS class and attribute names
|
|
110
|
+
directly in adapters. Class-only contracts and their subpaths have been removed.
|
|
111
|
+
Existing option type names are unchanged.
|
|
112
|
+
|
|
113
|
+
## Verification
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
pnpm --filter @simple-base/contracts typecheck
|
|
117
|
+
pnpm --filter @simple-base/contracts build
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
These commands check the shared types and build the runtime defaults and type
|
|
121
|
+
declarations.
|
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/badge.d.ts
|
|
2
|
+
export type BadgeVariant = "default" | "success" | "danger" | "warning" | "info" | "accent" | "command" | "outline" | "muted";
|
|
3
|
+
export type BadgeSize = "small" | "medium";
|
|
4
|
+
export type BadgeOptions = {
|
|
5
|
+
variant?: BadgeVariant;
|
|
6
|
+
size?: BadgeSize;
|
|
7
|
+
};
|
|
8
|
+
export declare const badgeDefaults: {
|
|
9
|
+
readonly variant: "default";
|
|
10
|
+
readonly size: "medium";
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
package/dist/badge.js
ADDED
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/button.d.ts
|
|
2
|
+
export type ButtonVariant = "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger-subtle";
|
|
3
|
+
export type ButtonSize = "small" | "medium" | "large";
|
|
4
|
+
export type ButtonOptions = {
|
|
5
|
+
variant?: ButtonVariant;
|
|
6
|
+
size?: ButtonSize;
|
|
7
|
+
};
|
|
8
|
+
export declare const buttonDefaults: {
|
|
9
|
+
readonly variant: "primary";
|
|
10
|
+
readonly size: "medium";
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
package/dist/button.js
ADDED
package/dist/card.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/card.d.ts
|
|
2
|
+
export type CardVariant = "flat" | "rule";
|
|
3
|
+
export type CardOptions = {
|
|
4
|
+
variant?: CardVariant;
|
|
5
|
+
padding?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const cardDefaults: {
|
|
8
|
+
readonly variant: "flat";
|
|
9
|
+
readonly padding: false;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
package/dist/card.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Placement } from "./placement.js";
|
|
2
|
+
//#region src/combobox.d.ts
|
|
3
|
+
export type ComboboxOption = {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type ComboboxOptions = {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
options: ComboboxOption[];
|
|
14
|
+
value?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
invalid?: boolean;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
placement?: Placement;
|
|
19
|
+
onValueChange: (value: string) => void;
|
|
20
|
+
onOpenChange?: (open: boolean) => void;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
package/dist/combobox.js
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BadgeOptions, BadgeSize, BadgeVariant, badgeDefaults } from "./badge.js";
|
|
2
|
+
import { ButtonOptions, ButtonSize, ButtonVariant, buttonDefaults } from "./button.js";
|
|
3
|
+
import { CardOptions, CardVariant, cardDefaults } from "./card.js";
|
|
4
|
+
import { Placement } from "./placement.js";
|
|
5
|
+
import { ComboboxOption, ComboboxOptions } from "./combobox.js";
|
|
6
|
+
import { SelectOption, SelectOptions } from "./select.js";
|
|
7
|
+
import { TableCellOptions, TableCellVariant } from "./table.js";
|
|
8
|
+
import { AlertOptions, AlertStatus, StatusOptions, StatusValue, ToastOptions, ToastStatus, toastDefaults } from "./status.js";
|
|
9
|
+
export { type AlertOptions, type AlertStatus, type BadgeOptions, type BadgeSize, type BadgeVariant, type ButtonOptions, type ButtonSize, type ButtonVariant, type CardOptions, type CardVariant, type ComboboxOption, type ComboboxOptions, type Placement, type SelectOption, type SelectOptions, type StatusOptions, type StatusValue, type TableCellOptions, type TableCellVariant, type ToastOptions, type ToastStatus, badgeDefaults, buttonDefaults, cardDefaults, toastDefaults };
|
package/dist/index.js
ADDED
|
File without changes
|
package/dist/select.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Placement } from "./placement.js";
|
|
2
|
+
//#region src/select.d.ts
|
|
3
|
+
export type SelectOption = {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type SelectOptions = {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
options: SelectOption[];
|
|
14
|
+
value?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
invalid?: boolean;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
placement?: Placement;
|
|
19
|
+
onValueChange: (value: string) => void;
|
|
20
|
+
onOpenChange?: (open: boolean) => void;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
package/dist/select.js
ADDED
|
File without changes
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/status.d.ts
|
|
2
|
+
export type StatusValue = "success" | "danger" | "info";
|
|
3
|
+
export type StatusOptions = {
|
|
4
|
+
status?: StatusValue;
|
|
5
|
+
};
|
|
6
|
+
export type AlertStatus = "danger" | "info";
|
|
7
|
+
export type AlertOptions = {
|
|
8
|
+
status?: AlertStatus;
|
|
9
|
+
};
|
|
10
|
+
export type ToastStatus = "success";
|
|
11
|
+
export type ToastOptions = {
|
|
12
|
+
status?: ToastStatus;
|
|
13
|
+
};
|
|
14
|
+
export declare const toastDefaults: {
|
|
15
|
+
readonly status: "success";
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
package/dist/status.js
ADDED
package/dist/table.d.ts
ADDED
package/dist/table.js
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simple-base/contracts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./badge": {
|
|
18
|
+
"types": "./dist/badge.d.ts",
|
|
19
|
+
"import": "./dist/badge.js"
|
|
20
|
+
},
|
|
21
|
+
"./button": {
|
|
22
|
+
"types": "./dist/button.d.ts",
|
|
23
|
+
"import": "./dist/button.js"
|
|
24
|
+
},
|
|
25
|
+
"./card": {
|
|
26
|
+
"types": "./dist/card.d.ts",
|
|
27
|
+
"import": "./dist/card.js"
|
|
28
|
+
},
|
|
29
|
+
"./combobox": {
|
|
30
|
+
"types": "./dist/combobox.d.ts",
|
|
31
|
+
"import": "./dist/combobox.js"
|
|
32
|
+
},
|
|
33
|
+
"./placement": {
|
|
34
|
+
"types": "./dist/placement.d.ts",
|
|
35
|
+
"import": "./dist/placement.js"
|
|
36
|
+
},
|
|
37
|
+
"./select": {
|
|
38
|
+
"types": "./dist/select.d.ts",
|
|
39
|
+
"import": "./dist/select.js"
|
|
40
|
+
},
|
|
41
|
+
"./status": {
|
|
42
|
+
"types": "./dist/status.d.ts",
|
|
43
|
+
"import": "./dist/status.js"
|
|
44
|
+
},
|
|
45
|
+
"./table": {
|
|
46
|
+
"types": "./dist/table.d.ts",
|
|
47
|
+
"import": "./dist/table.js"
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"registry": "https://registry.npmjs.org/"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^25.8.0",
|
|
57
|
+
"tsdown": "^0.23.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsdown",
|
|
61
|
+
"dev": "tsdown --watch --no-clean",
|
|
62
|
+
"typecheck": "tsc --noEmit"
|
|
63
|
+
}
|
|
64
|
+
}
|