-
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.
add makeStyles which exposes a useStyles hook with mergeDeep function resolves #20 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
- Loading branch information
1 parent
1042629
commit 9fe1501
Showing
3 changed files
with
49 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './components/Email'; | ||
export * from './utils'; |
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,38 @@ | ||
import { CSSProperties } from 'react'; | ||
import { CSSClasses } from './stylings'; | ||
|
||
const isObject = (item: CSSClasses | CSSProperties): boolean => { | ||
return item && typeof item === 'object' && !Array.isArray(item); | ||
}; | ||
|
||
export const mergeDeep = (target: CSSClasses, ...sources: CSSClasses[]): CSSClasses => { | ||
if (!sources.length) return target; | ||
const source: CSSClasses = sources.shift() as CSSClasses; | ||
|
||
if (isObject(target) && isObject(source)) { | ||
for (const key in source) { | ||
if (isObject(source[key])) { | ||
if (!target[key]) { | ||
Object.assign(target, { | ||
[key]: source[key], | ||
}); | ||
} else { | ||
const targetObject = { ...target[key] }; | ||
const srcObject = { ...source[key] }; | ||
const mergedObject = Object.assign(targetObject, srcObject); | ||
target[key] = mergedObject; | ||
} | ||
} else { | ||
Object.assign(target, { | ||
[key]: source[key], | ||
}); | ||
} | ||
} | ||
} | ||
|
||
if (sources.length) { | ||
return mergeDeep(target, ...sources); | ||
} else { | ||
return target; | ||
} | ||
}; |
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