Add card context

This commit is contained in:
Bill 2021-06-16 01:49:29 -04:00
parent 581ef7c0c6
commit d62c05fb19
5 changed files with 43 additions and 17 deletions

View File

@ -1,27 +1,26 @@
import { FC } from 'react';
import { DraggableWindow } from '../../hooks/draggable-window/DraggableWindow';
import { NitroCardContextProvider } from './context/NitroCardContext';
import { NitroCardViewProps } from './NitroCardView.types';
export const NitroCardView: FC<NitroCardViewProps> = props =>
{
const { className = '', simple = false, disableDrag = false, children = null } = props;
const { className = '', disableDrag = false, simple = false, theme = 'primary', children = null } = props;
if(simple)
{
return (
<NitroCardContextProvider value={ { theme } }>
{ simple &&
<div className={ 'nitro-card d-flex flex-column rounded border shadow overflow-hidden ' + className }>
{ children }
</div>
);
}
return (
</div> }
{ !simple &&
<div className="nitro-card-responsive">
<DraggableWindow handle=".drag-handler" disableDrag= { disableDrag }>
<div className={ 'nitro-card d-flex flex-column rounded border shadow overflow-hidden ' + className }>
{ children }
</div>
</DraggableWindow>
</div>
</div> }
</NitroCardContextProvider>
);
}

View File

@ -1,6 +1,7 @@
export interface NitroCardViewProps
{
className?: string;
simple?: boolean;
disableDrag?: boolean;
simple?: boolean;
theme?: string;
}

View File

@ -0,0 +1,13 @@
import { createContext, FC, useContext } from 'react';
import { INitroCardContext, NitroCardContextProps } from './NitroCardContext.types';
const NitroCardContext = createContext<INitroCardContext>({
theme: null
});
export const NitroCardContextProvider: FC<NitroCardContextProps> = props =>
{
return <NitroCardContext.Provider value={ props.value }>{ props.children }</NitroCardContext.Provider>
}
export const useNitroCardContext = () => useContext(NitroCardContext);

View File

@ -0,0 +1,11 @@
import { ProviderProps } from 'react';
export interface INitroCardContext
{
theme: string;
}
export interface NitroCardContextProps extends ProviderProps<INitroCardContext>
{
}

View File

@ -1,12 +1,14 @@
import { FC } from 'react';
import { useNitroCardContext } from '../context/NitroCardContext';
import { NitroCardHeaderViewProps } from './NitroCardHeaderView.types';
export const NitroCardHeaderView: FC<NitroCardHeaderViewProps> = props =>
{
const { headerText = null, onCloseClick = null } = props;
const { theme } = useNitroCardContext();
return (
<div className="drag-handler container-fluid bg-primary">
<div className={ `drag-handler container-fluid bg-${ theme }` }>
<div className="row nitro-card-header">
<div className="col-10 offset-1 d-flex justify-content-center align-items-center">
<div className="h4 m-0 text-white text-shadow">{ headerText }</div>