1
0

DarkTheme.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Theming\Themes;
  8. use OCA\Theming\ITheme;
  9. class DarkTheme extends DefaultTheme implements ITheme {
  10. protected bool $isDarkVariant = true;
  11. public function getId(): string {
  12. return 'dark';
  13. }
  14. public function getTitle(): string {
  15. return $this->l->t('Dark theme');
  16. }
  17. public function getEnableLabel(): string {
  18. return $this->l->t('Enable dark theme');
  19. }
  20. public function getDescription(): string {
  21. return $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness.');
  22. }
  23. public function getMediaQuery(): string {
  24. return '(prefers-color-scheme: dark)';
  25. }
  26. public function getMeta(): array {
  27. // https://html.spec.whatwg.org/multipage/semantics.html#meta-color-scheme
  28. return [[
  29. 'name' => 'color-scheme',
  30. 'content' => 'dark',
  31. ]];
  32. }
  33. public function getCSSVariables(): array {
  34. $defaultVariables = parent::getCSSVariables();
  35. $colorMainText = '#EBEBEB';
  36. $colorMainBackground = '#171717';
  37. $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
  38. $colorTextMaxcontrast = $this->util->darken($colorMainText, 32);
  39. $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
  40. $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
  41. $colorError = '#FF3333';
  42. $colorWarning = '#FFCC00';
  43. $colorSuccess = '#3B973B';
  44. $colorInfo = '#00AEFF';
  45. return array_merge(
  46. $defaultVariables,
  47. $this->generatePrimaryVariables($colorMainBackground, $colorMainText),
  48. [
  49. '--color-main-text' => $colorMainText,
  50. '--color-main-background' => $colorMainBackground,
  51. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  52. '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .85)',
  53. '--color-background-hover' => $this->util->lighten($colorMainBackground, 4),
  54. '--color-background-dark' => $this->util->lighten($colorMainBackground, 7),
  55. '--color-background-darker' => $this->util->lighten($colorMainBackground, 14),
  56. '--color-placeholder-light' => $this->util->lighten($colorMainBackground, 10),
  57. '--color-placeholder-dark' => $this->util->lighten($colorMainBackground, 20),
  58. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  59. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  60. '--color-text-maxcontrast-background-blur' => $this->util->lighten($colorTextMaxcontrast, 6),
  61. '--color-text-light' => 'var(--color-main-text)', // deprecated
  62. '--color-text-lighter' => 'var(--color-text-maxcontrast)', // deprecated
  63. '--color-error' => $colorError,
  64. '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
  65. '--color-error-hover' => $this->util->lighten($colorError, 10),
  66. '--color-error-text' => $this->util->lighten($colorError, 15),
  67. '--color-warning' => $colorWarning,
  68. '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
  69. '--color-warning-hover' => $this->util->lighten($colorWarning, 10),
  70. '--color-warning-text' => $colorWarning,
  71. '--color-success' => $colorSuccess,
  72. '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
  73. '--color-success-hover' => $this->util->lighten($colorSuccess, 10),
  74. '--color-success-text' => $this->util->lighten($colorSuccess, 15),
  75. '--color-info' => $colorInfo,
  76. '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
  77. '--color-info-hover' => $this->util->lighten($colorInfo, 10),
  78. '--color-info-text' => $colorInfo,
  79. '--color-favorite' => '#ffde00',
  80. // used for the icon loading animation
  81. '--color-loading-light' => '#777',
  82. '--color-loading-dark' => '#CCC',
  83. '--color-box-shadow' => $colorBoxShadow,
  84. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  85. '--color-border' => $this->util->lighten($colorMainBackground, 7),
  86. '--color-border-dark' => $this->util->lighten($colorMainBackground, 14),
  87. '--color-border-maxcontrast' => $this->util->lighten($colorMainBackground, 40),
  88. '--background-invert-if-dark' => 'invert(100%)',
  89. '--background-invert-if-bright' => 'no',
  90. ]
  91. );
  92. }
  93. }