Skip to content
feeds-prop-types / 0.0.0-beta-20240321171834

feeds-prop-types 0.0.0-beta-20240321171834

Install from the command line:
Learn more about npm packages
$ npm install @wpmedia/feeds-prop-types@0.0.0-beta-20240321171834
Install via package.json:
"@wpmedia/feeds-prop-types": "0.0.0-beta-20240321171834"

About this version

Feeds Prop Types

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.

Usage

Fusion custom fields are defined as React PropTypes.

propType definitions

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,
  ),
}

Functional propType definitions

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),
}

Generating propTypes for a feed type

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


Assets

  • feeds-prop-types-0.0.0-beta-20240321171834.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0