-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): add Theme support (#89)
* feat(theme): add Theme support Add Theme with context API Changes to makeStyles function to accept themeClasses inside useStyles hook Default Theme and types Resolves #88 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com> * docs(tsdoc): add TSDoc comments Add TSDoc comments for the Theme interface and theme props inside Email Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com> Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
- Loading branch information
1 parent
d629549
commit 05544f5
Showing
14 changed files
with
195 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { CSSProperties } from 'react'; | ||
|
||
import type { EmailStyles } from '../Email/Email'; | ||
import type { SectionStyles } from '../Section/Section'; | ||
import type { ColumnStyles } from '../Column/Column'; | ||
import type { ButtonStyles } from '../Button/Button'; | ||
import type { LinkStyles } from '../Link/Link'; | ||
import type { DividerStyles } from '../Divider/Divider'; | ||
import type { TypographyStyles } from '../Typography/Typography'; | ||
import type { ImageStyles } from '../Image/Image'; | ||
import type { PreheaderStyles } from '../Preheader/Preheader'; | ||
import type { QuoteStyles } from '../Quote/Quote'; | ||
|
||
/** | ||
* Interface for the Deafult and Custom Theme. | ||
*/ | ||
export interface ThemeOptions { | ||
/** | ||
* Theme for the `Email` component. | ||
*/ | ||
email?: { [key in EmailStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Section` component. | ||
*/ | ||
section?: { [key in SectionStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Column` component. | ||
*/ | ||
column?: { [key in ColumnStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Button` component. | ||
*/ | ||
button?: { [key in ButtonStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Link` component. | ||
*/ | ||
link?: { [key in LinkStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Divider` component. | ||
*/ | ||
divider?: { [key in DividerStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Typography` component. | ||
*/ | ||
typography?: { [key in TypographyStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Image` component. | ||
*/ | ||
image?: { [key in ImageStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Preheader` component. | ||
*/ | ||
preheader?: { [key in PreheaderStyles]?: CSSProperties }; | ||
/** | ||
* Theme for the `Quote` component. | ||
*/ | ||
quote?: { [key in QuoteStyles]?: CSSProperties }; | ||
} | ||
|
||
/** | ||
* Default theme for the whole layout. | ||
*/ | ||
export const defaultTheme: ThemeOptions = { | ||
email: { root: {} }, | ||
section: { root: {}, body: {}, row: {} }, | ||
column: { root: {} }, | ||
button: { | ||
root: {}, | ||
primary: {}, | ||
secondary: {}, | ||
}, | ||
link: { root: {} }, | ||
divider: { root: {} }, | ||
typography: { root: {} }, | ||
image: { | ||
root: {}, | ||
body: {}, | ||
table: {}, | ||
image: {}, | ||
caption: {}, | ||
imageSection: {}, | ||
captionSection: {}, | ||
imageColumn: {}, | ||
}, | ||
preheader: { root: {} }, | ||
quote: { root: {} }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createContext, ReactNode, useContext } from 'react'; | ||
import type { ThemeOptions } from '../DefaultTheme'; | ||
|
||
const ThemeContext = createContext<ThemeOptions>({}); | ||
|
||
type componentTypes = | ||
| 'email' | ||
| 'section' | ||
| 'column' | ||
| 'button' | ||
| 'link' | ||
| 'divider' | ||
| 'typography' | ||
| 'image' | ||
| 'preheader' | ||
| 'quote'; | ||
|
||
export const useTheme = (componentName: componentTypes) => { | ||
const theme = useContext(ThemeContext); | ||
return theme[componentName]; | ||
}; | ||
|
||
interface ThemeProviderProps { | ||
theme: ThemeOptions; | ||
children?: ReactNode; | ||
} | ||
|
||
export const ThemeProvider = ({ theme, children }: ThemeProviderProps) => { | ||
return <ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.