This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AvatarBase = feature({ | |
id: 'AvatarBase', | |
className: 'avatar', | |
mixes: [Aria, Clickable, Identifiable, LoadableImage, Sizeable], | |
propTypes: { | |
url: PropTypes.string, | |
name: PropTypes.string, | |
shorthand: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | |
}, | |
propDescriptions: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Takes a bunch of features, and merges the features' prop types, descriptions | |
* and default values into an object. If you pass a second parameter, it must be | |
* the object into which to mix the properties. Else, a blank object will be | |
* created and returned. | |
* @param {Array.<object>} features The array of features to mix. | |
* @param {Function|object=} dest If set, the object to mix into. | |
* @returns {object} The mixed object (`dest` if it was set). | |
*/ | |
const mix = (features, dest = { id: Symbol('mix') }) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Callout = (initialProps) => { | |
const params = useReclame(Callout, initialProps, [CalloutBase, Closable]) | |
const { bem, props, features, state } = params | |
return features.closable.isClosed ? null : ( | |
<aside className={bem.block()} {...renderRootProps(params)}> | |
{/* ... */} | |
</aside> | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useState } from 'react' | |
import PropTypes from '@ljn/prop-types' | |
import feature from 'core/feature' | |
/** | |
* Makes it possible to close a component, by interacting with a clickable element | |
* that must then trigger `features.closable.close`. | |
* | |
* @param {object} params The Reclame parameters of the component using this feature. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isString } from '@ljn/utils' | |
import PropTypes from '@ljn/prop-types' | |
import feature from 'core/feature' | |
const VariantAble = feature({ | |
id: 'variantAble', | |
modifiers: ({ props }) => { | |
return { variant: isString(props.variant) ? props.variant.split(' ') : props.variant } | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useTranslation } from 'react-i18next' | |
import feature from 'core/feature' | |
import i18nInstance from 'core/i18n' | |
/** | |
* Provides a translation function and i18n instance to Reclame components using | |
* the Translatable feature. The function is tied to the Reclame scope and Reclame's | |
* current locale. | |
* @param {object} params The parameters of the Reclame component. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const SomeSpecialHighlight = (initialProps) => { | |
// Instance initialisation; we mix the core feature and variant specific feature(s) | |
const params = useReclame(Highlight, initialProps, [HighlightBase, SomeSpecialFeature]) | |
const { bem, props } = params | |
// We try to avoid code here; we prefer to do state management and compute | |
// memoised values inside features' init hooks when possible.This keeps | |
// final component code as close to being a DOM declaration as possible | |
// and allows us to make variants with a rearranged DOM at next to no cost. |
NewerOlder