Skip to content

Commit

Permalink
TS config for ui package, Add TrackPopup to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Mar 25, 2020
1 parent ba66d8a commit c7776d6
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 16 deletions.
9 changes: 6 additions & 3 deletions packages/ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "../../.eslintrc.json",
"extends": [
"../../.eslintrc.json",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true,
"commonjs": true,
Expand All @@ -9,12 +12,12 @@
"_": true,
"process": true
},
"parser": "babel-eslint",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"ecmaVersion": 2020,
"sourceType": "module"
}
}
9 changes: 0 additions & 9 deletions packages/ui/.storybook/config.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/ui/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
stories: [
'../stories/*.stories.js',
'../stories/*.stories.tsx'
],
addons: [
'@storybook/preset-typescript',
'@storybook/addon-actions',
'@storybook/addon-links'
]
}
84 changes: 84 additions & 0 deletions packages/ui/lib/components/TrackPopup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';

import ContextPopup from '../ContextPopup';
import PopupButton from '../PopupButton';
import { Popup } from 'semantic-ui-react';

const TrackPopup: React.FC<{
trigger: React.ReactNode;
artist: string;
title: string;
thumb: string;

withAddToQueue: boolean;
withPlayNow: boolean;
withAddToFavorites: boolean;
withAddToDownloads: boolean;

onAddToQueue: () => void;
onPlayNow: () => void;
onAddToFavorites: () => void;
onAddToDownloads: () => void;
}> = ({
trigger,
artist,
title,
thumb,
withAddToQueue,
withPlayNow,
withAddToFavorites,
withAddToDownloads,
onAddToQueue,
onPlayNow,
onAddToFavorites,
onAddToDownloads
}) => (
<ContextPopup
trigger={trigger}
artist={artist}
title={title}
thumb={thumb}
>
{
withAddToQueue &&
<PopupButton
onClick={onAddToQueue}
ariaLabel='Add track to queue'
icon='plus'
label='Add to queue'
/>
}

{
withPlayNow &&
<PopupButton
onClick={onPlayNow}
ariaLabel='Play this track now'
icon='play'
label='Play now'
/>
}

{
withAddToFavorites &&
<PopupButton
onClick={onAddToFavorites}
ariaLabel='Add this track to favorites'
icon='star'
label='Add to favorites'
/>
}

{
withAddToDownloads &&
<PopupButton
onClick={onAddToDownloads}
ariaLabel='Download this track'
icon='download'
label='Download'
/>
}
</ContextPopup>
);

export default TrackPopup;
6 changes: 5 additions & 1 deletion packages/ui/lib/components/TrackRow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ const TrackRow = ({
{
displayArtist &&
<td className={styles.track_row_artist}>
{ track.artist }
{
_.isString(track.artist)
? track.artist
: track.artist.name
}
</td>
}
<td className={styles.track_row_name}>
Expand Down
1 change: 1 addition & 0 deletions packages/ui/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { default as StreamInfo } from './components/StreamInfo';
export { default as Range } from './components/Range';
export { default as Seekbar } from './components/Seekbar';
export { default as ToastContainer } from './components/ToastContainer';
export { default as TrackPopup } from './components/TrackPopup';
export { default as TrackRow } from './components/TrackRow';
export { default as UserPluginsItem } from './components/UserPluginsItem';
export { default as SearchBox } from './components/SearchBox';
Expand Down
14 changes: 11 additions & 3 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"license": "AGPL-3.0",
"scripts": {
"storybook": "start-storybook -p 9001 -c .storybook",
"start": "tsc",
"build": "tsc",
"lint": "eslint lib stories --fix",
"test": "eslint lib && ava"
},
Expand All @@ -32,10 +34,14 @@
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.6.2",
"@storybook/addon-actions": "^3.4.12",
"@storybook/addon-info": "^5.3.17",
"@storybook/addon-knobs": "^3.4.12",
"@storybook/addon-links": "^3.4.10",
"@storybook/cli": "^5.2.1",
"@storybook/react": "^5.2.1",
"@storybook/addon-links": "^3.4.12",
"@storybook/cli": "^5.3.17",
"@storybook/preset-typescript": "^2.1.0",
"@storybook/react": "^5.3.17",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"ava": "^2.4.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^8.0.6",
Expand All @@ -57,6 +63,8 @@
"react-hot-loader": "^4.3.4",
"sass-loader": "^6.0.7",
"style-loader": "^0.21.0",
"ts-loader": "^6.2.2",
"typescript": "^3.8.3",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0",
Expand Down
32 changes: 32 additions & 0 deletions packages/ui/stories/trackPopup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { Button } from 'semantic-ui-react';

import { TrackPopup } from '..';

export default {
title: 'Track popup'
}

const track = {
artist: 'Test',
title: 'Test title',
thumb: 'https://i.imgur.com/4euOws2.jpg'
};

export const WithNoButtons = () => <div className='bg'>
<TrackPopup
trigger={<Button>Click here</Button>}
{...track}
/>
</div>;

export const WithAllButtons = () => <div className='bg'>
<TrackPopup
trigger={<Button>Click here</Button>}
{...track}
withAddToQueue
withPlayNow
withAddToFavorites
withAddToDownloads
/>
</div>;
20 changes: 20 additions & 0 deletions packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"lib": ["DOM"],
"declaration": true,
"outDir": "dist",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": false,
"typeRoots": [
"node_modules/@types"
],
"jsx": "react"
},
"include": [
"lib",
"stories"
]
}

0 comments on commit c7776d6

Please sign in to comment.