@qwickapps/react-framework 1.3.3 → 1.3.5
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/README.md +227 -0
- package/dist/components/blocks/Content.d.ts.map +1 -1
- package/dist/components/blocks/ProductCard.d.ts.map +1 -1
- package/dist/components/forms/FormBlock.d.ts +1 -1
- package/dist/components/forms/FormBlock.d.ts.map +1 -1
- package/dist/components/input/SwitchInputField.d.ts +28 -0
- package/dist/components/input/SwitchInputField.d.ts.map +1 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.d.ts.map +1 -1
- package/dist/components/layout/CollapsibleLayout/CollapsibleLayout.d.ts +34 -0
- package/dist/components/layout/CollapsibleLayout/CollapsibleLayout.d.ts.map +1 -0
- package/dist/components/layout/CollapsibleLayout/index.d.ts +9 -0
- package/dist/components/layout/CollapsibleLayout/index.d.ts.map +1 -0
- package/dist/components/layout/index.d.ts +2 -0
- package/dist/components/layout/index.d.ts.map +1 -1
- package/dist/contexts/ThemeContext.d.ts.map +1 -1
- package/dist/index.esm.js +963 -105
- package/dist/index.js +967 -101
- package/dist/schemas/CollapsibleLayoutSchema.d.ts +31 -0
- package/dist/schemas/CollapsibleLayoutSchema.d.ts.map +1 -0
- package/dist/schemas/SwitchInputFieldSchema.d.ts +18 -0
- package/dist/schemas/SwitchInputFieldSchema.d.ts.map +1 -0
- package/dist/types/CollapsibleLayout.d.ts +142 -0
- package/dist/types/CollapsibleLayout.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/blocks/Content.tsx +25 -77
- package/src/components/blocks/ProductCard.tsx +50 -51
- package/src/components/forms/FormBlock.tsx +2 -2
- package/src/components/input/SwitchInputField.tsx +165 -0
- package/src/components/input/index.ts +2 -0
- package/src/components/layout/CollapsibleLayout/CollapsibleLayout.tsx +554 -0
- package/src/components/layout/CollapsibleLayout/__tests__/CollapsibleLayout.test.tsx +1469 -0
- package/src/components/layout/CollapsibleLayout/index.tsx +17 -0
- package/src/components/layout/index.ts +4 -1
- package/src/components/pages/FormPage.tsx +1 -1
- package/src/contexts/ThemeContext.tsx +1 -2
- package/src/schemas/CollapsibleLayoutSchema.ts +276 -0
- package/src/schemas/SwitchInputFieldSchema.ts +99 -0
- package/src/stories/CollapsibleLayout.stories.tsx +1566 -0
- package/src/types/CollapsibleLayout.ts +231 -0
- package/src/types/index.ts +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SwitchInputField - Switch toggle component with data binding support
|
|
3
|
+
*
|
|
4
|
+
* Provides a standardized switch field with:
|
|
5
|
+
* - Consistent Material-UI styling
|
|
6
|
+
* - Data binding capabilities
|
|
7
|
+
* - Label and helper text support
|
|
8
|
+
* - Focus and error handling
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2025 QwickApps.com. All rights reserved.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import {
|
|
15
|
+
FormControl,
|
|
16
|
+
FormControlLabel,
|
|
17
|
+
FormHelperText,
|
|
18
|
+
Paper,
|
|
19
|
+
Switch,
|
|
20
|
+
Typography
|
|
21
|
+
} from '@mui/material';
|
|
22
|
+
import type { WithDataBinding, ModelProps } from '@qwickapps/schema';
|
|
23
|
+
import { QWICKAPP_COMPONENT, useBaseProps } from '../../hooks';
|
|
24
|
+
import { useDataBinding } from '../../hooks';
|
|
25
|
+
import SwitchInputFieldModel from '../../schemas/SwitchInputFieldSchema';
|
|
26
|
+
|
|
27
|
+
type SwitchInputFieldViewProps = ModelProps<SwitchInputFieldModel> & {
|
|
28
|
+
/** Change handler */
|
|
29
|
+
onChange?: (checked: boolean) => void;
|
|
30
|
+
/** Focus handler */
|
|
31
|
+
onFocus?: () => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface SwitchInputFieldProps extends SwitchInputFieldViewProps, WithDataBinding {}
|
|
35
|
+
|
|
36
|
+
// View component - handles the actual rendering
|
|
37
|
+
function SwitchInputFieldView({
|
|
38
|
+
label,
|
|
39
|
+
checked = false,
|
|
40
|
+
onChange,
|
|
41
|
+
onFocus,
|
|
42
|
+
required = false,
|
|
43
|
+
disabled = false,
|
|
44
|
+
error,
|
|
45
|
+
helperText,
|
|
46
|
+
size = 'medium',
|
|
47
|
+
color = 'primary',
|
|
48
|
+
...restProps
|
|
49
|
+
}: SwitchInputFieldViewProps) {
|
|
50
|
+
const { styleProps, htmlProps } = useBaseProps(restProps);
|
|
51
|
+
|
|
52
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
53
|
+
if (onChange) {
|
|
54
|
+
onChange(event.target.checked);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<FormControl
|
|
60
|
+
{...htmlProps}
|
|
61
|
+
{...styleProps}
|
|
62
|
+
error={!!error}
|
|
63
|
+
required={required}
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
sx={{
|
|
66
|
+
display: 'block',
|
|
67
|
+
...styleProps.sx
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
<FormControlLabel
|
|
71
|
+
control={
|
|
72
|
+
<Switch
|
|
73
|
+
checked={checked}
|
|
74
|
+
onChange={handleChange}
|
|
75
|
+
onFocus={onFocus}
|
|
76
|
+
size={size}
|
|
77
|
+
color={color}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
/>
|
|
80
|
+
}
|
|
81
|
+
label={label}
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
/>
|
|
84
|
+
{(error || helperText) && (
|
|
85
|
+
<FormHelperText>
|
|
86
|
+
{error || helperText}
|
|
87
|
+
</FormHelperText>
|
|
88
|
+
)}
|
|
89
|
+
</FormControl>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* SwitchInputField component with data binding support
|
|
95
|
+
* Supports both traditional props and dataSource-driven rendering
|
|
96
|
+
*/
|
|
97
|
+
function SwitchInputField(props: SwitchInputFieldProps) {
|
|
98
|
+
const { dataSource, bindingOptions, ...restProps } = props;
|
|
99
|
+
|
|
100
|
+
// If no dataSource, use traditional props
|
|
101
|
+
if (!dataSource) {
|
|
102
|
+
return <SwitchInputFieldView {...restProps} />;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Use data binding
|
|
106
|
+
const bindingResult = useDataBinding<SwitchInputFieldModel>(
|
|
107
|
+
dataSource,
|
|
108
|
+
restProps as Partial<SwitchInputFieldModel>,
|
|
109
|
+
SwitchInputFieldModel.getSchema(),
|
|
110
|
+
{ cache: true, cacheTTL: 300000, strict: false, ...bindingOptions }
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Check if we're still loading data using the metadata properties
|
|
114
|
+
const bindingLoading = bindingResult.$loading;
|
|
115
|
+
|
|
116
|
+
// Extract all the actual switch properties (excluding metadata)
|
|
117
|
+
const { dataSource: _source, $loading, $error, $dataSource, $cached, cached, ...switchInputFieldProps } = bindingResult;
|
|
118
|
+
const error = bindingResult.$error;
|
|
119
|
+
|
|
120
|
+
// Show loading state while fetching data
|
|
121
|
+
if (bindingLoading) {
|
|
122
|
+
return (
|
|
123
|
+
<Paper
|
|
124
|
+
variant="outlined"
|
|
125
|
+
sx={{
|
|
126
|
+
p: 2,
|
|
127
|
+
textAlign: 'center'
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<Typography variant="body2">Loading SwitchInputField...</Typography>
|
|
131
|
+
<Typography variant="caption" color="text.secondary">
|
|
132
|
+
Loading switch field configuration from data source...
|
|
133
|
+
</Typography>
|
|
134
|
+
</Paper>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (error) {
|
|
139
|
+
console.error('Error loading switch input field:', error);
|
|
140
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
141
|
+
return (
|
|
142
|
+
<Paper
|
|
143
|
+
variant="outlined"
|
|
144
|
+
sx={{
|
|
145
|
+
p: 2,
|
|
146
|
+
textAlign: 'center',
|
|
147
|
+
borderColor: 'error.main'
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<Typography variant="body2" color="error">
|
|
151
|
+
Error loading switch field: {error.message}
|
|
152
|
+
</Typography>
|
|
153
|
+
</Paper>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return <SwitchInputFieldView {...switchInputFieldProps} />;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Mark as QwickApp component
|
|
163
|
+
(SwitchInputField as any)[QWICKAPP_COMPONENT] = true;
|
|
164
|
+
|
|
165
|
+
export default SwitchInputField;
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
export { default as ChoiceInputField } from './ChoiceInputField';
|
|
8
8
|
export { default as HtmlInputField } from './HtmlInputField';
|
|
9
9
|
export { default as SelectInputField } from './SelectInputField';
|
|
10
|
+
export { default as SwitchInputField } from './SwitchInputField';
|
|
10
11
|
export { default as TextField } from './TextField';
|
|
11
12
|
export { default as TextInputField } from './TextInputField';
|
|
12
13
|
|
|
13
14
|
export type { ChoiceInputFieldProps } from './ChoiceInputField';
|
|
14
15
|
export type { HtmlInputFieldProps } from './HtmlInputField';
|
|
15
16
|
export type { SelectInputFieldProps, SelectOption } from './SelectInputField';
|
|
17
|
+
export type { SwitchInputFieldProps } from './SwitchInputField';
|
|
16
18
|
export type { TextFieldProps } from './TextField';
|
|
17
19
|
export type { TextInputFieldProps } from './TextInputField';
|