@cloud-ru/ds-tabs 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 +300 -0
- package/dist/cjs/components/ScrollButton/ScrollButton.d.ts +8 -0
- package/dist/cjs/components/ScrollButton/ScrollButton.js +19 -0
- package/dist/cjs/components/ScrollButton/index.d.ts +1 -0
- package/dist/cjs/components/ScrollButton/index.js +17 -0
- package/dist/cjs/components/ScrollButton/styles.module.css +50 -0
- package/dist/cjs/components/Tab/Tab.d.ts +25 -0
- package/dist/cjs/components/Tab/Tab.js +78 -0
- package/dist/cjs/components/Tab/index.d.ts +1 -0
- package/dist/cjs/components/Tab/index.js +17 -0
- package/dist/cjs/components/Tab/styles.module.css +105 -0
- package/dist/cjs/components/TabBar/TabBar.d.ts +30 -0
- package/dist/cjs/components/TabBar/TabBar.js +119 -0
- package/dist/cjs/components/TabBar/hooks.d.ts +18 -0
- package/dist/cjs/components/TabBar/hooks.js +103 -0
- package/dist/cjs/components/TabBar/index.d.ts +1 -0
- package/dist/cjs/components/TabBar/index.js +17 -0
- package/dist/cjs/components/TabBar/styles.module.css +187 -0
- package/dist/cjs/components/TabContent/TabContent.d.ts +8 -0
- package/dist/cjs/components/TabContent/TabContent.js +14 -0
- package/dist/cjs/components/TabContent/index.d.ts +1 -0
- package/dist/cjs/components/TabContent/index.js +17 -0
- package/dist/cjs/components/Tabs/Tabs.d.ts +21 -0
- package/dist/cjs/components/Tabs/Tabs.js +39 -0
- package/dist/cjs/components/Tabs/index.d.ts +1 -0
- package/dist/cjs/components/Tabs/index.js +17 -0
- package/dist/cjs/components/Tabs/styles.module.css +21 -0
- package/dist/cjs/components/index.d.ts +5 -0
- package/dist/cjs/components/index.js +21 -0
- package/dist/cjs/constants.d.ts +32 -0
- package/dist/cjs/constants.js +35 -0
- package/dist/cjs/context.d.ts +17 -0
- package/dist/cjs/context.js +12 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/style.css +363 -0
- package/dist/cjs/types.d.ts +17 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils.d.ts +1 -0
- package/dist/cjs/utils.js +6 -0
- package/dist/esm/components/ScrollButton/ScrollButton.d.ts +8 -0
- package/dist/esm/components/ScrollButton/ScrollButton.js +13 -0
- package/dist/esm/components/ScrollButton/index.d.ts +1 -0
- package/dist/esm/components/ScrollButton/index.js +1 -0
- package/dist/esm/components/ScrollButton/styles.module.css +50 -0
- package/dist/esm/components/Tab/Tab.d.ts +25 -0
- package/dist/esm/components/Tab/Tab.js +72 -0
- package/dist/esm/components/Tab/index.d.ts +1 -0
- package/dist/esm/components/Tab/index.js +1 -0
- package/dist/esm/components/Tab/styles.module.css +105 -0
- package/dist/esm/components/TabBar/TabBar.d.ts +30 -0
- package/dist/esm/components/TabBar/TabBar.js +113 -0
- package/dist/esm/components/TabBar/hooks.d.ts +18 -0
- package/dist/esm/components/TabBar/hooks.js +99 -0
- package/dist/esm/components/TabBar/index.d.ts +1 -0
- package/dist/esm/components/TabBar/index.js +1 -0
- package/dist/esm/components/TabBar/styles.module.css +187 -0
- package/dist/esm/components/TabContent/TabContent.d.ts +8 -0
- package/dist/esm/components/TabContent/TabContent.js +11 -0
- package/dist/esm/components/TabContent/index.d.ts +1 -0
- package/dist/esm/components/TabContent/index.js +1 -0
- package/dist/esm/components/Tabs/Tabs.d.ts +21 -0
- package/dist/esm/components/Tabs/Tabs.js +33 -0
- package/dist/esm/components/Tabs/index.d.ts +1 -0
- package/dist/esm/components/Tabs/index.js +1 -0
- package/dist/esm/components/Tabs/styles.module.css +21 -0
- package/dist/esm/components/index.d.ts +5 -0
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/constants.d.ts +32 -0
- package/dist/esm/constants.js +32 -0
- package/dist/esm/context.d.ts +17 -0
- package/dist/esm/context.js +7 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/style.css +363 -0
- package/dist/esm/types.d.ts +17 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +3 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +48 -0
- package/src/components/ScrollButton/ScrollButton.tsx +42 -0
- package/src/components/ScrollButton/index.ts +1 -0
- package/src/components/ScrollButton/styles.module.scss +46 -0
- package/src/components/Tab/Tab.tsx +151 -0
- package/src/components/Tab/index.ts +1 -0
- package/src/components/Tab/styles.module.scss +135 -0
- package/src/components/TabBar/TabBar.tsx +269 -0
- package/src/components/TabBar/hooks.ts +139 -0
- package/src/components/TabBar/index.ts +1 -0
- package/src/components/TabBar/styles.module.scss +241 -0
- package/src/components/TabContent/TabContent.tsx +34 -0
- package/src/components/TabContent/index.ts +1 -0
- package/src/components/Tabs/Tabs.tsx +61 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/Tabs/styles.module.scss +25 -0
- package/src/components/index.ts +5 -0
- package/src/constants.ts +35 -0
- package/src/context.tsx +13 -0
- package/src/index.ts +5 -0
- package/src/types.ts +21 -0
- package/src/utils.ts +3 -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,300 @@
|
|
|
1
|
+
# Tabs
|
|
2
|
+
|
|
3
|
+
`@cloud-ru/ds-tabs` — Пакет табов — compound-компонент Tabs c субкомпонентами TabBar, Tab и TabContent для горизонтальной и вертикальной навигации.
|
|
4
|
+
|
|
5
|
+
Пакет `@cloud-ru/ds-tabs` — compound-компонент для переключения между разделами одного уровня. Родитель `Tabs` владеет состоянием; `TabBar`, `Tab`, `TabContent` читают его из контекста.
|
|
6
|
+
|
|
7
|
+
- ****Tabs**** — корневой компонент, хранит активную вкладку и раздаёт её через контекст.
|
|
8
|
+
- ****TabBar**** — контейнер для списка табов, управляет скроллингом и индикатором.
|
|
9
|
+
- ****Tab**** — отдельная кнопка-вкладка.
|
|
10
|
+
- ****TabContent**** — панель с содержимым активной вкладки.
|
|
11
|
+
|
|
12
|
+
## Когда использовать
|
|
13
|
+
|
|
14
|
+
- 2–7 связанных разделов одного уровня иерархии.
|
|
15
|
+
- Переключение между представлениями одного объекта (обзор / настройки / история).
|
|
16
|
+
|
|
17
|
+
Когда **не** подходит: для иерархической навигации используйте `Sidebar`, для шагов процесса — `Stepper`, для фильтров — `Chip`/`Select`.
|
|
18
|
+
|
|
19
|
+
## Установка
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @cloud-ru/ds-tabs
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Tabs } from '@cloud-ru/ds-tabs'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Tabs
|
|
30
|
+
|
|
31
|
+
Корневой контейнер Tabs — владеет состоянием выбранного таба, поддерживает контролируемый и неконтролируемый режим.
|
|
32
|
+
|
|
33
|
+
Корневой контейнер compound-компонента. Хранит `selectedTab` и передаёт его детям через React-контекст. Работает в двух режимах:
|
|
34
|
+
|
|
35
|
+
- **Неконтролируемый** — `defaultValue`, переключение через UI.
|
|
36
|
+
- **Контролируемый** — `value` + `onChange`, чаще всего синхронизируется с URL.
|
|
37
|
+
|
|
38
|
+
### Когда использовать
|
|
39
|
+
|
|
40
|
+
- Нужен compound API с независимым положением `TabBar` и `TabContent` в разметке.
|
|
41
|
+
- Состояние активного таба должно синхронизироваться с внешними источниками (URL, стор).
|
|
42
|
+
|
|
43
|
+
### Анатомия
|
|
44
|
+
|
|
45
|
+
#### Orientation
|
|
46
|
+
`horizontal` — табы в строку (дефолт), `vertical` — колонкой (для боковых навигаций).
|
|
47
|
+
|
|
48
|
+
#### Size
|
|
49
|
+
`m` — дефолт, `l` — для крупных лейаутов и посадочных страниц.
|
|
50
|
+
|
|
51
|
+
### Примеры использования
|
|
52
|
+
|
|
53
|
+
#### Неконтролируемый режим
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { Tabs } from '@cloud-ru/ds-tabs';
|
|
57
|
+
|
|
58
|
+
export function Uncontrolled() {
|
|
59
|
+
return (
|
|
60
|
+
<Tabs defaultValue='a'>
|
|
61
|
+
<Tabs.TabBar>
|
|
62
|
+
<Tabs.Tab value='a' label='Alpha' />
|
|
63
|
+
<Tabs.Tab value='b' label='Beta' />
|
|
64
|
+
</Tabs.TabBar>
|
|
65
|
+
<Tabs.TabContent value='a'>Alpha content</Tabs.TabContent>
|
|
66
|
+
<Tabs.TabContent value='b'>Beta content</Tabs.TabContent>
|
|
67
|
+
</Tabs>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Props
|
|
73
|
+
|
|
74
|
+
**TabsProps**
|
|
75
|
+
|
|
76
|
+
| Prop | Type | Default | Description |
|
|
77
|
+
|------|------|---------|-------------|
|
|
78
|
+
| `children` | `string \| number \| boolean \| ReactElement<any, string \| JSXElementConstructor<any>> \| Iterable<ReactNode> \| ReactPortal \| null \| undefined` | — | |
|
|
79
|
+
| `className` | `string` | — | Дополнительный класс на корневой контейнер |
|
|
80
|
+
| `defaultValue` | `T` | — | Выбранная вкладка по умолчанию |
|
|
81
|
+
| `onChange` | `((id: T) => void)` | — | Колбек выбора вкладки |
|
|
82
|
+
| `value` | `T` | — | Текущая вкладка |
|
|
83
|
+
|
|
84
|
+
## Tab
|
|
85
|
+
|
|
86
|
+
Отдельная вкладка в TabBar — поддерживает label, counter и disabled.
|
|
87
|
+
|
|
88
|
+
Одна вкладка внутри `TabBar`. Идентифицируется по `value` — это же значение используется в `TabContent` для сопоставления. Поддерживает `counter` (встроенный `Counter`) и `disabled`.
|
|
89
|
+
|
|
90
|
+
### Когда использовать
|
|
91
|
+
|
|
92
|
+
- Внутри `TabBar` для каждой доступной вкладки.
|
|
93
|
+
- Когда нужно показать счётчик (число уведомлений/записей) рядом с названием таба.
|
|
94
|
+
|
|
95
|
+
### Анатомия
|
|
96
|
+
|
|
97
|
+
#### Size
|
|
98
|
+
Высота таба: `m` — дефолт, `l` — для крупных лейаутов. Наследуется от `TabBar`.
|
|
99
|
+
|
|
100
|
+
#### Marker position
|
|
101
|
+
Положение активного маркера: `before` — перед содержимым, `after` — после. Наследуется от `TabBar`.
|
|
102
|
+
|
|
103
|
+
### Примеры использования
|
|
104
|
+
|
|
105
|
+
#### Tab с counter
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { Tabs } from '@cloud-ru/ds-tabs';
|
|
109
|
+
|
|
110
|
+
export function WithCounter() {
|
|
111
|
+
return (
|
|
112
|
+
<Tabs defaultValue='inbox'>
|
|
113
|
+
<Tabs.TabBar>
|
|
114
|
+
<Tabs.Tab value='inbox' label='Входящие' counter={{ label: 12 }} />
|
|
115
|
+
<Tabs.Tab value='archive' label='Архив' />
|
|
116
|
+
</Tabs.TabBar>
|
|
117
|
+
</Tabs>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Отключённый таб
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
import { Tabs } from '@cloud-ru/ds-tabs';
|
|
126
|
+
|
|
127
|
+
export function Disabled() {
|
|
128
|
+
return (
|
|
129
|
+
<Tabs defaultValue='a'>
|
|
130
|
+
<Tabs.TabBar>
|
|
131
|
+
<Tabs.Tab value='a' label='Активен' />
|
|
132
|
+
<Tabs.Tab value='b' label='Выключен' disabled />
|
|
133
|
+
</Tabs.TabBar>
|
|
134
|
+
</Tabs>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Props
|
|
140
|
+
|
|
141
|
+
**TabProps**
|
|
142
|
+
|
|
143
|
+
| Prop | Type | Default | Description |
|
|
144
|
+
|------|------|---------|-------------|
|
|
145
|
+
| `className` | `string` | — | CSS-класс |
|
|
146
|
+
| `counter` | `CounterProps` | — | Счетчик, отображающийся внутри кнопки переключения |
|
|
147
|
+
| `data-test-id` | `string` | — | |
|
|
148
|
+
| `disabled` | `boolean` | `false` | Деактивирована ли вкладка |
|
|
149
|
+
| `label` | `string` | — | Заголовок вкладки |
|
|
150
|
+
| `onClick` | `((event: MouseEvent<HTMLButtonElement, MouseEvent>) => void)` | — | Колбек клика по кнопке переключения |
|
|
151
|
+
| `value` | `string` | — | Value вкладки |
|
|
152
|
+
|
|
153
|
+
##### Related types
|
|
154
|
+
|
|
155
|
+
- `Size` = `"l"` \| `"m"`
|
|
156
|
+
|
|
157
|
+
## TabBar
|
|
158
|
+
|
|
159
|
+
Панель табов — задаёт размер, ориентацию, позицию маркера и слот справа (slotActionButton) для дополнительных действий.
|
|
160
|
+
|
|
161
|
+
Панель переключателей табов. Задаёт:
|
|
162
|
+
|
|
163
|
+
- `size` — `l` (верхнеуровневый) или `m` (внутри контента).
|
|
164
|
+
- `orientation` — `horizontal` (по умолчанию) или `vertical`.
|
|
165
|
+
- `markerPosition` — позиция активного маркера (`before` / `after`).
|
|
166
|
+
- `slotActionButton` — слот справа от табов для дополнительных действий.
|
|
167
|
+
|
|
168
|
+
### Когда использовать
|
|
169
|
+
|
|
170
|
+
- Внутри `Tabs` как единственный контейнер списка кнопок-табов.
|
|
171
|
+
- Если нужно разместить дополнительные действия справа от табов (через слот `slotActionButton`).
|
|
172
|
+
|
|
173
|
+
### Анатомия
|
|
174
|
+
|
|
175
|
+
#### Orientation
|
|
176
|
+
`horizontal` — бар в строку, `vertical` — колонкой.
|
|
177
|
+
|
|
178
|
+
#### Size
|
|
179
|
+
`m` — дефолт, `l` — для крупных лейаутов.
|
|
180
|
+
|
|
181
|
+
#### Marker position
|
|
182
|
+
Положение активного маркера относительно содержимого таба: `before` — перед, `after` — после.
|
|
183
|
+
|
|
184
|
+
### Примеры использования
|
|
185
|
+
|
|
186
|
+
#### Size L — верхнеуровневый
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { SIZE, Tabs } from '@cloud-ru/ds-tabs';
|
|
190
|
+
|
|
191
|
+
export function SizeL() {
|
|
192
|
+
return (
|
|
193
|
+
<Tabs defaultValue='a'>
|
|
194
|
+
<Tabs.TabBar size={SIZE.L}>
|
|
195
|
+
<Tabs.Tab value='a' label='Первая' />
|
|
196
|
+
<Tabs.Tab value='b' label='Вторая' />
|
|
197
|
+
</Tabs.TabBar>
|
|
198
|
+
</Tabs>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Vertical orientation
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
import { ORIENTATION, Tabs } from '@cloud-ru/ds-tabs';
|
|
207
|
+
|
|
208
|
+
export function Vertical() {
|
|
209
|
+
return (
|
|
210
|
+
<Tabs defaultValue='a'>
|
|
211
|
+
<Tabs.TabBar orientation={ORIENTATION.Vertical}>
|
|
212
|
+
<Tabs.Tab value='a' label='Профиль' />
|
|
213
|
+
<Tabs.Tab value='b' label='Безопасность' />
|
|
214
|
+
</Tabs.TabBar>
|
|
215
|
+
</Tabs>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Props
|
|
221
|
+
|
|
222
|
+
**TabBarProps**
|
|
223
|
+
|
|
224
|
+
| Prop | Type | Default | Description |
|
|
225
|
+
|------|------|---------|-------------|
|
|
226
|
+
| `children` | `TabProps` | — | Контент (элементы Tabs.Tab) |
|
|
227
|
+
| `className` | `string` | — | CSS-класс |
|
|
228
|
+
| `data-test-id` | `string` | — | |
|
|
229
|
+
| `disableDivider` | `boolean` | `false` | Скрыть разделитель под/рядом с панелью табов |
|
|
230
|
+
| `markerPosition` | `"after"` \| `"before"` | `after` | Позиция маркера относительно таб-бара. <br/> Значения ориентационно-нейтральны, в Figma та же ось названа сторонами: <br/> `before` = Figma `top` (horizontal) / `left` (vertical), <br/> `after` = Figma `bottom` (horizontal) / `right` (vertical). |
|
|
231
|
+
| `orientation` | `"horizontal"` \| `"vertical"` | `horizontal` | Ориентация |
|
|
232
|
+
| `size` | `"l"` \| `"m"` | `l` | Размер панели табов: L — верхнеуровневый, M — на уровне контента |
|
|
233
|
+
| `slotActionButton` | `ReactNode` | — | Слот действия: контент после списка табов — справа при горизонтальной <br/> ориентации, снизу при вертикальной. Разделитель под ним не продолжается. |
|
|
234
|
+
|
|
235
|
+
##### Related types
|
|
236
|
+
|
|
237
|
+
- `MarkerPosition` = `"after"` \| `"before"`
|
|
238
|
+
|
|
239
|
+
- `Orientation` = `"horizontal"` \| `"vertical"`
|
|
240
|
+
|
|
241
|
+
- `Size` = `"l"` \| `"m"`
|
|
242
|
+
|
|
243
|
+
**TabProps**
|
|
244
|
+
|
|
245
|
+
| Prop | Type | Default | Description |
|
|
246
|
+
|------|------|---------|-------------|
|
|
247
|
+
| `className` | `string \| undefined` | — | CSS-класс |
|
|
248
|
+
| `counter` | `CounterProps` | — | Счетчик, отображающийся внутри кнопки переключения |
|
|
249
|
+
| `data-test-id` | `string \| undefined` | — | |
|
|
250
|
+
| `disabled` | `boolean \| undefined` | — | Деактивирована ли вкладка |
|
|
251
|
+
| `label` | `string` | — | Заголовок вкладки |
|
|
252
|
+
| `onClick` | `((event: MouseEvent<HTMLButtonElement>) => void) \| undefined` | — | Колбек клика по кнопке переключения |
|
|
253
|
+
| `value` | `string` | — | Value вкладки |
|
|
254
|
+
|
|
255
|
+
## TabContent
|
|
256
|
+
|
|
257
|
+
Контейнер контента таба — рендерится только когда его value совпадает с активным табом.
|
|
258
|
+
|
|
259
|
+
Контейнер контента. Рендерится только при совпадении `value` с активным табом. Формирует `<div role='tabpanel'>` и связывается с кнопкой таба через `aria-labelledby`.
|
|
260
|
+
|
|
261
|
+
### Когда использовать
|
|
262
|
+
|
|
263
|
+
- Для каждой вкладки, у которой есть видимый контент.
|
|
264
|
+
- Когда нужен корректный `aria-labelledby`/`role='tabpanel'` из коробки.
|
|
265
|
+
|
|
266
|
+
### Примеры использования
|
|
267
|
+
|
|
268
|
+
#### Пара Tab + TabContent
|
|
269
|
+
|
|
270
|
+
```tsx
|
|
271
|
+
import { Tabs } from '@cloud-ru/ds-tabs';
|
|
272
|
+
|
|
273
|
+
export function WithContent() {
|
|
274
|
+
return (
|
|
275
|
+
<Tabs defaultValue='a'>
|
|
276
|
+
<Tabs.TabBar>
|
|
277
|
+
<Tabs.Tab value='a' label='Первая' />
|
|
278
|
+
<Tabs.Tab value='b' label='Вторая' />
|
|
279
|
+
</Tabs.TabBar>
|
|
280
|
+
<Tabs.TabContent value='a'>
|
|
281
|
+
<div style={{ padding: '12px 0' }}>Контент первого таба</div>
|
|
282
|
+
</Tabs.TabContent>
|
|
283
|
+
<Tabs.TabContent value='b'>
|
|
284
|
+
<div style={{ padding: '12px 0' }}>Контент второго таба</div>
|
|
285
|
+
</Tabs.TabContent>
|
|
286
|
+
</Tabs>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Props
|
|
292
|
+
|
|
293
|
+
**TabContentProps**
|
|
294
|
+
|
|
295
|
+
| Prop | Type | Default | Description |
|
|
296
|
+
|------|------|---------|-------------|
|
|
297
|
+
| `children` | `string \| number \| boolean \| ReactElement<any, string \| JSXElementConstructor<any>> \| Iterable<ReactNode> \| ReactPortal \| null \| undefined` | — | |
|
|
298
|
+
| `className` | `string` | — | |
|
|
299
|
+
| `data-test-id` | `string` | — | |
|
|
300
|
+
| `value` | `string` | — | Значение таба |
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Direction, Orientation, Size } from '../../types';
|
|
2
|
+
export type ScrollButtonProps = {
|
|
3
|
+
size: Size;
|
|
4
|
+
direction: Direction;
|
|
5
|
+
orientation: Orientation;
|
|
6
|
+
onClick(): void;
|
|
7
|
+
};
|
|
8
|
+
export declare function ScrollButton({ size, onClick, direction, orientation }: ScrollButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ScrollButton = ScrollButton;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const button_1 = require("@cloud-ru/ds-button");
|
|
9
|
+
const system_1 = require("@cloud-ru/ds-icons/interface/system");
|
|
10
|
+
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
11
|
+
const MAP_DIRECTION_TO_ICON = {
|
|
12
|
+
left: (0, jsx_runtime_1.jsx)(system_1.ChevronLeftSVG, {}),
|
|
13
|
+
right: (0, jsx_runtime_1.jsx)(system_1.ChevronRightSVG, {}),
|
|
14
|
+
top: (0, jsx_runtime_1.jsx)(system_1.ChevronUpSVG, {}),
|
|
15
|
+
bottom: (0, jsx_runtime_1.jsx)(system_1.ChevronDownSVG, {}),
|
|
16
|
+
};
|
|
17
|
+
function ScrollButton({ size, onClick, direction, orientation }) {
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.scrollButton, "data-direction": direction, "data-size": size, "data-orientation": orientation, "data-testid": `tabs__scroll-button-${direction}`, children: (0, jsx_runtime_1.jsx)(button_1.Button, { tabIndex: -1, icon: MAP_DIRECTION_TO_ICON[direction], size: 's', view: 'elevated', appearance: 'neutral', onClick: onClick, "aria-label": `Scroll ${direction}` }) }));
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ScrollButton';
|
|
@@ -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("./ScrollButton"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.scrollButton{
|
|
2
|
+
position:absolute;
|
|
3
|
+
display:flex;
|
|
4
|
+
align-items:center;
|
|
5
|
+
justify-content:center;
|
|
6
|
+
}
|
|
7
|
+
.scrollButton[data-size=m][data-direction=left]{
|
|
8
|
+
padding-left:var(--sn-tabs-anatomy-size-m-control-forward-padding, var(--sn-primitive-dimension-2, 2px));
|
|
9
|
+
}
|
|
10
|
+
.scrollButton[data-size=m][data-direction=right]{
|
|
11
|
+
padding-right:var(--sn-tabs-anatomy-size-m-control-forward-padding, var(--sn-primitive-dimension-2, 2px));
|
|
12
|
+
}
|
|
13
|
+
.scrollButton[data-size=m][data-direction=top]{
|
|
14
|
+
padding-top:var(--sn-tabs-anatomy-size-m-control-forward-padding, var(--sn-primitive-dimension-2, 2px));
|
|
15
|
+
}
|
|
16
|
+
.scrollButton[data-size=m][data-direction=bottom]{
|
|
17
|
+
padding-bottom:var(--sn-tabs-anatomy-size-m-control-forward-padding, var(--sn-primitive-dimension-2, 2px));
|
|
18
|
+
}
|
|
19
|
+
.scrollButton[data-size=l][data-direction=left]{
|
|
20
|
+
padding-left:var(--sn-tabs-anatomy-size-l-control-forward-padding, var(--sn-primitive-dimension-4, 4px));
|
|
21
|
+
}
|
|
22
|
+
.scrollButton[data-size=l][data-direction=right]{
|
|
23
|
+
padding-right:var(--sn-tabs-anatomy-size-l-control-forward-padding, var(--sn-primitive-dimension-4, 4px));
|
|
24
|
+
}
|
|
25
|
+
.scrollButton[data-size=l][data-direction=top]{
|
|
26
|
+
padding-top:var(--sn-tabs-anatomy-size-l-control-forward-padding, var(--sn-primitive-dimension-4, 4px));
|
|
27
|
+
}
|
|
28
|
+
.scrollButton[data-size=l][data-direction=bottom]{
|
|
29
|
+
padding-bottom:var(--sn-tabs-anatomy-size-l-control-forward-padding, var(--sn-primitive-dimension-4, 4px));
|
|
30
|
+
}
|
|
31
|
+
.scrollButton[data-direction=left]{
|
|
32
|
+
top:0;
|
|
33
|
+
bottom:0;
|
|
34
|
+
left:0;
|
|
35
|
+
}
|
|
36
|
+
.scrollButton[data-direction=right]{
|
|
37
|
+
top:0;
|
|
38
|
+
right:0;
|
|
39
|
+
bottom:0;
|
|
40
|
+
}
|
|
41
|
+
.scrollButton[data-direction=top]{
|
|
42
|
+
top:0;
|
|
43
|
+
right:0;
|
|
44
|
+
left:0;
|
|
45
|
+
}
|
|
46
|
+
.scrollButton[data-direction=bottom]{
|
|
47
|
+
right:0;
|
|
48
|
+
bottom:0;
|
|
49
|
+
left:0;
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CounterProps } from '@cloud-ru/ds-counter';
|
|
2
|
+
import { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
import { MouseEvent } from 'react';
|
|
4
|
+
export type TabProps = WithSupportProps<{
|
|
5
|
+
/** Value вкладки */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Заголовок вкладки */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Деактивирована ли вкладка */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** CSS-класс */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Счетчик, отображающийся внутри кнопки переключения */
|
|
14
|
+
counter?: {
|
|
15
|
+
/** Значение счетчика */
|
|
16
|
+
label: number;
|
|
17
|
+
/** Внешний вид */
|
|
18
|
+
appearance?: CounterProps['appearance'];
|
|
19
|
+
/** Роль, в которой применяется `appearance` счётчика */
|
|
20
|
+
roleAppearance?: CounterProps['roleAppearance'];
|
|
21
|
+
};
|
|
22
|
+
/** Колбек клика по кнопке переключения */
|
|
23
|
+
onClick?(event: MouseEvent<HTMLButtonElement>): void;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function Tab({ label, value, disabled, className, onClick, counter, ...otherProps }: TabProps): import("react/jsx-runtime").JSX.Element | null;
|