Skip to content

Commit

Permalink
Merge pull request #971 from equinor/chore/tutorial-guide
Browse files Browse the repository at this point in the history
📝 Added documentation on how to use TutorialHighlightingProvider
  • Loading branch information
mariush2 authored Feb 12, 2025
2 parents 703c9cd + b24121f commit 32dc512
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 27 deletions.
13 changes: 13 additions & 0 deletions .storybook/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

code {
background: #3d3d3d;
padding: 2px 4px;
color: white;
font-family: monospace;
white-space: pre-wrap;
}

pre:has(> code) {
background: #3d3d3d;
padding: 24px;
}
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config: StorybookConfig = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-designs',
'@storybook/addon-docs',
'storybook-addon-data-theme-switcher',
'./addons/GitHubSearchAddon/manager.js',
'./addons/SpacingsAddon/manager.js',
Expand Down
2 changes: 2 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { handlers } from 'src/tests/mockHandlers';

import { initialize, mswLoader } from 'msw-storybook-addon';

import './index.css';

const { colors } = tokens;
initialize({
quiet: true,
Expand Down
Binary file modified bun.lockb
Binary file not shown.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.2",
"@storybook/addon-actions": "^8.5.3",
"@storybook/addon-actions": "^8.5.4",
"@storybook/addon-designs": "^8.1.0",
"@storybook/addon-docs": "^8.5.3",
"@storybook/addon-essentials": "^8.5.3",
"@storybook/addon-links": "^8.5.3",
"@storybook/addon-mdx-gfm": "^8.5.3",
"@storybook/blocks": "^8.5.3",
"@storybook/components": "^8.5.3",
"@storybook/manager-api": "^8.5.3",
"@storybook/preview-api": "^8.5.3",
"@storybook/react": "^8.5.3",
"@storybook/react-vite": "^8.5.3",
"@storybook/addon-docs": "^8.5.4",
"@storybook/addon-essentials": "^8.5.4",
"@storybook/addon-links": "^8.5.4",
"@storybook/addon-mdx-gfm": "^8.5.4",
"@storybook/blocks": "^8.5.4",
"@storybook/components": "^8.5.4",
"@storybook/manager-api": "^8.5.4",
"@storybook/preview-api": "^8.5.4",
"@storybook/react": "^8.5.4",
"@storybook/react-vite": "^8.5.4",
"@tanstack/react-query": "^5.66.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
Expand Down Expand Up @@ -153,7 +153,7 @@
"rollup": "^4.34.6",
"rollup-plugin-delete": "^2.1.0",
"rollup-plugin-import-css": "^3.5.8",
"storybook": "^8.5.3",
"storybook": "^8.5.4",
"storybook-addon-data-theme-switcher": "^1.0.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.23.0",
Expand Down
1 change: 1 addition & 0 deletions src/organisms/TopBar/Tutorials/Tutorials.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const meta: Meta = {
)}
/>
),
tags: ['!autodocs'],
parameters: {
layout: 'fullscreen',
design: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@


## How to use the TutorialHighlightingProvider

1. Install `@equinor/subsurface-app-management` at `2.5.2` or above

2. Place the `TutorialHighlightingProvider` inside the Routes, usually this would be here:

<br />

```typescript dark
// src/App.tsx
...
import { TutorialHighlightingProvider, ... } from '@equinor/amplify-component-lib';

export function App() {
const { isOpen } = useSideBar();

return (
<TutorialHighlightingProvider>
<Template.GlobalStyles />
<Template>
<ApplicationTopBar />
<Template.Container>
<ApplicationSideBar />
<Template.Content $open={isOpen} id="content">
<Outlet />
</Template.Content>
</Template.Container>
</Template>
</TutorialHighlightingProvider>
);
}
```

This needs to be placed within the Routes, because it uses hooks from `react-router` to figure out what path you are on


3. Add the `<TopBar.Tutorials>` component to the topbar to make the menu accessible to the user


4. Create your tutorial in SAM and copy the tutorials ID to your app so you can use them to generate the correct IDs for the elements you want to highlight

```tsx dark
// src/constants/tutorials.ts
const MY_TUTORIAL_ID = 'my-tutorial-id';

// src/pages/SomeRandomPage.tsx
import { highlightTutorialElementID } from '@equinor/amplify-component-lib';

export const SomeRandomPage = () => {

return (
<div>
<h1>This is the header</h1>
<div id={highlightTutorialElementID(MY_TUTORIAL_ID, 0)}>First step in the tutorial!</div>
<section>Unrelated content</section>
<div id={highlightTutorialElementID(MY_TUTORIAL_ID, 1)}>Second step in the tutorial!</div>
</div>
);
};
```

This function takes in the tutorial ID and the step index, and generates a unique ID for the element you want to highlight. This is then again used by the `TutorialHighlightingProvider` to figure out the elements position and size.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { faker } from '@faker-js/faker';
import { Meta, StoryObj } from '@storybook/react';

import { TutorialHighlightingProvider } from './TutorialHighlightingProvider';
import page from './TutorialHighlightingProvider.docs.mdx';
import { highlightTutorialElementID } from 'src/atoms';
import { environment } from 'src/atoms/utils/auth_environment';
import {
Expand All @@ -15,7 +16,7 @@ import {
tokenHandler,
} from 'src/tests/mockHandlers';

import { delay, http, HttpResponse } from 'msw';
import { http, HttpResponse } from 'msw';

const TUTORIAL_IDS = [faker.string.uuid(), faker.string.uuid()];

Expand Down Expand Up @@ -100,6 +101,7 @@ const meta: Meta = {
/>
);
},
tags: ['!autodocs'],
parameters: {
layout: 'fullscreen',
design: {
Expand All @@ -118,14 +120,24 @@ const meta: Meta = {

export default meta;

export const HowToUse: StoryObj = {
parameters: {
layout: 'padded',
docs: {
source: {
dark: true,
},
},
},
render: page,
};

export const HighlightingElement: StoryObj = {
parameters: {
msw: {
handlers: [
tokenHandler,
http.get(`*/api/v1/Tutorial/*`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = TUTORIAL_IDS.map((id, index) =>
fakeTutorial(id, index === 0, true)
);
Expand All @@ -143,8 +155,6 @@ export const MultipleHighlightingElement: StoryObj = {
handlers: [
tokenHandler,
http.get(`*/api/v1/Tutorial/*`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = TUTORIAL_IDS.map((id) =>
fakeTutorial(id, true, true)
);
Expand All @@ -162,8 +172,6 @@ export const CenterTutorial: StoryObj = {
handlers: [
tokenHandler,
http.get(`*/api/v1/Tutorial/*`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = TUTORIAL_IDS.map((id, index) =>
fakeTutorial(id, index === 0, false)
);
Expand All @@ -181,8 +189,6 @@ export const MultipleCenterTutorial: StoryObj = {
handlers: [
tokenHandler,
http.get(`*/api/v1/Tutorial/*`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = TUTORIAL_IDS.map((id) =>
fakeTutorial(id, true, false)
);
Expand All @@ -200,8 +206,6 @@ export const MixedTutorial: StoryObj = {
handlers: [
tokenHandler,
http.get(`*/api/v1/Tutorial/*`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = [
{
id: TUTORIAL_IDS[0],
Expand Down Expand Up @@ -247,8 +251,6 @@ export const ScrollToElement: StoryObj = {
handlers: [
tokenHandler,
http.get(`*/api/v1/Tutorial/*`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = [
{
id: TUTORIAL_IDS[0],
Expand Down Expand Up @@ -301,8 +303,6 @@ export const TutorialWithImage: StoryObj = {
tokenHandler,
getTutorialImageHandler,
http.get(`*/api/v1/Tutorial/draft/:applicationName`, async () => {
await delay('real');

const tutorials: MyTutorialDto[] = [
{
id: TUTORIAL_IDS[0],
Expand Down

0 comments on commit 32dc512

Please sign in to comment.