@royaloperahouse/chord 1.13.0 → 1.13.1-a-test-snapshot
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 +3 -0
- package/README.md +250 -40
- package/dist/chord.cjs.development.js +112 -14
- package/dist/chord.cjs.development.js.map +1 -1
- package/dist/chord.cjs.production.min.js +1 -1
- package/dist/chord.cjs.production.min.js.map +1 -1
- package/dist/chord.esm.js +112 -14
- package/dist/chord.esm.js.map +1 -1
- package/dist/components/organisms/AnchorTabBar/AnchorTabBar.style.d.ts +4 -3
- package/dist/types/navigation.d.ts +34 -0
- package/package.json +2 -1
- package/README.GIT +0 -277
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,67 +1,277 @@
|
|
|
1
|
-
# Royal Opera House -
|
|
1
|
+
# Royal Opera House Chord - Front End Design System
|
|
2
2
|
|
|
3
|
-
Welcome to the Royal Opera House
|
|
3
|
+
Welcome to the Royal Opera House Front End Design System, `@royaloperahouse/chord`
|
|
4
4
|
|
|
5
5
|
This package is a library of UI components intended to be used in the ROH website.
|
|
6
6
|
|
|
7
|
+
It uses React, TypeScript, TSDX and Storybook.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
The NPM packages are published at [https://www.npmjs.com/package/@royaloperahouse/chord](https://www.npmjs.com/package/@royaloperahouse/chord)
|
|
10
|
+
|
|
11
|
+
The Storybook for the latest version of the library is hosted at [chord.roh.org.uk](chord.roh.org.uk)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
* Make sure the required package dependencies are installed using `yarn install`
|
|
18
|
+
|
|
19
|
+
* If this is the first time you are working on Chord, make sure to run `yarn build` to build all the modules.
|
|
20
|
+
|
|
21
|
+
* **To deploy the storybook publicly** you will need credentials for the **parent** 'Royal Opera House' AWS account in your `~/.aws/credentials` file.
|
|
22
|
+
* The deploy script expects these to be called `[parent]`.
|
|
23
|
+
|
|
24
|
+
* You can find these values at:
|
|
25
|
+
|
|
26
|
+
*AWS 'Your Applications' page -> 'Royal Opera House' -> 'Developer Access' -> 'Command line or programmatic access'*
|
|
27
|
+
|
|
28
|
+
* **To deploy a preview** for demo / QA you will need the `CHROMATIC_PROJECT_TOKEN` -- find this in 1Password
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
* **To publish the NPM package** you will need the ROH `NPM_TOKEN` -- find this in 1Password
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## Versioning
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
We use [Semantic Versioning](https://semver.org/) for Chord.
|
|
38
|
+
|
|
39
|
+
Given a version number MAJOR.MINOR.PATCH, increment the:
|
|
40
|
+
|
|
41
|
+
* MAJOR version when you make incompatible library changes
|
|
42
|
+
* MINOR version when you add functionality in a backwards compatible manner
|
|
43
|
+
* PATCH version when you make backwards compatible bug fixes
|
|
44
|
+
|
|
45
|
+
When you create a new release always update the `CHANGELOG` and `package.json`
|
|
46
|
+
|
|
47
|
+
Increment your version from the latest stable version on `chord-releases`
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Deploying the Storybook
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### **1. To build and deploy locally**
|
|
54
|
+
|
|
55
|
+
You can quickly build and serve the contents of `/storybook-static` from your local machine, for development and manual testing. To do this run:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
yarn storybook
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
By default the storybook will be accessible at
|
|
62
|
+
[http://localhost:6006/]()
|
|
63
|
+
|
|
64
|
+
The server will hot-reload on most changes.
|
|
65
|
+
|
|
66
|
+
### **2. To deploy a preview version remotely**
|
|
67
|
+
|
|
68
|
+
You can deploy a release candidate, or work-in-progress to [Chromatic](https://www.chromatic.com/) for showcase or QA.
|
|
69
|
+
|
|
70
|
+
**NOTE:** you will need the `CHROMATIC_PROJECT_TOKEN` as described in *Prerequisites* above.
|
|
71
|
+
|
|
72
|
+
Either set the token as a shell variable or use a `.env` file in the chord root directory containing the token, as so:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
CHROMATIC_PROJECT_TOKEN=tokengoeshere
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Run:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
yarn deploy-storybook-dev
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
to build and deploy the storybook from your repo to Chromatic.
|
|
85
|
+
|
|
86
|
+
You will find the address of your deployed storybook in the console output, looking something like this:
|
|
87
|
+
|
|
88
|
+
`→ View your Storybook at https://randomHexString-randomAlphabeticalString.chromatic.com`
|
|
89
|
+
|
|
90
|
+
### **3. To deploy a release version**
|
|
91
|
+
|
|
92
|
+
You can deploy the contents of `./storybook-static` to S3 as a static site, which is permanently accessible at [chord.roh.org.uk](chord.roh.org.uk)
|
|
93
|
+
|
|
94
|
+
**NOTE:** To do this you will need the correct `AWS` credentials set up, as described in *Prerequisites* above.
|
|
95
|
+
|
|
96
|
+
First build the storybook using:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
yarn build-storybook
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
then run:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
yarn deploy-storybook
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **IMPORTANT:** This URL is intended to showcase the latest stable version of Chord, it should be kept up to date with the main `chord-releases` branch and should **only** be used for release versions. If you want to deploy a development version follow the steps above under *To deploy a preview version remotely*.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## Releasing a New Package Version
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
This is the procedure for releasing a new Chord NPM package.
|
|
115
|
+
|
|
116
|
+
There are two types of package:
|
|
117
|
+
|
|
118
|
+
A **snapshot** can be published to use a development version of the Chord library in our frontend staging environments, to perform integrated, manual testing.
|
|
119
|
+
|
|
120
|
+
A **stable** package is published for use in production.
|
|
121
|
+
|
|
122
|
+
**NOTE:** You will need the `NPM_TOKEN`, as described in 'Prerequisites' above.
|
|
123
|
+
|
|
124
|
+
### **1. To release a snapshot version**
|
|
125
|
+
|
|
126
|
+
> **IMPORTANT:** Make sure you always publish your **snapshots** from `chord-development` after merging in your feature branch.
|
|
127
|
+
|
|
128
|
+
For snapshots, `RELEASE_VERSION` should be the same as the latest **stable** version of the Chord Library, as found in `chord-releases`, followed by an **unused** lowercase letter.
|
|
129
|
+
|
|
130
|
+
For example, if the latest stable release was 1.42.0, and the last snapshot published to NPM was 1.42.0-w, you would use RELEASE_VERSION `1.42.0-x`
|
|
131
|
+
|
|
132
|
+
To publish a snapshot use:
|
|
9
133
|
|
|
10
134
|
```bash
|
|
11
|
-
|
|
135
|
+
NPM_ROH_TOKEN={NPM_TOKEN} RELEASE_VERSION={RELEASE_VERSION} yarn publish-snapshot
|
|
12
136
|
```
|
|
137
|
+
|
|
138
|
+
The version published to NPM will be named, e.g. `1.42.0-a-chord-development`, use this to install the snapshot package in the frontend repos.
|
|
139
|
+
|
|
140
|
+
### **2. To release a stable version**
|
|
141
|
+
|
|
142
|
+
> **IMPORTANT:** Make sure you always publish your **stable** packages from `chord-releases` after merging in your feature branch.
|
|
143
|
+
|
|
144
|
+
For stable releases, increment your version from the latest **stable** version found on `chord-releases`, following the rules described in *Versioning* above, and use this as `RELEASE_VERSION`. (Make sure it matches the version in your `package.json` and `CHANGELOG.md`!)
|
|
145
|
+
|
|
146
|
+
To publish a stable package use:
|
|
147
|
+
|
|
13
148
|
```bash
|
|
14
|
-
|
|
149
|
+
NPM_ROH_TOKEN={NPM_TOKEN} RELEASE_VERSION={RELEASE_VERSION} yarn publish-release
|
|
15
150
|
```
|
|
16
151
|
|
|
17
|
-
## Usage
|
|
18
152
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
153
|
+
## Using the Package
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
The package is deployed to NPM, and can be installed using yarn or npm:
|
|
23
157
|
|
|
158
|
+
```bash
|
|
159
|
+
npm i --save @royaloperahouse/chord
|
|
24
160
|
```
|
|
25
|
-
|
|
161
|
+
```bash
|
|
162
|
+
yarn add @royaloperahouse/chord
|
|
163
|
+
```
|
|
164
|
+
|
|
26
165
|
|
|
27
|
-
|
|
166
|
+
## Testing
|
|
167
|
+
---
|
|
28
168
|
|
|
29
|
-
|
|
30
|
-
Footer, GlobalStyles, ThemeProvider, ThemeType,
|
|
31
|
-
} from '@royaloperahouse/chord';
|
|
169
|
+
To **Lint** the package use:
|
|
32
170
|
|
|
171
|
+
```bash
|
|
172
|
+
yarn lint
|
|
173
|
+
# Use the --fix option to perform automatic fixes
|
|
174
|
+
```
|
|
33
175
|
|
|
34
|
-
|
|
35
|
-
<ErrorBoundary>
|
|
36
|
-
<ThemeProvider theme={ThemeType.Core}>
|
|
37
|
-
<GlobalStyles />
|
|
38
|
-
<Wrapper>
|
|
39
|
-
<Header />
|
|
40
|
-
<GlobalStyle />
|
|
41
|
-
<HealthBanner />
|
|
42
|
-
<ErrorBoundary>
|
|
43
|
-
<Content>
|
|
44
|
-
{children}
|
|
45
|
-
</Content>
|
|
46
|
-
</ErrorBoundary>
|
|
47
|
-
<LiveChat />
|
|
48
|
-
</Wrapper>
|
|
49
|
-
<Footer data={footerData} />
|
|
50
|
-
</ThemeProvider>
|
|
51
|
-
</ErrorBoundary>
|
|
52
|
-
);
|
|
176
|
+
To run the **unit tests** (using Jest) use:
|
|
53
177
|
|
|
178
|
+
```bash
|
|
179
|
+
yarn test
|
|
180
|
+
|
|
181
|
+
# Use the -u option to update snapshots if needed
|
|
182
|
+
# Run `yarn test:watch` to re-run tests on changes
|
|
54
183
|
```
|
|
55
184
|
|
|
56
|
-
|
|
185
|
+
To **run and and store the unit tests** for display in storybook use:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
yarn test-storybook
|
|
189
|
+
# Use the -u option to update snapshots if needed
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
## Development Process
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### **1. Branching Model**
|
|
197
|
+
* The Chord project lives in the `roh-components` *monorepo*
|
|
198
|
+
* When working on Chord, treat the `roh-components/packages/chord` directory as your root
|
|
199
|
+
* The Chord **development** branch is currently `chord-development`
|
|
200
|
+
* The Chord **main** branch is currently `chord-releases`
|
|
201
|
+
* All work should be done on a correctly named **feature branch** of the format: `issueType/ticketNumber-short-description-of-feature`, e.g. `feature/RD-1234-update-chord-documentation`
|
|
202
|
+
* Always create your feature branch FROM, and submit pull requests TO, the **main** branch
|
|
203
|
+
* For **QA / UAT** of a Chord component in isolation: following review you should deploy a preview version to Chromatic straight from your **feature branch** _without_ merging to development
|
|
204
|
+
* For releasing an **NPM snapshot**: merge your feature branch into the **development** branch and publish the NPM snapshot from there
|
|
205
|
+
|
|
206
|
+
### **2. Detailed Workflow**
|
|
207
|
+
|
|
208
|
+
#### **Before review:**
|
|
209
|
+
|
|
210
|
+
* Git pull the latest version of `chord-releases`
|
|
211
|
+
* Checkout a new, correctly-named feature branch from `chord releases`
|
|
212
|
+
* Do your work on this feature branch
|
|
213
|
+
* Run: `yarn lint`
|
|
214
|
+
* Run: `yarn test`
|
|
215
|
+
* Commit your changes
|
|
216
|
+
* Create a pull request from your feature branch to `chord-releases`
|
|
217
|
+
* Add the appropriate reviewers
|
|
218
|
+
|
|
219
|
+
#### **Before QA / UAT:**
|
|
220
|
+
|
|
221
|
+
After your PR is approved, you have two options:
|
|
222
|
+
|
|
223
|
+
**i.** For QA of a component in isolation:
|
|
57
224
|
|
|
58
|
-
|
|
225
|
+
* Follow the steps above in *Deploying the Storybook -> 2. Deploying a preview version remotely*
|
|
226
|
+
* Share the generated Chromatic URL with the appropriate people for QA / UAT
|
|
227
|
+
|
|
228
|
+
**ii.** For integrated testing of a component in the frontend staging environments:
|
|
229
|
+
|
|
230
|
+
* Check out the `chord-development` branch
|
|
231
|
+
* Merge your work in to `chord-development`
|
|
232
|
+
* Follow the steps above under *Publishing a New Package Version -> 1. To release a snapshot version*
|
|
233
|
+
* Git push the updated `chord-development` branch to remote
|
|
234
|
+
* Finally, in the frontend repo:
|
|
235
|
+
|
|
236
|
+
1. Update the `package.json` to reference the new snapshot version
|
|
237
|
+
2. Run: `yarn install`
|
|
238
|
+
3. Deploy the frontend to a staging environment
|
|
239
|
+
|
|
240
|
+
#### **When ready for production:**
|
|
241
|
+
|
|
242
|
+
* Return to your chord **feature branch**
|
|
243
|
+
* Update the chord version in `package.json`, incrementing from the last **stable** release, found in `chord-releases`, and following the rules described in the *Versioning* section
|
|
244
|
+
* Update `CHANGELOG.md`, adding the new version number and a short description of your changes
|
|
245
|
+
* Run: `yarn lint`
|
|
246
|
+
* Run: `yarn test`
|
|
247
|
+
* Run: `yarn test-storybook -u`
|
|
248
|
+
* Run: `yarn build-storybook`
|
|
249
|
+
* Git commit, push, and update your PR for final approval
|
|
250
|
+
* Merge your approved PR to `chord-releases`
|
|
251
|
+
* Follow the steps in *Publishing a New Package Version -> 2. To release a stable version* to publish the NPM package
|
|
252
|
+
* Finally, follow the steps in *Deploying The Storybook -> 3. To deploy a release version*, to update the public Chord Storybook page
|
|
253
|
+
|
|
254
|
+
Once you have successfully published a new release version, you can open a ticket to update to this version in any of the frontend repos.
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
## Notes
|
|
258
|
+
---
|
|
259
|
+
### The `storybook-static` folder
|
|
260
|
+
|
|
261
|
+
This folder contains all the HTML / JS required to deploy the Storybook as a static site. It's autogenerated whenever the Storybook is built and therefore will show up a lot of merge conflicts when you merge other branches into your feature branch. It is best to leave generating the storybook until the later part of your workflow, but in case you run into conflicts earlier, it's ok to just delete the folder and regenerate using:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
yarn build-storybook
|
|
265
|
+
```
|
|
59
266
|
|
|
60
|
-
|
|
267
|
+
For the same reason changes to this folder will cause a lot of big diffs, when looking at a PR, but can mostly be skimmed over unless something looks unusual.
|
|
61
268
|
|
|
62
|
-
|
|
269
|
+
---
|
|
270
|
+
### Examples
|
|
63
271
|
|
|
272
|
+
There is an example implementation in the example folder. Alternatively there are also integration examples in storybook. Make sure to keep these updated so as to showcase the current components available.
|
|
64
273
|
|
|
65
|
-
|
|
274
|
+
---
|
|
275
|
+
### Bundle analysis
|
|
66
276
|
|
|
67
|
-
|
|
277
|
+
Calculate the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `yarn size` and visualize it with `yarn analyze`.
|
|
@@ -4181,20 +4181,28 @@ var Footer = function Footer(_ref) {
|
|
|
4181
4181
|
};
|
|
4182
4182
|
|
|
4183
4183
|
var _templateObject$y, _templateObject2$j, _templateObject3$c, _templateObject4$7, _templateObject5$5, _templateObject6$4;
|
|
4184
|
-
var
|
|
4184
|
+
var LIST_ITEM_GAP = 32;
|
|
4185
|
+
var AnchorTabbarWrapper = /*#__PURE__*/styled__default.div(_templateObject$y || (_templateObject$y = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: sticky;\n width: 100%;\n top: 0;\n border-bottom: ", ";\n background-color: var(--base-color-white);\n z-index: ", ";\n"])), function (_ref) {
|
|
4186
|
+
var bottomBorder = _ref.bottomBorder;
|
|
4187
|
+
return bottomBorder ? '2px solid var(--base-color-light-grey)' : 'none';
|
|
4188
|
+
}, zIndexes.anchor);
|
|
4185
4189
|
var TabsGrid = /*#__PURE__*/styled__default(Grid)(_templateObject2$j || (_templateObject2$j = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n height: var(--anchor-tabs-height);\n"])));
|
|
4186
4190
|
var TabsWrapper = /*#__PURE__*/styled__default.div(_templateObject3$c || (_templateObject3$c = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n"])));
|
|
4187
|
-
var TabsList = /*#__PURE__*/styled__default.ul(_templateObject4$7 || (_templateObject4$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: ", ";\n display: flex;\n gap:
|
|
4188
|
-
var tabsOverflow = _ref.tabsOverflow;
|
|
4189
|
-
return tabsOverflow ? 'calc(100% - 74px)' : '100%';
|
|
4190
|
-
}, function (_ref2) {
|
|
4191
|
+
var TabsList = /*#__PURE__*/styled__default.ul(_templateObject4$7 || (_templateObject4$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: ", ";\n display: flex;\n gap: ", "px;\n justify-content: ", ";\n align-items: center;\n list-style: none;\n padding: 0;\n margin: 0;\n height: var(--anchor-tabs-height);\n white-space: nowrap;\n overflow: scroll;\n scrollbar-width: none;\n ::-webkit-scrollbar {\n display: none;\n }\n scroll-behavior: smooth;\n\n @media ", " {\n background: linear-gradient(\n 135deg,\n rgba(255, 255, 255, 1) 0%,\n rgba(255, 255, 255, 0.48) 85%,\n rgba(235, 235, 235, 0.4) 99%,\n rgba(255, 255, 255, 0.39) 100%\n );\n }\n\n @media ", " {\n & {\n width: ", ";\n }\n }\n"])), function (_ref2) {
|
|
4191
4192
|
var tabsOverflow = _ref2.tabsOverflow;
|
|
4192
|
-
return tabsOverflow ? '
|
|
4193
|
-
},
|
|
4193
|
+
return tabsOverflow ? 'calc(100% - 74px)' : '100%';
|
|
4194
|
+
}, LIST_ITEM_GAP, function (_ref3) {
|
|
4194
4195
|
var tabsOverflow = _ref3.tabsOverflow;
|
|
4195
|
-
return tabsOverflow ? '
|
|
4196
|
+
return tabsOverflow ? 'start' : 'center';
|
|
4197
|
+
}, devices.mobileAndTablet, devices.mobile, function (_ref4) {
|
|
4198
|
+
var tabsOverflow = _ref4.tabsOverflow,
|
|
4199
|
+
hasTwoArrows = _ref4.hasTwoArrows;
|
|
4200
|
+
return tabsOverflow && hasTwoArrows ? 'calc(100% - 50px)' : '100%';
|
|
4201
|
+
});
|
|
4202
|
+
var ArrowsContainer = /*#__PURE__*/styled__default.div(_templateObject5$5 || (_templateObject5$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: ", ";\n height: var(--anchor-tabs-height);\n background-color: var(--base-color-white);\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 10px;\n"])), function (_ref5) {
|
|
4203
|
+
var fullWidth = _ref5.fullWidth;
|
|
4204
|
+
return fullWidth ? '74px' : '46px';
|
|
4196
4205
|
});
|
|
4197
|
-
var ArrowsContainer = /*#__PURE__*/styled__default.div(_templateObject5$5 || (_templateObject5$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 74px;\n height: var(--anchor-tabs-height);\n background-color: var(--base-color-white);\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 10px;\n"])));
|
|
4198
4206
|
var ArrowWrapper = /*#__PURE__*/styled__default.div(_templateObject6$4 || (_templateObject6$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 24px;\n height: 24px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: flex-center;\n\n :hover {\n && svg path {\n fill: var(--base-color-primary);\n }\n }\n"])));
|
|
4199
4207
|
|
|
4200
4208
|
var _excluded$8 = ["id", "text"];
|
|
@@ -4202,8 +4210,12 @@ var _excluded$8 = ["id", "text"];
|
|
|
4202
4210
|
var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
4203
4211
|
var tabs = _ref.tabs,
|
|
4204
4212
|
onTabClick = _ref.onTabClick,
|
|
4205
|
-
activeTab = _ref.activeTab
|
|
4213
|
+
activeTab = _ref.activeTab,
|
|
4214
|
+
absolutePositionParams = _ref.absolutePositionParams,
|
|
4215
|
+
_ref$bottomBorder = _ref.bottomBorder,
|
|
4216
|
+
bottomBorder = _ref$bottomBorder === void 0 ? false : _ref$bottomBorder;
|
|
4206
4217
|
var tabListRef = React.useRef(null);
|
|
4218
|
+
var wrapperRef = React.useRef(null);
|
|
4207
4219
|
|
|
4208
4220
|
var _useState = React.useState(activeTab || ''),
|
|
4209
4221
|
selectedItem = _useState[0],
|
|
@@ -4221,6 +4233,9 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4221
4233
|
canScrollToRight = _useState4[0],
|
|
4222
4234
|
setCanScrollToRight = _useState4[1];
|
|
4223
4235
|
|
|
4236
|
+
var timer = null;
|
|
4237
|
+
var hasTwoArrows = canScrollToRight && canScrollToLeft;
|
|
4238
|
+
|
|
4224
4239
|
var isSelectedItem = function isSelectedItem(id) {
|
|
4225
4240
|
return id === selectedItem;
|
|
4226
4241
|
};
|
|
@@ -4233,6 +4248,69 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4233
4248
|
setSelectedItem(id);
|
|
4234
4249
|
};
|
|
4235
4250
|
|
|
4251
|
+
var getScrollWidth = function getScrollWidth() {
|
|
4252
|
+
var width = 0;
|
|
4253
|
+
var selectedItemIndex = tabs.findIndex(function (el) {
|
|
4254
|
+
return el.id === selectedItem;
|
|
4255
|
+
});
|
|
4256
|
+
var tabLinks = document.getElementsByClassName('anchor-tab-bar-tablink');
|
|
4257
|
+
|
|
4258
|
+
for (var i = 0; i < selectedItemIndex; ++i) {
|
|
4259
|
+
width += tabLinks[i].scrollWidth + LIST_ITEM_GAP;
|
|
4260
|
+
}
|
|
4261
|
+
|
|
4262
|
+
return width;
|
|
4263
|
+
};
|
|
4264
|
+
|
|
4265
|
+
var changeWrapperVisibility = function changeWrapperVisibility(showWrapper, topOffset) {
|
|
4266
|
+
if (showWrapper === void 0) {
|
|
4267
|
+
showWrapper = false;
|
|
4268
|
+
}
|
|
4269
|
+
|
|
4270
|
+
var wrapperEl = wrapperRef.current;
|
|
4271
|
+
wrapperEl.style.position = 'absolute';
|
|
4272
|
+
wrapperEl.style.visibility = showWrapper && topOffset !== undefined ? 'visible' : 'hidden';
|
|
4273
|
+
if (showWrapper && topOffset !== undefined) wrapperEl.style.top = topOffset + "px";
|
|
4274
|
+
};
|
|
4275
|
+
|
|
4276
|
+
var handleScrollForAbsolutePosition = function handleScrollForAbsolutePosition() {
|
|
4277
|
+
var _absolutePositionPara = absolutePositionParams.navigationHeight,
|
|
4278
|
+
navigationHeight = _absolutePositionPara === void 0 ? 0 : _absolutePositionPara,
|
|
4279
|
+
_absolutePositionPara2 = absolutePositionParams.topOffset,
|
|
4280
|
+
topOffset = _absolutePositionPara2 === void 0 ? 0 : _absolutePositionPara2;
|
|
4281
|
+
|
|
4282
|
+
if (wrapperRef.current && window.pageYOffset > topOffset + navigationHeight) {
|
|
4283
|
+
changeWrapperVisibility();
|
|
4284
|
+
} else if (wrapperRef.current && window.pageYOffset < topOffset + navigationHeight) {
|
|
4285
|
+
changeWrapperVisibility(true, topOffset);
|
|
4286
|
+
}
|
|
4287
|
+
|
|
4288
|
+
if (timer !== null) clearTimeout(timer);
|
|
4289
|
+
timer = setTimeout(function () {
|
|
4290
|
+
if (window.pageYOffset > topOffset + navigationHeight && wrapperRef.current) {
|
|
4291
|
+
changeWrapperVisibility(true, window.pageYOffset - navigationHeight);
|
|
4292
|
+
}
|
|
4293
|
+
}, 300);
|
|
4294
|
+
}; // We use this behavior only on iOS devices because there is a known issue that
|
|
4295
|
+
// sticky elements lose their stickiness when a keyboard appears on the screen
|
|
4296
|
+
|
|
4297
|
+
|
|
4298
|
+
React.useEffect(function () {
|
|
4299
|
+
if (absolutePositionParams) {
|
|
4300
|
+
changeWrapperVisibility(true, absolutePositionParams.topOffset);
|
|
4301
|
+
document.addEventListener('scroll', handleScrollForAbsolutePosition);
|
|
4302
|
+
return function () {
|
|
4303
|
+
document.removeEventListener('scroll', handleScrollForAbsolutePosition);
|
|
4304
|
+
};
|
|
4305
|
+
}
|
|
4306
|
+
|
|
4307
|
+
return;
|
|
4308
|
+
}, []);
|
|
4309
|
+
React.useEffect(function () {
|
|
4310
|
+
setTimeout(function () {
|
|
4311
|
+
if (tabListRef.current) tabListRef.current.scrollLeft += getScrollWidth();
|
|
4312
|
+
}, 500);
|
|
4313
|
+
}, []);
|
|
4236
4314
|
React.useEffect(function () {
|
|
4237
4315
|
var _tabListRef$current, _tabListRef$current2;
|
|
4238
4316
|
|
|
@@ -4287,6 +4365,12 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4287
4365
|
if (tabListRef.current) {
|
|
4288
4366
|
var scroll = tabListRef.current.scrollLeft;
|
|
4289
4367
|
var newScroll = Math.min(tabListRef.current.clientWidth, tabListRef.current.scrollWidth - scroll);
|
|
4368
|
+
|
|
4369
|
+
if (scroll - newScroll < LIST_ITEM_GAP) {
|
|
4370
|
+
tabListRef.current.scrollLeft += newScroll + LIST_ITEM_GAP;
|
|
4371
|
+
return;
|
|
4372
|
+
}
|
|
4373
|
+
|
|
4290
4374
|
tabListRef.current.scrollLeft += newScroll;
|
|
4291
4375
|
}
|
|
4292
4376
|
};
|
|
@@ -4295,6 +4379,12 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4295
4379
|
if (tabListRef.current) {
|
|
4296
4380
|
var scroll = tabListRef.current.scrollLeft;
|
|
4297
4381
|
var newScroll = Math.max(0, scroll - tabListRef.current.clientWidth);
|
|
4382
|
+
|
|
4383
|
+
if (newScroll < LIST_ITEM_GAP) {
|
|
4384
|
+
tabListRef.current.scrollLeft = newScroll - LIST_ITEM_GAP;
|
|
4385
|
+
return;
|
|
4386
|
+
}
|
|
4387
|
+
|
|
4298
4388
|
tabListRef.current.scrollLeft = newScroll;
|
|
4299
4389
|
}
|
|
4300
4390
|
};
|
|
@@ -4308,11 +4398,15 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4308
4398
|
_ref3$scrollWidth = _ref3.scrollWidth,
|
|
4309
4399
|
scrollWidth = _ref3$scrollWidth === void 0 ? 0 : _ref3$scrollWidth;
|
|
4310
4400
|
|
|
4311
|
-
setCanScrollToLeft(scrollLeft >
|
|
4312
|
-
setCanScrollToRight(scrollLeft + clientWidth < scrollWidth);
|
|
4401
|
+
setCanScrollToLeft(scrollLeft > LIST_ITEM_GAP);
|
|
4402
|
+
setCanScrollToRight(scrollLeft + clientWidth + LIST_ITEM_GAP < scrollWidth);
|
|
4313
4403
|
};
|
|
4314
4404
|
|
|
4315
|
-
return /*#__PURE__*/React__default.createElement(AnchorTabbarWrapper,
|
|
4405
|
+
return /*#__PURE__*/React__default.createElement(AnchorTabbarWrapper, {
|
|
4406
|
+
bottomBorder: bottomBorder,
|
|
4407
|
+
ref: wrapperRef,
|
|
4408
|
+
id: "AnchorTabbarWrapper"
|
|
4409
|
+
}, /*#__PURE__*/React__default.createElement(TabsGrid, null, /*#__PURE__*/React__default.createElement(GridItem, {
|
|
4316
4410
|
columnStartDesktop: tabsColumnStart,
|
|
4317
4411
|
columnSpanDesktop: tabsColumnSpan,
|
|
4318
4412
|
columnStartDevice: 2,
|
|
@@ -4320,6 +4414,7 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4320
4414
|
}, /*#__PURE__*/React__default.createElement(TabsWrapper, {
|
|
4321
4415
|
"data-testid": "anchor-tabs"
|
|
4322
4416
|
}, /*#__PURE__*/React__default.createElement(TabsList, {
|
|
4417
|
+
hasTwoArrows: hasTwoArrows,
|
|
4323
4418
|
ref: tabListRef,
|
|
4324
4419
|
tabsOverflow: tabsOverflow,
|
|
4325
4420
|
onScroll: onTabsScroll
|
|
@@ -4332,13 +4427,16 @@ var AnchorTabBar = function AnchorTabBar(_ref) {
|
|
|
4332
4427
|
key: id
|
|
4333
4428
|
}, /*#__PURE__*/React__default.createElement(TabLink, Object.assign({
|
|
4334
4429
|
selected: isSelectedItem(id),
|
|
4430
|
+
className: 'anchor-tab-bar-tablink',
|
|
4335
4431
|
id: "tablink-" + id,
|
|
4336
4432
|
onClick: function onClick(e) {
|
|
4337
4433
|
return onClicktab(e, id);
|
|
4338
4434
|
},
|
|
4339
4435
|
tabIndex: 0
|
|
4340
4436
|
}, rest), text));
|
|
4341
|
-
})), tabsOverflow ? /*#__PURE__*/React__default.createElement(ArrowsContainer,
|
|
4437
|
+
})), tabsOverflow ? /*#__PURE__*/React__default.createElement(ArrowsContainer, {
|
|
4438
|
+
fullWidth: hasTwoArrows
|
|
4439
|
+
}, canScrollToLeft ? /*#__PURE__*/React__default.createElement(ArrowWrapper, {
|
|
4342
4440
|
onClick: scrollToLeft
|
|
4343
4441
|
}, /*#__PURE__*/React__default.createElement(Icon, {
|
|
4344
4442
|
iconName: "Arrow",
|