@geektech/one 0.0.1
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-zh.md +143 -0
- package/README.md +144 -0
- package/dist/button/OneButton.d.ts +19 -0
- package/dist/button/index.d.ts +2 -0
- package/dist/card/OneCard.d.ts +12 -0
- package/dist/card/index.d.ts +2 -0
- package/dist/categories.d.ts +18 -0
- package/dist/checkbox/OneCheckbox.d.ts +31 -0
- package/dist/checkbox/OneCheckboxGroup.d.ts +28 -0
- package/dist/checkbox/index.d.ts +4 -0
- package/dist/form/OneForm.d.ts +29 -0
- package/dist/form/OneFormItem.d.ts +28 -0
- package/dist/form/context.d.ts +30 -0
- package/dist/form/index.d.ts +7 -0
- package/dist/form/model.d.ts +25 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1476 -0
- package/dist/index.js.map +23 -0
- package/dist/input/OneInput.d.ts +38 -0
- package/dist/input/index.d.ts +2 -0
- package/dist/select/OneSelect.d.ts +48 -0
- package/dist/select/index.d.ts +2 -0
- package/dist/styles/shared.d.ts +30 -0
- package/dist/switch/OneSwitch.d.ts +30 -0
- package/dist/switch/index.d.ts +2 -0
- package/dist/types.d.ts +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Geek Tech Team
|
|
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-zh.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# One UI
|
|
2
|
+
|
|
3
|
+
One UI(`@geektech/one`)是面向 TSone 类组件框架的轻量级、无额外运行时依赖
|
|
4
|
+
UI 组件库。TSone 是它的 peer dependency,使用 One UI 的应用必须同时安装
|
|
5
|
+
TSone。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @geektech/tsone @geektech/one
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 快速开始
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
Component,
|
|
18
|
+
createApp,
|
|
19
|
+
createComponent,
|
|
20
|
+
type VNode,
|
|
21
|
+
} from '@geektech/tsone';
|
|
22
|
+
import { OneButton, OneCard, OneInput } from '@geektech/one';
|
|
23
|
+
|
|
24
|
+
class App extends Component {
|
|
25
|
+
protected initState(): object {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected initStyles(): void {}
|
|
30
|
+
|
|
31
|
+
protected render(): VNode {
|
|
32
|
+
return {
|
|
33
|
+
tag: 'main',
|
|
34
|
+
children: [
|
|
35
|
+
createComponent(OneButton, {}, ['保存']),
|
|
36
|
+
createComponent(OneInput, {
|
|
37
|
+
placeholder: '项目名称',
|
|
38
|
+
ariaLabel: '项目名称',
|
|
39
|
+
}),
|
|
40
|
+
createComponent(OneCard, { title: 'One UI' }, [
|
|
41
|
+
'为 TSone 提供轻量级组件。',
|
|
42
|
+
]),
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createApp({ root: App }).mount();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 按钮变体、尺寸、加载状态和事件
|
|
52
|
+
|
|
53
|
+
`OneButton` 提供 `primary`、`secondary`、`danger` 三种变体,以及 `sm`、
|
|
54
|
+
`md`、`lg` 三种尺寸。加载状态下按钮会被禁用并带有 `aria-busy`。
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { OneButton } from '@geektech/one';
|
|
58
|
+
|
|
59
|
+
const button = new OneButton({
|
|
60
|
+
variant: 'danger',
|
|
61
|
+
size: 'lg',
|
|
62
|
+
loading: false,
|
|
63
|
+
children: ['删除'],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
button.on('click', (event) => {
|
|
67
|
+
console.log('已点击', event);
|
|
68
|
+
button.setProps({ loading: true });
|
|
69
|
+
});
|
|
70
|
+
button.mount(document.querySelector('#actions') as HTMLElement);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 受控与非受控输入框
|
|
74
|
+
|
|
75
|
+
受控输入框传入 `value`,收到事件后通过 `setProps` 接受新值;非受控输入框传入
|
|
76
|
+
`defaultValue`,值由 One UI 自己维护。
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { OneInput, type OneInputValueEvent } from '@geektech/one';
|
|
80
|
+
|
|
81
|
+
const controlled = new OneInput({
|
|
82
|
+
value: 'one',
|
|
83
|
+
ariaLabel: '受控项目名称',
|
|
84
|
+
});
|
|
85
|
+
controlled.on('input', (payload) => {
|
|
86
|
+
const event = payload as OneInputValueEvent;
|
|
87
|
+
controlled.setProps({ value: event.value });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const uncontrolled = new OneInput({
|
|
91
|
+
defaultValue: '草稿',
|
|
92
|
+
ariaLabel: '草稿名称',
|
|
93
|
+
});
|
|
94
|
+
uncontrolled.on('change', (payload) => {
|
|
95
|
+
const event = payload as OneInputValueEvent;
|
|
96
|
+
console.log(event.value, event.originalEvent);
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 卡片插槽
|
|
101
|
+
|
|
102
|
+
带有 `slot: 'header'` 或 `slot: 'footer'` 的子节点进入对应命名插槽,未指定
|
|
103
|
+
slot 的子节点进入默认内容区。
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { createComponent } from '@geektech/tsone';
|
|
107
|
+
import { OneCard } from '@geektech/one';
|
|
108
|
+
|
|
109
|
+
const card = createComponent(OneCard, {}, [
|
|
110
|
+
{ tag: 'h2', slot: 'header', children: ['账户'] },
|
|
111
|
+
{ tag: 'p', children: ['默认插槽内容'] },
|
|
112
|
+
{ tag: 'button', slot: 'footer', children: ['继续'] },
|
|
113
|
+
]);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 主题覆盖
|
|
117
|
+
|
|
118
|
+
One UI 样式限定在 `.one-*` 选择器中。可以在应用容器或 `:root` 上覆盖公开
|
|
119
|
+
CSS 变量:
|
|
120
|
+
|
|
121
|
+
```css
|
|
122
|
+
.my-app {
|
|
123
|
+
--one-color-primary: #326bff;
|
|
124
|
+
--one-radius-md: 12px;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
对应的默认回退值也可以从 `ONE_THEME_DEFAULTS` 读取。
|
|
129
|
+
|
|
130
|
+
## 开发
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
bun install
|
|
134
|
+
bun test packages/one
|
|
135
|
+
bunx tsc --noEmit --project packages/one/tsconfig.json
|
|
136
|
+
bun run --cwd packages/one build
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
在仓库根目录运行完整发布前检查:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
bun test packages/one/tests/package-contract.test.ts packages/one/tests/component-types.test.ts packages/one/tests/style-contract.test.ts packages/one/tests/package-smoke.test.ts && bunx tsc --noEmit --project packages/one/tsconfig.json && bun run --cwd packages/one build && bun pm pack --cwd packages/one --dry-run
|
|
143
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# One UI
|
|
2
|
+
|
|
3
|
+
One UI (`@geektech/one`) is a lightweight, zero-runtime-dependency UI
|
|
4
|
+
component library for the TSone class-component framework. TSone is a peer
|
|
5
|
+
dependency and must be installed by the consuming application.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @geektech/tsone @geektech/one
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
Component,
|
|
18
|
+
createApp,
|
|
19
|
+
createComponent,
|
|
20
|
+
type VNode,
|
|
21
|
+
} from '@geektech/tsone';
|
|
22
|
+
import { OneButton, OneCard, OneInput } from '@geektech/one';
|
|
23
|
+
|
|
24
|
+
class App extends Component {
|
|
25
|
+
protected initState(): object {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected initStyles(): void {}
|
|
30
|
+
|
|
31
|
+
protected render(): VNode {
|
|
32
|
+
return {
|
|
33
|
+
tag: 'main',
|
|
34
|
+
children: [
|
|
35
|
+
createComponent(OneButton, {}, ['Save']),
|
|
36
|
+
createComponent(OneInput, {
|
|
37
|
+
placeholder: 'Project name',
|
|
38
|
+
ariaLabel: 'Project name',
|
|
39
|
+
}),
|
|
40
|
+
createComponent(OneCard, { title: 'One UI' }, [
|
|
41
|
+
'Lightweight components for TSone.',
|
|
42
|
+
]),
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createApp({ root: App }).mount();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Button variants, sizes, loading and events
|
|
52
|
+
|
|
53
|
+
`OneButton` supports `primary`, `secondary`, and `danger` variants and `sm`,
|
|
54
|
+
`md`, and `lg` sizes. Loading buttons are disabled and expose `aria-busy`.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { OneButton } from '@geektech/one';
|
|
58
|
+
|
|
59
|
+
const button = new OneButton({
|
|
60
|
+
variant: 'danger',
|
|
61
|
+
size: 'lg',
|
|
62
|
+
loading: false,
|
|
63
|
+
children: ['Delete'],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
button.on('click', (event) => {
|
|
67
|
+
console.log('clicked', event);
|
|
68
|
+
button.setProps({ loading: true });
|
|
69
|
+
});
|
|
70
|
+
button.mount(document.querySelector('#actions') as HTMLElement);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Controlled and uncontrolled inputs
|
|
74
|
+
|
|
75
|
+
Pass `value` for a controlled input and accept emitted values through
|
|
76
|
+
`setProps`. Pass `defaultValue` when One UI should maintain the value.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { OneInput, type OneInputValueEvent } from '@geektech/one';
|
|
80
|
+
|
|
81
|
+
const controlled = new OneInput({
|
|
82
|
+
value: 'one',
|
|
83
|
+
ariaLabel: 'Controlled project name',
|
|
84
|
+
});
|
|
85
|
+
controlled.on('input', (payload) => {
|
|
86
|
+
const event = payload as OneInputValueEvent;
|
|
87
|
+
controlled.setProps({ value: event.value });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const uncontrolled = new OneInput({
|
|
91
|
+
defaultValue: 'draft',
|
|
92
|
+
ariaLabel: 'Draft project name',
|
|
93
|
+
});
|
|
94
|
+
uncontrolled.on('change', (payload) => {
|
|
95
|
+
const event = payload as OneInputValueEvent;
|
|
96
|
+
console.log(event.value, event.originalEvent);
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Card slots
|
|
101
|
+
|
|
102
|
+
Children with `slot: 'header'` or `slot: 'footer'` fill the named regions;
|
|
103
|
+
children without a slot fill the default body.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { createComponent } from '@geektech/tsone';
|
|
107
|
+
import { OneCard } from '@geektech/one';
|
|
108
|
+
|
|
109
|
+
const card = createComponent(OneCard, {}, [
|
|
110
|
+
{ tag: 'h2', slot: 'header', children: ['Account'] },
|
|
111
|
+
{ tag: 'p', children: ['Default slot content'] },
|
|
112
|
+
{ tag: 'button', slot: 'footer', children: ['Continue'] },
|
|
113
|
+
]);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Theme overrides
|
|
117
|
+
|
|
118
|
+
One UI styles are scoped to `.one-*` selectors. Override public CSS variables
|
|
119
|
+
on an application container or `:root`:
|
|
120
|
+
|
|
121
|
+
```css
|
|
122
|
+
.my-app {
|
|
123
|
+
--one-color-primary: #326bff;
|
|
124
|
+
--one-radius-md: 12px;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The matching fallback values are also available from
|
|
129
|
+
`ONE_THEME_DEFAULTS`.
|
|
130
|
+
|
|
131
|
+
## Development
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
bun install
|
|
135
|
+
bun test packages/one
|
|
136
|
+
bunx tsc --noEmit --project packages/one/tsconfig.json
|
|
137
|
+
bun run --cwd packages/one build
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Run the complete publish verification from the repository root:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
bun test packages/one/tests/package-contract.test.ts packages/one/tests/component-types.test.ts packages/one/tests/style-contract.test.ts packages/one/tests/package-smoke.test.ts && bunx tsc --noEmit --project packages/one/tsconfig.json && bun run --cwd packages/one build && bun pm pack --cwd packages/one --dry-run
|
|
144
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component, type VNode } from '@geektech/tsone';
|
|
2
|
+
import { type OneNamedStyle } from '../styles/shared';
|
|
3
|
+
import type { OneComponentSize } from '../types';
|
|
4
|
+
export type OneButtonVariant = 'primary' | 'secondary' | 'danger';
|
|
5
|
+
export interface OneButtonProps {
|
|
6
|
+
variant?: OneButtonVariant;
|
|
7
|
+
size?: OneComponentSize;
|
|
8
|
+
type?: 'button' | 'submit' | 'reset';
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
loading?: boolean;
|
|
11
|
+
children?: Array<VNode | string>;
|
|
12
|
+
}
|
|
13
|
+
export declare const ONE_BUTTON_STYLES: OneNamedStyle[];
|
|
14
|
+
export declare function normalizeButtonVariant(value: unknown): OneButtonVariant;
|
|
15
|
+
export declare class OneButton extends Component<OneButtonProps> {
|
|
16
|
+
protected initState(): object;
|
|
17
|
+
protected initStyles(): void;
|
|
18
|
+
protected render(): VNode;
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Component, type VNode } from '@geektech/tsone';
|
|
2
|
+
import { type OneNamedStyle } from '../styles/shared';
|
|
3
|
+
export interface OneCardProps {
|
|
4
|
+
title?: string;
|
|
5
|
+
children?: Array<VNode | string>;
|
|
6
|
+
}
|
|
7
|
+
export declare const ONE_CARD_STYLES: OneNamedStyle[];
|
|
8
|
+
export declare class OneCard extends Component<OneCardProps> {
|
|
9
|
+
protected initState(): object;
|
|
10
|
+
protected initStyles(): void;
|
|
11
|
+
protected render(): VNode;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type OneComponentCategory = 'basic' | 'form' | 'data-display' | 'feedback';
|
|
2
|
+
export declare const ONE_COMPONENT_CATEGORIES: readonly [{
|
|
3
|
+
readonly id: "basic";
|
|
4
|
+
readonly label: "基础";
|
|
5
|
+
readonly components: readonly ["OneButton", "OneInput"];
|
|
6
|
+
}, {
|
|
7
|
+
readonly id: "form";
|
|
8
|
+
readonly label: "表单";
|
|
9
|
+
readonly components: readonly ["OneForm", "OneFormItem", "OneSelect", "OneCheckbox", "OneCheckboxGroup", "OneSwitch"];
|
|
10
|
+
}, {
|
|
11
|
+
readonly id: "data-display";
|
|
12
|
+
readonly label: "数据展示";
|
|
13
|
+
readonly components: readonly ["OneCard"];
|
|
14
|
+
}, {
|
|
15
|
+
readonly id: "feedback";
|
|
16
|
+
readonly label: "反馈与浮层";
|
|
17
|
+
readonly components: readonly [];
|
|
18
|
+
}];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Component, type VNode } from '@geektech/tsone';
|
|
2
|
+
import { type OneNamedStyle } from '../styles/shared';
|
|
3
|
+
export interface OneCheckboxProps {
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
defaultChecked?: boolean;
|
|
6
|
+
name?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
invalid?: boolean;
|
|
10
|
+
ariaLabel?: string;
|
|
11
|
+
children?: Array<VNode | string>;
|
|
12
|
+
}
|
|
13
|
+
interface OneCheckboxState {
|
|
14
|
+
internalChecked: boolean;
|
|
15
|
+
revision: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const ONE_CHECKBOX_STYLES: OneNamedStyle[];
|
|
18
|
+
export declare class OneCheckbox extends Component<OneCheckboxProps, OneCheckboxState> {
|
|
19
|
+
private fieldContext;
|
|
20
|
+
private unsubscribe;
|
|
21
|
+
protected initState(): OneCheckboxState;
|
|
22
|
+
protected initStyles(): void;
|
|
23
|
+
protected beforeMount(): void;
|
|
24
|
+
protected onMounted(): void;
|
|
25
|
+
protected onUnmounted(): void;
|
|
26
|
+
protected onUpdated(): void;
|
|
27
|
+
protected render(): VNode;
|
|
28
|
+
private getChecked;
|
|
29
|
+
private emitChecked;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component, type VNode } from '@geektech/tsone';
|
|
2
|
+
import type { OneSelectOption } from '../select';
|
|
3
|
+
export interface OneCheckboxGroupProps {
|
|
4
|
+
options: readonly OneSelectOption[];
|
|
5
|
+
value?: string[];
|
|
6
|
+
defaultValue?: string[];
|
|
7
|
+
name?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
invalid?: boolean;
|
|
10
|
+
ariaLabel?: string;
|
|
11
|
+
}
|
|
12
|
+
interface OneCheckboxGroupState {
|
|
13
|
+
internalValue: string[];
|
|
14
|
+
revision: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class OneCheckboxGroup extends Component<OneCheckboxGroupProps, OneCheckboxGroupState> {
|
|
17
|
+
private fieldContext;
|
|
18
|
+
private unsubscribe;
|
|
19
|
+
protected initState(): OneCheckboxGroupState;
|
|
20
|
+
protected initStyles(): void;
|
|
21
|
+
protected beforeMount(): void;
|
|
22
|
+
protected onMounted(): void;
|
|
23
|
+
protected onUnmounted(): void;
|
|
24
|
+
protected render(): VNode;
|
|
25
|
+
private getValue;
|
|
26
|
+
private toggle;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component, type VNode } from '@geektech/tsone';
|
|
2
|
+
import type { OneNamedStyle } from '../styles/shared';
|
|
3
|
+
import type { OneFormInitialValues, OneFormRules, OneFormValidationResult, OneFormValues } from './context';
|
|
4
|
+
import { OneFormModel } from './model';
|
|
5
|
+
export interface OneFormProps {
|
|
6
|
+
initialValues?: OneFormInitialValues;
|
|
7
|
+
rules?: OneFormRules;
|
|
8
|
+
children?: Array<VNode | string>;
|
|
9
|
+
}
|
|
10
|
+
export interface OneFormSubmitEvent {
|
|
11
|
+
values: OneFormValues;
|
|
12
|
+
}
|
|
13
|
+
interface OneFormState {
|
|
14
|
+
revision: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const ONE_FORM_STYLES: OneNamedStyle[];
|
|
17
|
+
export declare class OneForm extends Component<OneFormProps, OneFormState> {
|
|
18
|
+
readonly model: OneFormModel;
|
|
19
|
+
constructor(props?: OneFormProps);
|
|
20
|
+
validate(): OneFormValidationResult;
|
|
21
|
+
reset(): void;
|
|
22
|
+
getValues(): OneFormValues;
|
|
23
|
+
protected initState(): OneFormState;
|
|
24
|
+
protected initStyles(): void;
|
|
25
|
+
protected render(): VNode;
|
|
26
|
+
private handleSubmit;
|
|
27
|
+
private handleReset;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component, type VNode } from '@geektech/tsone';
|
|
2
|
+
import type { OneNamedStyle } from '../styles/shared';
|
|
3
|
+
export interface OneFormItemProps {
|
|
4
|
+
name: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
children?: Array<VNode | string>;
|
|
8
|
+
}
|
|
9
|
+
interface OneFormItemState {
|
|
10
|
+
revision: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const ONE_FORM_ITEM_STYLES: OneNamedStyle[];
|
|
13
|
+
export declare class OneFormItem extends Component<OneFormItemProps, OneFormItemState> {
|
|
14
|
+
private model;
|
|
15
|
+
private unsubscribe;
|
|
16
|
+
private unregister;
|
|
17
|
+
private fieldSignature;
|
|
18
|
+
protected initState(): OneFormItemState;
|
|
19
|
+
protected initStyles(): void;
|
|
20
|
+
protected beforeMount(): void;
|
|
21
|
+
protected onMounted(): void;
|
|
22
|
+
protected onUnmounted(): void;
|
|
23
|
+
protected render(): VNode;
|
|
24
|
+
private getFieldContext;
|
|
25
|
+
private getIds;
|
|
26
|
+
private getFieldSignature;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { InjectionKey } from '@geektech/tsone';
|
|
2
|
+
import type { OneFormModel } from './model';
|
|
3
|
+
export type OneFieldValue = string | boolean | string[];
|
|
4
|
+
export type OneFormValues = Readonly<Record<string, OneFieldValue | undefined>>;
|
|
5
|
+
export type OneFormInitialValues = Readonly<Record<string, OneFieldValue | undefined>>;
|
|
6
|
+
export interface OneFieldValueEvent<TValue extends OneFieldValue> {
|
|
7
|
+
value: TValue;
|
|
8
|
+
originalEvent: Event;
|
|
9
|
+
}
|
|
10
|
+
export interface OneValidationRule {
|
|
11
|
+
required?: boolean;
|
|
12
|
+
minLength?: number;
|
|
13
|
+
maxLength?: number;
|
|
14
|
+
pattern?: RegExp;
|
|
15
|
+
message?: string;
|
|
16
|
+
validator?: (value: OneFieldValue | undefined, values: OneFormValues) => string | undefined;
|
|
17
|
+
}
|
|
18
|
+
export type OneFormRules = Readonly<Record<string, readonly OneValidationRule[] | undefined>>;
|
|
19
|
+
export interface OneFormValidationResult {
|
|
20
|
+
valid: boolean;
|
|
21
|
+
errors: Readonly<Record<string, readonly string[]>>;
|
|
22
|
+
}
|
|
23
|
+
export interface OneFormFieldContext {
|
|
24
|
+
name: string;
|
|
25
|
+
controlId: string;
|
|
26
|
+
describedBy: string | undefined;
|
|
27
|
+
model: OneFormModel;
|
|
28
|
+
}
|
|
29
|
+
export declare const ONE_FORM_MODEL_KEY: InjectionKey<OneFormModel>;
|
|
30
|
+
export declare const ONE_FORM_FIELD_KEY: InjectionKey<OneFormFieldContext>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { OneFormModel } from './model';
|
|
2
|
+
export { OneForm } from './OneForm';
|
|
3
|
+
export type { OneFormProps, OneFormSubmitEvent } from './OneForm';
|
|
4
|
+
export { OneFormItem } from './OneFormItem';
|
|
5
|
+
export type { OneFormItemProps } from './OneFormItem';
|
|
6
|
+
export { ONE_FORM_FIELD_KEY, ONE_FORM_MODEL_KEY, } from './context';
|
|
7
|
+
export type { OneFieldValue, OneFieldValueEvent, OneFormFieldContext, OneFormInitialValues, OneFormRules, OneFormValidationResult, OneFormValues, OneValidationRule, } from './context';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { OneFieldValue, OneFormInitialValues, OneFormRules, OneFormValidationResult, OneFormValues } from './context';
|
|
2
|
+
type OneFormSubscriber = () => void;
|
|
3
|
+
export declare class OneFormModel {
|
|
4
|
+
private readonly initialValues;
|
|
5
|
+
private readonly rules;
|
|
6
|
+
private readonly values;
|
|
7
|
+
private readonly errors;
|
|
8
|
+
private readonly fields;
|
|
9
|
+
private readonly subscribers;
|
|
10
|
+
constructor(initialValues?: OneFormInitialValues, rules?: OneFormRules);
|
|
11
|
+
ensureValue(name: string, fallback: OneFieldValue): void;
|
|
12
|
+
setValue(name: string, value: OneFieldValue): void;
|
|
13
|
+
getValue(name: string): OneFieldValue | undefined;
|
|
14
|
+
getValues(): OneFormValues;
|
|
15
|
+
getErrors(name: string): readonly string[];
|
|
16
|
+
validate(): OneFormValidationResult;
|
|
17
|
+
reset(): void;
|
|
18
|
+
subscribe(listener: OneFormSubscriber): () => void;
|
|
19
|
+
registerField(name: string, focus: () => void): () => void;
|
|
20
|
+
focusFirstInvalidField(): boolean;
|
|
21
|
+
private validateField;
|
|
22
|
+
private getValidationResult;
|
|
23
|
+
private notify;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type { OneComponentSize } from './types';
|
|
2
|
+
export { OneButton } from './button';
|
|
3
|
+
export type { OneButtonProps, OneButtonVariant } from './button';
|
|
4
|
+
export { OneInput } from './input';
|
|
5
|
+
export type { OneInputProps, OneInputValueEvent } from './input';
|
|
6
|
+
export { OneForm, OneFormItem, OneFormModel } from './form';
|
|
7
|
+
export type { OneFieldValue, OneFieldValueEvent, OneFormInitialValues, OneFormItemProps, OneFormProps, OneFormRules, OneFormSubmitEvent, OneFormValidationResult, OneFormValues, OneValidationRule, } from './form';
|
|
8
|
+
export { OneCheckbox } from './checkbox';
|
|
9
|
+
export type { OneCheckboxGroupProps, OneCheckboxProps } from './checkbox';
|
|
10
|
+
export { OneCheckboxGroup } from './checkbox';
|
|
11
|
+
export { OneSwitch } from './switch';
|
|
12
|
+
export type { OneSwitchProps } from './switch';
|
|
13
|
+
export { OneSelect } from './select';
|
|
14
|
+
export type { OneSelectOption, OneSelectOptionGroup, OneSelectProps } from './select';
|
|
15
|
+
export { ONE_COMPONENT_CATEGORIES } from './categories';
|
|
16
|
+
export type { OneComponentCategory } from './categories';
|
|
17
|
+
export { OneCard } from './card';
|
|
18
|
+
export type { OneCardProps } from './card';
|
|
19
|
+
export { ONE_THEME_DEFAULTS } from './styles/shared';
|
|
20
|
+
export declare const ONE_NAME = "@geektech/one";
|
|
21
|
+
export declare const ONE_VERSION = "0.0.1";
|