feeds-prop-types 0.0.0-canary-20240228231756
Install from the command line:
Learn more about npm packages
$ npm install @wpmedia/feeds-prop-types@0.0.0-canary-20240228231756
Install via package.json:
"@wpmedia/feeds-prop-types": "0.0.0-canary-20240228231756"
About this version
Fusion allows features to define custom fields used configure the feature. Many of the outbound feeds share custom fields. This package stores shared custom fields PropType information to use in features.
Fusion custom fields are defined as React PropTypes.
Fusion propTypes
are the same as React propTypes
, but they are extended with a tag
function to add metadata to the custom field. See the Fusion custom field docs for more detail.
In propInfo.js
, custom field props are grouped by feed type. If you wanted to add a shared RSS PropType, you would do the following:
const propInfo = {
rss: {
sharedProp: {
type: 'boolean',
tag: {
label: 'Include this shared value?',
defaultValue: true,
},
},
},
}
PropTypes are generally defined as PropType.[type].tag([tagOptions])
. The object above corresponds to this format, e.g., using the above custom field,
Feature.propTypes = {
sharedProp: PropTypes[propInfo.rss.sharedProp.type].tag(
propInfo.rss.sharedProp.tag,
),
}
Some PropType validation options are functions, i.e., oneOf
. You can define a functional PropType as well.
const propInfo = {
rss: {
funcProp: {
type: 'oneOf',
args: ['News', 'Photos'],
tag: {
defaultValue: 'News',
},
},
},
}
Which is used similar to what was shown above:
Feature.propTypes = {
sharedProp: PropTypes[propInfo.rss.funcProp.type](
propInfo.rss.funProp.args,
).tag(propInfo.rss.sharedProp.tag),
}
Defining all shared custom fields as shown above can get tedious. This package provides a generatePropsForFeed
function that will return the right shape for custom fields.
Feature.propTypes = {
customFields: PropTypes.shape(generatePropsForFeed('rss', PropTypes)),
}
If you'd like to add additional custom fields, you can spread the return value into your customFields
shape:
Feature.propTypes = {
customFields: PropTypes.shape({
...generatePropsForFeed('rss', PropTypes),
featureSpecific: PropTypes.string.tag(),
}),
}
Details
- feeds-prop-types
- WPMedia
- 11 months ago
- CC-BY-NC-ND-4.0
- 1 dependencies
Assets
- feeds-prop-types-0.0.0-canary-20240228231756.tgz
Download activity
- Total downloads 1
- Last 30 days 0
- Last week 0
- Today 0