@ticatec/uniface-element 0.3.18 → 0.3.20

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.
@@ -0,0 +1,184 @@
1
+ # ColorPicker
2
+
3
+ A color picker component that provides an intuitive interface for selecting colors using the native HTML5 color input.
4
+
5
+ ## Features
6
+
7
+ - **Native Picker**: Uses browser's native color picker for consistent UX
8
+ - **Visual Preview**: Color swatch showing current selection
9
+ - **Hex Display**: Shows the hex color code
10
+ - **Multiple Variants**: Plain, outlined, and filled styles
11
+ - **Compact Mode**: Space-saving option for dense UIs
12
+ - **Disabled & Readonly**: Full support for disabled and readonly states
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @ticatec/uniface-element
18
+ ```
19
+
20
+ ```typescript
21
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
22
+ ```
23
+
24
+ ## Basic Usage
25
+
26
+ ```svelte
27
+ <script>
28
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
29
+
30
+ let selectedColor = '#ff3e00';
31
+ </script>
32
+
33
+ <ColorPicker bind:value={selectedColor} />
34
+ ```
35
+
36
+ ## Props
37
+
38
+ | Prop | Type | Default | Description |
39
+ |------|------|---------|-------------|
40
+ | `value` | `string` | `'#ff3e00'` | Selected color (hex format) |
41
+ | `variant` | `'' \| 'plain' \| 'outlined' \| 'filled'` | `''` | Visual style variant |
42
+ | `disabled` | `boolean` | `false` | Disable the picker |
43
+ | `readonly` | `boolean` | `false` | Show in read-only mode |
44
+ | `compact` | `boolean` | `false` | Use compact layout |
45
+ | `style` | `string` | `''` | Additional CSS styles |
46
+ | `onChange` | `(value: string) => void` | - | Callback when color changes |
47
+
48
+ ## Examples
49
+
50
+ ### Basic Color Picker
51
+
52
+ ```svelte
53
+ <script>
54
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
55
+
56
+ let color = '#007acc';
57
+ </script>
58
+
59
+ <ColorPicker bind:value={color} />
60
+ <p>Selected: {color}</p>
61
+ ```
62
+
63
+ ### With Change Handler
64
+
65
+ ```svelte
66
+ <script>
67
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
68
+
69
+ let color = '#ff5722';
70
+
71
+ function handleColorChange(newColor) {
72
+ console.log('Color changed to:', newColor);
73
+ color = newColor;
74
+ }
75
+ </script>
76
+
77
+ <ColorPicker value={color} onChange={handleColorChange} />
78
+ ```
79
+
80
+ ### Different Variants
81
+
82
+ ```svelte
83
+ <script>
84
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
85
+
86
+ let color1 = '#e91e63';
87
+ let color2 = '#9c27b0';
88
+ let color3 = '#673ab7';
89
+ </script>
90
+
91
+ <div style="display: flex; flex-direction: column; gap: 16px;">
92
+ <!-- Default -->
93
+ <ColorPicker bind:value={color1} />
94
+
95
+ <!-- Plain -->
96
+ <ColorPicker bind:value={color2} variant="plain" />
97
+
98
+ <!-- Outlined -->
99
+ <ColorPicker bind:value={color3} variant="outlined" />
100
+
101
+ <!-- Filled -->
102
+ <ColorPicker bind:value={color1} variant="filled" />
103
+ </div>
104
+ ```
105
+
106
+ ### Compact Mode
107
+
108
+ ```svelte
109
+ <script>
110
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
111
+
112
+ let color = '#4caf50';
113
+ </script>
114
+
115
+ <ColorPicker bind:value={color} compact />
116
+ ```
117
+
118
+ ### Disabled & Readonly
119
+
120
+ ```svelte
121
+ <script>
122
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
123
+
124
+ let disabledColor = '#f44336';
125
+ let readonlyColor = '#2196f3';
126
+ </script>
127
+
128
+ <div style="display: flex; gap: 16px;">
129
+ <ColorPicker bind:value={disabledColor} disabled />
130
+ <ColorPicker bind:value={readonlyColor} readonly />
131
+ </div>
132
+ ```
133
+
134
+ ### Color Theming Example
135
+
136
+ ```svelte
137
+ <script>
138
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
139
+
140
+ let primaryColor = '#007acc';
141
+ let secondaryColor = '#22bdff';
142
+ let backgroundColor = '#f5f5f5';
143
+ let textColor = '#374151';
144
+ </script>
145
+
146
+ <div style="padding: 24px;">
147
+ <FormField label="Primary Color">
148
+ <ColorPicker bind:value={primaryColor} />
149
+ </FormField>
150
+
151
+ <FormField label="Secondary Color">
152
+ <ColorPicker bind:value={secondaryColor} />
153
+ </FormField>
154
+
155
+ <FormField label="Background">
156
+ <ColorPicker bind:value={backgroundColor} />
157
+ </FormField>
158
+
159
+ <FormField label="Text Color">
160
+ <ColorPicker bind:value={textColor} />
161
+ </FormField>
162
+ </div>
163
+ ```
164
+
165
+ ## Best Practices
166
+
167
+ 1. **Hex Format**: Always use hex color codes (#RRGGBB)
168
+ 2. **Default Colors**: Provide sensible defaults for better UX
169
+ 3. **Live Preview**: Show the selected color in context when possible
170
+ 4. **Validation**: Ensure valid hex format when accepting user input
171
+ 5. **Accessibility**: Consider color contrast for accessibility requirements
172
+
173
+ ## Browser Support
174
+
175
+ - Modern browsers with HTML5 color input support
176
+ - Chrome, Firefox, Safari, Edge (recent versions)
177
+ - Falls back gracefully on older browsers
178
+
179
+ ## Notes
180
+
181
+ - The component uses the native color picker for optimal performance and consistency
182
+ - Color values should be in hex format (#RRGGBB)
183
+ - The color swatch displays the currently selected color
184
+ - Click the color swatch to open the native color picker dialog
@@ -0,0 +1,185 @@
1
+ # ColorPicker 颜色选择器
2
+
3
+ 一个颜色选择器组件,使用原生 HTML5 颜色输入提供直观的颜色选择界面。
4
+
5
+ ## 特性
6
+
7
+ - **原生选择器**: 使用浏览器的原生颜色选择器以获得一致的用户体验
8
+ - **视觉预览**: 显示当前选择的颜色色板
9
+ - **十六进制显示**: 显示十六进制颜色代码
10
+ - **多种变体**: 纯净、轮廓和填充样式
11
+ - **紧凑模式**: 为密集 UI 节省空间的选项
12
+ - **禁用和只读**: 完全支持禁用和只读状态
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install @ticatec/uniface-element
18
+ ```
19
+
20
+ ```typescript
21
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
22
+ ```
23
+
24
+ ## 基本用法
25
+
26
+ ```svelte
27
+ <script>
28
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
29
+
30
+ let selectedColor = '#ff3e00';
31
+ </script>
32
+
33
+ <ColorPicker bind:value={selectedColor} />
34
+ ```
35
+
36
+ ## 属性
37
+
38
+ | 属性 | 类型 | 默认值 | 说明 |
39
+ |------|------|---------|-------------|
40
+ | `value` | `string` | `'#ff3e00'` | 选中的颜色(十六进制格式) |
41
+ | `variant` | `'' \| 'plain' \| 'outlined' \| 'filled'` | `''` | 视觉样式变体 |
42
+ | `disabled` | `boolean` | `false` | 禁用选择器 |
43
+ | `readonly` | `boolean` | `false` | 以只读模式显示 |
44
+ | `compact` | `boolean` | `false` | 使用紧凑布局 |
45
+ | `style` | `string` | `''` | 附加CSS样式 |
46
+ | `onChange` | `(value: string) => void` | - | 颜色更改时的回调 |
47
+
48
+ ## 示例
49
+
50
+ ### 基本颜色选择器
51
+
52
+ ```svelte
53
+ <script>
54
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
55
+
56
+ let color = '#007acc';
57
+ </script>
58
+
59
+ <ColorPicker bind:value={color} />
60
+ <p>已选择: {color}</p>
61
+ ```
62
+
63
+ ### 带更改处理程序
64
+
65
+ ```svelte
66
+ <script>
67
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
68
+
69
+ let color = '#ff5722';
70
+
71
+ function handleColorChange(newColor) {
72
+ console.log('颜色已更改为:', newColor);
73
+ color = newColor;
74
+ }
75
+ </script>
76
+
77
+ <ColorPicker value={color} onChange={handleColorChange} />
78
+ ```
79
+
80
+ ### 不同变体
81
+
82
+ ```svelte
83
+ <script>
84
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
85
+
86
+ let color1 = '#e91e63';
87
+ let color2 = '#9c27b0';
88
+ let color3 = '#673ab7';
89
+ </script>
90
+
91
+ <div style="display: flex; flex-direction: column; gap: 16px;">
92
+ <!-- 默认 -->
93
+ <ColorPicker bind:value={color1} />
94
+
95
+ <!-- 纯净 -->
96
+ <ColorPicker bind:value={color2} variant="plain" />
97
+
98
+ <!-- 轮廓 -->
99
+ <ColorPicker bind:value={color3} variant="outlined" />
100
+
101
+ <!-- 填充 -->
102
+ <ColorPicker bind:value={color1} variant="filled" />
103
+ </div>
104
+ ```
105
+
106
+ ### 紧凑模式
107
+
108
+ ```svelte
109
+ <script>
110
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
111
+
112
+ let color = '#4caf50';
113
+ </script>
114
+
115
+ <ColorPicker bind:value={color} compact />
116
+ ```
117
+
118
+ ### 禁用和只读
119
+
120
+ ```svelte
121
+ <script>
122
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
123
+
124
+ let disabledColor = '#f44336';
125
+ let readonlyColor = '#2196f3';
126
+ </script>
127
+
128
+ <div style="display: flex; gap: 16px;">
129
+ <ColorPicker bind:value={disabledColor} disabled />
130
+ <ColorPicker bind:value={readonlyColor} readonly />
131
+ </div>
132
+ ```
133
+
134
+ ### 主题颜色示例
135
+
136
+ ```svelte
137
+ <script>
138
+ import ColorPicker from '@ticatec/uniface-element/ColorPicker';
139
+ import FormField from '@ticatec/uniface-element/FormField';
140
+
141
+ let primaryColor = '#007acc';
142
+ let secondaryColor = '#22bdff';
143
+ let backgroundColor = '#f5f5f5';
144
+ let textColor = '#374151';
145
+ </script>
146
+
147
+ <div style="padding: 24px;">
148
+ <FormField label="主色">
149
+ <ColorPicker bind:value={primaryColor} />
150
+ </FormField>
151
+
152
+ <FormField label="辅助色">
153
+ <ColorPicker bind:value={secondaryColor} />
154
+ </FormField>
155
+
156
+ <FormField label="背景色">
157
+ <ColorPicker bind:value={backgroundColor} />
158
+ </FormField>
159
+
160
+ <FormField label="文字颜色">
161
+ <ColorPicker bind:value={textColor} />
162
+ </FormField>
163
+ </div>
164
+ ```
165
+
166
+ ## 最佳实践
167
+
168
+ 1. **十六进制格式**: 始终使用十六进制颜色代码 (#RRGGBB)
169
+ 2. **默认颜色**: 为更好的用户体验提供合理的默认值
170
+ 3. **实时预览**: 尽可能在上下文中显示选中的颜色
171
+ 4. **验证**: 接受用户输入时确保有效的十六进制格式
172
+ 5. **无障碍访问**: 考虑无障碍要求的颜色对比度
173
+
174
+ ## 浏览器支持
175
+
176
+ - 支持 HTML5 颜色输入的现代浏览器
177
+ - Chrome、Firefox、Safari、Edge(最新版本)
178
+ - 在旧浏览器上优雅降级
179
+
180
+ ## 注意事项
181
+
182
+ - 组件使用原生颜色选择器以获得最佳性能和一致性
183
+ - 颜色值应采用十六进制格式 (#RRGGBB)
184
+ - 色板显示当前选中的颜色
185
+ - 点击色板打开原生颜色选择器对话框
@@ -0,0 +1,193 @@
1
+ # FormField
2
+
3
+ A form field wrapper component that provides consistent layout for form inputs with labels, error messages, and required indicators.
4
+
5
+ ## Features
6
+
7
+ - **Label Support**: Display labels with optional suffix
8
+ - **Required Indicator**: Visual indicator for required fields
9
+ - **Error Display**: Show validation error messages
10
+ - **Flexible Layout**: Center or top label alignment
11
+ - **Custom Styling**: Custom styles for label and container
12
+ - **Responsive Height**: Adjustable field height
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @ticatec/uniface-element
18
+ ```
19
+
20
+ ```typescript
21
+ import FormField from '@ticatec/uniface-element/FormField';
22
+ ```
23
+
24
+ ## Basic Usage
25
+
26
+ ```svelte
27
+ <script>
28
+ import FormField from '@ticatec/uniface-element/FormField';
29
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
30
+ </script>
31
+
32
+ <FormField label="Username" required>
33
+ <TextEditor placeholder="Enter username" />
34
+ </FormField>
35
+ ```
36
+
37
+ ## Props
38
+
39
+ | Prop | Type | Default | Description |
40
+ |------|------|---------|-------------|
41
+ | `label` | `string` | `'Label:'` | Field label text |
42
+ | `labelSuffix` | `string` | `':'` | Suffix text after label |
43
+ | `required` | `boolean` | `false` | Show required indicator (*) |
44
+ | `error` | `string \| null` | `null` | Error message to display |
45
+ | `labelAlignment` | `'center' \| 'top'` | `'center'` | Label vertical alignment |
46
+ | `labelStyle` | `string \| null` | `null` | Custom CSS for label |
47
+ | `style` | `string` | `''` | Custom CSS for container |
48
+ | `height` | `string` | `'auto'` | Height of the field area |
49
+ | `class` | `string` | `''` | CSS class name |
50
+
51
+ ## Examples
52
+
53
+ ### Basic Form Field
54
+
55
+ ```svelte
56
+ <script>
57
+ import FormField from '@ticatec/uniface-element/FormField';
58
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
59
+ </script>
60
+
61
+ <FormField label="Email">
62
+ <TextEditor type="email" placeholder="user@example.com" />
63
+ </FormField>
64
+ ```
65
+
66
+ ### Required Field
67
+
68
+ ```svelte
69
+ <script>
70
+ import FormField from '@ticatec/uniface-element/FormField';
71
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
72
+ </script>
73
+
74
+ <FormField label="Password" required>
75
+ <TextEditor type="password" placeholder="Enter password" />
76
+ </FormField>
77
+ ```
78
+
79
+ ### With Error Message
80
+
81
+ ```svelte
82
+ <script>
83
+ import FormField from '@ticatec/uniface-element/FormField';
84
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
85
+
86
+ let error = 'This field is required';
87
+ </script>
88
+
89
+ <FormField label="Username" {error} required>
90
+ <TextEditor placeholder="Enter username" />
91
+ </FormField>
92
+ ```
93
+
94
+ ### Top Label Alignment
95
+
96
+ ```svelte
97
+ <script>
98
+ import FormField from '@ticatec/uniface-element/FormField';
99
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
100
+ </script>
101
+
102
+ <FormField label="Description" labelAlignment="top">
103
+ <TextEditor placeholder="Enter description" />
104
+ </FormField>
105
+ ```
106
+
107
+ ### Custom Label Style
108
+
109
+ ```svelte
110
+ <script>
111
+ import FormField from '@ticatec/uniface-element/FormField';
112
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
113
+ </script>
114
+
115
+ <FormField
116
+ label="Important Field"
117
+ labelStyle="color: #007acc; font-weight: bold;"
118
+ >
119
+ <TextEditor placeholder="Enter value" />
120
+ </FormField>
121
+ ```
122
+
123
+ ### Complete Form Example
124
+
125
+ ```svelte
126
+ <script>
127
+ import FormField from '@ticatec/uniface-element/FormField';
128
+ import TextEditor from '@ticatec/uniface-element/TextEditor';
129
+ import Button from '@ticatec/uniface-element/Button';
130
+
131
+ let formData = {
132
+ username: '',
133
+ email: '',
134
+ password: ''
135
+ };
136
+
137
+ let errors = {
138
+ username: '',
139
+ email: '',
140
+ password: ''
141
+ };
142
+
143
+ function validate() {
144
+ if (!formData.username) {
145
+ errors.username = 'Username is required';
146
+ }
147
+ if (!formData.email) {
148
+ errors.email = 'Email is required';
149
+ }
150
+ if (!formData.password) {
151
+ errors.password = 'Password is required';
152
+ }
153
+ }
154
+
155
+ function handleSubmit() {
156
+ validate();
157
+ if (Object.values(errors).every(e => !e)) {
158
+ console.log('Form submitted:', formData);
159
+ }
160
+ }
161
+ </script>
162
+
163
+ <form on:submit|preventDefault={handleSubmit}>
164
+ <FormField label="Username" required error={errors.username}>
165
+ <TextEditor bind:value={formData.username} placeholder="Enter username" />
166
+ </FormField>
167
+
168
+ <FormField label="Email" required error={errors.email}>
169
+ <TextEditor bind:value={formData.email} type="email" placeholder="user@example.com" />
170
+ </FormField>
171
+
172
+ <FormField label="Password" required error={errors.password}>
173
+ <TextEditor bind:value={formData.password} type="password" placeholder="Enter password" />
174
+ </FormField>
175
+
176
+ <Button type="primary" onclick={handleSubmit}>Submit</Button>
177
+ </form>
178
+ ```
179
+
180
+ ## Best Practices
181
+
182
+ 1. **Always use labels**: Provide clear, descriptive labels for accessibility
183
+ 2. **Mark required fields**: Use the `required` prop for mandatory fields
184
+ 3. **Show errors**: Display validation errors below the field
185
+ 4. **Consistent alignment**: Use the same label alignment throughout a form
186
+ 5. **Custom styling**: Use labelStyle for special emphasis when needed
187
+
188
+ ## Accessibility
189
+
190
+ - Proper label association with form fields
191
+ - Required indicator for screen readers
192
+ - Error message display for validation feedback
193
+ - Semantic HTML structure