DefaultTheme.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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\ImageManager;
  9. use OCA\Theming\ITheme;
  10. use OCA\Theming\ThemingDefaults;
  11. use OCA\Theming\Util;
  12. use OCP\App\IAppManager;
  13. use OCP\IConfig;
  14. use OCP\IL10N;
  15. use OCP\IURLGenerator;
  16. use OCP\IUserSession;
  17. class DefaultTheme implements ITheme {
  18. use CommonThemeTrait;
  19. public Util $util;
  20. public ThemingDefaults $themingDefaults;
  21. public IUserSession $userSession;
  22. public IURLGenerator $urlGenerator;
  23. public ImageManager $imageManager;
  24. public IConfig $config;
  25. public IL10N $l;
  26. public IAppManager $appManager;
  27. public string $defaultPrimaryColor;
  28. public string $primaryColor;
  29. public function __construct(Util $util,
  30. ThemingDefaults $themingDefaults,
  31. IUserSession $userSession,
  32. IURLGenerator $urlGenerator,
  33. ImageManager $imageManager,
  34. IConfig $config,
  35. IL10N $l,
  36. IAppManager $appManager) {
  37. $this->util = $util;
  38. $this->themingDefaults = $themingDefaults;
  39. $this->userSession = $userSession;
  40. $this->urlGenerator = $urlGenerator;
  41. $this->imageManager = $imageManager;
  42. $this->config = $config;
  43. $this->l = $l;
  44. $this->appManager = $appManager;
  45. $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
  46. $this->primaryColor = $this->themingDefaults->getColorPrimary();
  47. }
  48. public function getId(): string {
  49. return 'default';
  50. }
  51. public function getType(): int {
  52. return ITheme::TYPE_THEME;
  53. }
  54. public function getTitle(): string {
  55. return $this->l->t('System default theme');
  56. }
  57. public function getEnableLabel(): string {
  58. return $this->l->t('Enable the system default');
  59. }
  60. public function getDescription(): string {
  61. return $this->l->t('Using the default system appearance.');
  62. }
  63. public function getMediaQuery(): string {
  64. return '';
  65. }
  66. public function getMeta(): array {
  67. return [];
  68. }
  69. public function getCSSVariables(): array {
  70. $colorMainText = '#222222';
  71. $colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText));
  72. // Color that still provides enough contrast for text, so we need a ratio of 4.5:1 on main background AND hover
  73. $colorTextMaxcontrast = '#6b6b6b'; // 4.5 : 1 for hover background and background dark
  74. $colorMainBackground = '#ffffff';
  75. $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
  76. $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
  77. $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
  78. $colorError = '#DB0606';
  79. $colorWarning = '#A37200';
  80. $colorSuccess = '#2d7b41';
  81. $colorInfo = '#0071ad';
  82. $variables = [
  83. '--color-main-background' => $colorMainBackground,
  84. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  85. '--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
  86. '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
  87. '--filter-background-blur' => 'blur(25px)',
  88. // to use like this: background-image: linear-gradient(0, var('--gradient-main-background));
  89. '--gradient-main-background' => 'var(--color-main-background) 0%, var(--color-main-background-translucent) 85%, transparent 100%',
  90. // used for different active/hover/focus/disabled states
  91. '--color-background-hover' => $this->util->darken($colorMainBackground, 4),
  92. '--color-background-dark' => $this->util->darken($colorMainBackground, 7),
  93. '--color-background-darker' => $this->util->darken($colorMainBackground, 14),
  94. '--color-placeholder-light' => $this->util->darken($colorMainBackground, 10),
  95. '--color-placeholder-dark' => $this->util->darken($colorMainBackground, 20),
  96. // max contrast for WCAG compliance
  97. '--color-main-text' => $colorMainText,
  98. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  99. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  100. '--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
  101. '--color-text-light' => 'var(--color-main-text)', // deprecated
  102. '--color-text-lighter' => 'var(--color-text-maxcontrast)', // deprecated
  103. '--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',
  104. // error/warning/success/info feedback colours
  105. '--color-error' => $colorError,
  106. '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
  107. '--color-error-hover' => $this->util->mix($colorError, $colorMainBackground, 75),
  108. '--color-error-text' => $this->util->darken($colorError, 5),
  109. '--color-warning' => $colorWarning,
  110. '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
  111. '--color-warning-hover' => $this->util->darken($colorWarning, 5),
  112. '--color-warning-text' => $this->util->darken($colorWarning, 7),
  113. '--color-success' => $colorSuccess,
  114. '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
  115. '--color-success-hover' => $this->util->mix($colorSuccess, $colorMainBackground, 80),
  116. '--color-success-text' => $this->util->darken($colorSuccess, 4),
  117. '--color-info' => $colorInfo,
  118. '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
  119. '--color-info-hover' => $this->util->mix($colorInfo, $colorMainBackground, 80),
  120. '--color-info-text' => $this->util->darken($colorInfo, 4),
  121. '--color-favorite' => '#A37200',
  122. // used for the icon loading animation
  123. '--color-loading-light' => '#cccccc',
  124. '--color-loading-dark' => '#444444',
  125. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  126. '--color-box-shadow' => "rgba(var(--color-box-shadow-rgb), 0.5)",
  127. '--color-border' => $this->util->darken($colorMainBackground, 7),
  128. '--color-border-dark' => $this->util->darken($colorMainBackground, 14),
  129. '--color-border-maxcontrast' => $this->util->darken($colorMainBackground, 51),
  130. '--font-face' => "system-ui, -apple-system, 'Segoe UI', Roboto, Oxygen-Sans, Cantarell, Ubuntu, 'Helvetica Neue', 'Noto Sans', 'Liberation Sans', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'",
  131. '--default-font-size' => '15px',
  132. // TODO: support "(prefers-reduced-motion)"
  133. '--animation-quick' => '100ms',
  134. '--animation-slow' => '300ms',
  135. // Default variables --------------------------------------------
  136. // Border width for input elements such as text fields and selects
  137. '--border-width-input' => '1px',
  138. '--border-width-input-focused' => '2px',
  139. '--border-radius' => '3px',
  140. '--border-radius-large' => '10px',
  141. '--border-radius-rounded' => '28px',
  142. '--border-radius-element' => '8px',
  143. // pill-style button, value is large so big buttons also have correct roundness
  144. '--border-radius-pill' => '100px',
  145. '--default-clickable-area' => '34px',
  146. '--clickable-area-large' => '48px',
  147. '--clickable-area-small' => '24px',
  148. '--default-line-height' => '24px',
  149. '--default-grid-baseline' => '4px',
  150. // various structure data
  151. '--header-height' => '50px',
  152. '--navigation-width' => '300px',
  153. '--sidebar-min-width' => '300px',
  154. '--sidebar-max-width' => '500px',
  155. '--list-min-width' => '200px',
  156. '--list-max-width' => '300px',
  157. '--header-menu-item-height' => '44px',
  158. '--header-menu-profile-item-height' => '66px',
  159. // mobile. Keep in sync with core/js/js.js
  160. '--breakpoint-mobile' => '1024px',
  161. '--background-invert-if-dark' => 'no',
  162. '--background-invert-if-bright' => 'invert(100%)',
  163. '--background-image-invert-if-bright' => 'no',
  164. ];
  165. // Primary variables
  166. $variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText));
  167. $variables = array_merge($variables, $this->generateGlobalBackgroundVariables());
  168. $variables = array_merge($variables, $this->generateUserBackgroundVariables());
  169. return $variables;
  170. }
  171. public function getCustomCss(): string {
  172. return '';
  173. }
  174. }