diff --git a/packages/arwes/src/Button/index.js b/packages/arwes/src/Button/index.js index 2f8deb04..717b80f5 100644 --- a/packages/arwes/src/Button/index.js +++ b/packages/arwes/src/Button/index.js @@ -1,5 +1,5 @@ import withStyles from '../tools/withStyles'; -import withSounds from '../tools/withSounds'; +import { withSounds } from '@arwes/sounds'; import Button from './Button'; import styles from './styles'; diff --git a/packages/arwes/src/Footer/index.js b/packages/arwes/src/Footer/index.js index cde19df6..ae6088df 100644 --- a/packages/arwes/src/Footer/index.js +++ b/packages/arwes/src/Footer/index.js @@ -1,5 +1,5 @@ import withStyles from '../tools/withStyles'; -import withSounds from '../tools/withSounds'; +import { withSounds } from '@arwes/sounds'; import Footer from './Footer'; import styles from './styles'; diff --git a/packages/arwes/src/Frame/index.js b/packages/arwes/src/Frame/index.js index 5bdb6a31..1026bfb5 100644 --- a/packages/arwes/src/Frame/index.js +++ b/packages/arwes/src/Frame/index.js @@ -1,5 +1,5 @@ import withStyles from '../tools/withStyles'; -import withSounds from '../tools/withSounds'; +import { withSounds } from '@arwes/sounds'; import Frame from './Frame'; import styles from './styles'; diff --git a/packages/arwes/src/Frame/sandbox.js b/packages/arwes/src/Frame/sandbox.js index 4c96e54b..abc55d7f 100644 --- a/packages/arwes/src/Frame/sandbox.js +++ b/packages/arwes/src/Frame/sandbox.js @@ -15,6 +15,7 @@ export default class Example extends React.Component { { } }, + // TODO: The hover rule is not being referenced by JSS. '&$hover:hover': { '& $border': { borderColor: props => getColor(theme, props, 'base'), diff --git a/packages/arwes/src/Header/index.js b/packages/arwes/src/Header/index.js index 144b2f77..f7d5ab2e 100644 --- a/packages/arwes/src/Header/index.js +++ b/packages/arwes/src/Header/index.js @@ -1,5 +1,5 @@ import withStyles from '../tools/withStyles'; -import withSounds from '../tools/withSounds'; +import { withSounds } from '@arwes/sounds'; import Header from './Header'; import styles from './styles'; diff --git a/packages/arwes/src/Project/index.js b/packages/arwes/src/Project/index.js index 546bedc2..f3b3c511 100644 --- a/packages/arwes/src/Project/index.js +++ b/packages/arwes/src/Project/index.js @@ -1,5 +1,5 @@ import withStyles from '../tools/withStyles'; -import withSounds from '../tools/withSounds'; +import { withSounds } from '@arwes/sounds'; import Project from './Project'; import styles from './styles'; diff --git a/packages/arwes/src/SoundsProvider/Readme.md b/packages/arwes/src/SoundsProvider/Readme.md deleted file mode 100644 index 29d21aaa..00000000 --- a/packages/arwes/src/SoundsProvider/Readme.md +++ /dev/null @@ -1,10 +0,0 @@ -Sounds provider process the sounds to play and rain them down to the child -components with the HOC `withSounds` so they may use them. - -In the Arwes built-in components the sounds are optional, they check if the players -are provided to play them, so this provider is optional for Arwes components. - -More sounds can be configured with `createSounds` tool and passed to the provider -so any child component can use them. - -Go to [Sounds System](/docs/sounds-system) for more details. diff --git a/packages/arwes/src/SoundsProvider/index.js b/packages/arwes/src/SoundsProvider/index.js deleted file mode 100644 index 1372b7c0..00000000 --- a/packages/arwes/src/SoundsProvider/index.js +++ /dev/null @@ -1,43 +0,0 @@ -import { Component } from 'react'; -import PropTypes from 'prop-types'; -import createPlayerModule from '../tools/createPlayer'; - -export default class SoundsProvider extends Component { - static propTypes = { - sounds: PropTypes.object.isRequired, - createPlayer: PropTypes.any.isRequired - }; - - static defaultProps = { - createPlayer: createPlayerModule - }; - - static childContextTypes = { - sounds: PropTypes.object - }; - - getChildContext() { - const { sounds, createPlayer } = this.props; - const { shared, players } = sounds; - - const soundsPlayers = {}; - - Object.keys(players).forEach(name => { - const player = players[name]; - - // Spread the shared config for all sounds. - player.sound = { - ...shared, - ...player.sound - }; - - soundsPlayers[name] = createPlayer(null, player); - }); - - return { sounds: soundsPlayers }; - } - - render() { - return this.props.children; - } -} diff --git a/packages/arwes/src/SoundsProvider/index.test.js b/packages/arwes/src/SoundsProvider/index.test.js deleted file mode 100644 index 7cf74a6f..00000000 --- a/packages/arwes/src/SoundsProvider/index.test.js +++ /dev/null @@ -1,65 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import Enzyme, { mount } from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -import SoundsProvider from './index'; - -Enzyme.configure({ adapter: new Adapter() }); - -describe('SoundsProvider', function() { - it('Should be able to create a sounds provider', function() { - const sounds = { shared: {}, players: { click: {} } }; - class Howl {} - const createPlayer = () => new Howl(); - - class MyComp extends React.Component { - static contextTypes = { - sounds: PropTypes.object - }; - render() { - expect(this.context.sounds.click).toBeTruthy(); - expect(this.context.sounds.click instanceof Howl).toBeTruthy(); - return
; - } - } - - mount( - - - - ); - }); - - it('Should be able to define players with shared config', function() { - const sounds = { - shared: { volume: 0.75 }, - players: { click: { sound: { loop: true } } } - }; - class Howl { - constructor(config) { - this.config = config; - } - } - const createPlayer = (deps, config) => new Howl(config.sound); - - class MyComp extends React.Component { - static contextTypes = { - sounds: PropTypes.object - }; - render() { - expect(this.context.sounds.click.config).toEqual({ - volume: 0.75, - loop: true - }); - return
; - } - } - - mount( - - - - ); - }); -}); diff --git a/packages/arwes/src/SoundsProvider/sandbox.js b/packages/arwes/src/SoundsProvider/sandbox.js deleted file mode 100644 index 8865f9db..00000000 --- a/packages/arwes/src/SoundsProvider/sandbox.js +++ /dev/null @@ -1,31 +0,0 @@ -import React from 'react'; -import createSounds from '../tools/createSounds'; -import withSounds from '../tools/withSounds'; -import SoundsProvider from './index'; - -const Player = withSounds()(props => ( - -)); - -const sounds = { - shared: { volume: 1 }, - players: { - information: { sound: { src: ['/sound/information.mp3'] } }, - ask: { sound: { src: ['/sound/ask.mp3'] } }, - warning: { sound: { src: ['/sound/warning.mp3'] } }, - error: { sound: { src: ['/sound/error.mp3'] } } - } -}; - -export default () => ( - -
- - - - -
-
-); diff --git a/packages/arwes/src/Words/index.js b/packages/arwes/src/Words/index.js index c250d3c2..52e0b0c2 100644 --- a/packages/arwes/src/Words/index.js +++ b/packages/arwes/src/Words/index.js @@ -1,5 +1,5 @@ import withStyles from '../tools/withStyles'; -import withSounds from '../tools/withSounds'; +import { withSounds } from '@arwes/sounds'; import Words from './Words'; import styles from './styles'; diff --git a/packages/arwes/src/index.js b/packages/arwes/src/index.js index 2b435af7..14371dbe 100644 --- a/packages/arwes/src/index.js +++ b/packages/arwes/src/index.js @@ -27,13 +27,8 @@ export ThemeProvider from './ThemeProvider'; export withStyles from './tools/withStyles'; export createTheme from './tools/createTheme'; -export SoundsProvider from './SoundsProvider'; -export withSounds from './tools/withSounds'; -export createSounds from './tools/createSounds'; - export createLoader from './tools/createLoader'; export createResponsive from './tools/createResponsive'; -export createPlayer from './tools/createPlayer'; import * as toolsUtils from './tools/utils'; export const utils = toolsUtils; diff --git a/packages/arwes/src/tools/createPlayer/index.js b/packages/arwes/src/tools/createPlayer/index.js deleted file mode 100644 index 09c61c38..00000000 --- a/packages/arwes/src/tools/createPlayer/index.js +++ /dev/null @@ -1,35 +0,0 @@ -import howler from 'howler'; - -/** - * Create handler for sound player functionalities. - * This uses the `howler` package to create a player. - * @param {Object} depencencies - * @param {Function} depencencies.Howl - * @param {Object} conf - Player configuration - * @param {Object} conf.sound - Configuration passed to `howler.Howl`. - * @param {Object} conf.settings - Sound settings - * @return {Howl} - */ -export default (depencencies, conf) => { - const deps = { - Howl: howler.Howl, - ...depencencies - }; - - const { sound = {}, settings = {} } = conf || {}; - const player = new deps.Howl(sound); - - if (settings.oneAtATime) { - const play = player.play.bind(player); - let lastPlay; - player.play = function(...args) { - if (lastPlay) { - this.stop(lastPlay); - } - lastPlay = play(...args); - return lastPlay; - }; - } - - return player; -}; diff --git a/packages/arwes/src/tools/createPlayer/index.test.js b/packages/arwes/src/tools/createPlayer/index.test.js deleted file mode 100644 index 8d9e2be4..00000000 --- a/packages/arwes/src/tools/createPlayer/index.test.js +++ /dev/null @@ -1,39 +0,0 @@ -import sinon from 'sinon'; -import createPlayer from './index'; - -describe('createPlayer', function() { - it('Should create a player with default config', function() { - class Howl {} - const player = createPlayer({ Howl }); - expect(player instanceof Howl).toBeTruthy(); - }); - - it('Should create a player with config', function() { - class Howl { - constructor(config) { - this.config = config; - } - } - const sound = 10; - const player = createPlayer({ Howl }, { sound }); - expect(player.config).toBe(sound); - }); - - it('Should create a player to play the sound only once a time', function() { - const play = sinon.stub().returns(100); - const stop = sinon.spy(); - class Howl { - constructor() { - this.play = play; - this.stop = stop; - } - } - const player = createPlayer({ Howl }, { settings: { oneAtATime: true } }); - - const lastPlayId = player.play(); - player.play(); - - expect(stop.callCount).toBe(1); - expect(stop.calledWith(lastPlayId)).toBeTruthy(); - }); -}); diff --git a/packages/arwes/src/tools/createSounds/index.js b/packages/arwes/src/tools/createSounds/index.js deleted file mode 100644 index 986d806b..00000000 --- a/packages/arwes/src/tools/createSounds/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import extend from 'extend'; -import sounds from './sounds'; - -/** - * Extend the default sounds with new properties. - * @param {Object} overwrite - * @return {Object} - */ -export default overwrite => { - return extend(true, {}, sounds, overwrite); -}; diff --git a/packages/arwes/src/tools/createSounds/sounds.js b/packages/arwes/src/tools/createSounds/sounds.js deleted file mode 100644 index 27923c2a..00000000 --- a/packages/arwes/src/tools/createSounds/sounds.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - shared: { - preload: true, - volume: 0.5 - }, - players: {} -}; diff --git a/packages/arwes/src/tools/withSounds/index.js b/packages/arwes/src/tools/withSounds/index.js deleted file mode 100644 index b1efa541..00000000 --- a/packages/arwes/src/tools/withSounds/index.js +++ /dev/null @@ -1,26 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import hoistNonReactStatics from 'hoist-non-react-statics'; - -export default () => { - return Inner => { - const displayName = Inner.displayName || Inner.name || 'Component'; - - const defaultProps = { ...Inner.defaultProps }; - delete defaultProps.sounds; - - class Sounds extends Component { - static displayName = `ArwesSounds(${displayName})`; - static defaultProps = defaultProps; - static contextTypes = { - sounds: PropTypes.object - }; - render() { - const { props, context } = this; - return ; - } - } - - return hoistNonReactStatics(Sounds, Inner); - }; -}; diff --git a/packages/arwes/src/tools/withSounds/index.test.js b/packages/arwes/src/tools/withSounds/index.test.js deleted file mode 100644 index 328f19a2..00000000 --- a/packages/arwes/src/tools/withSounds/index.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import Enzyme, { mount } from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -import withSounds from './index'; - -Enzyme.configure({ adapter: new Adapter() }); - -describe('withSounds', function() { - it('Should create a component with sounds by provider', function() { - // These sounds are provided - const sounds = { thesounds: 1 }; - - // A provider mock - class Provider extends React.Component { - static childContextTypes = { - sounds: PropTypes.object - }; - getChildContext() { - return { sounds }; - } - render() { - return this.props.children; - } - } - - const MyComp = props => { - // Assert the provided sounds are the same - expect(props.sounds).toBe(sounds); - return
; - }; - const MyCompWithSounds = withSounds()(MyComp); - - mount( - - - - ); - }); -});