File tree Expand file tree Collapse file tree 9 files changed +57
-6
lines changed
components/demo-components/filemosaic-demo
file-mosaic/components/file-mosaic Expand file tree Collapse file tree 9 files changed +57
-6
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ const DemoFileMosaicDarkMode = (props: { card?: boolean }) => {
4848 onDelete = { removeFile }
4949 info
5050 elevation = { elevation as FileCardProps [ "elevation" ] }
51+ darkMode = { false }
5152 />
5253 ) ) }
5354 </ div >
@@ -88,7 +89,7 @@ const DemoFileMosaicDarkMode = (props: { card?: boolean }) => {
8889 flexGrow : 1 ,
8990 } }
9091 >
91- < FileMosaic { ...sampleFileProps } info onDelete = { removeFile } />
92+ < FileMosaic { ...sampleFileProps } info onDelete = { removeFile } darkMode = { false } />
9293 </ div >
9394 < div
9495 style = { {
Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { FilesUiConfig } from "./FilesUiContextType" ;
3+
4+ export const FilesUiContext : React . Context < FilesUiConfig >
5+ = React . createContext ( { } ) ;
Original file line number Diff line number Diff line change 1+ export type FilesUiConfig = {
2+ darkMode ?:boolean ;
3+ }
Original file line number Diff line number Diff line change 1+ import * as React from "react" ;
2+ import { FilesUiContext } from "./FilesUiContext" ;
3+ import { FilesUiConfig } from "./FilesUiContextType" ;
4+
5+ interface FilesUiProviderProps {
6+ children : React . ReactNode ;
7+ config ?: FilesUiConfig ;
8+ }
9+ const FilesUiProvider : React . FC < FilesUiProviderProps > = (
10+ props : FilesUiProviderProps
11+ ) => {
12+ const { children, config } = props ;
13+ return (
14+ < FilesUiContext . Provider value = { config || { } } >
15+ { children }
16+ </ FilesUiContext . Provider >
17+ ) ;
18+ } ;
19+ export default FilesUiProvider ;
Original file line number Diff line number Diff line change 1+ export { default as FilesUiProvider } from "./FilesUiProvider" ;
2+ export * from "./FilesUiProvider" ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import FileMosaicStatus from "../file-mosaic/components/FileMosaicStatus/FileMos
1616import FileCardUploadLayer from "./components/FileCardUploadLayer" ;
1717import { Tooltip } from "../tooltip" ;
1818import DownloadHidden from "../download-hidden/DownloadHidden" ;
19+ import { FilesUiContext } from "../../FilesUiProvider/FilesUiContext" ;
1920
2021const setFinalElevation = ( elevation : string | number ) : number => {
2122 // let finalElevation: number = "";
@@ -83,7 +84,7 @@ const FileCard: React.FC<FileCardProps> = (props: FileCardProps) => {
8384 videoUrl,
8485 info,
8586 backgroundBlurImage = true ,
86- darkMode,
87+ darkMode : darkModeProp ,
8788
8889 alwaysActive = true ,
8990
@@ -107,6 +108,11 @@ const FileCard: React.FC<FileCardProps> = (props: FileCardProps) => {
107108 smartImgFit = "orientation" ,
108109 //} = mergeProps(props, FileCardPropsDefault);
109110 } = props ;
111+ //context
112+ const { darkMode : darkModeContext } = React . useContext ( FilesUiContext ) ;
113+ const darkMode : boolean | undefined =
114+ darkModeProp !== undefined ? darkModeProp : darkModeContext ;
115+
110116
111117 //ref for anchor element
112118 const downloadRef = React . useRef < HTMLAnchorElement > ( null ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import FileMosaicInfoLayer from "../FileMosaicInfoLayer/FileMosaicInfoLayer";
2121import useProgress from "../../hooks/useProgress" ;
2222import DownloadHidden from "../../../download-hidden/DownloadHidden" ;
2323import FileMosaicMainLayer from "../FileMosaicMainLayer.tsx/FileMosaicMainLayer" ;
24+ import { FilesUiContext } from "../../../../FilesUiProvider/FilesUiContext" ;
2425
2526const FileMosaic : React . FC < FileMosaicProps > = ( props : FileMosaicProps ) => {
2627 const {
@@ -47,7 +48,7 @@ const FileMosaic: React.FC<FileMosaicProps> = (props: FileMosaicProps) => {
4748 videoUrl,
4849 info,
4950 backgroundBlurImage = true ,
50- darkMode,
51+ darkMode : darkModeProp ,
5152
5253 alwaysActive = true ,
5354
@@ -68,6 +69,13 @@ const FileMosaic: React.FC<FileMosaicProps> = (props: FileMosaicProps) => {
6869 onRightClick,
6970 smartImgFit = "orientation" ,
7071 } = props ;
72+
73+ //context
74+ const { darkMode : darkModeContext } = React . useContext ( FilesUiContext ) ;
75+ const darkMode : boolean | undefined =
76+ darkModeProp !== undefined ? darkModeProp : darkModeContext ;
77+ console . log ( "globalConfig" , darkMode ) ;
78+
7179 //localizers
7280
7381 //ref for anchor download element
Original file line number Diff line number Diff line change @@ -52,4 +52,8 @@ export type {
5252 UploadResponse ,
5353 UploadConfig ,
5454 ValidateFileResponse
55- } from "./core" ;
55+ } from "./core" ;
56+
57+
58+ export { default as FilesUiProvider } from "./FilesUiProvider/FilesUiProvider" ;
59+ export * from "./FilesUiProvider/FilesUiProvider" ;
Original file line number Diff line number Diff line change 11import { UserContext } from "../contexts/UserContext" ;
22import * as React from "react" ;
33import { UserFilesUi } from "../types/UserFilesUi" ;
4- import { userInitializer , userReducer } from "../reducers/userReducer" ;
4+ import { userInitializer , userReducer } from "../reducers/userReducer" ;
55import { ThemeProvider } from "@emotion/react" ;
66import { MUItheme } from "../../theme/mainTheme" ;
77import { FuiAction } from "../types/FuiAction" ;
8+ import { FilesUiProvider } from "../../files-ui" ;
89
910export const UserProvider = ( props : {
1011 children : React . ReactNode ;
@@ -23,7 +24,9 @@ export const UserProvider = (props: {
2324 return (
2425 < UserContext . Provider value = { [ usuario , dispatch ] } >
2526 < ThemeProvider theme = { MUItheme ( usuario . darkMode ? "dark" : "light" ) } >
26- { children }
27+ < FilesUiProvider config = { { darkMode : usuario . darkMode } } >
28+ { children }
29+ </ FilesUiProvider >
2730 </ ThemeProvider >
2831 </ UserContext . Provider >
2932 ) ;
You can’t perform that action at this time.
0 commit comments