Skip to content

Instantly share code, notes, and snippets.

@interactivellama
Created March 14, 2019 04:50
Show Gist options
  • Save interactivellama/23a40d0352c7e4b5ac6763aa891dd435 to your computer and use it in GitHub Desktop.
Save interactivellama/23a40d0352c7e4b5ac6763aa891dd435 to your computer and use it in GitHub Desktop.
doc site component renderer
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import React from 'react';
import PropTypes from 'prop-types';
import CodeMirror from '../components/examples';
import Snippets from '../../../node_modules/@salesforce/design-system-react/components/site-stories';
import ComponentWrapper from '../components/component-wrapper';
import { components as packageComponents } from '@salesforce/design-system-react/package.json';
import filter from 'lodash.filter';
import startCase from 'lodash.startcase';
import kebabCase from 'lodash.kebabcase';
// Props come from React Router
const ComponentRenderer = (props) => {
const filterPredicate = { 'url-slug': props.page };
const pageComponent = filter(packageComponents, filterPredicate)[0];
// this is the plural with spaces version
const name = pageComponent['display-name'];
const url = `https://www.lightningdesignsystem.com${pageComponent['SLDS-component-path']}`;
// this is the non-plural with hyphens version
const snippetFile = kebabCase(pageComponent.component);
const component = pageComponent.component;
const status = pageComponent.status;
return (
<ComponentWrapper
component={component}
name={name}
url={url}
status={status}
>
<section className="slds-p-vertical--large">
<h2 id="examples" className="slds-text-heading--medium"><a href="#examples" className="slds-text-link--reset site-text-heading--callout">Interactive Examples</a></h2>
{Snippets[snippetFile].map((node, index) => (
<CodeMirror key={component + index} codeText={node} />
))}
</section>
<section className="slds-p-bottom--large">
<h3 id="examples" className="slds-text-heading--small slds-p-bottom--small">Need more examples? Find a bug?</h3>
<p>For even more examples, please take a preview of <a href="http://design-system-react-components.herokuapp.com/">our development environment</a> built on the popular <a href="https://storybook.js.org/">Storybook</a> platform that is an always up-to-date deploy of <a href="https://github.com/salesforce/design-system-react">this repository's</a> <code>master</code> branch. All <a href={`https://github.com/salesforce/design-system-react/tree/master/components/${component}/__examples__/`} >example code</a> on this page can be found in the <code>{`/components/${component}/__examples__/`}</code> folder. Storybook <a href={`https://github.com/salesforce/design-system-react/tree/master/components/${component}/__docs__/storybook-stories.jsx`} >example code</a> can be found in <code>{`/components/${component}/__docs__/storybook-stories.jsx`}</code>.</p>
</section>
</ComponentWrapper>
);
};
ComponentRenderer.displayName = 'ComponentRenderer';
ComponentRenderer.propTypes = {
page: PropTypes.string
};
export default ComponentRenderer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment