@flipova/foundation 2.3.0 → 2.4.0
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 +157 -156
- package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +16 -7
- package/components/ui/accordion/AccordionAnimatedHeight.tsx +3 -15
- package/components/ui/accordion/AccordionAnimatedIcon.tsx +2 -9
- package/components/ui/accordion/AnimatedHeight.tsx +3 -15
- package/components/ui/accordion/AnimatedIcon.tsx +2 -9
- package/components/ui/accordion/MIGRATION_SUMMARY.md +22 -11
- package/components/ui/accordion/USAGE_EXAMPLE.tsx +10 -25
- package/components/ui/accordion/index.tsx +71 -139
- package/components/ui/actionsheet/index.tsx +63 -105
- package/components/ui/alert/index.tsx +20 -50
- package/components/ui/alert-dialog/index.tsx +23 -48
- package/components/ui/avatar/index.tsx +32 -68
- package/components/ui/badge/index.tsx +18 -49
- package/components/ui/bottomsheet/index.tsx +20 -52
- package/components/ui/box/index.tsx +4 -9
- package/components/ui/box/index.web.tsx +3 -9
- package/components/ui/button/index.tsx +73 -109
- package/components/ui/calendar/creator.tsx +69 -30
- package/components/ui/calendar/index.tsx +81 -159
- package/components/ui/calendar/styles.tsx +10 -10
- package/components/ui/card/index.tsx +8 -9
- package/components/ui/card/index.web.tsx +4 -10
- package/components/ui/center/index.tsx +6 -11
- package/components/ui/center/index.web.tsx +3 -9
- package/components/ui/checkbox/index.tsx +46 -107
- package/components/ui/date-time-picker/creator.tsx +14 -1
- package/components/ui/date-time-picker/index.tsx +107 -156
- package/components/ui/date-time-picker/index.web.tsx +11 -33
- package/components/ui/date-time-picker/styles.tsx +5 -5
- package/components/ui/divider/index.tsx +5 -6
- package/components/ui/drawer/index.tsx +108 -128
- package/components/ui/fab/index.tsx +25 -68
- package/components/ui/flat-list/index.tsx +11 -8
- package/components/ui/form-control/index.tsx +49 -90
- package/components/ui/gluestack-ui-provider/index.tsx +4 -18
- package/components/ui/gluestack-ui-provider/index.web.tsx +10 -11
- package/components/ui/gluestack-ui-provider/script.ts +1 -3
- package/components/ui/gluestack-ui-provider/theme-context.ts +2 -2
- package/components/ui/gluestack-ui-provider/useGluestackColors.ts +2 -6
- package/components/ui/grid/index.tsx +128 -165
- package/components/ui/grid/index.web.tsx +17 -19
- package/components/ui/grid/styles.tsx +1 -3
- package/components/ui/heading/index.tsx +146 -169
- package/components/ui/heading/index.web.tsx +7 -28
- package/components/ui/heading/styles.tsx +5 -5
- package/components/ui/hstack/index.tsx +16 -15
- package/components/ui/hstack/index.web.tsx +17 -17
- package/components/ui/hstack/styles.tsx +5 -5
- package/components/ui/icon/index.tsx +95 -486
- package/components/ui/icon/index.web.tsx +79 -439
- package/components/ui/image/index.tsx +13 -18
- package/components/ui/image-viewer/index.tsx +149 -221
- package/components/ui/image-viewer/index.web.tsx +88 -113
- package/components/ui/input/index.tsx +20 -33
- package/components/ui/link/index.tsx +16 -22
- package/components/ui/liquid-glass/index.tsx +19 -25
- package/components/ui/menu/index.tsx +44 -66
- package/components/ui/modal/index.tsx +70 -91
- package/components/ui/popover/index.tsx +102 -121
- package/components/ui/portal/index.tsx +5 -6
- package/components/ui/pressable/index.tsx +5 -9
- package/components/ui/progress/index.tsx +4 -11
- package/components/ui/radio/index.tsx +47 -83
- package/components/ui/select/index.tsx +38 -59
- package/components/ui/select/select-actionsheet.tsx +61 -108
- package/components/ui/skeleton/index.tsx +22 -43
- package/components/ui/skeleton/index.web.tsx +63 -75
- package/components/ui/slider/index.tsx +36 -56
- package/components/ui/spinner/index.tsx +1 -10
- package/components/ui/switch/index.tsx +6 -13
- package/components/ui/table/index.tsx +39 -102
- package/components/ui/table/index.web.tsx +41 -79
- package/components/ui/tabs/TabsAnimatedIndicator.tsx +10 -38
- package/components/ui/tabs/creator.tsx +32 -24
- package/components/ui/tabs/index.tsx +253 -309
- package/components/ui/text/index.tsx +23 -37
- package/components/ui/text/index.web.tsx +33 -35
- package/components/ui/text/styles.tsx +5 -5
- package/components/ui/textarea/index.tsx +24 -38
- package/components/ui/toast/index.tsx +47 -52
- package/components/ui/tooltip/index.tsx +12 -28
- package/components/ui/vstack/index.tsx +17 -17
- package/components/ui/vstack/index.web.tsx +17 -17
- package/components/ui/vstack/styles.tsx +5 -5
- package/design/tools/design.js +15 -12
- package/design/tools/npm.js +4 -3
- package/dist/{chunk-B277QSR5.mjs → chunk-2R66P5X5.mjs} +1816 -3124
- package/dist/chunk-2R66P5X5.mjs.map +1 -0
- package/dist/{chunk-GD37RFBR.js → chunk-LCTFQJZM.js} +1816 -3124
- package/dist/chunk-LCTFQJZM.js.map +1 -0
- package/dist/index.js +294 -294
- package/dist/index.mjs +1 -1
- package/dist/ui/index.js +294 -294
- package/dist/ui/index.mjs +1 -1
- package/package.json +12 -7
- package/dist/chunk-B277QSR5.mjs.map +0 -1
- package/dist/chunk-GD37RFBR.js.map +0 -1
|
@@ -10,13 +10,7 @@ import {
|
|
|
10
10
|
} from './useGluestackColors';
|
|
11
11
|
import { ThemeContext, MountedThemeContext, resolveThemeId } from './theme-context';
|
|
12
12
|
|
|
13
|
-
export {
|
|
14
|
-
ThemeContext,
|
|
15
|
-
MountedThemeContext,
|
|
16
|
-
useMountedColors,
|
|
17
|
-
useMountedTheme,
|
|
18
|
-
resolveThemeId,
|
|
19
|
-
} from './theme-context';
|
|
13
|
+
export { ThemeContext, MountedThemeContext, useMountedColors, useMountedTheme, resolveThemeId } from './theme-context';
|
|
20
14
|
|
|
21
15
|
export type ModeType = 'light' | 'dark' | 'system';
|
|
22
16
|
|
|
@@ -67,11 +61,7 @@ export function createGluestackUIProvider(theme: GluestackTheme) {
|
|
|
67
61
|
const variantMap = theme.variants;
|
|
68
62
|
const themeIds = Object.keys(vars);
|
|
69
63
|
|
|
70
|
-
return function ThemedProvider({
|
|
71
|
-
mode = 'light',
|
|
72
|
-
variant,
|
|
73
|
-
...props
|
|
74
|
-
}: GluestackUIProviderProps) {
|
|
64
|
+
return function ThemedProvider({ mode = 'light', variant, ...props }: GluestackUIProviderProps) {
|
|
75
65
|
const { colorScheme, setColorScheme } = useColorScheme();
|
|
76
66
|
|
|
77
67
|
useEffect(() => {
|
|
@@ -82,13 +72,9 @@ export function createGluestackUIProvider(theme: GluestackTheme) {
|
|
|
82
72
|
// Nativewind only reports light/dark, so `system` resolves through it while a
|
|
83
73
|
// named mode is taken as-is; either way the VARIANT picks the pair. Falling
|
|
84
74
|
// back to the mode keeps a theme set without variants working untouched.
|
|
85
|
-
const resolvedMode =
|
|
86
|
-
mode === 'system' ? colorScheme ?? 'light' : mode;
|
|
75
|
+
const resolvedMode = mode === 'system' ? (colorScheme ?? 'light') : mode;
|
|
87
76
|
const themeId = resolveThemeId(variantMap, variant, resolvedMode);
|
|
88
|
-
const mountedTheme = React.useMemo(
|
|
89
|
-
() => ({ themeId, themeIds }),
|
|
90
|
-
[themeId, themeIds]
|
|
91
|
-
);
|
|
77
|
+
const mountedTheme = React.useMemo(() => ({ themeId, themeIds }), [themeId, themeIds]);
|
|
92
78
|
|
|
93
79
|
return (
|
|
94
80
|
<View
|
|
@@ -20,8 +20,7 @@ const createStyle = (styleTagId: string) => {
|
|
|
20
20
|
return style;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export const useSafeLayoutEffect =
|
|
24
|
-
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
23
|
+
export const useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
25
24
|
|
|
26
25
|
export function GluestackUIProvider({
|
|
27
26
|
mode = 'light',
|
|
@@ -41,15 +40,12 @@ export function GluestackUIProvider({
|
|
|
41
40
|
let cssVariablesWithMode = ``;
|
|
42
41
|
let variantCss = ``;
|
|
43
42
|
themeIds.forEach((configKey) => {
|
|
44
|
-
const cssVariables = Object.keys(
|
|
45
|
-
config[configKey as keyof typeof config]
|
|
46
|
-
).reduce((acc: string, curr: string) => {
|
|
43
|
+
const cssVariables = Object.keys(config[configKey as keyof typeof config]).reduce((acc: string, curr: string) => {
|
|
47
44
|
acc += `${curr}:${config[configKey as keyof typeof config][curr]}; `;
|
|
48
45
|
return acc;
|
|
49
46
|
}, '');
|
|
50
47
|
if (isDefaultId(configKey)) {
|
|
51
|
-
cssVariablesWithMode +=
|
|
52
|
-
configKey === 'dark' ? `\n .dark {\n ` : `\n:root {\n`;
|
|
48
|
+
cssVariablesWithMode += configKey === 'dark' ? `\n .dark {\n ` : `\n:root {\n`;
|
|
53
49
|
cssVariablesWithMode += `${cssVariables} \n}`;
|
|
54
50
|
} else {
|
|
55
51
|
variantCss += `\n[data-theme='${configKey}'] {\n${cssVariables} \n}`;
|
|
@@ -59,10 +55,13 @@ export function GluestackUIProvider({
|
|
|
59
55
|
|
|
60
56
|
setFlushStyles(cssVariablesWithMode);
|
|
61
57
|
|
|
62
|
-
const handleMediaQuery = React.useCallback(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
const handleMediaQuery = React.useCallback(
|
|
59
|
+
(e: MediaQueryListEvent) => {
|
|
60
|
+
const resolved = e.matches ? 'dark' : 'light';
|
|
61
|
+
script(resolved, resolveThemeId(variants, variant, resolved), resolved);
|
|
62
|
+
},
|
|
63
|
+
[variant],
|
|
64
|
+
);
|
|
66
65
|
|
|
67
66
|
// The script keeps the light/dark class AND the variant class/attribute in step.
|
|
68
67
|
const activeMode = mode === 'system' ? 'light' : mode;
|
|
@@ -2,9 +2,7 @@ export const script = (mode: string, themeId: string, modeClass: string) => {
|
|
|
2
2
|
const documentElement = document.documentElement;
|
|
3
3
|
|
|
4
4
|
function getSystemColorMode() {
|
|
5
|
-
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
6
|
-
? 'dark'
|
|
7
|
-
: 'light';
|
|
5
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
8
6
|
}
|
|
9
7
|
|
|
10
8
|
try {
|
|
@@ -44,8 +44,8 @@ export const useMountedTheme = (): MountedTheme | null => useContext(MountedThem
|
|
|
44
44
|
export function resolveThemeId(
|
|
45
45
|
variants: Record<string, Record<string, string>> | undefined,
|
|
46
46
|
variant: string | undefined,
|
|
47
|
-
mode: string
|
|
47
|
+
mode: string,
|
|
48
48
|
): string {
|
|
49
49
|
const mapped = variant ? variants?.[variant]?.[mode] : undefined;
|
|
50
50
|
return mapped ?? mode;
|
|
51
|
-
}
|
|
51
|
+
}
|
|
@@ -24,8 +24,7 @@ function rgbToHex(rgbString: string): string {
|
|
|
24
24
|
return isNaN(num) ? 0 : num;
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
const toHex = (n: number) =>
|
|
28
|
-
Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
|
|
27
|
+
const toHex = (n: number) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
|
|
29
28
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -52,10 +51,7 @@ export function useGluestackColors(): Record<string, string> {
|
|
|
52
51
|
// the active id is only known at runtime.
|
|
53
52
|
const palettes = theme as Record<string, Record<string, string>>;
|
|
54
53
|
const palette =
|
|
55
|
-
palettes[mounted?.themeId ?? ''] ??
|
|
56
|
-
palettes[colorScheme || 'light'] ??
|
|
57
|
-
palettes[mounted?.themeIds[0] ?? ''] ??
|
|
58
|
-
{};
|
|
54
|
+
palettes[mounted?.themeId ?? ''] ?? palettes[colorScheme || 'light'] ?? palettes[mounted?.themeIds[0] ?? ''] ?? {};
|
|
59
55
|
|
|
60
56
|
// Dynamically convert all CSS variables to camelCase hex colors
|
|
61
57
|
const result: Record<string, string> = {};
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useState,
|
|
3
|
-
createContext,
|
|
4
|
-
useContext,
|
|
5
|
-
useMemo,
|
|
6
|
-
forwardRef,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, { useState, createContext, useContext, useMemo, forwardRef } from 'react';
|
|
8
2
|
import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils';
|
|
9
3
|
import { View, Dimensions, Platform, ViewProps } from 'react-native';
|
|
10
4
|
import { gridStyle, gridItemStyle } from './styles';
|
|
11
5
|
import { cssInterop } from 'nativewind';
|
|
12
|
-
import {
|
|
13
|
-
useBreakpointValue,
|
|
14
|
-
getBreakPointValue,
|
|
15
|
-
} from '@gluestack-ui/utils/hooks';
|
|
6
|
+
import { useBreakpointValue, getBreakPointValue } from '@gluestack-ui/utils/hooks';
|
|
16
7
|
const { width: DEVICE_WIDTH } = Dimensions.get('window');
|
|
17
8
|
const GridContext = createContext<any>({});
|
|
18
9
|
function arrangeChildrenIntoRows({
|
|
@@ -40,9 +31,7 @@ function arrangeChildrenIntoRows({
|
|
|
40
31
|
// if current row is not full, add colSpan to current row
|
|
41
32
|
currentRowTotalColSpan += colSpan;
|
|
42
33
|
}
|
|
43
|
-
rowItemsCount[currentRow] = rowItemsCount[currentRow]
|
|
44
|
-
? [...rowItemsCount[currentRow], i]
|
|
45
|
-
: [i];
|
|
34
|
+
rowItemsCount[currentRow] = rowItemsCount[currentRow] ? [...rowItemsCount[currentRow], i] : [i];
|
|
46
35
|
}
|
|
47
36
|
return rowItemsCount;
|
|
48
37
|
}
|
|
@@ -64,11 +53,7 @@ function generateResponsiveNumColumns({ gridClass }: { gridClass: string }) {
|
|
|
64
53
|
});
|
|
65
54
|
return result;
|
|
66
55
|
}
|
|
67
|
-
function generateResponsiveColSpans({
|
|
68
|
-
gridItemClassName,
|
|
69
|
-
}: {
|
|
70
|
-
gridItemClassName: string;
|
|
71
|
-
}) {
|
|
56
|
+
function generateResponsiveColSpans({ gridItemClassName }: { gridItemClassName: string }) {
|
|
72
57
|
const gridClassNamePattern = /\b(?:\w+:)?col-span-?\d+\b/g;
|
|
73
58
|
const colSpan: any = gridItemClassName?.match(gridClassNamePattern);
|
|
74
59
|
if (!colSpan) {
|
|
@@ -104,83 +89,79 @@ type IGridProps = ViewProps &
|
|
|
104
89
|
className: string;
|
|
105
90
|
};
|
|
106
91
|
};
|
|
107
|
-
const Grid = forwardRef<React.ComponentRef<typeof View>, IGridProps>(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return responsiveNumColumns;
|
|
124
|
-
}
|
|
125
|
-
return colSpan;
|
|
126
|
-
});
|
|
127
|
-
const childrenArray = React.Children.toArray(children);
|
|
128
|
-
const rowItemsCount = arrangeChildrenIntoRows({
|
|
129
|
-
childrenArray,
|
|
130
|
-
colSpanArr,
|
|
131
|
-
numColumns: responsiveNumColumns,
|
|
132
|
-
});
|
|
133
|
-
return rowItemsCount;
|
|
134
|
-
}, [responsiveNumColumns, children]);
|
|
135
|
-
const childrenWithProps = React.Children.map(children, (child, index) => {
|
|
136
|
-
if (React.isValidElement(child)) {
|
|
137
|
-
return React.cloneElement(child, { key: index, index: index } as any);
|
|
92
|
+
const Grid = forwardRef<React.ComponentRef<typeof View>, IGridProps>(function Grid(
|
|
93
|
+
{ className, _extra, children, ...props },
|
|
94
|
+
ref,
|
|
95
|
+
) {
|
|
96
|
+
const [calculatedWidth, setCalculatedWidth] = useState<number | null>(null);
|
|
97
|
+
const gridClass = _extra?.className;
|
|
98
|
+
const obj = generateResponsiveNumColumns({ gridClass });
|
|
99
|
+
const responsiveNumColumns: any = useBreakpointValue(obj);
|
|
100
|
+
const itemsPerRow = useMemo(() => {
|
|
101
|
+
// get the colSpan of each child
|
|
102
|
+
const colSpanArr = React.Children.map(children, (child: any) => {
|
|
103
|
+
const gridItemClassName = child?.props?._extra?.className;
|
|
104
|
+
const colSpan2 = getBreakPointValue(generateResponsiveColSpans({ gridItemClassName }), DEVICE_WIDTH);
|
|
105
|
+
const colSpan = colSpan2 ? colSpan2 : 1;
|
|
106
|
+
if (colSpan > responsiveNumColumns) {
|
|
107
|
+
return responsiveNumColumns;
|
|
138
108
|
}
|
|
139
|
-
return
|
|
109
|
+
return colSpan;
|
|
140
110
|
});
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
111
|
+
const childrenArray = React.Children.toArray(children);
|
|
112
|
+
const rowItemsCount = arrangeChildrenIntoRows({
|
|
113
|
+
childrenArray,
|
|
114
|
+
colSpanArr,
|
|
115
|
+
numColumns: responsiveNumColumns,
|
|
116
|
+
});
|
|
117
|
+
return rowItemsCount;
|
|
118
|
+
}, [responsiveNumColumns, children]);
|
|
119
|
+
const childrenWithProps = React.Children.map(children, (child, index) => {
|
|
120
|
+
if (React.isValidElement(child)) {
|
|
121
|
+
return React.cloneElement(child, { key: index, index: index } as any);
|
|
122
|
+
}
|
|
123
|
+
return child;
|
|
124
|
+
});
|
|
125
|
+
const gridClassMerged = `${Platform.select({
|
|
126
|
+
web: gridClass ?? '',
|
|
127
|
+
})}`;
|
|
128
|
+
const contextValue = useMemo(() => {
|
|
129
|
+
return {
|
|
130
|
+
calculatedWidth,
|
|
131
|
+
numColumns: responsiveNumColumns,
|
|
132
|
+
itemsPerRow,
|
|
133
|
+
flexDirection: props?.flexDirection || 'row',
|
|
134
|
+
gap: props?.gap || 0,
|
|
135
|
+
columnGap: props?.columnGap || 0,
|
|
136
|
+
};
|
|
137
|
+
}, [calculatedWidth, itemsPerRow, responsiveNumColumns, props]);
|
|
138
|
+
const borderLeftWidth = props?.borderLeftWidth || props?.borderWidth || 0;
|
|
139
|
+
const borderRightWidth = props?.borderRightWidth || props?.borderWidth || 0;
|
|
140
|
+
const borderWidthToSubtract = borderLeftWidth + borderRightWidth;
|
|
141
|
+
return (
|
|
142
|
+
<GridContext.Provider value={contextValue}>
|
|
143
|
+
<View
|
|
144
|
+
ref={ref}
|
|
145
|
+
className={gridStyle({
|
|
146
|
+
class: className + ' ' + gridClassMerged,
|
|
147
|
+
})}
|
|
148
|
+
onLayout={(event) => {
|
|
149
|
+
const paddingLeftToSubtract = props?.paddingStart || props?.paddingLeft || props?.padding || 0;
|
|
150
|
+
const paddingRightToSubtract = props?.paddingEnd || props?.paddingRight || props?.padding || 0;
|
|
151
|
+
const gridWidth =
|
|
152
|
+
Math.floor(event.nativeEvent.layout.width) -
|
|
153
|
+
paddingLeftToSubtract -
|
|
154
|
+
paddingRightToSubtract -
|
|
155
|
+
borderWidthToSubtract;
|
|
156
|
+
setCalculatedWidth(gridWidth);
|
|
157
|
+
}}
|
|
158
|
+
{...props}
|
|
159
|
+
>
|
|
160
|
+
{calculatedWidth && childrenWithProps}
|
|
161
|
+
</View>
|
|
162
|
+
</GridContext.Provider>
|
|
163
|
+
);
|
|
164
|
+
});
|
|
184
165
|
cssInterop(Grid, {
|
|
185
166
|
className: {
|
|
186
167
|
target: 'style',
|
|
@@ -207,77 +188,59 @@ type IGridItemProps = ViewProps &
|
|
|
207
188
|
className: string;
|
|
208
189
|
};
|
|
209
190
|
};
|
|
210
|
-
const GridItem = forwardRef<React.ComponentRef<typeof View>, IGridItemProps>(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
class: className,
|
|
264
|
-
})}
|
|
265
|
-
{...props}
|
|
266
|
-
style={[
|
|
267
|
-
{
|
|
268
|
-
width:
|
|
269
|
-
typeof flexBasisValue === 'number' ? flexBasisValue : undefined,
|
|
270
|
-
flexBasis:
|
|
271
|
-
typeof flexBasisValue === 'string' ? flexBasisValue : undefined,
|
|
272
|
-
flexShrink: 0,
|
|
273
|
-
flexGrow: 0,
|
|
274
|
-
},
|
|
275
|
-
props.style,
|
|
276
|
-
]}
|
|
277
|
-
/>
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
);
|
|
191
|
+
const GridItem = forwardRef<React.ComponentRef<typeof View>, IGridItemProps>(function GridItem(
|
|
192
|
+
{ className, _extra, ...props },
|
|
193
|
+
ref,
|
|
194
|
+
) {
|
|
195
|
+
const { calculatedWidth, numColumns, itemsPerRow, flexDirection, gap, columnGap } = useContext(GridContext);
|
|
196
|
+
const gridItemClass = _extra?.className;
|
|
197
|
+
const responsiveColSpan = (useBreakpointValue(generateResponsiveColSpans({ gridItemClassName: gridItemClass })) ??
|
|
198
|
+
1) as number;
|
|
199
|
+
const flexBasisValue = useMemo(() => {
|
|
200
|
+
if (!calculatedWidth || !numColumns || responsiveColSpan <= 0) {
|
|
201
|
+
return 'auto';
|
|
202
|
+
}
|
|
203
|
+
if (flexDirection?.includes('column')) {
|
|
204
|
+
return 'auto';
|
|
205
|
+
}
|
|
206
|
+
// Find which row this item is in
|
|
207
|
+
const row = Object.keys(itemsPerRow).find((key) => {
|
|
208
|
+
return itemsPerRow[key].includes(props?.index);
|
|
209
|
+
});
|
|
210
|
+
if (!row) {
|
|
211
|
+
return 'auto';
|
|
212
|
+
}
|
|
213
|
+
const rowColsCount = itemsPerRow[row]?.length || 1;
|
|
214
|
+
const space = columnGap || gap || 0;
|
|
215
|
+
// Calculate available width accounting for gaps
|
|
216
|
+
const totalGapWidth = space * (rowColsCount - 1);
|
|
217
|
+
const availableWidth = calculatedWidth - totalGapWidth;
|
|
218
|
+
// Calculate the width for this item based on its column span
|
|
219
|
+
const itemWidth = (availableWidth * responsiveColSpan) / numColumns;
|
|
220
|
+
// Return the width directly instead of percentage for better native compatibility
|
|
221
|
+
return Math.max(0, Math.floor(itemWidth));
|
|
222
|
+
}, [calculatedWidth, responsiveColSpan, numColumns, columnGap, gap, flexDirection, itemsPerRow, props?.index]);
|
|
223
|
+
return (
|
|
224
|
+
<View
|
|
225
|
+
ref={ref}
|
|
226
|
+
// @ts-expect-error : internal implementation for r-19/react-native-web
|
|
227
|
+
gridItemClass={gridItemClass}
|
|
228
|
+
className={gridItemStyle({
|
|
229
|
+
class: className,
|
|
230
|
+
})}
|
|
231
|
+
{...props}
|
|
232
|
+
style={[
|
|
233
|
+
{
|
|
234
|
+
width: typeof flexBasisValue === 'number' ? flexBasisValue : undefined,
|
|
235
|
+
flexBasis: typeof flexBasisValue === 'string' ? flexBasisValue : undefined,
|
|
236
|
+
flexShrink: 0,
|
|
237
|
+
flexGrow: 0,
|
|
238
|
+
},
|
|
239
|
+
props.style,
|
|
240
|
+
]}
|
|
241
|
+
/>
|
|
242
|
+
);
|
|
243
|
+
});
|
|
281
244
|
Grid.displayName = 'Grid';
|
|
282
245
|
GridItem.displayName = 'GridItem';
|
|
283
246
|
export { Grid, GridItem };
|
|
@@ -19,10 +19,7 @@ type IGridProps = React.ComponentPropsWithoutRef<'div'> &
|
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const Grid = React.forwardRef<HTMLDivElement, IGridProps>(function Grid(
|
|
23
|
-
{ className, _extra, ...props },
|
|
24
|
-
ref
|
|
25
|
-
) {
|
|
22
|
+
const Grid = React.forwardRef<HTMLDivElement, IGridProps>(function Grid({ className, _extra, ...props }, ref) {
|
|
26
23
|
const gridClass = _extra?.className;
|
|
27
24
|
const finalGridClass = gridClass ?? '';
|
|
28
25
|
return (
|
|
@@ -43,22 +40,23 @@ type IGridItemProps = React.ComponentPropsWithoutRef<'div'> &
|
|
|
43
40
|
className: string;
|
|
44
41
|
};
|
|
45
42
|
};
|
|
46
|
-
const GridItem = React.forwardRef<HTMLDivElement, IGridItemProps>(
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const GridItem = React.forwardRef<HTMLDivElement, IGridItemProps>(function GridItem(
|
|
44
|
+
{ className, _extra, ...props },
|
|
45
|
+
ref,
|
|
46
|
+
) {
|
|
47
|
+
const gridItemClass = _extra?.className;
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
49
|
+
const finalGridItemClass = gridItemClass ?? '';
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
ref={ref}
|
|
53
|
+
className={gridItemStyle({
|
|
54
|
+
class: className + ' ' + finalGridItemClass,
|
|
55
|
+
})}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
});
|
|
62
60
|
|
|
63
61
|
Grid.displayName = 'Grid';
|
|
64
62
|
GridItem.displayName = 'GridItem';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { tva } from '@gluestack-ui/utils/nativewind-utils';
|
|
2
2
|
import { isWeb } from '@gluestack-ui/utils/nativewind-utils';
|
|
3
3
|
|
|
4
|
-
const gridBaseStyle = isWeb
|
|
5
|
-
? 'grid grid-cols-12'
|
|
6
|
-
: 'box-border flex-row flex-wrap justify-start';
|
|
4
|
+
const gridBaseStyle = isWeb ? 'grid grid-cols-12' : 'box-border flex-row flex-wrap justify-start';
|
|
7
5
|
const gridItemBaseStyle = isWeb ? 'w-auto col-span-1' : '';
|
|
8
6
|
|
|
9
7
|
export const gridStyle = tva({
|