@cloud-ru/ds-adaptive 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 +195 -0
- package/dist/cjs/components/AdaptiveProvider/AdaptiveProvider.d.ts +15 -0
- package/dist/cjs/components/AdaptiveProvider/AdaptiveProvider.js +17 -0
- package/dist/cjs/components/AdaptiveProvider/index.d.ts +1 -0
- package/dist/cjs/components/AdaptiveProvider/index.js +17 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/components/withLayoutType/index.d.ts +1 -0
- package/dist/cjs/components/withLayoutType/index.js +17 -0
- package/dist/cjs/components/withLayoutType/withLayoutType.d.ts +14 -0
- package/dist/cjs/components/withLayoutType/withLayoutType.js +20 -0
- package/dist/cjs/constants/adaptive.d.ts +57 -0
- package/dist/cjs/constants/adaptive.js +61 -0
- package/dist/cjs/constants/index.d.ts +1 -0
- package/dist/cjs/constants/index.js +17 -0
- package/dist/cjs/context/adaptiveContext.d.ts +15 -0
- package/dist/cjs/context/adaptiveContext.js +15 -0
- package/dist/cjs/context/index.d.ts +2 -0
- package/dist/cjs/context/index.js +5 -0
- package/dist/cjs/hooks/index.d.ts +4 -0
- package/dist/cjs/hooks/index.js +20 -0
- package/dist/cjs/hooks/useAdaptiveBootstrap.d.ts +18 -0
- package/dist/cjs/hooks/useAdaptiveBootstrap.js +22 -0
- package/dist/cjs/hooks/useClientLayoutType.d.ts +10 -0
- package/dist/cjs/hooks/useClientLayoutType.js +35 -0
- package/dist/cjs/hooks/useLayoutDefaults.d.ts +14 -0
- package/dist/cjs/hooks/useLayoutDefaults.js +21 -0
- package/dist/cjs/hooks/useMatchMedia.d.ts +18 -0
- package/dist/cjs/hooks/useMatchMedia.js +42 -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 +10 -0
- package/dist/cjs/ssr.js +32 -0
- package/dist/cjs/store/createAdaptiveStore.d.ts +22 -0
- package/dist/cjs/store/createAdaptiveStore.js +29 -0
- package/dist/cjs/store/globalStore.d.ts +20 -0
- package/dist/cjs/store/globalStore.js +43 -0
- package/dist/cjs/store/index.d.ts +2 -0
- package/dist/cjs/store/index.js +18 -0
- package/dist/cjs/types/adaptive.d.ts +6 -0
- package/dist/cjs/types/adaptive.js +2 -0
- package/dist/cjs/types/index.d.ts +3 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/layoutTypes.d.ts +13 -0
- package/dist/cjs/types/layoutTypes.js +10 -0
- package/dist/cjs/types/presets.d.ts +6 -0
- package/dist/cjs/types/presets.js +2 -0
- package/dist/cjs/types/valueOf.d.ts +2 -0
- package/dist/cjs/types/valueOf.js +2 -0
- package/dist/cjs/utils/getAdaptive.d.ts +15 -0
- package/dist/cjs/utils/getAdaptive.js +39 -0
- package/dist/cjs/utils/getLayoutBootstrapScript.d.ts +2 -0
- package/dist/cjs/utils/getLayoutBootstrapScript.js +9 -0
- package/dist/cjs/utils/getMatchMedia.d.ts +12 -0
- package/dist/cjs/utils/getMatchMedia.js +24 -0
- package/dist/cjs/utils/getSSRInitialLayoutType.d.ts +21 -0
- package/dist/cjs/utils/getSSRInitialLayoutType.js +32 -0
- package/dist/cjs/utils/getUserAgentInfo.d.ts +43 -0
- package/dist/cjs/utils/getUserAgentInfo.js +114 -0
- package/dist/cjs/utils/index.d.ts +6 -0
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/isBrowser.d.ts +3 -0
- package/dist/cjs/utils/isBrowser.js +9 -0
- package/dist/cjs/utils/layoutTypeFromMatchMedia.d.ts +4 -0
- package/dist/cjs/utils/layoutTypeFromMatchMedia.js +18 -0
- package/dist/cjs/utils/layoutTypeFromUserAgent.d.ts +6 -0
- package/dist/cjs/utils/layoutTypeFromUserAgent.js +20 -0
- package/dist/cjs/utils/layoutTypeFromWidth.d.ts +3 -0
- package/dist/cjs/utils/layoutTypeFromWidth.js +18 -0
- package/dist/cjs/utils/resolveByLayout.d.ts +28 -0
- package/dist/cjs/utils/resolveByLayout.js +49 -0
- package/dist/cjs/utils/resolveLayoutType.d.ts +11 -0
- package/dist/cjs/utils/resolveLayoutType.js +19 -0
- package/dist/esm/components/AdaptiveProvider/AdaptiveProvider.d.ts +15 -0
- package/dist/esm/components/AdaptiveProvider/AdaptiveProvider.js +14 -0
- package/dist/esm/components/AdaptiveProvider/index.d.ts +1 -0
- package/dist/esm/components/AdaptiveProvider/index.js +1 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/withLayoutType/index.d.ts +1 -0
- package/dist/esm/components/withLayoutType/index.js +1 -0
- package/dist/esm/components/withLayoutType/withLayoutType.d.ts +14 -0
- package/dist/esm/components/withLayoutType/withLayoutType.js +17 -0
- package/dist/esm/constants/adaptive.d.ts +57 -0
- package/dist/esm/constants/adaptive.js +57 -0
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/context/adaptiveContext.d.ts +15 -0
- package/dist/esm/context/adaptiveContext.js +11 -0
- package/dist/esm/context/index.d.ts +2 -0
- package/dist/esm/context/index.js +1 -0
- package/dist/esm/hooks/index.d.ts +4 -0
- package/dist/esm/hooks/index.js +4 -0
- package/dist/esm/hooks/useAdaptiveBootstrap.d.ts +18 -0
- package/dist/esm/hooks/useAdaptiveBootstrap.js +19 -0
- package/dist/esm/hooks/useClientLayoutType.d.ts +10 -0
- package/dist/esm/hooks/useClientLayoutType.js +32 -0
- package/dist/esm/hooks/useLayoutDefaults.d.ts +14 -0
- package/dist/esm/hooks/useLayoutDefaults.js +18 -0
- package/dist/esm/hooks/useMatchMedia.d.ts +18 -0
- package/dist/esm/hooks/useMatchMedia.js +37 -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 +10 -0
- package/dist/esm/ssr.js +16 -0
- package/dist/esm/store/createAdaptiveStore.d.ts +22 -0
- package/dist/esm/store/createAdaptiveStore.js +26 -0
- package/dist/esm/store/globalStore.d.ts +20 -0
- package/dist/esm/store/globalStore.js +40 -0
- package/dist/esm/store/index.d.ts +2 -0
- package/dist/esm/store/index.js +2 -0
- package/dist/esm/types/adaptive.d.ts +6 -0
- package/dist/esm/types/adaptive.js +1 -0
- package/dist/esm/types/index.d.ts +3 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/layoutTypes.d.ts +13 -0
- package/dist/esm/types/layoutTypes.js +7 -0
- package/dist/esm/types/presets.d.ts +6 -0
- package/dist/esm/types/presets.js +1 -0
- package/dist/esm/types/valueOf.d.ts +2 -0
- package/dist/esm/types/valueOf.js +1 -0
- package/dist/esm/utils/getAdaptive.d.ts +15 -0
- package/dist/esm/utils/getAdaptive.js +36 -0
- package/dist/esm/utils/getLayoutBootstrapScript.d.ts +2 -0
- package/dist/esm/utils/getLayoutBootstrapScript.js +6 -0
- package/dist/esm/utils/getMatchMedia.d.ts +12 -0
- package/dist/esm/utils/getMatchMedia.js +18 -0
- package/dist/esm/utils/getSSRInitialLayoutType.d.ts +21 -0
- package/dist/esm/utils/getSSRInitialLayoutType.js +28 -0
- package/dist/esm/utils/getUserAgentInfo.d.ts +43 -0
- package/dist/esm/utils/getUserAgentInfo.js +110 -0
- package/dist/esm/utils/index.d.ts +6 -0
- package/dist/esm/utils/index.js +6 -0
- package/dist/esm/utils/isBrowser.d.ts +3 -0
- package/dist/esm/utils/isBrowser.js +6 -0
- package/dist/esm/utils/layoutTypeFromMatchMedia.d.ts +4 -0
- package/dist/esm/utils/layoutTypeFromMatchMedia.js +15 -0
- package/dist/esm/utils/layoutTypeFromUserAgent.d.ts +6 -0
- package/dist/esm/utils/layoutTypeFromUserAgent.js +17 -0
- package/dist/esm/utils/layoutTypeFromWidth.d.ts +3 -0
- package/dist/esm/utils/layoutTypeFromWidth.js +15 -0
- package/dist/esm/utils/resolveByLayout.d.ts +28 -0
- package/dist/esm/utils/resolveByLayout.js +45 -0
- package/dist/esm/utils/resolveLayoutType.d.ts +11 -0
- package/dist/esm/utils/resolveLayoutType.js +15 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +45 -0
- package/src/components/AdaptiveProvider/AdaptiveProvider.tsx +28 -0
- package/src/components/AdaptiveProvider/index.ts +1 -0
- package/src/components/index.ts +2 -0
- package/src/components/withLayoutType/index.ts +1 -0
- package/src/components/withLayoutType/withLayoutType.tsx +26 -0
- package/src/constants/adaptive.ts +73 -0
- package/src/constants/index.ts +1 -0
- package/src/context/adaptiveContext.ts +27 -0
- package/src/context/index.ts +2 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAdaptiveBootstrap.ts +38 -0
- package/src/hooks/useClientLayoutType.ts +51 -0
- package/src/hooks/useLayoutDefaults.ts +21 -0
- package/src/hooks/useMatchMedia.ts +52 -0
- package/src/index.ts +7 -0
- package/src/keys.ts +18 -0
- package/src/ssr.ts +16 -0
- package/src/store/createAdaptiveStore.ts +42 -0
- package/src/store/globalStore.ts +57 -0
- package/src/store/index.ts +2 -0
- package/src/types/adaptive.ts +8 -0
- package/src/types/index.ts +3 -0
- package/src/types/layoutTypes.ts +15 -0
- package/src/types/presets.ts +7 -0
- package/src/types/valueOf.ts +2 -0
- package/src/utils/getAdaptive.ts +46 -0
- package/src/utils/getLayoutBootstrapScript.ts +8 -0
- package/src/utils/getMatchMedia.ts +36 -0
- package/src/utils/getSSRInitialLayoutType.ts +50 -0
- package/src/utils/getUserAgentInfo.ts +145 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/isBrowser.ts +6 -0
- package/src/utils/layoutTypeFromMatchMedia.ts +20 -0
- package/src/utils/layoutTypeFromUserAgent.ts +19 -0
- package/src/utils/layoutTypeFromWidth.ts +20 -0
- package/src/utils/resolveByLayout.ts +72 -0
- package/src/utils/resolveLayoutType.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,195 @@
|
|
|
1
|
+
# Adaptive
|
|
2
|
+
|
|
3
|
+
`@cloud-ru/ds-adaptive` — React Context текущей раскладки (layoutType) — переключает компоненты дизайн-системы между mobile и desktop поверхностями.
|
|
4
|
+
|
|
5
|
+
`@cloud-ru/ds-adaptive` несёт через React Context текущую раскладку экрана — `layoutType` (`mobile` / `tablet` / `desktopSmall` / `desktop`). `AdaptiveProvider` ставится один раз в корне приложения, а адаптивные компоненты дизайн-системы (`Droplist`, `Modal`, `Drawer`, `Dropdown` и др.) сами читают раскладку из контекста и переключают поверхность: на `mobile` обычно открывается `BottomSheet`, иначе — десктопный popover / modal.
|
|
6
|
+
|
|
7
|
+
Полное руководство по модели — в паттерне [Адаптивность — руководство](/patterns/adaptive).
|
|
8
|
+
|
|
9
|
+
## Когда использовать
|
|
10
|
+
|
|
11
|
+
- Приложение использует адаптивные компоненты дизайн-системы и должно переключать их между mobile и desktop поверхностями. Провайдер ставится один раз в корне.
|
|
12
|
+
- Раскладка считается в корне через `useAdaptiveBootstrap()` (user-agent + media-query) и раздаётся вложенным компонентам без проброса пропа.
|
|
13
|
+
- Микрофронт получает раскладку из реактивного стора хост-приложения — провайдер подключается через `store` (адаптер собирается `createAdaptiveStore`).
|
|
14
|
+
- Серверный рендеринг: раскладка вычисляется из user-agent запроса через подпуть `@cloud-ru/ds-adaptive/ssr` (чистые функции без React Context).
|
|
15
|
+
|
|
16
|
+
Точечно зафиксировать платформу для поддерева можно вложенным `<AdaptiveProvider layoutType=…>` или HOC `withLayoutType(Component, …)` — он затеняет внешний контекст. Пропа `layoutType` у самих компонентов нет: форс идёт только через контекст.
|
|
17
|
+
|
|
18
|
+
## Установка
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @cloud-ru/ds-adaptive
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { AdaptiveProvider, withLayoutType, useAdaptiveBootstrap, useAdaptiveLayout, isMobileLayout, LAYOUT_TYPE } from '@cloud-ru/ds-adaptive'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Примеры использования
|
|
29
|
+
|
|
30
|
+
### AdaptiveProvider в корне
|
|
31
|
+
|
|
32
|
+
Провайдер раздаёт `layoutType`; вложенный компонент читает его через `useAdaptiveLayout()` и `isMobileLayout()`.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { AdaptiveProvider, isMobileLayout, LAYOUT_TYPE, LayoutType, useAdaptiveLayout } from '@cloud-ru/ds-adaptive';
|
|
36
|
+
import { SegmentControl } from '@cloud-ru/ds-segment-control';
|
|
37
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
38
|
+
import { Typography } from '@cloud-ru/ds-typography';
|
|
39
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
40
|
+
import { useState } from 'react';
|
|
41
|
+
|
|
42
|
+
const LAYOUT_ITEMS = Object.values(LAYOUT_TYPE).map(value => ({ value, label: value }));
|
|
43
|
+
|
|
44
|
+
// Потребитель берёт раскладку из AdaptiveProvider через useAdaptiveLayout() — без пропа и обёрток.
|
|
45
|
+
// Так же ведут себя Adaptive*-компоненты внутри (на mobile уходят в BottomSheet).
|
|
46
|
+
function LayoutSurface() {
|
|
47
|
+
const { layoutType } = useAdaptiveLayout();
|
|
48
|
+
const mobile = isMobileLayout(layoutType);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Flex gap='2m' align='center' wrap>
|
|
52
|
+
<Tag
|
|
53
|
+
appearance={mobile ? 'blue' : 'green'}
|
|
54
|
+
label={mobile ? 'Мобильная ветка → BottomSheet' : 'Десктопная ветка'}
|
|
55
|
+
/>
|
|
56
|
+
<Typography variant='body' size='s'>
|
|
57
|
+
useAdaptiveLayout(): {layoutType}
|
|
58
|
+
</Typography>
|
|
59
|
+
</Flex>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ProviderBasic() {
|
|
64
|
+
const [layoutType, setLayoutType] = useState<LayoutType>(LAYOUT_TYPE.Desktop);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<AdaptiveProvider layoutType={layoutType}>
|
|
68
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
69
|
+
<SegmentControl
|
|
70
|
+
items={LAYOUT_ITEMS}
|
|
71
|
+
value={layoutType}
|
|
72
|
+
onChange={value => setLayoutType(value as LayoutType)}
|
|
73
|
+
/>
|
|
74
|
+
<LayoutSurface />
|
|
75
|
+
</Flex>
|
|
76
|
+
</AdaptiveProvider>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Свои брейкпоинты приложения
|
|
82
|
+
|
|
83
|
+
`useAdaptiveBootstrap({ breakpoints })` переопределяет пороги раскладки; набор тиров остаётся прежним.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { AdaptiveProvider, isMobileLayout, useAdaptiveBootstrap, useAdaptiveLayout } from '@cloud-ru/ds-adaptive';
|
|
87
|
+
import { Tag } from '@cloud-ru/ds-tag';
|
|
88
|
+
import { Typography } from '@cloud-ru/ds-typography';
|
|
89
|
+
import { Flex } from '@cloud-ru/ds-uikit-product-flex';
|
|
90
|
+
|
|
91
|
+
// Раскладка приходит из контекста; Tag перекрашивается, когда ширина окна пересекает порог.
|
|
92
|
+
function LayoutSurface() {
|
|
93
|
+
const { layoutType } = useAdaptiveLayout();
|
|
94
|
+
const mobile = isMobileLayout(layoutType);
|
|
95
|
+
|
|
96
|
+
return <Tag appearance={mobile ? 'blue' : 'green'} label={`layoutType: ${layoutType}`} />;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function CustomBreakpoints() {
|
|
100
|
+
// Брейкпоинты переопределяются на уровне приложения: mobile-порог опущен с 767 до 480 px.
|
|
101
|
+
// useAdaptiveBootstrap() читает ширину окна в корне приложения и передаёт результат в AdaptiveProvider.
|
|
102
|
+
const { layoutType } = useAdaptiveBootstrap({ breakpoints: { mobile: 480 } });
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<AdaptiveProvider layoutType={layoutType}>
|
|
106
|
+
<Flex direction='column' gap='2m' align='flex-start'>
|
|
107
|
+
<Typography variant='body' size='s'>
|
|
108
|
+
Порог mobile опущен до 480 px. Сузьте окно до этой ширины, чтобы раскладка стала мобильной.
|
|
109
|
+
</Typography>
|
|
110
|
+
<LayoutSurface />
|
|
111
|
+
</Flex>
|
|
112
|
+
</AdaptiveProvider>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Props
|
|
118
|
+
|
|
119
|
+
**AdaptiveProviderProps**
|
|
120
|
+
|
|
121
|
+
| Prop | Type | Default | Description |
|
|
122
|
+
|------|------|---------|-------------|
|
|
123
|
+
| `children` | `string \| number \| boolean \| ReactElement<any, string \| JSXElementConstructor<any>> \| Iterable<ReactNode> \| ReactPortal \| null \| undefined` | — | |
|
|
124
|
+
| `layoutType` | `"desktop"` \| `"desktopSmall"` \| `"mobile"` \| `"tablet"` | — | Статичная раскладка (SSR — значение на запрос, либо `useAdaptiveBootstrap()` в корне CSR). Реактивный источник — через `store`. |
|
|
125
|
+
| `store` | `AdaptiveStore` | — | Внешний реактивный стор раскладки; приоритетнее `layoutType`, обновляет подписчиков без перерендера провайдера. |
|
|
126
|
+
|
|
127
|
+
#### Related types
|
|
128
|
+
|
|
129
|
+
**AdaptiveStore**
|
|
130
|
+
|
|
131
|
+
| Prop | Type | Default | Description |
|
|
132
|
+
|------|------|---------|-------------|
|
|
133
|
+
| `getServerSnapshot` | `(() => AdaptiveContextValue) \| undefined` | — | Значение для SSR/гидрации. Если не задан — используется `getSnapshot`. |
|
|
134
|
+
| `getSnapshot` | `() => AdaptiveContextValue` | — | Текущее значение. Обязан возвращать стабильную (по `Object.is`) ссылку, пока значение не менялось. |
|
|
135
|
+
| `subscribe` | `(onStoreChange: () => void) => () => void` | — | Подписка на изменения; возвращает функцию отписки. |
|
|
136
|
+
|
|
137
|
+
- `LayoutType` = `"desktop"` \| `"desktopSmall"` \| `"mobile"` \| `"tablet"`
|
|
138
|
+
|
|
139
|
+
## Смотри также
|
|
140
|
+
|
|
141
|
+
- [Адаптивность — руководство](/patterns/adaptive) — полная модель адаптивных компонентов `@ds`.
|
|
142
|
+
- [Оформление — тема, бренд, плотность](/patterns/theme) — модель провайдера темы.
|
|
143
|
+
- [Локализация — строки в пакетах](/patterns/localization) — модель провайдера локали.
|
|
144
|
+
- [Порталы — корневой DOM-узел](/patterns/portal-context) — модель провайдера портала.
|
|
145
|
+
- **Locale** — рантайм локализации.
|
|
146
|
+
- **PortalContext** — корневой DOM-узел для порталов.
|
|
147
|
+
## Раскладки и брейкпоинты
|
|
148
|
+
|
|
149
|
+
`layoutType` выбирается по ширине окна (`max-width` в px). Дефолтные пороги:
|
|
150
|
+
|
|
151
|
+
| layoutType | Порог | Назначение |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| `mobile` | ≤ 767 px | Телефон — единственный тир, уходящий в mobile-ветку (`BottomSheet`). |
|
|
154
|
+
| `tablet` | ≤ 1023 px | Планшет — десктопная ветка. |
|
|
155
|
+
| `desktopSmall` | ≤ 1279 px | Узкий десктоп — десктопная ветка. |
|
|
156
|
+
| `desktop` | ≤ 1439 px | Десктоп — десктопная ветка. SSR-baseline. |
|
|
157
|
+
|
|
158
|
+
Ширина ≥ 1440 px (`large`) достижима только через `useAdaptiveMatchMedia()` — в `layoutType` она не маппится. Пороги переопределяются на уровне приложения через `useAdaptiveBootstrap({ breakpoints })`.
|
|
159
|
+
|
|
160
|
+
На сервере и до монтирования раскладка равна `desktop` (`DEFAULT_LAYOUT_TYPE`) — это baseline без доступа к вьюпорту, а не «всегда desktop». На сервере её можно выбрать по request-User-Agent (см. рецепт «Сервер» ниже). Зафиксировать раскладку для поддерева можно вложенным `<AdaptiveProvider layoutType=…>` или `withLayoutType(...)` — он затеняет внешний контекст.
|
|
161
|
+
|
|
162
|
+
## Подписка на раскладку
|
|
163
|
+
|
|
164
|
+
Раскладку **вычисляют один раз в корне** и раздают через `AdaptiveProvider`; компоненты её только **читают**. Утилиты:
|
|
165
|
+
|
|
166
|
+
**Реактивный корень (CSR).** `useAdaptiveBootstrap()` вычисляет `layoutType` по user-agent + media-query и сам переподписывается на изменения вьюпорта (resize / поворот). Результат скармливается провайдеру:
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { AdaptiveProvider, useAdaptiveBootstrap } from '@cloud-ru/ds-adaptive'
|
|
170
|
+
|
|
171
|
+
function Root({ app }) {
|
|
172
|
+
const { layoutType } = useAdaptiveBootstrap() // ре-вычисляется при смене ширины окна
|
|
173
|
+
return <AdaptiveProvider layoutType={layoutType}>{app}</AdaptiveProvider>
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Чтение в компоненте.** `useAdaptiveLayout()` берёт раскладку из ближайшего `AdaptiveProvider` и ре-рендерит потребителя при её смене:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import { isMobileLayout, useAdaptiveLayout } from '@cloud-ru/ds-adaptive'
|
|
181
|
+
|
|
182
|
+
const { layoutType } = useAdaptiveLayout()
|
|
183
|
+
if (isMobileLayout(layoutType)) { /* mobile-ветка */ }
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Произвольные media-query.** Для условий вне `layoutType` (например, тир `large` ≥ 1440 px) — `useAdaptiveMatchMedia()`.
|
|
187
|
+
|
|
188
|
+
**Сервер (SSR по User-Agent).** На сервере `navigator` недоступен, поэтому `useAdaptiveBootstrap` отдаёт `desktop`. Чтобы убрать flip при гидрации — резолвьте раскладку из request-UA через `getAdaptive` из серверобезопасного входа `@cloud-ru/ds-adaptive/ssr` (без React-импортов) и передайте статикой:
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
import { getAdaptive, INITIAL_ADAPTIVE_QUERIES_VALUE } from '@cloud-ru/ds-adaptive/ssr'
|
|
192
|
+
|
|
193
|
+
const { layoutType } = getAdaptive(INITIAL_ADAPTIVE_QUERIES_VALUE, headers().get('user-agent'))
|
|
194
|
+
// <AdaptiveProvider layoutType={layoutType}>{children}</AdaptiveProvider>
|
|
195
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AdaptiveStore } from '../../context/adaptiveContext';
|
|
3
|
+
import { LayoutType } from '../../types/layoutTypes';
|
|
4
|
+
export type AdaptiveProviderProps = {
|
|
5
|
+
/** Статичная раскладка (SSR — значение на запрос, либо `useAdaptiveBootstrap()` в корне CSR). Реактивный источник — через `store`. */
|
|
6
|
+
layoutType?: LayoutType;
|
|
7
|
+
/** Внешний реактивный стор раскладки; приоритетнее `layoutType`, обновляет подписчиков без перерендера провайдера. */
|
|
8
|
+
store?: AdaptiveStore;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Провайдер текущей раскладки для `Adaptive*`-компонентов. Ставится один раз в корне; вложенные
|
|
13
|
+
* `Adaptive*` берут `layoutType` из контекста. Принимает статичный `layoutType` либо реактивный `store`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function AdaptiveProvider({ layoutType, store, children }: AdaptiveProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdaptiveProvider = AdaptiveProvider;
|
|
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 adaptive_1 = require("../../constants/adaptive");
|
|
8
|
+
const adaptiveContext_1 = require("../../context/adaptiveContext");
|
|
9
|
+
/**
|
|
10
|
+
* Провайдер текущей раскладки для `Adaptive*`-компонентов. Ставится один раз в корне; вложенные
|
|
11
|
+
* `Adaptive*` берут `layoutType` из контекста. Принимает статичный `layoutType` либо реактивный `store`.
|
|
12
|
+
*/
|
|
13
|
+
function AdaptiveProvider({ layoutType, store, children }) {
|
|
14
|
+
// Стабильный snapshot: новый объект только при смене layoutType, иначе useSyncExternalStore зациклится.
|
|
15
|
+
const staticAdaptiveStore = (0, react_1.useMemo)(() => (0, context_kit_1.staticStore)({ layoutType: layoutType ?? adaptive_1.DEFAULT_LAYOUT_TYPE }), [layoutType]);
|
|
16
|
+
return (0, jsx_runtime_1.jsx)(adaptiveContext_1.AdaptiveStoreProvider, { store: store ?? staticAdaptiveStore, children: children });
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AdaptiveProvider';
|
|
@@ -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("./AdaptiveProvider"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./AdaptiveProvider"), exports);
|
|
18
|
+
__exportStar(require("./withLayoutType"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './withLayoutType';
|
|
@@ -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("./withLayoutType"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { LayoutType } from '../../types/layoutTypes';
|
|
3
|
+
/**
|
|
4
|
+
* HOC форса раскладки: оборачивает компонент в `<AdaptiveProvider layoutType=…>`, фиксируя раскладку
|
|
5
|
+
* для него и поддерева. Дженерик-параметры стираются (для них — инлайновый `AdaptiveProvider`).
|
|
6
|
+
* Вызывать на module-scope, не в теле рендера.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const DesktopSection = withLayoutType(Section, 'desktop');
|
|
10
|
+
*/
|
|
11
|
+
export declare function withLayoutType<P extends object>(Component: ComponentType<P>, layoutType: LayoutType): {
|
|
12
|
+
(props: P): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
displayName: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withLayoutType = withLayoutType;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const AdaptiveProvider_1 = require("../AdaptiveProvider");
|
|
6
|
+
/**
|
|
7
|
+
* HOC форса раскладки: оборачивает компонент в `<AdaptiveProvider layoutType=…>`, фиксируя раскладку
|
|
8
|
+
* для него и поддерева. Дженерик-параметры стираются (для них — инлайновый `AdaptiveProvider`).
|
|
9
|
+
* Вызывать на module-scope, не в теле рендера.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const DesktopSection = withLayoutType(Section, 'desktop');
|
|
13
|
+
*/
|
|
14
|
+
function withLayoutType(Component, layoutType) {
|
|
15
|
+
function Fixed(props) {
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(AdaptiveProvider_1.AdaptiveProvider, { layoutType: layoutType, children: (0, jsx_runtime_1.jsx)(Component, { ...props }) }));
|
|
17
|
+
}
|
|
18
|
+
Fixed.displayName = `withLayoutType(${Component.displayName ?? Component.name}, ${layoutType})`;
|
|
19
|
+
return Fixed;
|
|
20
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LayoutType } from '../types/layoutTypes';
|
|
2
|
+
/** Брейкпоинты adaptive-раскладки (max-width в px). Форма дефолта `ADAPTIVE_BREAKPOINT`. */
|
|
3
|
+
export type AdaptiveBreakpoints = {
|
|
4
|
+
mobile: number;
|
|
5
|
+
tablet: number;
|
|
6
|
+
desktopSmall: number;
|
|
7
|
+
desktop: number;
|
|
8
|
+
};
|
|
9
|
+
/** Брейкпоинты adaptive-раскладки (max-width в px), по которым `useAdaptiveBootstrap` выбирает `layoutType`. */
|
|
10
|
+
export declare const ADAPTIVE_BREAKPOINT: AdaptiveBreakpoints;
|
|
11
|
+
/** CSS media-query строки, собранные из `ADAPTIVE_BREAKPOINT`. */
|
|
12
|
+
export declare const CSS_BREAKPOINTS: {
|
|
13
|
+
readonly mobile: `(max-width: ${number}px)`;
|
|
14
|
+
readonly tablet: `(max-width: ${number}px)`;
|
|
15
|
+
readonly desktopSmall: `(max-width: ${number}px)`;
|
|
16
|
+
readonly desktop: `(max-width: ${number}px)`;
|
|
17
|
+
readonly large: `(min-width: ${number}px)`;
|
|
18
|
+
};
|
|
19
|
+
/** Ключи media-query, отслеживаемых `useAdaptiveMatchMedia`. */
|
|
20
|
+
export declare const ADAPTIVE_QUERY: {
|
|
21
|
+
readonly IsMobile: "isMobile";
|
|
22
|
+
readonly IsTablet: "isTablet";
|
|
23
|
+
readonly IsSmallDesktop: "isSmallDesktop";
|
|
24
|
+
readonly IsDesktop: "isDesktop";
|
|
25
|
+
readonly IsLarge: "isLarge";
|
|
26
|
+
};
|
|
27
|
+
/** Карта `query-key → media-query строка` для подписки. */
|
|
28
|
+
export declare const ADAPTIVE_QUERIES: {
|
|
29
|
+
readonly isMobile: `(max-width: ${number}px)`;
|
|
30
|
+
readonly isTablet: `(max-width: ${number}px)`;
|
|
31
|
+
readonly isSmallDesktop: `(max-width: ${number}px)`;
|
|
32
|
+
readonly isDesktop: `(max-width: ${number}px)`;
|
|
33
|
+
readonly isLarge: `(min-width: ${number}px)`;
|
|
34
|
+
};
|
|
35
|
+
/** Собирает карту adaptive media-query из произвольных брейкпоинтов — для per-app override. */
|
|
36
|
+
export declare function buildAdaptiveQueries(breakpoints: AdaptiveBreakpoints): {
|
|
37
|
+
isMobile: string;
|
|
38
|
+
isTablet: string;
|
|
39
|
+
isSmallDesktop: string;
|
|
40
|
+
isDesktop: string;
|
|
41
|
+
isLarge: string;
|
|
42
|
+
};
|
|
43
|
+
/** SSR-safe начальные значения (на сервере ни один media-query не матчится). */
|
|
44
|
+
export declare const INITIAL_ADAPTIVE_QUERIES_VALUE: {
|
|
45
|
+
readonly isMobile: false;
|
|
46
|
+
readonly isTablet: false;
|
|
47
|
+
readonly isSmallDesktop: false;
|
|
48
|
+
readonly isDesktop: false;
|
|
49
|
+
readonly isLarge: false;
|
|
50
|
+
};
|
|
51
|
+
/** SSR-baseline раскладки адаптивных компонентов: на сервере и до mount — desktop. */
|
|
52
|
+
export declare const DEFAULT_LAYOUT_TYPE: LayoutType;
|
|
53
|
+
/** Наборы `layoutType`, уходящие по mobile-ветке surface-swap. Один источник для runtime, stories и docs. */
|
|
54
|
+
export declare const LAYOUT_SPLIT_MOBILE_TIERS: {
|
|
55
|
+
/** Только phone уходит в mobile-ветку. */
|
|
56
|
+
readonly mobileOnly: readonly ["mobile"];
|
|
57
|
+
};
|