mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14:40:50 +01:00
Add card context
This commit is contained in:
parent
581ef7c0c6
commit
d62c05fb19
@ -1,27 +1,26 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { DraggableWindow } from '../../hooks/draggable-window/DraggableWindow';
|
import { DraggableWindow } from '../../hooks/draggable-window/DraggableWindow';
|
||||||
|
import { NitroCardContextProvider } from './context/NitroCardContext';
|
||||||
import { NitroCardViewProps } from './NitroCardView.types';
|
import { NitroCardViewProps } from './NitroCardView.types';
|
||||||
|
|
||||||
export const NitroCardView: FC<NitroCardViewProps> = props =>
|
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 (
|
|
||||||
<div className={ 'nitro-card d-flex flex-column rounded border shadow overflow-hidden ' + className }>
|
|
||||||
{ children }
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="nitro-card-responsive">
|
<NitroCardContextProvider value={ { theme } }>
|
||||||
<DraggableWindow handle=".drag-handler" disableDrag= { disableDrag }>
|
{ simple &&
|
||||||
<div className={ 'nitro-card d-flex flex-column rounded border shadow overflow-hidden ' + className }>
|
<div className={ 'nitro-card d-flex flex-column rounded border shadow overflow-hidden ' + className }>
|
||||||
{ children }
|
{ children }
|
||||||
</div>
|
</div> }
|
||||||
</DraggableWindow>
|
{ !simple &&
|
||||||
</div>
|
<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> }
|
||||||
|
</NitroCardContextProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export interface NitroCardViewProps
|
export interface NitroCardViewProps
|
||||||
{
|
{
|
||||||
className?: string;
|
className?: string;
|
||||||
simple?: boolean;
|
|
||||||
disableDrag?: boolean;
|
disableDrag?: boolean;
|
||||||
|
simple?: boolean;
|
||||||
|
theme?: string;
|
||||||
}
|
}
|
||||||
|
13
src/layout/card/context/NitroCardContext.tsx
Normal file
13
src/layout/card/context/NitroCardContext.tsx
Normal 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);
|
11
src/layout/card/context/NitroCardContext.types.ts
Normal file
11
src/layout/card/context/NitroCardContext.types.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { ProviderProps } from 'react';
|
||||||
|
|
||||||
|
export interface INitroCardContext
|
||||||
|
{
|
||||||
|
theme: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NitroCardContextProps extends ProviderProps<INitroCardContext>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,14 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
|
import { useNitroCardContext } from '../context/NitroCardContext';
|
||||||
import { NitroCardHeaderViewProps } from './NitroCardHeaderView.types';
|
import { NitroCardHeaderViewProps } from './NitroCardHeaderView.types';
|
||||||
|
|
||||||
export const NitroCardHeaderView: FC<NitroCardHeaderViewProps> = props =>
|
export const NitroCardHeaderView: FC<NitroCardHeaderViewProps> = props =>
|
||||||
{
|
{
|
||||||
const { headerText = null, onCloseClick = null } = props;
|
const { headerText = null, onCloseClick = null } = props;
|
||||||
|
const { theme } = useNitroCardContext();
|
||||||
|
|
||||||
return (
|
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="row nitro-card-header">
|
||||||
<div className="col-10 offset-1 d-flex justify-content-center align-items-center">
|
<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>
|
<div className="h4 m-0 text-white text-shadow">{ headerText }</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user