Skip to content

Instantly share code, notes, and snippets.

@Sidnioulz
Last active December 14, 2021 16:04
Show Gist options
  • Save Sidnioulz/1909d14fe4307655ba8e05f9285944fa to your computer and use it in GitHub Desktop.
Save Sidnioulz/1909d14fe4307655ba8e05f9285944fa to your computer and use it in GitHub Desktop.
LJN Reclame Architecture - Gist 10
import PropTypes from '@ljn/prop-types'
import Disableable from 'interfaces/Disableable'
import feature from 'core/feature'
/**
* Allows focusing a target element.
* @param {object} params The Reclame parameters of the instance during init.
* @returns {object} The following feature state:
* <ul>
* <li>props.target: a function to compute props for the focus target</li>
* </ul>.
*/
const useFocusable = (params) => {
return {
props: {
target: (runtimeParams) => {
const { features, props } = runtimeParams
return {
onFocus: props.onFocus || undefined,
onBlur: props.onBlur || undefined,
tabIndex: 0,
...features.disableable.props.target(runtimeParams),
}
},
},
}
}
const Focusable = feature({
id: 'focusable',
modifiers: ({ props }) => ({ isDisabled: props.isDisabled }),
hook: useFocusable,
mixes: [Disableable],
propTypes: {
onFocus: PropTypes.func,
onBlur: PropTypes.func,
},
propDescriptions: {
// ...
},
defaultProps: {
onFocus: null,
onBlur: null,
},
})
export default Focusable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment