ferns-ui 0.36.4 → 0.37.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/dist/Banner.d.ts +6 -16
- package/dist/Banner.js +52 -43
- package/dist/Banner.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/useStoredState.d.ts +1 -0
- package/dist/useStoredState.js +33 -0
- package/dist/useStoredState.js.map +1 -0
- package/package.json +55 -56
- package/src/ActionSheet.tsx +1231 -0
- package/src/Avatar.tsx +317 -0
- package/src/Badge.tsx +65 -0
- package/src/Banner.tsx +149 -0
- package/src/BlurBox.native.tsx +40 -0
- package/src/BlurBox.tsx +31 -0
- package/src/Body.tsx +32 -0
- package/src/Box.tsx +308 -0
- package/src/Button.tsx +219 -0
- package/src/Card.tsx +23 -0
- package/src/CheckBox.tsx +118 -0
- package/src/Common.ts +2743 -0
- package/src/Constants.ts +53 -0
- package/src/CustomSelect.tsx +85 -0
- package/src/DateTimeActionSheet.tsx +409 -0
- package/src/DateTimeField.android.tsx +101 -0
- package/src/DateTimeField.ios.tsx +83 -0
- package/src/DateTimeField.tsx +69 -0
- package/src/DecimalRangeActionSheet.tsx +113 -0
- package/src/ErrorBoundary.tsx +37 -0
- package/src/ErrorPage.tsx +44 -0
- package/src/FernsProvider.tsx +21 -0
- package/src/Field.tsx +299 -0
- package/src/FieldWithLabels.tsx +36 -0
- package/src/FlatList.tsx +2 -0
- package/src/Form.tsx +182 -0
- package/src/HeaderButtons.tsx +107 -0
- package/src/Heading.tsx +53 -0
- package/src/HeightActionSheet.tsx +104 -0
- package/src/Hyperlink.tsx +181 -0
- package/src/Icon.tsx +24 -0
- package/src/IconButton.tsx +165 -0
- package/src/Image.tsx +50 -0
- package/src/ImageBackground.tsx +14 -0
- package/src/InfoTooltipButton.tsx +23 -0
- package/src/Layer.tsx +17 -0
- package/src/Link.tsx +17 -0
- package/src/Mask.tsx +21 -0
- package/src/MediaQuery.ts +46 -0
- package/src/Meta.tsx +9 -0
- package/src/Modal.tsx +248 -0
- package/src/ModalSheet.tsx +58 -0
- package/src/NumberPickerActionSheet.tsx +66 -0
- package/src/Page.tsx +133 -0
- package/src/Permissions.ts +44 -0
- package/src/PickerSelect.tsx +553 -0
- package/src/Pill.tsx +24 -0
- package/src/Pog.tsx +87 -0
- package/src/ProgressBar.tsx +55 -0
- package/src/ScrollView.tsx +2 -0
- package/src/SegmentedControl.tsx +102 -0
- package/src/SelectList.tsx +89 -0
- package/src/SideDrawer.tsx +62 -0
- package/src/Spinner.tsx +20 -0
- package/src/SplitPage.native.tsx +160 -0
- package/src/SplitPage.tsx +302 -0
- package/src/Switch.tsx +19 -0
- package/src/Table.tsx +87 -0
- package/src/TableHeader.tsx +36 -0
- package/src/TableHeaderCell.tsx +76 -0
- package/src/TableRow.tsx +87 -0
- package/src/TapToEdit.tsx +221 -0
- package/src/Text.tsx +131 -0
- package/src/TextArea.tsx +16 -0
- package/src/TextField.tsx +401 -0
- package/src/TextFieldNumberActionSheet.tsx +61 -0
- package/src/Toast.tsx +106 -0
- package/src/Tooltip.tsx +269 -0
- package/src/UnifiedScreens.ts +24 -0
- package/src/Unifier.ts +371 -0
- package/src/Utilities.tsx +159 -0
- package/src/WithLabel.tsx +57 -0
- package/src/dayjsExtended.ts +10 -0
- package/src/index.tsx +1347 -0
- package/src/polyfill.d.ts +11 -0
- package/src/tableContext.tsx +80 -0
- package/src/useStoredState.ts +39 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React, {Context, createContext, useContext} from "react";
|
|
2
|
+
|
|
3
|
+
export interface ColumnSortInterface {
|
|
4
|
+
column: number | undefined;
|
|
5
|
+
direction: "asc" | "desc" | undefined;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface TableContextType {
|
|
9
|
+
columns: Array<number | string>;
|
|
10
|
+
hasDrawerContents: boolean;
|
|
11
|
+
sortColumn?: ColumnSortInterface | undefined;
|
|
12
|
+
setSortColumn?: (sort: ColumnSortInterface | undefined) => void;
|
|
13
|
+
stickyHeader?: boolean;
|
|
14
|
+
borderStyle?: "sm" | "none";
|
|
15
|
+
alternateRowBackground?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Props extends TableContextType {
|
|
19
|
+
children: React.ReactElement;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const TableContext: Context<TableContextType> = createContext<TableContextType>({
|
|
23
|
+
columns: [],
|
|
24
|
+
hasDrawerContents: false,
|
|
25
|
+
sortColumn: undefined,
|
|
26
|
+
setSortColumn: () => {},
|
|
27
|
+
stickyHeader: true,
|
|
28
|
+
borderStyle: "sm",
|
|
29
|
+
alternateRowBackground: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const {Provider} = TableContext;
|
|
33
|
+
|
|
34
|
+
export function TableContextProvider({
|
|
35
|
+
children,
|
|
36
|
+
columns,
|
|
37
|
+
hasDrawerContents,
|
|
38
|
+
sortColumn,
|
|
39
|
+
setSortColumn,
|
|
40
|
+
stickyHeader,
|
|
41
|
+
borderStyle,
|
|
42
|
+
alternateRowBackground,
|
|
43
|
+
}: Props): React.ReactElement<typeof Provider> {
|
|
44
|
+
return (
|
|
45
|
+
<Provider
|
|
46
|
+
value={{
|
|
47
|
+
columns,
|
|
48
|
+
alternateRowBackground,
|
|
49
|
+
borderStyle,
|
|
50
|
+
hasDrawerContents,
|
|
51
|
+
sortColumn,
|
|
52
|
+
setSortColumn,
|
|
53
|
+
stickyHeader,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{children}
|
|
57
|
+
</Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function useTableContext(): TableContextType {
|
|
62
|
+
const {
|
|
63
|
+
columns,
|
|
64
|
+
hasDrawerContents,
|
|
65
|
+
setSortColumn,
|
|
66
|
+
sortColumn,
|
|
67
|
+
stickyHeader,
|
|
68
|
+
alternateRowBackground,
|
|
69
|
+
borderStyle,
|
|
70
|
+
} = useContext(TableContext);
|
|
71
|
+
return {
|
|
72
|
+
columns,
|
|
73
|
+
hasDrawerContents,
|
|
74
|
+
setSortColumn,
|
|
75
|
+
sortColumn,
|
|
76
|
+
stickyHeader,
|
|
77
|
+
alternateRowBackground,
|
|
78
|
+
borderStyle,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {useCallback, useEffect, useState} from "react";
|
|
2
|
+
|
|
3
|
+
import {Unifier} from "./Unifier";
|
|
4
|
+
|
|
5
|
+
export const useStoredState = <T>(
|
|
6
|
+
key: string,
|
|
7
|
+
initialValue?: T
|
|
8
|
+
): [T | undefined | null, (value: T | undefined | null) => Promise<void>] => {
|
|
9
|
+
const [state, setState] = useState<T | undefined | null>(initialValue);
|
|
10
|
+
|
|
11
|
+
// Function to fetch data from AsyncStorage
|
|
12
|
+
const fetchData = useCallback(async (): Promise<T | undefined> => {
|
|
13
|
+
try {
|
|
14
|
+
return await Unifier.storage.getItem(key);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error("Error reading data from AsyncStorage:", error);
|
|
17
|
+
return initialValue;
|
|
18
|
+
}
|
|
19
|
+
}, [initialValue, key]);
|
|
20
|
+
|
|
21
|
+
// Fetch data when the component mounts
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
fetchData().then((value) => {
|
|
24
|
+
setState(value);
|
|
25
|
+
});
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
const setAsyncStorageState = async (newValue: T | undefined | null): Promise<void> => {
|
|
30
|
+
try {
|
|
31
|
+
await Unifier.storage.setItem(key, newValue);
|
|
32
|
+
setState(newValue);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Error writing data to AsyncStorage:", error);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return [state, setAsyncStorageState];
|
|
39
|
+
};
|