Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DE-6498: Add Storybook #12

Merged
merged 12 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
app/dist/
.npmrc
.vscode/
.DS_Store
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!dist/**/*
dist/storybook/**/*
26 changes: 26 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import type { StorybookConfig } from "@storybook/react-webpack5";

const config: StorybookConfig = {
stories: ["../story/stories/**/*.mdx", "../story/stories/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-webpack5",
options: {},
},
docs: {
autodocs: "tag",
},
babel: (options) => ({
...options,
configFile: './story/.babelrc.json'
}),
};



export default config;
6 changes: 6 additions & 0 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from '@storybook/manager-api';
import theme from './theme';

addons.setConfig({
theme,
});
23 changes: 23 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PrestoContextDecorator } from "../story/stories/prep";
import "./style.css"

import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
options: {
method: 'alphabetical',
order: ['Intro'],
},
},
decorators: [PrestoContextDecorator],
};

export default preview;
21 changes: 21 additions & 0 deletions .storybook/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
button.docblock-code-toggle {
font-style:italic;
}

.sb-clpp-anchor {
font-size: 1em;
cursor: pointer;
color: #2c98db;
font-family: "Nunito Sans",-apple-system,".SFNSText-Regular",
"San Francisco",BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Helvetica,Arial,sans-serif
}
.sb-clpp-anchor:visited {
color: #205576;
}
.sb-clpp-anchor:hover {
color: #58baf6;
}

.css-79elbk {
display: none;
}
9 changes: 9 additions & 0 deletions .storybook/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { create } from '@storybook/theming/create';

export default create({
base: 'light',
brandTitle: 'My custom Storybook',
brandUrl: '#',
brandImage: 'https://castlabs.com/wp-content/uploads/castlabs-logo.svg',
brandTarget: '_self',
});
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Breaking changes

* Removed `showWhenDisabled` props from `PlayerControls`, it is no longer meaningful after the recent changes
to controls visibility. Now controls are always visible when video is paused or idle.
* Removed the `player` prop from all components (except `PlayerSurface`). Instead of it, all components should
be descendants of `PlayerSurface` and this way they get access to the `player` instance from its context.
```jsx
Expand Down Expand Up @@ -36,9 +38,19 @@

## Fixes

* Fixes to `BaseThemeOverlay`:
* Before start of playback make sure `CurrentTime` displays a valid value of `0:00`.
* Make sure seek bar is visible.
* Improve responsiveness of the UI.
* Improve positioning by `HoverContainer`.
* All components now accept `style` and `className` prop and apply them to their top-most element.
* Removed `children` prop from components that do not render any child components.
* Fix `Duration` to display the correct value even when it is rendered after the video has been loaded.

## Changes

* Player controls auto-hide after 3s instead of 5s.
* Added `mode` prop to `PlayerControls` which can be used to configure the visibility of player controls.

# 0.6.0 (Beta)

Expand Down
7 changes: 7 additions & 0 deletions README_INTERNAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ npm run publish
npm run test
```

## Docs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add note how to run storybook?


We are transitioning to use `Storybook` for public docs. Once that is done `app` can be deleted.

```sh
npm run storybook
```
37 changes: 17 additions & 20 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {
useMemo,
useState,
} from 'react'
import ClickAway from 'react-hook-click-away'

