@lynx-example/lynx-ui-form 0.0.1 → 0.0.2
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/Basic/data.ts +35 -0
- package/Basic/index.css +241 -0
- package/Basic/index.tsx +113 -0
- package/CHANGELOG.md +8 -0
- package/KeyboardAware/data.ts +103 -0
- package/KeyboardAware/index.css +205 -0
- package/KeyboardAware/index.tsx +119 -0
- package/dist/FormBasic.lynx.bundle +0 -0
- package/dist/FormBasic.web.bundle +1 -1
- package/dist/FormKeyboardAware.lynx.bundle +0 -0
- package/dist/FormKeyboardAware.web.bundle +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { root, useState } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
FormField,
|
|
9
|
+
FormRoot,
|
|
10
|
+
FormSubmitButton,
|
|
11
|
+
KeyboardAwareResponder,
|
|
12
|
+
KeyboardAwareRoot,
|
|
13
|
+
KeyboardAwareTrigger,
|
|
14
|
+
} from '@lynx-js/lynx-ui'
|
|
15
|
+
|
|
16
|
+
import { demoItems } from './data'
|
|
17
|
+
|
|
18
|
+
import './index.css'
|
|
19
|
+
|
|
20
|
+
const initialValues = Object.fromEntries(
|
|
21
|
+
demoItems
|
|
22
|
+
.filter(
|
|
23
|
+
(item) => item.type === 'input' || item.type === 'textarea',
|
|
24
|
+
)
|
|
25
|
+
.map((item) => [item.name, '']),
|
|
26
|
+
) as Record<string, string>
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
const [submitted, setSubmitted] = useState<Record<string, unknown> | null>(
|
|
30
|
+
null,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<view className='demo-container lunaris-dark luna-gradient-berry'>
|
|
35
|
+
<KeyboardAwareRoot androidStatusBarPlusBottomBarHeight={74}>
|
|
36
|
+
<FormRoot
|
|
37
|
+
initialValues={initialValues}
|
|
38
|
+
>
|
|
39
|
+
<KeyboardAwareResponder as='ScrollView' className='demo-canvas'>
|
|
40
|
+
<view className='form-container'>
|
|
41
|
+
<text className='form-title'>Keyboard-aware Form</text>
|
|
42
|
+
<text className='form-subtitle'>
|
|
43
|
+
Form fields stay visible while typing in a long scroll.
|
|
44
|
+
</text>
|
|
45
|
+
|
|
46
|
+
<view className='form-divider' />
|
|
47
|
+
|
|
48
|
+
{demoItems.map((item) => {
|
|
49
|
+
if (item.type === 'block') {
|
|
50
|
+
return <view key={item.key} className='block' />
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (item.type === 'input') {
|
|
54
|
+
return (
|
|
55
|
+
<KeyboardAwareTrigger key={item.key} offset={0}>
|
|
56
|
+
<view className='form-card'>
|
|
57
|
+
<text className='form-label'>{item.label}</text>
|
|
58
|
+
<view className='input-container'>
|
|
59
|
+
<FormField
|
|
60
|
+
as='Input'
|
|
61
|
+
name={item.name}
|
|
62
|
+
className='form-input'
|
|
63
|
+
placeholder={item.placeholder}
|
|
64
|
+
/>
|
|
65
|
+
</view>
|
|
66
|
+
</view>
|
|
67
|
+
</KeyboardAwareTrigger>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<KeyboardAwareTrigger key={item.key} offset={0}>
|
|
73
|
+
<view className='form-card'>
|
|
74
|
+
<text className='form-label'>{item.label}</text>
|
|
75
|
+
<view className='form-textarea-wrap'>
|
|
76
|
+
<FormField
|
|
77
|
+
as='TextArea'
|
|
78
|
+
name={item.name}
|
|
79
|
+
className='form-textarea'
|
|
80
|
+
placeholder={item.placeholder}
|
|
81
|
+
maxLines={12}
|
|
82
|
+
maxLength={600}
|
|
83
|
+
/>
|
|
84
|
+
</view>
|
|
85
|
+
</view>
|
|
86
|
+
</KeyboardAwareTrigger>
|
|
87
|
+
)
|
|
88
|
+
})}
|
|
89
|
+
|
|
90
|
+
<view className='form-divider' />
|
|
91
|
+
|
|
92
|
+
<FormSubmitButton
|
|
93
|
+
className='submit-button'
|
|
94
|
+
onSubmit={(values) => setSubmitted(values)}
|
|
95
|
+
>
|
|
96
|
+
<text className='submit-button-text'>Submit</text>
|
|
97
|
+
</FormSubmitButton>
|
|
98
|
+
|
|
99
|
+
{submitted
|
|
100
|
+
? (
|
|
101
|
+
<view className='form-values-display'>
|
|
102
|
+
<text className='form-values-text'>
|
|
103
|
+
{JSON.stringify(submitted, null, 2)}
|
|
104
|
+
</text>
|
|
105
|
+
</view>
|
|
106
|
+
)
|
|
107
|
+
: null}
|
|
108
|
+
|
|
109
|
+
<view className='bottom-spacer' />
|
|
110
|
+
</view>
|
|
111
|
+
</KeyboardAwareResponder>
|
|
112
|
+
</FormRoot>
|
|
113
|
+
</KeyboardAwareRoot>
|
|
114
|
+
</view>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
root.render(<App />)
|
|
119
|
+
export default App
|
|
Binary file
|