@app-studio/web 0.9.57 → 0.9.59
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/dist/components/Background/Background/Background.props.d.ts +15 -8
- package/dist/components/Background/Background/Background.style.d.ts +0 -2
- package/dist/components/Background/Background/Background.view.d.ts +2 -1
- package/dist/components/Background/Background.d.ts +1 -0
- package/dist/components/ChatInput/ChatInput/ChatInput.props.d.ts +17 -0
- package/dist/components/Formik/Formik.Uploader.d.ts +1 -1
- package/dist/components/ProgressBar/ProgressBar/ProgressBar.props.d.ts +36 -2
- package/dist/components/ProgressBar/ProgressBar.d.ts +1 -0
- package/dist/components/Title/Title/Title.props.d.ts +0 -5
- package/dist/web.cjs.development.js +149 -99
- package/dist/web.cjs.development.js.map +1 -1
- package/dist/web.cjs.production.min.js +1 -1
- package/dist/web.cjs.production.min.js.map +1 -1
- package/dist/web.esm.js +149 -99
- package/dist/web.esm.js.map +1 -1
- package/dist/web.umd.development.js +153 -102
- package/dist/web.umd.development.js.map +1 -1
- package/dist/web.umd.production.min.js +1 -1
- package/dist/web.umd.production.min.js.map +1 -1
- package/docs/app-studio/Animation.md +241 -0
- package/docs/app-studio/Components.md +192 -0
- package/docs/app-studio/Design.md +121 -0
- package/docs/app-studio/Events.md +296 -0
- package/docs/app-studio/Hooks.md +469 -0
- package/docs/app-studio/Providers.md +186 -0
- package/docs/app-studio/README.md +781 -0
- package/docs/app-studio/Responsive.md +135 -0
- package/docs/app-studio/Theming.md +488 -0
- package/docs/components/Background.mdx +2 -2
- package/docs/components/ChatInput.mdx +133 -0
- package/package.json +3 -2
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# Event Management
|
|
2
|
+
|
|
3
|
+
App-Studio provides intuitive ways to manage events in your CSS through the `on` prop and underscore-prefixed properties. These features are designed to offer convenient ways to style elements based on various interactive states, represented by CSS pseudo-classes like `hover`, `active`, and `focus`.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Introduction to Event-Based Styling
|
|
8
|
+
|
|
9
|
+
### Using the `on` Prop
|
|
10
|
+
|
|
11
|
+
The `on` prop takes an object as its value. The keys in this object correspond to the names of the CSS pseudo-classes, and the values are objects that define the styles to apply when the event occurs.
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
on={{ [eventName]: { [styleProps]: [styleValue] } }}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Here `eventName` is the name of the CSS pseudo-class, `styleProps` are the CSS properties you wish to change, and `styleValue` are the values you want to apply.
|
|
18
|
+
|
|
19
|
+
### Using Underscore-Prefixed Properties
|
|
20
|
+
|
|
21
|
+
As an alternative to the `on` prop, you can use underscore-prefixed properties directly. This provides a more concise syntax for common event-based styling:
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
_hover={{ backgroundColor: 'blue.100' }}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
You can also use string values for simple color changes:
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
_hover="color.blue.500"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Underscore-prefixed properties support all the same events as the `on` prop, but with a more direct syntax. For example, instead of writing:
|
|
34
|
+
|
|
35
|
+
```jsx
|
|
36
|
+
on={{ hover: { backgroundColor: 'blue.100' } }}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You can simply write:
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
_hover={{ backgroundColor: 'blue.100' }}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Both approaches achieve the same result, so you can choose the syntax that best fits your coding style. The underscore-prefixed approach is particularly useful when you want to apply styles to multiple different states without nesting them all within a single `on` prop object.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 2. Usage Examples
|
|
50
|
+
|
|
51
|
+
### Example 1: Changing Background Color on Hover for `View`
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
<View
|
|
55
|
+
backgroundColor="grey"
|
|
56
|
+
padding={20}
|
|
57
|
+
on={{ hover: { backgroundColor: 'blue.100' } }}
|
|
58
|
+
>
|
|
59
|
+
Hover over me
|
|
60
|
+
</View>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
In this example, the `View` component's background color will change to `blue.100` when the user hovers over it.
|
|
64
|
+
|
|
65
|
+
### Example 2: Background Color Toggle for `Element`
|
|
66
|
+
|
|
67
|
+
```jsx
|
|
68
|
+
<Element backgroundColor="blue" on={{ hover: { backgroundColor: 'color.red' } }} />
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Here, the `Element` component initially has a background color of `blue`. When hovered over, the background color toggles to `red`.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 3. Supported Events
|
|
76
|
+
|
|
77
|
+
The `on` prop supports a comprehensive set of CSS pseudo-classes, allowing you to fine-tune your UI based on various states and interactions. These are grouped by category for easier reference:
|
|
78
|
+
|
|
79
|
+
### Basic Interaction States
|
|
80
|
+
|
|
81
|
+
- `hover`: Triggered when the mouse is placed over the component.
|
|
82
|
+
- `active`: Triggered when the component is actively being interacted with (e.g., a mouse click).
|
|
83
|
+
- `focus`: Triggered when the component gains focus (e.g., through tab navigation).
|
|
84
|
+
- `visited`: Triggered for links that have been visited.
|
|
85
|
+
|
|
86
|
+
### Form States
|
|
87
|
+
|
|
88
|
+
- `disabled`: Triggered when the component is disabled.
|
|
89
|
+
- `enabled`: Triggered when the component is enabled.
|
|
90
|
+
- `checked`: Triggered for checked inputs (like checkboxes or radio buttons).
|
|
91
|
+
- `unchecked`: Triggered for unchecked inputs.
|
|
92
|
+
- `invalid`: Triggered when a form element's value is invalid.
|
|
93
|
+
- `valid`: Triggered when a form element's value is valid.
|
|
94
|
+
- `required`: Triggered for form elements with the required attribute.
|
|
95
|
+
- `optional`: Triggered for form elements without the required attribute.
|
|
96
|
+
- `placeholder`: Triggered when an input is showing its placeholder text.
|
|
97
|
+
|
|
98
|
+
### Selection States
|
|
99
|
+
|
|
100
|
+
- `selected`: Triggered for selected items (like options in a select element).
|
|
101
|
+
|
|
102
|
+
### Target States
|
|
103
|
+
|
|
104
|
+
- `target`: Triggered when the element is the target of the URL fragment (e.g., #section).
|
|
105
|
+
|
|
106
|
+
### Child Position States
|
|
107
|
+
|
|
108
|
+
- `firstChild`: Triggered when the element is the first child of its parent.
|
|
109
|
+
- `lastChild`: Triggered when the element is the last child of its parent.
|
|
110
|
+
- `onlyChild`: Triggered when the element is the only child of its parent.
|
|
111
|
+
- `firstOfType`: Triggered when the element is the first of its type among siblings.
|
|
112
|
+
- `lastOfType`: Triggered when the element is the last of its type among siblings.
|
|
113
|
+
|
|
114
|
+
### Other States
|
|
115
|
+
|
|
116
|
+
- `empty`: Triggered when the element has no children.
|
|
117
|
+
- `focusVisible`: Triggered when the element has keyboard focus.
|
|
118
|
+
- `focusWithin`: Triggered when the element or any of its descendants has focus.
|
|
119
|
+
|
|
120
|
+
## 4. Advanced Examples
|
|
121
|
+
|
|
122
|
+
### Example 3: Form Input States Using the `on` Prop
|
|
123
|
+
|
|
124
|
+
```jsx
|
|
125
|
+
<Form.Input
|
|
126
|
+
value="Focus me"
|
|
127
|
+
on={{
|
|
128
|
+
focus: { borderColor: 'color.blue.500', boxShadow: '0 0 0 3px rgba(66, 153, 225, 0.5)' },
|
|
129
|
+
invalid: { borderColor: 'color.red.500' },
|
|
130
|
+
disabled: { backgroundColor: 'color.gray.100', cursor: 'not-allowed' },
|
|
131
|
+
placeholder: { color: 'color.gray.400' }
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This example shows how to style an input field in different states: when it has focus, when it contains invalid data, when it's disabled, and when it's showing placeholder text.
|
|
137
|
+
|
|
138
|
+
### Example 3b: Form Input States Using Underscore Properties
|
|
139
|
+
|
|
140
|
+
```jsx
|
|
141
|
+
<Form.Input
|
|
142
|
+
value="Focus me"
|
|
143
|
+
_focus={{ borderColor: 'color.blue.500', boxShadow: '0 0 0 3px rgba(66, 153, 225, 0.5)' }}
|
|
144
|
+
_invalid={{ borderColor: 'color.red.500' }}
|
|
145
|
+
_disabled={{ backgroundColor: 'color.gray.100', cursor: 'not-allowed' }}
|
|
146
|
+
_placeholder={{ color: 'color.gray.400' }}
|
|
147
|
+
/>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
This example achieves the same result as the previous one but uses the more concise underscore-prefixed properties.
|
|
151
|
+
|
|
152
|
+
### Example 4: Interactive Button with Multiple States Using the `on` Prop
|
|
153
|
+
|
|
154
|
+
```jsx
|
|
155
|
+
<Button
|
|
156
|
+
backgroundColor="color.blue.500"
|
|
157
|
+
color="white"
|
|
158
|
+
padding={10}
|
|
159
|
+
borderRadius={4}
|
|
160
|
+
on={{
|
|
161
|
+
hover: { backgroundColor: 'color.blue.600', shadow: 3 },
|
|
162
|
+
active: { backgroundColor: 'color.blue.700', transform: 'scale(0.98)', shadow: 1 },
|
|
163
|
+
focus: { boxShadow: '0 0 0 3px rgba(66, 153, 225, 0.5)' },
|
|
164
|
+
disabled: { opacity: 0.6, cursor: 'not-allowed', shadow: 0 }
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
Click Me
|
|
168
|
+
</Button>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
> **Note:** You can use the `shadow` property inside the `on` prop to change the shadow level based on interaction state. The shadow property accepts numbers from 0-9, with higher numbers creating more pronounced shadows.
|
|
172
|
+
|
|
173
|
+
This button changes its appearance based on different interaction states, providing visual feedback to users.
|
|
174
|
+
|
|
175
|
+
### Example 4b: Interactive Button with Multiple States Using Underscore Properties
|
|
176
|
+
|
|
177
|
+
```jsx
|
|
178
|
+
<Button
|
|
179
|
+
backgroundColor="color.blue.500"
|
|
180
|
+
color="white"
|
|
181
|
+
padding={10}
|
|
182
|
+
borderRadius={4}
|
|
183
|
+
_hover={{ backgroundColor: 'color.blue.600', shadow: 3 }}
|
|
184
|
+
_active={{ backgroundColor: 'color.blue.700', transform: 'scale(0.98)', shadow: 1 }}
|
|
185
|
+
_focus={{ boxShadow: '0 0 0 3px rgba(66, 153, 225, 0.5)' }}
|
|
186
|
+
_disabled={{ opacity: 0.6, cursor: 'not-allowed', shadow: 0 }}
|
|
187
|
+
>
|
|
188
|
+
Click Me
|
|
189
|
+
</Button>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
This example achieves the same result as the previous one but uses the more concise underscore-prefixed properties.
|
|
193
|
+
|
|
194
|
+
### Example 5: List Item with Position-Based Styling
|
|
195
|
+
|
|
196
|
+
```jsx
|
|
197
|
+
<View as="ul" padding={0} margin={0} listStyle="none">
|
|
198
|
+
{items.map(item => (
|
|
199
|
+
<View
|
|
200
|
+
as="li"
|
|
201
|
+
padding={10}
|
|
202
|
+
borderBottom="1px solid color.gray.200"
|
|
203
|
+
on={{
|
|
204
|
+
firstChild: { borderTop: '1px solid color.gray.200' },
|
|
205
|
+
lastChild: { borderBottom: 'none' },
|
|
206
|
+
hover: { backgroundColor: 'color.gray.50' }
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
{item.name}
|
|
210
|
+
</View>
|
|
211
|
+
))}
|
|
212
|
+
</View>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
This example shows how to apply different styles to list items based on their position in the list.
|
|
216
|
+
|
|
217
|
+
### Example 6: Form Checkbox with State Styling
|
|
218
|
+
|
|
219
|
+
```jsx
|
|
220
|
+
<View
|
|
221
|
+
as="label"
|
|
222
|
+
display="flex"
|
|
223
|
+
alignItems="center"
|
|
224
|
+
cursor="pointer"
|
|
225
|
+
>
|
|
226
|
+
<Input
|
|
227
|
+
type="checkbox"
|
|
228
|
+
marginRight={8}
|
|
229
|
+
on={{
|
|
230
|
+
checked: { /* Custom styles for the checked state */ },
|
|
231
|
+
focus: { outline: 'none', boxShadow: '0 0 0 2px color.blue.300' }
|
|
232
|
+
}}
|
|
233
|
+
/>
|
|
234
|
+
Accept terms and conditions
|
|
235
|
+
</View>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
This example demonstrates styling a checkbox input based on its checked and focus states.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## 5. Combining with Animations
|
|
243
|
+
|
|
244
|
+
### Using the `on` Prop with Animations
|
|
245
|
+
|
|
246
|
+
The `on` prop can be combined with animations to create dynamic effects:
|
|
247
|
+
|
|
248
|
+
```jsx
|
|
249
|
+
<Button
|
|
250
|
+
padding={10}
|
|
251
|
+
backgroundColor="color.purple.500"
|
|
252
|
+
color="white"
|
|
253
|
+
borderRadius={4}
|
|
254
|
+
on={{
|
|
255
|
+
hover: {
|
|
256
|
+
backgroundColor: 'color.purple.600',
|
|
257
|
+
animate: Animation.pulse({ duration: '1s', iterationCount: 'infinite' })
|
|
258
|
+
},
|
|
259
|
+
active: {
|
|
260
|
+
backgroundColor: 'color.purple.700',
|
|
261
|
+
animate: Animation.scale({ from: { transform: 'scale(1)' }, to: { transform: 'scale(0.95)' }, duration: '0.1s' })
|
|
262
|
+
}
|
|
263
|
+
}}
|
|
264
|
+
>
|
|
265
|
+
Animated Button
|
|
266
|
+
</Button>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Using Underscore Properties with Animations
|
|
270
|
+
|
|
271
|
+
You can also use underscore-prefixed properties with animations:
|
|
272
|
+
|
|
273
|
+
```jsx
|
|
274
|
+
<Button
|
|
275
|
+
padding={10}
|
|
276
|
+
backgroundColor="color.purple.500"
|
|
277
|
+
color="white"
|
|
278
|
+
borderRadius={4}
|
|
279
|
+
_hover={{
|
|
280
|
+
backgroundColor: 'color.purple.600',
|
|
281
|
+
animate: Animation.pulse({ duration: '1s', iterationCount: 'infinite' })
|
|
282
|
+
}}
|
|
283
|
+
_active={{
|
|
284
|
+
backgroundColor: 'color.purple.700',
|
|
285
|
+
animate: Animation.scale({ from: { transform: 'scale(1)' }, to: { transform: 'scale(0.95)' }, duration: '0.1s' })
|
|
286
|
+
}}
|
|
287
|
+
>
|
|
288
|
+
Animated Button
|
|
289
|
+
</Button>
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
App-Studio provides powerful and efficient ways to manage events in your CSS through both the `on` prop and underscore-prefixed properties. These approaches offer straightforward methods for enhancing your components' interactivity, making for a more dynamic and engaging user experience.
|
|
295
|
+
|
|
296
|
+
The `on` prop is great for grouping related event styles together, while underscore-prefixed properties offer a more concise syntax that some developers may prefer. By leveraging CSS pseudo-classes through either approach, you can create sophisticated UI behaviors without complex JavaScript logic.
|