-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mobile] Checks theme colors for validity and fallbacks to defaults (#…
…25440) Loads default colors/gradients when theme colors/gradients are not valid
- Loading branch information
Antonis Lilis
authored
Sep 25, 2020
1 parent
411efbc
commit 51233ab
Showing
5 changed files
with
101 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as transformStyles } from './transform-styles'; | ||
export * from './theme'; |
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,48 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { SETTINGS_DEFAULTS } from '../store/defaults'; | ||
|
||
/** | ||
* Given an array of theme colors checks colors for validity | ||
* | ||
* @param {Array} colors The array of theme colors | ||
* | ||
* @return {Array} The array of valid theme colors or the default colors | ||
*/ | ||
export function validateThemeColors( colors ) { | ||
if ( colors === undefined ) { | ||
colors = SETTINGS_DEFAULTS.colors; | ||
} else { | ||
const validColors = colors.filter( ( c ) => c.color ); | ||
if ( validColors.length === 0 ) { | ||
colors = SETTINGS_DEFAULTS.colors; | ||
} else if ( validColors.length < colors.length ) { | ||
// Filter out invalid colors | ||
colors = validColors; | ||
} | ||
} | ||
return colors; | ||
} | ||
|
||
/** | ||
* Given an array of theme gradients checks gradients for validity | ||
* | ||
* @param {Array} gradients The array of theme gradients | ||
* | ||
* @return {Array} The array of valid theme gradients or the default gradients | ||
*/ | ||
export function validateThemeGradients( gradients ) { | ||
if ( gradients === undefined ) { | ||
gradients = SETTINGS_DEFAULTS.gradients; | ||
} else { | ||
const validGradients = gradients.filter( ( c ) => c.gradient ); | ||
if ( validGradients.length === 0 ) { | ||
gradients = SETTINGS_DEFAULTS.gradients; | ||
} else if ( validGradients.length < gradients.length ) { | ||
// Filter out invalid gradients | ||
gradients = validGradients; | ||
} | ||
} | ||
return gradients; | ||
} |
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