diff --git a/docs/src/components/ComponentDoc/ComponentExample/ComponentExample.js b/docs/src/components/ComponentDoc/ComponentExample/ComponentExample.js index 3bdc769bc4..7589bfa03a 100644 --- a/docs/src/components/ComponentDoc/ComponentExample/ComponentExample.js +++ b/docs/src/components/ComponentDoc/ComponentExample/ComponentExample.js @@ -1,9 +1,10 @@ +import { KnobProvider } from '@stardust-ui/docs-components' import cx from 'classnames' import copyToClipboard from 'copy-to-clipboard' import PropTypes from 'prop-types' import React, { Component } from 'react' import VisibilitySensor from 'react-visibility-sensor' -import { Grid } from 'semantic-ui-react' +import { Checkbox, Grid, Label } from 'semantic-ui-react' import { examplePathToHash, scrollToAnchor } from 'docs/src/utils' import CarbonAdNative from 'docs/src/components/CarbonAd/CarbonAdNative' @@ -11,6 +12,7 @@ import formatCode from 'docs/src/utils/formatCode' import ComponentControls from '../ComponentControls' import ExampleEditor from '../ExampleEditor' import ComponentDocContext from '../ComponentDocContext' +import ComponentExampleKnobs from './ComponentExampleKnobs' import ComponentExampleTitle from './ComponentExampleTitle' const childrenStyle = { @@ -23,6 +25,29 @@ const componentControlsStyle = { width: 'auto', } +/* eslint-disable react/prop-types */ +const knobComponents = { + KnobControl: (props) => ( +
+ {props.children} +
+ ), + KnobBoolean: (props) => ( + props.setValue(data.checked)} + type='checkbox' + value={props.value} + /> + ), + KnobLabel: (props) => ( + + ), +} +/* eslint-enable react/prop-types */ + /** * Renders a `component` and the raw `code` that produced it. * Allows toggling the the raw `code` code block. @@ -78,9 +103,7 @@ class ComponentExample extends Component { if (wasCodeChanged) { /* eslint-disable-next-line no-console */ console.warn( - `[HMR] the code of example (${ - props.examplePath - }) was not reload because it was modified, please reset your changes.`, + `[HMR] the code of example (${props.examplePath}) was not reload because it was modified, please reset your changes.`, ) } else { derivedState.originalSourceCode = props.sourceCode @@ -173,27 +196,31 @@ class ComponentExample extends Component { /> + + - {children && ( - - {children} + {children && ( + + {children} + + )} + + + - )} - - - - + + {isActiveHash && } diff --git a/docs/src/components/ComponentDoc/ComponentExample/ComponentExampleKnobs.js b/docs/src/components/ComponentDoc/ComponentExample/ComponentExampleKnobs.js new file mode 100644 index 0000000000..6e1470f595 --- /dev/null +++ b/docs/src/components/ComponentDoc/ComponentExample/ComponentExampleKnobs.js @@ -0,0 +1,43 @@ +import { CodeSnippet, KnobInspector, useKnobValues } from '@stardust-ui/docs-components' +import _ from 'lodash' +import React from 'react' +import { Grid } from 'semantic-ui-react' + +const columnStyles = { + padding: 0, +} + +const knobsStyles = { + background: 'whitesmoke', + color: '#777', + lineHeight: '1.5', + padding: '1rem', +} + +const rowStyles = { + padding: 0, +} + +const ComponentExampleKnobs = () => { + const knobValues = useKnobValues() + const values = _.fromPairs(knobValues.map((knob) => [knob.name, knob.value])) + + return ( + + {(knobs) => + knobs && ( + + +
{knobs}
+
+ + + +
+ ) + } +
+ ) +} + +export default ComponentExampleKnobs diff --git a/docs/src/components/ComponentDoc/ExampleEditor/renderConfig.js b/docs/src/components/ComponentDoc/ExampleEditor/renderConfig.js index 33cf224934..edb9f03276 100644 --- a/docs/src/components/ComponentDoc/ExampleEditor/renderConfig.js +++ b/docs/src/components/ComponentDoc/ExampleEditor/renderConfig.js @@ -1,3 +1,4 @@ +import * as docsComponents from '@stardust-ui/docs-components' import faker from 'faker' import React from 'react' import PropTypes from 'prop-types' @@ -16,6 +17,7 @@ export const babelConfig = { } export const externals = { + '@stardust-ui/docs-components': docsComponents, faker, lodash: require('lodash'), react: React, diff --git a/docs/src/components/ExternalExampleLayout.js b/docs/src/components/ExternalExampleLayout.js index 71862a3ef4..5fbc95d646 100644 --- a/docs/src/components/ExternalExampleLayout.js +++ b/docs/src/components/ExternalExampleLayout.js @@ -1,11 +1,12 @@ +import { KnobProvider } from '@stardust-ui/docs-components' import PropTypes from 'prop-types' -import { createElement } from 'react' +import React, { createElement } from 'react' import { withRouteData } from 'react-static' const ExternalExampleLayout = (props) => { const exampleComponent = require(`docs/src/examples/${props.path}`).default - return createElement(exampleComponent) + return {createElement(exampleComponent)} } ExternalExampleLayout.propTypes = { diff --git a/docs/src/examples/modules/Popup/Usage/PopupExampleActions.js b/docs/src/examples/modules/Popup/Usage/PopupExampleActions.js index 3c47111415..28e19b1d95 100644 --- a/docs/src/examples/modules/Popup/Usage/PopupExampleActions.js +++ b/docs/src/examples/modules/Popup/Usage/PopupExampleActions.js @@ -26,7 +26,7 @@ const PopupExampleActions = () => ( Click me or Hover me} + trigger={} header='Movie Search' content='Multiple events can trigger a popup' on={['hover', 'click']} diff --git a/docs/src/examples/modules/Popup/Usage/PopupExampleEventsEnabled.js b/docs/src/examples/modules/Popup/Usage/PopupExampleEventsEnabled.js new file mode 100644 index 0000000000..57e7f9c94f --- /dev/null +++ b/docs/src/examples/modules/Popup/Usage/PopupExampleEventsEnabled.js @@ -0,0 +1,25 @@ +import { useBooleanKnob } from '@stardust-ui/docs-components' +import React from 'react' +import { Button, Popup } from 'semantic-ui-react' + +const PopupExampleEventsEnabled = () => { + const [eventsEnabled] = useBooleanKnob({ + name: 'eventsEnabled', + initialValue: true, + }) + const [open, setOpen] = useBooleanKnob({ name: 'open' }) + + return ( + setOpen(false)} + onOpen={() => setOpen(true)} + open={open} + trigger={