Socket
Socket
Sign inDemoInstall

terra-props-table

Package Overview
Dependencies
Maintainers
10
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terra-props-table - npm Package Compare versions

Comparing version 2.15.0 to 2.16.0

12

bin/generateMarkdown/generatePropRow.js
const generatePropType = require('./generatePropType');
const generatePropRow = (propName, prop) => (
`| ${propName || ''}` +
`| ${prop.type ? generatePropType(prop.type) : ''}` +
`| ${prop.required ? '`required`' : 'optional'}` +
`| ${prop.defaultValue ? `\`${prop.defaultValue.value}\`` : ''}` +
`| ${prop.description ? prop.description.replace(/\n|\r/g, ' ') : ''}` +
'|'
`| ${propName || ''}`
+ `| ${prop.type ? generatePropType(prop.type) : ''}`
+ `| ${prop.required ? '`required`' : 'optional'}`
+ `| ${prop.defaultValue ? `\`${prop.defaultValue.value}\`` : ''}`
+ `| ${prop.description ? prop.description.replace(/\n|\r/g, ' ') : ''}`
+ '|'
);
module.exports = generatePropRow;

@@ -5,8 +5,7 @@ #!/usr/bin/env node

const path = require('path');
const pkg = require('../package.json');
const commander = require('commander');
const glob = require('glob');
const uniq = require('lodash/uniq');
const { parse } = require('react-docgen');
const generateMarkdown = require('./generateMarkdown/generateMarkdown');
const { parse } = require('react-docgen');
const pkg = require('../package.json');

@@ -31,3 +30,3 @@ commander

// verify filenames are unique
filenames = uniq(filenames);
filenames = [...new Set(filenames)];

@@ -34,0 +33,0 @@ // check if filenames exist

@@ -7,2 +7,9 @@ Changelog

2.15.0 - (August 29, 2018)
------------------
### Changed
* Minor dependency version bump
* Updated `react-docgen` parse function to handle multiple exports
* Dropped dependency on lodash/uniq and replaced with vanilla JavaScript
2.14.0 - (July 19, 2018)

@@ -9,0 +16,0 @@ ------------------

@@ -12,3 +12,3 @@ # Dependency Information

| react-docgen | ^2.15.0 | -- | A CLI and toolkit to extract information from React components for documentation generation. |
| terra-markdown | ^2.11.0 | ^16.2.0 | terra-markdown |
| terra-markdown | ^2.12.0 | ^16.2.0 | terra-markdown |

@@ -15,0 +15,0 @@ ## peerDependencies

@@ -63,3 +63,4 @@ 'use strict';

null,
' array of objects structured like: ',
' ',
'array of objects structured like:',
_react2.default.createElement(

@@ -81,3 +82,4 @@ 'pre',

{ key: option.value },
' an object structured like:',
' ',
'an object structured like:',
_react2.default.createElement(

@@ -109,3 +111,4 @@ 'pre',

null,
' an object structured like: ',
' ',
'an object structured like:',
_react2.default.createElement(

@@ -133,6 +136,7 @@ 'pre',

/**
* Runs component source code through react-docgen
* Runs component source code through react-docgen. Passing second argument to parse
* function to account for mutiple export.
* @type {Object}
*/
var componentMetaData = (0, _reactDocgen.parse)(src);
var componentMetaData = (0, _reactDocgen.parse)(src, _reactDocgen.resolver.findAllComponentDefinitions);

@@ -143,3 +147,3 @@ /**

*/
var componentProps = componentMetaData.props;
var componentProps = componentMetaData[0].props;

@@ -156,3 +160,4 @@ var tableRowClass = cx('prop-table-row');

componentName,
' Props'
' ',
'Props'
),

@@ -159,0 +164,0 @@ _react2.default.createElement(

{
"name": "terra-props-table",
"main": "lib/PropsTable.js",
"version": "2.15.0",
"version": "2.16.0",
"description": "terra-props-table",

@@ -34,6 +34,5 @@ "repository": {

"glob": "^7.1.2",
"lodash": "^4.17.4",
"prop-types": "^15.5.8",
"react-docgen": "^2.15.0",
"terra-markdown": "^2.12.0"
"terra-markdown": "^2.13.0"
},

@@ -40,0 +39,0 @@ "scripts": {

# Terra Props Table
[![NPM version](http://img.shields.io/npm/v/terra-props-table.svg)](https://www.npmjs.org/package/terra-props-table)
[![Build Status](https://travis-ci.org/cerner/terra-core.svg?branch=master)](https://travis-ci.org/cerner/terra-core)
[![NPM version](https://badgen.net/npm/v/terra-props-table)](https://www.npmjs.org/package/terra-props-table)
[![Build Status](https://badgen.net/travis/cerner/terra-core)](https://travis-ci.org/cerner/terra-core)

@@ -7,0 +7,0 @@ React component to render a table view for the props metadata of another react component.

/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import PropTypes from 'prop-types';
import { parse } from 'react-docgen';
import { parse, resolver } from 'react-docgen';
import Markdown from 'terra-markdown';

@@ -33,3 +33,13 @@ import classNames from 'classnames/bind';

if (type.value.name === 'shape') {
typeName = <span> array of objects structured like: <pre className={cx('props-table-pre')}> {formatShape(type.value.value)} </pre></span>;
typeName = (
<span>
{' '}
array of objects structured like:
<pre className={cx('props-table-pre')}>
{' '}
{formatShape(type.value.value)}
{' '}
</pre>
</span>
);
} else {

@@ -41,6 +51,17 @@ typeName = `array of ${type.value.name}s`;

const name = option.name === 'shape' ? ((
<span key={option.value}> an object structured like:
<pre className={cx('props-table-pre')}> {formatShape(option.value)} </pre>
<span key={option.value}>
{' '}
an object structured like:
<pre className={cx('props-table-pre')}>
{' '}
{formatShape(option.value)}
{' '}
</pre>
</span>
)) : (<span key={option.name}> {option.name}</span>);
)) : (
<span key={option.name}>
{' '}
{option.name}
</span>
);
return name;

@@ -50,3 +71,13 @@ });

} else if (typeName === 'shape') {
typeName = <span> an object structured like: <pre className={cx('props-table-pre')}> {formatShape(type.value)} </pre></span>;
typeName = (
<span>
{' '}
an object structured like:
<pre className={cx('props-table-pre')}>
{' '}
{formatShape(type.value)}
{' '}
</pre>
</span>
);
}

@@ -62,6 +93,7 @@

/**
* Runs component source code through react-docgen
* Runs component source code through react-docgen. Passing second argument to parse
* function to account for mutiple export.
* @type {Object}
*/
const componentMetaData = parse(src);
const componentMetaData = parse(src, resolver.findAllComponentDefinitions);

@@ -72,3 +104,3 @@ /**

*/
const componentProps = componentMetaData.props;
const componentProps = componentMetaData[0].props;

@@ -83,3 +115,7 @@ const tableRowClass = cx('prop-table-row');

<div dir="ltr" className="markdown-body">
<h2>{componentName} Props</h2>
<h2>
{componentName}
{' '}
Props
</h2>
<table {...customProps} className={tableClassNames}>

@@ -104,8 +140,8 @@ <thead>

<td>{(prop.type ? type : '')}</td>
{(prop.required ?
<td style={{ color: '#d53700' }}>required</td>
: <td style={{ color: '#444' }}>optional</td>)}
{(prop.defaultValue ?
<td style={{ fontWeight: 'bold' }}>{prop.defaultValue.value}</td>
: <td style={{ color: '#444' }}>none</td>)}
{(prop.required
? <td style={{ color: '#d53700' }}>required</td>
: <td style={{ color: '#444' }}>optional</td>)}
{(prop.defaultValue
? <td style={{ fontWeight: 'bold' }}>{prop.defaultValue.value}</td>
: <td style={{ color: '#444' }}>none</td>)}
<td><Markdown src={prop.description} /></td>

@@ -112,0 +148,0 @@ </tr>

@@ -17,6 +17,5 @@ const generatePropType = require('../../bin/generateMarkdown/generatePropType');

it('should return "string" for enum', () => {
const enumProp =
{
name: 'enum',
value:
const enumProp = {
name: 'enum',
value:
[{ value: '\'default\'' },

@@ -26,3 +25,3 @@ { value: '\'link\'' },

{ value: '\'secondary\'' }],
};
};
expect(generatePropType(enumProp)).toEqual('`string`');

@@ -32,6 +31,5 @@ });

it('should return "number" for enum', () => {
const enumProp =
{
name: 'enum',
value:
const enumProp = {
name: 'enum',
value:
[{ value: '2' },

@@ -41,3 +39,3 @@ { value: '4' },

{ value: '3' }],
};
};
expect(generatePropType(enumProp)).toEqual('`number`');

@@ -47,8 +45,7 @@ });

it('should return list of types for oneOfType', () => {
const propType =
{
name: 'union',
value:
const propType = {
name: 'union',
value:
[{ name: 'string' }, { name: 'number' }],
};
};
expect(generatePropType(propType)).toEqual('`string or number`');

@@ -58,8 +55,7 @@ });

it('should return type for arrayOf', () => {
const propType =
{
name: 'arrayOf',
value:
const propType = {
name: 'arrayOf',
value:
{ name: 'string' },
};
};
expect(generatePropType(propType)).toEqual('`array of strings`');

@@ -69,10 +65,9 @@ });

it('should return object format for arrayOf shapes', () => {
const propType =
{
name: 'arrayOf',
value: {
name: 'shape',
value: { row: 'string', icon: 'element' },
},
};
const propType = {
name: 'arrayOf',
value: {
name: 'shape',
value: { row: 'string', icon: 'element' },
},
};
expect(generatePropType(propType)).toEqual('`array of objects structured like: {"row":"string","icon":"element"}`');

@@ -82,9 +77,8 @@ });

it('should return object format for shape', () => {
const propType =
{
name: 'shape',
value: { row: 'string', icon: 'element' },
};
const propType = {
name: 'shape',
value: { row: 'string', icon: 'element' },
};
expect(generatePropType(propType)).toEqual('`an object structured like: {"row":"string","icon":"element"}`');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc