app-studio 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.md +208 -0
- package/dist/app-studio.cjs.development.js +944 -0
- package/dist/app-studio.cjs.development.js.map +1 -0
- package/dist/app-studio.cjs.production.min.js +2 -0
- package/dist/app-studio.cjs.production.min.js.map +1 -0
- package/dist/app-studio.esm.js +907 -0
- package/dist/app-studio.esm.js.map +1 -0
- package/dist/components/Element.d.ts +30 -0
- package/dist/components/Image.d.ts +23 -0
- package/dist/components/Layout.d.ts +11 -0
- package/dist/components/Text.d.ts +23 -0
- package/dist/components/View.d.ts +32 -0
- package/dist/components/Wrapper.d.ts +4 -0
- package/dist/hooks/useMount.d.ts +1 -0
- package/dist/hooks/useResponsive.d.ts +9 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/providers/Responsive.d.ts +20 -0
- package/dist/providers/Theme.d.ts +19 -0
- package/dist/utils/colors.d.ts +14 -0
- package/dist/utils/env.d.ts +15 -0
- package/dist/utils/shadow.d.ts +103 -0
- package/dist/utils/typography.d.ts +46 -0
- package/package.json +114 -0
- package/src/components/Element.tsx +430 -0
- package/src/components/Image.tsx +56 -0
- package/src/components/Layout.tsx +49 -0
- package/src/components/Text.tsx +118 -0
- package/src/components/View.md +6 -0
- package/src/components/View.tsx +87 -0
- package/src/components/Wrapper.tsx +11 -0
- package/src/hooks/useMount.ts +6 -0
- package/src/hooks/useResponsive.ts +102 -0
- package/src/index.tsx +8 -0
- package/src/providers/Responsive.tsx +61 -0
- package/src/providers/Theme.tsx +73 -0
- package/src/types/module.d.ts +1 -0
- package/src/types/style.d.ts +696 -0
- package/src/utils/colors.ts +321 -0
- package/src/utils/env.ts +43 -0
- package/src/utils/shadow.ts +102 -0
- package/src/utils/typography.ts +45 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { useTheme } from '../providers/Theme';
|
|
4
|
+
|
|
5
|
+
export const TransformStyleProps = [
|
|
6
|
+
'transform',
|
|
7
|
+
'transformMatrix',
|
|
8
|
+
'rotation',
|
|
9
|
+
'scaleX',
|
|
10
|
+
'scaleY',
|
|
11
|
+
'translateX',
|
|
12
|
+
'translateY',
|
|
13
|
+
// 'perspective',
|
|
14
|
+
// 'rotate',
|
|
15
|
+
// 'rotateX',
|
|
16
|
+
// 'rotateY',
|
|
17
|
+
// 'rotateZ',
|
|
18
|
+
// 'scale',
|
|
19
|
+
// 'skewX',
|
|
20
|
+
// 'skewY',
|
|
21
|
+
'testID',
|
|
22
|
+
'decomposedMatrix',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export const ImageStyleProps = [
|
|
26
|
+
'borderTopRightRadius',
|
|
27
|
+
'backfaceVisibility',
|
|
28
|
+
'borderBottomLeftRadius',
|
|
29
|
+
'borderBottomRightRadius',
|
|
30
|
+
'borderColor',
|
|
31
|
+
'borderRadius',
|
|
32
|
+
'borderTopLeftRadius',
|
|
33
|
+
'backgroundColor',
|
|
34
|
+
'borderWidth',
|
|
35
|
+
'opacity',
|
|
36
|
+
'overflow',
|
|
37
|
+
'overflowX',
|
|
38
|
+
'overflowY',
|
|
39
|
+
'resizeMode',
|
|
40
|
+
'tintColor',
|
|
41
|
+
'overlayColor',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
export const LayoutStyleProps = [
|
|
45
|
+
'alignContent',
|
|
46
|
+
'alignItems',
|
|
47
|
+
'alignSelf',
|
|
48
|
+
'aspectRatio',
|
|
49
|
+
'borderBottomWidth',
|
|
50
|
+
'borderEndWidth',
|
|
51
|
+
'borderLeftWidth',
|
|
52
|
+
'borderRightWidth',
|
|
53
|
+
'borderStartWidth',
|
|
54
|
+
'borderTopWidth',
|
|
55
|
+
'borderWidth',
|
|
56
|
+
'bottom',
|
|
57
|
+
'direction',
|
|
58
|
+
'display',
|
|
59
|
+
'end',
|
|
60
|
+
'flex',
|
|
61
|
+
'flexBasis',
|
|
62
|
+
'flexDirection',
|
|
63
|
+
'flexGrow',
|
|
64
|
+
'flexShrink',
|
|
65
|
+
'flexWrap',
|
|
66
|
+
'height',
|
|
67
|
+
'justifyContent',
|
|
68
|
+
'left',
|
|
69
|
+
'margin',
|
|
70
|
+
'marginBottom',
|
|
71
|
+
'marginEnd',
|
|
72
|
+
'marginHorizontal',
|
|
73
|
+
'marginLeft',
|
|
74
|
+
'marginRight',
|
|
75
|
+
'marginStart',
|
|
76
|
+
'marginTop',
|
|
77
|
+
'marginVertical',
|
|
78
|
+
'maxHeight',
|
|
79
|
+
'maxWidth',
|
|
80
|
+
'minHeight',
|
|
81
|
+
'minWidth',
|
|
82
|
+
'overflow',
|
|
83
|
+
'overflowX',
|
|
84
|
+
'overflowY',
|
|
85
|
+
'padding',
|
|
86
|
+
'paddingBottom',
|
|
87
|
+
'paddingEnd',
|
|
88
|
+
'paddingHorizontal',
|
|
89
|
+
'paddingLeft',
|
|
90
|
+
'paddingRight',
|
|
91
|
+
'paddingStart',
|
|
92
|
+
'paddingTop',
|
|
93
|
+
'paddingVertical',
|
|
94
|
+
'position',
|
|
95
|
+
'right',
|
|
96
|
+
'start',
|
|
97
|
+
'top',
|
|
98
|
+
'width',
|
|
99
|
+
'zIndex',
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
export const ShadowStyleProps = [
|
|
103
|
+
'shadowColor',
|
|
104
|
+
'shadowOffset',
|
|
105
|
+
'shadowOpacity',
|
|
106
|
+
'shadowRadius',
|
|
107
|
+
];
|
|
108
|
+
export const TextStyleProps = [
|
|
109
|
+
'textShadowOffset',
|
|
110
|
+
'color',
|
|
111
|
+
'fontSize',
|
|
112
|
+
'fontStyle',
|
|
113
|
+
'fontWeight',
|
|
114
|
+
'lineHeight',
|
|
115
|
+
'textAlign',
|
|
116
|
+
'textDecorationLine',
|
|
117
|
+
'textShadowColor',
|
|
118
|
+
'fontFamily',
|
|
119
|
+
'textShadowRadius',
|
|
120
|
+
'includeFontPadding',
|
|
121
|
+
'textAlignVertical',
|
|
122
|
+
'fontVariant',
|
|
123
|
+
'letterSpacing',
|
|
124
|
+
'textDecorationColor',
|
|
125
|
+
'textDecorationStyle',
|
|
126
|
+
'textTransform',
|
|
127
|
+
'writingDirection',
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
export const ViewStyleProps = [
|
|
131
|
+
'borderRightColor',
|
|
132
|
+
'backfaceVisibility',
|
|
133
|
+
'borderBottomColor',
|
|
134
|
+
'borderBottomEndRadius',
|
|
135
|
+
'borderBottomLeftRadius',
|
|
136
|
+
'borderBottomRightRadius',
|
|
137
|
+
'borderBottomStartRadius',
|
|
138
|
+
'borderBottomWidth',
|
|
139
|
+
'borderColor',
|
|
140
|
+
'borderEndColor',
|
|
141
|
+
'borderLeftColor',
|
|
142
|
+
'borderLeftWidth',
|
|
143
|
+
'borderRadius',
|
|
144
|
+
'backgroundColor',
|
|
145
|
+
'borderRightWidth',
|
|
146
|
+
'borderStartColor',
|
|
147
|
+
'borderStyle',
|
|
148
|
+
'borderTopColor',
|
|
149
|
+
'borderTopEndRadius',
|
|
150
|
+
'borderTopLeftRadius',
|
|
151
|
+
'borderTopRightRadius',
|
|
152
|
+
'borderTopStartRadius',
|
|
153
|
+
'borderTopWidth',
|
|
154
|
+
'borderWidth',
|
|
155
|
+
'border',
|
|
156
|
+
'opacity',
|
|
157
|
+
'elevation',
|
|
158
|
+
'size',
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
export const ScrollViewStyleProps = [
|
|
162
|
+
'alwaysBounceHorizontal',
|
|
163
|
+
'alwaysBounceVertical',
|
|
164
|
+
'automaticallyAdjustContentInsets',
|
|
165
|
+
'bounces',
|
|
166
|
+
'bouncesZoom',
|
|
167
|
+
'canCancelContentTouches',
|
|
168
|
+
'centerContent',
|
|
169
|
+
'contentLayoutStyle',
|
|
170
|
+
'contentInset',
|
|
171
|
+
'contentInsetAdjustmentBehavior',
|
|
172
|
+
'contentOffset',
|
|
173
|
+
'decelerationRate',
|
|
174
|
+
'directionalLockEnabled',
|
|
175
|
+
'disableIntervalMomentum',
|
|
176
|
+
'disableScrollViewPanResponder',
|
|
177
|
+
'endFillColor',
|
|
178
|
+
'fadingEdgeLength',
|
|
179
|
+
'horizontal',
|
|
180
|
+
'indicatorStyle',
|
|
181
|
+
'invertStickyHeaders',
|
|
182
|
+
'keyboardDismissMode',
|
|
183
|
+
'keyboardShouldPersistTaps',
|
|
184
|
+
'maintainVisibleContentPosition',
|
|
185
|
+
'maximumZoomScale',
|
|
186
|
+
'minimumZoomScale',
|
|
187
|
+
'nestedScrollEnabled',
|
|
188
|
+
'onContentSizeChange',
|
|
189
|
+
'onMomentumScrollBegin',
|
|
190
|
+
'onMomentumScrollEnd',
|
|
191
|
+
'onScroll',
|
|
192
|
+
'onScrollBeginDrag',
|
|
193
|
+
'onScrollEndDrag',
|
|
194
|
+
'onScrollToTop',
|
|
195
|
+
'overScrollMode',
|
|
196
|
+
'pagingEnabled',
|
|
197
|
+
'persistentScrollbar',
|
|
198
|
+
'pinchGestureEnabled',
|
|
199
|
+
'refreshControl',
|
|
200
|
+
'removeClippedSubviews',
|
|
201
|
+
'scrollBarThumbImage',
|
|
202
|
+
'scrollEnabled',
|
|
203
|
+
'scrollEventThrottle',
|
|
204
|
+
'scrollIndicatorInsets',
|
|
205
|
+
'scrollPerfTag',
|
|
206
|
+
'scrollToOverflowEnabled',
|
|
207
|
+
'scrollsToTop',
|
|
208
|
+
'DEPRECATED_sendUpdatedChildFrames',
|
|
209
|
+
'showsHorizontalScrollIndicator',
|
|
210
|
+
'showsVerticalScrollIndicator',
|
|
211
|
+
'snapToAlignment',
|
|
212
|
+
'snapToEnd',
|
|
213
|
+
'snapToInterval',
|
|
214
|
+
'snapToOffsets',
|
|
215
|
+
'snapToStart',
|
|
216
|
+
'stickyHeaderIndices',
|
|
217
|
+
'zoomScale',
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
export const BaseStyleProperty: any = {};
|
|
221
|
+
LayoutStyleProps.concat(ShadowStyleProps, TransformStyleProps).map(
|
|
222
|
+
(property) => {
|
|
223
|
+
BaseStyleProperty[property] = true;
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
export const ViewStyleProperty: any = BaseStyleProperty;
|
|
228
|
+
ViewStyleProps.map((property) => {
|
|
229
|
+
ViewStyleProperty[property] = true;
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
export const ScrollViewStyleProperty: any = ViewStyleProperty;
|
|
233
|
+
ScrollViewStyleProps.map((property) => {
|
|
234
|
+
ScrollViewStyleProperty[property] = true;
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export const ImageStyleProperty: any = ViewStyleProperty;
|
|
238
|
+
ImageStyleProps.map((property) => {
|
|
239
|
+
ImageStyleProperty[property] = true;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
export const TextStyleProperty: any = BaseStyleProperty;
|
|
243
|
+
TextStyleProps.map((property) => {
|
|
244
|
+
TextStyleProperty[property] = true;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
export const allStyleProps: string[] = LayoutStyleProps.concat(
|
|
248
|
+
ShadowStyleProps,
|
|
249
|
+
TransformStyleProps,
|
|
250
|
+
ViewStyleProps,
|
|
251
|
+
ScrollViewStyleProps,
|
|
252
|
+
TextStyleProps,
|
|
253
|
+
ImageStyleProps
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const WidthWords = ['X', 'Width', 'Horizontal', 'Right', 'Left'];
|
|
257
|
+
|
|
258
|
+
export const WidthStyleProperty = ['x', 'width', 'right', 'left'].concat(
|
|
259
|
+
allStyleProps.filter((property) => {
|
|
260
|
+
return WidthWords.some((item) => property.indexOf(item) >= 0);
|
|
261
|
+
})
|
|
262
|
+
);
|
|
263
|
+
export const WidthStyleProps: any = {};
|
|
264
|
+
WidthStyleProperty.map((property) => {
|
|
265
|
+
WidthStyleProps[property] = true;
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const HeightWords = ['Y', 'Height', 'Vertical', 'top', 'bottom'];
|
|
269
|
+
|
|
270
|
+
export const HeightStyleProperty = ['y', 'height', 'top', 'bottom'].concat(
|
|
271
|
+
allStyleProps.filter((property) => {
|
|
272
|
+
return HeightWords.some((item) => property.indexOf(item) >= 0);
|
|
273
|
+
})
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
export const HeightStyleProps: any = {};
|
|
277
|
+
HeightStyleProperty.map((property) => {
|
|
278
|
+
HeightStyleProps[property] = true;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
export const SizeProps: any = {};
|
|
282
|
+
HeightStyleProperty.concat(WidthStyleProperty).map((property) => {
|
|
283
|
+
SizeProps[property] = true;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
export const StyleProps: any = {};
|
|
287
|
+
allStyleProps.map((property) => {
|
|
288
|
+
StyleProps[property] = true;
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
export const setSize = (newSize: string | number, newProps: any) => {
|
|
292
|
+
newProps.height = newProps.width = newSize;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export const applyStyle = (props: any) => {
|
|
296
|
+
const { getColor } = useTheme();
|
|
297
|
+
|
|
298
|
+
const newProps: any = {};
|
|
299
|
+
|
|
300
|
+
if (props.onClick) {
|
|
301
|
+
newProps.cursor = 'pointer';
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const size =
|
|
305
|
+
props.height !== undefined &&
|
|
306
|
+
props.width !== undefined &&
|
|
307
|
+
props.height === props.width
|
|
308
|
+
? props.height
|
|
309
|
+
: props.size
|
|
310
|
+
? props.size
|
|
311
|
+
: null;
|
|
312
|
+
|
|
313
|
+
if (size) {
|
|
314
|
+
setSize(size, newProps);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (props.paddingHorizontal) {
|
|
318
|
+
newProps.paddingLeft = props.paddingHorizontal;
|
|
319
|
+
newProps.paddingRight = props.paddingHorizontal;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (props.marginHorizontal) {
|
|
323
|
+
newProps.marginLeft = props.marginHorizontal;
|
|
324
|
+
newProps.marginRight = props.marginHorizontal;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (props.paddingVertical) {
|
|
328
|
+
newProps.paddingTop = props.paddingVertical;
|
|
329
|
+
newProps.paddingBottom = props.paddingVertical;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (props.marginVertical) {
|
|
333
|
+
newProps.marginTop = props.marginVertical;
|
|
334
|
+
newProps.marginBottom = props.marginVertical;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
Object.keys(props)
|
|
338
|
+
.filter(
|
|
339
|
+
(property) => StyleProps[property] !== undefined || property[0] == '&'
|
|
340
|
+
)
|
|
341
|
+
.map((property) => {
|
|
342
|
+
newProps[property] = props[property];
|
|
343
|
+
|
|
344
|
+
// console.log(property, propertyType);
|
|
345
|
+
|
|
346
|
+
if (property.toLowerCase().indexOf('color') !== -1) {
|
|
347
|
+
newProps[property] = getColor(props[property]);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// return {newProps,responsive};
|
|
352
|
+
return newProps;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// function convertToCSS(props: any) {
|
|
356
|
+
// return Object.entries(props).reduce((str, [key, val]) => {
|
|
357
|
+
// const casedKey = key.replace(
|
|
358
|
+
// /[A-Z]/g,
|
|
359
|
+
// (match) => `-${match.toLowerCase()}`
|
|
360
|
+
// );
|
|
361
|
+
// return `${str}${casedKey}:${typeof val === 'number' ? val + 'px' : val};\n`;
|
|
362
|
+
// }, '');
|
|
363
|
+
// }
|
|
364
|
+
|
|
365
|
+
// export const getResponsiveMediaQueries = (props: any) => {
|
|
366
|
+
// const { breakpointKeys, breakpoints } = useResponsive();
|
|
367
|
+
// console.log('mediaQueries', props);
|
|
368
|
+
|
|
369
|
+
// const mediaQueries = breakpointKeys
|
|
370
|
+
// .map((size) => {
|
|
371
|
+
// return props && props[size] !== undefined
|
|
372
|
+
// ? `
|
|
373
|
+
// @media ${
|
|
374
|
+
// breakpoints[size].min
|
|
375
|
+
// ? ' (min-width:' +
|
|
376
|
+
// (breakpoints[size].min > 0 ? breakpoints[size].min : 0) +
|
|
377
|
+
// 'px)'
|
|
378
|
+
// : ''
|
|
379
|
+
// } ${
|
|
380
|
+
// breakpoints[size].min &&
|
|
381
|
+
// breakpoints[size].max &&
|
|
382
|
+
// breakpoints[size].max >= 0 &&
|
|
383
|
+
// breakpoints[size].max < Infinity
|
|
384
|
+
// ? ' and '
|
|
385
|
+
// : ''
|
|
386
|
+
// } ${
|
|
387
|
+
// breakpoints[size].max &&
|
|
388
|
+
// breakpoints[size].max >= 0 &&
|
|
389
|
+
// breakpoints[size].max < Infinity
|
|
390
|
+
// ? ' (max-width:' + breakpoints[size].max + 'px)'
|
|
391
|
+
// : ''
|
|
392
|
+
// } {
|
|
393
|
+
// ${convertToCSS(props[size])}
|
|
394
|
+
// }`
|
|
395
|
+
// : '';
|
|
396
|
+
// })
|
|
397
|
+
// .join('\n');
|
|
398
|
+
|
|
399
|
+
// return mediaQueries;
|
|
400
|
+
// };
|
|
401
|
+
|
|
402
|
+
export const StyledView = styled.div((props: any) => {
|
|
403
|
+
return applyStyle(props);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
export const StyledImage = styled.img((props: any) => {
|
|
407
|
+
return applyStyle(props);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
export class ViewElement extends React.PureComponent<any> {
|
|
411
|
+
render() {
|
|
412
|
+
let { onClick } = this.props;
|
|
413
|
+
if (this.props.onPress !== undefined) {
|
|
414
|
+
onClick = this.props.onPress;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
//console.log(this.props);
|
|
418
|
+
return <StyledView {...this.props} onClick={onClick} />;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export class ImageElement extends React.PureComponent<any> {
|
|
423
|
+
render() {
|
|
424
|
+
let { onClick } = this.props;
|
|
425
|
+
if (this.props.onPress !== undefined) {
|
|
426
|
+
onClick = this.props.onPress;
|
|
427
|
+
}
|
|
428
|
+
return <StyledImage {...this.props} onClick={onClick} />;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CSSProperties } from 'styled-components';
|
|
3
|
+
import { ImageElement } from './Element';
|
|
4
|
+
import { View } from './View';
|
|
5
|
+
import {
|
|
6
|
+
ImageProps as ComponentImageProps,
|
|
7
|
+
ResponsiveStyle,
|
|
8
|
+
} from '../types/style';
|
|
9
|
+
|
|
10
|
+
export interface ImageProps
|
|
11
|
+
extends Omit<ComponentImageProps, 'pointerEvents' | 'source'>,
|
|
12
|
+
CSSProperties {
|
|
13
|
+
size?: number;
|
|
14
|
+
className?: string;
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
onPress?: () => void;
|
|
17
|
+
action?: string;
|
|
18
|
+
alt?: string;
|
|
19
|
+
src: string | any;
|
|
20
|
+
style?: any;
|
|
21
|
+
responsive?: ResponsiveStyle;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ImageBackgroundProps extends ImageProps {
|
|
25
|
+
src: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class ImageBackground extends React.PureComponent<ImageBackgroundProps> {
|
|
29
|
+
render() {
|
|
30
|
+
const { src, style, onClick, onPress, ...props } = this.props;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<View
|
|
34
|
+
style={{
|
|
35
|
+
backgroundSize: 'contain',
|
|
36
|
+
backgroundImage: `url("${src}")`,
|
|
37
|
+
backgroundPosition: 'center center',
|
|
38
|
+
backgroundRepeat: 'no-repeat',
|
|
39
|
+
...style,
|
|
40
|
+
}}
|
|
41
|
+
onClick={onClick ? onClick : onPress}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const Image = (props: ImageProps) => <ImageElement {...props} />;
|
|
49
|
+
|
|
50
|
+
export const RoundedImage = ({ size, src, ...props }: any) => (
|
|
51
|
+
<ImageBackground borderRadius={size / 2} size={size} src={src} {...props} />
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export const SquaredImage = ({ size, src, ...props }: any) => (
|
|
55
|
+
<ImageBackground {...props} size={size} src={src} />
|
|
56
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from './View';
|
|
3
|
+
|
|
4
|
+
export const Layout = (props: any) => <View {...props} />;
|
|
5
|
+
|
|
6
|
+
export const Horizontal = (props: any) => (
|
|
7
|
+
<View display={'flex'} flexDirection="row" {...props} />
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const Inline = (props: any) => (
|
|
11
|
+
<View
|
|
12
|
+
display={'flex'}
|
|
13
|
+
flexDirection="row"
|
|
14
|
+
wordBreak="break-word"
|
|
15
|
+
{...props}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const Vertical = (props: any) => (
|
|
20
|
+
<View flexDirection="column" {...props} />
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const Center = (props: any) => (
|
|
24
|
+
<View
|
|
25
|
+
display={'flex'}
|
|
26
|
+
justifyContent="center"
|
|
27
|
+
alignItems={'center'}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const AlignStart = (props: any) => (
|
|
33
|
+
<View display={'flex'} justifyContent="flex-start" {...props} />
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export const AlignCenter = (props: any) => (
|
|
37
|
+
<View display={'flex'} justifyContent="center" width={'100%'} {...props} />
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const AlignEnd = (props: any) => (
|
|
41
|
+
<View display={'flex'} justifyContent="flex-end" width={'100%'} {...props} />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const Start = (props: any) => (
|
|
45
|
+
<View display={'flex'} alignSelf="flex-end" {...props} />
|
|
46
|
+
);
|
|
47
|
+
export const End = (props: any) => (
|
|
48
|
+
<View display={'flex'} alignSelf="flex-end" {...props} />
|
|
49
|
+
);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CSSProperties } from 'styled-components';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { applyStyle } from './Element';
|
|
5
|
+
import { useTheme } from '../providers/Theme';
|
|
6
|
+
import {
|
|
7
|
+
GenericStyleProp,
|
|
8
|
+
TextProps,
|
|
9
|
+
TextStyle,
|
|
10
|
+
ResponsiveStyle,
|
|
11
|
+
} from '../types/style';
|
|
12
|
+
|
|
13
|
+
export interface ComponentTextProps
|
|
14
|
+
extends Omit<TextProps, 'pointerEvents' | 'onPress'>,
|
|
15
|
+
CSSProperties {
|
|
16
|
+
data?: object;
|
|
17
|
+
children?: string | any;
|
|
18
|
+
className?: string;
|
|
19
|
+
paddingHorizontal?: number | string;
|
|
20
|
+
marginHorizontal?: number | string;
|
|
21
|
+
paddingVertical?: number | string;
|
|
22
|
+
marginVertical?: number | string;
|
|
23
|
+
locale?: string;
|
|
24
|
+
toUpperCase?: boolean;
|
|
25
|
+
style?: GenericStyleProp<TextStyle>;
|
|
26
|
+
responsive?: ResponsiveStyle;
|
|
27
|
+
backgroundColor?: string;
|
|
28
|
+
|
|
29
|
+
onPress?: void;
|
|
30
|
+
action?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const formatTextStyle: any = ({
|
|
34
|
+
hint = false,
|
|
35
|
+
disabled = false,
|
|
36
|
+
opacity,
|
|
37
|
+
fontSize,
|
|
38
|
+
...props
|
|
39
|
+
}: CSSProperties & {
|
|
40
|
+
disabled: number | boolean;
|
|
41
|
+
hint: number | boolean;
|
|
42
|
+
opacity: number;
|
|
43
|
+
fontSize?: number;
|
|
44
|
+
}) => {
|
|
45
|
+
if (props) {
|
|
46
|
+
if (hint) {
|
|
47
|
+
opacity = hint as number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (disabled) {
|
|
51
|
+
opacity = disabled as number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { ...props, opacity, fontSize };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return props;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const TextSpan: React.FC<CSSProperties> = styled.div(
|
|
61
|
+
(props: CSSProperties) => {
|
|
62
|
+
props.display = 'inherit';
|
|
63
|
+
props.flexDirection = 'column';
|
|
64
|
+
return applyStyle(props);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const TextComponent: React.FC<ComponentTextProps> = (textProps) => {
|
|
69
|
+
const { getColor } = useTheme();
|
|
70
|
+
|
|
71
|
+
const styledProps = applyStyle(textProps);
|
|
72
|
+
const {
|
|
73
|
+
toUpperCase = false,
|
|
74
|
+
children,
|
|
75
|
+
textTypographyConfig,
|
|
76
|
+
...props
|
|
77
|
+
} = styledProps;
|
|
78
|
+
let content: any = children;
|
|
79
|
+
|
|
80
|
+
if (children && typeof children === 'string') {
|
|
81
|
+
content = children.toString().trim();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof content === 'string' && toUpperCase) {
|
|
85
|
+
content = content.toUpperCase();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let style = props.style || {};
|
|
89
|
+
|
|
90
|
+
if (textTypographyConfig) {
|
|
91
|
+
style = formatTextStyle({ ...textTypographyConfig, ...style });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (typeof content === 'string') {
|
|
95
|
+
content = content.split('\n').map((item, key) => {
|
|
96
|
+
return (
|
|
97
|
+
<span key={key.toString()}>
|
|
98
|
+
{item}
|
|
99
|
+
<br />
|
|
100
|
+
</span>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Object.values(style).map((val) => {
|
|
106
|
+
if (typeof val === 'string' && val.toLowerCase().indexOf('color') !== -1) {
|
|
107
|
+
val = getColor(val);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<TextSpan {...style} {...props}>
|
|
113
|
+
{content}
|
|
114
|
+
</TextSpan>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const Text: React.FC<ComponentTextProps> = TextComponent;
|