DarkTheme.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Theming\Themes;
  26. use OCA\Theming\ITheme;
  27. class DarkTheme extends DefaultTheme implements ITheme {
  28. public function getId(): string {
  29. return 'dark';
  30. }
  31. public function getMediaQuery(): string {
  32. return '(prefers-color-scheme: dark)';
  33. }
  34. public function getTitle(): string {
  35. return $this->l->t('Dark theme');
  36. }
  37. public function getEnableLabel(): string {
  38. return $this->l->t('Enable dark theme');
  39. }
  40. public function getDescription(): string {
  41. return $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness.');
  42. }
  43. public function getCSSVariables(): array {
  44. $defaultVariables = parent::getCSSVariables();
  45. $colorMainText = '#D8D8D8';
  46. $colorMainBackground = '#171717';
  47. $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
  48. $colorTextMaxcontrast = $this->util->darken($colorMainText, 30);
  49. $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
  50. $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
  51. $colorError = '#d91812';
  52. $colorWarning = '#c28900';
  53. $colorSuccess = '#2d7b41';
  54. $colorInfo = '#0071ad';
  55. return array_merge(
  56. $defaultVariables,
  57. $this->generatePrimaryVariables($colorMainBackground, $colorMainText),
  58. [
  59. '--color-main-text' => $colorMainText,
  60. '--color-main-background' => $colorMainBackground,
  61. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  62. '--color-scrollbar' => $this->util->lighten($colorMainBackground, 15),
  63. '--color-background-hover' => $this->util->lighten($colorMainBackground, 4),
  64. '--color-background-dark' => $this->util->lighten($colorMainBackground, 7),
  65. '--color-background-darker' => $this->util->lighten($colorMainBackground, 14),
  66. '--color-placeholder-light' => $this->util->lighten($colorMainBackground, 10),
  67. '--color-placeholder-dark' => $this->util->lighten($colorMainBackground, 20),
  68. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  69. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  70. '--color-text-maxcontrast-background-blur' => $this->util->lighten($colorTextMaxcontrast, 2),
  71. '--color-text-light' => $this->util->darken($colorMainText, 10),
  72. '--color-text-lighter' => $this->util->darken($colorMainText, 20),
  73. '--color-error' => $colorError,
  74. '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
  75. '--color-error-hover' => $this->util->mix($colorError, $colorMainBackground, 85),
  76. '--color-error-text' => $this->util->lighten($colorError, 12),
  77. '--color-warning' => $colorWarning,
  78. '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
  79. '--color-warning-hover' => $this->util->mix($colorWarning, $colorMainBackground, 60),
  80. '--color-warning-text' => $colorWarning,
  81. '--color-success' => $colorSuccess,
  82. '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
  83. '--color-success-hover' => $this->util->mix($colorSuccess, $colorMainBackground, 85),
  84. '--color-success-text' => $this->util->lighten($colorSuccess, 6),
  85. '--color-info' => $colorInfo,
  86. '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
  87. '--color-info-hover' => $this->util->mix($colorInfo, $colorMainBackground, 85),
  88. '--color-info-text' => $this->util->lighten($colorInfo, 9),
  89. // used for the icon loading animation
  90. '--color-loading-light' => '#777',
  91. '--color-loading-dark' => '#CCC',
  92. '--color-box-shadow' => $colorBoxShadow,
  93. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  94. '--color-border' => $this->util->lighten($colorMainBackground, 7),
  95. '--color-border-dark' => $this->util->lighten($colorMainBackground, 14),
  96. '--color-border-maxcontrast' => $this->util->lighten($colorMainBackground, 30),
  97. '--background-invert-if-dark' => 'invert(100%)',
  98. '--background-invert-if-bright' => 'no',
  99. ]
  100. );
  101. }
  102. }