@cloud-ru/ds-theme 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/README.md +365 -0
- package/dist/cjs/components/ChildThemeProvider/ChildThemeProvider.d.ts +24 -0
- package/dist/cjs/components/ChildThemeProvider/ChildThemeProvider.js +25 -0
- package/dist/cjs/components/ChildThemeProvider/index.d.ts +1 -0
- package/dist/cjs/components/ChildThemeProvider/index.js +17 -0
- package/dist/cjs/components/RootThemeProvider/RootThemeProvider.d.ts +49 -0
- package/dist/cjs/components/RootThemeProvider/RootThemeProvider.js +30 -0
- package/dist/cjs/components/RootThemeProvider/index.d.ts +1 -0
- package/dist/cjs/components/RootThemeProvider/index.js +17 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.d.ts +28 -0
- package/dist/cjs/components/ThemeProvider/ThemeProvider.js +16 -0
- package/dist/cjs/components/ThemeProvider/index.d.ts +1 -0
- package/dist/cjs/components/ThemeProvider/index.js +17 -0
- package/dist/cjs/components/ThemeScope/ThemeScope.d.ts +32 -0
- package/dist/cjs/components/ThemeScope/ThemeScope.js +65 -0
- package/dist/cjs/components/ThemeScope/index.d.ts +1 -0
- package/dist/cjs/components/ThemeScope/index.js +17 -0
- package/dist/cjs/components/index.d.ts +3 -0
- package/dist/cjs/components/index.js +19 -0
- package/dist/cjs/constants/appearance.d.ts +22 -0
- package/dist/cjs/constants/appearance.js +27 -0
- package/dist/cjs/constants/colorScheme.d.ts +17 -0
- package/dist/cjs/constants/colorScheme.js +23 -0
- package/dist/cjs/constants/index.d.ts +2 -0
- package/dist/cjs/constants/index.js +18 -0
- package/dist/cjs/context/appearanceContext.d.ts +20 -0
- package/dist/cjs/context/appearanceContext.js +22 -0
- package/dist/cjs/context/index.d.ts +4 -0
- package/dist/cjs/context/index.js +7 -0
- package/dist/cjs/context/themeContext.d.ts +12 -0
- package/dist/cjs/context/themeContext.js +15 -0
- package/dist/cjs/hooks/index.d.ts +4 -0
- package/dist/cjs/hooks/index.js +20 -0
- package/dist/cjs/hooks/useApplyCustomTheme.d.ts +27 -0
- package/dist/cjs/hooks/useApplyCustomTheme.js +39 -0
- package/dist/cjs/hooks/useColorScheme.d.ts +37 -0
- package/dist/cjs/hooks/useColorScheme.js +80 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.d.ts +7 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +16 -0
- package/dist/cjs/hooks/useThemeClassnames.d.ts +11 -0
- package/dist/cjs/hooks/useThemeClassnames.js +18 -0
- package/dist/cjs/hooks/useThemeConfig.d.ts +24 -0
- package/dist/cjs/hooks/useThemeConfig.js +15 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/keys.d.ts +4 -0
- package/dist/cjs/keys.js +19 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/ssr.d.ts +15 -0
- package/dist/cjs/ssr.js +38 -0
- package/dist/cjs/store/globalStore.d.ts +29 -0
- package/dist/cjs/store/globalStore.js +72 -0
- package/dist/cjs/store/index.d.ts +1 -0
- package/dist/cjs/store/index.js +17 -0
- package/dist/cjs/types/appearance.d.ts +23 -0
- package/dist/cjs/types/appearance.js +3 -0
- package/dist/cjs/types/colorScheme.d.ts +5 -0
- package/dist/cjs/types/colorScheme.js +2 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/cjs/utils/colorSchemeFromHeaders.d.ts +22 -0
- package/dist/cjs/utils/colorSchemeFromHeaders.js +44 -0
- package/dist/cjs/utils/colorSchemeStorage.d.ts +35 -0
- package/dist/cjs/utils/colorSchemeStorage.js +85 -0
- package/dist/cjs/utils/customTheme/buildBrandPaletteCss.d.ts +11 -0
- package/dist/cjs/utils/customTheme/buildBrandPaletteCss.js +35 -0
- package/dist/cjs/utils/customTheme/buildBrandPaletteVars.d.ts +11 -0
- package/dist/cjs/utils/customTheme/buildBrandPaletteVars.js +42 -0
- package/dist/cjs/utils/customTheme/color/apca.d.ts +4 -0
- package/dist/cjs/utils/customTheme/color/apca.js +62 -0
- package/dist/cjs/utils/customTheme/color/colorSpace.d.ts +5 -0
- package/dist/cjs/utils/customTheme/color/colorSpace.js +72 -0
- package/dist/cjs/utils/customTheme/color/conversions.d.ts +17 -0
- package/dist/cjs/utils/customTheme/color/conversions.js +101 -0
- package/dist/cjs/utils/customTheme/color/hex.d.ts +10 -0
- package/dist/cjs/utils/customTheme/color/hex.js +34 -0
- package/dist/cjs/utils/customTheme/color/index.d.ts +4 -0
- package/dist/cjs/utils/customTheme/color/index.js +20 -0
- package/dist/cjs/utils/customTheme/color/oklch.d.ts +3 -0
- package/dist/cjs/utils/customTheme/color/oklch.js +21 -0
- package/dist/cjs/utils/customTheme/color/types.d.ts +40 -0
- package/dist/cjs/utils/customTheme/color/types.js +2 -0
- package/dist/cjs/utils/customTheme/constants.d.ts +31 -0
- package/dist/cjs/utils/customTheme/constants.js +49 -0
- package/dist/cjs/utils/customTheme/generateBrandPalette.d.ts +10 -0
- package/dist/cjs/utils/customTheme/generateBrandPalette.js +25 -0
- package/dist/cjs/utils/customTheme/index.d.ts +4 -0
- package/dist/cjs/utils/customTheme/index.js +20 -0
- package/dist/cjs/utils/getThemeClassnames.d.ts +17 -0
- package/dist/cjs/utils/getThemeClassnames.js +38 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.js +23 -0
- package/dist/cjs/utils/mergeAppearance.d.ts +7 -0
- package/dist/cjs/utils/mergeAppearance.js +17 -0
- package/dist/cjs/utils/resolveColorScheme.d.ts +7 -0
- package/dist/cjs/utils/resolveColorScheme.js +15 -0
- package/dist/cjs/utils/themeBootstrap.d.ts +12 -0
- package/dist/cjs/utils/themeBootstrap.js +19 -0
- package/dist/esm/components/ChildThemeProvider/ChildThemeProvider.d.ts +24 -0
- package/dist/esm/components/ChildThemeProvider/ChildThemeProvider.js +22 -0
- package/dist/esm/components/ChildThemeProvider/index.d.ts +1 -0
- package/dist/esm/components/ChildThemeProvider/index.js +1 -0
- package/dist/esm/components/RootThemeProvider/RootThemeProvider.d.ts +49 -0
- package/dist/esm/components/RootThemeProvider/RootThemeProvider.js +27 -0
- package/dist/esm/components/RootThemeProvider/index.d.ts +1 -0
- package/dist/esm/components/RootThemeProvider/index.js +1 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.d.ts +28 -0
- package/dist/esm/components/ThemeProvider/ThemeProvider.js +13 -0
- package/dist/esm/components/ThemeProvider/index.d.ts +1 -0
- package/dist/esm/components/ThemeProvider/index.js +1 -0
- package/dist/esm/components/ThemeScope/ThemeScope.d.ts +32 -0
- package/dist/esm/components/ThemeScope/ThemeScope.js +59 -0
- package/dist/esm/components/ThemeScope/index.d.ts +1 -0
- package/dist/esm/components/ThemeScope/index.js +1 -0
- package/dist/esm/components/index.d.ts +3 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/constants/appearance.d.ts +22 -0
- package/dist/esm/constants/appearance.js +24 -0
- package/dist/esm/constants/colorScheme.d.ts +17 -0
- package/dist/esm/constants/colorScheme.js +20 -0
- package/dist/esm/constants/index.d.ts +2 -0
- package/dist/esm/constants/index.js +2 -0
- package/dist/esm/context/appearanceContext.d.ts +20 -0
- package/dist/esm/context/appearanceContext.js +18 -0
- package/dist/esm/context/index.d.ts +4 -0
- package/dist/esm/context/index.js +2 -0
- package/dist/esm/context/themeContext.d.ts +12 -0
- package/dist/esm/context/themeContext.js +11 -0
- package/dist/esm/hooks/index.d.ts +4 -0
- package/dist/esm/hooks/index.js +4 -0
- package/dist/esm/hooks/useApplyCustomTheme.d.ts +27 -0
- package/dist/esm/hooks/useApplyCustomTheme.js +36 -0
- package/dist/esm/hooks/useColorScheme.d.ts +37 -0
- package/dist/esm/hooks/useColorScheme.js +76 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect.d.ts +7 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +13 -0
- package/dist/esm/hooks/useThemeClassnames.d.ts +11 -0
- package/dist/esm/hooks/useThemeClassnames.js +15 -0
- package/dist/esm/hooks/useThemeConfig.d.ts +24 -0
- package/dist/esm/hooks/useThemeConfig.js +12 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/keys.d.ts +4 -0
- package/dist/esm/keys.js +16 -0
- package/dist/esm/ssr.d.ts +15 -0
- package/dist/esm/ssr.js +15 -0
- package/dist/esm/store/globalStore.d.ts +29 -0
- package/dist/esm/store/globalStore.js +69 -0
- package/dist/esm/store/index.d.ts +1 -0
- package/dist/esm/store/index.js +1 -0
- package/dist/esm/types/appearance.d.ts +23 -0
- package/dist/esm/types/appearance.js +2 -0
- package/dist/esm/types/colorScheme.d.ts +5 -0
- package/dist/esm/types/colorScheme.js +1 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/utils/colorSchemeFromHeaders.d.ts +22 -0
- package/dist/esm/utils/colorSchemeFromHeaders.js +40 -0
- package/dist/esm/utils/colorSchemeStorage.d.ts +35 -0
- package/dist/esm/utils/colorSchemeStorage.js +81 -0
- package/dist/esm/utils/customTheme/buildBrandPaletteCss.d.ts +11 -0
- package/dist/esm/utils/customTheme/buildBrandPaletteCss.js +32 -0
- package/dist/esm/utils/customTheme/buildBrandPaletteVars.d.ts +11 -0
- package/dist/esm/utils/customTheme/buildBrandPaletteVars.js +39 -0
- package/dist/esm/utils/customTheme/color/apca.d.ts +4 -0
- package/dist/esm/utils/customTheme/color/apca.js +59 -0
- package/dist/esm/utils/customTheme/color/colorSpace.d.ts +5 -0
- package/dist/esm/utils/customTheme/color/colorSpace.js +68 -0
- package/dist/esm/utils/customTheme/color/conversions.d.ts +17 -0
- package/dist/esm/utils/customTheme/color/conversions.js +91 -0
- package/dist/esm/utils/customTheme/color/hex.d.ts +10 -0
- package/dist/esm/utils/customTheme/color/hex.js +29 -0
- package/dist/esm/utils/customTheme/color/index.d.ts +4 -0
- package/dist/esm/utils/customTheme/color/index.js +4 -0
- package/dist/esm/utils/customTheme/color/oklch.d.ts +3 -0
- package/dist/esm/utils/customTheme/color/oklch.js +18 -0
- package/dist/esm/utils/customTheme/color/types.d.ts +40 -0
- package/dist/esm/utils/customTheme/color/types.js +1 -0
- package/dist/esm/utils/customTheme/constants.d.ts +31 -0
- package/dist/esm/utils/customTheme/constants.js +46 -0
- package/dist/esm/utils/customTheme/generateBrandPalette.d.ts +10 -0
- package/dist/esm/utils/customTheme/generateBrandPalette.js +22 -0
- package/dist/esm/utils/customTheme/index.d.ts +4 -0
- package/dist/esm/utils/customTheme/index.js +4 -0
- package/dist/esm/utils/getThemeClassnames.d.ts +17 -0
- package/dist/esm/utils/getThemeClassnames.js +34 -0
- package/dist/esm/utils/index.d.ts +7 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/mergeAppearance.d.ts +7 -0
- package/dist/esm/utils/mergeAppearance.js +14 -0
- package/dist/esm/utils/resolveColorScheme.d.ts +7 -0
- package/dist/esm/utils/resolveColorScheme.js +12 -0
- package/dist/esm/utils/themeBootstrap.d.ts +12 -0
- package/dist/esm/utils/themeBootstrap.js +16 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/src/components/ChildThemeProvider/ChildThemeProvider.tsx +54 -0
- package/src/components/ChildThemeProvider/index.ts +1 -0
- package/src/components/RootThemeProvider/RootThemeProvider.tsx +87 -0
- package/src/components/RootThemeProvider/index.ts +1 -0
- package/src/components/ThemeProvider/ThemeProvider.tsx +41 -0
- package/src/components/ThemeProvider/index.ts +1 -0
- package/src/components/ThemeScope/ThemeScope.tsx +106 -0
- package/src/components/ThemeScope/index.ts +1 -0
- package/src/components/index.ts +3 -0
- package/src/constants/appearance.ts +27 -0
- package/src/constants/colorScheme.ts +23 -0
- package/src/constants/index.ts +2 -0
- package/src/context/appearanceContext.tsx +39 -0
- package/src/context/index.ts +4 -0
- package/src/context/themeContext.ts +18 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useApplyCustomTheme.ts +56 -0
- package/src/hooks/useColorScheme.ts +131 -0
- package/src/hooks/useIsomorphicLayoutEffect.ts +17 -0
- package/src/hooks/useThemeClassnames.ts +18 -0
- package/src/hooks/useThemeConfig.tsx +44 -0
- package/src/index.ts +7 -0
- package/src/keys.ts +18 -0
- package/src/ssr.ts +25 -0
- package/src/store/globalStore.ts +93 -0
- package/src/store/index.ts +1 -0
- package/src/types/appearance.ts +29 -0
- package/src/types/colorScheme.ts +7 -0
- package/src/types/index.ts +2 -0
- package/src/utils/colorSchemeFromHeaders.ts +57 -0
- package/src/utils/colorSchemeStorage.ts +117 -0
- package/src/utils/customTheme/buildBrandPaletteCss.ts +37 -0
- package/src/utils/customTheme/buildBrandPaletteVars.ts +56 -0
- package/src/utils/customTheme/color/apca.ts +74 -0
- package/src/utils/customTheme/color/colorSpace.ts +82 -0
- package/src/utils/customTheme/color/conversions.ts +113 -0
- package/src/utils/customTheme/color/hex.ts +39 -0
- package/src/utils/customTheme/color/index.ts +4 -0
- package/src/utils/customTheme/color/oklch.ts +22 -0
- package/src/utils/customTheme/color/types.ts +32 -0
- package/src/utils/customTheme/constants.ts +57 -0
- package/src/utils/customTheme/generateBrandPalette.ts +30 -0
- package/src/utils/customTheme/index.ts +4 -0
- package/src/utils/getThemeClassnames.ts +40 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/mergeAppearance.ts +16 -0
- package/src/utils/resolveColorScheme.ts +15 -0
- package/src/utils/themeBootstrap.ts +18 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 Cloud technology Limited (Ltd.)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# Theme
|
|
2
|
+
|
|
3
|
+
`@cloud-ru/ds-theme` — Провайдер оформления — оси (цветовая схема, бренд, плотность, акрил) живут в контексте, полный набор sn-* классов эмитится на DOM-границе.
|
|
4
|
+
|
|
5
|
+
`@cloud-ru/ds-theme` управляет оформлением дизайн-системы. **Оси оформления живут в React-контексте, а полный набор CSS-классов `sn-*` эмитится на DOM-границу.** `RootThemeProvider` ставится один раз в корне и держит оси (`colorScheme`, `brand`, `brandRole`, `density`, `acrylic`), эмитя из них полный набор `sn-*` на `rootRef` (обычно `<html>`). Локальные переопределения в поддереве делает `ChildThemeProvider`, а компонент, фиксирующий ось у себя, — хук `useThemeClassnames`.
|
|
6
|
+
|
|
7
|
+
Кроме предустановленных брендов `@cloud-ru/ds-theme` умеет собрать бренд-палитру из **одного seed-цвета** (white-label): из него генерируется полная шкала тонов `--sn-brand-color-primary-*`, и весь семантический слой каскадит из неё — см. секцию «Кастомный бренд-цвет».
|
|
8
|
+
|
|
9
|
+
Полное руководство по модели и подключению — в паттерне [Оформление — тема, бренд, плотность](/patterns/theme).
|
|
10
|
+
|
|
11
|
+
## Когда использовать
|
|
12
|
+
|
|
13
|
+
- Хост-приложение задаёт оформление в корне: `RootThemeProvider value={{ colorScheme, brand, density }}` (или `store` для multi-root / MFE через `getGlobalThemeStore().store`).
|
|
14
|
+
- Цветовая схема light/dark берётся из `useColorScheme` (`prefers-color-scheme` + опциональный персист-адаптер) и передаётся в `value.colorScheme`.
|
|
15
|
+
- Часть дерева должна иметь другой бренд / плотность / схему — `ChildThemeProvider` сливает partial-переопределение с ближайшим контекстом.
|
|
16
|
+
- Компонент локально фиксирует ось (мобильная обёртка с `density: 'comfort'`) — `useThemeClassnames({ density })` подмешивает текущие colorScheme/brand из контекста.
|
|
17
|
+
- Нужен бренд-цвет вне предустановленного набора (white-label под клиента) — `RootThemeProvider brandColor='#RRGGBB'` (декларативно) либо хук `useApplyCustomTheme({ color })` (императивно).
|
|
18
|
+
|
|
19
|
+
> Полный набор `sn-*` обязателен на каждой границе: классы токенов не переопределяются по одной оси через CSS-каскад. Никогда не ставьте одиночный `sn-comfort` руками — для этого есть провайдеры и хук. Старый `ThemeProvider` / `useThemeConfig` (произвольные темы по `themeMap`) — отдельный legacy-механизм, не путать с `RootThemeProvider`.
|
|
20
|
+
|
|
21
|
+
## Установка
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @cloud-ru/ds-theme
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import {
|
|
29
|
+
RootThemeProvider,
|
|
30
|
+
ChildThemeProvider,
|
|
31
|
+
useThemeClassnames,
|
|
32
|
+
useColorScheme,
|
|
33
|
+
useApplyCustomTheme,
|
|
34
|
+
getGlobalThemeStore,
|
|
35
|
+
} from '@cloud-ru/ds-theme'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Примеры использования
|
|
39
|
+
|
|
40
|
+
### Бренд для поддерева
|
|
41
|
+
|
|
42
|
+
`ChildThemeProvider` сливает ось `brand` с ближайшим контекстом и реэмитит полный набор `sn-*` на своей границе.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { Block } from '@cloud-ru/ds-block';
|
|
46
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
47
|
+
import { Counter } from '@cloud-ru/ds-counter';
|
|
48
|
+
import { SegmentControl } from '@cloud-ru/ds-segment-control';
|
|
49
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
50
|
+
import { BRAND, Brand, ChildThemeProvider } from '@cloud-ru/ds-theme';
|
|
51
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
52
|
+
import { useState } from 'react';
|
|
53
|
+
|
|
54
|
+
const BRAND_ITEMS = Object.values(BRAND).map(value => ({ value, label: value }));
|
|
55
|
+
|
|
56
|
+
export function BrandSwitch() {
|
|
57
|
+
const [brand, setBrand] = useState<Brand>(BRAND.A);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
61
|
+
<SegmentControl items={BRAND_ITEMS} value={brand} onChange={value => setBrand(value as Brand)} />
|
|
62
|
+
|
|
63
|
+
{/* ChildThemeProvider сливает ось `brand` с ближайшим контекстом и реэмитит полный набор
|
|
64
|
+
sn-* на своей границе — акцентные цвета компонентов ниже меняются вслед за брендом. */}
|
|
65
|
+
<ChildThemeProvider value={{ brand }}>
|
|
66
|
+
<Block>
|
|
67
|
+
<Flex gap='2m' align='center' wrap>
|
|
68
|
+
<Button appearance='primary' label='Действие' />
|
|
69
|
+
<Tag appearance='primary' label='Бренд' />
|
|
70
|
+
<Counter value={8} appearance='primary' />
|
|
71
|
+
</Flex>
|
|
72
|
+
</Block>
|
|
73
|
+
</ChildThemeProvider>
|
|
74
|
+
</Flex>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Переключение цветовой схемы
|
|
80
|
+
|
|
81
|
+
Поддерево рендерится в выбранной схеме (`sn-light` / `sn-dark`). В приложении схема — источник истины `useColorScheme`.
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import { Block } from '@cloud-ru/ds-block';
|
|
85
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
86
|
+
import { SegmentControl } from '@cloud-ru/ds-segment-control';
|
|
87
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
88
|
+
import { ChildThemeProvider, COLOR_SCHEME, ColorScheme } from '@cloud-ru/ds-theme';
|
|
89
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
90
|
+
import { useState } from 'react';
|
|
91
|
+
|
|
92
|
+
const SCHEME_ITEMS = [
|
|
93
|
+
{ value: COLOR_SCHEME.Light, label: 'Светлая' },
|
|
94
|
+
{ value: COLOR_SCHEME.Dark, label: 'Тёмная' },
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
export function ColorSchemeToggle() {
|
|
98
|
+
const [colorScheme, setColorScheme] = useState<ColorScheme>(COLOR_SCHEME.Light);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
102
|
+
<SegmentControl
|
|
103
|
+
items={SCHEME_ITEMS}
|
|
104
|
+
value={colorScheme}
|
|
105
|
+
onChange={value => setColorScheme(value as ColorScheme)}
|
|
106
|
+
/>
|
|
107
|
+
|
|
108
|
+
{/* В приложении colorScheme — источник истины `useColorScheme` (cookie + prefers-color-scheme),
|
|
109
|
+
а корень держит RootThemeProvider. Здесь ChildThemeProvider переключает схему для поддерева:
|
|
110
|
+
материал-подложка Block и компоненты на ней перекрашиваются вслед за схемой. */}
|
|
111
|
+
<ChildThemeProvider value={{ colorScheme }}>
|
|
112
|
+
<Block>
|
|
113
|
+
<Flex gap='2m' align='center' wrap>
|
|
114
|
+
<Button appearance='primary' label='Действие' />
|
|
115
|
+
<Button appearance='neutral' view='outline' label='Отмена' />
|
|
116
|
+
<Tag appearance='blue' label='Метка' />
|
|
117
|
+
</Flex>
|
|
118
|
+
</Block>
|
|
119
|
+
</ChildThemeProvider>
|
|
120
|
+
</Flex>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Локальная плотность
|
|
126
|
+
|
|
127
|
+
Компонент фиксирует `density` через `useThemeClassnames({ density })` — хук подмешивает текущие colorScheme/brand из контекста.
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
131
|
+
import { SegmentControl } from '@cloud-ru/ds-segment-control';
|
|
132
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
133
|
+
import { DENSITY, Density, useThemeClassnames } from '@cloud-ru/ds-theme';
|
|
134
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
135
|
+
import { useState } from 'react';
|
|
136
|
+
|
|
137
|
+
const DENSITY_ITEMS = Object.values(DENSITY).map(value => ({ value, label: value }));
|
|
138
|
+
|
|
139
|
+
function DensitySurface({ density }: { density: Density }) {
|
|
140
|
+
// useThemeClassnames({ density }) подмешивает текущие colorScheme/brand из контекста и навешивает
|
|
141
|
+
// ПОЛНЫЙ набор sn-* (а не одиночный sn-comfort) — внутренние отступы компонентов меняются вслед
|
|
142
|
+
// за плотностью, а тёмная тема при этом не ломается.
|
|
143
|
+
const className = useThemeClassnames({ density });
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<div className={className}>
|
|
147
|
+
<Flex gap='2m' align='center' wrap>
|
|
148
|
+
<Button appearance='primary' label='Кнопка' />
|
|
149
|
+
<Button appearance='neutral' view='outline' label='Ещё' />
|
|
150
|
+
<Tag appearance='primary' label='Тег' />
|
|
151
|
+
</Flex>
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function LocalDensity() {
|
|
157
|
+
const [density, setDensity] = useState<Density>(DENSITY.Compact);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
161
|
+
<SegmentControl items={DENSITY_ITEMS} value={density} onChange={value => setDensity(value as Density)} />
|
|
162
|
+
<DensitySurface density={density} />
|
|
163
|
+
</Flex>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Props
|
|
169
|
+
|
|
170
|
+
### RootThemeProvider
|
|
171
|
+
|
|
172
|
+
**RootThemeProviderProps**
|
|
173
|
+
|
|
174
|
+
| Prop | Type | Default | Description |
|
|
175
|
+
|------|------|---------|-------------|
|
|
176
|
+
| `brandColor` | `string` | — | Кастомный бренд-цвет потребителя (hex `#rrggbb`) для white-label. Генерирует бренд-палитру из <br/> seed-цвета и инжектит scoped `<style>` на бренд-классы этого поддерева. Правило на бренд-классе <br/> (а не inline на одном элементе) переживает переэмиты `sn-*` вложенными компонентами (Table и т.п.), <br/> поэтому кастомный цвет доходит до всей вложенности. Невалидный hex игнорируется. Глобальная <br/> (app-root) альтернатива для порталов — хук `useApplyCustomTheme`. |
|
|
177
|
+
| `children` | `string \| number \| boolean \| ReactElement<any, string \| JSXElementConstructor<any>> \| Iterable<ReactNode> \| ReactPortal \| null \| undefined` | — | |
|
|
178
|
+
| `className` | `string` | — | Дополнительный класс на wrapper-`<div>` (паддинги/фон). Только в wrapper-режиме (без `rootRef`). |
|
|
179
|
+
| `nonce` | `string` | — | CSP-`nonce` для инжектируемого `<style>` кастомного бренд-цвета. |
|
|
180
|
+
| `rootRef` | `RefObject<HTMLElement \| null>` | — | Внешний элемент для полного набора `sn-*` (обычно `<html>`/`<body>`). Если не задан — провайдер <br/> оборачивает children в `<div>` с этим набором. |
|
|
181
|
+
| `store` | `ThemeAppearanceStore` | — | Внешний реактивный стор оформления (`getGlobalThemeStore().store`). Если задан — приоритетнее <br/> `value`; подписанные провайдеры обновляются при смене темы без перерендера провайдера. Так один <br/> глобальный стор охватывает все микрофронты. Сеттер для shell — `getGlobalThemeStore().setAppearance`. |
|
|
182
|
+
| `value` | `ThemeAppearance` | — | Оформление приложения. Используется в static-режиме (один React-корень: SSR — одно значение на <br/> запрос, либо CSR с собственным state, напр. `colorScheme` из `useColorScheme`). Для multi-root <br/> (single-spa) — см. `store`. |
|
|
183
|
+
|
|
184
|
+
#### Related types
|
|
185
|
+
|
|
186
|
+
- `Brand` = `"brandA"` \| `"brandB"` \| `"brandC"` \| `"brandD"` \| `"brandE"`
|
|
187
|
+
|
|
188
|
+
- `BrandRole` = `"alter"` \| `"alter2"` \| `"alter3"` \| `"alter4"` \| `"main"`
|
|
189
|
+
|
|
190
|
+
- `ColorScheme` = `"dark"` \| `"light"`
|
|
191
|
+
|
|
192
|
+
- `Density` = `"comfort"` \| `"compact"` \| `"spacious"`
|
|
193
|
+
|
|
194
|
+
**ThemeAppearance**
|
|
195
|
+
|
|
196
|
+
| Prop | Type | Default | Description |
|
|
197
|
+
|------|------|---------|-------------|
|
|
198
|
+
| `acrylic` | `boolean \| undefined` | — | Акрил (blur-материал) — `sn-yes` при `true`, иначе `sn-no`. |
|
|
199
|
+
| `brand` | `"brandA"` \| `"brandB"` \| `"brandC"` \| `"brandD"` \| `"brandE"` | — | Бренд — `sn-brandA` … |
|
|
200
|
+
| `brandRole` | `"alter"` \| `"alter2"` \| `"alter3"` \| `"alter4"` \| `"main"` | — | Роль бренда (палитра) — `sn-main` … |
|
|
201
|
+
| `colorScheme` | `"dark"` \| `"light"` | — | Цветовая схема — `sn-light` / `sn-dark`. |
|
|
202
|
+
| `density` | `"comfort"` \| `"compact"` \| `"spacious"` | — | Плотность — `sn-comfort` / `sn-compact` / `sn-spacious`. |
|
|
203
|
+
|
|
204
|
+
**ThemeAppearanceStore**
|
|
205
|
+
|
|
206
|
+
| Prop | Type | Default | Description |
|
|
207
|
+
|------|------|---------|-------------|
|
|
208
|
+
| `getServerSnapshot` | `(() => ThemeAppearanceContextValue) \| undefined` | — | Значение для SSR/гидрации. Если не задан — используется `getSnapshot`. |
|
|
209
|
+
| `getSnapshot` | `() => ThemeAppearanceContextValue` | — | Текущее значение. Обязан возвращать стабильную (по `Object.is`) ссылку, пока значение не менялось. |
|
|
210
|
+
| `subscribe` | `(onStoreChange: () => void) => () => void` | — | Подписка на изменения; возвращает функцию отписки. |
|
|
211
|
+
|
|
212
|
+
### ChildThemeProvider
|
|
213
|
+
|
|
214
|
+
**ChildThemeProviderProps**
|
|
215
|
+
|
|
216
|
+
| Prop | Type | Default | Description |
|
|
217
|
+
|------|------|---------|-------------|
|
|
218
|
+
| `children` | `string \| number \| boolean \| ReactElement<any, string \| JSXElementConstructor<any>> \| Iterable<ReactNode> \| ReactPortal \| null \| undefined` | — | |
|
|
219
|
+
| `className` | `string` | — | Дополнительный класс на wrapper-`<div>` (паддинги/фон). Только в wrapper-режиме (без `rootRef`). |
|
|
220
|
+
| `rootRef` | `RefObject<HTMLElement \| null>` | — | Внешний элемент для полного слитого набора `sn-*`. Если не задан — провайдер оборачивает <br/> children в `<div>` с этим набором. |
|
|
221
|
+
| `value` | `ThemeAppearance` | — | Оси, переопределяемые в поддереве. Остальные наследуются от ближайшего родителя (слияние). |
|
|
222
|
+
|
|
223
|
+
#### Related types
|
|
224
|
+
|
|
225
|
+
- `Brand` = `"brandA"` \| `"brandB"` \| `"brandC"` \| `"brandD"` \| `"brandE"`
|
|
226
|
+
|
|
227
|
+
- `BrandRole` = `"alter"` \| `"alter2"` \| `"alter3"` \| `"alter4"` \| `"main"`
|
|
228
|
+
|
|
229
|
+
- `ColorScheme` = `"dark"` \| `"light"`
|
|
230
|
+
|
|
231
|
+
- `Density` = `"comfort"` \| `"compact"` \| `"spacious"`
|
|
232
|
+
|
|
233
|
+
**ThemeAppearance**
|
|
234
|
+
|
|
235
|
+
| Prop | Type | Default | Description |
|
|
236
|
+
|------|------|---------|-------------|
|
|
237
|
+
| `acrylic` | `boolean \| undefined` | — | Акрил (blur-материал) — `sn-yes` при `true`, иначе `sn-no`. |
|
|
238
|
+
| `brand` | `"brandA"` \| `"brandB"` \| `"brandC"` \| `"brandD"` \| `"brandE"` | — | Бренд — `sn-brandA` … |
|
|
239
|
+
| `brandRole` | `"alter"` \| `"alter2"` \| `"alter3"` \| `"alter4"` \| `"main"` | — | Роль бренда (палитра) — `sn-main` … |
|
|
240
|
+
| `colorScheme` | `"dark"` \| `"light"` | — | Цветовая схема — `sn-light` / `sn-dark`. |
|
|
241
|
+
| `density` | `"comfort"` \| `"compact"` \| `"spacious"` | — | Плотность — `sn-comfort` / `sn-compact` / `sn-spacious`. |
|
|
242
|
+
|
|
243
|
+
## Смотри также
|
|
244
|
+
|
|
245
|
+
- [Оформление — тема, бренд, плотность](/patterns/theme) — полная модель подключения темы.
|
|
246
|
+
- **Adaptive** — раскладка `layoutType` (источник `density` в приложении).
|
|
247
|
+
- **Locale** — рантайм локализации.
|
|
248
|
+
- **PortalContext** — корневой DOM-узел для порталов.
|
|
249
|
+
## Кастомный бренд-цвет
|
|
250
|
+
|
|
251
|
+
Помимо предустановленных брендов (`brandA` / `brandB` / `brandC` / `brandD` / `brandE`) `@cloud-ru/ds-theme` собирает бренд-палитру из одного seed-цвета — для white-label под клиента. Из seed генерируется полная шкала тонов `--sn-brand-color-primary-*` (OKLCH: светлота и насыщенность берутся из опорной шкалы, hue поворачивается к seed) плюс activated-тинты; семантический слой `--sn-theme-color-primary-*` каскадит из неё. Поэтому один цвет перекрашивает акцент во всех компонентах — и в светлой, и в тёмной схеме.
|
|
252
|
+
|
|
253
|
+
Палитра применяется **CSS-правилом на бренд-классы** (`.sn-brandA/B/C/D/E`), а не inline-переменными на одном элементе. Это принципиально: компоненты, переобъявляющие полный набор `sn-*` на своих внутренних обёртках (Table, Stepper и т.п. через `useThemeClassnames`), заново объявляют бренд-палитру из класса — inline-переменные предка в таких поддеревьях перекрываются, а правило на том же бренд-классе — нет. Два способа применить:
|
|
254
|
+
|
|
255
|
+
- **Декларативно** — проп `brandColor` у `RootThemeProvider`. Добавляет scoped-правило на бренд-классы поддерева провайдера (доходит до вложенных переобъявлений):
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
<RootThemeProvider value={{ colorScheme }} brandColor={brand.primaryColor}>
|
|
259
|
+
{app}
|
|
260
|
+
</RootThemeProvider>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
- **Императивно** — хук `useApplyCustomTheme`. Без `scope` добавляет **глобальное** правило на все бренд-классы страницы (покрывает и порталы — дропдауны, тултипы); со `scope` ограничивает поддеревом. Удобно, когда бренд-цвет приходит асинхронно из бэкенда в bootstrap-компоненте:
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
useApplyCustomTheme({ color: brand.primaryColor, enabled: Boolean(brand), nonce })
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Порталы монтируются вне поддерева провайдера, поэтому для их перекраски используйте **глобальный** `useApplyCustomTheme` в корне приложения (без `scope`), а не scoped-`brandColor`.
|
|
270
|
+
|
|
271
|
+
Схему (light/dark) кастомный бренд-цвет не задаёт — она остаётся из `colorScheme`, а палитра тонов от схемы не зависит. Для SSR без мигания палитру можно собрать строкой заранее: `generateBrandPalette(color)` / `buildBrandPaletteVars(color)` из `@cloud-ru/ds-theme/ssr` (чистые, без React и DOM).
|
|
272
|
+
|
|
273
|
+
### Бренд-цвет из seed
|
|
274
|
+
|
|
275
|
+
`brandColor` генерирует палитру `--sn-brand-color-primary-*` из одного цвета — акцент компонентов перекрашивается вслед за выбором.
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
import { Block } from '@cloud-ru/ds-block';
|
|
279
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
280
|
+
import { Counter } from '@cloud-ru/ds-counter';
|
|
281
|
+
import { SegmentControl } from '@cloud-ru/ds-segment-control';
|
|
282
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
283
|
+
import { RootThemeProvider } from '@cloud-ru/ds-theme';
|
|
284
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
285
|
+
import { useState } from 'react';
|
|
286
|
+
|
|
287
|
+
const COLOR_ITEMS = [
|
|
288
|
+
{ value: '#ff7a00', label: 'Оранжевый' },
|
|
289
|
+
{ value: '#8a2be2', label: 'Фиолетовый' },
|
|
290
|
+
{ value: '#0077ff', label: 'Синий' },
|
|
291
|
+
{ value: '#e5006e', label: 'Розовый' },
|
|
292
|
+
];
|
|
293
|
+
|
|
294
|
+
export function CustomBrandColor() {
|
|
295
|
+
const [color, setColor] = useState('#ff7a00');
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
299
|
+
<SegmentControl items={COLOR_ITEMS} value={color} onChange={value => setColor(String(value))} />
|
|
300
|
+
|
|
301
|
+
{/* brandColor генерирует палитру `--sn-brand-color-primary-*` из одного seed-цвета — акцент
|
|
302
|
+
компонентов ниже перекрашивается вслед за выбором. */}
|
|
303
|
+
<RootThemeProvider value={{ colorScheme: 'light', brand: 'brandA', brandRole: 'main' }} brandColor={color}>
|
|
304
|
+
<Block>
|
|
305
|
+
<Flex gap='2m' align='center' wrap>
|
|
306
|
+
<Button appearance='primary' label='Действие' />
|
|
307
|
+
<Tag appearance='primary' label='Бренд' />
|
|
308
|
+
<Counter value={8} appearance='primary' />
|
|
309
|
+
</Flex>
|
|
310
|
+
</Block>
|
|
311
|
+
</RootThemeProvider>
|
|
312
|
+
</Flex>
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Императивный хук со scope
|
|
318
|
+
|
|
319
|
+
`useApplyCustomTheme({ color, scope })` инжектит правило, скоупленное на `#brand-hook-scope` — результат применяется ко всем компонентам внутри поддерева. Без `scope` правило глобальное (покрывает и порталы).
|
|
320
|
+
|
|
321
|
+
```tsx
|
|
322
|
+
import { Block } from '@cloud-ru/ds-block';
|
|
323
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
324
|
+
import { Counter } from '@cloud-ru/ds-counter';
|
|
325
|
+
import { SegmentControl } from '@cloud-ru/ds-segment-control';
|
|
326
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
327
|
+
import { RootThemeProvider, useApplyCustomTheme } from '@cloud-ru/ds-theme';
|
|
328
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
329
|
+
import { useState } from 'react';
|
|
330
|
+
|
|
331
|
+
const COLOR_ITEMS = [
|
|
332
|
+
{ value: '#8a2be2', label: 'Фиолетовый' },
|
|
333
|
+
{ value: '#ff7a00', label: 'Оранжевый' },
|
|
334
|
+
{ value: '#0077ff', label: 'Синий' },
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
// `scope` — CSS-селектор корня поддерева. Здесь правило скоуплено на `#brand-hook-scope`, поэтому
|
|
338
|
+
// бренд-акцент перекрашивается только внутри этого блока (и во всех компонентах ниже по дереву — Button,
|
|
339
|
+
// Tag, Counter). Без `scope` правило было бы глобальным и перекрасило бы всю страницу, включая порталы.
|
|
340
|
+
const SCOPE_ID = 'brand-hook-scope';
|
|
341
|
+
|
|
342
|
+
export function CustomBrandColorHook() {
|
|
343
|
+
const [color, setColor] = useState('#8a2be2');
|
|
344
|
+
|
|
345
|
+
useApplyCustomTheme({ color, scope: `#${SCOPE_ID}` });
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
349
|
+
<SegmentControl items={COLOR_ITEMS} value={color} onChange={value => setColor(String(value))} />
|
|
350
|
+
|
|
351
|
+
<div id={SCOPE_ID}>
|
|
352
|
+
<RootThemeProvider value={{ colorScheme: 'light', brand: 'brandA', brandRole: 'main' }}>
|
|
353
|
+
<Block>
|
|
354
|
+
<Flex gap='2m' align='center' wrap>
|
|
355
|
+
<Button appearance='primary' label='Внутри scope' />
|
|
356
|
+
<Tag appearance='primary' label='Бренд' />
|
|
357
|
+
<Counter value={8} appearance='primary' />
|
|
358
|
+
</Flex>
|
|
359
|
+
</Block>
|
|
360
|
+
</RootThemeProvider>
|
|
361
|
+
</div>
|
|
362
|
+
</Flex>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
|
+
import { ThemeAppearance } from '../../types/appearance';
|
|
3
|
+
export type ChildThemeProviderProps = {
|
|
4
|
+
/** Оси, переопределяемые в поддереве. Остальные наследуются от ближайшего родителя (слияние). */
|
|
5
|
+
value: Partial<ThemeAppearance>;
|
|
6
|
+
/**
|
|
7
|
+
* Внешний элемент для полного слитого набора `sn-*`. Если не задан — провайдер оборачивает
|
|
8
|
+
* children в `<div>` с этим набором.
|
|
9
|
+
*/
|
|
10
|
+
rootRef?: RefObject<HTMLElement | null>;
|
|
11
|
+
/** Дополнительный класс на wrapper-`<div>` (паддинги/фон). Только в wrapper-режиме (без `rootRef`). */
|
|
12
|
+
className?: string;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Вложенный провайдер оформления (Figma-цепочка модификаторов): читает ближайшее оформление, сливает
|
|
17
|
+
* свои `value`-переопределения и реэмитит полный слитый набор `sn-*` на границе. Потребители ниже
|
|
18
|
+
* читают уже слитое значение. Read-only — глобальное значение менять нельзя (это умеет только
|
|
19
|
+
* `RootThemeProvider`/`getGlobalThemeStore`).
|
|
20
|
+
*/
|
|
21
|
+
export declare function ChildThemeProvider({ value, rootRef, className, children }: ChildThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare namespace ChildThemeProvider {
|
|
23
|
+
var displayName: string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChildThemeProvider = ChildThemeProvider;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const context_kit_1 = require("@cloud-ru/ds-context-kit");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const appearanceContext_1 = require("../../context/appearanceContext");
|
|
8
|
+
const mergeAppearance_1 = require("../../utils/mergeAppearance");
|
|
9
|
+
const ThemeScope_1 = require("../ThemeScope");
|
|
10
|
+
/**
|
|
11
|
+
* Вложенный провайдер оформления (Figma-цепочка модификаторов): читает ближайшее оформление, сливает
|
|
12
|
+
* свои `value`-переопределения и реэмитит полный слитый набор `sn-*` на границе. Потребители ниже
|
|
13
|
+
* читают уже слитое значение. Read-only — глобальное значение менять нельзя (это умеет только
|
|
14
|
+
* `RootThemeProvider`/`getGlobalThemeStore`).
|
|
15
|
+
*/
|
|
16
|
+
function ChildThemeProvider({ value, rootRef, className, children }) {
|
|
17
|
+
const { appearance: parent } = (0, appearanceContext_1.useThemeAppearance)();
|
|
18
|
+
const { colorScheme, brand, brandRole, density, acrylic } = value;
|
|
19
|
+
const childStore = (0, react_1.useMemo)(() => (0, context_kit_1.staticStore)({
|
|
20
|
+
appearance: (0, mergeAppearance_1.mergeAppearance)(parent, { colorScheme, brand, brandRole, density, acrylic }),
|
|
21
|
+
setAppearance: undefined,
|
|
22
|
+
}), [parent, colorScheme, brand, brandRole, density, acrylic]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(appearanceContext_1.ThemeAppearanceStoreProvider, { store: childStore, children: (0, jsx_runtime_1.jsx)(ThemeScope_1.ThemeScope, { rootRef: rootRef, className: className, children: children }) }));
|
|
24
|
+
}
|
|
25
|
+
ChildThemeProvider.displayName = 'ChildThemeProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ChildThemeProvider';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ChildThemeProvider"), exports);
|