Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martynaskadisa committed Jul 26, 2020
1 parent f2c2887 commit c2bd4ed
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 60 deletions.
26 changes: 26 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"plugins": ["react-hooks"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
"ignorePatterns": "dist/**/*"
}
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": false
},
"[typescript]": {
"editor.formatOnSave": false
},
"[typescriptreact]": {
"editor.formatOnSave": false
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
20 changes: 20 additions & 0 deletions example/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": ["plugin:react-hooks/recommended", "plugin:prettier/recommended"],
"plugins": ["react-hooks"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
}
}
17 changes: 12 additions & 5 deletions example/public/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#0c2427" />

<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link
href="https://fonts.googleapis.com/css2?family=Recursive:[email protected]&display=swap"
rel="stylesheet"
/>

<title>use-media-session</title>
</head>
Expand Down
42 changes: 33 additions & 9 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import React from 'react'

import { useMyHook } from 'use-media-session'
import React from 'react';
import { useMediaMeta } from 'use-media-session';

const App = () => {
const example = useMyHook()
useMediaMeta({
title: 'React app',
album: 'React',
artist: 'React',
});
return (
<div>
{example}
<div style={{ maxWidth: 800, margin: '2rem auto', padding: '1rem' }}>
<h1 style={{ textAlign: 'center' }}>use-media-session</h1>
<p style={{ textAlign: 'center', marginBottom: '5rem' }}>
Hooks for interacting with Media Session API
</p>
<div style={{ textAlign: 'center' }}>
<a
href="https://github.com/martynaskadisa/use-media-session"
target="_blank"
rel="noopener noreferrer"
class="button"
>
Github
</a>
</div>
<h2 style={{ marginTop: '5rem' }}>Install</h2>
<pre>npm install use-media-session</pre>
<p>or</p>
<pre>yarn add use-media-session</pre>
<h2 style={{ marginTop: '5rem' }}>Examples</h2>
<p>// @TODO</p>
<h3>API reference</h3>
<p>// also @TODO</p>
</div>
)
}
export default App
);
};
export default App;
64 changes: 61 additions & 3 deletions example/src/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
/* body {
:root {
--color-1: #ec93a2;
--color-2: #dbc1e1;
--color-3: #0c2427;
--color-4: #f8c296;

--text-color: var(--color-2);
--background: var(--color-3);
}

@media (prefers-color-scheme: light) {
:root {
--text-color: var(--color-3);
--background: var(--color-4);
}
}

body {
margin: 0;
padding: 0;
font-family: sans-serif;
} */
background: var(--background);
color: var(--text-color);
font-size: 125%;
font-family: 'Recursive', monospace;
}

h1 {
font-size: 3rem;
font-variation-settings: 'wght' 800;
}

pre {
display: block;
padding: 1rem;
border-width: 1px;
border-style: solid;
border-color: currentcolor;
border-image: initial;
border-radius: 3px;
}

.button {
display: inline-block;
color: inherit;
text-decoration: none;
margin: 0;
padding: 1rem 1.2rem;
border-width: 1px;
border-style: solid;
border-color: currentcolor;
border-radius: 3px;
}

.button:hover {
background: var(--text-color);
color: var(--background)
}

*,
*:before,
*:after {
box-sizing: border-box;
}
10 changes: 5 additions & 5 deletions example/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom'
import React from 'react';
import ReactDOM from 'react-dom';

import './index.css'
import App from './App'
import './index.css';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'))
ReactDOM.render(<App />, document.getElementById('root'));
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-media-session",
"version": "1.0.0",
"version": "0.0.1",
"description": "React hooks for Media Session API",
"author": "martynaskadisa",
"license": "MIT",
Expand All @@ -15,6 +15,7 @@
"scripts": {
"test": "cross-env CI=1 react-scripts test --env=jsdom",
"test:watch": "react-scripts test --env=jsdom",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"build": "rollup -c",
"start": "rollup -c -w",
"prepare": "yarn run build",
Expand All @@ -31,8 +32,15 @@
"@testing-library/react-hooks": "^3.2.1",
"@types/jest": "^23.3.13",
"@types/react": "^16.7.22",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.7.0",
"cross-env": "^5.2.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react-hooks": "^4.0.8",
"gh-pages": "^2.0.1",
"prettier": "^2.0.5",
"react": "^16.9.0",
"react-scripts": "^3.4.0",
"react-test-renderer": "^16.9.0",
Expand Down
14 changes: 9 additions & 5 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useMyHook } from './'
import { renderHook, act } from "@testing-library/react-hooks";
import { useMediaMeta } from './';
import { renderHook, act } from '@testing-library/react-hooks';

// mock timer using jest
jest.useFakeTimers();

describe('useMyHook', () => {
it('updates every second', () => {
const { result } = renderHook(() => useMyHook());
const { result } = renderHook(() =>
useMediaMeta({
title: 'Title',
})
);

expect(result.current).toBe(0);

Expand All @@ -25,5 +29,5 @@ describe('useMyHook', () => {

// Check after total 2 sec
expect(result.current).toBe(2);
})
})
});
});
Loading

0 comments on commit c2bd4ed

Please sign in to comment.