-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from syntaxlexx/theme-mods
Feat: added theme setting options - dark mode, palette
- Loading branch information
Showing
11 changed files
with
1,432 additions
and
1,112 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,125 @@ | ||
<?php | ||
|
||
|
||
namespace Asantibanez\LivewireCharts\Models; | ||
|
||
|
||
trait HasTheme | ||
{ | ||
private $theme; | ||
private $mode; | ||
private $palette; | ||
|
||
/** | ||
* Initialize | ||
*/ | ||
public function initTheme() | ||
{ | ||
$this->theme = $this->defaultTheme(); | ||
} | ||
|
||
/** | ||
* set default theme | ||
* | ||
* @return array $theme | ||
*/ | ||
private function defaultTheme() | ||
{ | ||
return [ | ||
'mode' => 'light', | ||
'palette' => 'palette1' | ||
]; | ||
} | ||
|
||
/** | ||
* set theme mode | ||
* | ||
* @param string $mode | ||
* | ||
* @return $this | ||
*/ | ||
public function setThemeMode(string $mode) | ||
{ | ||
data_set($this->theme, 'mode', $mode); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* set theme mode to dark theme | ||
* | ||
* @return $this | ||
*/ | ||
public function darkMode() | ||
{ | ||
data_set($this->theme, 'mode', 'dark'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* set theme mode to light theme | ||
* | ||
* @return $this | ||
*/ | ||
public function lightMode() | ||
{ | ||
data_set($this->theme, 'mode', 'light'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* set the dark mode option to on or off | ||
* | ||
* @param bool $status = true | ||
* | ||
* @return $this | ||
*/ | ||
public function setDarkMode(bool $status = true) | ||
{ | ||
data_set($this->theme, 'mode', $status ? 'dark' : 'light'); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* set theme pallete | ||
* | ||
* @param string $pallete | ||
* | ||
* @return $this | ||
*/ | ||
public function setThemePalette(string $palette) | ||
{ | ||
data_set($this->theme, 'palette', $palette); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* convert the theme to array | ||
* | ||
* @param string $mode | ||
* | ||
* @return $this | ||
*/ | ||
protected function themeToArray() | ||
{ | ||
return [ | ||
'theme' => $this->theme, | ||
]; | ||
} | ||
|
||
/** | ||
* set theme from array | ||
* | ||
* @param string $mode | ||
* | ||
* @return $this | ||
*/ | ||
protected function themeFromArray($array) | ||
{ | ||
$this->theme = data_get($array, 'theme', $this->defaultTheme()); | ||
} | ||
} |