import { Asset, TestAssets } from './Asset'
import { BasicOverlayPage } from './BasicOverlayPage'
Expand Down Expand Up @@ -78,26 +77,24 @@ export function App() {
<h1>PRESTOplay React Components</h1>
</div>

<ClickAway onClickAway={() => setNavVisible(false)}>
<nav className={`sidenav ${navVisible ? 'visible' : ''}`} ref={navRef}>
<button onClick={toggleNav} className={'nav-toggle'}>Hide</button>
<h3>Content</h3>
<button onClick={selectAsset(0)} className={`${assetId === 0 ? 'selected' : ''}`}>{TestAssets[0].title}</button>
<button onClick={selectAsset(1)} className={`${assetId === 1 ? 'selected' : ''}`}>{TestAssets[1].title}</button>
<button onClick={selectAsset(2)} className={`${assetId === 2 ? 'selected' : ''}`}>{TestAssets[2].title}</button>
<button onClick={selectAsset(3)} className={`${assetId === 3 ? 'selected' : ''}`}>{TestAssets[3].title}</button>
<h3>Options</h3>
<label>
<input type={'checkbox'} checked={autoload} onChange={() => {setAutoload(!autoload)}}/>
<nav className={`sidenav ${navVisible ? 'visible' : ''}`} ref={navRef}>
<button onClick={toggleNav} className={'nav-toggle'}>Hide</button>
<h3>Content</h3>
<button onClick={selectAsset(0)} className={`${assetId === 0 ? 'selected' : ''}`}>{TestAssets[0].title}</button>
<button onClick={selectAsset(1)} className={`${assetId === 1 ? 'selected' : ''}`}>{TestAssets[1].title}</button>
<button onClick={selectAsset(2)} className={`${assetId === 2 ? 'selected' : ''}`}>{TestAssets[2].title}</button>
<button onClick={selectAsset(3)} className={`${assetId === 3 ? 'selected' : ''}`}>{TestAssets[3].title}</button>
<h3>Options</h3>
<label>
<input type={'checkbox'} checked={autoload} onChange={() => {setAutoload(!autoload)}}/>
Auto Load
</label>
<h3>Layouts</h3>
<button onClick={selectPage('basic')} className={`${pageId === 'basic' ? 'selected' : ''}`}>Basic Overlay</button>
<button onClick={selectPage('custom')} className={`${pageId === 'custom' ? 'selected' : ''}`}>Custom Overlay</button>
<button onClick={selectPage('youtube')} className={`${pageId === 'youtube' ? 'selected' : ''}`}>Youtube Overlay</button>
<button onClick={selectPage('components')} className={`${pageId === 'components' ? 'selected' : ''}`}>Components</button>
</nav>
</ClickAway>
</label>
<h3>Layouts</h3>
<button onClick={selectPage('basic')} className={`${pageId === 'basic' ? 'selected' : ''}`}>Basic Overlay</button>
<button onClick={selectPage('custom')} className={`${pageId === 'custom' ? 'selected' : ''}`}>Custom Overlay</button>
<button onClick={selectPage('youtube')} className={`${pageId === 'youtube' ? 'selected' : ''}`}>Youtube Overlay</button>
<button onClick={selectPage('components')} className={`${pageId === 'components' ? 'selected' : ''}`}>Components</button>
</nav>

<div>
{page}
Expand Down
59 changes: 0 additions & 59 deletions app/src/youtube.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,65 +105,6 @@
position: relative;
}

.pp-yt-center-background {
position: absolute;
top: 50%;
left: 50%;
right: 50%;
bottom: 50%;
width: 64px;
height: 64px;

transform: translate(-50%,-50%);
z-index: -1;
border-radius: 32px;
background-color: rgba(0, 0, 0, .25);
}

.pp-yt-center-toggle .pp-ui-playpause-toggle {
opacity: 0;
}

.pp-yt-center-toggle.pp-ui-playpause-toggle-pause {
opacity: 0;
animation-name: center-fade;
animation-duration: 500ms;
animation-direction: normal;
animation-fill-mode: forwards;
animation-timing-function: ease;
}

.pp-yt-center-toggle.pp-ui-playpause-toggle-play {
opacity: 0;
animation-name: center-fade-2;
animation-duration: 500ms;
animation-direction: normal;
animation-fill-mode: forwards;
animation-timing-function: ease;
}

@keyframes center-fade {
from {
opacity: .8;
scale: .25;
}
to {
opacity: 0;
scale: 1.75;
}
}


@keyframes center-fade-2 {
from {
opacity: .8;
scale: .25;
}
to {
opacity: 0;
scale: 1.75;
}
}

.pp-yt-gradient-bottom {
height: 146px;
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = {
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
testEnvironment: 'jsdom',
transformIgnorePatterns: ['/node_modules/(?!(@castlabs/prestoplay)/)'],
moduleNameMapper: {
'@castlabs/prestoplay.*': '<rootDir>/tests/fake_clpp.js',
}
},
resolver: '<rootDir>/jest.resolver.js',
}
31 changes: 31 additions & 0 deletions jest.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Imports from @react-hook are for some reason not resolved correctly, and they end up
* importing ESM code instead of transpiled ES5 which causes a crash of the test suite.
* Fix it by correcting those paths here.
*
* (The package.json.exports field in @react-hook/ is the problem.
* Ideally I would fix this via the `options.packageFilter`, but that
* for some reason is not working - possibly a bug in Jest. So I'm just
* doing a simple replace here instead.)
*/
function fixReactHookPaths(path) {
doubeka marked this conversation as resolved.
Show resolved Hide resolved
const replacements = {
'@react-hook/resize-observer/dist/module/index.js': '@react-hook/resize-observer/dist/main/index.js',
'@react-hook/passive-layout-effect/dist/module/index.js': '@react-hook/passive-layout-effect/dist/main/index.js',
'@react-hook/latest/dist/module/index.js': '@react-hook/latest/dist/main/index.js',
}

Object.keys(replacements).forEach(key => {
path = path.replace(key, replacements[key])
})

return path
}

/**
* https://jestjs.io/docs/configuration/#resolver-string
*/
module.exports = (path, options) => {
let result = options.defaultResolver(path, options)
return fixReactHookPaths(result)
}
Loading