Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(ComponentExample): allow to disable HTML preview #3404

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import Routes from 'react-static-routes'
const App = () => (
<Router>
<Switch>
<Switch>
<Routes />
</Switch>
<Routes />
</Switch>
</Router>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ComponentControlsCodeSandbox = isBrowser()
const ComponentControls = (props) => {
const {
anchorName,
disableHtml,
exampleCode,
examplePath,
showHTML,
Expand All @@ -33,7 +34,7 @@ const ComponentControls = (props) => {
return (
<Menu color='green' compact icon='labeled' size='tiny' text>
<ComponentControlsEditCode active={showCode} onClick={onShowCode} />
<ComponentControlsShowHtml active={showHTML} onClick={onShowHTML} />
<ComponentControlsShowHtml active={showHTML} disabled={disableHtml} onClick={onShowHTML} />
<ComponentControlsCodeSandbox exampleCode={exampleCode} />
<ComponentControlsMaximize examplePath={examplePath} />
<ComponentControlsCopyLink anchorName={anchorName} onClick={onCopyLink} />
Expand All @@ -42,9 +43,10 @@ const ComponentControls = (props) => {
}

ComponentControls.propTypes = {
anchorName: PropTypes.string,
disableHtml: PropTypes.bool,
exampleCode: PropTypes.string,
examplePath: PropTypes.string,
anchorName: PropTypes.string,
onCopyLink: PropTypes.func,
onShowCode: PropTypes.func,
onShowHTML: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import PropTypes from 'prop-types'
import React from 'react'
import { Icon, Menu } from 'semantic-ui-react'

const ComponentControlsShowHtml = ({ active, onClick }) => (
<Menu.Item active={active} onClick={onClick}>
const ComponentControlsShowHtml = ({ active, disabled, onClick }) => (
<Menu.Item
active={active}
disabled={disabled}
onClick={onClick}
title={disabled ? 'HTML preview is disabled for this example' : ''}
>
<Icon color={active ? 'green' : 'grey'} size='large' name='html5' fitted />
Show HTML
</Menu.Item>
)

ComponentControlsShowHtml.propTypes = {
active: PropTypes.bool,
disabled: PropTypes.bool,
onClick: PropTypes.func,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ class ComponentExample extends PureComponent {
history: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
renderHtml: PropTypes.bool,
suiVersion: PropTypes.string,
title: PropTypes.node,
}

static defaultProps = {
renderHtml: true,
}

componentWillMount() {
const { examplePath } = this.props
this.anchorName = examplePathToHash(examplePath)
Expand Down Expand Up @@ -193,7 +198,15 @@ class ComponentExample extends PureComponent {
handleRenderSuccess = (error, { markup }) => this.setState({ error, htmlMarkup: markup })

render() {
const { children, description, displayName, examplePath, suiVersion, title } = this.props
const {
children,
description,
displayName,
examplePath,
renderHtml,
suiVersion,
title,
} = this.props
const {
error,
handleMouseLeave,
Expand Down Expand Up @@ -247,6 +260,7 @@ class ComponentExample extends PureComponent {
<Grid.Column textAlign='right' style={componentControlsStyle}>
<ComponentControls
anchorName={this.anchorName}
disableHtml={!renderHtml}
exampleCode={sourceCode}
examplePath={examplePath}
onCopyLink={this.handleDirectLinkClick}
Expand All @@ -273,6 +287,7 @@ class ComponentExample extends PureComponent {
displayName={displayName}
onError={this.handleRenderError}
onSuccess={this.handleRenderSuccess}
renderHtml={renderHtml}
sourceCode={sourceCode}
/>
</Grid.Column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ const resolver = (importPath, { displayName }) => {
)
}

const ComponentExampleRenderSource = ({ displayName, onError, onSuccess, sourceCode }) => (
const ComponentExampleRenderSource = ({
displayName,
onError,
onSuccess,
renderHtml,
sourceCode,
}) => (
<SourceRender
babelConfig={babelConfig}
displayName={displayName}
onError={onError}
onSuccess={onSuccess}
renderHtml={renderHtml}
resolver={resolver}
source={sourceCode}
/>
Expand All @@ -47,6 +54,7 @@ ComponentExampleRenderSource.propTypes = {
displayName: PropTypes.string.isRequired,
onError: PropTypes.func.isRequired,
onSuccess: PropTypes.func.isRequired,
renderHtml: PropTypes.bool.isRequired,
sourceCode: PropTypes.string.isRequired,
}

Expand Down
89 changes: 79 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4059,6 +4059,13 @@ define-properties@^1.1.2:
foreach "^2.0.5"
object-keys "^1.0.8"

define-properties@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
integrity sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==
dependencies:
object-keys "^1.0.12"

define-property@^0.2.5:
version "0.2.5"
resolved "https://registry.yarnpkg.com/define-property/-/define-property-0.2.5.tgz#c35b1ef918ec3c990f9a5bc57be04aacec5c8116"
Expand Down Expand Up @@ -4547,24 +4554,28 @@ entities@^1.1.1, entities@~1.1.1:
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"

enzyme-adapter-react-16@^1.5.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.6.0.tgz#3fca28d3c32f3ff427495380fe2dd51494689073"
version "1.8.0"
resolved "https://registry.yarnpkg.com/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.8.0.tgz#7055d8e908d8d27b807cf4292244db3c815ca11d"
integrity sha512-7cVHIKutqnesGeM3CjNFHSvktpypSWBokrBO8wIW+BVx+HGxWCF87W9TpkIIYJqgCtdw9FQGFrAbLg8kSwPRuQ==
dependencies:
enzyme-adapter-utils "^1.8.0"
enzyme-adapter-utils "^1.10.0"
function.prototype.name "^1.1.0"
object.assign "^4.1.0"
object.values "^1.0.4"
object.values "^1.1.0"
prop-types "^15.6.2"
react-is "^16.5.2"
react-is "^16.7.0"
react-test-renderer "^16.0.0-0"

enzyme-adapter-utils@^1.8.0:
version "1.8.1"
resolved "https://registry.yarnpkg.com/enzyme-adapter-utils/-/enzyme-adapter-utils-1.8.1.tgz#a927d840ce2c14b42892a533aec836809d4e022b"
enzyme-adapter-utils@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/enzyme-adapter-utils/-/enzyme-adapter-utils-1.10.0.tgz#5836169f68b9e8733cb5b69cad5da2a49e34f550"
integrity sha512-VnIXJDYVTzKGbdW+lgK8MQmYHJquTQZiGzu/AseCZ7eHtOMAj4Rtvk8ZRopodkfPves0EXaHkXBDkVhPa3t0jA==
dependencies:
function.prototype.name "^1.1.0"
object.assign "^4.1.0"
object.fromentries "^2.0.0"
prop-types "^15.6.2"
semver "^5.6.0"

enzyme@^3.7.0:
version "3.7.0"
Expand Down Expand Up @@ -4619,6 +4630,18 @@ es-abstract@^1.10.0, es-abstract@^1.5.0, es-abstract@^1.5.1:
is-callable "^1.1.3"
is-regex "^1.0.4"

es-abstract@^1.11.0, es-abstract@^1.12.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.13.0.tgz#ac86145fdd5099d8dd49558ccba2eaf9b88e24e9"
integrity sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==
dependencies:
es-to-primitive "^1.2.0"
function-bind "^1.1.1"
has "^1.0.3"
is-callable "^1.1.4"
is-regex "^1.0.4"
object-keys "^1.0.12"

es-abstract@^1.6.1, es-abstract@^1.7.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864"
Expand All @@ -4637,6 +4660,15 @@ es-to-primitive@^1.1.1:
is-date-object "^1.0.1"
is-symbol "^1.0.1"

es-to-primitive@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.0.tgz#edf72478033456e8dda8ef09e00ad9650707f377"
integrity sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==
dependencies:
is-callable "^1.1.4"
is-date-object "^1.0.1"
is-symbol "^1.0.2"

es5-ext@^0.10.14, es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.14:
version "0.10.37"
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.37.tgz#0ee741d148b80069ba27d020393756af257defc3"
Expand Down Expand Up @@ -7036,6 +7068,13 @@ is-symbol@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572"

is-symbol@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.2.tgz#a055f6ae57192caee329e7a860118b497a950f38"
integrity sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==
dependencies:
has-symbols "^1.0.0"

is-typedarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
Expand Down Expand Up @@ -8692,6 +8731,11 @@ object-keys@^1.0.10, object-keys@^1.0.11, object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"

object-keys@^1.0.12:
version "1.0.12"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.12.tgz#09c53855377575310cca62f55bb334abff7b3ed2"
integrity sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==

object-visit@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/object-visit/-/object-visit-1.0.1.tgz#f79c4493af0c5377b59fe39d395e41042dd045bb"
Expand Down Expand Up @@ -8733,6 +8777,16 @@ object.entries@^1.0.4:
function-bind "^1.1.0"
has "^1.0.1"

object.fromentries@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/object.fromentries/-/object.fromentries-2.0.0.tgz#49a543d92151f8277b3ac9600f1e930b189d30ab"
integrity sha512-9iLiI6H083uiqUuvzyY6qrlmc/Gz8hLQFOcb/Ri/0xXFkSNS3ctV+CbE6yM2+AnkYfOB3dGjdzC0wrMLIhQICA==
dependencies:
define-properties "^1.1.2"
es-abstract "^1.11.0"
function-bind "^1.1.1"
has "^1.0.1"

object.getownpropertydescriptors@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16"
Expand Down Expand Up @@ -8776,6 +8830,16 @@ object.values@^1.0.4:
function-bind "^1.1.0"
has "^1.0.1"

object.values@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/object.values/-/object.values-1.1.0.tgz#bf6810ef5da3e5325790eaaa2be213ea84624da9"
integrity sha512-8mf0nKLAoFX6VlNVdhGj31SVYpaNFtUnuoOXWyFEstsWRgU837AK+JYM0iAxwkSzGRbwn8cbFmgbyxj1j4VbXg==
dependencies:
define-properties "^1.1.3"
es-abstract "^1.12.0"
function-bind "^1.1.1"
has "^1.0.3"

obuf@^1.0.0, obuf@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/obuf/-/obuf-1.1.2.tgz#09bea3343d41859ebd446292d11c9d4db619084e"
Expand Down Expand Up @@ -10008,10 +10072,15 @@ react-hot-loader@^4.3.11:
react-lifecycles-compat "^3.0.4"
shallowequal "^1.0.2"

react-is@^16.5.2, react-is@^16.6.0:
react-is@^16.6.0:
version "16.6.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.0.tgz#456645144581a6e99f6816ae2bd24ee94bdd0c01"

react-is@^16.7.0:
version "16.7.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.7.0.tgz#c1bd21c64f1f1364c6f70695ec02d69392f41bfa"
integrity sha512-Z0VRQdF4NPDoI0tsXVMLkJLiwEBa+RP66g0xDHxgxysxSoCUccSten4RTF/UFvZF1dZvZ9Zu1sx+MDXwcOR34g==

react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
Expand Down Expand Up @@ -10933,7 +11002,7 @@ semver@^5.4.1, semver@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"

semver@^5.5.1:
semver@^5.5.1, semver@^5.6.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"

Expand Down